Skip to content

Commit

Permalink
chore(maven): Add 'editFile' field to extracted deps (#6752)
Browse files Browse the repository at this point in the history
* feat(maven): Add 'editFile' field when extracting

* Set 'editFile' only for parent files
  • Loading branch information
zharinov committed Jul 14, 2020
1 parent 467994b commit 74b6669
Show file tree
Hide file tree
Showing 4 changed files with 186 additions and 1 deletion.
1 change: 1 addition & 0 deletions lib/manager/common.ts
Expand Up @@ -171,6 +171,7 @@ export interface PackageDependency<T = Record<string, any>> extends Package<T> {
replaceString?: string;
autoReplaceStringTemplate?: string;
depIndex?: number;
editFile?: string;
}

export interface Upgrade<T = Record<string, any>>
Expand Down
178 changes: 178 additions & 0 deletions lib/manager/maven/__snapshots__/index.spec.ts.snap
Expand Up @@ -156,3 +156,181 @@ Array [
},
]
`;

exports[`manager/maven updateDependency should include registryUrls from parent pom files 1`] = `
Array [
Object {
"datasource": "maven",
"deps": Array [
Object {
"currentValue": "42",
"datasource": "maven",
"depName": "org.example:child",
"fileReplacePosition": 185,
"registryUrls": Array [
"https://repo.maven.apache.org/maven2",
"http://example.com/nexus/xyz",
"http://example.com/",
],
},
Object {
"currentValue": "1.2.3.4",
"datasource": "maven",
"depName": "org.example:quux",
"editFile": "parent.pom.xml",
"fileReplacePosition": 470,
"groupName": "quuxVersion",
"registryUrls": Array [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
],
},
],
"packageFile": "parent.pom.xml",
"parent": "child.pom.xml",
},
Object {
"datasource": "maven",
"deps": Array [
Object {
"currentValue": "42",
"datasource": "maven",
"depName": "org.example:parent",
"fileReplacePosition": 186,
"registryUrls": Array [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
],
},
Object {
"currentValue": "0.0.1",
"datasource": "maven",
"depName": "org.example:foo",
"fileReplacePosition": 806,
"registryUrls": Array [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
],
},
Object {
"currentValue": "1.0.0",
"datasource": "maven",
"depName": "org.example:bar",
"fileReplacePosition": 954,
"registryUrls": Array [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
],
},
Object {
"currentValue": "2.4.2",
"datasource": "maven",
"depName": "org.apache.maven.plugins:maven-release-plugin",
"fileReplacePosition": 1188,
"registryUrls": Array [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
],
},
Object {
"currentValue": "1.8.1",
"datasource": "maven",
"depName": "org.apache.maven.scm:maven-scm-provider-gitexe",
"fileReplacePosition": 1386,
"registryUrls": Array [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
],
},
Object {
"currentValue": "0.0.1",
"datasource": "maven",
"depName": "org.example:\${artifact-id-placeholder}",
"fileReplacePosition": 2131,
"registryUrls": Array [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
],
"skipReason": "name-placeholder",
},
Object {
"currentValue": "0.0.1",
"datasource": "maven",
"depName": "\${group-id-placeholder}:baz",
"fileReplacePosition": 2281,
"registryUrls": Array [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
],
"skipReason": "name-placeholder",
},
Object {
"currentValue": "1.2.3",
"datasource": "maven",
"depName": "org.example:quuz",
"fileReplacePosition": 2574,
"registryUrls": Array [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
],
},
Object {
"currentValue": "it's not a version",
"datasource": "maven",
"depName": "org.example:quuuz",
"fileReplacePosition": 2714,
"registryUrls": Array [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
],
},
Object {
"currentValue": "[1.0.0]",
"datasource": "maven",
"depName": "org.example:hard-range",
"fileReplacePosition": 2872,
"registryUrls": Array [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
],
},
Object {
"currentValue": "\${profile-placeholder}",
"datasource": "maven",
"depName": "org.example:profile-artifact",
"fileReplacePosition": 3134,
"registryUrls": Array [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
],
"skipReason": "version-placeholder",
},
Object {
"currentValue": "2.17",
"datasource": "maven",
"depName": "org.apache.maven.plugins:maven-checkstyle-plugin",
"fileReplacePosition": 3410,
"registryUrls": Array [
"https://repo.maven.apache.org/maven2",
"http://example.com/",
"http://example.com/nexus/xyz",
],
},
],
"packageFile": "child.pom.xml",
"parent": "parent.pom.xml",
},
]
`;
7 changes: 6 additions & 1 deletion lib/manager/maven/extract.ts
Expand Up @@ -89,6 +89,7 @@ function deepExtract(

function applyProps(
dep: PackageDependency<Record<string, any>>,
depPackageFile: string,
props: MavenProp
): PackageDependency<Record<string, any>> {
const replaceAll = (str: string): string =>
Expand Down Expand Up @@ -137,6 +138,10 @@ function applyProps(
result.skipReason = SkipReason.VersionPlaceholder;
}

if (propSource && depPackageFile !== propSource) {
result.editFile = propSource;
}

return result;
}

Expand Down Expand Up @@ -270,7 +275,7 @@ export function resolveParents(packages: PackageFile[]): PackageFile[] {
packageFileNames.forEach((name) => {
const pkg = extractedPackages[name];
pkg.deps.forEach((rawDep) => {
const dep = applyProps(rawDep, extractedProps[name]);
const dep = applyProps(rawDep, name, extractedProps[name]);
const sourceName = dep.propSource || name;
extractedDeps[sourceName].push(dep);
});
Expand Down
1 change: 1 addition & 0 deletions lib/manager/maven/index.spec.ts
Expand Up @@ -115,6 +115,7 @@ describe('manager/maven', () => {
expect(depUrls).toEqual(urls);
});
});
expect(packages).toMatchSnapshot();
});

it('should not touch content if new and old versions are equal', () => {
Expand Down

0 comments on commit 74b6669

Please sign in to comment.