From 279f632b2680c50d94cc1c73707b62cabf498033 Mon Sep 17 00:00:00 2001 From: Sergio Zharinov <zharinov@users.noreply.github.com> Date: Mon, 11 Feb 2019 12:58:49 +0400 Subject: [PATCH] fix(maven): parse additional Maven repositories from pomfiles (#3198) --- lib/manager/maven/extract.js | 20 ++++++++++++++++++- test/_fixtures/maven/simple.pom.xml | 12 +++++++++++ .../maven/__snapshots__/extract.spec.js.snap | 6 ++++++ 3 files changed, 37 insertions(+), 1 deletion(-) diff --git a/lib/manager/maven/extract.js b/lib/manager/maven/extract.js index 583a9819ea..36ad0dcc09 100644 --- a/lib/manager/maven/extract.js +++ b/lib/manager/maven/extract.js @@ -1,6 +1,8 @@ const { XmlDocument } = require('xmldoc'); const { isVersion } = require('../../versioning/maven'); +const DEFAULT_MAVEN_REPO = 'https://repo.maven.apache.org/maven2'; + function parsePom(raw) { let project; try { @@ -40,7 +42,7 @@ function depFromNode(node) { const offset = '<version>'.length - 1; result.fileReplacePosition = versionNode.startTagPosition + offset; result.datasource = 'maven'; - result.registryUrls = ['https://repo.maven.apache.org/maven2']; + result.registryUrls = [DEFAULT_MAVEN_REPO]; } return result; } @@ -80,6 +82,22 @@ function extractDependencies(raw) { result.deps = deepExtract(project); + const repositories = project.childNamed('repositories'); + if (repositories && repositories.children) { + const repoUrls = []; + for (const repo of repositories.childrenNamed('repository')) { + const repoUrl = repo.valueWithPath('url'); + if (repoUrl) { + repoUrls.push(repoUrl); + } + } + result.deps.forEach(dep => { + if (dep.registryUrls) { + repoUrls.forEach(url => dep.registryUrls.push(url)); + } + }); + } + return result; } diff --git a/test/_fixtures/maven/simple.pom.xml b/test/_fixtures/maven/simple.pom.xml index 0151002b32..e11ebf54d4 100644 --- a/test/_fixtures/maven/simple.pom.xml +++ b/test/_fixtures/maven/simple.pom.xml @@ -124,4 +124,16 @@ </plugin> </plugins> </reporting> + + <repositories> + <repository> + <id>atlassian</id> + <name>Atlassian Repository</name> + <url>https://maven.atlassian.com/content/repositories/atlassian-public/</url> + </repository> + <repository> + <id>nonsense</id> + <name>The item without url</name> + </repository> + </repositories> </project> diff --git a/test/manager/maven/__snapshots__/extract.spec.js.snap b/test/manager/maven/__snapshots__/extract.spec.js.snap index c896b77981..6a563704d9 100644 --- a/test/manager/maven/__snapshots__/extract.spec.js.snap +++ b/test/manager/maven/__snapshots__/extract.spec.js.snap @@ -11,6 +11,7 @@ Object { "fileReplacePosition": 186, "registryUrls": Array [ "https://repo.maven.apache.org/maven2", + "https://maven.atlassian.com/content/repositories/atlassian-public/", ], }, Object { @@ -20,6 +21,7 @@ Object { "fileReplacePosition": 757, "registryUrls": Array [ "https://repo.maven.apache.org/maven2", + "https://maven.atlassian.com/content/repositories/atlassian-public/", ], }, Object { @@ -29,6 +31,7 @@ Object { "fileReplacePosition": 905, "registryUrls": Array [ "https://repo.maven.apache.org/maven2", + "https://maven.atlassian.com/content/repositories/atlassian-public/", ], }, Object { @@ -38,6 +41,7 @@ Object { "fileReplacePosition": 1337, "registryUrls": Array [ "https://repo.maven.apache.org/maven2", + "https://maven.atlassian.com/content/repositories/atlassian-public/", ], }, Object { @@ -62,6 +66,7 @@ Object { "fileReplacePosition": 2529, "registryUrls": Array [ "https://repo.maven.apache.org/maven2", + "https://maven.atlassian.com/content/repositories/atlassian-public/", ], }, Object { @@ -81,6 +86,7 @@ Object { "fileReplacePosition": 3218, "registryUrls": Array [ "https://repo.maven.apache.org/maven2", + "https://maven.atlassian.com/content/repositories/atlassian-public/", ], }, ], -- GitLab