Adding POM-level properties.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@279572 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-09-08 15:08:57 +00:00
parent 4ac603b57b
commit 6d4537dc97
8 changed files with 145 additions and 79 deletions

View File

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

View File

@ -682,6 +682,18 @@
<type>DistributionManagement</type>
</association>
</field>
<field>
<name>properties</name>
<version>4.0.0</version>
<description><![CDATA[
Properties used to fill in plugin configuration
]]></description>
<type>Properties</type>
<association xml.mapStyle="inline">
<type>String</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
</class>
<!-- @todo: is any of this too CVS specific? Investigate other SCMs -->
@ -2563,18 +2575,6 @@
<type>BuildBase</type>
</association>
</field>
<field>
<name>properties</name>
<version>4.0.0</version>
<description><![CDATA[
Properties used to fill in plugin configuration when this profile is active
]]></description>
<type>Properties</type>
<association xml.mapStyle="inline">
<type>String</type>
<multiplicity>*</multiplicity>
</association>
</field>
</fields>
<codeSegments>
<codeSegment>

View File

@ -85,7 +85,6 @@ import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
/**
@ -433,16 +432,12 @@ public class DefaultMavenProjectBuilder
List activeProfiles;
Properties profileProperties = new Properties();
superProjectProfileManager.addProfiles( superModel.getProfiles() );
activeProfiles = injectActiveProfiles( superProjectProfileManager, superModel, profileProperties );
activeProfiles = injectActiveProfiles( superProjectProfileManager, superModel );
MavenProject superProject = new MavenProject( superModel );
superProject.addProfileProperties( profileProperties );
superProject.setActiveProfiles( activeProfiles );
//noinspection CollectionDeclaredAsConcreteClass
@ -558,13 +553,6 @@ public class DefaultMavenProjectBuilder
modelCache.put( key, model );
}
Properties profileProperties = project.getProfileProperties();
if ( profileProperties == null )
{
profileProperties = new Properties();
}
List activeProfiles = project.getActiveProfiles();
if ( activeProfiles == null )
@ -572,7 +560,7 @@ public class DefaultMavenProjectBuilder
activeProfiles = new ArrayList();
}
List injectedProfiles = injectActiveProfiles( profileMgr, model, profileProperties );
List injectedProfiles = injectActiveProfiles( profileMgr, model );
activeProfiles.addAll( injectedProfiles );
@ -610,10 +598,6 @@ public class DefaultMavenProjectBuilder
project.setActiveProfiles( activeProfiles );
project.addProfileProperties( profileProperties );
project.assembleProfilePropertiesInheritance();
// TODO: maybe not strictly correct, while we should enfore that packaging has a type handler of the same id, we don't
Artifact projectArtifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(),
project.getVersion(), project.getPackaging() );
@ -692,15 +676,13 @@ public class DefaultMavenProjectBuilder
List activeProfiles;
Properties profileProperties = new Properties();
try
{
profileManager.addProfiles( model.getProfiles() );
loadProjectExternalProfiles( profileManager, projectDir );
activeProfiles = injectActiveProfiles( profileManager, model, profileProperties );
activeProfiles = injectActiveProfiles( profileManager, model );
}
catch ( ProfileActivationException e )
{
@ -709,8 +691,6 @@ public class DefaultMavenProjectBuilder
MavenProject project = new MavenProject( model );
project.addProfileProperties( profileProperties );
project.setActiveProfiles( activeProfiles );
lineage.addFirst( project );
@ -819,7 +799,7 @@ public class DefaultMavenProjectBuilder
return project;
}
private List injectActiveProfiles( ProfileManager profileManager, Model model, Properties profileProperties )
private List injectActiveProfiles( ProfileManager profileManager, Model model )
throws ProjectBuildingException
{
List activeProfiles;
@ -840,8 +820,6 @@ public class DefaultMavenProjectBuilder
Profile profile = (Profile) it.next();
profileInjector.inject( profile, model );
profileProperties.putAll( profile.getProperties() );
}
}
else
@ -1106,16 +1084,12 @@ public class DefaultMavenProjectBuilder
List activeProfiles;
Properties profileProperties = new Properties();
profileManager.addProfiles( superModel.getProfiles() );
activeProfiles = injectActiveProfiles( profileManager, superModel, profileProperties );
activeProfiles = injectActiveProfiles( profileManager, superModel );
MavenProject project = new MavenProject( superModel );
project.addProfileProperties( profileProperties );
project.setActiveProfiles( activeProfiles );
project.setOriginalModel( superModel );

View File

@ -61,7 +61,6 @@ import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import java.util.Stack;
/**
* The concern of the project is provide runtime values based on the model. <p/>
@ -92,8 +91,6 @@ public class MavenProject
private List remoteArtifactRepositories;
private Properties profileProperties = new Properties();
private List collectedProjects = Collections.EMPTY_LIST;
private List attachedArtifacts;
@ -174,8 +171,6 @@ public class MavenProject
this.testCompileSourceRoots = new ArrayList( project.testCompileSourceRoots );
this.scriptSourceRoots = new ArrayList( project.scriptSourceRoots );
this.profileProperties = new Properties( project.profileProperties );
this.model = ModelUtils.cloneModel( project.model );
if ( project.originalModel != null )
@ -603,6 +598,97 @@ public class MavenProject
return list;
}
public List getSystemClasspathElements()
throws DependencyResolutionRequiredException
{
List list = new ArrayList( getArtifacts().size() );
list.add( getBuild().getOutputDirectory() );
for ( Iterator i = getArtifacts().iterator(); i.hasNext(); )
{
Artifact a = (Artifact) i.next();
if ( isAddedToClasspath( a ) )
{
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
{
String refId = getProjectReferenceId( a.getGroupId(), a.getArtifactId() );
MavenProject project = (MavenProject) projectReferences.get( refId );
if ( project != null )
{
list.add( project.getBuild().getOutputDirectory() );
}
else
{
File file = a.getFile();
if ( file == null )
{
throw new DependencyResolutionRequiredException( a );
}
list.add( file.getPath() );
}
}
}
}
return list;
}
public List getSystemArtifacts()
{
List list = new ArrayList( getArtifacts().size() );
for ( Iterator i = getArtifacts().iterator(); i.hasNext(); )
{
Artifact a = (Artifact) i.next();
// TODO: classpath check doesn't belong here - that's the other method
if ( isAddedToClasspath( a ) )
{
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
{
list.add( a );
}
}
}
return list;
}
public List getSystemDependencies()
{
Set artifacts = getArtifacts();
if ( artifacts == null || artifacts.isEmpty() )
{
return Collections.EMPTY_LIST;
}
List list = new ArrayList( artifacts.size() );
for ( Iterator i = getArtifacts().iterator(); i.hasNext(); )
{
Artifact a = (Artifact) i.next();
// TODO: let the scope handler deal with this
if ( Artifact.SCOPE_SYSTEM.equals( a.getScope() ) )
{
Dependency dependency = new Dependency();
dependency.setArtifactId( a.getArtifactId() );
dependency.setGroupId( a.getGroupId() );
dependency.setVersion( a.getVersion() );
dependency.setScope( a.getScope() );
dependency.setType( a.getType() );
dependency.setClassifier( a.getClassifier() );
list.add( dependency );
}
}
return list;
}
private static boolean isAddedToClasspath( Artifact artifact )
{
String type = artifact.getType();
@ -1071,14 +1157,20 @@ public class MavenProject
return model.getPluginRepositories();
}
/**
* @deprecated use getProperties() instead
*/
public Properties getProfileProperties()
{
return profileProperties;
return getProperties();
}
/**
* @deprecated should add properties to the model instead
*/
public void addProfileProperties( Properties profileConfiguration )
{
this.profileProperties.putAll( profileConfiguration );
getProperties().putAll( profileConfiguration );
}
public void setActiveProfiles( List activeProfiles )
@ -1328,35 +1420,13 @@ public class MavenProject
return groupId + ":" + artifactId;
}
public void assembleProfilePropertiesInheritance()
{
Stack propertyStack = new Stack();
MavenProject current = this;
while ( current != null )
{
Properties toAdd = current.profileProperties;
if ( toAdd != null && !toAdd.isEmpty() )
{
propertyStack.push( toAdd );
}
current = current.getParent();
}
Properties newProfilesProperties = new Properties();
while ( !propertyStack.isEmpty() )
{
newProfilesProperties.putAll( (Properties) propertyStack.pop() );
}
this.profileProperties = newProfilesProperties;
}
public void attachArtifact( String type, String classifier, File file )
{
}
public Properties getProperties()
{
return getModel().getProperties();
}
}

