Skip to content

Commit

Permalink
[MNG-7417] Several classes do not set properties properly for buildin…
Browse files Browse the repository at this point in the history
…g requests

This closes #306
  • Loading branch information
slachiewicz authored and michael-o committed Feb 20, 2022
1 parent 03df5f7 commit 69d6c6d
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 23 deletions.
Expand Up @@ -570,6 +570,7 @@ private ProjectRelocation retrieveRelocatedProject( Artifact artifact, MetadataR
configuration.setProcessPlugins( false );
configuration.setRepositoryMerging( ProjectBuildingRequest.RepositoryMerging.REQUEST_DOMINANT );
configuration.setSystemProperties( getSystemProperties() );
configuration.setUserProperties( new Properties() );
configuration.setRepositorySession( legacySupport.getRepositorySession() );

project = projectBuilder.build( pomArtifact, configuration ).getProject();
Expand Down
Expand Up @@ -128,7 +128,8 @@ protected MavenSession createMavenSession( File pom, Properties executionPropert
.setLocalRepository( request.getLocalRepository() )
.setRemoteRepositories( request.getRemoteRepositories() )
.setPluginArtifactRepositories( request.getPluginArtifactRepositories() )
.setSystemProperties( executionProperties );
.setSystemProperties( executionProperties )
.setUserProperties( new Properties() );

List<MavenProject> projects = new ArrayList<>();

Expand Down
Expand Up @@ -257,7 +257,7 @@ public void testValidationErrorUponNonUniqueDependencyManagementKeyInProfile()
public void testDuplicateDependenciesCauseLastDeclarationToBePickedInLenientMode()
throws Exception
{
PomTestWrapper pom = buildPom( "unique-dependency-key/deps", true, null );
PomTestWrapper pom = buildPom( "unique-dependency-key/deps", true, null, null );
assertEquals( 1, ( (List<?>) pom.getValue( "dependencies" ) ).size() );
assertEquals( "0.2", pom.getValue( "dependencies[1]/version" ) );
}
Expand Down Expand Up @@ -1517,7 +1517,7 @@ public void testJdkActivation()
Properties props = new Properties();
props.put( "java.version", "1.5.0_15" );

PomTestWrapper pom = buildPom( "jdk-activation", props );
PomTestWrapper pom = buildPom( "jdk-activation", props, null );
assertEquals( 3, pom.getMavenProject().getActiveProfiles().size() );
assertEquals( "PASSED", pom.getValue( "properties/jdkProperty3" ) );
assertEquals( "PASSED", pom.getValue( "properties/jdkProperty2" ) );
Expand Down Expand Up @@ -1624,7 +1624,7 @@ public void testInterpolationWithSystemProperty()
{
Properties sysProps = new Properties();
sysProps.setProperty( "system.property", "PASSED" );
PomTestWrapper pom = buildPom( "system-property-interpolation", sysProps );
PomTestWrapper pom = buildPom( "system-property-interpolation", sysProps, null );
assertEquals( "PASSED", pom.getValue( "name" ) );
}

Expand Down Expand Up @@ -1764,7 +1764,7 @@ public void testCliPropsDominateProjectPropsDuringInterpolation()
{
Properties props = new Properties();
props.setProperty( "testProperty", "PASSED" );
PomTestWrapper pom = buildPom( "interpolation-cli-wins", props );
PomTestWrapper pom = buildPom( "interpolation-cli-wins", null, props );

assertEquals( "PASSED", pom.getValue( "properties/interpolatedProperty" ) );
}
Expand Down Expand Up @@ -1918,17 +1918,17 @@ private void assertPathWithNormalizedFileSeparators( Object value )
private PomTestWrapper buildPom( String pomPath, String... profileIds )
throws Exception
{
return buildPom( pomPath, null, profileIds );
return buildPom( pomPath, null, null, profileIds );
}

private PomTestWrapper buildPom( String pomPath, Properties executionProperties, String... profileIds )
private PomTestWrapper buildPom( String pomPath, Properties systemProperties, Properties userProperties, String... profileIds )
throws Exception
{
return buildPom( pomPath, false, executionProperties, profileIds );
return buildPom( pomPath, false, systemProperties, userProperties, profileIds );
}

private PomTestWrapper buildPom( String pomPath, boolean lenientValidation, Properties executionProperties,
String... profileIds )
private PomTestWrapper buildPom( String pomPath, boolean lenientValidation, Properties systemProperties,
Properties userProperties, String... profileIds )
throws Exception
{
File pomFile = new File( testDirectory, pomPath );
Expand All @@ -1944,8 +1944,8 @@ private PomTestWrapper buildPom( String pomPath, boolean lenientValidation, Prop
localRepoUrl = "file://" + localRepoUrl;
config.setLocalRepository( repositorySystem.createArtifactRepository( "local", localRepoUrl, new DefaultRepositoryLayout(), null, null ) );
config.setActiveProfileIds( Arrays.asList( profileIds ) );
config.setSystemProperties( executionProperties );
config.setUserProperties( executionProperties );
config.setSystemProperties( systemProperties );
config.setUserProperties( userProperties );
config.setValidationLevel( lenientValidation ? ModelBuildingRequest.VALIDATION_LEVEL_MAVEN_2_0
: ModelBuildingRequest.VALIDATION_LEVEL_STRICT );

Expand Down
Expand Up @@ -216,8 +216,8 @@ private Model loadPom( RepositorySystemSession session, ArtifactDescriptorReques
modelRequest.setValidationLevel( ModelBuildingRequest.VALIDATION_LEVEL_MINIMAL );
modelRequest.setProcessPlugins( false );
modelRequest.setTwoPhaseBuilding( false );
modelRequest.setSystemProperties( toProperties( session.getUserProperties(),
session.getSystemProperties() ) );
modelRequest.setSystemProperties( toProperties( session.getSystemProperties() ) );
modelRequest.setUserProperties( toProperties( session.getUserProperties() ) );
modelRequest.setModelCache( DefaultModelCache.newInstance( session ) );
modelRequest.setModelResolver( new DefaultModelResolver( session, trace.newChild( modelRequest ),
request.getRequestContext(), artifactResolver,
Expand Down Expand Up @@ -273,17 +273,10 @@ private Model loadPom( RepositorySystemSession session, ArtifactDescriptorReques
}
}

private Properties toProperties( Map<String, String> dominant, Map<String, String> recessive )
private Properties toProperties( Map<String, String> map )
{
Properties props = new Properties();
if ( recessive != null )
{
props.putAll( recessive );
}
if ( dominant != null )
{
props.putAll( dominant );
}
props.putAll( map );
return props;
}

Expand Down

0 comments on commit 69d6c6d

Please sign in to comment.