Skip to content

Commit 1cf2702

Browse files
committed
* Updates to the SCM bits. Verified that this works. The default branch patterns are still configured for CI servers to specify the /origin/<branch>, rather than a local branch name which omits the 'origin'
1 parent 4b9237e commit 1cf2702

File tree

4 files changed

+8
-13
lines changed

4 files changed

+8
-13
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ It does so by:
77
* Enforcing [gitflow](http://nvie.com/posts/a-successful-git-branching-model/) version heuristics in [Maven](http://maven.apache.org/) projects.
88
* Coercing Maven to gracefully support the gitflow workflow without imposing complex CI job configurations or complex Maven setups.
99
* Setting distributionManagement repositories (for things like [maven-deploy-plugin](https://maven.apache.org/plugins/maven-deploy-plugin/)) based upon the current git branch.
10-
* SCM tagging builds for the master branch, using the CI server's repository connection information. (Zero Maven scm configuration necessary)
10+
* SCM tagging builds for the master branch, using the CI server's repository connection information. (Zero Maven scm configuration necessary, or if you prefer it, you can use the &lt;scm&gt; from maven)
1111
* 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.
1212
* Enabling the decoupling of repository deployment and execution environment delivery based on the current git branch.
1313
* 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).
@@ -34,7 +34,7 @@ All of the solutions to these issues are implemented independently in different
3434

3535
1. Make sure you have a your Project SCM configured for your git repository, or that your build server sets environment variables for git branches and git URLs.
3636
Out of the box, the plugin will try to resolve the git branch based upon the SCM definition on your maven project, or fall back to the environment variables set by Jenkins and Hudson.
37-
2. Configure the plugin goals and add the build extension to your Maven project. Here's an example that will get you going quickly...
37+
2. Configure the plugin goals and add the build extension to your Maven project. Here's an example that will get you going quickly with all the features...
3838

3939
```
4040
<project>
@@ -53,7 +53,7 @@ All of the solutions to these issues are implemented independently in different
5353
<releaseDeploymentRepository>${release.repository}</releaseDeploymentRepository>
5454
<stageDeploymentRepository>${stage.repository}</stageDeploymentRepository>
5555
<snapshotDeploymentRepository>${snapshot.repository}</snapshotDeploymentRepository>
56-
<!-- The plugin will read the git branch ang git url by resolving these properties at run-time -->
56+
<!-- The plugin will read the git branch and git url by resolving these properties at run-time -->
5757
<gitBranchExpression/>
5858
</configuration>
5959
<executions>

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,10 +102,6 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti
102102
}
103103
}
104104

105-
if (gitBranchExpression == null) {
106-
gitBranchExpression = ScmUtils.resolveBranchOrExpression(scmManager, project, new DefaultLog(logger));
107-
}
108-
109105
pluginsToDrop.put(project, dropPlugins);
110106
}
111107

@@ -117,8 +113,8 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti
117113
logger.debug("Master Branch Pattern: " + masterBranchPattern);
118114

119115
if (gitBranchExpression == null) {
120-
logger.debug("Using default gitBranchExpression.");
121-
gitBranchExpression = "${env.GIT_BRANCH}";
116+
logger.debug("Using default branch expression resolver.");
117+
gitBranchExpression = ScmUtils.resolveBranchOrExpression(scmManager, session.getTopLevelProject(), new DefaultLog(logger));
122118
}
123119
logger.debug("Git Branch Expression: " + gitBranchExpression);
124120

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,11 @@ public abstract class ScmUtils {
2121
* Given the ScmManager for the current execution cycle, and the MavenProject structure, determine the SCM URL or
2222
* an expression we can resolve the URL from.
2323
*
24-
* @param scmManager The current maven ScmManager
2524
* @param project The Current maven Project
2625
* @param log A Log to write to
2726
* @return The developerConnection, if none set, the connection, if none set, then the expression, <code>"${env.GIT_URL}"</code>
2827
*/
29-
public static String resolveUrlOrExpression(final ScmManager scmManager, final MavenProject project, final Log log) {
28+
public static String resolveUrlOrExpression(final MavenProject project, final Log log) {
3029
String connectionUrl = null;
3130

3231
// Some projects don't specify SCM Blocks, and instead rely upon the CI server to provide an '${env.GIT_BRANCH}'
@@ -53,7 +52,7 @@ public static String resolveUrlOrExpression(final ScmManager scmManager, final M
5352
* @throws ScmException
5453
*/
5554
public static String resolveBranchOrExpression(final ScmManager scmManager, final MavenProject project, final Log log) {
56-
String connectionUrl = resolveUrlOrExpression(scmManager, project, log);
55+
String connectionUrl = resolveUrlOrExpression(project, log);
5756

5857
// If a connectionURL other than the default expression was resolved, try to resolve the branch.
5958
if (!StringUtils.equals(connectionUrl, DEFAULT_URL_EXPRESSION)) {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ public class TagMasterMojo extends AbstractGitflowBranchMojo {
2929
protected void execute(final GitBranchType type, final String gitBranch, final String branchPattern) throws MojoExecutionException, MojoFailureException {
3030
if (project.isExecutionRoot() && type.equals(GitBranchType.MASTER)) {
3131
if (gitURLExpression == null) {
32-
gitURLExpression = ScmUtils.resolveUrlOrExpression(scmManager, project, getLog());
32+
gitURLExpression = ScmUtils.resolveUrlOrExpression(project, getLog());
3333
}
3434
String gitURL = resolveExpression(gitURLExpression);
3535
getLog().debug("gitURLExpression: '" + gitURLExpression + "' resolved to: '" + gitURL + "'");

0 commit comments

Comments
 (0)