From 7fd1e2f9ce95ff005b011682d0c0c1134d4814ce Mon Sep 17 00:00:00 2001 From: Thorsten Wendelmuth <thorsten.wendelmuth@gmx.de> Date: Fri, 25 Jun 2021 14:39:28 +0200 Subject: [PATCH] feat(maven): lookup parent homepage/scm information from pom (#9722) --- .../__fixtures__/child-all-info/meta.xml | 11 + .../maven/__fixtures__/child-all-info/pom.xml | 12 + .../maven/__fixtures__/child-empty/meta.xml | 11 + .../maven/__fixtures__/child-empty/pom.xml | 4 + .../maven/__fixtures__/child-no-info/meta.xml | 11 + .../maven/__fixtures__/child-no-info/pom.xml | 7 + .../child-parent-cycle/child.meta.xml | 11 + .../child-parent-cycle/child.pom.xml | 17 + .../child-parent-cycle/parent.pom.xml | 8 + .../child-scm-gitatcolon/meta.xml | 11 + .../__fixtures__/child-scm-gitatcolon/pom.xml | 6 + .../child-scm-gitatslash/meta.xml | 11 + .../__fixtures__/child-scm-gitatslash/pom.xml | 6 + .../child-scm-gitprotocol/meta.xml | 11 + .../child-scm-gitprotocol/pom.xml | 6 + .../maven/__fixtures__/child-scm/meta.xml | 11 + .../maven/__fixtures__/child-scm/pom.xml | 11 + .../maven/__fixtures__/child-url/meta.xml | 11 + .../maven/__fixtures__/child-url/pom.xml | 8 + .../__fixtures__/parent-scm-homepage/meta.xml | 11 + .../__fixtures__/parent-scm-homepage/pom.xml | 7 + .../maven/__snapshots__/index.spec.ts.snap | 360 ++++++++++++++++++ lib/datasource/maven/index.spec.ts | 187 +++++++++ lib/datasource/maven/util.ts | 65 +++- 24 files changed, 801 insertions(+), 13 deletions(-) create mode 100644 lib/datasource/maven/__fixtures__/child-all-info/meta.xml create mode 100644 lib/datasource/maven/__fixtures__/child-all-info/pom.xml create mode 100644 lib/datasource/maven/__fixtures__/child-empty/meta.xml create mode 100644 lib/datasource/maven/__fixtures__/child-empty/pom.xml create mode 100644 lib/datasource/maven/__fixtures__/child-no-info/meta.xml create mode 100644 lib/datasource/maven/__fixtures__/child-no-info/pom.xml 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 create mode 100644 lib/datasource/maven/__fixtures__/child-scm-gitatcolon/meta.xml create mode 100644 lib/datasource/maven/__fixtures__/child-scm-gitatcolon/pom.xml create mode 100644 lib/datasource/maven/__fixtures__/child-scm-gitatslash/meta.xml create mode 100644 lib/datasource/maven/__fixtures__/child-scm-gitatslash/pom.xml create mode 100644 lib/datasource/maven/__fixtures__/child-scm-gitprotocol/meta.xml create mode 100644 lib/datasource/maven/__fixtures__/child-scm-gitprotocol/pom.xml create mode 100644 lib/datasource/maven/__fixtures__/child-scm/meta.xml create mode 100644 lib/datasource/maven/__fixtures__/child-scm/pom.xml create mode 100644 lib/datasource/maven/__fixtures__/child-url/meta.xml create mode 100644 lib/datasource/maven/__fixtures__/child-url/pom.xml create mode 100644 lib/datasource/maven/__fixtures__/parent-scm-homepage/meta.xml create mode 100644 lib/datasource/maven/__fixtures__/parent-scm-homepage/pom.xml diff --git a/lib/datasource/maven/__fixtures__/child-all-info/meta.xml b/lib/datasource/maven/__fixtures__/child-all-info/meta.xml new file mode 100644 index 0000000000..8927f14aa2 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-all-info/meta.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?><metadata> + <groupId>org.example</groupId> + <artifactId>child-all-info</artifactId> + <version>2.0.0</version> + <versioning> + <versions> + <version>2.0.0</version> + </versions> + <lastUpdated>20130301200000</lastUpdated> + </versioning> +</metadata> diff --git a/lib/datasource/maven/__fixtures__/child-all-info/pom.xml b/lib/datasource/maven/__fixtures__/child-all-info/pom.xml new file mode 100644 index 0000000000..38a060ce17 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-all-info/pom.xml @@ -0,0 +1,12 @@ +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <groupId>org.example</groupId> + <artifactId>parent</artifactId> + <version>1.0.0</version> + </parent> + <scm> + <!-- example taken from https://maven.apache.org/scm/git.html --> + <url>scm:git:http://www.github.com/child-scm/child</url> + </scm> + <url>https://child-home.example.com</url> +</project> 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 0000000000..efcaf60919 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-empty/meta.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?><metadata> + <groupId>org.example</groupId> + <artifactId>child-no-info</artifactId> + <version>2.0.0</version> + <versioning> + <versions> + <version>2.0.0</version> + </versions> + <lastUpdated>20130301200000</lastUpdated> + </versioning> +</metadata> 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 0000000000..b3f546cac0 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-empty/pom.xml @@ -0,0 +1,4 @@ +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + </parent> +</project> diff --git a/lib/datasource/maven/__fixtures__/child-no-info/meta.xml b/lib/datasource/maven/__fixtures__/child-no-info/meta.xml new file mode 100644 index 0000000000..efcaf60919 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-no-info/meta.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?><metadata> + <groupId>org.example</groupId> + <artifactId>child-no-info</artifactId> + <version>2.0.0</version> + <versioning> + <versions> + <version>2.0.0</version> + </versions> + <lastUpdated>20130301200000</lastUpdated> + </versioning> +</metadata> diff --git a/lib/datasource/maven/__fixtures__/child-no-info/pom.xml b/lib/datasource/maven/__fixtures__/child-no-info/pom.xml new file mode 100644 index 0000000000..1ec845afb4 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-no-info/pom.xml @@ -0,0 +1,7 @@ +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <groupId>org.example</groupId> + <artifactId>parent</artifactId> + <version>1.0.0</version> + </parent> +</project> 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 0000000000..07848472ae --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-parent-cycle/child.meta.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?><metadata> + <groupId>org.example</groupId> + <artifactId>package</artifactId> + <version>2.0.0</version> + <versioning> + <versions> + <version>2.0.0</version> + </versions> + <lastUpdated>20130301200000</lastUpdated> + </versioning> +</metadata> 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 0000000000..6e3c7456ba --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-parent-cycle/child.pom.xml @@ -0,0 +1,17 @@ + +<!-- + License +--> +<project xmlns="http://maven.apache.org/POM/4.0.0" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <groupId>org.example</groupId> + <artifactId>parent</artifactId> + <version>2.0.0</version> + </parent> + <groupId>org.example</groupId> + <artifactId>child</artifactId> + <name>Generic Package</name> + <description>Generic Maven Package</description> +</project> 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 0000000000..2760a1dd81 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-parent-cycle/parent.pom.xml @@ -0,0 +1,8 @@ +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <groupId>org.example</groupId> + <artifactId>child</artifactId> + <version>2.0.0</version> + </parent> + <url>https://parent-home.example.com</url> +</project> diff --git a/lib/datasource/maven/__fixtures__/child-scm-gitatcolon/meta.xml b/lib/datasource/maven/__fixtures__/child-scm-gitatcolon/meta.xml new file mode 100644 index 0000000000..f42fe85897 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-scm-gitatcolon/meta.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?><metadata> + <groupId>org.example</groupId> + <artifactId>child-scm-gitatcolon</artifactId> + <version>2.0.0</version> + <versioning> + <versions> + <version>2.0.0</version> + </versions> + <lastUpdated>20130301200000</lastUpdated> + </versioning> +</metadata> diff --git a/lib/datasource/maven/__fixtures__/child-scm-gitatcolon/pom.xml b/lib/datasource/maven/__fixtures__/child-scm-gitatcolon/pom.xml new file mode 100644 index 0000000000..7c3157b5c4 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-scm-gitatcolon/pom.xml @@ -0,0 +1,6 @@ +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <scm> + <!-- as seen in https://repo.maven.apache.org/maven2/org/freemarker/freemarker/2.3.20/freemarker-2.3.20.pom --> + <url>git@github.com:child-scm/child</url> + </scm> +</project> diff --git a/lib/datasource/maven/__fixtures__/child-scm-gitatslash/meta.xml b/lib/datasource/maven/__fixtures__/child-scm-gitatslash/meta.xml new file mode 100644 index 0000000000..07a2b3af12 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-scm-gitatslash/meta.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?><metadata> + <groupId>org.example</groupId> + <artifactId>child-scm-gitatslash</artifactId> + <version>2.0.0</version> + <versioning> + <versions> + <version>2.0.0</version> + </versions> + <lastUpdated>20130301200000</lastUpdated> + </versioning> +</metadata> diff --git a/lib/datasource/maven/__fixtures__/child-scm-gitatslash/pom.xml b/lib/datasource/maven/__fixtures__/child-scm-gitatslash/pom.xml new file mode 100644 index 0000000000..2ad57eaa1f --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-scm-gitatslash/pom.xml @@ -0,0 +1,6 @@ +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <scm> + <!-- as seen in https://repo.maven.apache.org/maven2/ro/nextreports/nextreports-engine/9.2/nextreports-engine-9.2.pom --> + <url>git@github.com/child-scm/child</url> + </scm> +</project> 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 0000000000..1741d39654 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-scm-gitprotocol/meta.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?><metadata> + <groupId>org.example</groupId> + <artifactId>child-scm-gitprotocol</artifactId> + <version>2.0.0</version> + <versioning> + <versions> + <version>2.0.0</version> + </versions> + <lastUpdated>20130301200000</lastUpdated> + </versioning> +</metadata> diff --git a/lib/datasource/maven/__fixtures__/child-scm-gitprotocol/pom.xml b/lib/datasource/maven/__fixtures__/child-scm-gitprotocol/pom.xml new file mode 100644 index 0000000000..da09dda8a9 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-scm-gitprotocol/pom.xml @@ -0,0 +1,6 @@ +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <scm> + <!-- as seen in https://repo.maven.apache.org/maven2/org/xhtmlrenderer/flying-saucer-parent/9.1.9/flying-saucer-parent-9.1.9.pom --> + <url>git://github.com/child-scm/child</url> + </scm> +</project> 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 0000000000..c0f390f2ae --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-scm/meta.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?><metadata> + <groupId>org.example</groupId> + <artifactId>child-scm</artifactId> + <version>2.0.0</version> + <versioning> + <versions> + <version>2.0.0</version> + </versions> + <lastUpdated>20130301200000</lastUpdated> + </versioning> +</metadata> diff --git a/lib/datasource/maven/__fixtures__/child-scm/pom.xml b/lib/datasource/maven/__fixtures__/child-scm/pom.xml new file mode 100644 index 0000000000..a6cf6fea3a --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-scm/pom.xml @@ -0,0 +1,11 @@ +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <groupId>org.example</groupId> + <artifactId>parent</artifactId> + <version>1.0.0</version> + </parent> + <scm> + <!-- example taken from https://maven.apache.org/scm/git.html --> + <url>scm:git:https://www.github.com/child-scm/child</url> + </scm> +</project> 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 0000000000..3fd1398f52 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-url/meta.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?><metadata> + <groupId>org.example</groupId> + <artifactId>child-url</artifactId> + <version>2.0.0</version> + <versioning> + <versions> + <version>2.0.0</version> + </versions> + <lastUpdated>20130301200000</lastUpdated> + </versioning> +</metadata> diff --git a/lib/datasource/maven/__fixtures__/child-url/pom.xml b/lib/datasource/maven/__fixtures__/child-url/pom.xml new file mode 100644 index 0000000000..f153707958 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/child-url/pom.xml @@ -0,0 +1,8 @@ +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <parent> + <groupId>org.example</groupId> + <artifactId>parent</artifactId> + <version>1.0.0</version> + </parent> + <url>https://child-home.example.com</url> +</project> diff --git a/lib/datasource/maven/__fixtures__/parent-scm-homepage/meta.xml b/lib/datasource/maven/__fixtures__/parent-scm-homepage/meta.xml new file mode 100644 index 0000000000..2a44ff7757 --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent-scm-homepage/meta.xml @@ -0,0 +1,11 @@ +<?xml version="1.0" encoding="UTF-8"?><metadata> + <groupId>org.example</groupId> + <artifactId>parent</artifactId> + <version>1.0.0</version> + <versioning> + <versions> + <version>1.0.0</version> + </versions> + <lastUpdated>20130301200000</lastUpdated> + </versioning> +</metadata> diff --git a/lib/datasource/maven/__fixtures__/parent-scm-homepage/pom.xml b/lib/datasource/maven/__fixtures__/parent-scm-homepage/pom.xml new file mode 100644 index 0000000000..18357e50fb --- /dev/null +++ b/lib/datasource/maven/__fixtures__/parent-scm-homepage/pom.xml @@ -0,0 +1,7 @@ +<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> + <scm> + <!-- example taken from https://maven.apache.org/scm/git.html --> + <url>scm:git:git://www.github.com/parent-scm/parent</url> + </scm> + <url>https://parent-home.example.com</url> +</project> diff --git a/lib/datasource/maven/__snapshots__/index.spec.ts.snap b/lib/datasource/maven/__snapshots__/index.spec.ts.snap index aba4930ded..f401e28a77 100644 --- a/lib/datasource/maven/__snapshots__/index.spec.ts.snap +++ b/lib/datasource/maven/__snapshots__/index.spec.ts.snap @@ -204,6 +204,366 @@ 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 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", + }, + 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", + }, +] +`; + +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 { + "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 4c9c719fcb..e610a5cc68 100644 --- a/lib/datasource/maven/index.spec.ts +++ b/lib/datasource/maven/index.spec.ts @@ -305,4 +305,191 @@ describe(getName(), () => { expect(res).toMatchSnapshot(); expect(httpMock.getTrace()).toMatchSnapshot(); }); + + 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 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 = { + 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'), + 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 () => { + 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 () => { + 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 () => { + 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 () => { + 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 () => { + 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(); + }); + }); }); diff --git a/lib/datasource/maven/util.ts b/lib/datasource/maven/util.ts index ed7f7355ce..18316d73df 100644 --- a/lib/datasource/maven/util.ts +++ b/lib/datasource/maven/util.ts @@ -163,10 +163,22 @@ export async function downloadMavenXml( return { authorization, xml: new XmlDocument(rawContent) }; } +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 + version: string, + recursionLimit = 5 ): Promise<Partial<ReleaseResult>> { const result: Partial<ReleaseResult> = {}; const path = `${version}/${dependency.name}-${version}.pom`; @@ -185,19 +197,46 @@ export async function getDependencyInfo( const sourceUrl = pomContent.valueWithPath('scm.url'); if (sourceUrl && !containsPlaceholder(sourceUrl)) { - result.sourceUrl = sourceUrl.replace(/^scm:/, ''); + 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}`; + } } - return result; -} + const parent = pomContent.childNamed('parent'); + 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, 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; + } + } + } -export function getDependencyParts(lookupName: string): MavenDependency { - const [group, name] = lookupName.split(':'); - const dependencyUrl = `${group.replace(/\./g, '/')}/${name}`; - return { - display: lookupName, - group, - name, - dependencyUrl, - }; + return result; } -- GitLab