Skip to content

Commit

Permalink
fix(common): improve the checking/adding of a maven plugin in pom.xml
Browse files Browse the repository at this point in the history
  • Loading branch information
tinesoft authored Jul 3, 2022
1 parent b118a4e commit b8f59cf
Showing 1 changed file with 5 additions and 10 deletions.
15 changes: 5 additions & 10 deletions packages/common/src/lib/core/jvm/maven-utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,19 @@ export function hasMavenPlugin(tree: Tree, rootFolder: string, groupId: string,
const pomXmlStr = tree.read(`${rootFolder}/pom.xml`, 'utf-8');
const pomXml = readXml(pomXmlStr);

const pluginGrouIdNode = findXmlMatching(pomXml, `/project/build/plugins/plugin/groupId/text()[.="${groupId}"]`);
const pluginArtifactIdNode = findXmlMatching(pomXml, `/project/build/plugins/plugin/artifactId/text()[.="${artifactId}"]`);
if (pluginGrouIdNode && pluginArtifactIdNode) {
const pluginVersionNode = findXmlMatching(pomXml, `/project/build/plugins/plugin/version/text()[.="${version}"]`);

return version ? !!pluginVersionNode : true;
let pluginXPath = `/project/build/plugins/plugin/groupId/text()[.="${groupId}"]/../../artifactId/text()[.="${artifactId}"]`;
if (version) {
pluginXPath += `/../../version/text()[.="${version}"]`;
}

return false;
return !! findXmlMatching(pomXml, pluginXPath)?.up()?.up();
}

export function addMavenPlugin(tree: Tree, rootFolder: string, groupId: string, artifactId: string, version?: string, configuration?: { [key: string]: any } | string): boolean {
const pomXmlStr = tree.read(`${rootFolder}/pom.xml`, 'utf-8');
const pomXml = readXml(pomXmlStr);

const pluginGrouIdNode = findXmlMatching(pomXml, `/project/build/plugins/plugin/groupId/text()[.="${groupId}"]`);
const pluginArtifactIdNode = findXmlMatching(pomXml, `/project/build/plugins/plugin/artifactId/text()[.="${artifactId}"]`);
if (pluginGrouIdNode && pluginArtifactIdNode) {
if (hasMavenPlugin(tree, rootFolder, groupId, artifactId, version)) {
return false;// plugin already exists
}

Expand Down

0 comments on commit b8f59cf

Please sign in to comment.