Skip to content

Commit 1c5111d

Browse files
committed
Documentation updates
1 parent 388f2d0 commit 1c5111d

File tree

3 files changed

+40
-23
lines changed

3 files changed

+40
-23
lines changed

README.md

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,8 @@ All of the solutions to these issues are implemented independently in different
3232

3333
# I want all of that. (Usage)
3434

35-
1. Make sure your build server sets environment variables for git branches and git URLs. The plugin defaults are configured out of the box for Jenkins & Hudson.
35+
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.
36+
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.
3637
2. Configure the plugin goals and add the build extension to your Maven project. Here's an example that will get you going quickly...
3738

3839
```
@@ -53,7 +54,7 @@ All of the solutions to these issues are implemented independently in different
5354
<stageDeploymentRepository>${stage.repository}</stageDeploymentRepository>
5455
<snapshotDeploymentRepository>${snapshot.repository}</snapshotDeploymentRepository>
5556
<!-- The plugin will read the git branch ang git url by resolving these properties at run-time -->
56-
<gitBranchProperty>
57+
<gitBranchExpression/>
5758
</configuration>
5859
<executions>
5960
<execution>
@@ -102,7 +103,7 @@ The following properties change the behavior of this goal:
102103

103104
| Property | Default Value | SNAPSHOT allowed? | Description |
104105
| -------------------- | ------------- | --------------------------- | ----------- |
105-
| gitBranchExpression | ${env.GIT_BRANCH} | n/a | Maven property expression to resolve in order to determine the current git branch |
106+
| gitBranchExpression | current git branch resolved from SCM or ${env.GIT_BRANCH} | n/a | Maven property expression to resolve in order to determine the current git branch |
106107
| masterBranchPattern | origin/master | No | Regex. When matched, signals the master branch is being built. Note the lack of a subgroup. |
107108
| releaseBranchPattern | origin/release/(.*) | No | Regex. When matched, signals a release branch being built. Subgroup 1, if present, must match the Maven project version. |
108109
| hotfixBranchPattern | origin/hotfix/(.*) | No | Regex. When matched, signals a hotfix branch is being built. Subgroup 1, if present, must match the Maven project version. |
@@ -122,7 +123,7 @@ plugins in the build process (deploy, site-deploy, etc.) will use the repositori
122123

123124
| Property | Default Value | Description |
124125
| -------- | ------------- | ----------- |
125-
| gitBranchExpression | ${env.GIT_BRANCH} | Maven property expression to resolve in order to determine the current git branch |
126+
| gitBranchExpression | current git branch resolved from SCM or ${env.GIT_BRANCH} | Maven property expression to resolve in order to determine the current git branch |
126127
| releaseDeploymentRepository | n/a | The repository to use for releases. (Builds with a GIT_BRANCH matching `masterBranchPattern`) |
127128
| stageDeploymentRepository | n/a | The repository to use for staging. (Builds with a GIT_BRANCH matching `releaseBranchPattern` or `hotfixBranchPattern` |
128129
| snapshotDeploymentRepository | n/a | The repository to use for snapshots. (Builds matching `developmentBranchPattern` |
@@ -179,21 +180,16 @@ Can be replaced with the following plugin configuration, which also introduces t
179180
In a gitflow environment, a commit to a master branch should trigger a job to build on the master branch, which would result in the release being tagged if successful.
180181

181182
The `tag-master` goal executes the [maven-scm-plugin tag goal](https://maven.apache.org/scm/maven-scm-plugin/tag-mojo.html) when the
182-
`gitBranchExpression` resolves to a value matching the `masterBranchPattern` regular expression. To determine the SCM URL to use, the `gitURLExpression`
183-
is evaluated at run-time. The default expression, `${env.GIT_URL}`, is provided by Jenkins & Hudson.
184-
185-
To resolve the `<developerConnection>` in an `<scm>` block in your pom, you can specify the following in your plugin configuration:
186-
187-
```
188-
<gitURLExpression>${project.scm.developerConnection}</gitURLExpression>
189-
```
183+
`gitBranchExpression` resolves to a value matching the `masterBranchPattern` regular expression. To determine the SCM URL to use, the plugin looks for a
184+
`developerConnection` or `connection` information in an SCM block, and if not found the `gitURLExpression` is evaluated at run-time.
185+
The default expression, `${env.GIT_URL}`, is one that is commonly provided by Jenkins & Hudson.
190186

191187
The following properties can be configured for this goal:
192188

193189
| Property | Default Value | Description |
194190
| -------------------- | ------------- | ----------- |
195-
| gitBranchExpression | ${env.GIT_BRANCH} | Maven property expression to resolve in order to determine the current git branch |
196-
| gitURLExpression | ${env.GIT_URL} | Maven property expression to resolve for the GIT URL connection to use. |
191+
| gitBranchExpression | current git branch resolved from SCM or ${env.GIT_BRANCH} | Maven property expression to resolve in order to determine the current git branch |
192+
| gitURLExpression | current git branch resolved from SCM or ${env.GIT_URL} | Maven property expression to resolve for the GIT URL connection to use. |
197193
| masterBranchPattern | origin/master | Regex. When matched against the resolved value of `gitBranchExpression` this plugin executes the scm:tag goal using the `gitURLExpression` to resolve the git URL to use. |
198194
| tag | ${project.version} | An expression to use for the SCM tag. |
199195
| tag.plugin.groupId | org.apache.maven.plugins | The groupId of the plugin to use for tagging. |

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

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -13,17 +13,20 @@
1313
import org.apache.maven.scm.repository.ScmRepository;
1414

1515
public abstract class ScmUtils {
16+
17+
public static final String DEFAULT_URL_EXPRESSION = "${env.GIT_URL}";
18+
public static final String DEFAULT_BRANCH_EXPRESSION = "${env.GIT_BRANCH}";
19+
1620
/**
17-
* Given the ScmManager for the current execution cycle, and the MavenProject structure, determine if we can
18-
* find a maven-provided manner of resolving the current git branch.
21+
* Given the ScmManager for the current execution cycle, and the MavenProject structure, determine the SCM URL or
22+
* an expression we can resolve the URL from.
1923
*
2024
* @param scmManager The current maven ScmManager
2125
* @param project The Current maven Project
2226
* @param log A Log to write to
23-
* @return The current git branch name, or <code>${env.GIT_BRACH}</code> if the current git branch could not be resolved.
24-
* @throws ScmException
27+
* @return The developerConnection, if none set, the connection, if none set, then the expression, <code>"${env.GIT_URL}"</code>
2528
*/
26-
public static String resolveBranchOrExpression(final ScmManager scmManager, final MavenProject project, final Log log) {
29+
public static String resolveUrlOrExpression(final ScmManager scmManager, final MavenProject project, final Log log) {
2730
String connectionUrl = null;
2831

2932
// Some projects don't specify SCM Blocks, and instead rely upon the CI server to provide an '${env.GIT_BRANCH}'
@@ -33,9 +36,27 @@ public static String resolveBranchOrExpression(final ScmManager scmManager, fina
3336
if (StringUtils.isBlank(connectionUrl)) {
3437
connectionUrl = project.getScm().getConnection();
3538
}
39+
return connectionUrl;
3640
}
3741

38-
if (StringUtils.isNotBlank(connectionUrl)) {
42+
return DEFAULT_URL_EXPRESSION;
43+
}
44+
45+
/**
46+
* Given the ScmManager for the current execution cycle, and the MavenProject structure, determine if we can
47+
* find a maven-provided manner of resolving the current git branch.
48+
*
49+
* @param scmManager The current maven ScmManager
50+
* @param project The Current maven Project
51+
* @param log A Log to write to
52+
* @return The current git branch name, or <code>${env.GIT_BRACH}</code> if the current git branch could not be resolved.
53+
* @throws ScmException
54+
*/
55+
public static String resolveBranchOrExpression(final ScmManager scmManager, final MavenProject project, final Log log) {
56+
String connectionUrl = resolveUrlOrExpression(scmManager, project, log);
57+
58+
// If a connectionURL other than the default expression was resolved, try to resolve the branch.
59+
if (!StringUtils.equals(connectionUrl, DEFAULT_URL_EXPRESSION)) {
3960
try {
4061
ScmRepository repository = scmManager.makeScmRepository(connectionUrl);
4162
ScmProvider provider = scmManager.getProviderByRepository(repository);
@@ -51,7 +72,7 @@ public static String resolveBranchOrExpression(final ScmManager scmManager, fina
5172
}
5273
}
5374

54-
log.debug("Git branch unresolvable from Project SCM definition, defaulting to ${env.GIT_BRANCH}");
55-
return "${env.GIT_BRANCH}";
75+
log.debug("Git branch unresolvable from Project SCM definition, defaulting to " + DEFAULT_BRANCH_EXPRESSION);
76+
return DEFAULT_BRANCH_EXPRESSION;
5677
}
5778
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ public class TagMasterMojo extends AbstractGitflowBranchMojo {
4444
protected void execute(final GitBranchType type, final String gitBranch, final String branchPattern) throws MojoExecutionException, MojoFailureException {
4545
if (project.isExecutionRoot() && type.equals(GitBranchType.MASTER)) {
4646
if (gitURLExpression == null) {
47-
gitURLExpression = "${env.GIT_URL}";
47+
gitURLExpression = ScmUtils.resolveUrlOrExpression(scmManager, project, getLog());
4848
}
4949
String gitURL = resolveExpression(gitURLExpression);
5050
getLog().debug("gitURLExpression: '" + gitURLExpression + "' resolved to: '" + gitURL + "'");

0 commit comments

Comments
 (0)