Fixed problems with merging profile-defined properties into the project, and fixed the ITs testing profile definitions in the process.

This should finally resolve MNG-421


git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@189768 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-06-09 15:53:31 +00:00
parent 2ab04f7c84
commit 8a257be6fc
20 changed files with 72 additions and 248 deletions

View File

@ -20,5 +20,5 @@ it0018
it0019 it0019
it0020 it0020
it0021 it0021
#it0022 it0022
#it0023 it0023

View File

@ -1 +1 @@
target/classes/org/apache/maven/it0022/test.txt target/test.txt

View File

@ -1 +1 @@
package core-it:touch

View File

@ -4,23 +4,21 @@
<artifactId>maven-it0022</artifactId> <artifactId>maven-it0022</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-core-it-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration> <configuration>
<test>${test}</test> <pluginItem>${test}</pluginItem>
</configuration> </configuration>
</plugin> </plugin>
<!-- plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-projecthelp-plugin</artifactId>
<version>2.0-alpha-3-SNAPSHOT</version>
</plugin -->
</plugins> </plugins>
</build> </build>
</model> </model>

View File

@ -10,7 +10,7 @@
</activation> </activation>
<properties> <properties>
<test>**/SomeAddTest*</test> <test>test.txt</test>
</properties> </properties>
</profile> </profile>
</profiles> </profiles>

View File

@ -1,45 +0,0 @@
package org.apache.maven.it0022;
import java.io.*;
import java.net.URL;
import junit.framework.TestCase;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class SomeAddTest
extends TestCase
{
public void testAdd() throws Exception
{
String className = Person.class.getName().replace( '.', '/' ) + ".class";
URL resource = Person.class.getClassLoader().getResource( className );
File personFile = new File( resource.getPath() ).getAbsoluteFile();
File dir = personFile.getParentFile();
File testFile = new File( dir, "test.txt" );
FileWriter writer = new FileWriter( testFile );
writer.write("this is a test");
writer.flush();
writer.close();
}
}

View File

@ -1,45 +0,0 @@
package org.apache.maven.it0022;
import java.io.File;
import java.net.URL;
import junit.framework.TestCase;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class SomeRemoveTest
extends TestCase
{
public void testRemove()
{
String className = Person.class.getName().replace( '.', '/' ) + ".class";
URL resource = Person.class.getClassLoader().getResource( className );
File personFile = new File( resource.getPath() ).getAbsoluteFile();
File dir = personFile.getParentFile();
File testFile = new File( dir, "test.txt" );
if( testFile.exists() )
{
testFile.delete();
}
}
}

View File

@ -1 +1 @@
target/classes/org/apache/maven/it0023/test.txt target/test.txt

View File

@ -1 +1 @@
package core-it:touch

View File

@ -4,23 +4,21 @@
<artifactId>maven-it0023</artifactId> <artifactId>maven-it0023</artifactId>
<version>1.0-SNAPSHOT</version> <version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
</dependency>
</dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.maven.plugins</groupId> <groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId> <artifactId>maven-core-it-plugin</artifactId>
<version>1.0-SNAPSHOT</version>
<configuration> <configuration>
<test>${test}</test> <pluginItem>${test}</pluginItem>
</configuration> </configuration>
</plugin> </plugin>
<!-- plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-projecthelp-plugin</artifactId>
<version>2.0-alpha-3-SNAPSHOT</version>
</plugin -->
</plugins> </plugins>
</build> </build>
</model> </model>

View File

@ -14,7 +14,7 @@
</activation> </activation>
<properties> <properties>
<test>**/SomeAddTest*</test> <test>test.txt</test>
</properties> </properties>
</profile> </profile>
</profiles> </profiles>

View File

@ -1,45 +0,0 @@
package org.apache.maven.it0023;
import java.io.*;
import java.net.URL;
import junit.framework.TestCase;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class SomeAddTest
extends TestCase
{
public void testAdd() throws Exception
{
String className = Person.class.getName().replace( '.', '/' ) + ".class";
URL resource = Person.class.getClassLoader().getResource( className );
File personFile = new File( resource.getPath() ).getAbsoluteFile();
File dir = personFile.getParentFile();
File testFile = new File( dir, "test.txt" );
FileWriter writer = new FileWriter( testFile );
writer.write("this is a test");
writer.flush();
writer.close();
}
}

