11package com .e_gineering .maven .gitflowhelper ;
22
33import com .e_gineering .maven .gitflowhelper .properties .ExpansionBuffer ;
4- import org .apache .maven .execution .MavenSession ;
5- import org .apache .maven .plugin .BuildPluginManager ;
64import org .apache .maven .plugin .MojoExecutionException ;
75import org .apache .maven .plugin .MojoFailureException ;
8- import org .apache .maven .plugins .annotations .Component ;
96import org .apache .maven .plugins .annotations .LifecyclePhase ;
107import org .apache .maven .plugins .annotations .Mojo ;
118import 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 )
1919public 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