Skip to content
Snippets Groups Projects
Commit 4c26d593 authored by Sergio Zharinov's avatar Sergio Zharinov Committed by Rhys Arkins
Browse files

refactor(maven): unify `depName` between Maven and Gradle (#3179)

Closes #3173
parent 565f584a
Branches
No related tags found
No related merge requests found
...@@ -69,12 +69,13 @@ async function getPkgReleases({ lookupName, registryUrls }) { ...@@ -69,12 +69,13 @@ async function getPkgReleases({ lookupName, registryUrls }) {
} }
function getDependencyParts(lookupName) { function getDependencyParts(lookupName) {
const [group, name] = lookupName.split('/'); const [group, name] = lookupName.split(':');
const dependencyUrl = `${group.replace(/\./g, '/')}/${name}`;
return { return {
display: lookupName.replace('/', ':'), display: lookupName,
group, group,
name, name,
dependencyUrl: generateMavenUrl(lookupName), dependencyUrl,
}; };
} }
...@@ -150,11 +151,6 @@ async function downloadHttpProtocol(pkgUrl) { ...@@ -150,11 +151,6 @@ async function downloadHttpProtocol(pkgUrl) {
return raw.body; return raw.body;
} }
function generateMavenUrl(lookupName) {
const [group, name] = lookupName.split('/');
return group.replace(/\./g, '/') + `/${name}`;
}
function isMavenCentral(pkgUrl) { function isMavenCentral(pkgUrl) {
return pkgUrl.host === 'central.maven.org'; return pkgUrl.host === 'central.maven.org';
} }
......
...@@ -24,7 +24,7 @@ function depFromNode(node) { ...@@ -24,7 +24,7 @@ function depFromNode(node) {
const artifactId = node.valueWithPath('artifactId'); const artifactId = node.valueWithPath('artifactId');
const currentValue = node.valueWithPath('version'); const currentValue = node.valueWithPath('version');
if (groupId && artifactId && currentValue) { if (groupId && artifactId && currentValue) {
const depName = `${groupId}/${artifactId}`; const depName = `${groupId}:${artifactId}`;
const result = { const result = {
depName, depName,
currentValue, currentValue,
......
...@@ -53,7 +53,7 @@ describe('datasource/maven', () => { ...@@ -53,7 +53,7 @@ describe('datasource/maven', () => {
it('should return empty if library is not found', async () => { it('should return empty if library is not found', async () => {
const releases = await datasource.getPkgReleases({ const releases = await datasource.getPkgReleases({
...config, ...config,
lookupName: 'unknown/unknown', lookupName: 'unknown:unknown',
registryUrls: [ registryUrls: [
'file://test/_fixtures/gradle/maven/repo1.maven.org/maven2/', 'file://test/_fixtures/gradle/maven/repo1.maven.org/maven2/',
], ],
...@@ -64,7 +64,7 @@ describe('datasource/maven', () => { ...@@ -64,7 +64,7 @@ describe('datasource/maven', () => {
it('should simply return all versions of a specific library', async () => { it('should simply return all versions of a specific library', async () => {
const releases = await datasource.getPkgReleases({ const releases = await datasource.getPkgReleases({
...config, ...config,
lookupName: 'org.hamcrest/hamcrest-core', lookupName: 'org.hamcrest:hamcrest-core',
registryUrls: [ registryUrls: [
'file://test/_fixtures/gradle/maven/repo1.maven.org/maven2/', 'file://test/_fixtures/gradle/maven/repo1.maven.org/maven2/',
'file://test/_fixtures/gradle/maven/custom_maven_repo/maven2/', 'file://test/_fixtures/gradle/maven/custom_maven_repo/maven2/',
...@@ -86,7 +86,7 @@ describe('datasource/maven', () => { ...@@ -86,7 +86,7 @@ describe('datasource/maven', () => {
it('should return versions in all repositories for a specific library', async () => { it('should return versions in all repositories for a specific library', async () => {
const releases = await datasource.getPkgReleases({ const releases = await datasource.getPkgReleases({
...config, ...config,
lookupName: 'mysql/mysql-connector-java', lookupName: 'mysql:mysql-connector-java',
registryUrls: [ registryUrls: [
'file://test/_fixtures/gradle/maven/repo1.maven.org/maven2/', 'file://test/_fixtures/gradle/maven/repo1.maven.org/maven2/',
'file://test/_fixtures/gradle/maven/custom_maven_repo/maven2/', 'file://test/_fixtures/gradle/maven/custom_maven_repo/maven2/',
...@@ -100,7 +100,7 @@ describe('datasource/maven', () => { ...@@ -100,7 +100,7 @@ describe('datasource/maven', () => {
it('should return all versions of a specific library for http repositories', async () => { it('should return all versions of a specific library for http repositories', async () => {
const releases = await datasource.getPkgReleases({ const releases = await datasource.getPkgReleases({
...config, ...config,
lookupName: 'mysql/mysql-connector-java', lookupName: 'mysql:mysql-connector-java',
registryUrls: ['http://central.maven.org/maven2/'], registryUrls: ['http://central.maven.org/maven2/'],
}); });
expect(releases.releases).toEqual(generateReleases(MYSQL_VERSIONS)); expect(releases.releases).toEqual(generateReleases(MYSQL_VERSIONS));
...@@ -109,7 +109,7 @@ describe('datasource/maven', () => { ...@@ -109,7 +109,7 @@ describe('datasource/maven', () => {
it('should return all versions of a specific library if a repository fails', async () => { it('should return all versions of a specific library if a repository fails', async () => {
const releases = await datasource.getPkgReleases({ const releases = await datasource.getPkgReleases({
...config, ...config,
lookupName: 'mysql/mysql-connector-java', lookupName: 'mysql:mysql-connector-java',
registryUrls: [ registryUrls: [
'http://central.maven.org/maven2/', 'http://central.maven.org/maven2/',
'http://failed_repo/', 'http://failed_repo/',
...@@ -130,7 +130,7 @@ describe('datasource/maven', () => { ...@@ -130,7 +130,7 @@ describe('datasource/maven', () => {
try { try {
await datasource.getPkgReleases({ await datasource.getPkgReleases({
...config, ...config,
lookupName: 'org/artifact', lookupName: 'org:artifact',
registryUrls: ['http://central.maven.org/maven2/'], registryUrls: ['http://central.maven.org/maven2/'],
}); });
} catch (e) { } catch (e) {
...@@ -141,7 +141,7 @@ describe('datasource/maven', () => { ...@@ -141,7 +141,7 @@ describe('datasource/maven', () => {
it('should return all versions of a specific library if a repository fails because invalid protocol', async () => { it('should return all versions of a specific library if a repository fails because invalid protocol', async () => {
const releases = await datasource.getPkgReleases({ const releases = await datasource.getPkgReleases({
...config, ...config,
lookupName: 'mysql/mysql-connector-java', lookupName: 'mysql:mysql-connector-java',
registryUrls: [ registryUrls: [
'http://central.maven.org/maven2/', 'http://central.maven.org/maven2/',
'http://failed_repo/', 'http://failed_repo/',
...@@ -167,7 +167,7 @@ describe('datasource/maven', () => { ...@@ -167,7 +167,7 @@ describe('datasource/maven', () => {
.reply(200, invalidMavenMetadata); .reply(200, invalidMavenMetadata);
const releases = await datasource.getPkgReleases({ const releases = await datasource.getPkgReleases({
...config, ...config,
lookupName: 'mysql/mysql-connector-java', lookupName: 'mysql:mysql-connector-java',
registryUrls: [ registryUrls: [
'http://central.maven.org/maven2/', 'http://central.maven.org/maven2/',
'http://invalid_metadata_repo/maven2/', 'http://invalid_metadata_repo/maven2/',
...@@ -185,7 +185,7 @@ describe('datasource/maven', () => { ...@@ -185,7 +185,7 @@ describe('datasource/maven', () => {
.reply(200, invalidMavenMetadata); .reply(200, invalidMavenMetadata);
const releases = await datasource.getPkgReleases({ const releases = await datasource.getPkgReleases({
...config, ...config,
lookupName: 'mysql/mysql-connector-java', lookupName: 'mysql:mysql-connector-java',
registryUrls: [ registryUrls: [
'http://central.maven.org/maven2/', 'http://central.maven.org/maven2/',
'http://invalid_metadata_repo/maven2/', 'http://invalid_metadata_repo/maven2/',
...@@ -197,7 +197,7 @@ describe('datasource/maven', () => { ...@@ -197,7 +197,7 @@ describe('datasource/maven', () => {
it('should return all versions of a specific library if a repository does not end with /', async () => { it('should return all versions of a specific library if a repository does not end with /', async () => {
const releases = await datasource.getPkgReleases({ const releases = await datasource.getPkgReleases({
...config, ...config,
lookupName: 'mysql/mysql-connector-java', lookupName: 'mysql:mysql-connector-java',
registryUrls: ['http://central.maven.org/maven2'], registryUrls: ['http://central.maven.org/maven2'],
}); });
expect(releases).not.toBeNull(); expect(releases).not.toBeNull();
...@@ -206,7 +206,7 @@ describe('datasource/maven', () => { ...@@ -206,7 +206,7 @@ describe('datasource/maven', () => {
it('should return null if no repositories defined', async () => { it('should return null if no repositories defined', async () => {
const releases = await datasource.getPkgReleases({ const releases = await datasource.getPkgReleases({
...config, ...config,
lookupName: 'mysql/mysql-connector-java', lookupName: 'mysql:mysql-connector-java',
}); });
expect(releases).toBeNull(); expect(releases).toBeNull();
}); });
......
...@@ -7,7 +7,7 @@ Object { ...@@ -7,7 +7,7 @@ Object {
Object { Object {
"currentValue": "42", "currentValue": "42",
"datasource": "maven", "datasource": "maven",
"depName": "org.example/parent", "depName": "org.example:parent",
"fileReplacePosition": 186, "fileReplacePosition": 186,
"registryUrls": Array [ "registryUrls": Array [
"https://repo.maven.apache.org/maven2", "https://repo.maven.apache.org/maven2",
...@@ -16,7 +16,7 @@ Object { ...@@ -16,7 +16,7 @@ Object {
Object { Object {
"currentValue": "0.0.1", "currentValue": "0.0.1",
"datasource": "maven", "datasource": "maven",
"depName": "org.example/foo", "depName": "org.example:foo",
"fileReplacePosition": 757, "fileReplacePosition": 757,
"registryUrls": Array [ "registryUrls": Array [
"https://repo.maven.apache.org/maven2", "https://repo.maven.apache.org/maven2",
...@@ -25,7 +25,7 @@ Object { ...@@ -25,7 +25,7 @@ Object {
Object { Object {
"currentValue": "1.0.0", "currentValue": "1.0.0",
"datasource": "maven", "datasource": "maven",
"depName": "org.example/bar", "depName": "org.example:bar",
"fileReplacePosition": 905, "fileReplacePosition": 905,
"registryUrls": Array [ "registryUrls": Array [
"https://repo.maven.apache.org/maven2", "https://repo.maven.apache.org/maven2",
...@@ -34,7 +34,7 @@ Object { ...@@ -34,7 +34,7 @@ Object {
Object { Object {
"currentValue": "1.8.1", "currentValue": "1.8.1",
"datasource": "maven", "datasource": "maven",
"depName": "org.apache.maven.scm/maven-scm-provider-gitexe", "depName": "org.apache.maven.scm:maven-scm-provider-gitexe",
"fileReplacePosition": 1337, "fileReplacePosition": 1337,
"registryUrls": Array [ "registryUrls": Array [
"https://repo.maven.apache.org/maven2", "https://repo.maven.apache.org/maven2",
...@@ -42,23 +42,23 @@ Object { ...@@ -42,23 +42,23 @@ Object {
}, },
Object { Object {
"currentValue": "0.0.1", "currentValue": "0.0.1",
"depName": "org.example/\${artifact-id-placeholder}", "depName": "org.example:\${artifact-id-placeholder}",
"skipReason": "name-placeholder", "skipReason": "name-placeholder",
}, },
Object { Object {
"currentValue": "0.0.1", "currentValue": "0.0.1",
"depName": "\${group-id-placeholder}/baz", "depName": "\${group-id-placeholder}:baz",
"skipReason": "name-placeholder", "skipReason": "name-placeholder",
}, },
Object { Object {
"currentValue": "\${resourceServerVersion}", "currentValue": "\${resourceServerVersion}",
"depName": "org.example/quux", "depName": "org.example:quux",
"skipReason": "version-placeholder", "skipReason": "version-placeholder",
}, },
Object { Object {
"currentValue": "1.2.3", "currentValue": "1.2.3",
"datasource": "maven", "datasource": "maven",
"depName": "org.example/quuz", "depName": "org.example:quuz",
"fileReplacePosition": 2529, "fileReplacePosition": 2529,
"registryUrls": Array [ "registryUrls": Array [
"https://repo.maven.apache.org/maven2", "https://repo.maven.apache.org/maven2",
...@@ -66,18 +66,18 @@ Object { ...@@ -66,18 +66,18 @@ Object {
}, },
Object { Object {
"currentValue": "it's not a version", "currentValue": "it's not a version",
"depName": "org.example/quuuz", "depName": "org.example:quuuz",
"skipReason": "not-a-version", "skipReason": "not-a-version",
}, },
Object { Object {
"currentValue": "\${profile-placeholder}", "currentValue": "\${profile-placeholder}",
"depName": "org.example/profile-artifact", "depName": "org.example:profile-artifact",
"skipReason": "version-placeholder", "skipReason": "version-placeholder",
}, },
Object { Object {
"currentValue": "2.17", "currentValue": "2.17",
"datasource": "maven", "datasource": "maven",
"depName": "org.apache.maven.plugins/maven-checkstyle-plugin", "depName": "org.apache.maven.plugins:maven-checkstyle-plugin",
"fileReplacePosition": 3218, "fileReplacePosition": 3218,
"registryUrls": Array [ "registryUrls": Array [
"https://repo.maven.apache.org/maven2", "https://repo.maven.apache.org/maven2",
......
...@@ -10,7 +10,7 @@ const pomContent = fs.readFileSync( ...@@ -10,7 +10,7 @@ const pomContent = fs.readFileSync(
'utf8' 'utf8'
); );
const findFn = ({ depName }) => depName === 'org.example/quuz'; const findFn = ({ depName }) => depName === 'org.example:quuz';
describe('manager/maven', () => { describe('manager/maven', () => {
describe('extractAllPackageFiles', () => { describe('extractAllPackageFiles', () => {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment