Skip to content

Commit 374c149

Browse files
committed
This should work, and here's some documentation.
1 parent b0eb266 commit 374c149

File tree

2 files changed

+35
-5
lines changed

2 files changed

+35
-5
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.

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,8 @@ protected void execute(final GitBranchType type, final String gitBranch, final S
6262
break;
6363
}
6464
}
65-
getLog().info("Setting " + key + " = '" + resolvedValue + "'");
66-
project.getProperties().put(key, resolvedValue);
65+
String resolvedKey = resolveExpression(key);
66+
getLog().info("Setting " + resolvedKey + " = '" + resolvedValue + "'");
67+
project.getProperties().put(resolvedKey, resolvedValue);
6768
}
6869
}

0 commit comments

Comments
 (0)