View File

@ -34,6 +34,7 @@ import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
public final class ModelUtils
@ -465,10 +466,12 @@ public final class ModelUtils
newModel.setParent( cloneParent( model.getParent() ) );
newModel.setVersion( model.getVersion() );
newModel.setArtifactId( model.getArtifactId() );
newModel.setProperties( new Properties( model.getProperties() ) );
newModel.setGroupId( model.getGroupId() );
newModel.setPackaging( model.getPackaging() );
newModel.setModules( cloneModules( model.getModules() ) );
assembler.copyModel( newModel, model );
return newModel;
}

View File

@ -35,6 +35,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
/**
@ -172,6 +173,12 @@ public class DefaultModelInheritanceAssembler
assembleDependencyManagementInheritance( child, parent );
assembleDistributionManagementInheritance( child, parent );
Properties props = new Properties();
props.putAll( parent.getProperties() );
props.putAll( child.getProperties() );
child.setProperties( props );
}
private void assembleDistributionManagementInheritance( Model child, Model parent )

View File

@ -24,6 +24,7 @@ import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.TreeMap;
/**
@ -61,6 +62,12 @@ public class DefaultProfileInjector
injectDistributionManagement( profile, model );
injectBuild( profile, model );
Properties props = new Properties();
props.putAll( model.getProperties() );
props.putAll( profile.getProperties() );
model.setProperties( props );
}
private void injectBuild( Profile profile, Model model )

View File

@ -104,6 +104,11 @@ public class RegexBasedModelInterpolator
{
value = ReflectionValueExtractor.evaluate( realExpr, model );
}
if ( value == null )
{
value = model.getProperties().getProperty( realExpr );
}
}
catch ( Exception e )
{