Skip to content

Commit

Permalink
fix(datasource): rename adoptium-java to java-version (#20245)
Browse files Browse the repository at this point in the history
  • Loading branch information
RahulGautamSingh authored Feb 13, 2023
1 parent e0a74eb commit 09402a3
Show file tree
Hide file tree
Showing 20 changed files with 55 additions and 32 deletions.
13 changes: 12 additions & 1 deletion lib/config/migrations/custom/datasource-migration.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,18 @@
import { DatasourceMigration } from './datasource-migration';

describe('config/migrations/custom/datasource-migration', () => {
it('should migrate properly', () => {
it('should migrate adoptium-java', () => {
expect(DatasourceMigration).toMigrate(
{
datasource: 'adoptium-java',
},
{
datasource: 'java-version',
}
);
});

it('should migrate donet', () => {
expect(DatasourceMigration).toMigrate(
{
datasource: 'dotnet',
Expand Down
10 changes: 9 additions & 1 deletion lib/config/migrations/custom/datasource-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,15 @@ export class DatasourceMigration extends AbstractMigration {

override run(value: unknown): void {
if (is.string(value)) {
const newValue = value === 'dotnet' ? 'dotnet-version' : value;
let newValue = value;
switch (newValue) {
case 'adoptium-java':
newValue = 'java-version';
break;
case 'dotnet':
newValue = 'dotnet-version';
break;
}

this.rewrite(newValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@ describe('config/migrations/custom/match-datasources-migration', () => {
it('should migrate properly', () => {
expect(MatchDatasourcesMigration).toMigrate(
{
matchDatasources: ['dotnet'],
matchDatasources: ['adoptium-java', 'dotnet', 'npm'],
},
{
matchDatasources: ['dotnet-version'],
matchDatasources: ['java-version', 'dotnet-version', 'npm'],
}
);
});
Expand Down
15 changes: 10 additions & 5 deletions lib/config/migrations/custom/match-datasources-migration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,16 @@ export class MatchDatasourcesMigration extends AbstractMigration {

override run(value: unknown): void {
if (Array.isArray(value)) {
const newValue = value
.filter(is.nonEmptyString)
.map((datasource) =>
datasource === 'dotnet' ? 'dotnet-version' : datasource
);
const newValue = value.filter(is.nonEmptyString).map((datasource) => {
switch (datasource) {
case 'adoptium-java':
return 'java-version';
case 'dotnet':
return 'dotnet-version';
default:
return datasource;
}
});

this.rewrite(newValue);
}
Expand Down
1 change: 1 addition & 0 deletions lib/config/migrations/migrations-service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ export class MigrationsService {
]);

static readonly renamedProperties: ReadonlyMap<string, string> = new Map([
['adoptium-java', 'java-version'],
['endpoints', 'hostRules'],
['excludedPackageNames', 'excludePackageNames'],
['exposeEnv', 'exposeAllEnv'],
Expand Down
2 changes: 1 addition & 1 deletion lib/config/presets/internal/workarounds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ export const presets: Record<string, Preset> = {
allowedVersions: '/^(?:8|11|17)(?:\\.|-|$)/',
description:
'Limit Java runtime versions to LTS releases. To receive all major releases add `workarounds:javaLTSVersions` to the `ignorePresets` array.',
matchDatasources: ['docker', 'adoptium-java'],
matchDatasources: ['docker', 'java-version'],
matchPackageNames: [
'eclipse-temurin',
'amazoncorretto',
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/datasource/api.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import { AdoptiumJavaDatasource } from './adoptium-java';
import { ArtifactoryDatasource } from './artifactory';
import { AwsMachineImageDataSource } from './aws-machine-image';
import { AwsRdsDataSource } from './aws-rds';
Expand Down Expand Up @@ -32,6 +31,7 @@ import { HelmDatasource } from './helm';
import { HermitDatasource } from './hermit';
import { HexDatasource } from './hex';
import { HexpmBobDatasource } from './hexpm-bob';
import { JavaVersionDatasource } from './java-version';
import { JenkinsPluginsDatasource } from './jenkins-plugins';
import { KubernetesApiDatasource } from './kubernetes-api';
import { MavenDatasource } from './maven';
Expand All @@ -55,7 +55,6 @@ import type { DatasourceApi } from './types';
const api = new Map<string, DatasourceApi>();
export default api;

api.set(AdoptiumJavaDatasource.id, new AdoptiumJavaDatasource());
api.set(ArtifactoryDatasource.id, new ArtifactoryDatasource());
api.set(AwsMachineImageDataSource.id, new AwsMachineImageDataSource());
api.set(AwsRdsDataSource.id, new AwsRdsDataSource());
Expand Down Expand Up @@ -89,6 +88,7 @@ api.set(HelmDatasource.id, new HelmDatasource());
api.set(HermitDatasource.id, new HermitDatasource());
api.set(HexDatasource.id, new HexDatasource());
api.set(HexpmBobDatasource.id, new HexpmBobDatasource());
api.set(JavaVersionDatasource.id, new JavaVersionDatasource());
api.set(JenkinsPluginsDatasource.id, new JenkinsPluginsDatasource());
api.set(KubernetesApiDatasource.id, new KubernetesApiDatasource());
api.set(MavenDatasource.id, new MavenDatasource());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`modules/datasource/adoptium-java/index getReleases pages 1`] = `
exports[`modules/datasource/java-version/index getReleases pages 1`] = `
{
"homepage": "https://adoptium.net",
"registryUrl": "https://api.adoptium.net/",
Expand Down Expand Up @@ -159,7 +159,7 @@ exports[`modules/datasource/adoptium-java/index getReleases pages 1`] = `
}
`;

exports[`modules/datasource/adoptium-java/index getReleases processes real data (jre) 1`] = `
exports[`modules/datasource/java-version/index getReleases processes real data (jre) 1`] = `
{
"homepage": "https://adoptium.net",
"registryUrl": "https://api.adoptium.net/",
Expand All @@ -174,7 +174,7 @@ exports[`modules/datasource/adoptium-java/index getReleases processes real data
}
`;

exports[`modules/datasource/adoptium-java/index getReleases processes real data 1`] = `
exports[`modules/datasource/java-version/index getReleases processes real data 1`] = `
{
"homepage": "https://adoptium.net",
"registryUrl": "https://api.adoptium.net/",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export const pageSize = 50;

export const defaultRegistryUrl = 'https://api.adoptium.net/';

export const datasource = 'adoptium-java';
export const datasource = 'java-version';

export function getImageType(packageName: string): string {
switch (packageName) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function getPath(page: number, imageType = 'jdk'): string {

const depName = 'java';

describe('modules/datasource/adoptium-java/index', () => {
describe('modules/datasource/java-version/index', () => {
describe('getReleases', () => {
it('throws for error', async () => {
httpMock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import {
} from './common';
import type { AdoptiumJavaResponse } from './types';

export class AdoptiumJavaDatasource extends Datasource {
export class JavaVersionDatasource extends Datasource {
static readonly id = datasource;

constructor() {
Expand Down Expand Up @@ -55,8 +55,7 @@ export class AdoptiumJavaDatasource extends Datasource {
namespace: `datasource-${datasource}`,
key: ({ registryUrl, packageName }: GetReleasesConfig) =>
// TODO: types (#7154)
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
`${registryUrl}:${getImageType(packageName)}`,
`${registryUrl!}:${getImageType(packageName)}`,
})
async getReleases({
registryUrl,
Expand All @@ -68,8 +67,7 @@ export class AdoptiumJavaDatasource extends Datasource {
'fetching java release'
);
// TODO: types (#7154)
// eslint-disable-next-line @typescript-eslint/restrict-template-expressions
const url = `${registryUrl}v3/info/release_versions?page_size=${pageSize}&image_type=${imageType}&project=jdk&release_type=ga&sort_method=DATE&sort_order=DESC`;
const url = `${registryUrl!}v3/info/release_versions?page_size=${pageSize}&image_type=${imageType}&project=jdk&release_type=ga&sort_method=DATE&sort_order=DESC`;

const result: ReleaseResult = {
homepage: 'https://adoptium.net',
Expand Down
2 changes: 1 addition & 1 deletion lib/modules/datasource/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Datasources are used in Renovate primarily to fetch released versions of package
## Follow the class-based programming style

New datasources _must_ follow the class-based programming style.
Use the `adoptium-java` datasource as a reference.
Use the `java-version` datasource as a reference.

Add the datasource to the API in [`api.ts`](api.ts) so that the new datasource is usable. If you find `Pending mocks!` errors in the Jest tests and your mocked URLs are correct, ensure the datasource is correctly registered.

Expand Down
6 changes: 3 additions & 3 deletions lib/modules/manager/asdf/extract.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ dummy 1.2.3
},
{
currentValue: '16.0.0+36',
datasource: 'adoptium-java',
datasource: 'java-version',
packageName: 'java-jdk',
depName: 'java',
},
Expand Down Expand Up @@ -369,7 +369,7 @@ dummy 1.2.3
deps: [
{
currentValue: '16.0.0+36',
datasource: 'adoptium-java',
datasource: 'java-version',
depName: 'java',
packageName: 'java-jdk',
},
Expand All @@ -380,7 +380,7 @@ dummy 1.2.3
deps: [
{
currentValue: '16.0.0+36',
datasource: 'adoptium-java',
datasource: 'java-version',
depName: 'java',
packageName: 'java-jre',
},
Expand Down
4 changes: 2 additions & 2 deletions lib/modules/manager/asdf/index.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AdoptiumJavaDatasource } from '../../datasource/adoptium-java';
import { DockerDatasource } from '../../datasource/docker';
import { GithubReleasesDatasource } from '../../datasource/github-releases';
import { GithubTagsDatasource } from '../../datasource/github-tags';
import { HexpmBobDatasource } from '../../datasource/hexpm-bob';
import { JavaVersionDatasource } from '../../datasource/java-version';
import { NodeDatasource } from '../../datasource/node';
import { RubyVersionDatasource } from '../../datasource/ruby-version';

Expand All @@ -15,7 +15,7 @@ export const defaultConfig = {
};

export const supportedDatasources = [
AdoptiumJavaDatasource.id,
JavaVersionDatasource.id,
DockerDatasource.id,
GithubReleasesDatasource.id,
GithubTagsDatasource.id,
Expand Down
6 changes: 3 additions & 3 deletions lib/modules/manager/asdf/upgradeable-tooling.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { AdoptiumJavaDatasource } from '../../datasource/adoptium-java';
import { DockerDatasource } from '../../datasource/docker';
import { GithubReleasesDatasource } from '../../datasource/github-releases';
import { GithubTagsDatasource } from '../../datasource/github-tags';
import { HexpmBobDatasource } from '../../datasource/hexpm-bob';
import { JavaVersionDatasource } from '../../datasource/java-version';
import { NodeDatasource } from '../../datasource/node';
import { RubyVersionDatasource } from '../../datasource/ruby-version';
import * as regexVersioning from '../../versioning/regex';
Expand Down Expand Up @@ -181,7 +181,7 @@ export const upgradeableTooling: Record<string, ToolingDefinition> = {
);
if (adoptOpenJdkMatches) {
return {
datasource: AdoptiumJavaDatasource.id,
datasource: JavaVersionDatasource.id,
packageName: 'java-jdk',
currentValue: adoptOpenJdkMatches.groups!.version,
};
Expand All @@ -191,7 +191,7 @@ export const upgradeableTooling: Record<string, ToolingDefinition> = {
);
if (adoptOpenJreMatches) {
return {
datasource: AdoptiumJavaDatasource.id,
datasource: JavaVersionDatasource.id,
packageName: 'java-jre',
currentValue: adoptOpenJreMatches.groups!.version,
};
Expand Down
2 changes: 1 addition & 1 deletion lib/util/exec/containerbase.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const allToolConfig: Record<string, ToolConfig> = {
versioning: semverVersioningId,
},
java: {
datasource: 'adoptium-java',
datasource: 'java-version',
depName: 'java',
versioning: npmVersioningId,
},
Expand Down

0 comments on commit 09402a3

Please sign in to comment.