@@ -37,6 +37,7 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti
3737
3838 // Look for a gitflow-helper-maven-plugin, so we can determine what the gitBranchExpression and masterBranchPattern are...
3939 String masterBranchPattern = null ;
40+
4041 String gitBranchExpression = null ;
4142 boolean pluginFound = false ;
4243
@@ -47,27 +48,21 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti
4748 List <Plugin > dropPlugins = new ArrayList <Plugin >();
4849
4950 for (Plugin plugin : project .getBuildPlugins ()) {
50- // Don't drop our plugin. Read it's config.
51+ // Don't drop our plugin. Read it's config
5152 if (plugin .getKey ().equals ("com.e-gineering:gitflow-helper-maven-plugin" )) {
5253 pluginFound = true ;
5354
5455 logger .debug ("gitflow-helper-maven-plugin found in project: [" + project .getName () + "]" );
5556
5657 if (masterBranchPattern == null ) {
57- masterBranchPattern = extractMasterBranchPattern (plugin .getConfiguration ());
58- for (int i = 0 ; i < plugin .getExecutions ().size () && masterBranchPattern == null ; i ++) {
59- masterBranchPattern = extractMasterBranchPattern (plugin .getExecutions ().get (i ).getConfiguration ());
60- }
58+ masterBranchPattern = extractPluginConfigValue ("masterBranchPattern" , plugin );
6159 }
6260
6361 if (gitBranchExpression == null ) {
64- gitBranchExpression = extractGitBranchExpression (plugin .getConfiguration ());
65- for (int i = 0 ; i < plugin .getExecutions ().size () && gitBranchExpression == null ; i ++) {
66- gitBranchExpression = extractGitBranchExpression (plugin .getExecutions ().get (i ).getConfiguration ());
67- }
62+ gitBranchExpression = extractPluginConfigValue ("gitBranchExpression" , plugin );
6863 }
6964
70- // Don't drop the maven-deploy-plugin. Read it's config.
65+ // Don't drop the maven-deploy-plugin
7166 } else if (plugin .getKey ().equals ("org.apache.maven.plugins:maven-deploy-plugin" )) {
7267 logger .debug ("gitflow-helper-maven-plugin removing plugin: " + plugin + " from project: " + project .getName ());
7368 } else {
@@ -108,17 +103,17 @@ public void afterProjectsRead(MavenSession session) throws MavenExecutionExcepti
108103 }
109104 }
110105
111- private String extractMasterBranchPattern ( Object configuration ) {
112- try {
113- return (( Xpp3Dom ) configuration ). getChild ( "masterBranchPattern" ). getValue ();
114- } catch ( Exception ex ) {
106+ private String extractPluginConfigValue ( String parameter , Plugin plugin ) {
107+ String value = extractConfigValue ( parameter , plugin . getConfiguration ());
108+ for ( int i = 0 ; i < plugin . getExecutions (). size () && value == null ; i ++) {
109+ value = extractConfigValue ( parameter , plugin . getExecutions (). get ( i ). getConfiguration ());
115110 }
116- return null ;
111+ return value ;
117112 }
118113
119- private String extractGitBranchExpression ( Object configuration ) {
114+ private String extractConfigValue ( String parameter , Object configuration ) {
120115 try {
121- return ((Xpp3Dom ) configuration ).getChild ("gitBranchExpression" ).getValue ();
116+ return ((Xpp3Dom ) configuration ).getChild (parameter ).getValue ();
122117 } catch (Exception ex ) {
123118 }
124119 return null ;
0 commit comments