Skip to content

Commit 8cee294

Browse files
committed
expand upon property functions.
1 parent ef9c1a6 commit 8cee294

File tree

2 files changed

+95
-69
lines changed

2 files changed

+95
-69
lines changed
Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
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+
import java.util.Enumeration;
10+
import java.util.Properties;
11+
12+
/**
13+
* Set a project property value based upon the current ${env.GIT_BRANCH} resolution.
14+
*/
15+
@Mojo(name = "set-properties", defaultPhase = LifecyclePhase.INITIALIZE)
16+
public class SetPropertiesMojo extends AbstractGitflowBranchMojo {
17+
18+
@Parameter(property = "masterBranchProperties", readonly = true, required = false)
19+
private Properties masterBranchProperties = new Properties();
20+
21+
@Parameter(property = "releaseBranchProperties", readonly = true, required = false)
22+
private Properties releaseBranchProperties = new Properties();
23+
24+
@Parameter(property = "hotfixBranchProperties", readonly = true, required = false)
25+
private Properties hotfixBranchProperties = new Properties();
26+
27+
@Parameter(property = "developmentBranchValue", readonly = true, required = false)
28+
private Properties developmentBranchProperties = new Properties();
29+
30+
@Parameter(property = "otherBranchValue", readonly = true, required = false)
31+
private Properties otherBranchProperties = new Properties();
32+
33+
@Parameter(property = "undefinedBranchValue", readonly = true, required = false)
34+
private Properties undefinedBranchValue = new Properties();
35+
36+
@Parameter(property = "scope", readonly = false, required = true, defaultValue = "project")
37+
private String scope;
38+
39+
@Parameter(property ="resolve", defaultValue = "true")
40+
private boolean resolve;
41+
42+
43+
@Override
44+
protected void execute(final GitBranchType type, final String gitBranch, final String branchPattern) throws MojoExecutionException, MojoFailureException {
45+
Properties toInject = null;
46+
switch (type) {
47+
case MASTER: {
48+
toInject = masterBranchProperties;
49+
break;
50+
}
51+
case RELEASE: {
52+
toInject = releaseBranchProperties;
53+
break;
54+
}
55+
case HOTFIX: {
56+
toInject = hotfixBranchProperties;
57+
break;
58+
}
59+
case DEVELOPMENT: {
60+
toInject = developmentBranchProperties;
61+
break;
62+
}
63+
case OTHER: {
64+
toInject = otherBranchProperties;
65+
break;
66+
}
67+
case UNDEFINED: {
68+
toInject = undefinedBranchValue;
69+
break;
70+
}
71+
}
72+
73+
getLog().debug("Setting " + toInject.size() + " properties...");
74+
75+
for (Enumeration<?> propertyNames = toInject.propertyNames(); propertyNames.hasMoreElements(); ) {
76+
String propertyName = propertyNames.nextElement().toString();
77+
78+
String key = resolveExpression(propertyName);
79+
String value = resolveExpression(toInject.getProperty(propertyName));
80+
81+
getLog().debug(" " + key + " = " + value);
82+
83+
Object replaced;
84+
if ("system".equalsIgnoreCase(scope)) {
85+
replaced = System.setProperty(key, value);
86+
} else {
87+
replaced = project.getProperties().setProperty(key, value);
88+
}
89+
90+
if (replaced != null) {
91+
getLog().debug(" replaced previous value : " + replaced);
92+
}
93+
}
94+
}
95+
}

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

Lines changed: 0 additions & 69 deletions
This file was deleted.

0 commit comments

Comments
 (0)