diff --git a/src/main/java/com/soebes/maven/plugins/iterator/AbstractInvokerMojo.java b/src/main/java/com/soebes/maven/plugins/iterator/AbstractInvokerMojo.java index 438dab6..c2cc601 100644 --- a/src/main/java/com/soebes/maven/plugins/iterator/AbstractInvokerMojo.java +++ b/src/main/java/com/soebes/maven/plugins/iterator/AbstractInvokerMojo.java @@ -22,9 +22,11 @@ import java.io.File; import java.util.ArrayList; import java.util.Collections; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Properties; +import java.util.Set; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; @@ -309,7 +311,7 @@ protected InvocationRequest createAndConfigureAnInvocationRequest( ItemWithPrope // mvn -pl xyz-@item@ clean package request.setProjects( getProjectsAfterPlaceHolderIsReplaced( currentValue.getName() ) ); - Properties props = getMergedProperties(currentValue ); + Properties props = getMergedProperties( currentValue ); request.setProperties( props ); request.setRecursive( isRecursive() ); @@ -328,10 +330,6 @@ protected InvocationRequest createAndConfigureAnInvocationRequest( ItemWithPrope private Properties getMergedProperties( ItemWithProperties item ) { Properties props = new Properties(); - if ( getMavenProject().getProperties() != null ) - { - props.putAll( getMavenProject().getProperties() ); - } if ( getProperties() != null ) { @@ -343,10 +341,18 @@ private Properties getMergedProperties( ItemWithProperties item ) props.putAll( item.getProperties() ); } - for ( Map.Entry property : props.entrySet() ) + Set relevantKeys = new HashSet<>(props.keySet()); + + // Simply adding all project properties can cause issues with the command line character limit + // Thus only explicitly "activated" properties are added (plugin, item and relevant system-properties) + if ( getMavenProject().getProperties() != null ) + { + relevantKeys.addAll( getMavenProject().getProperties().keySet() ); + } + + for ( Object key : relevantKeys ) { - String key = (String) property.getKey(); - String systemPropertyValue = System.getProperty( key ); + String systemPropertyValue = System.getProperty( (String) key ); if ( systemPropertyValue != null ) { diff --git a/src/test/java/com/soebes/maven/plugins/iterator/AbstractInvokerMojoTest.java b/src/test/java/com/soebes/maven/plugins/iterator/AbstractInvokerMojoTest.java index 28e888e..79b53e9 100644 --- a/src/test/java/com/soebes/maven/plugins/iterator/AbstractInvokerMojoTest.java +++ b/src/test/java/com/soebes/maven/plugins/iterator/AbstractInvokerMojoTest.java @@ -24,7 +24,6 @@ import java.io.File; import java.util.Arrays; import java.util.Collections; -import java.util.Map; import java.util.Properties; import org.apache.maven.project.MavenProject; @@ -39,7 +38,8 @@ */ public class AbstractInvokerMojoTest { - + private static final String PROPERTY_KEY = "prop-key"; + private AbstractInvokerMojo mock; @BeforeMethod @@ -51,6 +51,8 @@ public void beforeMethod() mock.setEndToken( "@" ); mock.setMavenProject(new MavenProject()); mock.setProperties(new Properties()); + + System.getProperties().remove(PROPERTY_KEY); } @Test @@ -137,9 +139,32 @@ public void shouldReplaceInMultipleProjects() } @Test - public void shouldAddProjectProperties() + public void shouldNotAddAllProjectProperties() + { + mock.getMavenProject().getProperties().put(PROPERTY_KEY, "value1" ); + + ItemWithProperties prop = new ItemWithProperties( "item" , ItemWithProperties.NO_PROPERTIES ); + InvocationRequest createAndConfigureAnInvocationRequest = mock.createAndConfigureAnInvocationRequest( prop ); + + assertThat( createAndConfigureAnInvocationRequest.getProperties().entrySet() ).isEmpty(); + } + + @Test + public void shouldNotAddAllSystemProperties() + { + System.getProperties().put(PROPERTY_KEY, "value1" ); + + ItemWithProperties prop = new ItemWithProperties( "item" , ItemWithProperties.NO_PROPERTIES ); + InvocationRequest createAndConfigureAnInvocationRequest = mock.createAndConfigureAnInvocationRequest( prop ); + + assertThat( createAndConfigureAnInvocationRequest.getProperties().entrySet() ).isEmpty(); + } + + @Test + public void shouldAddSystemPropertyAlsoDefinedAsProjectProperty() { - mock.getMavenProject().getProperties().put( "prop1", "value1" ); + mock.getMavenProject().getProperties().put(PROPERTY_KEY, "value1" ); + System.getProperties().put(PROPERTY_KEY, "value2" ); ItemWithProperties prop = new ItemWithProperties( "item" , ItemWithProperties.NO_PROPERTIES ); InvocationRequest createAndConfigureAnInvocationRequest = mock.createAndConfigureAnInvocationRequest( prop ); @@ -147,14 +172,14 @@ public void shouldAddProjectProperties() assertThat( createAndConfigureAnInvocationRequest.getProperties().entrySet() ) .hasSize( 1 ) .extracting( "key", "value" ) - .containsExactly(Tuple.tuple( "prop1", "value1" )); + .containsExactly(Tuple.tuple(PROPERTY_KEY, "value2" )); } @Test public void shouldAddPluginProperties() { - mock.getMavenProject().getProperties().put( "prop1", "value1" ); - mock.getProperties().put( "prop1", "value2" ); + mock.getMavenProject().getProperties().put(PROPERTY_KEY, "value1" ); + mock.getProperties().put(PROPERTY_KEY, "value2" ); ItemWithProperties prop = new ItemWithProperties( "item" , ItemWithProperties.NO_PROPERTIES ); InvocationRequest createAndConfigureAnInvocationRequest = mock.createAndConfigureAnInvocationRequest( prop ); @@ -162,16 +187,16 @@ public void shouldAddPluginProperties() assertThat( createAndConfigureAnInvocationRequest.getProperties().entrySet() ) .hasSize( 1 ) .extracting( "key", "value" ) - .containsExactly(Tuple.tuple( "prop1", "value2" )); + .containsExactly(Tuple.tuple(PROPERTY_KEY, "value2" )); } @Test public void shouldAddItemProperties() { - mock.getMavenProject().getProperties().put( "prop1", "value1" ); - mock.getProperties().put( "prop1", "value2" ); + mock.getMavenProject().getProperties().put(PROPERTY_KEY, "value1" ); + mock.getProperties().put(PROPERTY_KEY, "value2" ); Properties itemProperties = new Properties(); - itemProperties.put( "prop1", "value3" ); + itemProperties.put(PROPERTY_KEY, "value3" ); ItemWithProperties prop = new ItemWithProperties( "item" , itemProperties ); InvocationRequest createAndConfigureAnInvocationRequest = mock.createAndConfigureAnInvocationRequest( prop ); @@ -179,17 +204,17 @@ public void shouldAddItemProperties() assertThat( createAndConfigureAnInvocationRequest.getProperties().entrySet() ) .hasSize( 1 ) .extracting( "key", "value" ) - .containsExactly(Tuple.tuple( "prop1", "value3" )); + .containsExactly(Tuple.tuple(PROPERTY_KEY, "value3" )); } @Test public void shouldAddSystemProperties() { - mock.getMavenProject().getProperties().put( "prop1", "value1" ); - mock.getProperties().put( "prop1", "value2" ); + mock.getMavenProject().getProperties().put(PROPERTY_KEY, "value1" ); + mock.getProperties().put(PROPERTY_KEY, "value2" ); Properties itemProperties = new Properties(); - itemProperties.put( "prop1", "value3" ); - System.getProperties().put( "prop1", "value4" ); + itemProperties.put(PROPERTY_KEY, "value3" ); + System.getProperties().put(PROPERTY_KEY, "value4" ); ItemWithProperties prop = new ItemWithProperties( "item" , itemProperties ); InvocationRequest createAndConfigureAnInvocationRequest = mock.createAndConfigureAnInvocationRequest( prop ); @@ -197,6 +222,6 @@ public void shouldAddSystemProperties() assertThat( createAndConfigureAnInvocationRequest.getProperties().entrySet() ) .hasSize( 1 ) .extracting( "key", "value" ) - .containsExactly(Tuple.tuple( "prop1", "value4" )); + .containsExactly(Tuple.tuple(PROPERTY_KEY, "value4" )); } }