Skip to content

Commit

Permalink
fix(managers/maven): change order of extracted registryUrls (#26828)
Browse files Browse the repository at this point in the history
Co-authored-by: Sebastian Poxhofer <secustor@users.noreply.github.com>
Co-authored-by: Johannes Feichtner <343448+Churro@users.noreply.github.com>
Co-authored-by: Michael Kriese <michael.kriese@visualon.de>
  • Loading branch information
4 people committed Feb 9, 2024
1 parent 1fd9be0 commit 82e621f
Show file tree
Hide file tree
Showing 5 changed files with 72 additions and 44 deletions.
18 changes: 0 additions & 18 deletions lib/modules/manager/maven/__snapshots__/extract.spec.ts.snap
Expand Up @@ -11,7 +11,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depType": "parent",
"fileReplacePosition": 186,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand All @@ -22,7 +21,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depType": "compile",
"fileReplacePosition": 905,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand All @@ -33,7 +31,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depType": "compile",
"fileReplacePosition": 1093,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand All @@ -44,7 +41,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depType": "build",
"fileReplacePosition": 1347,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand All @@ -55,7 +51,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depType": "build",
"fileReplacePosition": 1545,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand All @@ -66,7 +61,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depType": "build",
"fileReplacePosition": 2276,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand All @@ -77,7 +71,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depType": "compile",
"fileReplacePosition": 2484,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand All @@ -88,7 +81,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depType": "compile",
"fileReplacePosition": 2634,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand All @@ -99,7 +91,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depType": "compile",
"fileReplacePosition": 2779,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand All @@ -110,7 +101,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depType": "compile",
"fileReplacePosition": 2938,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand All @@ -121,7 +111,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depType": "test",
"fileReplacePosition": 3086,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand All @@ -132,7 +121,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depType": "compile",
"fileReplacePosition": 3252,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand All @@ -143,7 +131,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depType": "compile",
"fileReplacePosition": 3410,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand All @@ -154,7 +141,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depType": "optional",
"fileReplacePosition": 3555,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand All @@ -164,7 +150,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depName": "org.example:relocation-artifact",
"fileReplacePosition": 3787,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand All @@ -175,7 +160,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depType": "compile",
"fileReplacePosition": 4119,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand All @@ -186,7 +170,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depType": "build",
"fileReplacePosition": 4375,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand All @@ -197,7 +180,6 @@ exports[`modules/manager/maven/extract extractDependencies extract dependencies
"depType": "build",
"fileReplacePosition": 4769,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"https://maven.atlassian.com/content/repositories/atlassian-public/",
],
},
Expand Down
28 changes: 14 additions & 14 deletions lib/modules/manager/maven/__snapshots__/index.spec.ts.snap
Expand Up @@ -12,9 +12,9 @@ exports[`modules/manager/maven/index updateDependency should include registryUrl
"depType": "parent",
"fileReplacePosition": 185,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"http://example.com/nexus/xyz",
"http://example.com/",
"https://repo.maven.apache.org/maven2",
],
},
{
Expand All @@ -26,9 +26,9 @@ exports[`modules/manager/maven/index updateDependency should include registryUrl
"fileReplacePosition": 470,
"groupName": "quuxVersion",
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
"https://repo.maven.apache.org/maven2",
],
},
],
Expand All @@ -44,9 +44,9 @@ exports[`modules/manager/maven/index updateDependency should include registryUrl
"depType": "parent",
"fileReplacePosition": 186,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
"https://repo.maven.apache.org/maven2",
],
},
{
Expand All @@ -56,9 +56,9 @@ exports[`modules/manager/maven/index updateDependency should include registryUrl
"depType": "compile",
"fileReplacePosition": 806,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
"https://repo.maven.apache.org/maven2",
],
},
{
Expand All @@ -68,9 +68,9 @@ exports[`modules/manager/maven/index updateDependency should include registryUrl
"depType": "compile",
"fileReplacePosition": 954,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
"https://repo.maven.apache.org/maven2",
],
},
{
Expand All @@ -80,9 +80,9 @@ exports[`modules/manager/maven/index updateDependency should include registryUrl
"depType": "build",
"fileReplacePosition": 1188,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
"https://repo.maven.apache.org/maven2",
],
},
{
Expand All @@ -92,9 +92,9 @@ exports[`modules/manager/maven/index updateDependency should include registryUrl
"depType": "build",
"fileReplacePosition": 1386,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
"https://repo.maven.apache.org/maven2",
],
},
{
Expand All @@ -104,9 +104,9 @@ exports[`modules/manager/maven/index updateDependency should include registryUrl
"depType": "compile",
"fileReplacePosition": 2131,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
"https://repo.maven.apache.org/maven2",
],
"skipReason": "name-placeholder",
},
Expand All @@ -117,9 +117,9 @@ exports[`modules/manager/maven/index updateDependency should include registryUrl
"depType": "compile",
"fileReplacePosition": 2281,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
"https://repo.maven.apache.org/maven2",
],
"skipReason": "name-placeholder",
},
Expand All @@ -130,9 +130,9 @@ exports[`modules/manager/maven/index updateDependency should include registryUrl
"depType": "compile",
"fileReplacePosition": 2574,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
"https://repo.maven.apache.org/maven2",
],
},
{
Expand All @@ -142,9 +142,9 @@ exports[`modules/manager/maven/index updateDependency should include registryUrl
"depType": "compile",
"fileReplacePosition": 2714,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
"https://repo.maven.apache.org/maven2",
],
},
{
Expand All @@ -154,9 +154,9 @@ exports[`modules/manager/maven/index updateDependency should include registryUrl
"depType": "compile",
"fileReplacePosition": 2872,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
"https://repo.maven.apache.org/maven2",
],
},
{
Expand All @@ -166,9 +166,9 @@ exports[`modules/manager/maven/index updateDependency should include registryUrl
"depType": "compile",
"fileReplacePosition": 3134,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
"https://repo.maven.apache.org/maven2",
],
"skipReason": "version-placeholder",
},
Expand All @@ -179,9 +179,9 @@ exports[`modules/manager/maven/index updateDependency should include registryUrl
"depType": "build",
"fileReplacePosition": 3410,
"registryUrls": [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
"https://repo.maven.apache.org/maven2",
],
},
],
Expand Down
23 changes: 23 additions & 0 deletions lib/modules/manager/maven/extract.spec.ts
@@ -1,3 +1,4 @@
import { codeBlock } from 'common-tags';
import { Fixtures } from '../../../../test/fixtures';
import { extractPackage, extractRegistries } from './extract';

Expand Down Expand Up @@ -173,5 +174,27 @@ describe('modules/manager/maven/extract', () => {
'https://repo.adobe.com/v4/nexus/content/groups/public',
]);
});

it('extract registries from a settings file that uses updated schema', () => {
const settingsUpdatedContent = codeBlock`
<settings xmlns="http://maven.apache.org/SETTINGS/1.2.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/SETTINGS/1.2.0 http://maven.apache.org/xsd/settings-1.2.0.xsd">
<mirrors>
<mirror>
<id>Test-Internal-repository</id>
<name>Proxy Repository Manager</name>
<url>https://proxy-repo.com/artifactory/apache-maven</url>
<mirrorOf>central</mirrorOf>
</mirror>
</mirrors>
<profiles/>
<activeProfiles/>
</settings>
`;
const res = extractRegistries(settingsUpdatedContent);
expect(res).toStrictEqual([
'https://proxy-repo.com/artifactory/apache-maven',
]);
});
});
});
20 changes: 11 additions & 9 deletions lib/modules/manager/maven/extract.ts
Expand Up @@ -9,6 +9,12 @@ import { MAVEN_REPO } from '../../datasource/maven/common';
import type { ExtractConfig, PackageDependency, PackageFile } from '../types';
import type { MavenProp } from './types';

const supportedNamespaces = [
'http://maven.apache.org/SETTINGS/1.0.0',
'http://maven.apache.org/SETTINGS/1.1.0',
'http://maven.apache.org/SETTINGS/1.2.0',
];

function parsePom(raw: string, packageFile: string): XmlDocument | null {
let project: XmlDocument;
try {
Expand Down Expand Up @@ -58,13 +64,12 @@ function depFromNode(
const versionNode = node.descendantWithPath('version')!;
const fileReplacePosition = versionNode.position;
const datasource = MavenDatasource.id;
const registryUrls = [MAVEN_REPO];
const result: PackageDependency = {
datasource,
depName,
currentValue,
fileReplacePosition,
registryUrls,
registryUrls: [],
};

switch (node.name) {
Expand Down Expand Up @@ -367,7 +372,7 @@ export function parseSettings(raw: string): XmlDocument | null {
if (name !== 'settings') {
return null;
}
if (attr.xmlns === 'http://maven.apache.org/SETTINGS/1.0.0') {
if (supportedNamespaces.includes(attr.xmlns)) {
return settings;
}
return null;
Expand Down Expand Up @@ -464,6 +469,8 @@ function cleanResult(packageFiles: MavenInterimPackageFile[]): PackageFile[] {
delete packageFile.parent;
packageFile.deps.forEach((dep) => {
delete dep.propSource;
//Add Registry From SuperPom
dep.registryUrls!.push(MAVEN_REPO);
});
});
return packageFiles;
Expand Down Expand Up @@ -503,12 +510,7 @@ export async function extractAllPackageFiles(
if (additionalRegistryUrls) {
for (const pkgFile of packages) {
for (const dep of pkgFile.deps) {
/* istanbul ignore else */
if (dep.registryUrls) {
dep.registryUrls.push(...additionalRegistryUrls);
} else {
dep.registryUrls = [...additionalRegistryUrls];
}
dep.registryUrls!.unshift(...additionalRegistryUrls);
}
}
}
Expand Down

0 comments on commit 82e621f

Please sign in to comment.