Skip to content

Commit 932be4c

Browse files
authored
Merge pull request #32 from egineering-llc/release/1.3.0
Release/1.3.0
2 parents 1c05bcb + ee9570e commit 932be4c

File tree

3 files changed

+102
-4
lines changed

3 files changed

+102
-4
lines changed

README.md

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@ This plugin solves a few specific issues common in consolidated Hudson/Jenkins C
1919
1. Ensure the developers are following the (git branching) project version rules, and fail the build if they are not.
2020
2. Enable the maven-deploy-plugin to target a snapshots, test-releases, and releases repository.
2121
3. _Copy_ (rather than rebuild) the tested artifacts from the test-releases repository to the release repository, without doing a full project rebuild from the master branch.
22-
4. Reliably tag deploy builds from the 'master' branch
23-
5. Enable split 'deploy' vs. 'deliver' maven CI job configuration, without rebuilding artifacts for the 'deliver' phase.
22+
4. Set arbitrary project properties based upon the type of GIT branch being built.
23+
5. Reliably tag deploy builds from the 'master' branch
24+
6. Enable split 'deploy' vs. 'deliver' maven CI job configuration, without rebuilding artifacts for the 'deliver' phase.
2425

2526
In addition to supporting these goals for the project, this plugin does it in a manner that tries to be as effortless (yet configurable) as possible.
2627
If you use non-standard gitflow branch names (emer instead of hotfix), this plugin supports that. If you don't want to do version enforcement, this plugin supports that.
@@ -63,6 +64,21 @@ All of the solutions to these issues are implemented independently in different
6364
<goal>promote-master</goal>
6465
</goals>
6566
</execution>
67+
<execution>
68+
<id>git-branch-based-property</id>
69+
<goals>
70+
<goal>set-property</goal>
71+
</goals>
72+
<configuration>
73+
<key>a.property.name</key>
74+
<masterBranchValue>prod</masterBranchValue>
75+
<releaseBranchValue>${some.arbitrary.value.resolved.at.runtime}</releaseBranchValue>
76+
<hotfixBranchValue>emer</masterBranchValue>
77+
<developmentBranchValue>dev</developmentBranchValue>
78+
<otherBranchValue>foo</otherBranchValue>
79+
<undefinedBranchValue>local.build</undefinedBranchValue>
80+
</configuration>
81+
</execution>
6682
</executions>
6783
</plugin>
6884
</plugins>
@@ -261,5 +277,18 @@ that the first build deployed into. Once they're attached to the project, the `j
261277
the artifacts built by the first job into a jboss application server.
262278

263279

264-
280+
## Goal: `set-property` (Dynamically Set a Maven Project Property)
281+
282+
Some situations with automated testing (and integration testing in particular) demand changing configuration properties
283+
based upon the branch type being built. This is a common necessity when configuring automated DB refactorings as part of
284+
a build, or needing to setup / configure datasources for automated tests to run against.
285+
286+
This goal allows configuration of a single project property. If more than one property is needed, it would
287+
likely be advantageous to leverage the properties-maven-plugin:read-project-properties goal to read the properties from
288+
a file. The filename/url paths loaded by the properties-maven-plugin can reference a property configured by this
289+
gitflow-helper-maven-plugin:set-property goal. Since there is another clear path to load many properties based upon the
290+
value of a single property, the gitflow-helper-maven-plugin only sets a single property.
265291

292+
Configuration consists of defining the property key value, which can itself contain property references, as well as
293+
values for each type of branch. Any branch without a defined value will have the property resolve to `""`, an empty
294+
string.

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<groupId>com.e-gineering</groupId>
1010
<artifactId>gitflow-helper-maven-plugin</artifactId>
1111

12-
<version>1.2.5</version>
12+
<version>1.3.0</version>
1313
<packaging>maven-plugin</packaging>
1414

1515
<name>gitflow-helper-maven-plugin</name>
Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
package com.e_gineering.maven.gitflowhelper;
2+
3+
import org.apache.maven.plugin.MojoExecutionException;
4+
import org.apache.maven.plugin.MojoFailureException;
5+
import org.apache.maven.plugins.annotations.LifecyclePhase;
6+
import org.apache.maven.plugins.annotations.Mojo;
7+
import org.apache.maven.plugins.annotations.Parameter;
8+
9+
/**
10+
* Set a project property value based upon the current ${env.GIT_BRANCH} resolution.
11+
*/
12+
@Mojo(name = "set-property", defaultPhase = LifecyclePhase.VALIDATE)
13+
public class SetPropertyMojo extends AbstractGitflowBranchMojo {
14+
15+
@Parameter(property = "key", readonly = true, required = true)
16+
private String key;
17+
18+
@Parameter(property = "masterBranchValue", readonly = true, required = false)
19+
private String masterBranchValue = null;
20+
21+
@Parameter(property = "releaseBranchValue", readonly = true, required = false)
22+
private String releaseBranchValue = null;
23+
24+
@Parameter(property = "hotfixBranchValue", readonly = true, required = false)
25+
private String hotfixBranchValue = null;
26+
27+
@Parameter(property = "developmentBranchValue", readonly = true, required = false)
28+
private String developmentBranchValue = null;
29+
30+
@Parameter(property = "otherBranchValue", readonly = true, required = false)
31+
private String otherBranchValue = null;
32+
33+
@Parameter(property = "undefinedBranchValue", readonly = true, required = false)
34+
private String undefinedBranchValue = null;
35+
36+
@Override
37+
protected void execute(final GitBranchType type, final String gitBranch, final String branchPattern) throws MojoExecutionException, MojoFailureException {
38+
String resolvedValue = null;
39+
switch (type) {
40+
case MASTER: {
41+
resolvedValue = resolveExpression(masterBranchValue);
42+
break;
43+
}
44+
case RELEASE: {
45+
resolvedValue = resolveExpression(releaseBranchValue);
46+
break;
47+
}
48+
case HOTFIX: {
49+
resolvedValue = resolveExpression(hotfixBranchValue);
50+
break;
51+
}
52+
case DEVELOPMENT: {
53+
resolvedValue = resolveExpression(developmentBranchValue);
54+
break;
55+
}
56+
case OTHER: {
57+
resolvedValue = resolveExpression(otherBranchValue);
58+
break;
59+
}
60+
case UNDEFINED: {
61+
resolvedValue = resolveExpression(undefinedBranchValue);
62+
break;
63+
}
64+
}
65+
String resolvedKey = resolveExpression(key);
66+
getLog().info("Setting " + resolvedKey + " = '" + resolvedValue + "'");
67+
project.getProperties().put(resolvedKey, resolvedValue);
68+
}
69+
}

0 commit comments

Comments
 (0)