Skip to content

Commit 2b755bd

Browse files
committed
* Updated regex patterns to work for jenkins injected ${env.GIT_BRANCH} and local git HEAD resolution. (origin/) as an optional group match.
* Version enforcement expects the last sub group matched to be the version expression. * Version enforcement now asserts -SNAPSHOT on development branch. I think this was lost in the change to only assert that releaseable branches are non-snapshot, and undefined branches should never be asserted. * Updated a log statement so it's a bit more obvious.
1 parent 1cf2702 commit 2b755bd

File tree

3 files changed

+14
-12
lines changed

3 files changed

+14
-12
lines changed

src/main/java/com/e_gineering/maven/gitflowhelper/AbstractGitflowBranchMojo.java

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,16 @@ public abstract class AbstractGitflowBranchMojo extends AbstractMojo {
3030
@Component
3131
protected ScmManager scmManager;
3232

33-
@Parameter(defaultValue = "origin/master", property = "masterBranchPattern", required = true)
33+
@Parameter(defaultValue = "(origin/)?master", property = "masterBranchPattern", required = true)
3434
private String masterBranchPattern;
3535

36-
@Parameter(defaultValue = "origin/release/(.*)", property = "releaseBranchPattern", required = true)
36+
@Parameter(defaultValue = "(origin/)?release/(.*)", property = "releaseBranchPattern", required = true)
3737
private String releaseBranchPattern;
3838

39-
@Parameter(defaultValue = "origin/hotfix/(.*)", property = "hotfixBranchPattern", required = true)
39+
@Parameter(defaultValue = "(origin/)?hotfix/(.*)", property = "hotfixBranchPattern", required = true)
4040
private String hotfixBranchPattern;
4141

42-
@Parameter(defaultValue = "origin/develop", property = "developmentBranchPattern", required = true)
42+
@Parameter(defaultValue = "(origin/)?develop", property = "developmentBranchPattern", required = true)
4343
private String developmentBranchPattern;
4444

4545
// @Parameter tag causes property resolution to fail for patterns containing ${env.}. Default provided in execute();
@@ -84,9 +84,9 @@ public void execute() throws MojoExecutionException, MojoFailureException {
8484

8585
if (!eb.hasMoreLegalPlaceholders()) {
8686
/*
87-
* /origin/master goes to the maven 'release' repo.
88-
* /origin/release/.* , /origin/hotfix/.* , and /origin/bugfix/.* go to the maven 'stage' repo.
89-
* /origin/develop goes to the 'snapshot' repo.
87+
* (/origin/)?master goes to the maven 'release' repo.
88+
* (/origin/)?release/(.*) , (/origin/)?hotfix/(.*) , and (/origin/)?bugfix/(.*) go to the maven 'stage' repo.
89+
* (/origin/)?develop goes to the 'snapshot' repo.
9090
* All other builds will use the default semantics for 'deploy'.
9191
*/
9292
if (gitBranch.matches(masterBranchPattern)) {

src/main/java/com/e_gineering/maven/gitflowhelper/EnforceVersionsMojo.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,15 @@ protected void execute(final GitBranchType type, final String gitBranch, final S
2828
throw new MojoFailureException("The current git branch: [" + gitBranch + "] is defined as a release branch. The maven project version: [" + project.getVersion() + "] is currently a snapshot version.");
2929
}
3030

31-
// If there is a group 1, expect it to match (exactly) the current projectVersion.
32-
if (gitMatcher.groupCount() >= 1) {
33-
if (!gitMatcher.group(1).trim().equals(project.getVersion().trim())) {
34-
throw new MojoFailureException("The current git branch: [" + gitBranch + "] expected the maven project version to be: [" + gitMatcher.group(1).trim() + "], but the maven project version is: [" + project.getVersion() + "]");
31+
// Expect the last group to match (exactly) the current projectVersion.
32+
if (gitMatcher.groupCount() > 0) {
33+
if (!gitMatcher.group(gitMatcher.groupCount()).trim().equals(project.getVersion().trim())) {
34+
throw new MojoFailureException("The current git branch: [" + gitBranch + "] expected the maven project version to be: [" + gitMatcher.group(gitMatcher.groupCount()).trim() + "], but the maven project version is: [" + project.getVersion() + "]");
3535
}
3636
}
3737
}
38+
} else if (GitBranchType.DEVELOPMENT.equals(type) && !ArtifactUtils.isSnapshot(project.getVersion())) {
39+
throw new MojoFailureException("The current git branch: [" + gitBranch + "] is detected as the gitflow development branch, and expects a maven project version ending with -SNAPSHOT. The maven project version found was: [" + project.getVersion() + "]");
3840
}
3941
}
4042
}

src/main/java/com/e_gineering/maven/gitflowhelper/MasterPromoteExtension.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti
121121

122122
PropertyResolver pr = new PropertyResolver();
123123
String gitBranch = pr.resolveValue(gitBranchExpression, session.getCurrentProject().getProperties(), systemEnvVars);
124-
logger.info("Build Extension Resolved: " + gitBranchExpression + " to: " + gitBranch);
124+
logger.info("gitflow-helper-maven-plugin: Build Extension resolved gitBranchExpression: " + gitBranchExpression + " to: " + gitBranch);
125125

126126
// Test to see if the current GIT_BRANCH matches the masterBranchPattern...
127127
if (gitBranch != null && gitBranch.matches(masterBranchPattern)) {

0 commit comments

Comments
 (0)