View File

@ -1,45 +0,0 @@
package org.apache.maven.it0023;
import java.io.File;
import java.net.URL;
import junit.framework.TestCase;
/*
* Copyright 2001-2005 The Apache Software Foundation.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
public class SomeRemoveTest
extends TestCase
{
public void testRemove()
{
String className = Person.class.getName().replace( '.', '/' ) + ".class";
URL resource = Person.class.getClassLoader().getResource( className );
File personFile = new File( resource.getPath() ).getAbsoluteFile();
File dir = personFile.getParentFile();
File testFile = new File( dir, "test.txt" );
if( testFile.exists() )
{
testFile.delete();
}
}
}

View File

@ -36,6 +36,8 @@ public final class ModelNormalizationUtils
{ {
Profile profile = new Profile(); Profile profile = new Profile();
profile.setId( settingsProfile.getId() );
profile.setSource( "settings.xml" ); profile.setSource( "settings.xml" );
org.apache.maven.settings.Activation settingsActivation = settingsProfile.getActivation(); org.apache.maven.settings.Activation settingsActivation = settingsProfile.getActivation();
@ -59,7 +61,7 @@ public final class ModelNormalizationUtils
} }
} }
profile.addEvalProperties( settingsProfile.getProperties() ); profile.setProperties( settingsProfile.getProperties() );
List repos = settingsProfile.getRepositories(); List repos = settingsProfile.getRepositories();
if ( repos != null ) if ( repos != null )
@ -88,6 +90,8 @@ public final class ModelNormalizationUtils
{ {
Profile profile = new Profile(); Profile profile = new Profile();
profile.setId( profileXmlProfile.getId() );
profile.setSource( "profiles.xml" ); profile.setSource( "profiles.xml" );
org.apache.maven.profiles.Activation profileActivation = profileXmlProfile.getActivation(); org.apache.maven.profiles.Activation profileActivation = profileXmlProfile.getActivation();
@ -117,7 +121,7 @@ public final class ModelNormalizationUtils
profile.setActivation( new AlwaysOnActivation() ); profile.setActivation( new AlwaysOnActivation() );
} }
profile.addEvalProperties( profileXmlProfile.getProperties() ); profile.setProperties( profileXmlProfile.getProperties() );
List repos = profileXmlProfile.getRepositories(); List repos = profileXmlProfile.getRepositories();
if ( repos != null ) if ( repos != null )

View File

@ -135,9 +135,9 @@ public class PluginParameterExpressionEvaluator
// Check properties that have been injected via profiles before we default over to // Check properties that have been injected via profiles before we default over to
// system properties. // system properties.
if( context.getProject().getProfileConfiguration() != null ) if( context.getProject().getProfileProperties() != null )
{ {
value = context.getProject().getProfileConfiguration().getProperty( expression ); value = context.getProject().getProfileProperties().getProperty( expression );
} }
if( value == null ) if( value == null )

View File

@ -664,24 +664,6 @@
</association> </association>
</field> </field>
</fields> </fields>
<codeSegments>
<codeSegment>
<version>4.0.0</version>
<code><![CDATA[
private Properties evalProperties = new Properties();
public void addEvalProperties( Properties properties )
{
this.evalProperties.putAll( properties );
}
public Properties getEvalProperties()
{
return evalProperties;
}
]]></code>
</codeSegment>
</codeSegments>
</class> </class>
<!-- @todo: is any of this too CVS specific? Investigate other SCMs --> <!-- @todo: is any of this too CVS specific? Investigate other SCMs -->
<class> <class>
@ -2328,6 +2310,7 @@
// We don't want this to be parseable...it's sort of 'hidden' // We don't want this to be parseable...it's sort of 'hidden'
// default source for this profile is in the pom itself. // default source for this profile is in the pom itself.
private String source = "pom"; private String source = "pom";
private Properties properties = new Properties();
public void setSource( String source ) public void setSource( String source )
{ {
@ -2338,6 +2321,21 @@
{ {
return source; return source;
} }
public String toString()
{
return "Profile {id: " + getId() + ", source: " + getSource() + "}";
}
public void setProperties( Properties properties )
{
this.properties = properties;
}
public Properties getProperties()
{
return properties;
}
]]></code> ]]></code>
</codeSegment> </codeSegment>
</codeSegments> </codeSegments>

View File

@ -20,7 +20,8 @@
<plugin> <plugin>
<groupId>org.codehaus.modello</groupId> <groupId>org.codehaus.modello</groupId>
<artifactId>modello-maven-plugin</artifactId> <artifactId>modello-maven-plugin</artifactId>
<version>1.0-alpha-3-SNAPSHOT</version> <version>1.0-alpha-2</version>
<!-- version>1.0-alpha-3-SNAPSHOT</version -->
<configuration> <configuration>
<version>4.0.0</version> <version>4.0.0</version>
<model>maven.mdo</model> <model>maven.mdo</model>

View File

@ -67,6 +67,7 @@ import java.util.Iterator;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Properties;
import java.util.Set; import java.util.Set;
/** /**
@ -283,20 +284,25 @@ public class DefaultMavenProjectBuilder
modelCache.put( key, model ); modelCache.put( key, model );
} }
// TODO: Add profiles support here?
List activeProfiles = new ArrayList( externalProfiles ); List activeProfiles = new ArrayList( externalProfiles );
List activePomProfiles = profileActivationCalculator.calculateActiveProfiles( model.getProfiles() ); List activePomProfiles = profileActivationCalculator.calculateActiveProfiles( model.getProfiles() );
activeProfiles.addAll( activePomProfiles ); activeProfiles.addAll( activePomProfiles );
Properties profileProperties = new Properties();
for ( Iterator it = activeProfiles.iterator(); it.hasNext(); ) for ( Iterator it = activeProfiles.iterator(); it.hasNext(); )
{ {
Profile profile = (Profile) it.next(); Profile profile = (Profile) it.next();
modelInheritanceAssembler.mergeProfileWithModel( model, profile ); modelInheritanceAssembler.mergeProfileWithModel( model, profile );
profileProperties.putAll( profile.getProperties() );
} }
// TODO: Clean this up...we're using this to 'jump' the interpolation step for model properties not expressed in XML.
model = modelInterpolator.interpolate( model ); model = modelInterpolator.interpolate( model );
// interpolation is before injection, because interpolation is off-limits in the injected variables // interpolation is before injection, because interpolation is off-limits in the injected variables
@ -306,7 +312,9 @@ public class DefaultMavenProjectBuilder
project = new MavenProject( model ); project = new MavenProject( model );
project.addActiveProfiles( activePomProfiles ); project.addProfileProperties( profileProperties );
project.setActiveProfiles( activeProfiles );
project.setPluginArtifactRepositories( ProjectUtils.buildArtifactRepositories( model.getPluginRepositories(), artifactRepositoryFactory, container ) ); project.setPluginArtifactRepositories( ProjectUtils.buildArtifactRepositories( model.getPluginRepositories(), artifactRepositoryFactory, container ) );

View File

@ -80,7 +80,7 @@ public class MavenProject
private List remoteArtifactRepositories; private List remoteArtifactRepositories;
private Properties profileConfiguration; private Properties profileProperties = new Properties();
private List collectedProjects = Collections.EMPTY_LIST; private List collectedProjects = Collections.EMPTY_LIST;
@ -891,17 +891,17 @@ public class MavenProject
return model.getPluginRepositories(); return model.getPluginRepositories();
} }
public Properties getProfileConfiguration() public Properties getProfileProperties()
{ {
return profileConfiguration; return profileProperties;
} }
public void addProfileConfiguration( Properties profileConfiguration ) public void addProfileProperties( Properties profileConfiguration )
{ {
this.profileConfiguration = profileConfiguration; this.profileProperties.putAll( profileConfiguration );
} }
public void addActiveProfiles( List activeProfiles ) public void setActiveProfiles( List activeProfiles )
{ {
this.activeProfiles.addAll( activeProfiles ); this.activeProfiles.addAll( activeProfiles );
} }

View File

@ -221,9 +221,6 @@ public class DefaultModelInheritanceAssembler
} }
assembleDependencyManagementInheritance( child, parent ); assembleDependencyManagementInheritance( child, parent );
// Evaluation Properties :: aggregate
child.addEvalProperties( parent.getEvalProperties() );
} }
private void assembleDependencyManagementInheritance( ModelBase child, ModelBase parent ) private void assembleDependencyManagementInheritance( ModelBase child, ModelBase parent )