mirror of https://github.com/apache/maven.git
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:
parent
4ac603b57b
commit
6d4537dc97
|
@ -238,9 +238,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 ( project.getProfileProperties() != null )
|
if ( project.getProperties() != null )
|
||||||
{
|
{
|
||||||
value = project.getProfileProperties().getProperty( expression );
|
value = project.getProperties().getProperty( expression );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( value == null )
|
if ( value == null )
|
||||||
|
|
|
@ -682,6 +682,18 @@
|
||||||
<type>DistributionManagement</type>
|
<type>DistributionManagement</type>
|
||||||
</association>
|
</association>
|
||||||
</field>
|
</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>
|
</fields>
|
||||||
</class>
|
</class>
|
||||||
<!-- @todo: is any of this too CVS specific? Investigate other SCMs -->
|
<!-- @todo: is any of this too CVS specific? Investigate other SCMs -->
|
||||||
|
@ -2563,18 +2575,6 @@
|
||||||
<type>BuildBase</type>
|
<type>BuildBase</type>
|
||||||
</association>
|
</association>
|
||||||
</field>
|
</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>
|
</fields>
|
||||||
<codeSegments>
|
<codeSegments>
|
||||||
<codeSegment>
|
<codeSegment>
|
||||||
|
|
|
@ -85,7 +85,6 @@ 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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -433,16 +432,12 @@ public class DefaultMavenProjectBuilder
|
||||||
|
|
||||||
List activeProfiles;
|
List activeProfiles;
|
||||||
|
|
||||||
Properties profileProperties = new Properties();
|
|
||||||
|
|
||||||
superProjectProfileManager.addProfiles( superModel.getProfiles() );
|
superProjectProfileManager.addProfiles( superModel.getProfiles() );
|
||||||
|
|
||||||
activeProfiles = injectActiveProfiles( superProjectProfileManager, superModel, profileProperties );
|
activeProfiles = injectActiveProfiles( superProjectProfileManager, superModel );
|
||||||
|
|
||||||
MavenProject superProject = new MavenProject( superModel );
|
MavenProject superProject = new MavenProject( superModel );
|
||||||
|
|
||||||
superProject.addProfileProperties( profileProperties );
|
|
||||||
|
|
||||||
superProject.setActiveProfiles( activeProfiles );
|
superProject.setActiveProfiles( activeProfiles );
|
||||||
|
|
||||||
//noinspection CollectionDeclaredAsConcreteClass
|
//noinspection CollectionDeclaredAsConcreteClass
|
||||||
|
@ -558,13 +553,6 @@ public class DefaultMavenProjectBuilder
|
||||||
modelCache.put( key, model );
|
modelCache.put( key, model );
|
||||||
}
|
}
|
||||||
|
|
||||||
Properties profileProperties = project.getProfileProperties();
|
|
||||||
|
|
||||||
if ( profileProperties == null )
|
|
||||||
{
|
|
||||||
profileProperties = new Properties();
|
|
||||||
}
|
|
||||||
|
|
||||||
List activeProfiles = project.getActiveProfiles();
|
List activeProfiles = project.getActiveProfiles();
|
||||||
|
|
||||||
if ( activeProfiles == null )
|
if ( activeProfiles == null )
|
||||||
|
@ -572,7 +560,7 @@ public class DefaultMavenProjectBuilder
|
||||||
activeProfiles = new ArrayList();
|
activeProfiles = new ArrayList();
|
||||||
}
|
}
|
||||||
|
|
||||||
List injectedProfiles = injectActiveProfiles( profileMgr, model, profileProperties );
|
List injectedProfiles = injectActiveProfiles( profileMgr, model );
|
||||||
|
|
||||||
activeProfiles.addAll( injectedProfiles );
|
activeProfiles.addAll( injectedProfiles );
|
||||||
|
|
||||||
|
@ -610,10 +598,6 @@ public class DefaultMavenProjectBuilder
|
||||||
|
|
||||||
project.setActiveProfiles( activeProfiles );
|
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
|
// 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(),
|
Artifact projectArtifact = artifactFactory.createBuildArtifact( project.getGroupId(), project.getArtifactId(),
|
||||||
project.getVersion(), project.getPackaging() );
|
project.getVersion(), project.getPackaging() );
|
||||||
|
@ -692,15 +676,13 @@ public class DefaultMavenProjectBuilder
|
||||||
|
|
||||||
List activeProfiles;
|
List activeProfiles;
|
||||||
|
|
||||||
Properties profileProperties = new Properties();
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
profileManager.addProfiles( model.getProfiles() );
|
profileManager.addProfiles( model.getProfiles() );
|
||||||
|
|
||||||
loadProjectExternalProfiles( profileManager, projectDir );
|
loadProjectExternalProfiles( profileManager, projectDir );
|
||||||
|
|
||||||
activeProfiles = injectActiveProfiles( profileManager, model, profileProperties );
|
activeProfiles = injectActiveProfiles( profileManager, model );
|
||||||
}
|
}
|
||||||
catch ( ProfileActivationException e )
|
catch ( ProfileActivationException e )
|
||||||
{
|
{
|
||||||
|
@ -709,8 +691,6 @@ public class DefaultMavenProjectBuilder
|
||||||
|
|
||||||
MavenProject project = new MavenProject( model );
|
MavenProject project = new MavenProject( model );
|
||||||
|
|
||||||
project.addProfileProperties( profileProperties );
|
|
||||||
|
|
||||||
project.setActiveProfiles( activeProfiles );
|
project.setActiveProfiles( activeProfiles );
|
||||||
|
|
||||||
lineage.addFirst( project );
|
lineage.addFirst( project );
|
||||||
|
@ -819,7 +799,7 @@ public class DefaultMavenProjectBuilder
|
||||||
return project;
|
return project;
|
||||||
}
|
}
|
||||||
|
|
||||||
private List injectActiveProfiles( ProfileManager profileManager, Model model, Properties profileProperties )
|
private List injectActiveProfiles( ProfileManager profileManager, Model model )
|
||||||
throws ProjectBuildingException
|
throws ProjectBuildingException
|
||||||
{
|
{
|
||||||
List activeProfiles;
|
List activeProfiles;
|
||||||
|
@ -840,8 +820,6 @@ public class DefaultMavenProjectBuilder
|
||||||
Profile profile = (Profile) it.next();
|
Profile profile = (Profile) it.next();
|
||||||
|
|
||||||
profileInjector.inject( profile, model );
|
profileInjector.inject( profile, model );
|
||||||
|
|
||||||
profileProperties.putAll( profile.getProperties() );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -1106,16 +1084,12 @@ public class DefaultMavenProjectBuilder
|
||||||
|
|
||||||
List activeProfiles;
|
List activeProfiles;
|
||||||
|
|
||||||
Properties profileProperties = new Properties();
|
|
||||||
|
|
||||||
profileManager.addProfiles( superModel.getProfiles() );
|
profileManager.addProfiles( superModel.getProfiles() );
|
||||||
|
|
||||||
activeProfiles = injectActiveProfiles( profileManager, superModel, profileProperties );
|
activeProfiles = injectActiveProfiles( profileManager, superModel );
|
||||||
|
|
||||||
MavenProject project = new MavenProject( superModel );
|
MavenProject project = new MavenProject( superModel );
|
||||||
|
|
||||||
project.addProfileProperties( profileProperties );
|
|
||||||
|
|
||||||
project.setActiveProfiles( activeProfiles );
|
project.setActiveProfiles( activeProfiles );
|
||||||
|
|
||||||
project.setOriginalModel( superModel );
|
project.setOriginalModel( superModel );
|
||||||
|
|
|
@ -61,7 +61,6 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
import java.util.Stack;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The concern of the project is provide runtime values based on the model. <p/>
|
* 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 List remoteArtifactRepositories;
|
||||||
|
|
||||||
private Properties profileProperties = new Properties();
|
|
||||||
|
|
||||||
private List collectedProjects = Collections.EMPTY_LIST;
|
private List collectedProjects = Collections.EMPTY_LIST;
|
||||||
|
|
||||||
private List attachedArtifacts;
|
private List attachedArtifacts;
|
||||||
|
@ -174,8 +171,6 @@ public class MavenProject
|
||||||
this.testCompileSourceRoots = new ArrayList( project.testCompileSourceRoots );
|
this.testCompileSourceRoots = new ArrayList( project.testCompileSourceRoots );
|
||||||
this.scriptSourceRoots = new ArrayList( project.scriptSourceRoots );
|
this.scriptSourceRoots = new ArrayList( project.scriptSourceRoots );
|
||||||
|
|
||||||
this.profileProperties = new Properties( project.profileProperties );
|
|
||||||
|
|
||||||
this.model = ModelUtils.cloneModel( project.model );
|
this.model = ModelUtils.cloneModel( project.model );
|
||||||
|
|
||||||
if ( project.originalModel != null )
|
if ( project.originalModel != null )
|
||||||
|
@ -603,6 +598,97 @@ public class MavenProject
|
||||||
return list;
|
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 )
|
private static boolean isAddedToClasspath( Artifact artifact )
|
||||||
{
|
{
|
||||||
String type = artifact.getType();
|
String type = artifact.getType();
|
||||||
|
@ -1071,14 +1157,20 @@ public class MavenProject
|
||||||
return model.getPluginRepositories();
|
return model.getPluginRepositories();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated use getProperties() instead
|
||||||
|
*/
|
||||||
public Properties getProfileProperties()
|
public Properties getProfileProperties()
|
||||||
{
|
{
|
||||||
return profileProperties;
|
return getProperties();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @deprecated should add properties to the model instead
|
||||||
|
*/
|
||||||
public void addProfileProperties( Properties profileConfiguration )
|
public void addProfileProperties( Properties profileConfiguration )
|
||||||
{
|
{
|
||||||
this.profileProperties.putAll( profileConfiguration );
|
getProperties().putAll( profileConfiguration );
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setActiveProfiles( List activeProfiles )
|
public void setActiveProfiles( List activeProfiles )
|
||||||
|
@ -1328,35 +1420,13 @@ public class MavenProject
|
||||||
return groupId + ":" + artifactId;
|
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 void attachArtifact( String type, String classifier, File file )
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Properties getProperties()
|
||||||
|
{
|
||||||
|
return getModel().getProperties();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -34,6 +34,7 @@ import java.util.ArrayList;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
public final class ModelUtils
|
public final class ModelUtils
|
||||||
|
@ -465,10 +466,12 @@ public final class ModelUtils
|
||||||
newModel.setParent( cloneParent( model.getParent() ) );
|
newModel.setParent( cloneParent( model.getParent() ) );
|
||||||
newModel.setVersion( model.getVersion() );
|
newModel.setVersion( model.getVersion() );
|
||||||
newModel.setArtifactId( model.getArtifactId() );
|
newModel.setArtifactId( model.getArtifactId() );
|
||||||
|
newModel.setProperties( new Properties( model.getProperties() ) );
|
||||||
newModel.setGroupId( model.getGroupId() );
|
newModel.setGroupId( model.getGroupId() );
|
||||||
newModel.setPackaging( model.getPackaging() );
|
newModel.setPackaging( model.getPackaging() );
|
||||||
newModel.setModules( cloneModules( model.getModules() ) );
|
newModel.setModules( cloneModules( model.getModules() ) );
|
||||||
assembler.copyModel( newModel, model );
|
assembler.copyModel( newModel, model );
|
||||||
|
|
||||||
return newModel;
|
return newModel;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -35,6 +35,7 @@ import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -172,6 +173,12 @@ public class DefaultModelInheritanceAssembler
|
||||||
assembleDependencyManagementInheritance( child, parent );
|
assembleDependencyManagementInheritance( child, parent );
|
||||||
|
|
||||||
assembleDistributionManagementInheritance( 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 )
|
private void assembleDistributionManagementInheritance( Model child, Model parent )
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
import java.util.Properties;
|
||||||
import java.util.TreeMap;
|
import java.util.TreeMap;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -61,6 +62,12 @@ public class DefaultProfileInjector
|
||||||
injectDistributionManagement( profile, model );
|
injectDistributionManagement( profile, model );
|
||||||
|
|
||||||
injectBuild( 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 )
|
private void injectBuild( Profile profile, Model model )
|
||||||
|
|
|
@ -104,6 +104,11 @@ public class RegexBasedModelInterpolator
|
||||||
{
|
{
|
||||||
value = ReflectionValueExtractor.evaluate( realExpr, model );
|
value = ReflectionValueExtractor.evaluate( realExpr, model );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ( value == null )
|
||||||
|
{
|
||||||
|
value = model.getProperties().getProperty( realExpr );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch ( Exception e )
|
catch ( Exception e )
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue