Skip to content

Commit 8888dc7

Browse files
authored
Merge pull request #42 from egineering-llc/release/1.5.0
Release/1.5.0
2 parents 7a1e634 + 444b3a0 commit 8888dc7

File tree

2 files changed

+32
-5
lines changed

2 files changed

+32
-5
lines changed

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.4.0</version>
12+
<version>1.5.0</version>
1313
<packaging>maven-plugin</packaging>
1414

1515
<name>gitflow-helper-maven-plugin</name>

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

Lines changed: 31 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@
44
import org.apache.maven.AbstractMavenLifecycleParticipant;
55
import org.apache.maven.MavenExecutionException;
66
import org.apache.maven.execution.MavenSession;
7+
import org.apache.maven.lifecycle.internal.MojoDescriptorCreator;
78
import org.apache.maven.model.Plugin;
9+
import org.apache.maven.plugin.prefix.NoPluginFoundForPrefixException;
810
import org.apache.maven.project.MavenProject;
911
import org.codehaus.plexus.component.annotations.Component;
1012
import org.codehaus.plexus.component.annotations.Requirement;
@@ -13,7 +15,10 @@
1315
import org.codehaus.plexus.util.xml.Xpp3Dom;
1416

1517
import java.io.IOException;
16-
import java.util.*;
18+
import java.util.ArrayList;
19+
import java.util.HashMap;
20+
import java.util.List;
21+
import java.util.Properties;
1722

1823
/**
1924
* Maven extension which removes (skips) undesired plugins from the build reactor when running on a master branch.
@@ -23,6 +28,9 @@
2328
@Component(role = AbstractMavenLifecycleParticipant.class, hint = "promote-master")
2429
public class MasterPromoteExtension extends AbstractMavenLifecycleParticipant {
2530

31+
@Requirement
32+
private MojoDescriptorCreator descriptorCreator;
33+
2634
@Requirement
2735
private Logger logger;
2836

@@ -41,6 +49,22 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti
4149
String gitBranchExpression = null;
4250
boolean pluginFound = false;
4351

52+
// Any plugin which is part of the project goals needs to be retained.
53+
List<Plugin> pluginsToRetain = new ArrayList<Plugin>(session.getGoals().size());
54+
55+
List<String> goals = session.getGoals();
56+
for (String goal : goals) {
57+
int delimiter = goal.indexOf(":");
58+
if (delimiter != -1) {
59+
String prefix = goal.substring(0, delimiter);
60+
try {
61+
pluginsToRetain.add(descriptorCreator.findPluginForPrefix(prefix, session));
62+
} catch (NoPluginFoundForPrefixException ex) {
63+
throw new MavenExecutionException("Unable to resolve plugin for prefix: " + prefix, ex);
64+
}
65+
}
66+
}
67+
4468
// Build up a map of plugins to remove from projects, if we're on the master branch.
4569
HashMap<MavenProject, List<Plugin>> pluginsToDrop = new HashMap<MavenProject, List<Plugin>>();
4670

@@ -61,11 +85,14 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti
6185
if (gitBranchExpression == null) {
6286
gitBranchExpression = extractPluginConfigValue("gitBranchExpression", plugin);
6387
}
64-
65-
// Don't drop the maven-deploy-plugin
88+
// Don't drop things we declare goals for.
89+
} else if (pluginsToRetain.contains(plugin)) {
90+
logger.debug("gitflow-helper-maven-plugin retaining plugin: " + plugin + " from project: " + project.getName());
91+
// Don't drop the maven-deploy-plugin
6692
} else if (plugin.getKey().equals("org.apache.maven.plugins:maven-deploy-plugin")) {
67-
logger.debug("gitflow-helper-maven-plugin removing plugin: " + plugin + " from project: " + project.getName());
93+
logger.debug("gitflow-helper-maven-plugin retaining plugin: " + plugin + " from project: " + project.getName());
6894
} else {
95+
logger.debug("gitflow-helper-maven-plugin removing plugin: " + plugin + " from project: " + project.getName());
6996
dropPlugins.add(plugin);
7097
}
7198
}

0 commit comments

Comments
 (0)