Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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() );
Expand All @@ -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 )
{
Expand All @@ -343,10 +341,18 @@ private Properties getMergedProperties( ItemWithProperties item )
props.putAll( item.getProperties() );
}

for ( Map.Entry<Object, Object> property : props.entrySet() )
Set<Object> 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 )
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -39,7 +38,8 @@
*/
public class AbstractInvokerMojoTest
{

private static final String PROPERTY_KEY = "prop-key";

private AbstractInvokerMojo mock;

@BeforeMethod
Expand All @@ -51,6 +51,8 @@ public void beforeMethod()
mock.setEndToken( "@" );
mock.setMavenProject(new MavenProject());
mock.setProperties(new Properties());

System.getProperties().remove(PROPERTY_KEY);
}

@Test
Expand Down Expand Up @@ -137,66 +139,89 @@ 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 );

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 );

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 );

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 );

assertThat( createAndConfigureAnInvocationRequest.getProperties().entrySet() )
.hasSize( 1 )
.extracting( "key", "value" )
.containsExactly(Tuple.tuple( "prop1", "value4" ));
.containsExactly(Tuple.tuple(PROPERTY_KEY, "value4" ));
}
}