diff --git a/.travis.yml b/.travis.yml index 02b6a79..bb062d4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,7 @@ language: java script: mvn verify jdk: - - openjdk7 - - oraclejdk8 + - openjdk8 cache: directories: @@ -14,3 +13,6 @@ notifications: email: recipients: - eg.oss@e-gineering.com + +after_success: + - mvn jacoco:report coveralls:report diff --git a/README.md b/README.md index e5a1a05..f58bdc6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,4 @@ -# gitflow-helper-maven-plugin [![Build Status](https://travis-ci.org/egineering-llc/gitflow-helper-maven-plugin.svg?branch=master)](https://travis-ci.org/egineering-llc/gitflow-helper-maven-plugin) +# gitflow-helper-maven-plugin [![Build Status](https://travis-ci.org/egineering-llc/gitflow-helper-maven-plugin.svg?branch=master)](https://travis-ci.org/egineering-llc/gitflow-helper-maven-plugin) [![Coverage Status](https://coveralls.io/repos/github/egineering-llc/gitflow-helper-maven-plugin/badge.svg)](https://coveralls.io/github/egineering-llc/gitflow-helper-maven-plugin) A build extension and plugin that helps Maven play nicely with gitflow projects, CI servers and local development. @@ -10,6 +10,7 @@ It does so by: * SCM tagging builds for master and support branches. You can use the project SCM definition, or if you omit it, you can resolve the CI server's repository connection information. (Zero Maven scm configuration necessary) * Promoting existing tested (staged) artifacts for release, rather than re-building the artifacts. Eliminates the risk of accidental master merges or commits resulting in untested code being released, and provides digest hash traceability for the history of artifacts. * Enabling the decoupling of repository deployment and execution environment delivery based on the current git branch. + * Allowing for long-running non-release branches to be deployed to snapshots, automatically reversioning the artifacts based off the branch name. * Automated deployment, promotion, and delivery of projects without the [maven-release-plugin](http://maven.apache.org/maven-release/maven-release-plugin/) or some other [*almost there* solution](https://axelfontaine.com/blog/final-nail.html). * Customizing maven project and system properties based upon the current branch being built. This allows test cases to target different execution environments without changing the artifact results. * Enabling automatic purging and resolving (force update) of 'release' and 'hotfix' release versioned dependencies resolved from the 'stage' repository. @@ -24,6 +25,7 @@ This plugin solves a few specific issues common in consolidated Hudson/Jenkins C 4. Set arbitrary project properties based upon the type of GIT branch being built. 5. Reliably tag deploy builds from the master and support branches 6. Enable split 'deploy' vs. 'deliver' maven CI job configuration, without rebuilding artifacts for the 'deliver' phase. + 7. Allow for deployment of long-running feature branches to repositories without having to mangle the version in the pom.xml. In addition to supporting these goals for the project, this plugin does it in a manner that tries to be as effortless (yet configurable) as possible. If you use non-standard gitflow branch names (emer instead of hotfix), this plugin supports that. If you don't want to do version enforcement, this plugin supports that. @@ -107,14 +109,16 @@ All of the solutions to these issues are implemented independently in different localnexus-releases localnexus-stage localnexus-snapshots + + (origin/)feature/poc/.* enforce-versions + set-properties retarget-deploy update-stage-dependencies - set-properties tag-master promote-master @@ -124,7 +128,6 @@ All of the solutions to these issues are implemented independently in different foo/bar/emer.props foo/bar/test.props foo/bar/dev.props - foo/bar/feat.props foo/bar/ci.props foo/bar/local.props @@ -144,9 +147,9 @@ One common stumbling block for teams adjusting to gitflow with Maven projects is In practice, the Maven versions should: * Be synchronized with release branch and hotfix branch names. - * Never be -SNAPSHOT in the master, support, release, or hotfix branches. Also, no -SNAPSHOT parent or (plugin) dependencies are allowed. (This condition may be disabled by setting `enforceNonSnapshots` = `false`.) - * Always be -SNAPSHOT in the feature and develop branches. - * Be irrelevant if there's no git branch resolvable from your environment. + * Never be -SNAPSHOT in the master, support, release, or hotfix branches. Also, no -SNAPSHOT parent or (plugin) dependencies are allowed. + * Always be -SNAPSHOT in the develop branch. + * Be irrelevant if there's no git branch resolvable from your environment or working in a branch which is not deployed to remote repositories. The `enforce-versions` goal asserts these semantics when it can resolve the `gitBranchExpression`. @@ -166,9 +169,21 @@ The following properties change the behavior of this goal: | supportBranchPattern | (origin/)?support/(.*) | No | Regex. When matches, signals a support branch (long term master-equivalent for older release) being built. Last subgroup, if present, must be start of the Maven project version. | | releaseBranchPattern | (origin/)?release/(.*) | No | Regex. When matched, signals a release branch being built. Last subgroup, if present, must match the Maven project version. | | hotfixBranchPattern | (origin/)?hotfix/(.*) | No | Regex. When matched, signals a hotfix branch is being built. Last subgroup, if present, must match the Maven project version. | -| featureOrBugfixBranchPattern | (origin/)?(?:feature|bugfix)/(.*) | Yes | Regex. When matched, signals a feature or bugfix branch is being built. | | developmentBranchPattern | (origin/)?develop | Yes | Regex. When matched, signals a development branch is being built. Note the lack of a subgroup. | +## Goal: `set-properties` (Dynamically Set Maven Project / System Properties) + +Some situations with automated testing (and integration testing in particular) demand changing configuration properties +based upon the branch type being built. This is a common necessity when configuring automated DB refactorings as part of +a build, or needing to setup / configure datasources for automated tests to run against. + +The `set-properties` goal allows for setting project (or system) properties, dynamically based on the detected git +branch being built. Properties can be specified as a Properties collection in plugin configuration, or can be loaded +from a property file during the build. Both property key names and property values will have placeholders resolved. + +Multiple executions can be configured, and each execution can target different scopes (system or project), and can load +properties from files with an assigned keyPrefix, letting you name-space properties from execution ids. + ## Goal: `retarget-deploy` (Branch Specific Deploy Targets & Staging) @@ -185,11 +200,10 @@ plugins in the build process (deploy, site-deploy, etc.) will use the repositori | Property | Default Value | Description | | -------- | ------------- | ----------- | | gitBranchExpression | current git branch resolved from SCM or ${env.GIT_BRANCH} | Maven property expression to resolve in order to determine the current git branch | -| deploySnapshotTypeBranches | `false` | When `true`, feature branches will also be deployed to the snapshots repository. | | releaseDeploymentRepository | n/a | The repository to use for releases. (Builds with a GIT_BRANCH matching `masterBranchPattern` or `supportBranchPattern`) | | stageDeploymentRepository | n/a | The repository to use for staging. (Builds with a GIT_BRANCH matching `releaseBranchPattern` or `hotfixBranchPattern`) | | snapshotDeploymentRepository | n/a | The repository to use for snapshots. (Builds matching `developmentBranchPattern`) | - +| otherDeploymentBranchPattern | n/a | Regex. When matched, the branch name is normalized and any artifacts produced by the build will include the normalized branch name and -SNAPSHOT. Deployment will target the snapshot repository | **The repository properties should follow the following format**, `id::layout::url::uniqueVersion`. @@ -238,20 +252,15 @@ Can be replaced with the following plugin configuration, which also introduces t ... +### Deploying non-release (OTHER) type branches as -SNAPSHOT releases. -## Goal: `set-properties` (Dynamically Set Maven Project / System Properties) - -Some situations with automated testing (and integration testing in particular) demand changing configuration properties -based upon the branch type being built. This is a common necessity when configuring automated DB refactorings as part of -a build, or needing to setup / configure datasources for automated tests to run against. - -The `set-properties` goal allows for setting project (or system) properties, dynamically based on the detected git -branch being built. Properties can be specified as a Properties collection in plugin configuration, or can be loaded -from a property file during the build. Both property key names and property values will have placeholders resolved. - -Multiple executions can be configured, and each execution can target different scopes (system or project), and can load -properties from files with an assigned keyPrefix, letting you name-space properties from execution ids. - +In addition to setting up repository targets for release branches, the `retarget-depoy` branch can deploy other branches +matching the `otherDeploymentBranchPattern` as -SNAPSHOT artifacts which include the branch name as build metadata. +This is loosely based on the [semVer](https://semver.org) semantic version scheme, in that the plugin will reversion any +artifacts to be produced with `+feature-branch-name-normalized-SNAPSHOT` where any characters not in `[0-9A-Za-z-.]` will +be replaced with `-`. Artifact versions for feature branches will _always_ be -SNAPSHOT, and will _always_ target the +Snapshots repository. The intent for this configuration setting is to provide a way for long-running branches (matching +a naming convention you define) can be published to a SNAPSHOT repo for use by other projects. ## Goal: `update-stage-dependencies` (Force update of dependency staged Releases) @@ -339,8 +348,8 @@ The following table describes the git branch expression -> repository used for r | supportBranchPattern | release | | releaseBranchPattern | stage | | hotfixBranchPattern | stage | -| featureOrBugfixBranchPattern | snapshots | | developmentBranchPattern | snapshots | +| otherBranchesToDeploy | snapshots | | All Others | local | As an example, assume you have two CI jobs. @@ -361,15 +370,40 @@ it's building. The attach-deploy will 'clean' the maven project, then download t that the first build deployed into. Once they're attached to the project, the `jboss-as:deploy-only` goal will deliver the artifacts built by the first job into a jboss application server. +# Additional Notes +## How Git branch name resolution works +1. If the `` sections of the pom points to a git repository, `git symbolic-ref HEAD` to is used to check the local branch name. +2. If the `symbolic-ref` fails then it's likely due to a detached HEAD. + This is typical of CI servers like Jenkins, where the commit hash that was just pushed is pulled. + This can also be done as a consequene of attempting to rebuild from a tag, without branching, or in some + workflows where code reviews are done without branches. + + In the case of a detached HEAD the plugin will: + * Resolve the HEAD to a commit using `git rev-parse HEAD`. + * `git show-ref` to resolve which (local/remote) branches point to the commit. + * If the detached HEAD commit resolves to a single branch type, it uses that branch name. +3. If the first two methods fail, the plugin attempts to resolve `${env.GIT_BRANCH}`. + +## 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`: +``` +export GIT_BRANCH=origin/feature/mybranch-foo-bar +mvnDebug -Dstub.project.version=5.0.0-SNAPSHOT -DotherBranchDeploy=semver -DallowGitflowPluginSnapshot=true deploy +``` +You can then connect a remote debugger and step through the plugin code. -# Resolving the Git branch name -As stated before, the plugin determines what to do by resolving the Git branch name. +## Building with IntelliJ IDEA notes +### To Debug Test Code: +Configure the Maven commandline to include +`-DforkMode=never` You will likely get warnings when you run maven with this argument. - * The first try is a `git symbolic-ref HEAD` to check the local branch name. If it's found, that's the branch name that's used. - * If the `symbolic-ref` fails then it's probably due to a detached HEAD. This typically happens on Jenkins, when it simply checks out the commit hash that was just pushed. - Or, it's because of a developer doing a `git checkout origin/feature/x`, e.g. when doing a code review and no local branch is required. - In such a case: - * The plugin will first resolve the HEAD to a commit using `git rev-parse HEAD`. - * Next, it will do a `git show-ref` to check which (local/remote) branches point to the commit. - * If it can resolve the commit to a single branch type (e.g. develop or master) then that's the branch name that's used. - * If all of the above fails, `${env.GIT_BRANCH}` is tried. +### To inspect code-coverage results from Integration Tests: +* Select the **Analyze** -> **Show Coverage Data** menu. +* In the dialog that appears, click the **+** in the upper left corner to `Add (Insert)`, and browse to `target/jacoco.exec`. +* Selecting that file will show coverage data in the code editor. diff --git a/pom.xml b/pom.xml index 83e2ebd..7b2f854 100644 --- a/pom.xml +++ b/pom.xml @@ -8,7 +8,7 @@ com.e-gineering gitflow-helper-maven-plugin - 1.8.0 + 2.0.0 maven-plugin @@ -52,6 +52,8 @@ 1.7 1.7 UTF-8 + ${project.build.directory}/it-repositories + ${project.version} @@ -115,12 +117,6 @@ aether-util 0.9.0.M2 - - junit - junit - 4.8.2 - test - @@ -140,12 +136,6 @@ descriptor - - help-goal - - helpmojo - - @@ -179,6 +169,132 @@ + + testing + + true + + + + + src/test/java + + + src/test/resources + true + + + + + + org.jacoco + jacoco-maven-plugin + 0.8.1 + + + default-prepare-agent + + prepare-agent + + + + + pre-integration-test + + prepare-agent-integration + + + ${project.build.directory}/jacoco.exec + + + + + + + + org.apache.maven.plugins + maven-surefire-plugin + 2.22.0 + + + ${argLine} + + 1 + + + + + + org.apache.maven.plugins + maven-failsafe-plugin + 2.22.0 + + + + + ${it.repository.basedir}/local + ${project.version} + ${argLine} + + 1 + + + integration-test + verify + + + + + + + + org.apache.maven.plugins + maven-install-plugin + 2.5.2 + + + + ${it.repository.basedir}/local + ${project.groupId} + ${project.artifactId} + ${project.version} + ${pom.basedir}/pom.xml + ${project.build.directory}${file.separator}${project.build.finalName}.jar + + pre-integration-test + + install-file + + + + + + + + org.eluder.coveralls + coveralls-maven-plugin + 4.3.0 + + + + + + org.apache.maven.shared + maven-verifier + 1.6 + + + junit + junit + 4.8.2 + test + + + + eg.oss 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 cdeeda6..61b6008 100644 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/AbstractGitflowBasedRepositoryMojo.java +++ b/src/main/java/com/e_gineering/maven/gitflowhelper/AbstractGitflowBasedRepositoryMojo.java @@ -25,7 +25,15 @@ import org.eclipse.aether.util.repository.AuthenticationBuilder; import javax.annotation.Nullable; -import java.io.*; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.OutputStreamWriter; +import java.io.PrintWriter; import java.nio.file.Files; import java.util.ArrayList; import java.util.Collections; @@ -76,6 +84,9 @@ private static PrintWriter newPrintWriter(File catalog) throws FileNotFoundExcep @Parameter(defaultValue = "${repositorySystemSession}", required = true) RepositorySystemSession session; + @Parameter(property = "otherDeployBranchPattern", required = false) + String otherDeployBranchPattern; + @Component private EnhancedLocalRepositoryManagerFactory localRepositoryManagerFactory; diff --git a/src/main/java/com/e_gineering/maven/gitflowhelper/AbstractGitflowBranchMojo.java b/src/main/java/com/e_gineering/maven/gitflowhelper/AbstractGitflowBranchMojo.java index db8d964..9cabed6 100644 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/AbstractGitflowBranchMojo.java +++ b/src/main/java/com/e_gineering/maven/gitflowhelper/AbstractGitflowBranchMojo.java @@ -1,6 +1,5 @@ package com.e_gineering.maven.gitflowhelper; -import com.e_gineering.maven.gitflowhelper.properties.ExpansionBuffer; import com.e_gineering.maven.gitflowhelper.properties.PropertyResolver; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -42,18 +41,16 @@ public abstract class AbstractGitflowBranchMojo extends AbstractMojo { @Parameter(defaultValue = "(origin/)?develop", property = "developmentBranchPattern", required = true) private String developmentBranchPattern; - @Parameter(defaultValue = "(origin/)?(?:feature|bugfix)/(.*)", property = "featureOrBugfixBranchPattern", required = true) - private String featureOrBugfixBranchPattern; - // An expression that resolves to the git branch at run-time. // @Parameter tag causes property resolution to fail for patterns containing ${env.}. // The default value _must_ be provided programmaticially at run-time. @Parameter(property = "gitBranchExpression", required = false) private String gitBranchExpression; - @Parameter(defaultValue = "false", property = "deploySnapshotTypeBranches") - boolean deploySnapshotTypeBranches; - + /** + * If this is "equals" then exact version matching to branch name matching is preformed. + * Otherwise, this is treated as a "startsWith". + */ @Parameter(defaultValue = "equals", property = "releaseBranchMatchType", required = true) String releaseBranchMatchType; @@ -88,7 +85,7 @@ public void execute() throws MojoExecutionException, MojoFailureException { // Validate the match type. checkReleaseBranchMatchTypeParam(); - ScmUtils scmUtils = new ScmUtils(systemEnvVars, scmManager, project, getLog(), masterBranchPattern, supportBranchPattern, releaseBranchPattern, hotfixBranchPattern, developmentBranchPattern, featureOrBugfixBranchPattern); + ScmUtils scmUtils = new ScmUtils(systemEnvVars, scmManager, project, getLog(), masterBranchPattern, supportBranchPattern, releaseBranchPattern, hotfixBranchPattern, developmentBranchPattern); GitBranchInfo branchInfo = scmUtils.resolveBranchInfo(gitBranchExpression); getLog().debug("Building for: " + branchInfo); 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 8d3fd97..09030f2 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,6 @@ package com.e_gineering.maven.gitflowhelper; +import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.Execute; @@ -29,12 +30,19 @@ protected void execute(final GitBranchInfo gitBranchInfo) throws MojoExecutionEx attachExistingArtifacts(stageDeploymentRepository, true); break; } - case FEATURE_OR_BUGFIX_BRANCH: case DEVELOPMENT: { getLog().info("Attaching artifacts from snapshot repository..."); attachExistingArtifacts(snapshotDeploymentRepository, true); break; } + case OTHER: { + String otherBranchesToDeploy = resolveExpression(otherDeployBranchPattern); + if (!"".equals(otherBranchesToDeploy) && gitBranchInfo.getName().matches(otherBranchesToDeploy)) { + getLog().info("Attaching branch artifacts from snapshot repository..."); + attachExistingArtifacts(snapshotDeploymentRepository, true); + break; + } + } default: { getLog().info("Attaching Artifacts from local repository..."); // Use the 'local' repository to do this. diff --git a/src/main/java/com/e_gineering/maven/gitflowhelper/EnforceVersionsMojo.java b/src/main/java/com/e_gineering/maven/gitflowhelper/EnforceVersionsMojo.java index 9e44d83..5d76249 100644 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/EnforceVersionsMojo.java +++ b/src/main/java/com/e_gineering/maven/gitflowhelper/EnforceVersionsMojo.java @@ -17,7 +17,7 @@ /** * If there is an ${env.GIT_BRANCH} property, assert that the current ${project.version} is semantically correct for the - * git branch. Also, make sure there are no SNAPSHOT (plugin) dependencies. + * git branch. Also, make sure there are no SNAPSHOT (plugin) dependencies if enforceNonSnapshots = true. */ @Mojo(requiresDependencyCollection = ResolutionScope.TEST, name = "enforce-versions", defaultPhase = LifecyclePhase.VALIDATE) public class EnforceVersionsMojo extends AbstractGitflowBranchMojo { @@ -25,46 +25,42 @@ public class EnforceVersionsMojo extends AbstractGitflowBranchMojo { @Parameter(defaultValue = "true", property = "enforceNonSnapshots", required = true) private boolean enforceNonSnapshots; + @Parameter(defaultValue = "false", property = "allowGitflowPluginSnapshot", required = true) + private boolean allowGitflowPluginSnapshot; + @Override protected void execute(final GitBranchInfo branchInfo) throws MojoExecutionException, MojoFailureException { - if (GitBranchType.VERSIONED_TYPES.contains(branchInfo.getType())) { + if (branchInfo.isVersioned()) { getLog().debug("Versioned Branch: " + branchInfo); Matcher gitMatcher = Pattern.compile(branchInfo.getPattern()).matcher(branchInfo.getName()); // We're in a versioned branch, we expect a non-SNAPSHOT version in the POM. if (gitMatcher.matches()) { - if (enforceNonSnapshots) { - checkForSnapshots(branchInfo); + // Always assert that pom versions match our expectations. + if (hasSnapshotInModel(project)) { + throw new MojoFailureException("The current git branch: [" + branchInfo.getName() + "] is defined as a release branch. The maven project or one of its parents is currently a snapshot version."); } // Non-master version branches require a pom version match of some kind to the branch subgroups. if (gitMatcher.groupCount() > 0 && gitMatcher.group(gitMatcher.groupCount()) != null) { checkReleaseTypeBranchVersion(branchInfo, gitMatcher); } - } - } else if (GitBranchType.SNAPSHOT_TYPES.contains(branchInfo.getType()) && !ArtifactUtils.isSnapshot(project.getVersion())) { - throw new MojoFailureException("The current git branch: [" + branchInfo.getName() + "] is detected as a SNAPSHOT-type branch, and expects a maven project version ending with -SNAPSHOT. The maven project version found was: [" + project.getVersion() + "]"); - } else if (GitBranchType.FEATURE_OR_BUGFIX_BRANCH.equals(branchInfo.getType()) && deploySnapshotTypeBranches) { - checkFeatureOrBugfixBranchVersion(branchInfo); - } - } - private void checkFeatureOrBugfixBranchVersion(final GitBranchInfo branchInfo) throws MojoFailureException { - // For FEATURE and BUGFIX branches, check if the POM version includes the branch name - Matcher gitMatcher = Pattern.compile(branchInfo.getPattern()).matcher(branchInfo.getName()); - if (gitMatcher.matches()) { - String branchName = gitMatcher.group(gitMatcher.groupCount()); - String v = project.getVersion(); - String branchNameSnapshot = branchName + "-" + Artifact.SNAPSHOT_VERSION; - if (v.length() < branchNameSnapshot.length() || !v.regionMatches( - true, - v.length() - branchNameSnapshot.length(), - branchNameSnapshot, - 0, - branchNameSnapshot.length()) - ) { - throw new MojoFailureException("The project's version should end with [" + branchNameSnapshot + "]"); + // Optionally (default true) reinforce that no dependencies may be snapshots. + if (enforceNonSnapshots) { + Set snapshotDeps = getSnapshotDeps(); + if (!snapshotDeps.isEmpty()) { + throw new MojoFailureException("The current git branch: [" + branchInfo.getName() + "] is defined as a release branch. The maven project has the following SNAPSHOT dependencies: " + snapshotDeps.toString()); + } + + Set snapshotPluginDeps = getSnapshotPluginDeps(); + if (!snapshotPluginDeps.isEmpty()) { + throw new MojoFailureException("The current git branch: [" + branchInfo.getName() + "] is defined as a release branch. The maven project has the following SNAPSHOT plugin dependencies: " + snapshotPluginDeps.toString()); + } + } } + } else if (branchInfo.isSnapshot() && !ArtifactUtils.isSnapshot(project.getVersion())) { + throw new MojoFailureException("The current git branch: [" + branchInfo.getName() + "] is detected as a SNAPSHOT-type branch, and expects a maven project version ending with -SNAPSHOT. The maven project version found was: [" + project.getVersion() + "]"); } } @@ -94,22 +90,6 @@ private void checkReleaseTypeBranchVersion(final GitBranchInfo branchInfo, final } } - private void checkForSnapshots(final GitBranchInfo gitBranchInfo) throws MojoFailureException { - if (hasSnapshotInModel(project)) { - throw new MojoFailureException("The current git branch: [" + gitBranchInfo.getName() + "] is defined as a release branch. The maven project or one of its parents is currently a snapshot version."); - } - - Set snapshotDeps = getSnapshotDeps(); - if (!snapshotDeps.isEmpty()) { - throw new MojoFailureException("The current git branch: [" + gitBranchInfo.getName() + "] is defined as a release branch. The maven project has the following SNAPSHOT dependencies: " + snapshotDeps.toString()); - } - - Set snapshotPluginDeps = getSnapshotPluginDeps(); - if (!snapshotPluginDeps.isEmpty()) { - throw new MojoFailureException("The current git branch: [" + gitBranchInfo.getName() + "] is defined as a release branch. The maven project has the following SNAPSHOT plugin dependencies: " + snapshotPluginDeps.toString()); - } - } - private boolean hasSnapshotInModel(final MavenProject project) { MavenProject parent = project.getParent(); @@ -135,6 +115,10 @@ private Set getSnapshotPluginDeps() { Set snapshotPluginDeps = new HashSet<>(); for (Artifact plugin : project.getPluginArtifacts()) { if (plugin.isSnapshot()) { + if (allowGitflowPluginSnapshot && plugin.getGroupId().equals("com.e-gineering") && plugin.getArtifactId().equals("gitflow-helper-maven-plugin")) { + getLog().warn("SNAPSHOT com.e-gineering:gitflow-helper-maven-plugin detected. Allowing for this build."); + continue; + } getLog().debug("SNAPSHOT plugin dependency found: " + plugin.toString()); snapshotPluginDeps.add(plugin.toString()); } diff --git a/src/main/java/com/e_gineering/maven/gitflowhelper/GitBranchType.java b/src/main/java/com/e_gineering/maven/gitflowhelper/GitBranchType.java index 6703fce..bde0c98 100644 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/GitBranchType.java +++ b/src/main/java/com/e_gineering/maven/gitflowhelper/GitBranchType.java @@ -11,11 +11,10 @@ public enum GitBranchType { RELEASE, HOTFIX, DEVELOPMENT, - FEATURE_OR_BUGFIX_BRANCH, OTHER, UNDEFINED; static final EnumSet VERSIONED_TYPES = EnumSet.of(MASTER, SUPPORT, RELEASE, HOTFIX); - static final EnumSet SNAPSHOT_TYPES = EnumSet.of(DEVELOPMENT, FEATURE_OR_BUGFIX_BRANCH, OTHER); + static final EnumSet SNAPSHOT_TYPES = EnumSet.of(DEVELOPMENT); static final EnumSet UNIQUELY_VERSIONED_TYPES = EnumSet.of(SUPPORT, RELEASE, HOTFIX); } 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 6993f49..645a23d 100644 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/MasterPromoteExtension.java +++ b/src/main/java/com/e_gineering/maven/gitflowhelper/MasterPromoteExtension.java @@ -1,6 +1,5 @@ package com.e_gineering.maven.gitflowhelper; -import com.e_gineering.maven.gitflowhelper.properties.PropertyResolver; import org.apache.maven.AbstractMavenLifecycleParticipant; import org.apache.maven.MavenExecutionException; import org.apache.maven.execution.MavenSession; @@ -15,7 +14,6 @@ import org.codehaus.plexus.util.cli.CommandLineUtils; import org.codehaus.plexus.util.xml.Xpp3Dom; -import javax.annotation.Nullable; import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; @@ -168,10 +166,9 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti } logger.debug("Feature or Bugfix Branch Pattern: " + featureOrBugfixBranchPattern); - ScmUtils scmUtils = new ScmUtils(systemEnvVars, scmManager, session.getTopLevelProject(), new PlexusLoggerToMavenLog(logger), masterBranchPattern, supportBranchPattern, releaseBranchPattern, hotfixBranchPattern, developmentBranchPattern, featureOrBugfixBranchPattern); + ScmUtils scmUtils = new ScmUtils(systemEnvVars, scmManager, session.getTopLevelProject(), new PlexusLoggerToMavenLog(logger), masterBranchPattern, supportBranchPattern, releaseBranchPattern, hotfixBranchPattern, developmentBranchPattern); GitBranchInfo branchInfo = scmUtils.resolveBranchInfo(gitBranchExpression); - //GitBranchInfo branchInfo = ScmUtils.getGitBranchInfo(scmManager, session.getTopLevelProject(), new PlexusLoggerToMavenLog(logger), gitBranchExpression, masterBranchPattern, supportBranchPattern, releaseBranchPattern, hotfixBranchPattern, developmentBranchPattern, featureOrBugfixBranchPattern); boolean pruneBuild = false; if (branchInfo != null) { logger.info(branchInfo.toString()); 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 1c73400..c8d8789 100644 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/PromoteMasterMojo.java +++ b/src/main/java/com/e_gineering/maven/gitflowhelper/PromoteMasterMojo.java @@ -1,12 +1,13 @@ package com.e_gineering.maven.gitflowhelper; +import org.apache.maven.artifact.Artifact; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; import org.apache.maven.plugins.annotations.LifecyclePhase; import org.apache.maven.plugins.annotations.Mojo; /** - * If the build is being executed from a FEATURE_OR_BUGFIX, DEVELOPMENT, HOTFIX or RELEASE branch, attach an artifact containing a list of + * If the build is being executed from a DEVELOPMENT, HOTFIX or RELEASE branch, attach an artifact containing a list of * the attached artifacts. This list is then used for promoting artifacts from the stage repository to the release * repository. Or it can be used manually by the attach-deployed goal. * @@ -20,14 +21,21 @@ public class PromoteMasterMojo extends AbstractGitflowBasedRepositoryMojo { @Override protected void execute(final GitBranchInfo gitBranchInfo) throws MojoExecutionException, MojoFailureException { switch (gitBranchInfo.getType()) { - case FEATURE_OR_BUGFIX_BRANCH: case DEVELOPMENT: case HOTFIX: case RELEASE: { - // In order to use promote-master or attach-deployed, we need to build an artifactCatalog on deliverable branches. + // In order to use promote-master or attach-deployed, we need to build an artifactCatalog on deployable branches. attachArtifactCatalog(); break; } + // In order to use attach-deployed, we need to build the artifactCatalog. + case OTHER: { + String otherBranchesToDeploy = resolveExpression(otherDeployBranchPattern); + if (!"".equals(otherBranchesToDeploy) && gitBranchInfo.getName().matches(otherBranchesToDeploy)) { + attachArtifactCatalog(); + } + break; + } case SUPPORT: case MASTER: { 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 0fed318..8de6824 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,7 @@ package com.e_gineering.maven.gitflowhelper; +import org.apache.maven.artifact.Artifact; +import org.apache.maven.artifact.versioning.VersionRange; import org.apache.maven.model.DistributionManagement; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugin.MojoFailureException; @@ -20,38 +22,34 @@ protected void execute(final GitBranchInfo gitBranchInfo) throws MojoExecutionEx switch (gitBranchInfo.getType()) { case SUPPORT: case MASTER: { - getLog().info("Setting release artifact repository to: [" + releaseDeploymentRepository + "]"); - project.setSnapshotArtifactRepository(null); - project.setReleaseArtifactRepository(getDeploymentRepository(releaseDeploymentRepository)); - break; - } - case RELEASE: { - getLog().info("Setting release artifact repository to: [" + stageDeploymentRepository + "]"); - project.setSnapshotArtifactRepository(null); - project.setReleaseArtifactRepository(getDeploymentRepository(stageDeploymentRepository)); + setTargetRelease(); break; } + case RELEASE: case HOTFIX: { - getLog().info("Setting release artifact repository to: [" + stageDeploymentRepository + "]"); - project.setSnapshotArtifactRepository(null); - project.setReleaseArtifactRepository(getDeploymentRepository(stageDeploymentRepository)); + setTargetStage(); break; } case DEVELOPMENT: { - getLog().info("Setting snapshot artifact repository to: [" + snapshotDeploymentRepository + "]"); - project.setSnapshotArtifactRepository(getDeploymentRepository(snapshotDeploymentRepository)); - project.setReleaseArtifactRepository(null); + setTargetSnapshots(); break; } - case FEATURE_OR_BUGFIX_BRANCH: { - if (deploySnapshotTypeBranches) { - getLog().info("Setting snapshot artifact repository to: [" + snapshotDeploymentRepository + "]"); - project.setSnapshotArtifactRepository(getDeploymentRepository(snapshotDeploymentRepository)); - project.setReleaseArtifactRepository(null); - } else { - unsetRepos(); + case OTHER: { + String otherBranchesToDeploy = resolveExpression(otherDeployBranchPattern); + if (!"".equals(otherBranchesToDeploy) && gitBranchInfo.getName().matches(otherBranchesToDeploy)) { + setTargetSnapshots(); + + 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 semVer build metadata: " + getAsBranchSnapshotVersion("", gitBranchInfo.getName())); + break; } - break; } default: { unsetRepos(); @@ -60,6 +58,54 @@ 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", "") + "+" + 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)); + project.setReleaseArtifactRepository(null); + } + + private void setTargetStage() throws MojoExecutionException, MojoFailureException { + getLog().info("Setting release artifact repository to: [" + stageDeploymentRepository + "]"); + project.setSnapshotArtifactRepository(null); + project.setReleaseArtifactRepository(getDeploymentRepository(stageDeploymentRepository)); + } + + private void setTargetRelease() throws MojoExecutionException, MojoFailureException { + getLog().info("Setting release artifact repository to: [" + releaseDeploymentRepository + "]"); + project.setSnapshotArtifactRepository(null); + project.setReleaseArtifactRepository(getDeploymentRepository(releaseDeploymentRepository)); + } + private void unsetRepos() { getLog().info("Un-Setting artifact repositories."); project.setSnapshotArtifactRepository(null); diff --git a/src/main/java/com/e_gineering/maven/gitflowhelper/ScmUtils.java b/src/main/java/com/e_gineering/maven/gitflowhelper/ScmUtils.java index 50c42d5..abf0582 100644 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/ScmUtils.java +++ b/src/main/java/com/e_gineering/maven/gitflowhelper/ScmUtils.java @@ -3,7 +3,6 @@ import com.e_gineering.maven.gitflowhelper.properties.ExpansionBuffer; import com.e_gineering.maven.gitflowhelper.properties.PropertyResolver; import org.apache.commons.lang.StringUtils; -import org.apache.maven.MavenExecutionException; import org.apache.maven.plugin.logging.Log; import org.apache.maven.project.MavenProject; import org.apache.maven.scm.ScmException; @@ -20,7 +19,6 @@ import org.codehaus.plexus.util.cli.Commandline; import org.codehaus.plexus.util.cli.StreamConsumer; -import java.io.IOException; import java.util.HashSet; import java.util.Properties; import java.util.Set; @@ -45,7 +43,7 @@ class ScmUtils { public ScmUtils(final Properties systemEnvVars, final ScmManager scmManager, final MavenProject project, final Log log, final String masterBranchPattern, final String supportBranchPattern, final String releaseBranchPattern, - final String hotfixBranchPattern, final String developmentBranchPattern, final String featureOrBugfixBranchPattern) + final String hotfixBranchPattern, final String developmentBranchPattern) { this.systemEnvVars = systemEnvVars; this.scmManager = scmManager; @@ -199,8 +197,6 @@ private GitBranchInfo resolveBranchType(String branchName) { return new GitBranchInfo(branchName, GitBranchType.HOTFIX, hotfixBranchPattern); } else if (branchName.matches(developmentBranchPattern)) { return new GitBranchInfo(branchName, GitBranchType.DEVELOPMENT, developmentBranchPattern); - } else if (branchName.matches(featureOrBugfixBranchPattern)) { - return new GitBranchInfo(branchName, GitBranchType.FEATURE_OR_BUGFIX_BRANCH, featureOrBugfixBranchPattern); } else { return new GitBranchInfo(branchName, GitBranchType.OTHER, null); } diff --git a/src/main/java/com/e_gineering/maven/gitflowhelper/SetPropertiesMojo.java b/src/main/java/com/e_gineering/maven/gitflowhelper/SetPropertiesMojo.java index a7924c8..475c00d 100644 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/SetPropertiesMojo.java +++ b/src/main/java/com/e_gineering/maven/gitflowhelper/SetPropertiesMojo.java @@ -15,7 +15,7 @@ /** * Set a project property value based upon the current ${env.GIT_BRANCH} resolution. */ -@Mojo(name = "set-properties", defaultPhase = LifecyclePhase.INITIALIZE, threadSafe = true) +@Mojo(name = "set-properties", defaultPhase = LifecyclePhase.VALIDATE, threadSafe = true) public class SetPropertiesMojo extends AbstractGitflowBranchMojo { /** @@ -78,18 +78,6 @@ public class SetPropertiesMojo extends AbstractGitflowBranchMojo { @Parameter(property = "developmentBranchPropertyFile") private File developmentBranchPropertyFile; - /** - * Properties to be applied if executing against the development branch - */ - @Parameter(property = "featureOrBugfixBranchProperties") - private Properties featureOrBugfixBranchProperties; - - /** - * A Property file to load if executing against the feature or bugfix branch - */ - @Parameter(property = "featureOrBugfixBranchPropertyFile") - private File featureOrBugfixBranchPropertyFile; - /** * Properties to be applied if executing against a non-releasable branch */ @@ -163,11 +151,6 @@ protected void execute(final GitBranchInfo gitBranchInfo) throws MojoExecutionEx toLoad = developmentBranchPropertyFile; break; } - case FEATURE_OR_BUGFIX_BRANCH: { - toInject = featureOrBugfixBranchProperties; - toLoad = featureOrBugfixBranchPropertyFile; - break; - } case OTHER: { toInject = otherBranchProperties; toLoad = otherBranchPropertyFile; diff --git a/src/main/java/com/e_gineering/maven/gitflowhelper/properties/PropertyResolver.java b/src/main/java/com/e_gineering/maven/gitflowhelper/properties/PropertyResolver.java index ae742b2..33166f8 100644 --- a/src/main/java/com/e_gineering/maven/gitflowhelper/properties/PropertyResolver.java +++ b/src/main/java/com/e_gineering/maven/gitflowhelper/properties/PropertyResolver.java @@ -26,31 +26,6 @@ */ public class PropertyResolver { - /** - * Retrieves a property value, replacing values like ${token} using the Properties to look them up. Shamelessly - * adapted from: - * http://maven.apache.org/plugins/maven-war-plugin/xref/org/apache/maven/plugin/war/PropertyUtils.html It will - * leave unresolved properties alone, trying for System properties, and environment variables and implements - * reparsing (in the case that the value of a property contains a key), and will not loop endlessly on a pair like - * test = ${test} - * - * @param key property key - * @param properties project properties - * @param environment environment variables - * @return resolved property value - * @throws IllegalArgumentException when properties are circularly defined - */ - public static String getPropertyValue(String key, Properties properties, Properties environment) { - String value = properties.getProperty(key); - - ExpansionBuffer buffer = new ExpansionBuffer(value); - - CircularDefinitionPreventer circularDefinitionPreventer = - new CircularDefinitionPreventer().visited(key, value); - - return resolveValue(buffer, circularDefinitionPreventer, properties, environment); - } - public static String resolveValue(String value, Properties properties, Properties environment) { return resolveValue(new ExpansionBuffer(value), new CircularDefinitionPreventer(), properties, environment); } diff --git a/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml b/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml new file mode 100644 index 0000000..0928f2a --- /dev/null +++ b/src/main/resources/META-INF/m2e/lifecycle-mapping-metadata.xml @@ -0,0 +1,31 @@ + + + + + + + tag-master + retarget-deploy + promote-master + + + + + + + + + + enforce-versions + set-properties + update-stage-dependencies + + + + + false + + + + + diff --git a/src/test/java/com/e_gineering/maven/gitflowhelper/AbstractIntegrationTest.java b/src/test/java/com/e_gineering/maven/gitflowhelper/AbstractIntegrationTest.java new file mode 100644 index 0000000..2ddc38e --- /dev/null +++ b/src/test/java/com/e_gineering/maven/gitflowhelper/AbstractIntegrationTest.java @@ -0,0 +1,82 @@ +package com.e_gineering.maven.gitflowhelper; + + +import org.apache.maven.it.VerificationException; +import org.apache.maven.it.Verifier; +import org.apache.maven.it.util.ResourceExtractor; +import org.junit.Rule; +import org.junit.rules.TestName; + +import java.io.File; +import java.io.IOException; +import java.io.PrintStream; + +public abstract class AbstractIntegrationTest { + + private static PrintStream out = System.out; + private static PrintStream err = System.err; + + @Rule + public TestName name = new TestName(); + + protected Verifier createVerifier(String projectPath, String gitBranch, String projectVersion) throws IOException, VerificationException { + return createVerifier(ResourceExtractor.simpleExtractResources(getClass(), projectPath).getAbsolutePath(), null, gitBranch, projectVersion, false); + } + + private Verifier createVerifier(String basedir, String settings, String gitBranch, String stubProjectVersion, boolean debug) throws VerificationException { + Verifier verifier = new Verifier(basedir, debug); + verifier.setLogFileName(getClass().getSimpleName() + "_" + name.getMethodName() + "-log.txt"); + verifier.setAutoclean(true); + + if (System.getProperty("argLine", "").length() > 0) { + String opts = ""; + if (verifier.getEnvironmentVariables().get("MAVEN_OPTS") != null) { + opts += verifier.getEnvironmentVariables().get("MAVEN_OPTS"); + } + opts += System.getProperty("argLine", ""); + verifier.setEnvironmentVariable("MAVEN_OPTS", opts); + } + // Always allow our plugin to use snapshot versions when building / testing ourselves. + verifier.getCliOptions().add("-DallowGitflowPluginSnapshot=true"); + verifier.getCliOptions().add("-Dstub.project.version=" + stubProjectVersion); + verifier.getEnvironmentVariables().put("GIT_BRANCH", gitBranch); + + if (settings != null) { + File settingsFile; + if (settings.length() > 0) { + settingsFile = new File("settings-" + settings + ".xml"); + } else { + settingsFile = new File("settings.xml"); + } + + if (!settingsFile.isAbsolute()) { + String settingsDir = System.getProperty("maven.it.global-settings.dir", ""); + if (settingsDir.length() > 0) { + settingsFile = new File(settingsDir, settingsFile.getPath()); + } else { + // + // Make is easier to run ITs from m2e in Maven IT mode without having to set any additional + // properties. + // + settingsFile = new File("target/test-classes", settingsFile.getPath()); + } + } + + String path = settingsFile.getAbsolutePath(); + + verifier.getCliOptions().add("--global-settings"); + if (path.indexOf(' ') < 0) { + verifier.getCliOptions().add(path); + } else { + verifier.getCliOptions().add('"' + path + '"'); + } + } + + verifier.getSystemProperties().put("maven.multiModuleProjectDirectory", basedir); + + verifier.getSystemProperties().put("maven.compiler.source", "1.7"); + verifier.getSystemProperties().put("maven.compiler.target", "1.7"); + + return verifier; + } +} \ No newline at end of file diff --git a/src/test/java/com/e_gineering/maven/gitflowhelper/DevelopBranchIT.java b/src/test/java/com/e_gineering/maven/gitflowhelper/DevelopBranchIT.java new file mode 100644 index 0000000..d9ef11a --- /dev/null +++ b/src/test/java/com/e_gineering/maven/gitflowhelper/DevelopBranchIT.java @@ -0,0 +1,73 @@ +package com.e_gineering.maven.gitflowhelper; + +import org.apache.maven.it.VerificationException; +import org.apache.maven.it.Verifier; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.BlockJUnit4ClassRunner; + +@RunWith(BlockJUnit4ClassRunner.class) +public class DevelopBranchIT extends AbstractIntegrationTest { + /** + * Non-snapshot versions on the develop branch should fail. + */ + @Test(expected = VerificationException.class) + public void nonSnapshotDeployFails() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/develop", "1.0.0"); + try { + verifier.executeGoal("deploy"); + } catch (Exception ex) { + verifier.verifyTextInLog("The current git branch: [origin/develop] is detected as a SNAPSHOT-type branch, and expects a maven project version ending with -SNAPSHOT. The maven project version found was: [1.0.0]"); + throw ex; + } finally { + verifier.resetStreams(); + } + } + + /**. + * Snapshot versions on the develop branch should pass + * @throws Exception + */ + @Test + public void snapshotDeploySuccess() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/develop", "1.0.0-SNAPSHOT"); + + try { + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + } + + /** + * Attaching existing artifacts from the develop branch should pass. + * + * @throws Exception + */ + @Test + public void attachExistingArtifacts() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/develop", "1.0.0-SNAPSHOT"); + + try { + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + + // New verifier to attach existing artifacts + verifier = createVerifier("/project-stub", "origin/develop", "1.0.0-SNAPSHOT"); + + try { + verifier.executeGoal("gitflow-helper:attach-deployed"); + + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + } +} diff --git a/src/test/java/com/e_gineering/maven/gitflowhelper/EnforceVersionsIT.java b/src/test/java/com/e_gineering/maven/gitflowhelper/EnforceVersionsIT.java new file mode 100644 index 0000000..cac96a6 --- /dev/null +++ b/src/test/java/com/e_gineering/maven/gitflowhelper/EnforceVersionsIT.java @@ -0,0 +1,220 @@ +package com.e_gineering.maven.gitflowhelper; + +import org.apache.maven.it.VerificationException; +import org.apache.maven.it.Verifier; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.BlockJUnit4ClassRunner; + +@RunWith(BlockJUnit4ClassRunner.class) +public class EnforceVersionsIT extends AbstractIntegrationTest { + + @Test(expected = VerificationException.class) + public void versionEqualsMismatch() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/release/1.0.0", "1.2.0"); + + try { + verifier.executeGoal("gitflow-helper:enforce-versions"); + } finally { + verifier.resetStreams(); + } + } + + @Test(expected = VerificationException.class) + public void versionStartswithMismatch() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/release/1.2", "1.3.0"); + verifier.getCliOptions().add("-DreleaseBranchMatchType=startsWith"); + + try { + verifier.executeGoal("gitflow-helper:enforce-versions"); + } finally { + verifier.resetStreams(); + } + } + + @Test + public void versionStartswithMatch() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/release/1.2", "1.2.4"); + verifier.getCliOptions().add("-DreleaseBranchMatchType=startsWith"); + + try { + verifier.executeGoal("gitflow-helper:enforce-versions"); + } finally { + verifier.resetStreams(); + } + } + + @Test + public void supportsStartswithMatch() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/support/1.2", "1.2.4"); + + try { + verifier.executeGoal("gitflow-helper:enforce-versions"); + } finally { + verifier.resetStreams(); + } + } + + @Test(expected = VerificationException.class) + public void supportsStartswithMismatch() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/support/1.2", "1.3.2"); + + try { + verifier.executeGoal("gitflow-helper:enforce-versions"); + } finally { + verifier.resetStreams(); + } + } + + @Test + public void featureAllowsSnapshot() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/feature/aFeatureBranch", "1.0.0-SNAPSHOT"); + + try { + verifier.executeGoal("gitflow-helper:enforce-versions"); + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + } + + @Test + public void featureAllowsNonSnapshot() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/feature/aFeatureBranch", "1.0.0"); + + try { + verifier.executeGoal("gitflow-helper:enforce-versions"); + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + } + + @Test + public void dependencySuccesses() throws Exception { + // Stage the repository with version 1.0.0 of the stub. + + // Create a release version and get it deployed. + Verifier verifier = createVerifier("/project-stub", "origin/release/1.0.0", "1.0.0"); + + try { + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + // Promote (deploy) from /origin/master + verifier = createVerifier("/project-stub", "origin/master", "1.0.0"); + try { + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + // Build a project that depends upon the upstream project. + verifier = createVerifier("/project-alt1-stub", "origin/release/1.0.0", "1.0.0"); + verifier.getCliOptions().add("-Ddependency.stub.version=1.0.0"); + verifier.getCliOptions().add("-Dplugin.stub.version=1.0.0"); + + try { + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + verifier = createVerifier("/project-alt1-stub", "origin/master", "1.0.0"); + try { + verifier.getCliOptions().add("-Ddependency.stub.version=1.0.0"); + verifier.getCliOptions().add("-Dplugin.stub.version=1.0.0"); + + verifier.executeGoal("deploy"); + + verifier.verifyTextInLog( + "gitflow-helper-maven-plugin: Enabling MasterPromoteExtension. GIT_BRANCH: [origin/master] matches masterBranchPattern"); + verifier.verifyTextInLog("[INFO] Setting release artifact repository to: [releases]"); + verifier.verifyTextInLog( + "[INFO] Resolving & Reattaching existing artifacts from stageDeploymentRepository [test-releases]"); + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + } + + @Test(expected= VerificationException.class) + public void dependencySnapshotFail() throws Exception { + // Stage the repository with version 1.0.0 of the stub. + + // Create a release version and get it deployed. + Verifier verifier = createVerifier("/project-stub", "origin/release/1.0.0", "1.0.0"); + try { + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + // Promote (deploy) from /origin/master + verifier = createVerifier("/project-stub", "origin/master", "1.0.0"); + try { + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + // Build a project that depends upon the upstream project. + verifier = createVerifier("/project-alt1-stub", "origin/release/1.0.0", "1.0.0"); + verifier.getCliOptions().add("-Ddependency.stub.version=1.0.0-SNAPSHOT"); + verifier.getCliOptions().add("-Dplugin.stub.version=1.0.0"); + + try { + verifier.executeGoal("deploy"); + } finally { + verifier.resetStreams(); + } + } + + @Test(expected=VerificationException.class) + public void pluginSnapshotFail() throws Exception { + // Stage the repository with version 1.0.0 of the stub. + + // Create a release version and get it deployed. + Verifier verifier = createVerifier("/project-stub", "origin/release/1.0.0", "1.0.0"); + try { + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + // Promote (deploy) from /origin/master + verifier = createVerifier("/project-stub", "origin/master", "1.0.0"); + try { + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + // Build a project that depends upon the upstream project. + verifier = createVerifier("/project-alt1-stub", "origin/release/1.0.0", "1.0.0"); + verifier.getCliOptions().add("-Ddependency.stub.version=1.0.0"); + verifier.getCliOptions().add("-Dplugin.stub.version=1.0.0-SNAPSHOT"); + + try { + verifier.executeGoal("deploy"); + } finally { + verifier.resetStreams(); + } + } +} diff --git a/src/test/java/com/e_gineering/maven/gitflowhelper/GitBranchInfoTest.java b/src/test/java/com/e_gineering/maven/gitflowhelper/GitBranchInfoTest.java new file mode 100644 index 0000000..891927d --- /dev/null +++ b/src/test/java/com/e_gineering/maven/gitflowhelper/GitBranchInfoTest.java @@ -0,0 +1,20 @@ +package com.e_gineering.maven.gitflowhelper; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.BlockJUnit4ClassRunner; + +@RunWith(BlockJUnit4ClassRunner.class) +public class GitBranchInfoTest { + + @Test(expected = IllegalArgumentException.class) + public void testInitNoNameParams() { + new GitBranchInfo(null, GitBranchType.MASTER, null); + } + + @Test(expected = IllegalArgumentException.class) + public void testInitNoTypeParams() { + new GitBranchInfo("origin/release", null, null); + } + +} diff --git a/src/test/java/com/e_gineering/maven/gitflowhelper/MasterSupportBranchIT.java b/src/test/java/com/e_gineering/maven/gitflowhelper/MasterSupportBranchIT.java new file mode 100644 index 0000000..ff93c84 --- /dev/null +++ b/src/test/java/com/e_gineering/maven/gitflowhelper/MasterSupportBranchIT.java @@ -0,0 +1,124 @@ +package com.e_gineering.maven.gitflowhelper; + +import org.apache.maven.it.VerificationException; +import org.apache.maven.it.Verifier; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.BlockJUnit4ClassRunner; + +import java.util.Arrays; + +@RunWith(BlockJUnit4ClassRunner.class) +public class MasterSupportBranchIT extends AbstractIntegrationTest { + private static final String PROMOTION_FAILED_MESSAGE = "Promotion Deploy from origin/master allowed something to Compile."; + + @Test + public void releaseVersionSuccess() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/master", "1.0.0"); + + try { + verifier.executeGoal("gitflow-helper:enforce-versions"); + + verifier.verifyErrorFreeLog(); + verifier.verifyTextInLog("GitBranchInfo:"); + } finally { + verifier.resetStreams(); + } + } + + @Test(expected = VerificationException.class) + public void snapshotVersionFailure() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/master", "1.0.0-SNAPSHOT"); + + try { + verifier.executeGoal("gitflow-helper:enforce-versions"); + } finally { + try { + verifier.verifyTextInLog("GitBranchInfo:"); + verifier.verifyTextInLog("The maven project or one of its parents is currently a snapshot version."); + } finally { + verifier.resetStreams(); + } + } + } + + @Test + public void promotionOfRelease() throws Exception { + // Create a release version and get it deployed. + Verifier verifier = createVerifier("/project-stub", "origin/release/1.0.0", "1.0.0"); + + try { + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + // Promote (deploy) from /origin/master + verifier = createVerifier("/project-stub", "origin/master", "1.0.0"); + + try { + verifier.executeGoal("deploy"); + + try { + verifier.verifyTextInLog("Compiling"); + throw new VerificationException(PROMOTION_FAILED_MESSAGE); + } catch (VerificationException ve) { + if (ve.getMessage().equals(PROMOTION_FAILED_MESSAGE)) { + throw ve; + } + // Otherwise, it's the VerificationException from looking for "Compiling", and that's expected to fail. + } + + verifier.verifyTextInLog( + "gitflow-helper-maven-plugin: Enabling MasterPromoteExtension. GIT_BRANCH: [origin/master] matches masterBranchPattern"); + verifier.verifyTextInLog("[INFO] Setting release artifact repository to: [releases]"); + verifier.verifyTextInLog( + "[INFO] Resolving & Reattaching existing artifacts from stageDeploymentRepository [test-releases"); + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + } + + @Test + public void dontPruneExplicitlyInvokedPlugins() throws Exception { + // Create a release version and get it deployed. + Verifier verifier = createVerifier("/project-stub", "origin/release/1.1.0", "1.1.0"); + + try { + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + // Promote (deploy) from /origin/master + verifier = createVerifier("/project-stub", "origin/master", "1.1.0"); + + try { + verifier.executeGoals(Arrays.asList("jar:jar", "deploy")); + try { + verifier.verifyTextInLog("Compiling"); + throw new VerificationException(PROMOTION_FAILED_MESSAGE); + } catch (VerificationException ve) { + if (ve.getMessage().equals(PROMOTION_FAILED_MESSAGE)) { + throw ve; + } + // Otherwise, it's the VerificationException from looking for "Compiling", and that's expected to fail. + } + + verifier.verifyTextInLog("Building jar:"); // This should still be there. + verifier.verifyTextInLog( + "gitflow-helper-maven-plugin: Enabling MasterPromoteExtension. GIT_BRANCH: [origin/master] matches masterBranchPattern"); + verifier.verifyTextInLog("[INFO] Setting release artifact repository to: [releases]"); + verifier.verifyTextInLog( + "[INFO] Resolving & Reattaching existing artifacts from stageDeploymentRepository [test-releases"); + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + } +} diff --git a/src/test/java/com/e_gineering/maven/gitflowhelper/OtherBranchIT.java b/src/test/java/com/e_gineering/maven/gitflowhelper/OtherBranchIT.java new file mode 100644 index 0000000..ca6df37 --- /dev/null +++ b/src/test/java/com/e_gineering/maven/gitflowhelper/OtherBranchIT.java @@ -0,0 +1,97 @@ +package com.e_gineering.maven.gitflowhelper; + +import org.apache.maven.it.Verifier; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.BlockJUnit4ClassRunner; + +import java.util.Arrays; + +@RunWith(BlockJUnit4ClassRunner.class) +public class OtherBranchIT extends AbstractIntegrationTest { + @Test + public void featureSnapshotSemVer() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/feature/poc/my-feature-branch", "5.0.0-SNAPSHOT"); + try { + verifier.executeGoal("deploy"); + + verifier.verifyTextInLog("Artifact versions updated with semVer build metadata: +origin-feature-poc-my-feature-branch-SNAPSHOT"); + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + } + + @Test + 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("deploy"); + + verifier.verifyTextInLog("Artifact versions updated with semVer build metadata: +origin-feature-poc-my-feature-branch.with.other.identifiers-SNAPSHOT"); + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + } + + @Test + public void noOtherDeployMatch() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/feature/my-feature-branch", "5.0.1-SNAPSHOT"); + try { + verifier.executeGoal("deploy"); + + verifier.verifyTextInLog("Un-Setting artifact repositories."); + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + } + + @Test + public void automagicVersionDependenciesResolve() throws Exception { + // Create a -SNAPSHOT of the project-stub. + Verifier verifier = createVerifier("/project-stub", "origin/feature/poc/long-running", "2.0.0"); + try { + verifier.executeGoal("deploy"); + + verifier.verifyTextInLog("Artifact versions updated with semVer build metadata: +origin-feature-poc-long-running-SNAPSHOT"); + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + // Create a -SNAPSHOT of the project-alt1-stub that depends upon the other project's automagic version. + verifier = createVerifier("/project-alt1-stub", "origin/feature/poc/long-running", "2.0.0"); + try { + verifier.getCliOptions().add("-Ddependency.stub.version=2.0.0+origin-feature-poc-long-running-SNAPSHOT"); + verifier.getCliOptions().add("-Dplugin.stub.version=2.0.0+origin-feature-poc-long-running-SNAPSHOT"); + + verifier.executeGoal("deploy"); + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + } + + @Test + public void attachDeployed() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/feature/poc/reattach", "5.0.0-SNAPSHOT"); + try { + verifier.executeGoal("deploy"); + + verifier.verifyTextInLog("Artifact versions updated with semVer build metadata: +origin-feature-poc-reattach-SNAPSHOT"); + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + verifier = createVerifier("/project-stub", "origin/feature/poc/reattach", "5.0.0-SNAPSHOT"); + try { + verifier.executeGoals(Arrays.asList("validate", "gitflow-helper:attach-deployed")); + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + } +} diff --git a/src/test/java/com/e_gineering/maven/gitflowhelper/ReleaseBranchIT.java b/src/test/java/com/e_gineering/maven/gitflowhelper/ReleaseBranchIT.java new file mode 100644 index 0000000..23212d5 --- /dev/null +++ b/src/test/java/com/e_gineering/maven/gitflowhelper/ReleaseBranchIT.java @@ -0,0 +1,69 @@ +package com.e_gineering.maven.gitflowhelper; + +import org.apache.maven.it.VerificationException; +import org.apache.maven.it.Verifier; +import org.junit.Assume; +import org.junit.Test; +import org.junit.internal.AssumptionViolatedException; +import org.junit.runner.RunWith; +import org.junit.runners.BlockJUnit4ClassRunner; + +@RunWith(BlockJUnit4ClassRunner.class) +public class ReleaseBranchIT extends AbstractIntegrationTest { + + /** + * Non-snapshot versions on the develop branch should fail. + */ + @Test + public void snapshotDeployFails() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/release/1.0.0", "1.0.0-SNAPSHOT"); + + try { + verifier.executeGoal("deploy"); + } catch (Exception ex) { + verifier.verifyTextInLog("The current git branch: [origin/release/1.0.0] is defined as a release branch. The maven project or one of its parents is currently a snapshot version."); + } finally { + verifier.resetStreams(); + } + } + + /**. + * Snapshot versions on the develop branch should pass + * @throws Exception + */ + @Test + public void deploySuccess() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/release/1.0.0", "1.0.0"); + + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + + verifier.resetStreams(); + } + + /** + * Attaching existing artifacts from the develop branch should pass. + * + * @throws Exception + */ + @Test + public void attachExistingArtifacts() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/release/1.0.0", "1.0.0"); + + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + + verifier.resetStreams(); + + // Now re-attach in another verifier. + verifier = createVerifier("/project-stub", "origin/release/1.0.0", "1.0.0"); + + // Allow -SNAPSHOT builds of the plugin to succeed while still asserting the version match. + verifier.getCliOptions().add("-DenforceNonSnapshots=false"); + verifier.executeGoal("gitflow-helper:attach-deployed"); + + verifier.verifyErrorFreeLog(); + } +} diff --git a/src/test/java/com/e_gineering/maven/gitflowhelper/RetargetDeployIT.java b/src/test/java/com/e_gineering/maven/gitflowhelper/RetargetDeployIT.java new file mode 100644 index 0000000..f3ffe7f --- /dev/null +++ b/src/test/java/com/e_gineering/maven/gitflowhelper/RetargetDeployIT.java @@ -0,0 +1,135 @@ +package com.e_gineering.maven.gitflowhelper; + +import org.apache.maven.it.Verifier; +import org.junit.Assert; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.junit.runners.BlockJUnit4ClassRunner; + +import java.io.File; + +@RunWith(BlockJUnit4ClassRunner.class) +public class RetargetDeployIT extends AbstractIntegrationTest { + + @Test + public void devTargetsSnapshot() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/develop", "3.0.0-SNAPSHOT"); + + try { + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + // Ensure the file exists in the repo. + File artifactDir = new File(System.getProperty("basedir"), "target/it-repositories/snapshots/com/e-gineering/gitflow-helper-maven-plugin-test-stub/3.0.0-SNAPSHOT"); + Assert.assertTrue(artifactDir.exists() && artifactDir.isDirectory() && artifactDir.list().length > 0); + } + + @Test + public void releaseTargetsTest() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/release/3.1.0", "3.1.0"); + + try { + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + // Ensure the file exists in the repo. + File artifactDir = new File(System.getProperty("basedir"), "target/it-repositories/test-releases/com/e-gineering/gitflow-helper-maven-plugin-test-stub/3.1.0"); + Assert.assertTrue(artifactDir.exists() && artifactDir.isDirectory() && artifactDir.list().length > 0); + } + + @Test + public void hotfixTargetsTest() throws Exception { + Verifier verifier = createVerifier("/project-stub", "origin/hotfix/3.1.5", "3.1.5"); + + try { + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + // Ensure the file exists in the repo. + File artifactDir = new File(System.getProperty("basedir"), "target/it-repositories/test-releases/com/e-gineering/gitflow-helper-maven-plugin-test-stub/3.1.5"); + Assert.assertTrue(artifactDir.exists() && artifactDir.isDirectory() && artifactDir.list().length > 0); + } + + @Test + public void supportTargetsReleases() throws Exception { + // Deploy a hotfix to the test-releases. + Verifier verifier = createVerifier("/project-stub", "origin/hotfix/3.2.1", "3.2.1"); + try { + verifier.executeGoal("deploy"); + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + File artifactDir = new File(System.getProperty("basedir"), "target/it-repositories/test-releases/com/e-gineering/gitflow-helper-maven-plugin-test-stub/3.2.1"); + Assert.assertTrue(artifactDir.exists() && artifactDir.isDirectory() && artifactDir.list().length > 0); + + // Promote with the support branch + verifier = createVerifier("/project-stub", "origin/support/3.2", "3.2.1"); + try { + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + // Ensure the file exists in the repo. + artifactDir = new File(System.getProperty("basedir"), "target/it-repositories/releases/com/e-gineering/gitflow-helper-maven-plugin-test-stub/3.2.1"); + Assert.assertTrue(artifactDir.exists() && artifactDir.isDirectory() && artifactDir.list().length > 0); + } + + @Test + public void masterTargetsReleases() throws Exception { + // Deploy a hotfix to the test-releases. + Verifier verifier = createVerifier("/project-stub", "origin/release/3.3.0", "3.3.0"); + try { + verifier.executeGoal("deploy"); + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + File artifactDir = new File(System.getProperty("basedir"), "target/it-repositories/test-releases/com/e-gineering/gitflow-helper-maven-plugin-test-stub/3.3.0"); + Assert.assertTrue(artifactDir.exists() && artifactDir.isDirectory() && artifactDir.list().length > 0); + + // Promote with the support branch + verifier = createVerifier("/project-stub", "origin/master", "3.3.0"); + try { + verifier.setMavenDebug(true); + verifier.executeGoal("deploy"); + + verifier.verifyErrorFreeLog(); + } finally { + verifier.resetStreams(); + } + + // Ensure the file exists in the repo. + artifactDir = new File(System.getProperty("basedir"), "target/it-repositories/releases/com/e-gineering/gitflow-helper-maven-plugin-test-stub/3.3.0"); + Assert.assertTrue(artifactDir.exists() && artifactDir.isDirectory() && artifactDir.list().length > 0); + } + + @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"); + verifier.verifyTextInLog("[INFO] Skipping artifact deployment"); + } finally { + verifier.resetStreams(); + } + } +} diff --git a/src/test/resources/project-alt1-stub/pom.xml b/src/test/resources/project-alt1-stub/pom.xml new file mode 100644 index 0000000..e6f518a --- /dev/null +++ b/src/test/resources/project-alt1-stub/pom.xml @@ -0,0 +1,75 @@ + + + 4.0.0 + + com.e-gineering + gitflow-helper-maven-plugin-test-stub-alt + ${stub.project.version} + + jar + + + + 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 + + + + + + com.e-gineering + gitflow-helper-maven-plugin-test-stub + ${dependency.stub.version} + + + + + + + com.e-gineering + gitflow-helper-maven-plugin-test-stub + ${plugin.stub.version} + + + com.e-gineering + gitflow-helper-maven-plugin + ${version.gitflow.plugin} + true + + releases + test-releases + snapshots + + bar + + (origin/)?feature/poc/.* + + + + + enforce-versions + set-properties + retarget-deploy + update-stage-dependencies + promote-master + + + + + + + diff --git a/src/test/resources/project-alt1-stub/src/main/java/HelloWorld.java b/src/test/resources/project-alt1-stub/src/main/java/HelloWorld.java new file mode 100644 index 0000000..7edc00d --- /dev/null +++ b/src/test/resources/project-alt1-stub/src/main/java/HelloWorld.java @@ -0,0 +1,8 @@ +/** + * 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/project-stub/pom.xml b/src/test/resources/project-stub/pom.xml new file mode 100644 index 0000000..5a47f8a --- /dev/null +++ b/src/test/resources/project-stub/pom.xml @@ -0,0 +1,97 @@ + + + 4.0.0 + + com.e-gineering + gitflow-helper-maven-plugin-test-stub + ${stub.project.version} + + jar + + + + releases + file:${it.repository.basedir}/releases + false + true + + + + + + + + + snapshots + file:${it.repository.basedir}/snapshots + true + false + + + + + + + src/main/resources + true + + *.properties + + + + + + + com.e-gineering + gitflow-helper-maven-plugin + ${version.gitflow.plugin} + true + + releases + test-releases::default::file:${it.repository.basedir}/test-releases::false + 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 + + + + + + + + diff --git a/src/test/resources/project-stub/src/build/resources/master.build.properties b/src/test/resources/project-stub/src/build/resources/master.build.properties new file mode 100644 index 0000000..09237d3 --- /dev/null +++ b/src/test/resources/project-stub/src/build/resources/master.build.properties @@ -0,0 +1,3 @@ +build.branch.type=master +build.branch.string=${project.version}-type-${build.branch.type} +${build.branch.type}-foo=foomanchu! diff --git a/src/test/resources/project-stub/src/main/java/HelloWorld.java b/src/test/resources/project-stub/src/main/java/HelloWorld.java new file mode 100644 index 0000000..7edc00d --- /dev/null +++ b/src/test/resources/project-stub/src/main/java/HelloWorld.java @@ -0,0 +1,8 @@ +/** + * 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/project-stub/src/main/resources/project.properties b/src/test/resources/project-stub/src/main/resources/project.properties new file mode 100644 index 0000000..3715d25 --- /dev/null +++ b/src/test/resources/project-stub/src/main/resources/project.properties @@ -0,0 +1 @@ +app.buildinfo=${build.branch.string} \ No newline at end of file