From fa1cccb5162346473798f9970e533a12e0443c78 Mon Sep 17 00:00:00 2001 From: Bryan Varner <1652015+bvarner@users.noreply.github.com> Date: Thu, 14 Jan 2021 12:48:56 -0500 Subject: [PATCH] Revert "Feature/other branch reversioning extension" --- README.md | 14 +- pom.xml | 2 +- .../AbstractBranchDetectingExtension.java | 171 ---------- .../AbstractGitflowBasedRepositoryMojo.java | 7 +- .../AttachDeployedArtifactsMojo.java | 2 + .../gitflowhelper/MasterPromoteExtension.java | 135 +++++++- .../OtherBranchVersionExtension.java | 314 ------------------ .../gitflowhelper/PromoteMasterMojo.java | 2 + .../gitflowhelper/RetargetDeployMojo.java | 44 ++- .../UpdateStageDependenciesMojo.java | 6 +- .../CircularDefinitionPreventer.java | 6 +- .../maven/gitflowhelper/OtherBranchIT.java | 68 +--- .../maven/gitflowhelper/OtherBranchTest.java | 33 -- .../maven/gitflowhelper/RetargetDeployIT.java | 1 + .../multi-module-project-stub/child1/pom.xml | 16 - .../build/resources/master.build.properties | 3 - .../src/build/resources/my-text-file.txt | 1 - .../child1/src/main/java/HelloWorld.java | 8 - .../src/main/resources/project.properties | 1 - .../multi-module-project-stub/child2/pom.xml | 24 -- .../build/resources/master.build.properties | 3 - .../src/build/resources/my-text-file.txt | 1 - .../child2/src/main/java/HelloWorld.java | 8 - .../src/main/resources/project.properties | 1 - .../multi-module-project-stub/pom.xml | 134 -------- 25 files changed, 205 insertions(+), 800 deletions(-) delete mode 100644 src/main/java/com/e_gineering/maven/gitflowhelper/AbstractBranchDetectingExtension.java delete mode 100644 src/main/java/com/e_gineering/maven/gitflowhelper/OtherBranchVersionExtension.java delete mode 100644 src/test/java/com/e_gineering/maven/gitflowhelper/OtherBranchTest.java delete mode 100644 src/test/resources/multi-module-project-stub/child1/pom.xml delete mode 100644 src/test/resources/multi-module-project-stub/child1/src/build/resources/master.build.properties delete mode 100644 src/test/resources/multi-module-project-stub/child1/src/build/resources/my-text-file.txt delete mode 100644 src/test/resources/multi-module-project-stub/child1/src/main/java/HelloWorld.java delete mode 100644 src/test/resources/multi-module-project-stub/child1/src/main/resources/project.properties delete mode 100644 src/test/resources/multi-module-project-stub/child2/pom.xml delete mode 100644 src/test/resources/multi-module-project-stub/child2/src/build/resources/master.build.properties delete mode 100644 src/test/resources/multi-module-project-stub/child2/src/build/resources/my-text-file.txt delete mode 100644 src/test/resources/multi-module-project-stub/child2/src/main/java/HelloWorld.java delete mode 100644 src/test/resources/multi-module-project-stub/child2/src/main/resources/project.properties delete mode 100644 src/test/resources/multi-module-project-stub/pom.xml diff --git a/README.md b/README.md index e70671d..b85daaf 100644 --- a/README.md +++ b/README.md @@ -403,16 +403,16 @@ the artifacts built by the first job into a jboss application server. ## To Debug the plugin (replicating a test-case but without being run from jUnit) You can 'bootstrap' the plugin into your local repository and get the test project stubbed by running: +`mvn -Dmaven.test.skip=true install` + +Then, change directories: +`cd target/test-classes/project-stub` + +From there, you'll need to supply the required environment variables or commandline arguments to `mvnDebug`: ``` -mvn process-test-classes -mvn -Dmaven.test.skip=true install -cd target/test-classes/project-stub` export GIT_BRANCH=origin/feature/mybranch-foo-bar -mvnDebug -Dstub.project.version=5.0.0-SNAPSHOT -DallowGitflowPluginSnapshot=true deploy +mvnDebug -Dstub.project.version=5.0.0-SNAPSHOT -DotherBranchDeploy=semver -DallowGitflowPluginSnapshot=true deploy ``` -This will get the test classes into the target directory and install the plugin into your local repository. -Then you move to the proper stub directory, supply the environment variables and arguments to `mvnDebug`. - You can then connect a remote debugger and step through the plugin code. ## Building with IntelliJ IDEA notes diff --git a/pom.xml b/pom.xml index f9cbcf0..2eeabd3 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ com.e-gineering gitflow-helper-maven-plugin - 3.1.0-SNAPSHOT + 3.0.0 maven-plugin diff --git a/src/main/java/com/e_gineering/maven/gitflowhelper/AbstractBranchDetectingExtension.java b/src/main/java/com/e_gineering/maven/gitflowhelper/AbstractBranchDetectingExtension.java deleted file mode 100644 index dd75422..0000000 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/AbstractBranchDetectingExtension.java +++ /dev/null @@ -1,171 +0,0 @@ -package com.e_gineering.maven.gitflowhelper; - -import org.apache.maven.AbstractMavenLifecycleParticipant; -import org.apache.maven.MavenExecutionException; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.lifecycle.internal.MojoDescriptorCreator; -import org.apache.maven.model.Plugin; -import org.apache.maven.project.MavenProject; -import org.apache.maven.scm.manager.ScmManager; -import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.logging.Logger; -import org.codehaus.plexus.util.cli.CommandLineUtils; -import org.codehaus.plexus.util.xml.Xpp3Dom; - -import java.io.IOException; -import java.util.Properties; - -public abstract class AbstractBranchDetectingExtension extends AbstractMavenLifecycleParticipant { - @Requirement - MojoDescriptorCreator descriptorCreator; - - @Requirement - Logger logger; - - @Requirement - ScmManager scmManager; - - boolean pluginFound = false; - String masterBranchPattern; - String supportBranchPattern; - String releaseBranchPattern; - String hotfixBranchPattern; - String developmentBranchPattern; - String featureOrBugfixBranchPattern; - String otherDeployBranchPattern; - String otherBranchVersionDelimiter; - GitBranchInfo branchInfo; - Properties systemEnvVars; - - @Override - public void afterProjectsRead(MavenSession session) throws MavenExecutionException { - try { - systemEnvVars = CommandLineUtils.getSystemEnvVars(); - } catch (IOException ioe) { - throw new MavenExecutionException("Unable to read System Envirionment Variables: ", ioe); - } - - // Look for a configured gitflow-helper-maven-plugin, - // To determine what the gitBranchExpression and branch patterns are... - String gitBranchExpression = null; - - pluginFound = false; - for (MavenProject project : session.getProjects()) { - for (Plugin plugin : project.getModel().getBuild().getPlugins()) { - // Don't drop our plugin. Read it's config - if (plugin.getKey().equals("com.e-gineering:gitflow-helper-maven-plugin")) { - pluginFound = true; - - logger.debug("gitflow-helper-maven-plugin found in project: [" + project.getName() + "]"); - - if (masterBranchPattern == null) { - masterBranchPattern = extractPluginConfigValue("masterBranchPattern", plugin); - } - - if (supportBranchPattern == null) { - supportBranchPattern = extractPluginConfigValue("supportBranchPattern", plugin); - } - - if (releaseBranchPattern == null) { - releaseBranchPattern = extractPluginConfigValue("releaseBranchPattern", plugin); - } - - if (hotfixBranchPattern == null) { - hotfixBranchPattern = extractPluginConfigValue("hotfixBranchPattern", plugin); - } - - if (developmentBranchPattern == null) { - developmentBranchPattern = extractPluginConfigValue("developmentBranchPattern", plugin); - } - - if (featureOrBugfixBranchPattern == null) { - featureOrBugfixBranchPattern = extractPluginConfigValue("featureOrBugfixBranchPattern", plugin); - } - - if (otherDeployBranchPattern == null) { - otherDeployBranchPattern = extractPluginConfigValue("otherDeployBranchPattern", plugin); - } - - if (otherBranchVersionDelimiter == null) { - otherBranchVersionDelimiter = extractPluginConfigValue("otherBranchVersionDelimiter", plugin); - } - - if (gitBranchExpression == null) { - gitBranchExpression = extractPluginConfigValue("gitBranchExpression", plugin); - } - } - } - } - - // Any missing configuration options need to be defaulted. - if (pluginFound) { - if (masterBranchPattern == null) { - logger.debug("Using default master branch Pattern."); - masterBranchPattern = "(origin/)?master"; - } - logger.debug("Master Branch Pattern: " + masterBranchPattern); - - if (supportBranchPattern == null) { - logger.debug("Using default support branch Pattern."); - supportBranchPattern = "(origin/)?support/(.*)"; - } - logger.debug("Support Branch Pattern: " + supportBranchPattern); - - if (releaseBranchPattern == null) { - logger.debug("Using default release branch Pattern."); - releaseBranchPattern = "(origin/)?release/(.*)"; - } - logger.debug("Release Branch Pattern: " + releaseBranchPattern); - - if (hotfixBranchPattern == null) { - logger.debug("Using default hotfix branch Pattern."); - hotfixBranchPattern = "(origin/)?hotfix/(.*)"; - } - logger.debug("Hotfix Branch Pattern: " + hotfixBranchPattern); - - if (developmentBranchPattern == null) { - logger.debug("Using default development Pattern."); - developmentBranchPattern = "(origin/)?develop"; - } - logger.debug("Development Branch Pattern: " + developmentBranchPattern); - - if (featureOrBugfixBranchPattern == null) { - logger.debug("Using default feature or bugfix Pattern."); - featureOrBugfixBranchPattern = "(origin/)?(?:feature|bugfix)/(.*)"; - } - logger.debug("Feature or Bugfix Branch Pattern: " + featureOrBugfixBranchPattern); - - if (otherDeployBranchPattern == null) { - logger.debug("Using default other deployment branch Pattern."); - otherDeployBranchPattern = ""; - } - logger.debug("Other Branch Deployment Pattern: " + otherDeployBranchPattern); - - if (otherBranchVersionDelimiter == null) { - logger.debug("Using default otherBranchVersionDelimiter."); - otherBranchVersionDelimiter = "+"; - } - - ScmUtils scmUtils = new ScmUtils(systemEnvVars, scmManager, session.getTopLevelProject(), new PlexusLoggerToMavenLog(logger), masterBranchPattern, supportBranchPattern, releaseBranchPattern, hotfixBranchPattern, developmentBranchPattern); - branchInfo = scmUtils.resolveBranchInfo(gitBranchExpression); - } else { - logger.debug("Unable to configure gitflow-helper-maven-plugin lifecycle extensions. No Plugin configuration found."); - } - } - - private String extractPluginConfigValue(String parameter, Plugin plugin) { - String value = extractConfigValue(parameter, plugin.getConfiguration()); - for (int i = 0; i < plugin.getExecutions().size() && value == null; i++) { - value = extractConfigValue(parameter, plugin.getExecutions().get(i).getConfiguration()); - } - return value; - } - - private String extractConfigValue(String parameter, Object configuration) { - try { - return ((Xpp3Dom) configuration).getChild(parameter).getValue(); - } catch (Exception ignored) { - } - return null; - } -} diff --git a/src/main/java/com/e_gineering/maven/gitflowhelper/AbstractGitflowBasedRepositoryMojo.java b/src/main/java/com/e_gineering/maven/gitflowhelper/AbstractGitflowBasedRepositoryMojo.java index b5ef311..d091c57 100644 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/AbstractGitflowBasedRepositoryMojo.java +++ b/src/main/java/com/e_gineering/maven/gitflowhelper/AbstractGitflowBasedRepositoryMojo.java @@ -2,13 +2,17 @@ import org.apache.maven.RepositoryUtils; import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.artifact.repository.ArtifactRepository; +import org.apache.maven.bridge.MavenRepositorySystem; +import org.apache.maven.model.DeploymentRepository; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProjectHelper; import org.apache.maven.shared.utils.StringUtils; +import org.codehaus.plexus.component.annotations.Requirement; import org.codehaus.plexus.util.FileUtils; import org.eclipse.aether.DefaultRepositorySystemSession; import org.eclipse.aether.RepositorySystem; @@ -34,6 +38,7 @@ import java.io.PrintWriter; import java.nio.file.Files; import java.util.ArrayList; +import java.util.Arrays; import java.util.List; import java.util.Objects; import java.util.Optional; @@ -70,7 +75,7 @@ private static PrintWriter newPrintWriter(File catalog) throws FileNotFoundExcep RepositorySystemSession repositorySystemSession; @Parameter(defaultValue = "${project.build.directory}", required = true) - File buildDirectory; + private File buildDirectory; @Component private RepositorySystem repositorySystem; diff --git a/src/main/java/com/e_gineering/maven/gitflowhelper/AttachDeployedArtifactsMojo.java b/src/main/java/com/e_gineering/maven/gitflowhelper/AttachDeployedArtifactsMojo.java index b15eafe..29ce797 100644 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/AttachDeployedArtifactsMojo.java +++ b/src/main/java/com/e_gineering/maven/gitflowhelper/AttachDeployedArtifactsMojo.java @@ -1,5 +1,7 @@ package com.e_gineering.maven.gitflowhelper; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Execute; diff --git a/src/main/java/com/e_gineering/maven/gitflowhelper/MasterPromoteExtension.java b/src/main/java/com/e_gineering/maven/gitflowhelper/MasterPromoteExtension.java index 754eb09..3bc0429 100644 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/MasterPromoteExtension.java +++ b/src/main/java/com/e_gineering/maven/gitflowhelper/MasterPromoteExtension.java @@ -3,14 +3,22 @@ import org.apache.maven.AbstractMavenLifecycleParticipant; import org.apache.maven.MavenExecutionException; import org.apache.maven.execution.MavenSession; +import org.apache.maven.lifecycle.internal.MojoDescriptorCreator; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException; import org.apache.maven.project.MavenProject; +import org.apache.maven.scm.manager.ScmManager; import org.codehaus.plexus.component.annotations.Component; +import org.codehaus.plexus.component.annotations.Requirement; +import org.codehaus.plexus.logging.Logger; +import org.codehaus.plexus.util.cli.CommandLineUtils; +import org.codehaus.plexus.util.xml.Xpp3Dom; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Properties; /** * Maven extension which removes (skips) undesired plugins from the build reactor when running on a master branch. @@ -18,11 +26,37 @@ * Essentially, enables using the master branch as a 'promotion' branch. */ @Component(role = AbstractMavenLifecycleParticipant.class, hint = "promote-master") -public class MasterPromoteExtension extends AbstractBranchDetectingExtension { - +public class MasterPromoteExtension extends AbstractMavenLifecycleParticipant { + + @Requirement + private MojoDescriptorCreator descriptorCreator; + + @Requirement + private Logger logger; + + @Requirement + private ScmManager scmManager; + @Override - public void afterProjectsRead(final MavenSession session) throws MavenExecutionException { - super.afterProjectsRead(session); + public void afterProjectsRead(MavenSession session) throws MavenExecutionException { + Properties systemEnvVars = null; + try { + systemEnvVars = CommandLineUtils.getSystemEnvVars(); + } catch (IOException ioe) { + throw new MavenExecutionException("Unable to read System Envirionment Variables: ", ioe); + } + + // Look for a gitflow-helper-maven-plugin, so we can determine what the gitBranchExpression and branch patterns are... + String masterBranchPattern = null; + String supportBranchPattern = null; + // Although we're not interested in these patterns, they're needed for ScmUtils. + String releaseBranchPattern = null; + String hotfixBranchPattern = null; + String developmentBranchPattern = null; + String featureOrBugfixBranchPattern = null; + + String gitBranchExpression = null; + boolean pluginFound = false; // Any plugin which is part of the project goals needs to be retained. List pluginsToRetain = new ArrayList<>(session.getGoals().size()); @@ -47,13 +81,43 @@ public void afterProjectsRead(final MavenSession session) throws MavenExecutionE List dropPlugins = new ArrayList<>(); for (Plugin plugin : project.getModel().getBuild().getPlugins()) { - // Don't drop our plugin. + // Don't drop our plugin. Read it's config if (plugin.getKey().equals("com.e-gineering:gitflow-helper-maven-plugin")) { - continue; - // Don't drop things we declare goals for. + pluginFound = true; + + logger.debug("gitflow-helper-maven-plugin found in project: [" + project.getName() + "]"); + + if (masterBranchPattern == null) { + masterBranchPattern = extractPluginConfigValue("masterBranchPattern", plugin); + } + + if (supportBranchPattern == null) { + supportBranchPattern = extractPluginConfigValue("supportBranchPattern", plugin); + } + + if (releaseBranchPattern == null) { + releaseBranchPattern = extractPluginConfigValue("releaseBranchPattern", plugin); + } + + if (hotfixBranchPattern == null) { + hotfixBranchPattern = extractPluginConfigValue("hotfixBranchPattern", plugin); + } + + if (developmentBranchPattern == null) { + developmentBranchPattern = extractPluginConfigValue("developmentBranchPattern", plugin); + } + + if (featureOrBugfixBranchPattern == null) { + featureOrBugfixBranchPattern = extractPluginConfigValue("featureOrBugfixBranchPattern", plugin); + } + + if (gitBranchExpression == null) { + gitBranchExpression = extractPluginConfigValue("gitBranchExpression", plugin); + } + // Don't drop things we declare goals for. } else if (pluginsToRetain.contains(plugin)) { logger.debug("gitflow-helper-maven-plugin retaining plugin: " + plugin + " from project: " + project.getName()); - // Don't drop the maven-deploy-plugin + // Don't drop the maven-deploy-plugin } else if (plugin.getKey().equals("org.apache.maven.plugins:maven-deploy-plugin")) { logger.debug("gitflow-helper-maven-plugin retaining plugin: " + plugin + " from project: " + project.getName()); } else { @@ -66,6 +130,45 @@ public void afterProjectsRead(final MavenSession session) throws MavenExecutionE } if (pluginFound) { + if (masterBranchPattern == null) { + logger.debug("Using default master branch Pattern."); + masterBranchPattern = "(origin/)?master"; + } + logger.debug("Master Branch Pattern: " + masterBranchPattern); + + if (supportBranchPattern == null) { + logger.debug("Using default support branch Pattern."); + supportBranchPattern = "(origin/)?support/(.*)"; + } + logger.debug("Support Branch Pattern: " + supportBranchPattern); + + if (releaseBranchPattern == null) { + logger.debug("Using default release branch Pattern."); + releaseBranchPattern = "(origin/)?release/(.*)"; + } + logger.debug("Release Branch Pattern: " + releaseBranchPattern); + + if (hotfixBranchPattern == null) { + logger.debug("Using default hotfix branch Pattern."); + hotfixBranchPattern = "(origin/)?hotfix/(.*)"; + } + logger.debug("Hotfix Branch Pattern: " + hotfixBranchPattern); + + if (developmentBranchPattern == null) { + logger.debug("Using default development Pattern."); + developmentBranchPattern = "(origin/)?develop"; + } + logger.debug("Development Branch Pattern: " + developmentBranchPattern); + + if (featureOrBugfixBranchPattern == null) { + logger.debug("Using default feature or bugfix Pattern."); + featureOrBugfixBranchPattern = "(origin/)?(?:feature|bugfix)/(.*)"; + } + logger.debug("Feature or Bugfix Branch Pattern: " + featureOrBugfixBranchPattern); + + ScmUtils scmUtils = new ScmUtils(systemEnvVars, scmManager, session.getTopLevelProject(), new PlexusLoggerToMavenLog(logger), masterBranchPattern, supportBranchPattern, releaseBranchPattern, hotfixBranchPattern, developmentBranchPattern); + GitBranchInfo branchInfo = scmUtils.resolveBranchInfo(gitBranchExpression); + boolean pruneBuild = false; if (branchInfo != null) { logger.info(branchInfo.toString()); @@ -91,4 +194,20 @@ public void afterProjectsRead(final MavenSession session) throws MavenExecutionE } } } + + private String extractPluginConfigValue(String parameter, Plugin plugin) { + String value = extractConfigValue(parameter, plugin.getConfiguration()); + for (int i = 0; i < plugin.getExecutions().size() && value == null; i++) { + value = extractConfigValue(parameter, plugin.getExecutions().get(i).getConfiguration()); + } + return value; + } + + private String extractConfigValue(String parameter, Object configuration) { + try { + return ((Xpp3Dom) configuration).getChild(parameter).getValue(); + } catch (Exception ignored) { + } + return null; + } } diff --git a/src/main/java/com/e_gineering/maven/gitflowhelper/OtherBranchVersionExtension.java b/src/main/java/com/e_gineering/maven/gitflowhelper/OtherBranchVersionExtension.java deleted file mode 100644 index 0ea049c..0000000 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/OtherBranchVersionExtension.java +++ /dev/null @@ -1,314 +0,0 @@ -package com.e_gineering.maven.gitflowhelper; - -import com.e_gineering.maven.gitflowhelper.properties.PropertyResolver; -import org.apache.maven.AbstractMavenLifecycleParticipant; -import org.apache.maven.Maven; -import org.apache.maven.MavenExecutionException; -import org.apache.maven.artifact.Artifact; -import org.apache.maven.artifact.versioning.VersionRange; -import org.apache.maven.execution.DefaultMavenExecutionRequest; -import org.apache.maven.execution.MavenExecutionRequest; -import org.apache.maven.execution.MavenExecutionResult; -import org.apache.maven.execution.MavenSession; -import org.apache.maven.model.Dependency; -import org.apache.maven.model.Model; -import org.apache.maven.model.Parent; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.ReportPlugin; -import org.apache.maven.model.io.ModelWriter; -import org.apache.maven.plugin.LegacySupport; -import org.apache.maven.project.MavenProject; -import org.codehaus.plexus.component.annotations.Component; -import org.codehaus.plexus.component.annotations.Requirement; - -import java.io.File; -import java.io.IOException; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@Component(role = AbstractMavenLifecycleParticipant.class, hint = "other-branch-version") -public class OtherBranchVersionExtension extends AbstractBranchDetectingExtension { - - @Requirement(role = ModelWriter.class) - ModelWriter modelWriter; - - @Requirement(role = Maven.class) - Maven maven; - - @Requirement(role = LegacySupport.class) - LegacySupport legacySupport; - - private static final int ORIGINAL_VERSION_IDX = 0; - private static final int ADJUSTED_VERSION_IDX = 1; - - @Override - public void afterProjectsRead(final MavenSession session) throws MavenExecutionException { - super.afterProjectsRead(session); - - if (session.getUserProperties().containsKey("gitflow.skip.extension")) { - return; - } - - if (pluginFound) { - logger.debug("other-branch-version extension active."); - if (branchInfo != null) { - logger.debug("other-branch-version extension on git branch: " + branchInfo.toString()); - if(branchInfo.getType().equals(GitBranchType.OTHER)) { - String otherBranchesToDeploy = PropertyResolver.resolveValue(otherDeployBranchPattern, session.getTopLevelProject().getProperties(), systemEnvVars); - logger.debug("OTHER branch detected. Testing against pattern: `" + otherBranchesToDeploy + "`"); - if (!"".equals(otherBranchesToDeploy) && branchInfo.getName().matches(otherBranchesToDeploy)) { - // Build a cross-walk map of projects to versions. - HashMap adjustedVersions = new HashMap<>(); - - // Update the versions on all the project models (in-memory, effective models). - for (MavenProject project : session.getProjects()) { - // Resolve the originalVersion, in case it has properties. - String originalVersion = PropertyResolver.resolveValue(project.getVersion(), project.getProperties(), systemEnvVars); - String newVersion = getAsBranchSnapshotVersion(originalVersion, branchInfo.getName()); - adjustedVersions.put(project, new String[] {originalVersion, newVersion}); - logger.info("Updating project " + project.getGroupId() + ":" + project.getArtifactId() + ":" + originalVersion + " to: " + newVersion); - - // Update the default artifact information for the project in the reactor. - // This is a Non-Model type, so we'll update these here. - // This is used to generate all the other artifacts in the project. - if (project.getArtifact() != null) { - project.getArtifact().setBaseVersion(newVersion); - project.getArtifact().setVersion(newVersion); - project.getArtifact().setVersionRange(VersionRange.createFromVersion(newVersion)); - } - } - - final MavenProject topLevelProjectInsideReactor = session.getTopLevelProject(); - final MavenProject topLevelProject = findTopLevelProject(topLevelProjectInsideReactor); - logger.info("Top level project: " + topLevelProjectInsideReactor.getGroupId() + ":" + topLevelProjectInsideReactor.getArtifactId()); - if (!topLevelProjectInsideReactor.equals(topLevelProject)) { - // When only the partial tree of modules is being built, not all modules could be indexed - // into the cross-walk map. In order to deal with dependencies to modules outside the reactor, - // Another Maven execution is performed on the 'actual' top level project. This allows the - // cross-walk map to be completed with the modules that *are* part of the multi-module project, - // but are currently not part of the reactor. - - logger.info("Found top level project, but outside reactor: " + topLevelProject.getGroupId() + ":" + topLevelProject.getArtifactId() + " (" + topLevelProject.getFile() + ")"); - - // Initialization of the nested Maven execution, based on the current session's request - final MavenExecutionRequest request = DefaultMavenExecutionRequest.copy(session.getRequest()) - .setExecutionListener(null) /* Disable the observer of the outer maven session */ - .setTransferListener(null) /* Disable the observer of the outer maven session */ - .setGoals(null) /* Disable the goals used to execute the outer maven session */ - .setReactorFailureBehavior(MavenExecutionRequest.REACTOR_FAIL_NEVER) - .setPom(topLevelProject.getFile()) /* Use the pom file of the top-level project */ - .setBaseDirectory(topLevelProject.getBasedir()) /* Use the basedir of the top-level project */ - ; - // The following user property on the nested execution prevents this extension to activate - // in the nested execution. This is needed, as the extension is not reentrant. - request.getUserProperties().put("gitflow.skip.extension", true); - - // Perform the nested Maven execution, and grab the list of *all* projects (ie modules of the - // multi-module build). - final MavenExecutionResult mavenExecutionResult; - try { - mavenExecutionResult = maven.execute(request); - } finally { - // The additional Maven execution uses a new session, and at the end of the execution - // clears the Session object in LegacySupport. This may break other plugins/uses of - // LegacySupport; therefore always restore the session *after* the additional Maven - // execution. - legacySupport.setSession(session); - } - final List topologicallySortedProjects = mavenExecutionResult.getTopologicallySortedProjects(); - - // Iterate over these modules and process the 'new' ones just as the modules that are part - // of the reactor. - for (MavenProject parsedProject : topologicallySortedProjects) { - if (adjustedVersions.containsKey(parsedProject)) { - logger.info("Skipping " + parsedProject.getGroupId() + ":" + parsedProject.getArtifactId() + ": already part of reactor"); - } else { - String originalVersion = PropertyResolver.resolveValue(parsedProject.getVersion(), parsedProject.getProperties(), systemEnvVars); - String newVersion = getAsBranchSnapshotVersion(originalVersion, branchInfo.getName()); - adjustedVersions.put(parsedProject, new String[]{originalVersion, newVersion}); - logger.info("Updating outside-reactor project " + parsedProject.getGroupId() + ":" + parsedProject.getArtifactId() + ":" + originalVersion + " to: " + newVersion); - } - } - } - - // Once we have that populated, refilter the adjusted projects models - // updating dependencies on both the in-memory effective model, and the original pom.xml model. - for (Map.Entry adjustedProject : adjustedVersions.entrySet()) { - - - // If the parent artifact is one of the projects with an adjusted version.. - if (adjustedProject.getKey().getParentArtifact() != null) { - for (Map.Entry adjustedProjects : adjustedVersions.entrySet()) { - if (isProjectOfReplacedArtifactVersion(adjustedProjects.getKey(), adjustedProjects.getValue()[ORIGINAL_VERSION_IDX], adjustedProject.getKey().getParentArtifact())) { - logger.info("Updating project: " + adjustedProject.getKey() + " parent artifact: " + adjustedProject.getKey().getParentArtifact()); - adjustedProject.getKey().getParentArtifact().setVersion(adjustedProjects.getValue()[ADJUSTED_VERSION_IDX]); - adjustedProject.getKey().getParentArtifact().setVersionRange(VersionRange.createFromVersion(adjustedProjects.getValue()[ADJUSTED_VERSION_IDX])); - logger.info(" Now: " + adjustedProject.getKey().getParentArtifact()); - } - } - } - - // Update the in-reactor active and effective model. - updateProjectModel(adjustedProject.getKey(), adjustedProject.getKey().getModel(), adjustedProject.getValue(), adjustedVersions); - - // The original model is an un-effective Model of the original pom.xml - updateProjectModel(adjustedProject.getKey(), adjustedProject.getKey().getOriginalModel(), adjustedProject.getValue(), adjustedVersions); - - createMassagedPom(adjustedProject.getKey()); - } - } - } - } - } - - logger.info("Continuing execution...."); - } - - private MavenProject findTopLevelProject(MavenProject mavenProject) { - MavenProject parent = mavenProject; - - while (parent.getParentFile() != null) { - parent = parent.getParent(); - } - - return parent; - } - - private void updateProjectModel(final MavenProject projectContext, final Model model, final String[] versions, final Map adjustedVersions) { - model.setVersion(versions[ADJUSTED_VERSION_IDX]); - - // Parent - if (model.getParent() != null) { - for (Map.Entry adjustedProjects : adjustedVersions.entrySet()) { - if (isProjectOfReplacedParentVersion(adjustedProjects.getKey(), adjustedProjects.getValue()[ORIGINAL_VERSION_IDX], model.getParent())) { - String originalParentVersion = PropertyResolver.resolveValue(model.getParent().getVersion(), projectContext.getProperties(), systemEnvVars); - model.getParent().setVersion(originalParentVersion.replace(versions[ORIGINAL_VERSION_IDX], versions[ADJUSTED_VERSION_IDX])); - } - } - } - - // Dependency Management - if (model.getDependencyManagement() != null) { - for (Dependency dep : model.getDependencyManagement().getDependencies()) { - for (Map.Entry adjustedProjects : adjustedVersions.entrySet()) { - if (isProjectOfReplacedDependencyVersion(adjustedProjects.getKey(), adjustedProjects.getValue()[ORIGINAL_VERSION_IDX], dep)) { - logger.debug("Updating model: " + model + " managed dependency: " + dep); - dep.setVersion(adjustedProjects.getValue()[ADJUSTED_VERSION_IDX]); - } - } - } - } - - // Standard Dependencies - for (Dependency dep : model.getDependencies()) { - for (Map.Entry adjustedProjects : adjustedVersions.entrySet()) { - if (isProjectOfReplacedDependencyVersion(adjustedProjects.getKey(), adjustedProjects.getValue()[ORIGINAL_VERSION_IDX], dep)) { - logger.debug("Updating model: " + model + " dependency: " + dep); - dep.setVersion(adjustedProjects.getValue()[ADJUSTED_VERSION_IDX]); - } - } - } - - // Plugin Management - if (model.getBuild() != null) { - // Update / massage the build final name, in case it contains the version string. - if (model.getBuild().getFinalName() != null) { - String originalFinalName = PropertyResolver.resolveValue(model.getBuild().getFinalName(), projectContext.getProperties(), systemEnvVars); - model.getBuild().setFinalName(originalFinalName.replace(versions[ORIGINAL_VERSION_IDX], versions[ADJUSTED_VERSION_IDX])); - } - - if (model.getBuild().getPluginManagement() != null) { - for (Plugin plugin : model.getBuild().getPluginManagement().getPlugins()) { - for (Map.Entry adjustedProjects : adjustedVersions.entrySet()) { - if (isProjectOfReplacedPluginVersion(adjustedProjects.getKey(), adjustedProjects.getValue()[ORIGINAL_VERSION_IDX], plugin)) { - logger.debug("Updating model: " + model + " managed plugin: " + plugin); - plugin.setVersion(adjustedProjects.getValue()[ADJUSTED_VERSION_IDX]); - } - } - } - } - - // Build Plugins - for (Plugin plugin : model.getBuild().getPlugins()) { - for (Map.Entry adjustedProjects : adjustedVersions.entrySet()) { - if (isProjectOfReplacedPluginVersion(adjustedProjects.getKey(), adjustedProjects.getValue()[ORIGINAL_VERSION_IDX], plugin)) { - logger.debug("Updating model: " + model + " plugin: " + plugin); - plugin.setVersion(adjustedProjects.getValue()[ADJUSTED_VERSION_IDX]); - } - } - } - } - - // Reporting Plugins - if (model.getReporting() != null) { - for (ReportPlugin plugin : model.getReporting().getPlugins()) { - for (Map.Entry adjustedProjects : adjustedVersions.entrySet()) { - if (isProjectOfReplacedReportPluginVersion(adjustedProjects.getKey(), adjustedProjects.getValue()[ORIGINAL_VERSION_IDX], plugin)) { - logger.debug("Updating model: " + model + " report plugin: " + plugin); - plugin.setVersion(adjustedProjects.getValue()[ADJUSTED_VERSION_IDX]); - } - } - } - } - } - - private void createMassagedPom(final MavenProject project) throws MavenExecutionException { - try { - // Write the massaged original model - File massagedModelFile = new File(project.getFile().getParentFile(), "pom-gitflow-massaged.xml"); - modelWriter.write(massagedModelFile, null, project.getOriginalModel()); - project.setPomFile(massagedModelFile); - } catch (IOException ioe) { - throw new MavenExecutionException("Failed to massage pom file to update versioning for deployment branch.", ioe); - } - } - - private boolean isProjectOfReplacedParentVersion(final MavenProject project, final String replacedVersion, final Parent parent) { - return project.getGroupId().equals(parent.getGroupId()) && - project.getArtifactId().equals(parent.getArtifactId()) && - replacedVersion.equals(PropertyResolver.resolveValue(parent.getVersion(), project.getProperties(), systemEnvVars)); - } - - private boolean isProjectOfReplacedReportPluginVersion(final MavenProject project, final String replacedVersion, final ReportPlugin plugin) { - return project.getGroupId().equals(plugin.getGroupId()) && - project.getArtifactId().equals(plugin.getArtifactId()) && - replacedVersion.equals(PropertyResolver.resolveValue(plugin.getVersion(), project.getProperties(), systemEnvVars)); - } - - private boolean isProjectOfReplacedPluginVersion(final MavenProject project, final String replacedVersion, final Plugin plugin) { - return project.getGroupId().equals(plugin.getGroupId()) && - project.getArtifactId().equals(plugin.getArtifactId()) && - replacedVersion.equals(PropertyResolver.resolveValue(plugin.getVersion(), project.getProperties(), systemEnvVars)); - } - - private boolean isProjectOfReplacedDependencyVersion(final MavenProject project, final String replacedVersion, final Dependency dependency) { - return project.getGroupId().equals(dependency.getGroupId()) && - project.getArtifactId().equals(dependency.getArtifactId()) && - replacedVersion.equals(PropertyResolver.resolveValue(dependency.getVersion(), project.getProperties(), systemEnvVars)); - } - - private boolean isProjectOfReplacedArtifactVersion(final MavenProject project, final String replacedVersion, final Artifact artifact) { - return project.getGroupId().equals(artifact.getGroupId()) && - project.getArtifactId().equals(artifact.getArtifactId()) && - replacedVersion.equals(PropertyResolver.resolveValue(artifact.getVersion(), project.getProperties(), systemEnvVars)); - } - - - /** - * Given a String version (which may be a final or -SNAPSHOT version) return a - * version string mangled to include a `+normalized-branch-name-SNAPSHOT format version. - * - * @param version The base version (ie, 1.0.2-SNAPSHOT) - * @param branchName to be normalized - * @return A mangled version string with the branchname and -SNAPSHOT. - */ - public String getAsBranchSnapshotVersion(final String version, final String branchName) { - String branchNameSanitized = otherBranchVersionDelimiter + branchName.replaceAll("[^0-9A-Za-z-.]", "-") + "-SNAPSHOT"; - if(version.endsWith(branchNameSanitized)) { - return version; - } - return version.replace("-SNAPSHOT", "") + branchNameSanitized; - } - -} diff --git a/src/main/java/com/e_gineering/maven/gitflowhelper/PromoteMasterMojo.java b/src/main/java/com/e_gineering/maven/gitflowhelper/PromoteMasterMojo.java index c2353a4..3df1c1f 100644 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/PromoteMasterMojo.java +++ b/src/main/java/com/e_gineering/maven/gitflowhelper/PromoteMasterMojo.java @@ -1,5 +1,7 @@ package com.e_gineering.maven.gitflowhelper; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; diff --git a/src/main/java/com/e_gineering/maven/gitflowhelper/RetargetDeployMojo.java b/src/main/java/com/e_gineering/maven/gitflowhelper/RetargetDeployMojo.java index a111bc3..4bb30ee 100644 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/RetargetDeployMojo.java +++ b/src/main/java/com/e_gineering/maven/gitflowhelper/RetargetDeployMojo.java @@ -1,5 +1,9 @@ package com.e_gineering.maven.gitflowhelper; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.InvalidRepositoryException; +import org.apache.maven.artifact.versioning.VersionRange; +import org.apache.maven.model.DeploymentRepository; import org.apache.maven.model.DistributionManagement; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -37,7 +41,16 @@ protected void execute(final GitBranchInfo gitBranchInfo) throws MojoExecutionEx String otherBranchesToDeploy = resolveExpression(otherDeployBranchPattern); if (!"".equals(otherBranchesToDeploy) && gitBranchInfo.getName().matches(otherBranchesToDeploy)) { setTargetSnapshots(); - // Only break if we set something! + + project.setVersion(getAsBranchSnapshotVersion(project.getVersion(), gitBranchInfo.getName())); + + // Update any attached artifacts. + updateArtifactVersion(project.getArtifact(), gitBranchInfo.getName()); + for (Artifact a : project.getAttachedArtifacts()) { + updateArtifactVersion(a, gitBranchInfo.getName()); + } + + getLog().info("Artifact versions updated with build metadata: " + getAsBranchSnapshotVersion("", gitBranchInfo.getName())); break; } } @@ -48,6 +61,35 @@ protected void execute(final GitBranchInfo gitBranchInfo) throws MojoExecutionEx } } + /** + * Updates artifact versions for a given branch name. + * @param a artifact to update (may be null) + * @param branchName the branch name + */ + private void updateArtifactVersion(Artifact a, String branchName) { + if (a != null) { + a.setVersion(getAsBranchSnapshotVersion(a.getVersion(), branchName)); + try { + a.setVersionRange(VersionRange.createFromVersion(a.getVersion())); + } catch (UnsupportedOperationException uoe) { // Some artifact types don't like this. + getLog().debug("Unable to update VersionRange for artifact."); + } + } + } + + + /** + * Given a String version (which may be a final or -SNAPSHOT version) return a + * version version string mangled to include a `+normalized-branch-name-SNAPSHOT format version. + * + * @param version The base version (ie, 1.0.2-SNAPSHOT) + * @param branchName to be normalized + * @return A mangled version string with the branchname and -SNAPSHOT. + */ + private String getAsBranchSnapshotVersion(final String version, final String branchName) { + return version.replace("-SNAPSHOT", "") + otherBranchVersionDelimiter + branchName.replaceAll("[^0-9A-Za-z-.]", "-") + "-SNAPSHOT"; + } + private void setTargetSnapshots() throws MojoExecutionException, MojoFailureException { getLog().info("Setting snapshot artifact repository to: [" + snapshotDeploymentRepository + "]"); project.setSnapshotArtifactRepository(getDeploymentRepository(snapshotDeploymentRepository)); diff --git a/src/main/java/com/e_gineering/maven/gitflowhelper/UpdateStageDependenciesMojo.java b/src/main/java/com/e_gineering/maven/gitflowhelper/UpdateStageDependenciesMojo.java index ebd8f29..74d84b2 100644 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/UpdateStageDependenciesMojo.java +++ b/src/main/java/com/e_gineering/maven/gitflowhelper/UpdateStageDependenciesMojo.java @@ -2,6 +2,7 @@ import org.apache.commons.io.FileUtils; import org.apache.maven.RepositoryUtils; +import org.apache.maven.artifact.InvalidRepositoryException; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Component; @@ -21,6 +22,7 @@ import java.io.File; import java.io.IOException; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -49,8 +51,8 @@ protected void execute(final GitBranchInfo branchInfo) throws MojoExecutionExcep boolean itemsPurged = false; try { - DefaultDependencyResolutionRequest projectDepsRequest = new DefaultDependencyResolutionRequest(project, reresolveSession); - DependencyResolutionResult depencencyResult = dependenciesResolver.resolve(projectDepsRequest); + DependencyResolutionResult depencencyResult = dependenciesResolver.resolve( + new DefaultDependencyResolutionRequest(project, reresolveSession)); for (Dependency dependency : depencencyResult.getResolvedDependencies()) { if (!dependency.getArtifact().isSnapshot()) { diff --git a/src/main/java/com/e_gineering/maven/gitflowhelper/properties/CircularDefinitionPreventer.java b/src/main/java/com/e_gineering/maven/gitflowhelper/properties/CircularDefinitionPreventer.java index e31c4c9..6982f07 100644 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/properties/CircularDefinitionPreventer.java +++ b/src/main/java/com/e_gineering/maven/gitflowhelper/properties/CircularDefinitionPreventer.java @@ -19,11 +19,7 @@ * under the License. */ -import java.util.HashSet; -import java.util.Iterator; -import java.util.LinkedList; -import java.util.List; -import java.util.Set; +import java.util.*; /** * Shamelessly cribbed from https://raw.githubusercontent.com/mojohaus/properties-maven-plugin/master/src/main/java/org/codehaus/mojo/properties/CircularDefinitionPreventer.java diff --git a/src/test/java/com/e_gineering/maven/gitflowhelper/OtherBranchIT.java b/src/test/java/com/e_gineering/maven/gitflowhelper/OtherBranchIT.java index 2f85b84..245a105 100644 --- a/src/test/java/com/e_gineering/maven/gitflowhelper/OtherBranchIT.java +++ b/src/test/java/com/e_gineering/maven/gitflowhelper/OtherBranchIT.java @@ -13,10 +13,9 @@ public class OtherBranchIT extends AbstractIntegrationTest { public void featureSnapshotSemVer() throws Exception { Verifier verifier = createVerifier("/project-stub", "origin/feature/poc/my-feature-branch", "5.0.0-SNAPSHOT"); try { - verifier.addCliOption("-Dexpression=project.version"); - verifier.executeGoal("help:evaluate"); - - verifier.verifyTextInLog("Updating project com.e-gineering:gitflow-helper-maven-plugin-test-stub:5.0.0-SNAPSHOT to: 5.0.0+origin-feature-poc-my-feature-branch-SNAPSHOT"); + verifier.executeGoal("deploy"); + + verifier.verifyTextInLog("Artifact versions updated with build metadata: +origin-feature-poc-my-feature-branch-SNAPSHOT"); verifier.verifyErrorFreeLog(); } finally { verifier.resetStreams(); @@ -27,9 +26,9 @@ public void featureSnapshotSemVer() throws Exception { public void featureSemVer() throws Exception { Verifier verifier = createVerifier("/project-stub", "origin/feature/poc/my-feature-branch.with.other.identifiers", "5.0.1"); try { - verifier.executeGoal("initialize"); - - verifier.verifyTextInLog("Updating project com.e-gineering:gitflow-helper-maven-plugin-test-stub:5.0.1 to: 5.0.1+origin-feature-poc-my-feature-branch.with.other.identifiers-SNAPSHOT"); + verifier.executeGoal("deploy"); + + verifier.verifyTextInLog("Artifact versions updated with build metadata: +origin-feature-poc-my-feature-branch.with.other.identifiers-SNAPSHOT"); verifier.verifyErrorFreeLog(); } finally { verifier.resetStreams(); @@ -55,8 +54,8 @@ public void automagicVersionDependenciesResolve() throws Exception { Verifier verifier = createVerifier("/project-stub", "origin/feature/poc/long-running", "2.0.0"); try { verifier.executeGoal("deploy"); - - verifier.verifyTextInLog("Updating project com.e-gineering:gitflow-helper-maven-plugin-test-stub:2.0.0 to: 2.0.0+origin-feature-poc-long-running-SNAPSHOT"); + + verifier.verifyTextInLog("Artifact versions updated with build metadata: +origin-feature-poc-long-running-SNAPSHOT"); verifier.verifyErrorFreeLog(); } finally { verifier.resetStreams(); @@ -70,8 +69,7 @@ public void automagicVersionDependenciesResolve() throws Exception { verifier.getCliOptions().add("-Dplugin.stub.version=2.0.0+origin-feature-poc-long-running-SNAPSHOT"); verifier.executeGoal("deploy"); - // the alt project uses the `-` as the version delimiter, rather than `+` - verifier.verifyTextInLog("Updating project com.e-gineering:gitflow-helper-maven-plugin-test-stub-alt:2.0.0 to: 2.0.0-origin-feature-poc-long-running-SNAPSHOT"); + verifier.verifyTextInLog("Artifact versions updated with build metadata: -origin-feature-poc-long-running-SNAPSHOT"); verifier.verifyErrorFreeLog(); } finally { verifier.resetStreams(); @@ -83,7 +81,8 @@ public void attachDeployed() throws Exception { Verifier verifier = createVerifier("/project-stub", "origin/feature/poc/reattach", "5.0.0-SNAPSHOT"); try { verifier.executeGoal("deploy"); - verifier.verifyTextInLog("Updating project com.e-gineering:gitflow-helper-maven-plugin-test-stub:5.0.0-SNAPSHOT to: 5.0.0+origin-feature-poc-reattach-SNAPSHOT"); + + verifier.verifyTextInLog("Artifact versions updated with build metadata: +origin-feature-poc-reattach-SNAPSHOT"); verifier.verifyErrorFreeLog(); } finally { verifier.resetStreams(); @@ -92,51 +91,6 @@ public void attachDeployed() throws Exception { verifier = createVerifier("/project-stub", "origin/feature/poc/reattach", "5.0.0-SNAPSHOT"); try { verifier.executeGoals(Arrays.asList("validate", "gitflow-helper:attach-deployed")); - verifier.verifyTextInLog("Updating project com.e-gineering:gitflow-helper-maven-plugin-test-stub:5.0.0-SNAPSHOT to: 5.0.0+origin-feature-poc-reattach-SNAPSHOT"); - verifier.verifyErrorFreeLog(); - } finally { - verifier.resetStreams(); - } - } - - @Test - public void buildMultiModuleProject() throws Exception { - Verifier verifier = createVerifier("/multi-module-project-stub", "origin/feature/poc/test-partial-multi-module", "5.0.0-SNAPSHOT"); - try { - verifier.executeGoal("install"); - - // Verify that all 3 maven projects that are part of the multi-module build are recognized - verifier.verifyTextInLog("Updating project com.e-gineering:gitflow-helper-maven-plugin-multi-module-parent-stub:5.0.0-SNAPSHOT to: 5.0.0+origin-feature-poc-test-partial-multi-module-SNAPSHOT"); - verifier.verifyTextInLog("Updating project com.e-gineering:gitflow-helper-maven-plugin-multi-module-child1-stub:5.0.0-SNAPSHOT to: 5.0.0+origin-feature-poc-test-partial-multi-module-SNAPSHOT"); - verifier.verifyTextInLog("Updating project com.e-gineering:gitflow-helper-maven-plugin-multi-module-child2-stub:5.0.0-SNAPSHOT to: 5.0.0+origin-feature-poc-test-partial-multi-module-SNAPSHOT"); - - verifier.verifyErrorFreeLog(); - } finally { - verifier.resetStreams(); - } - } - - @Test - public void partialBuildMultiModuleProject() throws Exception { - // Partial builds of a multi-module project *must* be preceded by a full build - buildMultiModuleProject(); - - // After a full build, try to build module child2 in isolation - Verifier verifier = createVerifier("/multi-module-project-stub", "origin/feature/poc/test-partial-multi-module", "5.0.0-SNAPSHOT"); - try { - // Only build module child2 (thus this being a partial build) - verifier.addCliOption("-pl child2"); - verifier.executeGoal("install"); - - // Verify that the plugin detects that we are doing a partial build - verifier.verifyTextInLog("Found top level project, but outside reactor: com.e-gineering:gitflow-helper-maven-plugin-multi-module-parent-stub"); - - // Verify that the dependency to a module not part of the current build *is* being rewritten - verifier.verifyTextInLog("Updating outside-reactor project com.e-gineering:gitflow-helper-maven-plugin-multi-module-child1-stub:5.0.0-SNAPSHOT to: 5.0.0+origin-feature-poc-test-partial-multi-module-SNAPSHOT"); - - // Verify that the project that *is* part of the reactor is left alone in the construction of the cross-walk map. - verifier.verifyTextInLog("Skipping com.e-gineering:gitflow-helper-maven-plugin-multi-module-child2-stub: already part of reactor"); - verifier.verifyErrorFreeLog(); } finally { verifier.resetStreams(); diff --git a/src/test/java/com/e_gineering/maven/gitflowhelper/OtherBranchTest.java b/src/test/java/com/e_gineering/maven/gitflowhelper/OtherBranchTest.java deleted file mode 100644 index f4d8102..0000000 --- a/src/test/java/com/e_gineering/maven/gitflowhelper/OtherBranchTest.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.e_gineering.maven.gitflowhelper; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.runner.RunWith; -import org.junit.runners.BlockJUnit4ClassRunner; - -@RunWith(BlockJUnit4ClassRunner.class) -public class OtherBranchTest { - - private final String baseVersion = "1.0.2"; - private final String baseSnapshotVersion = "1.0.2-SNAPSHOT"; - private final String branchName = "feature/other-branch-name"; - private final String expectedSnapshotResult = "1.0.2+feature-other-branch-name-SNAPSHOT"; - - private OtherBranchVersionExtension getExtension() { - OtherBranchVersionExtension extension = new OtherBranchVersionExtension(); - extension.otherBranchVersionDelimiter = "+"; - return extension; - } - - @Test - public void assertOtherBranchNameIsPrefixedBeforeSnapshot() { - OtherBranchVersionExtension extension = getExtension(); - Assert.assertEquals(expectedSnapshotResult, extension.getAsBranchSnapshotVersion(baseSnapshotVersion,branchName)); - } - - @Test - public void assertOtherBranchNameIsOnlyPrefixedBeforeSnapshotOneTime() { - OtherBranchVersionExtension extension = getExtension(); - Assert.assertEquals(expectedSnapshotResult, extension.getAsBranchSnapshotVersion(extension.getAsBranchSnapshotVersion(baseSnapshotVersion,branchName),branchName)); - } -} diff --git a/src/test/java/com/e_gineering/maven/gitflowhelper/RetargetDeployIT.java b/src/test/java/com/e_gineering/maven/gitflowhelper/RetargetDeployIT.java index 526bbbe..f3ffe7f 100644 --- a/src/test/java/com/e_gineering/maven/gitflowhelper/RetargetDeployIT.java +++ b/src/test/java/com/e_gineering/maven/gitflowhelper/RetargetDeployIT.java @@ -123,6 +123,7 @@ public void masterTargetsReleases() throws Exception { @Test public void othersUnsetRepos() throws Exception { + // Deploy a hotfix to the test-releases. Verifier verifier = createVerifier("/project-stub", "feature/undeployable", "3.5.0-SNAPSHOT"); try { verifier.executeGoal("deploy"); diff --git a/src/test/resources/multi-module-project-stub/child1/pom.xml b/src/test/resources/multi-module-project-stub/child1/pom.xml deleted file mode 100644 index dd6c620..0000000 --- a/src/test/resources/multi-module-project-stub/child1/pom.xml +++ /dev/null @@ -1,16 +0,0 @@ - - - 4.0.0 - - com.e-gineering - gitflow-helper-maven-plugin-multi-module-child1-stub - - - jar - - - com.e-gineering - gitflow-helper-maven-plugin-multi-module-parent-stub - ${stub.project.version} - - diff --git a/src/test/resources/multi-module-project-stub/child1/src/build/resources/master.build.properties b/src/test/resources/multi-module-project-stub/child1/src/build/resources/master.build.properties deleted file mode 100644 index 09237d3..0000000 --- a/src/test/resources/multi-module-project-stub/child1/src/build/resources/master.build.properties +++ /dev/null @@ -1,3 +0,0 @@ -build.branch.type=master -build.branch.string=${project.version}-type-${build.branch.type} -${build.branch.type}-foo=foomanchu! diff --git a/src/test/resources/multi-module-project-stub/child1/src/build/resources/my-text-file.txt b/src/test/resources/multi-module-project-stub/child1/src/build/resources/my-text-file.txt deleted file mode 100644 index 0c759a4..0000000 --- a/src/test/resources/multi-module-project-stub/child1/src/build/resources/my-text-file.txt +++ /dev/null @@ -1 +0,0 @@ -test123 \ No newline at end of file diff --git a/src/test/resources/multi-module-project-stub/child1/src/main/java/HelloWorld.java b/src/test/resources/multi-module-project-stub/child1/src/main/java/HelloWorld.java deleted file mode 100644 index 7edc00d..0000000 --- a/src/test/resources/multi-module-project-stub/child1/src/main/java/HelloWorld.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Simple HelloWorld to stuff into a .jar for this project-stub. - */ -public class HelloWorld { - public static void main(String[] args) { - System.out.println("Hello, World."); - } -} \ No newline at end of file diff --git a/src/test/resources/multi-module-project-stub/child1/src/main/resources/project.properties b/src/test/resources/multi-module-project-stub/child1/src/main/resources/project.properties deleted file mode 100644 index 3715d25..0000000 --- a/src/test/resources/multi-module-project-stub/child1/src/main/resources/project.properties +++ /dev/null @@ -1 +0,0 @@ -app.buildinfo=${build.branch.string} \ No newline at end of file diff --git a/src/test/resources/multi-module-project-stub/child2/pom.xml b/src/test/resources/multi-module-project-stub/child2/pom.xml deleted file mode 100644 index 3eac9bd..0000000 --- a/src/test/resources/multi-module-project-stub/child2/pom.xml +++ /dev/null @@ -1,24 +0,0 @@ - - - 4.0.0 - - com.e-gineering - gitflow-helper-maven-plugin-multi-module-child2-stub - - - jar - - - com.e-gineering - gitflow-helper-maven-plugin-multi-module-parent-stub - ${stub.project.version} - - - - - com.e-gineering - gitflow-helper-maven-plugin-multi-module-child1-stub - ${stub.project.version} - - - diff --git a/src/test/resources/multi-module-project-stub/child2/src/build/resources/master.build.properties b/src/test/resources/multi-module-project-stub/child2/src/build/resources/master.build.properties deleted file mode 100644 index 09237d3..0000000 --- a/src/test/resources/multi-module-project-stub/child2/src/build/resources/master.build.properties +++ /dev/null @@ -1,3 +0,0 @@ -build.branch.type=master -build.branch.string=${project.version}-type-${build.branch.type} -${build.branch.type}-foo=foomanchu! diff --git a/src/test/resources/multi-module-project-stub/child2/src/build/resources/my-text-file.txt b/src/test/resources/multi-module-project-stub/child2/src/build/resources/my-text-file.txt deleted file mode 100644 index 0c759a4..0000000 --- a/src/test/resources/multi-module-project-stub/child2/src/build/resources/my-text-file.txt +++ /dev/null @@ -1 +0,0 @@ -test123 \ No newline at end of file diff --git a/src/test/resources/multi-module-project-stub/child2/src/main/java/HelloWorld.java b/src/test/resources/multi-module-project-stub/child2/src/main/java/HelloWorld.java deleted file mode 100644 index 7edc00d..0000000 --- a/src/test/resources/multi-module-project-stub/child2/src/main/java/HelloWorld.java +++ /dev/null @@ -1,8 +0,0 @@ -/** - * Simple HelloWorld to stuff into a .jar for this project-stub. - */ -public class HelloWorld { - public static void main(String[] args) { - System.out.println("Hello, World."); - } -} \ No newline at end of file diff --git a/src/test/resources/multi-module-project-stub/child2/src/main/resources/project.properties b/src/test/resources/multi-module-project-stub/child2/src/main/resources/project.properties deleted file mode 100644 index 3715d25..0000000 --- a/src/test/resources/multi-module-project-stub/child2/src/main/resources/project.properties +++ /dev/null @@ -1 +0,0 @@ -app.buildinfo=${build.branch.string} \ No newline at end of file diff --git a/src/test/resources/multi-module-project-stub/pom.xml b/src/test/resources/multi-module-project-stub/pom.xml deleted file mode 100644 index 1d3ba74..0000000 --- a/src/test/resources/multi-module-project-stub/pom.xml +++ /dev/null @@ -1,134 +0,0 @@ - - - 4.0.0 - - com.e-gineering - gitflow-helper-maven-plugin-multi-module-parent-stub - ${stub.project.version} - - pom - - - child1 - child2 - - - - 1.8 - 1.8 - UTF-8 - - - - - releases - file:${it.repository.basedir}/releases - false - true - - - test-releases - file:${it.repository.basedir}/test-releases - false - true - - - snapshots - file:${it.repository.basedir}/snapshots - true - false - - - - - - - src/main/resources - true - - *.properties - - - - - - - - org.codehaus.mojo - build-helper-maven-plugin - 3.0.0 - - - attach-text-file - - attach-artifact - - - - - src/build/resources/my-text-file.txt - text-file - - - - - - - - - - - - com.e-gineering - gitflow-helper-maven-plugin - ${version.gitflow.plugin} - true - - releases - test-releases - snapshots - src/build/resources/master.build.properties - - support - - - release - - - hotfix - - - develop - - - other - - - undefined - - (origin/)?feature/poc/.* - - - - - enforce-versions - set-properties - retarget-deploy - update-stage-dependencies - - - - promote-master - - promote-master - - - (origin/)?master - - - - - - - -