Skip to content

Commit 41f08b4

Browse files
authored
Merge pull request e-gineering#126 from egineering-llc/feature/other-branch-reversioning-extension
Feature/other branch reversioning extension
2 parents ca8de85 + 1261c44 commit 41f08b4

25 files changed

+800
-205
lines changed

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -403,16 +403,16 @@ the artifacts built by the first job into a jboss application server.
403403

404404
## To Debug the plugin (replicating a test-case but without being run from jUnit)
405405
You can 'bootstrap' the plugin into your local repository and get the test project stubbed by running:
406-
`mvn -Dmaven.test.skip=true install`
407-
408-
Then, change directories:
409-
`cd target/test-classes/project-stub`
410-
411-
From there, you'll need to supply the required environment variables or commandline arguments to `mvnDebug`:
412406
```
407+
mvn process-test-classes
408+
mvn -Dmaven.test.skip=true install
409+
cd target/test-classes/project-stub`
413410
export GIT_BRANCH=origin/feature/mybranch-foo-bar
414-
mvnDebug -Dstub.project.version=5.0.0-SNAPSHOT -DotherBranchDeploy=semver -DallowGitflowPluginSnapshot=true deploy
411+
mvnDebug -Dstub.project.version=5.0.0-SNAPSHOT -DallowGitflowPluginSnapshot=true deploy
415412
```
413+
This will get the test classes into the target directory and install the plugin into your local repository.
414+
Then you move to the proper stub directory, supply the environment variables and arguments to `mvnDebug`.
415+
416416
You can then connect a remote debugger and step through the plugin code.
417417

418418
## Building with IntelliJ IDEA notes

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@
274274
<dependency>
275275
<groupId>junit</groupId>
276276
<artifactId>junit</artifactId>
277-
<version>4.8.2</version>
277+
<version>4.13.1</version>
278278
<scope>test</scope>
279279
</dependency>
280280
</dependencies>
Lines changed: 171 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,171 @@
1+
package com.e_gineering.maven.gitflowhelper;
2+
3+
import org.apache.maven.AbstractMavenLifecycleParticipant;
4+
import org.apache.maven.MavenExecutionException;
5+
import org.apache.maven.execution.MavenSession;
6+
import org.apache.maven.lifecycle.internal.MojoDescriptorCreator;
7+
import org.apache.maven.model.Plugin;
8+
import org.apache.maven.project.MavenProject;
9+
import org.apache.maven.scm.manager.ScmManager;
10+
import org.codehaus.plexus.component.annotations.Requirement;
11+
import org.codehaus.plexus.logging.Logger;
12+
import org.codehaus.plexus.util.cli.CommandLineUtils;
13+
import org.codehaus.plexus.util.xml.Xpp3Dom;
14+
15+
import java.io.IOException;
16+
import java.util.Properties;
17+
18+
public abstract class AbstractBranchDetectingExtension extends AbstractMavenLifecycleParticipant {
19+
@Requirement
20+
MojoDescriptorCreator descriptorCreator;
21+
22+
@Requirement
23+
Logger logger;
24+
25+
@Requirement
26+
ScmManager scmManager;
27+
28+
boolean pluginFound = false;
29+
String masterBranchPattern;
30+
String supportBranchPattern;
31+
String releaseBranchPattern;
32+
String hotfixBranchPattern;
33+
String developmentBranchPattern;
34+
String featureOrBugfixBranchPattern;
35+
String otherDeployBranchPattern;
36+
String otherBranchVersionDelimiter;
37+
GitBranchInfo branchInfo;
38+
Properties systemEnvVars;
39+
40+
@Override
41+
public void afterProjectsRead(MavenSession session) throws MavenExecutionException {
42+
try {
43+
systemEnvVars = CommandLineUtils.getSystemEnvVars();
44+
} catch (IOException ioe) {
45+
throw new MavenExecutionException("Unable to read System Envirionment Variables: ", ioe);
46+
}
47+
48+
// Look for a configured gitflow-helper-maven-plugin,
49+
// To determine what the gitBranchExpression and branch patterns are...
50+
String gitBranchExpression = null;
51+
52+
pluginFound = false;
53+
for (MavenProject project : session.getProjects()) {
54+
for (Plugin plugin : project.getModel().getBuild().getPlugins()) {
55+
// Don't drop our plugin. Read it's config
56+
if (plugin.getKey().equals("com.e-gineering:gitflow-helper-maven-plugin")) {
57+
pluginFound = true;
58+
59+
logger.debug("gitflow-helper-maven-plugin found in project: [" + project.getName() + "]");
60+
61+
if (masterBranchPattern == null) {
62+
masterBranchPattern = extractPluginConfigValue("masterBranchPattern", plugin);
63+
}
64+
65+
if (supportBranchPattern == null) {
66+
supportBranchPattern = extractPluginConfigValue("supportBranchPattern", plugin);
67+
}
68+
69+
if (releaseBranchPattern == null) {
70+
releaseBranchPattern = extractPluginConfigValue("releaseBranchPattern", plugin);
71+
}
72+
73+
if (hotfixBranchPattern == null) {
74+
hotfixBranchPattern = extractPluginConfigValue("hotfixBranchPattern", plugin);
75+
}
76+
77+
if (developmentBranchPattern == null) {
78+
developmentBranchPattern = extractPluginConfigValue("developmentBranchPattern", plugin);
79+
}
80+
81+
if (featureOrBugfixBranchPattern == null) {
82+
featureOrBugfixBranchPattern = extractPluginConfigValue("featureOrBugfixBranchPattern", plugin);
83+
}
84+
85+
if (otherDeployBranchPattern == null) {
86+
otherDeployBranchPattern = extractPluginConfigValue("otherDeployBranchPattern", plugin);
87+
}
88+
89+
if (otherBranchVersionDelimiter == null) {
90+
otherBranchVersionDelimiter = extractPluginConfigValue("otherBranchVersionDelimiter", plugin);
91+
}
92+
93+
if (gitBranchExpression == null) {
94+
gitBranchExpression = extractPluginConfigValue("gitBranchExpression", plugin);
95+
}
96+
}
97+
}
98+
}
99+
100+
// Any missing configuration options need to be defaulted.
101+
if (pluginFound) {
102+
if (masterBranchPattern == null) {
103+
logger.debug("Using default master branch Pattern.");
104+
masterBranchPattern = "(origin/)?master";
105+
}
106+
logger.debug("Master Branch Pattern: " + masterBranchPattern);
107+
108+
if (supportBranchPattern == null) {
109+
logger.debug("Using default support branch Pattern.");
110+
supportBranchPattern = "(origin/)?support/(.*)";
111+
}
112+
logger.debug("Support Branch Pattern: " + supportBranchPattern);
113+
114+
if (releaseBranchPattern == null) {
115+
logger.debug("Using default release branch Pattern.");
116+
releaseBranchPattern = "(origin/)?release/(.*)";
117+
}
118+
logger.debug("Release Branch Pattern: " + releaseBranchPattern);
119+
120+
if (hotfixBranchPattern == null) {
121+
logger.debug("Using default hotfix branch Pattern.");
122+
hotfixBranchPattern = "(origin/)?hotfix/(.*)";
123+
}
124+
logger.debug("Hotfix Branch Pattern: " + hotfixBranchPattern);
125+
126+
if (developmentBranchPattern == null) {
127+
logger.debug("Using default development Pattern.");
128+
developmentBranchPattern = "(origin/)?develop";
129+
}
130+
logger.debug("Development Branch Pattern: " + developmentBranchPattern);
131+
132+
if (featureOrBugfixBranchPattern == null) {
133+
logger.debug("Using default feature or bugfix Pattern.");
134+
featureOrBugfixBranchPattern = "(origin/)?(?:feature|bugfix)/(.*)";
135+
}
136+
logger.debug("Feature or Bugfix Branch Pattern: " + featureOrBugfixBranchPattern);
137+
138+
if (otherDeployBranchPattern == null) {
139+
logger.debug("Using default other deployment branch Pattern.");
140+
otherDeployBranchPattern = "";
141+
}
142+
logger.debug("Other Branch Deployment Pattern: " + otherDeployBranchPattern);
143+
144+
if (otherBranchVersionDelimiter == null) {
145+
logger.debug("Using default otherBranchVersionDelimiter.");
146+
otherBranchVersionDelimiter = "+";
147+
}
148+
149+
ScmUtils scmUtils = new ScmUtils(systemEnvVars, scmManager, session.getTopLevelProject(), new PlexusLoggerToMavenLog(logger), masterBranchPattern, supportBranchPattern, releaseBranchPattern, hotfixBranchPattern, developmentBranchPattern);
150+
branchInfo = scmUtils.resolveBranchInfo(gitBranchExpression);
151+
} else {
152+
logger.debug("Unable to configure gitflow-helper-maven-plugin lifecycle extensions. No Plugin configuration found.");
153+
}
154+
}
155+
156+
private String extractPluginConfigValue(String parameter, Plugin plugin) {
157+
String value = extractConfigValue(parameter, plugin.getConfiguration());
158+
for (int i = 0; i < plugin.getExecutions().size() && value == null; i++) {
159+
value = extractConfigValue(parameter, plugin.getExecutions().get(i).getConfiguration());
160+
}
161+
return value;
162+
}
163+
164+
private String extractConfigValue(String parameter, Object configuration) {
165+
try {
166+
return ((Xpp3Dom) configuration).getChild(parameter).getValue();
167+
} catch (Exception ignored) {
168+
}
169+
return null;
170+
}
171+
}

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

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,17 +2,13 @@
22

33
import org.apache.maven.RepositoryUtils;
44
import org.apache.maven.artifact.Artifact;
5-
import org.apache.maven.artifact.InvalidRepositoryException;
65
import org.apache.maven.artifact.repository.ArtifactRepository;
7-
import org.apache.maven.bridge.MavenRepositorySystem;
8-
import org.apache.maven.model.DeploymentRepository;
96
import org.apache.maven.plugin.MojoExecutionException;
107
import org.apache.maven.plugin.MojoFailureException;
118
import org.apache.maven.plugins.annotations.Component;
129
import org.apache.maven.plugins.annotations.Parameter;
1310
import org.apache.maven.project.MavenProjectHelper;
1411
import org.apache.maven.shared.utils.StringUtils;
15-
import org.codehaus.plexus.component.annotations.Requirement;
1612
import org.codehaus.plexus.util.FileUtils;
1713
import org.eclipse.aether.DefaultRepositorySystemSession;
1814
import org.eclipse.aether.RepositorySystem;
@@ -38,7 +34,6 @@
3834
import java.io.PrintWriter;
3935
import java.nio.file.Files;
4036
import java.util.ArrayList;
41-
import java.util.Arrays;
4237
import java.util.List;
4338
import java.util.Objects;
4439
import java.util.Optional;
@@ -75,7 +70,7 @@ private static PrintWriter newPrintWriter(File catalog) throws FileNotFoundExcep
7570
RepositorySystemSession repositorySystemSession;
7671

7772
@Parameter(defaultValue = "${project.build.directory}", required = true)
78-
private File buildDirectory;
73+
File buildDirectory;
7974

8075
@Component
8176
private RepositorySystem repositorySystem;

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.e_gineering.maven.gitflowhelper;
22

3-
import org.apache.maven.artifact.Artifact;
4-
import org.apache.maven.artifact.InvalidRepositoryException;
53
import org.apache.maven.plugin.MojoExecutionException;
64
import org.apache.maven.plugin.MojoFailureException;
75
import org.apache.maven.plugins.annotations.Execute;

0 commit comments

Comments
 (0)