From 4adbb9a06b73504c20a7ac59be85e3f24f0edb5f Mon Sep 17 00:00:00 2001 From: Aleksandr Mashchenko Date: Fri, 18 Feb 2022 23:21:06 +0200 Subject: [PATCH] Set versions of used plugins in the code and allow to modify it with properties - closes #330 This solves source code incompatibility issues between this plugin and used versions-maven-plugin and tycho-versions-plugin. --- .../plugin/gitflow/AbstractGitFlowMojo.java | 41 ++++++++++++++----- 1 file changed, 31 insertions(+), 10 deletions(-) diff --git a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java index 439942b7..5dcb3abe 100644 --- a/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java +++ b/src/main/java/com/amashchenko/maven/plugin/gitflow/AbstractGitFlowMojo.java @@ -53,12 +53,18 @@ * */ public abstract class AbstractGitFlowMojo extends AbstractMojo { - /** A full name of the versions-maven-plugin set goal. */ - private static final String VERSIONS_MAVEN_PLUGIN_SET_GOAL = "org.codehaus.mojo:versions-maven-plugin:set"; - /** A full name of the versions-maven-plugin set-property goal. */ - private static final String VERSIONS_MAVEN_PLUGIN_SET_PROPERTY_GOAL = "org.codehaus.mojo:versions-maven-plugin:set-property"; - /** Name of the tycho-versions-plugin set-version goal. */ - private static final String TYCHO_VERSIONS_PLUGIN_SET_GOAL = "org.eclipse.tycho:tycho-versions-plugin:set-version"; + /** Group and artifact id of the versions-maven-plugin. */ + private static final String VERSIONS_MAVEN_PLUGIN = "org.codehaus.mojo:versions-maven-plugin"; + /** The versions-maven-plugin set goal. */ + private static final String VERSIONS_MAVEN_PLUGIN_SET_GOAL = "set"; + /** The versions-maven-plugin set-property goal. */ + private static final String VERSIONS_MAVEN_PLUGIN_SET_PROPERTY_GOAL = "set-property"; + + /** Group and artifact id of the tycho-versions-plugin. */ + private static final String TYCHO_VERSIONS_PLUGIN = "org.eclipse.tycho:tycho-versions-plugin"; + /** The tycho-versions-plugin set-version goal. */ + private static final String TYCHO_VERSIONS_PLUGIN_SET_GOAL = "set-version"; + /** Name of the property needed to have reproducible builds. */ private static final String REPRODUCIBLE_BUILDS_PROPERTY = "project.build.outputTimestamp"; @@ -180,6 +186,18 @@ public abstract class AbstractGitFlowMojo extends AbstractMojo { @Parameter(property = "updateOutputTimestamp", defaultValue = "true") private boolean updateOutputTimestamp = true; + /** + * Version of versions-maven-plugin to use. + */ + @Parameter(property = "versionsMavenPluginVersion", defaultValue = "2.8.1") + private String versionsMavenPluginVersion = "2.8.1"; + + /** + * Version of tycho-versions-plugin to use. + */ + @Parameter(property = "tychoVersionsPluginVersion", defaultValue = "0.24.0") + private String tychoVersionsPluginVersion = "0.24.0"; + /** * Options to pass to Git push command using --push-option. * Multiple options can be added separated with a space e.g. @@ -1140,7 +1158,8 @@ protected void mvnSetVersions(final String version) throws MojoFailureException, getLog().info("Updating property '" + versionProperty + "' to '" + version + "'."); } - executeMvnCommand(TYCHO_VERSIONS_PLUGIN_SET_GOAL, prop, newVersion, "-Dtycho.mode=maven"); + executeMvnCommand(TYCHO_VERSIONS_PLUGIN + ":" + tychoVersionsPluginVersion + ":" + TYCHO_VERSIONS_PLUGIN_SET_GOAL, prop, + newVersion, "-Dtycho.mode=maven"); } else { boolean runCommand = false; List args = new ArrayList<>(); @@ -1148,7 +1167,7 @@ protected void mvnSetVersions(final String version) throws MojoFailureException, args.add(newVersion); if (!skipUpdateVersion) { runCommand = true; - args.add(VERSIONS_MAVEN_PLUGIN_SET_GOAL); + args.add(VERSIONS_MAVEN_PLUGIN + ":" + versionsMavenPluginVersion + ":" + VERSIONS_MAVEN_PLUGIN_SET_GOAL); args.add(grp); args.add(art); } @@ -1157,7 +1176,7 @@ protected void mvnSetVersions(final String version) throws MojoFailureException, runCommand = true; getLog().info("Updating property '" + versionProperty + "' to '" + version + "'."); - args.add(VERSIONS_MAVEN_PLUGIN_SET_PROPERTY_GOAL); + args.add(VERSIONS_MAVEN_PLUGIN + ":" + versionsMavenPluginVersion + ":" + VERSIONS_MAVEN_PLUGIN_SET_PROPERTY_GOAL); args.add("-Dproperty=" + versionProperty); } if (runCommand) { @@ -1178,7 +1197,9 @@ protected void mvnSetVersions(final String version) throws MojoFailureException, getLog().info("Updating property '" + REPRODUCIBLE_BUILDS_PROPERTY + "' to '" + timestamp + "'."); - executeMvnCommand(VERSIONS_MAVEN_PLUGIN_SET_PROPERTY_GOAL, "-DgenerateBackupPoms=false", + executeMvnCommand( + VERSIONS_MAVEN_PLUGIN + ":" + versionsMavenPluginVersion + ":" + VERSIONS_MAVEN_PLUGIN_SET_PROPERTY_GOAL, + "-DgenerateBackupPoms=false", "-Dproperty=" + REPRODUCIBLE_BUILDS_PROPERTY, "-DnewVersion=" + timestamp); } }