Skip to content

Commit 923a943

Browse files
committed
Eliminates all reliance upon ${env.GIT_BRANCH}, but allows for it's use.
* Refactored SCM tagging to use the SCMManager component. ** No longer requires another plugin to run another maven instance inside of our build. ** No longer needs the scm:tag mojo, since we now interact with the SCM manager and execute tagging directly. * Changed the standard 'development' branch to 'orgin/develop' to be more in-line with the expected defaults from 'gitflow'. ** (Some opinionated people will just have to change their defaults, exposing that their opinions are 'non-standard') ;-D
1 parent 1c5111d commit 923a943

File tree

3 files changed

+23
-53
lines changed

3 files changed

+23
-53
lines changed

pom.xml

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,17 +64,6 @@
6464
</distributionManagement>
6565

6666
<dependencies>
67-
<dependency>
68-
<groupId>org.twdata.maven</groupId>
69-
<artifactId>mojo-executor</artifactId>
70-
<version>2.2.0</version>
71-
<exclusions>
72-
<exclusion>
73-
<groupId>org.apache.maven</groupId>
74-
<artifactId>maven-core</artifactId>
75-
</exclusion>
76-
</exclusions>
77-
</dependency>
7867
<dependency>
7968
<groupId>org.apache.maven</groupId>
8069
<artifactId>maven-core</artifactId>

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ public abstract class AbstractGitflowBranchMojo extends AbstractMojo {
3939
@Parameter(defaultValue = "origin/hotfix/(.*)", property = "hotfixBranchPattern", required = true)
4040
private String hotfixBranchPattern;
4141

42-
@Parameter(defaultValue = "origin/development", 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();
@@ -86,7 +86,7 @@ public void execute() throws MojoExecutionException, MojoFailureException {
8686
/*
8787
* /origin/master goes to the maven 'release' repo.
8888
* /origin/release/.* , /origin/hotfix/.* , and /origin/bugfix/.* go to the maven 'stage' repo.
89-
* /origin/development goes to the 'snapshot' 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/TagMasterMojo.java

Lines changed: 21 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,45 +1,30 @@
11
package com.e_gineering.maven.gitflowhelper;
22

33
import com.e_gineering.maven.gitflowhelper.properties.ExpansionBuffer;
4-
import org.apache.maven.execution.MavenSession;
5-
import org.apache.maven.plugin.BuildPluginManager;
64
import org.apache.maven.plugin.MojoExecutionException;
75
import org.apache.maven.plugin.MojoFailureException;
8-
import org.apache.maven.plugins.annotations.Component;
96
import org.apache.maven.plugins.annotations.LifecyclePhase;
107
import org.apache.maven.plugins.annotations.Mojo;
118
import org.apache.maven.plugins.annotations.Parameter;
12-
13-
import static org.twdata.maven.mojoexecutor.MojoExecutor.*;
9+
import org.apache.maven.scm.ScmException;
10+
import org.apache.maven.scm.ScmFileSet;
11+
import org.apache.maven.scm.ScmTagParameters;
12+
import org.apache.maven.scm.provider.ScmProvider;
13+
import org.apache.maven.scm.repository.ScmRepository;
1414

1515
/**
1616
* Invokes configures the builds SCM settings based on environment variables from a CI Server, and does an scm:tag for builds from Master.
1717
*/
1818
@Mojo(name = "tag-master", defaultPhase = LifecyclePhase.INSTALL)
1919
public class TagMasterMojo extends AbstractGitflowBranchMojo {
2020

21-
// @Parameter tag causes property resolution to fail for patterns containing ${env.}. Default provided in execute();
21+
// @Parameter tag causes property resolution to fail for patterns containing ${env.}. Default value is resolved in execute()
2222
@Parameter(property = "gitURLExpression")
2323
private String gitURLExpression;
2424

2525
@Parameter(defaultValue = "${project.version}", property = "tag", required = true)
2626
private String tag;
2727

28-
@Parameter(defaultValue = "org.apache.maven.plugins", property = "tag.plugin.groupId", required = true)
29-
private String tagGroupId;
30-
31-
@Parameter(defaultValue = "maven-scm-plugin", property = "tag.plugin.artifactId", required = true)
32-
private String tagArtifactId;
33-
34-
@Parameter(defaultValue = "1.9.4", property = "tag.plugin.version", required = true)
35-
private String tagVersion;
36-
37-
@Component
38-
private MavenSession mavenSession;
39-
40-
@Component
41-
private BuildPluginManager pluginManager;
42-
4328
@Override
4429
protected void execute(final GitBranchType type, final String gitBranch, final String branchPattern) throws MojoExecutionException, MojoFailureException {
4530
if (project.isExecutionRoot() && type.equals(GitBranchType.MASTER)) {
@@ -51,26 +36,22 @@ protected void execute(final GitBranchType type, final String gitBranch, final S
5136
ExpansionBuffer eb = new ExpansionBuffer(gitURL);
5237
if (!eb.hasMoreLegalPlaceholders()) {
5338

54-
getLog().info("Invoking scm:tag for CI build matching branchPattern: [" + branchPattern + "]");
39+
getLog().info("Tagging SCM for CI build matching branchPattern: [" + branchPattern + "]");
40+
41+
try {
42+
ScmRepository repository = scmManager.makeScmRepository(gitURL);
43+
ScmProvider provider = scmManager.getProviderByRepository(repository);
44+
45+
String sanitizedTag = provider.sanitizeTagName(tag);
46+
getLog().info("Sanitized tag: '" + sanitizedTag + "'");
47+
48+
ScmTagParameters tagParams = new ScmTagParameters("Release tag [" + sanitizedTag + "] generated by gitflow-helper-maven-plugin.");
49+
tagParams.setRemoteTagging(true);
5550

56-
// Use the execute mojo to run the maven-scm-plugin...
57-
executeMojo(
58-
plugin(
59-
groupId(tagGroupId),
60-
artifactId(tagArtifactId),
61-
version(tagVersion)
62-
),
63-
goal("tag"),
64-
configuration(
65-
element(name("tag"), tag),
66-
element(name("developerConnectionUrl"), "scm:git:" + gitURL)
67-
),
68-
executionEnvironment(
69-
project,
70-
mavenSession,
71-
pluginManager
72-
)
73-
);
51+
provider.tag(repository, new ScmFileSet(project.getBasedir()), sanitizedTag, tagParams);
52+
} catch (ScmException scme) {
53+
throw new MojoFailureException("Unable to tag master branch.", scme);
54+
}
7455
} else {
7556
throw new MojoFailureException("Unable to resolve gitURLExpression: " + gitURLExpression + ". Leaving build configuration unaltered.");
7657
}

0 commit comments

Comments
 (0)