From 6d07cf2310ff3278441944d2d66d86a966090d48 Mon Sep 17 00:00:00 2001 From: Thorsten Wendelmuth Date: Sun, 25 Apr 2021 19:19:03 +0200 Subject: [PATCH 1/9] (#6742) added support to lookup parent homepage/scm information from poms, made sbt use this implementation --- .../2.0.0/child-all-information-2.0.0.pom | 12 ++ .../child-all-information/maven-metadata.xml | 11 ++ .../2.0.0/child-no-information-2.0.0.pom | 7 + .../child-no-information/maven-metadata.xml | 11 ++ ...child-scm-gitatcolon-information-2.0.0.pom | 6 + .../maven-metadata.xml | 11 ++ ...child-scm-gitatslash-information-2.0.0.pom | 6 + .../maven-metadata.xml | 11 ++ ...hild-scm-gitprotocol-information-2.0.0.pom | 6 + .../maven-metadata.xml | 11 ++ .../2.0.0/child-scm-information-2.0.0.pom | 11 ++ .../child-scm-information/maven-metadata.xml | 11 ++ .../2.0.0/child-url-information-2.0.0.pom | 8 + .../child-url-information/maven-metadata.xml | 11 ++ .../1.0.0/parent-scm-homepage-1.0.0.pom | 7 + .../parent-scm-homepage/maven-metadata.xml | 11 ++ lib/datasource/maven/index.spec.ts | 136 +++++++++++++++++ lib/datasource/maven/index.ts | 115 +------------- lib/datasource/maven/util.ts | 142 ++++++++++++++++++ lib/datasource/sbt-package/index.ts | 92 +++++++----- lib/datasource/sbt-plugin/index.ts | 36 +++-- 21 files changed, 514 insertions(+), 158 deletions(-) create mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-all-information/2.0.0/child-all-information-2.0.0.pom create mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-all-information/maven-metadata.xml create mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-no-information/2.0.0/child-no-information-2.0.0.pom create mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-no-information/maven-metadata.xml create mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatcolon-information/2.0.0/child-scm-gitatcolon-information-2.0.0.pom create mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatcolon-information/maven-metadata.xml create mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatslash-information/2.0.0/child-scm-gitatslash-information-2.0.0.pom create mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatslash-information/maven-metadata.xml create mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitprotocol-information/2.0.0/child-scm-gitprotocol-information-2.0.0.pom create mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitprotocol-information/maven-metadata.xml create mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-information/2.0.0/child-scm-information-2.0.0.pom create mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-information/maven-metadata.xml create mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-url-information/2.0.0/child-url-information-2.0.0.pom create mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-url-information/maven-metadata.xml create mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/parent-scm-homepage/1.0.0/parent-scm-homepage-1.0.0.pom create mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/parent-scm-homepage/maven-metadata.xml diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-all-information/2.0.0/child-all-information-2.0.0.pom b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-all-information/2.0.0/child-all-information-2.0.0.pom new file mode 100644 index 00000000000000..28881edb816acf --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-all-information/2.0.0/child-all-information-2.0.0.pom @@ -0,0 +1,12 @@ + + + com.renovate + parent-scm-homepage + 1.0.0 + + + + scm:git:http://www.github.com/child-scm/child + + https://child-home.example.com + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-all-information/maven-metadata.xml b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-all-information/maven-metadata.xml new file mode 100644 index 00000000000000..95504355915d1e --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-all-information/maven-metadata.xml @@ -0,0 +1,11 @@ + + com.renovate + child-all-information + 2.0.0 + + + 2.0.0 + + 20130301200000 + + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-no-information/2.0.0/child-no-information-2.0.0.pom b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-no-information/2.0.0/child-no-information-2.0.0.pom new file mode 100644 index 00000000000000..160296dfde666e --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-no-information/2.0.0/child-no-information-2.0.0.pom @@ -0,0 +1,7 @@ + + + com.renovate + parent-scm-homepage + 1.0.0 + + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-no-information/maven-metadata.xml b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-no-information/maven-metadata.xml new file mode 100644 index 00000000000000..4090d649edb30b --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-no-information/maven-metadata.xml @@ -0,0 +1,11 @@ + + com.renovate + child-no-information + 2.0.0 + + + 2.0.0 + + 20130301200000 + + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatcolon-information/2.0.0/child-scm-gitatcolon-information-2.0.0.pom b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatcolon-information/2.0.0/child-scm-gitatcolon-information-2.0.0.pom new file mode 100644 index 00000000000000..7c3157b5c445bb --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatcolon-information/2.0.0/child-scm-gitatcolon-information-2.0.0.pom @@ -0,0 +1,6 @@ + + + + git@github.com:child-scm/child + + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatcolon-information/maven-metadata.xml b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatcolon-information/maven-metadata.xml new file mode 100644 index 00000000000000..8a543de22c6fc2 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatcolon-information/maven-metadata.xml @@ -0,0 +1,11 @@ + + com.renovate + child-scm-gitatcolon-information + 2.0.0 + + + 2.0.0 + + 20130301200000 + + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatslash-information/2.0.0/child-scm-gitatslash-information-2.0.0.pom b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatslash-information/2.0.0/child-scm-gitatslash-information-2.0.0.pom new file mode 100644 index 00000000000000..2ad57eaa1ffde2 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatslash-information/2.0.0/child-scm-gitatslash-information-2.0.0.pom @@ -0,0 +1,6 @@ + + + + git@github.com/child-scm/child + + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatslash-information/maven-metadata.xml b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatslash-information/maven-metadata.xml new file mode 100644 index 00000000000000..b9900c494f01dc --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatslash-information/maven-metadata.xml @@ -0,0 +1,11 @@ + + com.renovate + child-scm-gitatslash-information + 2.0.0 + + + 2.0.0 + + 20130301200000 + + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitprotocol-information/2.0.0/child-scm-gitprotocol-information-2.0.0.pom b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitprotocol-information/2.0.0/child-scm-gitprotocol-information-2.0.0.pom new file mode 100644 index 00000000000000..da09dda8a96e76 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitprotocol-information/2.0.0/child-scm-gitprotocol-information-2.0.0.pom @@ -0,0 +1,6 @@ + + + + git://github.com/child-scm/child + + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitprotocol-information/maven-metadata.xml b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitprotocol-information/maven-metadata.xml new file mode 100644 index 00000000000000..229e38f2678be9 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitprotocol-information/maven-metadata.xml @@ -0,0 +1,11 @@ + + com.renovate + child-scm-gitprotocol-information + 2.0.0 + + + 2.0.0 + + 20130301200000 + + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-information/2.0.0/child-scm-information-2.0.0.pom b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-information/2.0.0/child-scm-information-2.0.0.pom new file mode 100644 index 00000000000000..76c7da2b944aed --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-information/2.0.0/child-scm-information-2.0.0.pom @@ -0,0 +1,11 @@ + + + com.renovate + parent-scm-homepage + 1.0.0 + + + + scm:git:https://www.github.com/child-scm/child + + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-information/maven-metadata.xml b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-information/maven-metadata.xml new file mode 100644 index 00000000000000..f4d6714d785075 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-information/maven-metadata.xml @@ -0,0 +1,11 @@ + + com.renovate + child-scm-information + 2.0.0 + + + 2.0.0 + + 20130301200000 + + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-url-information/2.0.0/child-url-information-2.0.0.pom b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-url-information/2.0.0/child-url-information-2.0.0.pom new file mode 100644 index 00000000000000..214ff44c3c0392 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-url-information/2.0.0/child-url-information-2.0.0.pom @@ -0,0 +1,8 @@ + + + com.renovate + parent-scm-homepage + 1.0.0 + + https://child-home.example.com + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-url-information/maven-metadata.xml b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-url-information/maven-metadata.xml new file mode 100644 index 00000000000000..120e476b2355c4 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-url-information/maven-metadata.xml @@ -0,0 +1,11 @@ + + com.renovate + child-url-information + 2.0.0 + + + 2.0.0 + + 20130301200000 + + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/parent-scm-homepage/1.0.0/parent-scm-homepage-1.0.0.pom b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/parent-scm-homepage/1.0.0/parent-scm-homepage-1.0.0.pom new file mode 100644 index 00000000000000..18357e50fb1351 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/parent-scm-homepage/1.0.0/parent-scm-homepage-1.0.0.pom @@ -0,0 +1,7 @@ + + + + scm:git:git://www.github.com/parent-scm/parent + + https://parent-home.example.com + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/parent-scm-homepage/maven-metadata.xml b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/parent-scm-homepage/maven-metadata.xml new file mode 100644 index 00000000000000..ff0e190ad1f358 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/parent-scm-homepage/maven-metadata.xml @@ -0,0 +1,11 @@ + + com.renovate + parent-scm-homepage + 1.0.0 + + + 1.0.0 + + 20130301200000 + + diff --git a/lib/datasource/maven/index.spec.ts b/lib/datasource/maven/index.spec.ts index 9a411bb8e26bad..dd3f251bbdab14 100644 --- a/lib/datasource/maven/index.spec.ts +++ b/lib/datasource/maven/index.spec.ts @@ -312,5 +312,141 @@ describe(getName(__filename), () => { }); expect(releases.releases).toEqual(generateReleases(MYSQL_VERSIONS)); }); + + it('should get source and homepage from parent', async () => { + expect( + await getPkgReleases({ + ...config, + depName: 'com.renovate:child-no-information', + registryUrls: [ + 'file://lib/datasource/maven/__fixtures__/parent_repo/', + ], + }) + ).toEqual({ + group: 'com.renovate', + name: 'child-no-information', + display: 'com.renovate:child-no-information', + registryUrl: 'file://lib/datasource/maven/__fixtures__/parent_repo/', + releases: [{ version: '2.0.0' }], + sourceUrl: 'https://github.com/parent-scm/parent', + homepage: 'https://parent-home.example.com', + }); + }); + + it('should get source from own pom and homepage from parent', async () => { + expect( + await getPkgReleases({ + ...config, + depName: 'com.renovate:child-scm-information', + registryUrls: [ + 'file://lib/datasource/maven/__fixtures__/parent_repo/', + ], + }) + ).toEqual({ + group: 'com.renovate', + name: 'child-scm-information', + display: 'com.renovate:child-scm-information', + registryUrl: 'file://lib/datasource/maven/__fixtures__/parent_repo/', + releases: [{ version: '2.0.0' }], + sourceUrl: 'https://github.com/child-scm/child', + homepage: 'https://parent-home.example.com', + }); + }); + + it('should get homepage from own pom and source from parent', async () => { + expect( + await getPkgReleases({ + ...config, + depName: 'com.renovate:child-url-information', + registryUrls: [ + 'file://lib/datasource/maven/__fixtures__/parent_repo/', + ], + }) + ).toEqual({ + group: 'com.renovate', + name: 'child-url-information', + display: 'com.renovate:child-url-information', + registryUrl: 'file://lib/datasource/maven/__fixtures__/parent_repo/', + releases: [{ version: '2.0.0' }], + sourceUrl: 'https://github.com/parent-scm/parent', + homepage: 'https://child-home.example.com', + }); + }); + + it('should get homepage and source from own pom', async () => { + expect( + await getPkgReleases({ + ...config, + depName: 'com.renovate:child-all-information', + registryUrls: [ + 'file://lib/datasource/maven/__fixtures__/parent_repo/', + ], + }) + ).toEqual({ + group: 'com.renovate', + name: 'child-all-information', + display: 'com.renovate:child-all-information', + registryUrl: 'file://lib/datasource/maven/__fixtures__/parent_repo/', + releases: [{ version: '2.0.0' }], + sourceUrl: 'https://github.com/child-scm/child', + homepage: 'https://child-home.example.com', + }); + }); + + it('should be able to detect git@github.com:child-scm as valid sourceUrl', async () => { + expect( + await getPkgReleases({ + ...config, + depName: 'com.renovate:child-scm-gitatcolon-information', + registryUrls: [ + 'file://lib/datasource/maven/__fixtures__/parent_repo/', + ], + }) + ).toEqual({ + group: 'com.renovate', + name: 'child-scm-gitatcolon-information', + display: 'com.renovate:child-scm-gitatcolon-information', + registryUrl: 'file://lib/datasource/maven/__fixtures__/parent_repo/', + releases: [{ version: '2.0.0' }], + sourceUrl: 'https://github.com/child-scm/child', + }); + }); + + it('should be able to detect git@github.com/child-scm as valid sourceUrl', async () => { + expect( + await getPkgReleases({ + ...config, + depName: 'com.renovate:child-scm-gitatslash-information', + registryUrls: [ + 'file://lib/datasource/maven/__fixtures__/parent_repo/', + ], + }) + ).toEqual({ + group: 'com.renovate', + name: 'child-scm-gitatslash-information', + display: 'com.renovate:child-scm-gitatslash-information', + registryUrl: 'file://lib/datasource/maven/__fixtures__/parent_repo/', + releases: [{ version: '2.0.0' }], + sourceUrl: 'https://github.com/child-scm/child', + }); + }); + it('should be able to detect git://@github.com/child-scm as valid sourceUrl', async () => { + expect( + await getPkgReleases({ + ...config, + depName: 'com.renovate:child-scm-gitprotocol-information', + registryUrls: [ + 'file://lib/datasource/maven/__fixtures__/parent_repo/', + ], + }) + ).toEqual({ + group: 'com.renovate', + name: 'child-scm-gitprotocol-information', + display: 'com.renovate:child-scm-gitprotocol-information', + registryUrl: 'file://lib/datasource/maven/__fixtures__/parent_repo/', + releases: [{ version: '2.0.0' }], + sourceUrl: 'https://github.com/child-scm/child', + }); + }); }); }); diff --git a/lib/datasource/maven/index.ts b/lib/datasource/maven/index.ts index 5867caa41ca61c..27cf01b5190807 100644 --- a/lib/datasource/maven/index.ts +++ b/lib/datasource/maven/index.ts @@ -1,5 +1,4 @@ import url from 'url'; -import fs from 'fs-extra'; import pAll from 'p-all'; import { XmlDocument } from 'xmldoc'; import { logger } from '../../logger'; @@ -9,7 +8,14 @@ import * as mavenVersioning from '../../versioning/maven'; import { compare } from '../../versioning/maven/compare'; import type { GetReleasesConfig, Release, ReleaseResult } from '../types'; import { MAVEN_REPO } from './common'; -import { downloadHttpProtocol, isHttpResourceExists } from './util'; +import { + MavenDependency, + downloadMavenXml, + getDependencyInfo, + getDependencyParts, + getMavenUrl, + isHttpResourceExists, +} from './util'; export { id } from './common'; @@ -18,93 +24,6 @@ export const defaultRegistryUrls = [MAVEN_REPO]; export const defaultVersioning = mavenVersioning.id; export const registryStrategy = 'merge'; -function containsPlaceholder(str: string): boolean { - return /\${.*?}/g.test(str); -} - -async function downloadFileProtocol(pkgUrl: url.URL): Promise { - const pkgPath = pkgUrl.toString().replace('file://', ''); - if (!(await fs.exists(pkgPath))) { - return null; - } - return fs.readFile(pkgPath, 'utf8'); -} - -function getMavenUrl( - dependency: MavenDependency, - repoUrl: string, - path: string -): url.URL | null { - return new url.URL(`${dependency.dependencyUrl}/${path}`, repoUrl); -} - -interface MavenXml { - authorization?: boolean; - xml?: XmlDocument; -} - -async function downloadMavenXml( - pkgUrl: url.URL | null -): Promise { - /* istanbul ignore if */ - if (!pkgUrl) { - return {}; - } - let rawContent: string; - let authorization: boolean; - switch (pkgUrl.protocol) { - case 'file:': - rawContent = await downloadFileProtocol(pkgUrl); - break; - case 'http:': - case 'https:': - ({ authorization, body: rawContent } = await downloadHttpProtocol( - pkgUrl - )); - break; - case 's3:': - logger.debug('Skipping s3 dependency'); - return {}; - default: - logger.debug({ url: pkgUrl.toString() }, `Unsupported Maven protocol`); - return {}; - } - - if (!rawContent) { - logger.debug(`Content is not found for Maven url: ${pkgUrl.toString()}`); - return {}; - } - - return { authorization, xml: new XmlDocument(rawContent) }; -} - -async function getDependencyInfo( - dependency: MavenDependency, - repoUrl: string, - version: string -): Promise> { - const result: Partial = {}; - const path = `${version}/${dependency.name}-${version}.pom`; - - const pomUrl = getMavenUrl(dependency, repoUrl, path); - const { xml: pomContent } = await downloadMavenXml(pomUrl); - if (!pomContent) { - return result; - } - - const homepage = pomContent.valueWithPath('url'); - if (homepage && !containsPlaceholder(homepage)) { - result.homepage = homepage; - } - - const sourceUrl = pomContent.valueWithPath('scm.url'); - if (sourceUrl && !containsPlaceholder(sourceUrl)) { - result.sourceUrl = sourceUrl.replace(/^scm:/, ''); - } - - return result; -} - function isStableVersion(x: string): boolean { return mavenVersion.isStable(x); } @@ -121,24 +40,6 @@ function getLatestStableVersion(releases: Release[]): string | null { return null; } -interface MavenDependency { - display: string; - group?: string; - name?: string; - dependencyUrl: string; -} - -function getDependencyParts(lookupName: string): MavenDependency { - const [group, name] = lookupName.split(':'); - const dependencyUrl = `${group.replace(/\./g, '/')}/${name}`; - return { - display: lookupName, - group, - name, - dependencyUrl, - }; -} - function extractVersions(metadata: XmlDocument): string[] { const versions = metadata.descendantWithPath('versioning.versions'); const elements = versions?.childrenNamed('version'); diff --git a/lib/datasource/maven/util.ts b/lib/datasource/maven/util.ts index 335634caac0749..c9660d98193a95 100644 --- a/lib/datasource/maven/util.ts +++ b/lib/datasource/maven/util.ts @@ -1,8 +1,11 @@ import url from 'url'; +import fs from 'fs-extra'; +import { XmlDocument } from 'xmldoc'; import { HOST_DISABLED } from '../../constants/error-messages'; import { logger } from '../../logger'; import { ExternalHostError } from '../../types/errors/external-host-error'; import { Http, HttpResponse } from '../../util/http'; +import type { ReleaseResult } from '../types'; import { MAVEN_REPO, id } from './common'; @@ -96,6 +99,14 @@ export async function downloadHttpProtocol( } } +async function downloadFileProtocol(pkgUrl: url.URL): Promise { + const pkgPath = pkgUrl.toString().replace('file://', ''); + if (!(await fs.exists(pkgPath))) { + return null; + } + return fs.readFile(pkgPath, 'utf8'); +} + export async function isHttpResourceExists( pkgUrl: url.URL | string, hostType = id @@ -119,3 +130,134 @@ export async function isHttpResourceExists( return null; } } + +function containsPlaceholder(str: string): boolean { + return /\${.*?}/g.test(str); +} + +export interface MavenDependency { + display: string; + group?: string; + name?: string; + dependencyUrl: string; +} + +interface MavenXml { + authorization?: boolean; + xml?: XmlDocument; +} + +export async function downloadMavenXml( + pkgUrl: url.URL | null +): Promise { + /* istanbul ignore if */ + if (!pkgUrl) { + return {}; + } + let rawContent: string; + let authorization: boolean; + switch (pkgUrl.protocol) { + case 'file:': + rawContent = await downloadFileProtocol(pkgUrl); + break; + case 'http:': + case 'https:': + ({ authorization, body: rawContent } = await downloadHttpProtocol( + pkgUrl + )); + break; + case 's3:': + logger.debug('Skipping s3 dependency'); + return {}; + default: + logger.debug({ url: pkgUrl.toString() }, `Unsupported Maven protocol`); + return {}; + } + + if (!rawContent) { + logger.debug(`Content is not found for Maven url: ${pkgUrl.toString()}`); + return {}; + } + + return { authorization, xml: new XmlDocument(rawContent) }; +} + +export function getMavenUrl( + dependency: MavenDependency, + repoUrl: string, + path: string +): url.URL | null { + return new url.URL(`${dependency.dependencyUrl}/${path}`, repoUrl); +} + +export function getDependencyParts(lookupName: string): MavenDependency { + const [group, name] = lookupName.split(':'); + const dependencyUrl = `${group.replace(/\./g, '/')}/${name}`; + return { + display: lookupName, + group, + name, + dependencyUrl, + }; +} + +export async function getDependencyInfo( + dependency: MavenDependency, + repoUrl: string, + version: string +): Promise> { + const result: Partial = {}; + const path = `${version}/${dependency.name}-${version}.pom`; + + const pomUrl = getMavenUrl(dependency, repoUrl, path); + const { xml: pomContent } = await downloadMavenXml(pomUrl); + if (!pomContent) { + return result; + } + + const homepage = pomContent.valueWithPath('url'); + if (homepage && !containsPlaceholder(homepage)) { + result.homepage = homepage; + } + + const sourceUrl = pomContent.valueWithPath('scm.url'); + if (sourceUrl && !containsPlaceholder(sourceUrl)) { + result.sourceUrl = sourceUrl + .replace(/^scm:/, '') + .replace(/^git:/, '') + .replace(/^git@github.com:/, 'https://github.com/') + .replace(/^git@github.com\//, 'https://github.com/') + .replace(/\.git$/, ''); + + if (result.sourceUrl.startsWith('//')) { + // most likely the result of us stripping scm:, git: etc + // going with prepending https: here which should result in potential information retrival + result.sourceUrl = `https:${result.sourceUrl}`; + } + } + + const parent = pomContent.childNamed('parent'); + if (parent && (!result.sourceUrl || !result.homepage)) { + // if we found a parent and are missing some information + // trying to get the scm/homepage information from it + const parentGroupId = parent.valueWithPath('groupId').replace(/\s/g, ''); + const parentArtifactId = parent.valueWithPath('artifactId').replace(/\s/g, ''); // prettier-ignore + const parentVersion = parent.valueWithPath('version').replace(/\s/g, ''); + const parentDisplayId = `${parentGroupId}:${parentArtifactId}`; + const parentDependency = getDependencyParts(parentDisplayId); + + const parentInformation = await getDependencyInfo( + parentDependency, + repoUrl, + parentVersion + ); + if (!result.sourceUrl && parentInformation.sourceUrl) { + result.sourceUrl = parentInformation.sourceUrl; + } + if (!result.homepage && parentInformation.homepage) { + result.homepage = parentInformation.homepage; + } + } + + return result; +} diff --git a/lib/datasource/sbt-package/index.ts b/lib/datasource/sbt-package/index.ts index c1e5b154d7c134..a745d4344c66d6 100644 --- a/lib/datasource/sbt-package/index.ts +++ b/lib/datasource/sbt-package/index.ts @@ -1,9 +1,12 @@ -import { XmlDocument } from 'xmldoc'; import { logger } from '../../logger'; import * as ivyVersioning from '../../versioning/ivy'; import { compare } from '../../versioning/maven/compare'; import { MAVEN_REPO } from '../maven/common'; -import { downloadHttpProtocol } from '../maven/util'; +import { + MavenDependency, + downloadHttpProtocol, + getDependencyInfo, +} from '../maven/util'; import { parseIndexDir } from '../sbt-plugin/util'; import type { GetReleasesConfig, ReleaseResult } from '../types'; @@ -16,10 +19,13 @@ export const registryStrategy = 'hunt'; const ensureTrailingSlash = (str: string): string => str.replace(/\/?$/, '/'); export async function getArtifactSubdirs( - searchRoot: string, + registryUrl: string, + groupId: string, artifact: string, scalaVersion: string ): Promise { + const searchRoot = `${registryUrl}${groupId}`; + const { body: indexContent } = await downloadHttpProtocol( ensureTrailingSlash(searchRoot), 'sbt' @@ -52,9 +58,11 @@ export async function getArtifactSubdirs( } export async function getPackageReleases( - searchRoot: string, + registryUrl: string, + groupId: string, artifactSubdirs: string[] ): Promise { + const searchRoot = `${registryUrl}${groupId}`; if (artifactSubdirs) { const releases: string[] = []; const parseReleases = (content: string): string[] => @@ -87,7 +95,8 @@ export function getLatestVersion(versions: string[]): string | null { } export async function getUrls( - searchRoot: string, + repositoryUrl: string, + groupId: string, artifactDirs: string[], version: string ): Promise> { @@ -103,32 +112,27 @@ export async function getUrls( for (const artifactDir of artifactDirs) { const [artifact] = artifactDir.split('_'); - const pomFileNames = [ - `${artifactDir}-${version}.pom`, - `${artifact}-${version}.pom`, - ]; - - for (const pomFileName of pomFileNames) { - const pomUrl = `${searchRoot}/${artifactDir}/${version}/${pomFileName}`; - const { body: content } = await downloadHttpProtocol(pomUrl, 'sbt'); - - if (content) { - const pomXml = new XmlDocument(content); - - const homepage = pomXml.valueWithPath('url'); - if (homepage) { - result.homepage = homepage; - } + const namesToTry: string[] = []; + namesToTry.push(artifactDir); + namesToTry.push(artifact); + + for (const mavenName of namesToTry) { + const mavenDependency: MavenDependency = { + dependencyUrl: `${repositoryUrl}${groupId}/${artifactDir}`, + display: `${artifactDir}:${artifact}:${version}`, + group: artifactDir, + name: mavenName, + }; - const sourceUrl = pomXml.valueWithPath('scm.url'); - if (sourceUrl) { - result.sourceUrl = sourceUrl - .replace(/^scm:/, '') - .replace(/^git:/, '') - .replace(/^git@github.com:/, 'https://github.com/') - .replace(/\.git$/, ''); - } + const dependencyInfo = await getDependencyInfo( + mavenDependency, + repositoryUrl, + version + ); + if (dependencyInfo.homepage || dependencyInfo.sourceUrl) { + result.homepage = dependencyInfo.homepage; + result.sourceUrl = dependencyInfo.sourceUrl; return result; } } @@ -147,23 +151,33 @@ export async function getReleases({ const [artifact, scalaVersion] = artifactIdSplit; const repoRoot = ensureTrailingSlash(registryUrl); - const searchRoots: string[] = []; + const groupIds: string[] = []; // Optimize lookup order - searchRoots.push(`${repoRoot}${groupIdSplit.join('/')}`); - searchRoots.push(`${repoRoot}${groupIdSplit.join('.')}`); + groupIds.push(`${groupIdSplit.join('/')}`); + groupIds.push(`${groupIdSplit.join('.')}`); - for (let idx = 0; idx < searchRoots.length; idx += 1) { - const searchRoot = searchRoots[idx]; + for (let idx = 0; idx < groupIds.length; idx += 1) { + const groupIdLookup = groupIds[idx]; const artifactSubdirs = await getArtifactSubdirs( - searchRoot, + repoRoot, + groupIdLookup, artifact, scalaVersion ); - const versions = await getPackageReleases(searchRoot, artifactSubdirs); + const versions = await getPackageReleases( + repoRoot, + groupIdLookup, + artifactSubdirs + ); const latestVersion = getLatestVersion(versions); - const urls = await getUrls(searchRoot, artifactSubdirs, latestVersion); + const urls = await getUrls( + repoRoot, + groupIdLookup, + artifactSubdirs, + latestVersion + ); - const dependencyUrl = searchRoot; + const dependencyUrl = `${repoRoot}${groupIdLookup}`; if (versions) { return { @@ -175,7 +189,7 @@ export async function getReleases({ } logger.debug( - `No versions found for ${lookupName} in ${searchRoots.length} repositories` + `No versions found for ${lookupName} in ${groupIdSplit.length} repositories` ); return null; } diff --git a/lib/datasource/sbt-plugin/index.ts b/lib/datasource/sbt-plugin/index.ts index 12d6481b176424..1b700750a53e6e 100644 --- a/lib/datasource/sbt-plugin/index.ts +++ b/lib/datasource/sbt-plugin/index.ts @@ -21,10 +21,11 @@ const ensureTrailingSlash = (str: string): string => str.replace(/\/?$/, '/'); async function resolvePluginReleases( rootUrl: string, + groupId: string, artifact: string, scalaVersion: string ): Promise { - const searchRoot = `${rootUrl}/${artifact}`; + const searchRoot = `${rootUrl}${groupId}/${artifact}`; const parse = (content: string): string[] => parseIndexDir(content, (x) => !/^\.+$/.test(x)); const { body: indexContent } = await downloadHttpProtocol( @@ -78,15 +79,16 @@ export async function getReleases({ const [artifact, scalaVersion] = artifactIdSplit; const repoRoot = ensureTrailingSlash(registryUrl); - const searchRoots: string[] = []; + const groupIds: string[] = []; // Optimize lookup order - searchRoots.push(`${repoRoot}${groupIdSplit.join('.')}`); - searchRoots.push(`${repoRoot}${groupIdSplit.join('/')}`); + groupIds.push(`${groupIdSplit.join('/')}`); + groupIds.push(`${groupIdSplit.join('.')}`); - for (let idx = 0; idx < searchRoots.length; idx += 1) { - const searchRoot = searchRoots[idx]; + for (let idx = 0; idx < groupIds.length; idx += 1) { + const groupIdLookup = groupIds[idx]; let versions = await resolvePluginReleases( - searchRoot, + repoRoot, + groupIdLookup, artifact, scalaVersion ); @@ -94,16 +96,26 @@ export async function getReleases({ if (!versions?.length) { const artifactSubdirs = await getArtifactSubdirs( - searchRoot, + repoRoot, + groupIdLookup, artifact, scalaVersion ); - versions = await getPackageReleases(searchRoot, artifactSubdirs); + versions = await getPackageReleases( + repoRoot, + groupIdLookup, + artifactSubdirs + ); const latestVersion = getLatestVersion(versions); - urls = await getUrls(searchRoot, artifactSubdirs, latestVersion); + urls = await getUrls( + repoRoot, + groupIdLookup, + artifactSubdirs, + latestVersion + ); } - const dependencyUrl = `${searchRoot}/${artifact}`; + const dependencyUrl = `${repoRoot}${groupIdLookup}/${artifact}`; if (versions) { return { @@ -115,7 +127,7 @@ export async function getReleases({ } logger.debug( - `No versions found for ${lookupName} in ${searchRoots.length} repositories` + `No versions found for ${lookupName} in ${groupIds.length} repositories` ); return null; } From 8b3f6821194910abd5b9a2f13fb105c8e04c212c Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Mon, 26 Apr 2021 12:18:47 +0300 Subject: [PATCH 2/9] Fix --- lib/datasource/sbt-package/index.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/lib/datasource/sbt-package/index.ts b/lib/datasource/sbt-package/index.ts index a745d4344c66d6..a6b6beeeac50f6 100644 --- a/lib/datasource/sbt-package/index.ts +++ b/lib/datasource/sbt-package/index.ts @@ -2,11 +2,8 @@ import { logger } from '../../logger'; import * as ivyVersioning from '../../versioning/ivy'; import { compare } from '../../versioning/maven/compare'; import { MAVEN_REPO } from '../maven/common'; -import { - MavenDependency, - downloadHttpProtocol, - getDependencyInfo, -} from '../maven/util'; +import type { MavenDependency } from '../maven/types'; +import { downloadHttpProtocol, getDependencyInfo } from '../maven/util'; import { parseIndexDir } from '../sbt-plugin/util'; import type { GetReleasesConfig, ReleaseResult } from '../types'; From fe9dce1dceaf549056f6466c07f8f0c12f4636f1 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Fri, 30 Apr 2021 16:54:04 +0300 Subject: [PATCH 3/9] Use HTTP mocks --- .../meta.xml} | 4 +- .../pom.xml} | 4 +- .../meta.xml} | 4 +- .../pom.xml} | 4 +- .../meta.xml} | 4 +- .../pom.xml} | 0 .../meta.xml} | 4 +- .../pom.xml} | 0 .../child-scm-gitprotocol/meta.xml | 11 + .../pom.xml} | 0 .../maven/__fixtures__/child-scm/meta.xml | 11 + .../pom.xml} | 4 +- .../maven/__fixtures__/child-url/meta.xml | 11 + .../pom.xml} | 4 +- .../meta.xml} | 4 +- .../pom.xml} | 0 .../maven-metadata.xml | 11 - .../maven-metadata.xml | 11 - .../maven-metadata.xml | 11 - .../maven/__snapshots__/index.spec.ts.snap | 251 ++++++++++++++++ lib/datasource/maven/index.spec.ts | 284 ++++++++++-------- 21 files changed, 455 insertions(+), 182 deletions(-) rename lib/datasource/maven/__fixtures__/{parent_repo/com/renovate/child-no-information/maven-metadata.xml => child-all-info/meta.xml} (73%) rename lib/datasource/maven/__fixtures__/{parent_repo/com/renovate/child-all-information/2.0.0/child-all-information-2.0.0.pom => child-all-info/pom.xml} (84%) rename lib/datasource/maven/__fixtures__/{parent_repo/com/renovate/child-scm-information/maven-metadata.xml => child-no-info/meta.xml} (73%) rename lib/datasource/maven/__fixtures__/{parent_repo/com/renovate/child-no-information/2.0.0/child-no-information-2.0.0.pom => child-no-info/pom.xml} (76%) rename lib/datasource/maven/__fixtures__/{parent_repo/com/renovate/child-all-information/maven-metadata.xml => child-scm-gitatcolon/meta.xml} (73%) rename lib/datasource/maven/__fixtures__/{parent_repo/com/renovate/child-scm-gitatcolon-information/2.0.0/child-scm-gitatcolon-information-2.0.0.pom => child-scm-gitatcolon/pom.xml} (100%) rename lib/datasource/maven/__fixtures__/{parent_repo/com/renovate/child-url-information/maven-metadata.xml => child-scm-gitatslash/meta.xml} (73%) rename lib/datasource/maven/__fixtures__/{parent_repo/com/renovate/child-scm-gitatslash-information/2.0.0/child-scm-gitatslash-information-2.0.0.pom => child-scm-gitatslash/pom.xml} (100%) create mode 100644 lib/datasource/maven/__fixtures__/child-scm-gitprotocol/meta.xml rename lib/datasource/maven/__fixtures__/{parent_repo/com/renovate/child-scm-gitprotocol-information/2.0.0/child-scm-gitprotocol-information-2.0.0.pom => child-scm-gitprotocol/pom.xml} (100%) create mode 100644 lib/datasource/maven/__fixtures__/child-scm/meta.xml rename lib/datasource/maven/__fixtures__/{parent_repo/com/renovate/child-scm-information/2.0.0/child-scm-information-2.0.0.pom => child-scm/pom.xml} (83%) create mode 100644 lib/datasource/maven/__fixtures__/child-url/meta.xml rename lib/datasource/maven/__fixtures__/{parent_repo/com/renovate/child-url-information/2.0.0/child-url-information-2.0.0.pom => child-url/pom.xml} (79%) rename lib/datasource/maven/__fixtures__/{parent_repo/com/renovate/parent-scm-homepage/maven-metadata.xml => parent-scm-homepage/meta.xml} (73%) rename lib/datasource/maven/__fixtures__/{parent_repo/com/renovate/parent-scm-homepage/1.0.0/parent-scm-homepage-1.0.0.pom => parent-scm-homepage/pom.xml} (100%) delete mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatcolon-information/maven-metadata.xml delete mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatslash-information/maven-metadata.xml delete mode 100644 lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitprotocol-information/maven-metadata.xml diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-no-information/maven-metadata.xml b/lib/datasource/maven/__fixtures__/child-all-info/meta.xml similarity index 73% rename from lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-no-information/maven-metadata.xml rename to lib/datasource/maven/__fixtures__/child-all-info/meta.xml index 4090d649edb30b..8927f14aa205f0 100644 --- a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-no-information/maven-metadata.xml +++ b/lib/datasource/maven/__fixtures__/child-all-info/meta.xml @@ -1,6 +1,6 @@ - com.renovate - child-no-information + org.example + child-all-info 2.0.0 diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-all-information/2.0.0/child-all-information-2.0.0.pom b/lib/datasource/maven/__fixtures__/child-all-info/pom.xml similarity index 84% rename from lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-all-information/2.0.0/child-all-information-2.0.0.pom rename to lib/datasource/maven/__fixtures__/child-all-info/pom.xml index 28881edb816acf..38a060ce1769f1 100644 --- a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-all-information/2.0.0/child-all-information-2.0.0.pom +++ b/lib/datasource/maven/__fixtures__/child-all-info/pom.xml @@ -1,7 +1,7 @@ - com.renovate - parent-scm-homepage + org.example + parent 1.0.0 diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-information/maven-metadata.xml b/lib/datasource/maven/__fixtures__/child-no-info/meta.xml similarity index 73% rename from lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-information/maven-metadata.xml rename to lib/datasource/maven/__fixtures__/child-no-info/meta.xml index f4d6714d785075..efcaf6091919d5 100644 --- a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-information/maven-metadata.xml +++ b/lib/datasource/maven/__fixtures__/child-no-info/meta.xml @@ -1,6 +1,6 @@ - com.renovate - child-scm-information + org.example + child-no-info 2.0.0 diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-no-information/2.0.0/child-no-information-2.0.0.pom b/lib/datasource/maven/__fixtures__/child-no-info/pom.xml similarity index 76% rename from lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-no-information/2.0.0/child-no-information-2.0.0.pom rename to lib/datasource/maven/__fixtures__/child-no-info/pom.xml index 160296dfde666e..1ec845afb44865 100644 --- a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-no-information/2.0.0/child-no-information-2.0.0.pom +++ b/lib/datasource/maven/__fixtures__/child-no-info/pom.xml @@ -1,7 +1,7 @@ - com.renovate - parent-scm-homepage + org.example + parent 1.0.0 diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-all-information/maven-metadata.xml b/lib/datasource/maven/__fixtures__/child-scm-gitatcolon/meta.xml similarity index 73% rename from lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-all-information/maven-metadata.xml rename to lib/datasource/maven/__fixtures__/child-scm-gitatcolon/meta.xml index 95504355915d1e..f42fe8589746f0 100644 --- a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-all-information/maven-metadata.xml +++ b/lib/datasource/maven/__fixtures__/child-scm-gitatcolon/meta.xml @@ -1,6 +1,6 @@ - com.renovate - child-all-information + org.example + child-scm-gitatcolon 2.0.0 diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatcolon-information/2.0.0/child-scm-gitatcolon-information-2.0.0.pom b/lib/datasource/maven/__fixtures__/child-scm-gitatcolon/pom.xml similarity index 100% rename from lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatcolon-information/2.0.0/child-scm-gitatcolon-information-2.0.0.pom rename to lib/datasource/maven/__fixtures__/child-scm-gitatcolon/pom.xml diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-url-information/maven-metadata.xml b/lib/datasource/maven/__fixtures__/child-scm-gitatslash/meta.xml similarity index 73% rename from lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-url-information/maven-metadata.xml rename to lib/datasource/maven/__fixtures__/child-scm-gitatslash/meta.xml index 120e476b2355c4..07a2b3af129a9e 100644 --- a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-url-information/maven-metadata.xml +++ b/lib/datasource/maven/__fixtures__/child-scm-gitatslash/meta.xml @@ -1,6 +1,6 @@ - com.renovate - child-url-information + org.example + child-scm-gitatslash 2.0.0 diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatslash-information/2.0.0/child-scm-gitatslash-information-2.0.0.pom b/lib/datasource/maven/__fixtures__/child-scm-gitatslash/pom.xml similarity index 100% rename from lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatslash-information/2.0.0/child-scm-gitatslash-information-2.0.0.pom rename to lib/datasource/maven/__fixtures__/child-scm-gitatslash/pom.xml diff --git a/lib/datasource/maven/__fixtures__/child-scm-gitprotocol/meta.xml b/lib/datasource/maven/__fixtures__/child-scm-gitprotocol/meta.xml new file mode 100644 index 00000000000000..1741d3965409af --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-scm-gitprotocol/meta.xml @@ -0,0 +1,11 @@ + + org.example + child-scm-gitprotocol + 2.0.0 + + + 2.0.0 + + 20130301200000 + + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitprotocol-information/2.0.0/child-scm-gitprotocol-information-2.0.0.pom b/lib/datasource/maven/__fixtures__/child-scm-gitprotocol/pom.xml similarity index 100% rename from lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitprotocol-information/2.0.0/child-scm-gitprotocol-information-2.0.0.pom rename to lib/datasource/maven/__fixtures__/child-scm-gitprotocol/pom.xml diff --git a/lib/datasource/maven/__fixtures__/child-scm/meta.xml b/lib/datasource/maven/__fixtures__/child-scm/meta.xml new file mode 100644 index 00000000000000..c0f390f2aee0f1 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-scm/meta.xml @@ -0,0 +1,11 @@ + + org.example + child-scm + 2.0.0 + + + 2.0.0 + + 20130301200000 + + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-information/2.0.0/child-scm-information-2.0.0.pom b/lib/datasource/maven/__fixtures__/child-scm/pom.xml similarity index 83% rename from lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-information/2.0.0/child-scm-information-2.0.0.pom rename to lib/datasource/maven/__fixtures__/child-scm/pom.xml index 76c7da2b944aed..a6cf6fea3a0ff7 100644 --- a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-information/2.0.0/child-scm-information-2.0.0.pom +++ b/lib/datasource/maven/__fixtures__/child-scm/pom.xml @@ -1,7 +1,7 @@ - com.renovate - parent-scm-homepage + org.example + parent 1.0.0 diff --git a/lib/datasource/maven/__fixtures__/child-url/meta.xml b/lib/datasource/maven/__fixtures__/child-url/meta.xml new file mode 100644 index 00000000000000..3fd1398f527e5f --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-url/meta.xml @@ -0,0 +1,11 @@ + + org.example + child-url + 2.0.0 + + + 2.0.0 + + 20130301200000 + + diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-url-information/2.0.0/child-url-information-2.0.0.pom b/lib/datasource/maven/__fixtures__/child-url/pom.xml similarity index 79% rename from lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-url-information/2.0.0/child-url-information-2.0.0.pom rename to lib/datasource/maven/__fixtures__/child-url/pom.xml index 214ff44c3c0392..f153707958a38a 100644 --- a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-url-information/2.0.0/child-url-information-2.0.0.pom +++ b/lib/datasource/maven/__fixtures__/child-url/pom.xml @@ -1,7 +1,7 @@ - com.renovate - parent-scm-homepage + org.example + parent 1.0.0 https://child-home.example.com diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/parent-scm-homepage/maven-metadata.xml b/lib/datasource/maven/__fixtures__/parent-scm-homepage/meta.xml similarity index 73% rename from lib/datasource/maven/__fixtures__/parent_repo/com/renovate/parent-scm-homepage/maven-metadata.xml rename to lib/datasource/maven/__fixtures__/parent-scm-homepage/meta.xml index ff0e190ad1f358..2a44ff77578734 100644 --- a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/parent-scm-homepage/maven-metadata.xml +++ b/lib/datasource/maven/__fixtures__/parent-scm-homepage/meta.xml @@ -1,6 +1,6 @@ - com.renovate - parent-scm-homepage + org.example + parent 1.0.0 diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/parent-scm-homepage/1.0.0/parent-scm-homepage-1.0.0.pom b/lib/datasource/maven/__fixtures__/parent-scm-homepage/pom.xml similarity index 100% rename from lib/datasource/maven/__fixtures__/parent_repo/com/renovate/parent-scm-homepage/1.0.0/parent-scm-homepage-1.0.0.pom rename to lib/datasource/maven/__fixtures__/parent-scm-homepage/pom.xml diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatcolon-information/maven-metadata.xml b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatcolon-information/maven-metadata.xml deleted file mode 100644 index 8a543de22c6fc2..00000000000000 --- a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatcolon-information/maven-metadata.xml +++ /dev/null @@ -1,11 +0,0 @@ - - com.renovate - child-scm-gitatcolon-information - 2.0.0 - - - 2.0.0 - - 20130301200000 - - diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatslash-information/maven-metadata.xml b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatslash-information/maven-metadata.xml deleted file mode 100644 index b9900c494f01dc..00000000000000 --- a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitatslash-information/maven-metadata.xml +++ /dev/null @@ -1,11 +0,0 @@ - - com.renovate - child-scm-gitatslash-information - 2.0.0 - - - 2.0.0 - - 20130301200000 - - diff --git a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitprotocol-information/maven-metadata.xml b/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitprotocol-information/maven-metadata.xml deleted file mode 100644 index 229e38f2678be9..00000000000000 --- a/lib/datasource/maven/__fixtures__/parent_repo/com/renovate/child-scm-gitprotocol-information/maven-metadata.xml +++ /dev/null @@ -1,11 +0,0 @@ - - com.renovate - child-scm-gitprotocol-information - 2.0.0 - - - 2.0.0 - - 20130301200000 - - diff --git a/lib/datasource/maven/__snapshots__/index.spec.ts.snap b/lib/datasource/maven/__snapshots__/index.spec.ts.snap index 8906027ab35a76..d02e3886ea1ff0 100644 --- a/lib/datasource/maven/__snapshots__/index.spec.ts.snap +++ b/lib/datasource/maven/__snapshots__/index.spec.ts.snap @@ -204,6 +204,257 @@ Array [ ] `; +exports[`datasource/maven/index fetching parent info should be able to detect git://@github.com/child-scm as valid sourceUrl 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/package/maven-metadata.xml", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "HEAD", + "url": "https://repo.maven.apache.org/maven2/org/example/package/2.0.0/package-2.0.0.pom", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/package/2.0.0/package-2.0.0.pom", + }, +] +`; + +exports[`datasource/maven/index fetching parent info should be able to detect git@github.com/child-scm as valid sourceUrl 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/package/maven-metadata.xml", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "HEAD", + "url": "https://repo.maven.apache.org/maven2/org/example/package/2.0.0/package-2.0.0.pom", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/package/2.0.0/package-2.0.0.pom", + }, +] +`; + +exports[`datasource/maven/index fetching parent info should be able to detect git@github.com:child-scm as valid sourceUrl 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/package/maven-metadata.xml", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "HEAD", + "url": "https://repo.maven.apache.org/maven2/org/example/package/2.0.0/package-2.0.0.pom", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/package/2.0.0/package-2.0.0.pom", + }, +] +`; + +exports[`datasource/maven/index fetching parent info should get homepage and source from own pom 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/package/maven-metadata.xml", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "HEAD", + "url": "https://repo.maven.apache.org/maven2/org/example/package/2.0.0/package-2.0.0.pom", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/package/2.0.0/package-2.0.0.pom", + }, +] +`; + +exports[`datasource/maven/index fetching parent info should get homepage from own pom and source from parent 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/package/maven-metadata.xml", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "HEAD", + "url": "https://repo.maven.apache.org/maven2/org/example/package/2.0.0/package-2.0.0.pom", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/package/2.0.0/package-2.0.0.pom", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/parent/1.0.0/parent-1.0.0.pom", + }, +] +`; + +exports[`datasource/maven/index fetching parent info should get source and homepage from parent 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/package/maven-metadata.xml", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "HEAD", + "url": "https://repo.maven.apache.org/maven2/org/example/package/2.0.0/package-2.0.0.pom", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/package/2.0.0/package-2.0.0.pom", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/parent/1.0.0/parent-1.0.0.pom", + }, +] +`; + +exports[`datasource/maven/index fetching parent info should get source from own pom and homepage from parent 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/package/maven-metadata.xml", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "HEAD", + "url": "https://repo.maven.apache.org/maven2/org/example/package/2.0.0/package-2.0.0.pom", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/package/2.0.0/package-2.0.0.pom", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/parent/1.0.0/parent-1.0.0.pom", + }, +] +`; + exports[`datasource/maven/index handles optional slash at the end of registry url 1`] = ` Array [ Object { diff --git a/lib/datasource/maven/index.spec.ts b/lib/datasource/maven/index.spec.ts index b256f051b09d06..a57bd3401e65fa 100644 --- a/lib/datasource/maven/index.spec.ts +++ b/lib/datasource/maven/index.spec.ts @@ -14,54 +14,64 @@ const baseUrl = 'https://repo.maven.apache.org/maven2'; const baseUrlCustom = 'https://custom.registry.renovatebot.com'; interface MockOpts { + dep?: string; base?: string; - meta?: string; - pom?: string; - heads?: Record; + meta?: string | null; + pom?: string | null; + latest?: string; + jars?: Record | null; } function mockGenericPackage(opts: MockOpts = {}) { const { + dep = 'org.example:package', base = baseUrl, - meta = loadFixture('metadata.xml'), - pom = loadFixture('pom.xml'), - heads = { - '1.0.0': 200, - '1.0.1': 404, - '1.0.2': 500, - '2.0.0': 200, - }, + latest = '2.0.0', } = opts; + const meta = + opts.meta === undefined ? loadFixture('metadata.xml') : opts.meta; + const pom = opts.pom === undefined ? loadFixture('pom.xml') : opts.pom; + const jars = + opts.jars === undefined + ? { + '1.0.0': 200, + '1.0.1': 404, + '1.0.2': 500, + '2.0.0': 200, + } + : opts.jars; const scope = httpMock.scope(base); - scope.get('/org/example/package/maven-metadata.xml').reply(200, meta); + const [group, artifact] = dep.split(':'); + const packagePath = `${group.replace(/\./g, '/')}/${artifact}`; - if (heads) { - const pairs = Object.entries(heads); - const latest = pairs - .filter(([, s]) => s >= 200 && s < 300) - .map(([v]) => v) - .sort() - .pop(); + if (meta) { + scope.get(`/${packagePath}/maven-metadata.xml`).reply(200, meta); + } + + if (pom) { scope - .get(`/org/example/package/${latest}/package-${latest}.pom`) + .get(`/${packagePath}/${latest}/${artifact}-${latest}.pom`) .reply(200, pom); - pairs.forEach(([version, status]) => { + } + + if (jars) { + Object.entries(jars).forEach(([version, status]) => { const [major, minor, patch] = version .split('.') .map((x) => parseInt(x, 10)) .map((x) => (x < 10 ? `0${x}` : `${x}`)); const timestamp = `2020-01-01T${major}:${minor}:${patch}.000Z`; scope - .head(`/org/example/package/${version}/package-${version}.pom`) + .head(`/${packagePath}/${version}/${artifact}-${version}.pom`) .reply(status, '', { 'Last-Modified': timestamp }); }); } } function get( - depName: string, + depName = 'org.example:package', ...registryUrls: string[] ): Promise { const conf = { versioning, datasource, depName }; @@ -91,7 +101,7 @@ describe(getName(), () => { .get('/org/example/package/maven-metadata.xml') .reply(404); - const res = await get('org.example:package'); + const res = await get(); expect(res).toBeNull(); expect(httpMock.getTrace()).toMatchSnapshot(); @@ -100,7 +110,7 @@ describe(getName(), () => { it('returns releases', async () => { mockGenericPackage(); - const res = await get('org.example:package'); + const res = await get(); expect(res).toMatchSnapshot(); expect(httpMock.getTrace()).toMatchSnapshot(); @@ -120,7 +130,8 @@ describe(getName(), () => { mockGenericPackage({ base: baseUrlCustom, meta: loadFixture('metadata-extra.xml'), - heads: { '3.0.0': 200 }, + latest: '3.0.0', + jars: { '3.0.0': 200 }, }); const { releases } = await get( @@ -175,9 +186,7 @@ describe(getName(), () => { .get('/org/example/package/maven-metadata.xml') .reply(503); - await expect(get('org.example:package')).rejects.toThrow( - EXTERNAL_HOST_ERROR - ); + await expect(get()).rejects.toThrow(EXTERNAL_HOST_ERROR); expect(httpMock.getTrace()).toMatchSnapshot(); }); @@ -255,7 +264,7 @@ describe(getName(), () => { const pom = loadFixture('pom.scm-prefix.xml'); mockGenericPackage({ pom }); - const { sourceUrl } = await get('org.example:package'); + const { sourceUrl } = await get(); expect(sourceUrl).toEqual('https://github.com/example/test'); }); @@ -318,118 +327,131 @@ describe(getName(), () => { expect(fs.readFile.mock.calls).toMatchSnapshot(); }); - it('should get source and homepage from parent', async () => { - expect( - await get( - 'com.renovate:child-no-information', - 'file://lib/datasource/maven/__fixtures__/parent_repo/' - ) - ).toEqual({ - group: 'com.renovate', - name: 'child-no-information', - display: 'com.renovate:child-no-information', - registryUrl: 'file://lib/datasource/maven/__fixtures__/parent_repo/', - releases: [{ version: '2.0.0' }], - sourceUrl: 'https://github.com/parent-scm/parent', - homepage: 'https://parent-home.example.com', + describe('fetching parent info', () => { + const parentPackage = { + dep: 'org.example:parent', + meta: null, + pom: loadFixture('parent-scm-homepage/pom.xml'), + latest: '1.0.0', + jars: null, + }; + + it('should get source and homepage from parent', async () => { + mockGenericPackage({ + meta: loadFixture('child-no-info/meta.xml'), + pom: loadFixture('child-no-info/pom.xml'), + latest: '2.0.0', + jars: { '2.0.0': 200 }, + }); + mockGenericPackage(parentPackage); + + const res = await get(); + + expect(res).toMatchObject({ + sourceUrl: 'https://github.com/parent-scm/parent', + homepage: 'https://parent-home.example.com', + }); + expect(httpMock.getTrace()).toMatchSnapshot(); }); - }); - it('should get source from own pom and homepage from parent', async () => { - expect( - await get( - 'com.renovate:child-scm-information', - 'file://lib/datasource/maven/__fixtures__/parent_repo/' - ) - ).toEqual({ - group: 'com.renovate', - name: 'child-scm-information', - display: 'com.renovate:child-scm-information', - registryUrl: 'file://lib/datasource/maven/__fixtures__/parent_repo/', - releases: [{ version: '2.0.0' }], - sourceUrl: 'https://github.com/child-scm/child', - homepage: 'https://parent-home.example.com', + it('should get source from own pom and homepage from parent', async () => { + mockGenericPackage({ + meta: loadFixture('child-scm/meta.xml'), + pom: loadFixture('child-scm/pom.xml'), + latest: '2.0.0', + jars: { '2.0.0': 200 }, + }); + mockGenericPackage(parentPackage); + + const res = await get(); + + expect(res).toMatchObject({ + sourceUrl: 'https://github.com/child-scm/child', + homepage: 'https://parent-home.example.com', + }); + expect(httpMock.getTrace()).toMatchSnapshot(); }); - }); - it('should get homepage from own pom and source from parent', async () => { - expect( - await get( - 'com.renovate:child-url-information', - 'file://lib/datasource/maven/__fixtures__/parent_repo/' - ) - ).toEqual({ - group: 'com.renovate', - name: 'child-url-information', - display: 'com.renovate:child-url-information', - registryUrl: 'file://lib/datasource/maven/__fixtures__/parent_repo/', - releases: [{ version: '2.0.0' }], - sourceUrl: 'https://github.com/parent-scm/parent', - homepage: 'https://child-home.example.com', + it('should get homepage from own pom and source from parent', async () => { + mockGenericPackage({ + meta: loadFixture('child-url/meta.xml'), + pom: loadFixture('child-url/pom.xml'), + latest: '2.0.0', + jars: { '2.0.0': 200 }, + }); + mockGenericPackage(parentPackage); + + const res = await get(); + + expect(res).toMatchObject({ + sourceUrl: 'https://github.com/parent-scm/parent', + homepage: 'https://child-home.example.com', + }); + expect(httpMock.getTrace()).toMatchSnapshot(); }); - }); - it('should get homepage and source from own pom', async () => { - expect( - await get( - 'com.renovate:child-all-information', - 'file://lib/datasource/maven/__fixtures__/parent_repo/' - ) - ).toEqual({ - group: 'com.renovate', - name: 'child-all-information', - display: 'com.renovate:child-all-information', - registryUrl: 'file://lib/datasource/maven/__fixtures__/parent_repo/', - releases: [{ version: '2.0.0' }], - sourceUrl: 'https://github.com/child-scm/child', - homepage: 'https://child-home.example.com', + it('should get homepage and source from own pom', async () => { + mockGenericPackage({ + meta: loadFixture('child-all-info/meta.xml'), + pom: loadFixture('child-all-info/pom.xml'), + latest: '2.0.0', + jars: { '2.0.0': 200 }, + }); + + const res = await get(); + + expect(res).toMatchObject({ + sourceUrl: 'https://github.com/child-scm/child', + homepage: 'https://child-home.example.com', + }); + expect(httpMock.getTrace()).toMatchSnapshot(); }); - }); - it('should be able to detect git@github.com:child-scm as valid sourceUrl', async () => { - expect( - await get( - 'com.renovate:child-scm-gitatcolon-information', - 'file://lib/datasource/maven/__fixtures__/parent_repo/' - ) - ).toEqual({ - group: 'com.renovate', - name: 'child-scm-gitatcolon-information', - display: 'com.renovate:child-scm-gitatcolon-information', - registryUrl: 'file://lib/datasource/maven/__fixtures__/parent_repo/', - releases: [{ version: '2.0.0' }], - sourceUrl: 'https://github.com/child-scm/child', + it('should be able to detect git@github.com:child-scm as valid sourceUrl', async () => { + mockGenericPackage({ + meta: loadFixture('child-scm-gitatcolon/meta.xml'), + pom: loadFixture('child-scm-gitatcolon/pom.xml'), + latest: '2.0.0', + jars: { '2.0.0': 200 }, + }); + + const res = await get(); + + expect(res).toMatchObject({ + sourceUrl: 'https://github.com/child-scm/child', + }); + expect(httpMock.getTrace()).toMatchSnapshot(); }); - }); - it('should be able to detect git@github.com/child-scm as valid sourceUrl', async () => { - expect( - await get( - 'com.renovate:child-scm-gitatslash-information', - 'file://lib/datasource/maven/__fixtures__/parent_repo/' - ) - ).toEqual({ - group: 'com.renovate', - name: 'child-scm-gitatslash-information', - display: 'com.renovate:child-scm-gitatslash-information', - registryUrl: 'file://lib/datasource/maven/__fixtures__/parent_repo/', - releases: [{ version: '2.0.0' }], - sourceUrl: 'https://github.com/child-scm/child', + it('should be able to detect git@github.com/child-scm as valid sourceUrl', async () => { + mockGenericPackage({ + meta: loadFixture('child-scm-gitatslash/meta.xml'), + pom: loadFixture('child-scm-gitatslash/pom.xml'), + latest: '2.0.0', + jars: { '2.0.0': 200 }, + }); + + const res = await get(); + + expect(res).toMatchObject({ + sourceUrl: 'https://github.com/child-scm/child', + }); + expect(httpMock.getTrace()).toMatchSnapshot(); }); - }); - it('should be able to detect git://@github.com/child-scm as valid sourceUrl', async () => { - expect( - await get( - 'com.renovate:child-scm-gitprotocol-information', - 'file://lib/datasource/maven/__fixtures__/parent_repo/' - ) - ).toEqual({ - group: 'com.renovate', - name: 'child-scm-gitprotocol-information', - display: 'com.renovate:child-scm-gitprotocol-information', - registryUrl: 'file://lib/datasource/maven/__fixtures__/parent_repo/', - releases: [{ version: '2.0.0' }], - sourceUrl: 'https://github.com/child-scm/child', + it('should be able to detect git://@github.com/child-scm as valid sourceUrl', async () => { + mockGenericPackage({ + meta: loadFixture('child-scm-gitprotocol/meta.xml'), + pom: loadFixture('child-scm-gitprotocol/pom.xml'), + latest: '2.0.0', + jars: { '2.0.0': 200 }, + }); + + const res = await get(); + + expect(res).toMatchObject({ + sourceUrl: 'https://github.com/child-scm/child', + }); + expect(httpMock.getTrace()).toMatchSnapshot(); }); }); }); From 14e036a29dab746980f03b6769423c7646d5f49d Mon Sep 17 00:00:00 2001 From: Thorsten Wendelmuth Date: Mon, 3 May 2021 12:20:47 +0200 Subject: [PATCH 4/9] (feat) 6742 reverted sbt implementations to original --- lib/datasource/sbt-package/index.ts | 86 +++++++++++++---------------- lib/datasource/sbt-plugin/index.ts | 36 ++++-------- 2 files changed, 50 insertions(+), 72 deletions(-) diff --git a/lib/datasource/sbt-package/index.ts b/lib/datasource/sbt-package/index.ts index a6b6beeeac50f6..72055a3b1f5350 100644 --- a/lib/datasource/sbt-package/index.ts +++ b/lib/datasource/sbt-package/index.ts @@ -1,3 +1,4 @@ +import { XmlDocument } from 'xmldoc'; import { logger } from '../../logger'; import * as ivyVersioning from '../../versioning/ivy'; import { compare } from '../../versioning/maven/compare'; @@ -16,13 +17,10 @@ export const registryStrategy = 'hunt'; const ensureTrailingSlash = (str: string): string => str.replace(/\/?$/, '/'); export async function getArtifactSubdirs( - registryUrl: string, - groupId: string, + searchRoot: string, artifact: string, scalaVersion: string ): Promise { - const searchRoot = `${registryUrl}${groupId}`; - const { body: indexContent } = await downloadHttpProtocol( ensureTrailingSlash(searchRoot), 'sbt' @@ -55,11 +53,9 @@ export async function getArtifactSubdirs( } export async function getPackageReleases( - registryUrl: string, - groupId: string, + searchRoot: string, artifactSubdirs: string[] ): Promise { - const searchRoot = `${registryUrl}${groupId}`; if (artifactSubdirs) { const releases: string[] = []; const parseReleases = (content: string): string[] => @@ -92,8 +88,7 @@ export function getLatestVersion(versions: string[]): string | null { } export async function getUrls( - repositoryUrl: string, - groupId: string, + searchRoot: string, artifactDirs: string[], version: string ): Promise> { @@ -109,27 +104,32 @@ export async function getUrls( for (const artifactDir of artifactDirs) { const [artifact] = artifactDir.split('_'); - const namesToTry: string[] = []; - namesToTry.push(artifactDir); - namesToTry.push(artifact); - - for (const mavenName of namesToTry) { - const mavenDependency: MavenDependency = { - dependencyUrl: `${repositoryUrl}${groupId}/${artifactDir}`, - display: `${artifactDir}:${artifact}:${version}`, - group: artifactDir, - name: mavenName, - }; + const pomFileNames = [ + `${artifactDir}-${version}.pom`, + `${artifact}-${version}.pom`, + ]; - const dependencyInfo = await getDependencyInfo( - mavenDependency, - repositoryUrl, - version - ); + for (const pomFileName of pomFileNames) { + const pomUrl = `${searchRoot}/${artifactDir}/${version}/${pomFileName}`; + const { body: content } = await downloadHttpProtocol(pomUrl, 'sbt'); + + if (content) { + const pomXml = new XmlDocument(content); + + const homepage = pomXml.valueWithPath('url'); + if (homepage) { + result.homepage = homepage; + } + + const sourceUrl = pomXml.valueWithPath('scm.url'); + if (sourceUrl) { + result.sourceUrl = sourceUrl + .replace(/^scm:/, '') + .replace(/^git:/, '') + .replace(/^git@github.com:/, 'https://github.com/') + .replace(/\.git$/, ''); + } - if (dependencyInfo.homepage || dependencyInfo.sourceUrl) { - result.homepage = dependencyInfo.homepage; - result.sourceUrl = dependencyInfo.sourceUrl; return result; } } @@ -148,33 +148,23 @@ export async function getReleases({ const [artifact, scalaVersion] = artifactIdSplit; const repoRoot = ensureTrailingSlash(registryUrl); - const groupIds: string[] = []; + const searchRoots: string[] = []; // Optimize lookup order - groupIds.push(`${groupIdSplit.join('/')}`); - groupIds.push(`${groupIdSplit.join('.')}`); + searchRoots.push(`${repoRoot}${groupIdSplit.join('/')}`); + searchRoots.push(`${repoRoot}${groupIdSplit.join('.')}`); - for (let idx = 0; idx < groupIds.length; idx += 1) { - const groupIdLookup = groupIds[idx]; + for (let idx = 0; idx < searchRoots.length; idx += 1) { + const searchRoot = searchRoots[idx]; const artifactSubdirs = await getArtifactSubdirs( - repoRoot, - groupIdLookup, + searchRoot, artifact, scalaVersion ); - const versions = await getPackageReleases( - repoRoot, - groupIdLookup, - artifactSubdirs - ); + const versions = await getPackageReleases(searchRoot, artifactSubdirs); const latestVersion = getLatestVersion(versions); - const urls = await getUrls( - repoRoot, - groupIdLookup, - artifactSubdirs, - latestVersion - ); + const urls = await getUrls(searchRoot, artifactSubdirs, latestVersion); - const dependencyUrl = `${repoRoot}${groupIdLookup}`; + const dependencyUrl = searchRoot; if (versions) { return { @@ -186,7 +176,7 @@ export async function getReleases({ } logger.debug( - `No versions found for ${lookupName} in ${groupIdSplit.length} repositories` + `No versions found for ${lookupName} in ${searchRoots.length} repositories` ); return null; } diff --git a/lib/datasource/sbt-plugin/index.ts b/lib/datasource/sbt-plugin/index.ts index 1b700750a53e6e..12d6481b176424 100644 --- a/lib/datasource/sbt-plugin/index.ts +++ b/lib/datasource/sbt-plugin/index.ts @@ -21,11 +21,10 @@ const ensureTrailingSlash = (str: string): string => str.replace(/\/?$/, '/'); async function resolvePluginReleases( rootUrl: string, - groupId: string, artifact: string, scalaVersion: string ): Promise { - const searchRoot = `${rootUrl}${groupId}/${artifact}`; + const searchRoot = `${rootUrl}/${artifact}`; const parse = (content: string): string[] => parseIndexDir(content, (x) => !/^\.+$/.test(x)); const { body: indexContent } = await downloadHttpProtocol( @@ -79,16 +78,15 @@ export async function getReleases({ const [artifact, scalaVersion] = artifactIdSplit; const repoRoot = ensureTrailingSlash(registryUrl); - const groupIds: string[] = []; + const searchRoots: string[] = []; // Optimize lookup order - groupIds.push(`${groupIdSplit.join('/')}`); - groupIds.push(`${groupIdSplit.join('.')}`); + searchRoots.push(`${repoRoot}${groupIdSplit.join('.')}`); + searchRoots.push(`${repoRoot}${groupIdSplit.join('/')}`); - for (let idx = 0; idx < groupIds.length; idx += 1) { - const groupIdLookup = groupIds[idx]; + for (let idx = 0; idx < searchRoots.length; idx += 1) { + const searchRoot = searchRoots[idx]; let versions = await resolvePluginReleases( - repoRoot, - groupIdLookup, + searchRoot, artifact, scalaVersion ); @@ -96,26 +94,16 @@ export async function getReleases({ if (!versions?.length) { const artifactSubdirs = await getArtifactSubdirs( - repoRoot, - groupIdLookup, + searchRoot, artifact, scalaVersion ); - versions = await getPackageReleases( - repoRoot, - groupIdLookup, - artifactSubdirs - ); + versions = await getPackageReleases(searchRoot, artifactSubdirs); const latestVersion = getLatestVersion(versions); - urls = await getUrls( - repoRoot, - groupIdLookup, - artifactSubdirs, - latestVersion - ); + urls = await getUrls(searchRoot, artifactSubdirs, latestVersion); } - const dependencyUrl = `${repoRoot}${groupIdLookup}/${artifact}`; + const dependencyUrl = `${searchRoot}/${artifact}`; if (versions) { return { @@ -127,7 +115,7 @@ export async function getReleases({ } logger.debug( - `No versions found for ${lookupName} in ${groupIds.length} repositories` + `No versions found for ${lookupName} in ${searchRoots.length} repositories` ); return null; } From bb71dc0d910927bc6e534082024adeb36546352e Mon Sep 17 00:00:00 2001 From: Thorsten Wendelmuth Date: Mon, 3 May 2021 12:44:16 +0200 Subject: [PATCH 5/9] (feat) 6742 also reverted imports that we are not using right now --- lib/datasource/sbt-package/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/datasource/sbt-package/index.ts b/lib/datasource/sbt-package/index.ts index 72055a3b1f5350..c1e5b154d7c134 100644 --- a/lib/datasource/sbt-package/index.ts +++ b/lib/datasource/sbt-package/index.ts @@ -3,8 +3,7 @@ import { logger } from '../../logger'; import * as ivyVersioning from '../../versioning/ivy'; import { compare } from '../../versioning/maven/compare'; import { MAVEN_REPO } from '../maven/common'; -import type { MavenDependency } from '../maven/types'; -import { downloadHttpProtocol, getDependencyInfo } from '../maven/util'; +import { downloadHttpProtocol } from '../maven/util'; import { parseIndexDir } from '../sbt-plugin/util'; import type { GetReleasesConfig, ReleaseResult } from '../types'; From 6ea8020b125e9d5ad1f796538c66e38c1238d5ee Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Tue, 4 May 2021 11:05:35 +0300 Subject: [PATCH 6/9] Add recursion depth limit --- .../child-parent-cycle/child.meta.xml | 11 +++++ .../child-parent-cycle/child.pom.xml | 17 ++++++++ .../child-parent-cycle/parent.pom.xml | 8 ++++ .../maven/__snapshots__/index.spec.ts.snap | 41 +++++++++++++++++++ lib/datasource/maven/index.spec.ts | 39 ++++++++++++++++++ lib/datasource/maven/util.ts | 8 ++-- 6 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 lib/datasource/maven/__fixtures__/child-parent-cycle/child.meta.xml create mode 100644 lib/datasource/maven/__fixtures__/child-parent-cycle/child.pom.xml create mode 100644 lib/datasource/maven/__fixtures__/child-parent-cycle/parent.pom.xml diff --git a/lib/datasource/maven/__fixtures__/child-parent-cycle/child.meta.xml b/lib/datasource/maven/__fixtures__/child-parent-cycle/child.meta.xml new file mode 100644 index 00000000000000..07848472aec2ec --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-parent-cycle/child.meta.xml @@ -0,0 +1,11 @@ + + org.example + package + 2.0.0 + + + 2.0.0 + + 20130301200000 + + diff --git a/lib/datasource/maven/__fixtures__/child-parent-cycle/child.pom.xml b/lib/datasource/maven/__fixtures__/child-parent-cycle/child.pom.xml new file mode 100644 index 00000000000000..6e3c7456bae805 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-parent-cycle/child.pom.xml @@ -0,0 +1,17 @@ + + + + + org.example + parent + 2.0.0 + + org.example + child + Generic Package + Generic Maven Package + diff --git a/lib/datasource/maven/__fixtures__/child-parent-cycle/parent.pom.xml b/lib/datasource/maven/__fixtures__/child-parent-cycle/parent.pom.xml new file mode 100644 index 00000000000000..2760a1dd818d77 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-parent-cycle/parent.pom.xml @@ -0,0 +1,8 @@ + + + org.example + child + 2.0.0 + + https://parent-home.example.com + diff --git a/lib/datasource/maven/__snapshots__/index.spec.ts.snap b/lib/datasource/maven/__snapshots__/index.spec.ts.snap index 380afd166318b2..ed20ca24d9c00e 100644 --- a/lib/datasource/maven/__snapshots__/index.spec.ts.snap +++ b/lib/datasource/maven/__snapshots__/index.spec.ts.snap @@ -300,6 +300,47 @@ Array [ ] `; +exports[`datasource/maven/index fetching parent info should deal with circular hierarchy 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/child/maven-metadata.xml", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "HEAD", + "url": "https://repo.maven.apache.org/maven2/org/example/child/2.0.0/child-2.0.0.pom", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/child/2.0.0/child-2.0.0.pom", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/parent/2.0.0/parent-2.0.0.pom", + }, +] +`; + exports[`datasource/maven/index fetching parent info should get homepage and source from own pom 1`] = ` Array [ Object { diff --git a/lib/datasource/maven/index.spec.ts b/lib/datasource/maven/index.spec.ts index a57bd3401e65fa..6adf73cbdf169f 100644 --- a/lib/datasource/maven/index.spec.ts +++ b/lib/datasource/maven/index.spec.ts @@ -354,6 +354,45 @@ describe(getName(), () => { expect(httpMock.getTrace()).toMatchSnapshot(); }); + it('should deal with circular hierarchy', async () => { + const parentPom = loadFixture('child-parent-cycle/parent.pom.xml'); + const parentPomMock = { + dep: 'org.example:parent', + meta: null, + pom: parentPom, + latest: '2.0.0', + jars: null, + }; + + const childMeta = loadFixture('child-parent-cycle/child.meta.xml'); + const childPom = loadFixture('child-parent-cycle/child.pom.xml'); + const childPomMock = { + dep: 'org.example:child', + meta: null, + pom: childPom, + latest: '2.0.0', + jars: null, + }; + + mockGenericPackage({ + ...childPomMock, + meta: childMeta, + jars: { '2.0.0': 200 }, + }); + mockGenericPackage(parentPomMock); + mockGenericPackage(childPomMock); + mockGenericPackage(parentPomMock); + mockGenericPackage(childPomMock); + mockGenericPackage(parentPomMock); + + const res = await get('org.example:child'); + + expect(res).toMatchObject({ + homepage: 'https://parent-home.example.com', + }); + expect(httpMock.getTrace()).toMatchSnapshot(); + }); + it('should get source from own pom and homepage from parent', async () => { mockGenericPackage({ meta: loadFixture('child-scm/meta.xml'), diff --git a/lib/datasource/maven/util.ts b/lib/datasource/maven/util.ts index 2f4485ca03125d..b32e8df0272719 100644 --- a/lib/datasource/maven/util.ts +++ b/lib/datasource/maven/util.ts @@ -189,7 +189,8 @@ export function getDependencyParts(lookupName: string): MavenDependency { export async function getDependencyInfo( dependency: MavenDependency, repoUrl: string, - version: string + version: string, + recursionLimit = 5 ): Promise> { const result: Partial = {}; const path = `${version}/${dependency.name}-${version}.pom`; @@ -223,7 +224,7 @@ export async function getDependencyInfo( } const parent = pomContent.childNamed('parent'); - if (parent && (!result.sourceUrl || !result.homepage)) { + if (recursionLimit > 0 && parent && (!result.sourceUrl || !result.homepage)) { // if we found a parent and are missing some information // trying to get the scm/homepage information from it const parentGroupId = parent.valueWithPath('groupId').replace(/\s/g, ''); @@ -235,7 +236,8 @@ export async function getDependencyInfo( const parentInformation = await getDependencyInfo( parentDependency, repoUrl, - parentVersion + parentVersion, + recursionLimit - 1 ); if (!result.sourceUrl && parentInformation.sourceUrl) { result.sourceUrl = parentInformation.sourceUrl; From 3d54176413e26aad38210385589fadd3bb4f9001 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Tue, 4 May 2021 11:09:57 +0300 Subject: [PATCH 7/9] Fix snapshot --- .../maven/__snapshots__/index.spec.ts.snap | 36 +++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/lib/datasource/maven/__snapshots__/index.spec.ts.snap b/lib/datasource/maven/__snapshots__/index.spec.ts.snap index ed20ca24d9c00e..784feca10c90f0 100644 --- a/lib/datasource/maven/__snapshots__/index.spec.ts.snap +++ b/lib/datasource/maven/__snapshots__/index.spec.ts.snap @@ -338,6 +338,42 @@ Array [ "method": "GET", "url": "https://repo.maven.apache.org/maven2/org/example/parent/2.0.0/parent-2.0.0.pom", }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/child/2.0.0/child-2.0.0.pom", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/parent/2.0.0/parent-2.0.0.pom", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/child/2.0.0/child-2.0.0.pom", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/parent/2.0.0/parent-2.0.0.pom", + }, ] `; From d257e11a9f4eb359d6dc6f253b7134ee2b22e529 Mon Sep 17 00:00:00 2001 From: Sergei Zharinov Date: Thu, 27 May 2021 11:11:01 +0300 Subject: [PATCH 8/9] Handle empty fields --- .../maven/__fixtures__/child-empty/meta.xml | 11 ++++++ .../maven/__fixtures__/child-empty/pom.xml | 4 ++ .../maven/__snapshots__/index.spec.ts.snap | 32 ++++++++++++++++ lib/datasource/maven/index.spec.ts | 20 ++++++++++ lib/datasource/maven/util.ts | 37 ++++++++++--------- 5 files changed, 87 insertions(+), 17 deletions(-) create mode 100644 lib/datasource/maven/__fixtures__/child-empty/meta.xml create mode 100644 lib/datasource/maven/__fixtures__/child-empty/pom.xml diff --git a/lib/datasource/maven/__fixtures__/child-empty/meta.xml b/lib/datasource/maven/__fixtures__/child-empty/meta.xml new file mode 100644 index 00000000000000..efcaf6091919d5 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-empty/meta.xml @@ -0,0 +1,11 @@ + + org.example + child-no-info + 2.0.0 + + + 2.0.0 + + 20130301200000 + + diff --git a/lib/datasource/maven/__fixtures__/child-empty/pom.xml b/lib/datasource/maven/__fixtures__/child-empty/pom.xml new file mode 100644 index 00000000000000..b3f546cac09a4e --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-empty/pom.xml @@ -0,0 +1,4 @@ + + + + diff --git a/lib/datasource/maven/__snapshots__/index.spec.ts.snap b/lib/datasource/maven/__snapshots__/index.spec.ts.snap index 784feca10c90f0..0ad97a19158aba 100644 --- a/lib/datasource/maven/__snapshots__/index.spec.ts.snap +++ b/lib/datasource/maven/__snapshots__/index.spec.ts.snap @@ -377,6 +377,38 @@ Array [ ] `; +exports[`datasource/maven/index fetching parent info should deal with missing parent fields 1`] = ` +Array [ + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/package/maven-metadata.xml", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "HEAD", + "url": "https://repo.maven.apache.org/maven2/org/example/package/2.0.0/package-2.0.0.pom", + }, + Object { + "headers": Object { + "accept-encoding": "gzip, deflate, br", + "host": "repo.maven.apache.org", + "user-agent": "https://github.com/renovatebot/renovate", + }, + "method": "GET", + "url": "https://repo.maven.apache.org/maven2/org/example/package/2.0.0/package-2.0.0.pom", + }, +] +`; + exports[`datasource/maven/index fetching parent info should get homepage and source from own pom 1`] = ` Array [ Object { diff --git a/lib/datasource/maven/index.spec.ts b/lib/datasource/maven/index.spec.ts index 6adf73cbdf169f..891b934cdbf766 100644 --- a/lib/datasource/maven/index.spec.ts +++ b/lib/datasource/maven/index.spec.ts @@ -354,6 +354,26 @@ describe(getName(), () => { expect(httpMock.getTrace()).toMatchSnapshot(); }); + it('should deal with missing parent fields', async () => { + mockGenericPackage({ + meta: loadFixture('child-empty/meta.xml'), + pom: loadFixture('child-empty/pom.xml'), + latest: '2.0.0', + jars: { '2.0.0': 200 }, + }); + + const res = await get(); + + expect(res).toMatchObject({ + display: 'org.example:package', + group: 'org.example', + name: 'package', + }); + expect(res).not.toHaveProperty('homepage'); + expect(res).not.toHaveProperty('sourceUrl'); + expect(httpMock.getTrace()).toMatchSnapshot(); + }); + it('should deal with circular hierarchy', async () => { const parentPom = loadFixture('child-parent-cycle/parent.pom.xml'); const parentPomMock = { diff --git a/lib/datasource/maven/util.ts b/lib/datasource/maven/util.ts index b32e8df0272719..2e8c96c8c4144a 100644 --- a/lib/datasource/maven/util.ts +++ b/lib/datasource/maven/util.ts @@ -227,23 +227,26 @@ export async function getDependencyInfo( if (recursionLimit > 0 && parent && (!result.sourceUrl || !result.homepage)) { // if we found a parent and are missing some information // trying to get the scm/homepage information from it - const parentGroupId = parent.valueWithPath('groupId').replace(/\s/g, ''); - const parentArtifactId = parent.valueWithPath('artifactId').replace(/\s/g, ''); // prettier-ignore - const parentVersion = parent.valueWithPath('version').replace(/\s/g, ''); - const parentDisplayId = `${parentGroupId}:${parentArtifactId}`; - const parentDependency = getDependencyParts(parentDisplayId); - - const parentInformation = await getDependencyInfo( - parentDependency, - repoUrl, - parentVersion, - recursionLimit - 1 - ); - if (!result.sourceUrl && parentInformation.sourceUrl) { - result.sourceUrl = parentInformation.sourceUrl; - } - if (!result.homepage && parentInformation.homepage) { - result.homepage = parentInformation.homepage; + const [parentGroupId, parentArtifactId, parentVersion] = [ + 'groupId', + 'artifactId', + 'version', + ].map((k) => parent.valueWithPath(k)?.replace(/\s+/g, '')); + if (parentGroupId && parentArtifactId && parentVersion) { + const parentDisplayId = `${parentGroupId}:${parentArtifactId}`; + const parentDependency = getDependencyParts(parentDisplayId); + const parentInformation = await getDependencyInfo( + parentDependency, + repoUrl, + parentVersion, + recursionLimit - 1 + ); + if (!result.sourceUrl && parentInformation.sourceUrl) { + result.sourceUrl = parentInformation.sourceUrl; + } + if (!result.homepage && parentInformation.homepage) { + result.homepage = parentInformation.homepage; + } } } From 47901c539529d2b419239be955c67ec65a7565f1 Mon Sep 17 00:00:00 2001 From: "thorsten.wendelmuth" Date: Fri, 18 Jun 2021 10:55:14 +0200 Subject: [PATCH 9/9] fixed wrongly resolved conflict --- lib/datasource/maven/index.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/datasource/maven/index.spec.ts b/lib/datasource/maven/index.spec.ts index 3c48e4c8a8632f..e610a5cc68d35d 100644 --- a/lib/datasource/maven/index.spec.ts +++ b/lib/datasource/maven/index.spec.ts @@ -1,5 +1,6 @@ import { ReleaseResult, getPkgReleases } from '..'; import * as httpMock from '../../../test/http-mock'; +import { getName, loadFixture } from '../../../test/util'; import { EXTERNAL_HOST_ERROR } from '../../constants/error-messages'; import * as hostRules from '../../util/host-rules'; import { id as versioning } from '../../versioning/maven';