You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by si...@apache.org on 2008/09/09 03:04:21 UTC
svn commit: r693332 [5/6] - in /maven/components/trunk: ./
maven-core-it-runner/ maven-core/src/main/java/org/apache/maven/
maven-core/src/main/java/org/apache/maven/errors/
maven-core/src/main/java/org/apache/maven/execution/
maven-core/src/main/java/...
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java?rev=693332&r1=693331&r2=693332&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/artifact/ProjectArtifactMetadata.java Mon Sep 8 18:04:17 2008
@@ -45,8 +45,7 @@
this( artifact, null );
}
- public ProjectArtifactMetadata( Artifact artifact,
- File file )
+ public ProjectArtifactMetadata( Artifact artifact, File file )
{
super( artifact );
this.file = file;
@@ -67,8 +66,7 @@
return getArtifactId() + "-" + artifact.getVersion() + ".pom";
}
- public void storeInLocalRepository( ArtifactRepository localRepository,
- ArtifactRepository remoteRepository )
+ public void storeInLocalRepository( ArtifactRepository localRepository, ArtifactRepository remoteRepository )
throws RepositoryMetadataStoreException
{
File destination = new File( localRepository.getBasedir(),
@@ -90,7 +88,7 @@
throw new RepositoryMetadataStoreException( "Error copying POM to the local repository.", e );
}
}
-
+
public String toString()
{
return "project information for " + artifact.getArtifactId() + " " + artifact.getVersion();
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java?rev=693332&r1=693331&r2=693332&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java Mon Sep 8 18:04:17 2008
@@ -72,26 +72,40 @@
private List<ModelProperty> properties;
+ private static String findBaseUriFrom( List<ModelProperty> modelProperties )
+ {
+ String baseUri = null;
+ for ( ModelProperty mp : modelProperties )
+ {
+ if ( baseUri == null || mp.getUri().length() < baseUri.length() )
+ {
+ baseUri = mp.getUri();
+ }
+ }
+ return baseUri;
+ }
+
private ArtifactModelContainer( List<ModelProperty> properties )
{
this.properties = new ArrayList<ModelProperty>( properties );
this.properties = Collections.unmodifiableList( this.properties );
+ String uri = findBaseUriFrom( this.properties );
- for ( ModelProperty mp : properties )
+ for ( ModelProperty mp : this.properties )
{
- if ( mp.getUri().endsWith( "version" ) )
+ if ( version == null && mp.getUri().equals( uri + "/version" ) )
{
this.version = mp.getValue();
}
- else if ( mp.getUri().endsWith( "artifactId" ) )
+ else if ( artifactId == null && mp.getUri().equals( uri + "/artifactId" ) )
{
this.artifactId = mp.getValue();
}
- else if ( mp.getUri().endsWith( "groupId" ) )
+ else if ( groupId == null && mp.getUri().equals( uri + "/groupId" ) )
{
this.groupId = mp.getValue();
}
- else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.type ) )
+ else if ( mp.getUri().equals( ProjectUri.Dependencies.Dependency.type ) && type == null )
{
this.type = mp.getValue();
}
@@ -105,8 +119,13 @@
if ( artifactId == null )
{
- throw new IllegalArgumentException(
- "Properties does not contain artifact id. Group ID = " + groupId + ", Version = " + version );
+ StringBuffer sb = new StringBuffer();
+ for ( ModelProperty mp : properties )
+ {
+ sb.append( mp ).append( "\r\n" );
+ }
+ throw new IllegalArgumentException( "Properties does not contain artifact id. Group ID = " + groupId +
+ ", Version = " + version + ":" + sb );
}
if ( type == null )
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java?rev=693332&r1=693331&r2=693332&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java Mon Sep 8 18:04:17 2008
@@ -31,6 +31,8 @@
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
+import java.io.File;
+import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
@@ -59,6 +61,10 @@
private String id;
+ private File file;
+
+ private File parentFile;
+
/**
* Constructor
*
@@ -73,10 +79,20 @@
throw new IllegalArgumentException( "model: null" );
}
ByteArrayOutputStream baos = new ByteArrayOutputStream();
- Writer out = WriterFactory.newXmlWriter( baos );
+ Writer out = null;
MavenXpp3Writer writer = new MavenXpp3Writer();
- writer.write( out, model );
- out.close();
+ try
+ {
+ out = WriterFactory.newXmlWriter( baos );
+ writer.write( out, model );
+ }
+ finally
+ {
+ if ( out != null )
+ {
+ out.close();
+ }
+ }
inputBytes = baos.toByteArray();
}
@@ -96,6 +112,22 @@
this.inputBytes = IOUtil.toByteArray( inputStream );
}
+ public PomClassicDomainModel( File file )
+ throws IOException
+ {
+ this( new FileInputStream( file ) );
+ this.file = file;
+ }
+
+ public File getParentFile()
+ {
+ return parentFile;
+ }
+
+ public void setParentFile( File parentFile )
+ {
+ this.parentFile = parentFile;
+ }
/**
* Returns true if groupId.equals(a.groupId) && artifactId.equals(a.artifactId) && version.equals(a.version),
@@ -140,10 +172,15 @@
return "";
}
}
- String groupId = ( model.getGroupId() == null ) ? model.getParent().getGroupId() : model.getGroupId();
- String artifactId =
- ( model.getArtifactId() == null ) ? model.getParent().getArtifactId() : model.getArtifactId();
- String version = ( model.getVersion() == null ) ? model.getParent().getVersion() : model.getVersion();
+ String groupId = ( model.getGroupId() == null && model.getParent() != null )
+ ? model.getParent().getGroupId()
+ : model.getGroupId();
+ String artifactId = ( model.getArtifactId() == null && model.getParent() != null )
+ ? model.getParent().getArtifactId()
+ : model.getArtifactId();
+ String version = ( model.getVersion() == null && model.getParent() != null )
+ ? model.getParent().getVersion()
+ : model.getVersion();
id = groupId + ":" + artifactId + ":" + version;
}
@@ -212,6 +249,14 @@
}
/**
+ * @return file of pom. May be null.
+ */
+ public File getFile()
+ {
+ return file;
+ }
+
+ /**
* @see org.apache.maven.shared.model.DomainModel#getEventHistory()
*/
public String getEventHistory()
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java?rev=693332&r1=693331&r2=693332&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java Mon Sep 8 18:04:17 2008
@@ -22,6 +22,7 @@
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.shared.model.DomainModel;
import org.apache.maven.shared.model.ModelContainer;
+import org.apache.maven.shared.model.ModelContainerAction;
import org.apache.maven.shared.model.ModelDataSource;
import org.apache.maven.shared.model.ModelMarshaller;
import org.apache.maven.shared.model.ModelProperty;
@@ -33,11 +34,12 @@
import java.io.StringReader;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
-import java.util.Set;
import java.util.Map;
-import java.util.HashMap;
+import java.util.Set;
/**
* Provides methods for transforming model properties into a domain model for the pom classic format and vice versa.
@@ -49,71 +51,77 @@
/**
* The URIs this tranformer supports
*/
- private final Set<String> uris;
+ private static Set<String> uris = new HashSet<String>( Arrays.asList( ProjectUri.Build.Extensions.xUri,
+ ProjectUri.Build.PluginManagement.Plugins.xUri,
+ ProjectUri.Build.PluginManagement.Plugins.Plugin.configuration,
+ ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.xUri,
+ ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.Exclusions.xUri,
+ ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri,
+
+ ProjectUri.Build.Plugins.xUri,
+ ProjectUri.Build.Plugins.Plugin.configuration,
+ ProjectUri.Build.Plugins.Plugin.Dependencies.xUri,
+ ProjectUri.Build.Plugins.Plugin.Executions.xUri,
+ ProjectUri.Build.Resources.xUri,
+ ProjectUri.Build.Resources.Resource.includes,
+ ProjectUri.Build.Resources.Resource.excludes,
+ ProjectUri.Build.TestResources.xUri,
+
+ ProjectUri.CiManagement.Notifiers.xUri,
+
+ ProjectUri.Contributors.xUri,
+
+ ProjectUri.Dependencies.xUri,
+ ProjectUri.Dependencies.Dependency.Exclusions.xUri,
+
+ ProjectUri.DependencyManagement.Dependencies.xUri,
+ ProjectUri.DependencyManagement.Dependencies.Dependency.Exclusions.xUri,
+
+ ProjectUri.Developers.xUri,
+ ProjectUri.Developers.Developer.roles,
+ ProjectUri.Licenses.xUri,
+ ProjectUri.MailingLists.xUri,
+ ProjectUri.Modules.xUri,
+ ProjectUri.PluginRepositories.xUri,
+
+ ProjectUri.Profiles.xUri,
+ ProjectUri.Profiles.Profile.Build.Plugins.xUri,
+ ProjectUri.Profiles.Profile.Build.Plugins.Plugin.Dependencies.xUri,
+ ProjectUri.Profiles.Profile.Build.Resources.xUri,
+ ProjectUri.Profiles.Profile.Build.TestResources.xUri,
+ ProjectUri.Profiles.Profile.Dependencies.xUri,
+ ProjectUri.Profiles.Profile.Dependencies.Dependency.Exclusions.xUri,
+ ProjectUri.Profiles.Profile.DependencyManagement.Dependencies.xUri,
+ ProjectUri.Profiles.Profile.PluginRepositories.xUri,
+ ProjectUri.Profiles.Profile.Reporting.Plugins.xUri,
+ ProjectUri.Profiles.Profile.Repositories.xUri,
+
+ ProjectUri.Reporting.Plugins.xUri,
+ ProjectUri.Reporting.Plugins.Plugin.ReportSets.xUri,
+
+ ProjectUri.Repositories.xUri,
+
+ "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/dependencies#collection",
+ "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/dependencies/dependency/exclusions#collection",
+ "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/executions#collection",
+ "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins#collection",
+ "http://apache.org/maven/project/profiles/profile/build/plugins/plugin/dependencies/dependency/exclusions#collection",
+ "http://apache.org/maven/project/profiles/profile/dependencyManagement/dependencies/dependency/exclusions#collection",
+ "http://apache.org/maven/project/profiles/profile/reporting/plugins/plugin/reportSets#collection",
+ "http://apache.org/maven/project/profiles/profile/build/plugins/plugin/executions#collection" ) );
private static Map<String, List<ModelProperty>> cache = new HashMap<String, List<ModelProperty>>();
+ private Collection<Profile> profiles;
+
//private static List<DomainModel> cache = new ArrayList<DomainModel>();
/**
* Default constructor
*/
- public PomClassicTransformer()
+ public PomClassicTransformer( Collection<Profile> profiles )
{
- this.uris = new HashSet<String>( Arrays.asList( ProjectUri.Build.Extensions.xUri,
- ProjectUri.Build.PluginManagement.Plugins.xUri,
- ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.xUri,
- ProjectUri.Build.PluginManagement.Plugins.Plugin.Dependencies.Dependency.Exclusions.xUri,
- ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri,
- ProjectUri.Build.Plugins.xUri,
- ProjectUri.Build.Plugins.Plugin.configuration,
- ProjectUri.Build.Plugins.Plugin.Dependencies.xUri,
- ProjectUri.Build.Plugins.Plugin.Executions.xUri,
- ProjectUri.Build.Resources.xUri,
- ProjectUri.Build.Resources.Resource.includes,
- ProjectUri.Build.Resources.Resource.excludes,
- ProjectUri.Build.TestResources.xUri,
-
- ProjectUri.CiManagement.Notifiers.xUri,
-
- ProjectUri.Contributors.xUri,
-
- ProjectUri.Dependencies.xUri,
- ProjectUri.Dependencies.Dependency.Exclusions.xUri,
-
- ProjectUri.DependencyManagement.Dependencies.xUri,
- ProjectUri.DependencyManagement.Dependencies.Dependency.Exclusions.xUri,
-
- ProjectUri.Developers.xUri,
- ProjectUri.Developers.Developer.roles, ProjectUri.Licenses.xUri,
- ProjectUri.MailingLists.xUri, ProjectUri.Modules.xUri,
- ProjectUri.PluginRepositories.xUri,
-
- ProjectUri.Profiles.xUri,
- ProjectUri.Profiles.Profile.Build.Plugins.xUri,
- ProjectUri.Profiles.Profile.Build.Plugins.Plugin.Dependencies.xUri,
- ProjectUri.Profiles.Profile.Build.Resources.xUri,
- ProjectUri.Profiles.Profile.Build.TestResources.xUri,
- ProjectUri.Profiles.Profile.Dependencies.xUri,
- ProjectUri.Profiles.Profile.Dependencies.Dependency.Exclusions.xUri,
- ProjectUri.Profiles.Profile.DependencyManagement.Dependencies.xUri,
- ProjectUri.Profiles.Profile.PluginRepositories.xUri,
- ProjectUri.Profiles.Profile.Reporting.Plugins.xUri,
- ProjectUri.Profiles.Profile.Repositories.xUri,
-
- ProjectUri.Reporting.Plugins.xUri,
- ProjectUri.Reporting.Plugins.Plugin.ReportSets.xUri,
-
- ProjectUri.Repositories.xUri,
-
- "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/dependencies#collection",
- "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/dependencies/dependency/exclusions#collection",
- "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins/plugin/executions#collection",
- "http://apache.org/maven/project/profiles/profile/build/pluginManagement/plugins#collection",
- "http://apache.org/maven/project/profiles/profile/build/plugins/plugin/dependencies/dependency/exclusions#collection",
- "http://apache.org/maven/project/profiles/profile/dependencyManagement/dependencies/dependency/exclusions#collection",
- "http://apache.org/maven/project/profiles/profile/reporting/plugins/plugin/reportSets#collection",
- "http://apache.org/maven/project/profiles/profile/build/plugins/plugin/executions#collection" ) );
+ this.profiles = profiles;
}
/**
@@ -140,6 +148,102 @@
}
}
+ //dependency management
+ ModelDataSource source = new DefaultModelDataSource();
+ source.init( props, Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) );
+
+ for ( ModelContainer dependencyContainer : source.queryFor( ProjectUri.Dependencies.Dependency.xUri ) )
+ {
+ for ( ModelContainer managementContainer : source.queryFor(
+ ProjectUri.DependencyManagement.Dependencies.Dependency.xUri ) )
+ {
+ managementContainer = new ArtifactModelContainerFactory().create(
+ transformDependencyManagement( managementContainer.getProperties() ) );
+ ModelContainerAction action = dependencyContainer.containerAction( managementContainer );
+ if ( action.equals( ModelContainerAction.JOIN ) || action.equals( ModelContainerAction.DELETE ) )
+ {
+ source.join( dependencyContainer, managementContainer );
+ }
+ }
+ }
+
+ for ( ModelContainer dependencyContainer : source.queryFor( ProjectUri.Build.Plugins.Plugin.xUri ) )
+ {
+ for ( ModelContainer managementContainer : source.queryFor(
+ ProjectUri.Build.PluginManagement.Plugins.Plugin.xUri ) )
+ {
+ managementContainer = new ArtifactModelContainerFactory().create(
+ transformPluginManagement( managementContainer.getProperties() ) );
+
+ //Remove duplicate executions tags
+ boolean hasExecutionsTag = false;
+ for ( ModelProperty mp : dependencyContainer.getProperties() )
+ {
+ if ( mp.getUri().equals( ProjectUri.Build.Plugins.Plugin.Executions.xUri ) )
+ {
+ hasExecutionsTag = true;
+ break;
+ }
+ }
+ List<ModelProperty> pList = new ArrayList<ModelProperty>();
+ if ( !hasExecutionsTag )
+ {
+ pList = managementContainer.getProperties();
+ }
+ else
+ {
+ for ( ModelProperty mp : managementContainer.getProperties() )
+ {
+ if ( !mp.getUri().equals( ProjectUri.Build.Plugins.Plugin.Executions.xUri ) )
+ {
+ pList.add( mp );
+ }
+ }
+ }
+ managementContainer = new ArtifactModelContainerFactory().create( pList );
+
+ ModelContainerAction action = dependencyContainer.containerAction( managementContainer );
+ if ( action.equals( ModelContainerAction.JOIN ) || action.equals( ModelContainerAction.DELETE ) )
+ {
+ source.join( dependencyContainer, managementContainer );
+ }
+ }
+ }
+
+ props = source.getModelProperties();
+
+ //Rule: Do not join plugin executions without ids
+ Set<ModelProperty> removeProperties = new HashSet<ModelProperty>();
+ ModelDataSource dataSource = new DefaultModelDataSource();
+ dataSource.init( props, Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) );
+ List<ModelContainer> containers = dataSource.queryFor( ProjectUri.Build.Plugins.Plugin.xUri );
+ for ( ModelContainer pluginContainer : containers )
+ {
+ ModelDataSource executionSource = new DefaultModelDataSource();
+ executionSource.init( pluginContainer.getProperties(),
+ Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) );
+ List<ModelContainer> executionContainers =
+ executionSource.queryFor( ProjectUri.Build.Plugins.Plugin.Executions.Execution.xUri );
+ if ( executionContainers.size() < 2 )
+ {
+ continue;
+ }
+
+ boolean hasAtLeastOneWithoutId = true;
+ for ( ModelContainer executionContainer : executionContainers )
+ {
+ if ( hasAtLeastOneWithoutId )
+ {
+ hasAtLeastOneWithoutId = hasExecutionId( executionContainer );
+ }
+ if ( !hasAtLeastOneWithoutId && !hasExecutionId( executionContainer ) &&
+ executionContainers.indexOf( executionContainer ) > 0 )
+ {
+ removeProperties.addAll( executionContainer.getProperties() );
+ }
+ }
+ }
+ props.removeAll( removeProperties );
String xml = null;
try
{
@@ -150,7 +254,7 @@
{
throw new IOException( e + ":\r\n" + xml );
}
- }
+ }
/**
* @see ModelTransformer#transformToModelProperties(java.util.List)
@@ -168,6 +272,11 @@
StringBuffer scmUrl = new StringBuffer();
StringBuffer scmConnectionUrl = new StringBuffer();
StringBuffer scmDeveloperUrl = new StringBuffer();
+
+ boolean containsBuildResources = false;
+ boolean containsTestResources = false;
+ boolean containsPluginRepositories = false;
+
for ( DomainModel domainModel : domainModels )
{
if ( !( domainModel instanceof PomClassicDomainModel ) )
@@ -185,6 +294,7 @@
List<ModelProperty> tmp = ModelMarshaller.marshallXmlToModelProperties(
( (PomClassicDomainModel) domainModel ).getInputStream(), ProjectUri.baseUri, uris );
+
List clearedProperties = new ArrayList<ModelProperty>();
//Missing Version Rule
@@ -219,7 +329,7 @@
}
- //Not inherited plugin execution rule
+ //Not inherited plugin execution rule
if ( domainModels.indexOf( domainModel ) > 0 )
{
List<ModelProperty> removeProperties = new ArrayList<ModelProperty>();
@@ -320,25 +430,62 @@
tmp.add( index, new ModelProperty( ProjectUri.Scm.developerConnection, scmDeveloperUrl.toString() ) );
}
-
- //Remove Plugin Repository Inheritance Rule
//Project Name Inheritance Rule
//Packaging Inheritance Rule
- //Build Resources Inheritence Rule
- //Build Test Resources Inheritance Rule
//Profiles not inherited rule
for ( ModelProperty mp : tmp )
{
String uri = mp.getUri();
if ( domainModels.indexOf( domainModel ) > 0 && ( uri.equals( ProjectUri.name ) ||
- uri.equals( ProjectUri.packaging ) || uri.startsWith( ProjectUri.Profiles.xUri ) ||
- uri.startsWith( ProjectUri.Build.Resources.xUri ) ||
- uri.startsWith( ProjectUri.Build.TestResources.xUri ) ||
- uri.startsWith( ProjectUri.PluginRepositories.xUri ) ) )
+ uri.equals( ProjectUri.packaging ) || uri.startsWith( ProjectUri.Profiles.xUri ) ) )
{
clearedProperties.add( mp );
}
}
+
+ //Remove Plugin Repository Inheritance Rule
+ //Build Resources Inheritence Rule
+ //Build Test Resources Inheritance Rule
+ //Only inherit IF: the above is contained in super pom (domainModels.size() -1) && the child doesn't has it's own respective field
+ if ( domainModels.indexOf( domainModel ) == 0 )
+ {
+ containsBuildResources = hasProjectUri( ProjectUri.Build.Resources.xUri, tmp );
+ containsTestResources = hasProjectUri( ProjectUri.Build.TestResources.xUri, tmp );
+ containsPluginRepositories = hasProjectUri( ProjectUri.PluginRepositories.xUri, tmp );
+ }
+ for ( ModelProperty mp : tmp )
+ {
+ if ( domainModels.indexOf( domainModel ) > 0 )
+ {
+ String uri = mp.getUri();
+ boolean isNotSuperPom = domainModels.indexOf( domainModel ) != ( domainModels.size() - 1 );
+ if ( isNotSuperPom )
+ {
+ if ( uri.startsWith( ProjectUri.Build.Resources.xUri ) ||
+ uri.startsWith( ProjectUri.Build.TestResources.xUri ) ||
+ uri.startsWith( ProjectUri.PluginRepositories.xUri ) )
+ {
+ clearedProperties.add( mp );
+ }
+ }
+ else
+ {
+ if ( containsBuildResources && uri.startsWith( ProjectUri.Build.Resources.xUri ) )
+ {
+ clearedProperties.add( mp );
+ }
+ else if ( containsTestResources && uri.startsWith( ProjectUri.Build.TestResources.xUri ) )
+ {
+ clearedProperties.add( mp );
+ }
+ else if ( containsPluginRepositories && uri.startsWith( ProjectUri.PluginRepositories.xUri ) )
+ {
+ clearedProperties.add( mp );
+ }
+ }
+ }
+ }
+
ModelProperty artifactId = getPropertyFor( ProjectUri.artifactId, tmp );
if ( artifactId != null )
{
@@ -347,8 +494,9 @@
tmp.removeAll( clearedProperties );
modelProperties.addAll( tmp );
+ modelProperties.removeAll( clearedProperties );
- if ( domainModels.indexOf( domainModel ) > 0 )
+ if ( domainModels.indexOf( domainModel ) == 0 )
{
//cache.put( pomDomainModel.getId(), modelProperties );
}
@@ -362,9 +510,22 @@
}
*/
}
+
return modelProperties;
}
+ private static boolean hasExecutionId( ModelContainer executionContainer )
+ {
+ for ( ModelProperty mp : executionContainer.getProperties() )
+ {
+ if ( mp.getUri().equals( ProjectUri.Build.Plugins.Plugin.Executions.Execution.id ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Returns the base uri of all model properties: http://apache.org/maven/project/
*
@@ -375,6 +536,18 @@
return ProjectUri.baseUri;
}
+ private static boolean hasProjectUri( String projectUri, List<ModelProperty> modelProperties )
+ {
+ for ( ModelProperty mp : modelProperties )
+ {
+ if ( mp.getUri().equals( projectUri ) )
+ {
+ return true;
+ }
+ }
+ return false;
+ }
+
/**
* Returns all model properties containing the specified uri from the specified properties list.
*
@@ -414,5 +587,34 @@
}
return null;
}
+
+ private static List<ModelProperty> transformDependencyManagement( List<ModelProperty> modelProperties )
+ {
+ List<ModelProperty> transformedProperties = new ArrayList<ModelProperty>();
+ for ( ModelProperty mp : modelProperties )
+ {
+ if ( mp.getUri().startsWith( ProjectUri.DependencyManagement.xUri ) )
+ {
+ transformedProperties.add( new ModelProperty(
+ mp.getUri().replace( ProjectUri.DependencyManagement.xUri, ProjectUri.xUri ), mp.getValue() ) );
+ }
+ }
+ return transformedProperties;
+ }
+
+ public static List<ModelProperty> transformPluginManagement( List<ModelProperty> modelProperties )
+ {
+ List<ModelProperty> transformedProperties = new ArrayList<ModelProperty>();
+ for ( ModelProperty mp : modelProperties )
+ {
+ if ( mp.getUri().startsWith( ProjectUri.Build.PluginManagement.xUri ) )
+ {
+ transformedProperties.add( new ModelProperty(
+ mp.getUri().replace( ProjectUri.Build.PluginManagement.xUri, ProjectUri.Build.xUri ),
+ mp.getValue() ) );
+ }
+ }
+ return transformedProperties;
+ }
}
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java?rev=693332&r1=693331&r2=693332&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java Mon Sep 8 18:04:17 2008
@@ -21,6 +21,8 @@
import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuilderConfiguration;
+import org.apache.maven.shared.model.ImportModel;
import org.apache.maven.shared.model.InterpolatorProperty;
import java.io.File;
@@ -40,17 +42,19 @@
/**
* Returns a maven project for the specified input stream.
*
- * @param pom input stream of the model
- * @param inheritedModels list of models containing additional parent models in order from most to least specialized
- * @param interpolatorProperties properties used for interpolation of properties within the model
- * @param resolver artifact resolver used in resolving artifacts
- * @param baseDirectory the base directory of the model
+ * @param pom input stream of the model
+ * @param inheritedModels list of models containing additional parent models in order from most to least specialized
+ * @param interpolatorProperties properties used for interpolation of properties within the model
+ * @param resolver artifact resolver used in resolving artifacts
+ * @param baseDirectory the base directory of the model
+ * @param projectBuilderConfiguration
* @return a maven project for the specified input stream
* @throws IOException if there is a problem in the construction of the maven project
*/
- MavenProject buildFromLocalPath( InputStream pom, List<Model> inheritedModels,
+ MavenProject buildFromLocalPath( InputStream pom, List<Model> inheritedModels, Collection<ImportModel> importModels,
Collection<InterpolatorProperty> interpolatorProperties,
- PomArtifactResolver resolver, File baseDirectory )
+ PomArtifactResolver resolver, File baseDirectory,
+ ProjectBuilderConfiguration projectBuilderConfiguration )
throws IOException;
}
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/ProjectUri.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/ProjectUri.java?rev=693332&r1=693331&r2=693332&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/ProjectUri.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/ProjectUri.java Mon Sep 8 18:04:17 2008
@@ -372,27 +372,27 @@
public static class Executions
{
public static String xUri =
- "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions";
+ "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions#collection";
public static class Execution
{
public static String xUri =
- "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions/execution";
+ "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions#collection/execution";
public static String id =
- "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions/execution/id";
+ "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions#collection/execution/id";
public static String phase =
- "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions/execution/phase";
+ "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions#collection/execution/phase";
public static String goals =
- "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions/execution/goals";
+ "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions#collection/execution/goals";
public static String inherited =
- "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions/execution/inherited";
+ "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions#collection/execution/inherited";
public static String configuration =
- "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/executions/execution/configuration";
+ "http://apache.org/maven/project/build/pluginManagement/plugins#collection/plugin/execution#collections/execution/configuration";
}
}
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java?rev=693332&r1=693331&r2=693332&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java Mon Sep 8 18:04:17 2008
@@ -19,11 +19,15 @@
* under the License.
*/
+import org.apache.maven.MavenTools;
import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.ProjectBuilderConfiguration;
+import org.apache.maven.project.RepositoryHelper;
import org.apache.maven.project.builder.ArtifactModelContainerFactory;
import org.apache.maven.project.builder.IdModelContainerFactory;
import org.apache.maven.project.builder.PomArtifactResolver;
@@ -33,13 +37,13 @@
import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator;
import org.apache.maven.shared.model.DomainModel;
+import org.apache.maven.shared.model.ImportModel;
import org.apache.maven.shared.model.InterpolatorProperty;
import org.apache.maven.shared.model.ModelTransformerContext;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import java.io.File;
-import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
@@ -64,6 +68,10 @@
private ModelValidator validator;
+ private MavenTools mavenTools;
+
+ private RepositoryHelper repositoryHelper;
+
/**
* Default constructor
*/
@@ -86,11 +94,13 @@
}
/**
- * @see ProjectBuilder#buildFromLocalPath(java.io.InputStream, java.util.List, java.util.Collection, org.apache.maven.project.builder.PomArtifactResolver, java.io.File)
+ * @see ProjectBuilder#buildFromLocalPath(java.io.InputStream, java.util.List, java.util.Collection, java.util.Collection, org.apache.maven.project.builder.PomArtifactResolver, java.io.File, org.apache.maven.project.ProjectBuilderConfiguration)
*/
public MavenProject buildFromLocalPath( InputStream pom, List<Model> inheritedModels,
+ Collection<ImportModel> importModels,
Collection<InterpolatorProperty> interpolatorProperties,
- PomArtifactResolver resolver, File projectDirectory )
+ PomArtifactResolver resolver, File projectDirectory,
+ ProjectBuilderConfiguration projectBuilderConfiguration )
throws IOException
{
if ( pom == null )
@@ -132,16 +142,30 @@
List<DomainModel> domainModels = new ArrayList<DomainModel>();
domainModels.add( domainModel );
+ File parentFile = null;
if ( domainModel.getModel().getParent() != null )
{
+ List<DomainModel> mavenParents;
if ( isParentLocal( domainModel.getModel().getParent(), projectDirectory ) )
{
- domainModels.addAll( getDomainModelParentsFromLocalPath( domainModel, resolver, projectDirectory ) );
+ mavenParents = getDomainModelParentsFromLocalPath( domainModel, resolver, projectDirectory );
}
else
{
- domainModels.addAll( getDomainModelParentsFromRepository( domainModel, resolver ) );
+ mavenParents = getDomainModelParentsFromRepository( domainModel, resolver );
+ }
+
+ if ( mavenParents.size() > 0 )
+ {
+ PomClassicDomainModel dm = (PomClassicDomainModel) mavenParents.get( 0 );
+ parentFile = dm.getFile();
+ domainModel.setParentFile( parentFile );
+ // mavenParent = buildFromLocalPath( dm.getInputStream(), inheritedModels,
+ // importModels, interpolatorProperties, resolver, projectDirectory);
+ // mavenParent.setFile(dm.getFile());
}
+
+ domainModels.addAll( mavenParents );
}
for ( Model model : inheritedModels )
@@ -149,16 +173,37 @@
domainModels.add( new PomClassicDomainModel( model ) );
}
- PomClassicTransformer transformer = new PomClassicTransformer();
+ PomClassicTransformer transformer = new PomClassicTransformer( null );
ModelTransformerContext ctx = new ModelTransformerContext(
Arrays.asList( new ArtifactModelContainerFactory(), new IdModelContainerFactory() ) );
- PomClassicDomainModel transformedDomainModel =
- ( (PomClassicDomainModel) ctx.transform( domainModels, transformer, transformer, null, properties ) );
- Model model = transformedDomainModel.getModel();
- return new MavenProject( model );
+ PomClassicDomainModel transformedDomainModel = ( (PomClassicDomainModel) ctx.transform( domainModels,
+ transformer,
+ transformer,
+ importModels,
+ properties ) );
+ // System.out.println(transformedDomainModel.asString());
+ try
+ {
+ MavenProject mavenProject = new MavenProject( transformedDomainModel.getModel(), artifactFactory,
+ mavenTools, repositoryHelper, null,
+ projectBuilderConfiguration );
+ mavenProject.setParentFile( parentFile );
+ return mavenProject;
+ }
+ catch ( InvalidRepositoryException e )
+ {
+ throw new IOException( e.getMessage() );
+ }
}
+ /**
+ * Returns true if the relative path of the specified parent references a pom, otherwise returns false.
+ *
+ * @param parent the parent model info
+ * @param projectDirectory the project directory of the child pom
+ * @return true if the relative path of the specified parent references a pom, otherwise returns fals
+ */
private boolean isParentLocal( Parent parent, File projectDirectory )
{
try
@@ -199,11 +244,11 @@
artifactFactory.createParentArtifact( parent.getGroupId(), parent.getArtifactId(), parent.getVersion() );
artifactResolver.resolve( artifactParent );
- PomClassicDomainModel parentDomainModel =
- new PomClassicDomainModel( new FileInputStream( artifactParent.getFile() ) );
+ PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( artifactParent.getFile() );
if ( !parentDomainModel.matchesParent( domainModel.getModel().getParent() ) )
{
- logger.warn( "Parent pom ids do not match: File = " + artifactParent.getFile().getAbsolutePath() );
+ logger.warn( "Parent pom ids do not match: Parent File = " + artifactParent.getFile().getAbsolutePath() +
+ ": Child ID = " + domainModel.getModel().getId() );
return domainModels;
}
else
@@ -217,7 +262,15 @@
return domainModels;
}
-
+ /**
+ * Returns list of domain model parents of the specified domain model. The parent domain models are part
+ *
+ * @param domainModel
+ * @param artifactResolver
+ * @param projectDirectory
+ * @return
+ * @throws IOException
+ */
private List<DomainModel> getDomainModelParentsFromLocalPath( PomClassicDomainModel domainModel,
PomArtifactResolver artifactResolver,
File projectDirectory )
@@ -248,13 +301,14 @@
if ( !parentFile.exists() )
{
- throw new IOException( "File does not exist: File =" + parentFile.getAbsolutePath() );
+ throw new IOException( "File does not exist: File = " + parentFile.getAbsolutePath() );
}
- PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( new FileInputStream( parentFile ) );
+ PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( parentFile );
if ( !parentDomainModel.matchesParent( domainModel.getModel().getParent() ) )
{
- logger.warn( "Parent pom ids do not match: File = " + parentFile.getAbsolutePath() );
+ logger.warn( "Parent pom ids do not match: Parent File = " + parentFile.getAbsolutePath() +
+ ": Child ID = " + domainModel.getModel().getId() );
}
domainModels.add( parentDomainModel );
@@ -290,6 +344,4 @@
throw new IOException( "Failed to validate: " + validationResult.toString() );
}
}
-
-
}
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java?rev=693332&r1=693331&r2=693332&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/inheritance/DefaultModelInheritanceAssembler.java Mon Sep 8 18:04:17 2008
@@ -26,12 +26,15 @@
import org.apache.maven.model.DistributionManagement;
import org.apache.maven.model.Model;
import org.apache.maven.model.PluginManagement;
+import org.apache.maven.model.ReportPlugin;
+import org.apache.maven.model.ReportSet;
import org.apache.maven.model.Reporting;
import org.apache.maven.model.Resource;
import org.apache.maven.model.Scm;
import org.apache.maven.model.Site;
import org.apache.maven.project.ModelUtils;
import org.codehaus.plexus.util.StringUtils;
+import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.util.ArrayList;
import java.util.Iterator;
@@ -52,19 +55,129 @@
public class DefaultModelInheritanceAssembler
implements ModelInheritanceAssembler
{
- public void copyModel( Model dest, Model source )
+
+ // TODO: Remove this!
+ @SuppressWarnings("unchecked")
+ public void assembleBuildInheritance( Build childBuild, Build parentBuild, boolean handleAsInheritance )
{
- assembleModelInheritance( dest, source, null, false );
+ // The build has been set but we want to step in here and fill in
+ // values that have not been set by the child.
+
+ if ( childBuild.getSourceDirectory() == null )
+ {
+ childBuild.setSourceDirectory( parentBuild.getSourceDirectory() );
+ }
+
+ if ( childBuild.getScriptSourceDirectory() == null )
+ {
+ childBuild.setScriptSourceDirectory( parentBuild.getScriptSourceDirectory() );
+ }
+
+ if ( childBuild.getTestSourceDirectory() == null )
+ {
+ childBuild.setTestSourceDirectory( parentBuild.getTestSourceDirectory() );
+ }
+
+ if ( childBuild.getOutputDirectory() == null )
+ {
+ childBuild.setOutputDirectory( parentBuild.getOutputDirectory() );
+ }
+
+ if ( childBuild.getTestOutputDirectory() == null )
+ {
+ childBuild.setTestOutputDirectory( parentBuild.getTestOutputDirectory() );
+ }
+
+ // Extensions are accumlated
+ ModelUtils.mergeExtensionLists( childBuild, parentBuild );
+
+ if ( childBuild.getDirectory() == null )
+ {
+ childBuild.setDirectory( parentBuild.getDirectory() );
+ }
+
+ if ( childBuild.getDefaultGoal() == null )
+ {
+ childBuild.setDefaultGoal( parentBuild.getDefaultGoal() );
+ }
+
+ if ( childBuild.getFinalName() == null )
+ {
+ childBuild.setFinalName( parentBuild.getFinalName() );
+ }
+
+ ModelUtils.mergeFilterLists( childBuild.getFilters(), parentBuild.getFilters() );
+
+ List<Resource> resources = childBuild.getResources();
+ if ( ( resources == null ) || resources.isEmpty() )
+ {
+ childBuild.setResources( parentBuild.getResources() );
+ }
+
+ resources = childBuild.getTestResources();
+ if ( ( resources == null ) || resources.isEmpty() )
+ {
+ childBuild.setTestResources( parentBuild.getTestResources() );
+ }
+
+ // Plugins are aggregated if Plugin.inherit != false
+ ModelUtils.mergePluginLists( childBuild, parentBuild, handleAsInheritance );
+
+ // Plugin management :: aggregate
+ PluginManagement dominantPM = childBuild.getPluginManagement();
+ PluginManagement recessivePM = parentBuild.getPluginManagement();
+
+ if ( ( dominantPM == null ) && ( recessivePM != null ) )
+ {
+ // FIXME: Filter out the inherited == false stuff!
+ childBuild.setPluginManagement( recessivePM );
+ }
+ else
+ {
+ ModelUtils.mergePluginLists( childBuild.getPluginManagement(), parentBuild.getPluginManagement(), false );
+ }
}
- public void assembleModelInheritance( Model child, Model parent, String childPathAdjustment )
+ private void assembleScmInheritance( Model child, Model parent, String childPathAdjustment, boolean appendPaths )
{
- assembleModelInheritance( child, parent, childPathAdjustment, true );
+ if ( parent.getScm() != null )
+ {
+ Scm parentScm = parent.getScm();
+
+ Scm childScm = child.getScm();
+
+ if ( childScm == null )
+ {
+ childScm = new Scm();
+
+ child.setScm( childScm );
+ }
+
+ if ( StringUtils.isEmpty( childScm.getConnection() ) && !StringUtils.isEmpty( parentScm.getConnection() ) )
+ {
+ childScm.setConnection(
+ appendPath( parentScm.getConnection(), child.getArtifactId(), childPathAdjustment, appendPaths ) );
+ }
+
+ if ( StringUtils.isEmpty( childScm.getDeveloperConnection() ) &&
+ !StringUtils.isEmpty( parentScm.getDeveloperConnection() ) )
+ {
+ childScm
+ .setDeveloperConnection( appendPath( parentScm.getDeveloperConnection(), child.getArtifactId(),
+ childPathAdjustment, appendPaths ) );
+ }
+
+ if ( StringUtils.isEmpty( childScm.getUrl() ) && !StringUtils.isEmpty( parentScm.getUrl() ) )
+ {
+ childScm.setUrl(
+ appendPath( parentScm.getUrl(), child.getArtifactId(), childPathAdjustment, appendPaths ) );
+ }
+ }
}
- public void assembleModelInheritance( Model child, Model parent )
+ public void copyModel( Model dest, Model source )
{
- assembleModelInheritance( child, parent, null, true );
+ assembleModelInheritance( dest, source, null, false );
}
private void assembleModelInheritance( Model child, Model parent, String childPathAdjustment, boolean appendPaths )
@@ -243,181 +356,229 @@
childReporting.setOutputDirectory( parentReporting.getOutputDirectory() );
}
- ModelUtils.mergeReportPluginLists( childReporting, parentReporting, true );
+ mergeReportPluginLists( childReporting, parentReporting, true );
}
}
- // TODO: Remove this!
- @SuppressWarnings("unchecked")
- private void assembleDependencyInheritance( Model child, Model parent )
+ private static void mergeReportPluginLists( Reporting child, Reporting parent, boolean handleAsInheritance )
{
- Map<String, Dependency> depsMap = new LinkedHashMap<String, Dependency>();
-
- List<Dependency> deps = parent.getDependencies();
-
- if ( deps != null )
+ if ( ( child == null ) || ( parent == null ) )
{
- for ( Iterator<Dependency> it = deps.iterator(); it.hasNext(); )
- {
- Dependency dependency = it.next();
- depsMap.put( dependency.getManagementKey(), dependency );
- }
+ // nothing to do.
+ return;
}
- deps = child.getDependencies();
+ List parentPlugins = parent.getPlugins();
- if ( deps != null )
+ if ( ( parentPlugins != null ) && !parentPlugins.isEmpty() )
{
- for ( Iterator<Dependency> it = deps.iterator(); it.hasNext(); )
+ Map assembledPlugins = new TreeMap();
+
+ Map childPlugins = child.getReportPluginsAsMap();
+
+ for ( Iterator it = parentPlugins.iterator(); it.hasNext(); )
{
- Dependency dependency = it.next();
- depsMap.put( dependency.getManagementKey(), dependency );
- }
- }
+ ReportPlugin parentPlugin = (ReportPlugin) it.next();
- child.setDependencies( new ArrayList<Dependency>( depsMap.values() ) );
- }
+ String parentInherited = parentPlugin.getInherited();
- private void assembleBuildInheritance( Model child, Model parent )
- {
- Build childBuild = child.getBuild();
- Build parentBuild = parent.getBuild();
+ if ( !handleAsInheritance || ( parentInherited == null ) ||
+ Boolean.valueOf( parentInherited ).booleanValue() )
+ {
- if ( parentBuild != null )
- {
- if ( childBuild == null )
+ ReportPlugin assembledPlugin = parentPlugin;
+
+ ReportPlugin childPlugin = (ReportPlugin) childPlugins.get( parentPlugin.getKey() );
+
+ if ( childPlugin != null )
+ {
+ assembledPlugin = childPlugin;
+
+ mergeReportPluginDefinitions( childPlugin, parentPlugin, handleAsInheritance );
+ }
+
+ if ( handleAsInheritance && ( parentInherited == null ) )
+ {
+ assembledPlugin.unsetInheritanceApplied();
+ }
+
+ assembledPlugins.put( assembledPlugin.getKey(), assembledPlugin );
+ }
+ }
+
+ for ( Iterator it = childPlugins.values().iterator(); it.hasNext(); )
{
- childBuild = new Build();
- child.setBuild( childBuild );
+ ReportPlugin childPlugin = (ReportPlugin) it.next();
+
+ if ( !assembledPlugins.containsKey( childPlugin.getKey() ) )
+ {
+ assembledPlugins.put( childPlugin.getKey(), childPlugin );
+ }
}
- assembleBuildInheritance( childBuild, parentBuild, true );
+ child.setPlugins( new ArrayList( assembledPlugins.values() ) );
+
+ child.flushReportPluginMap();
}
}
- // TODO: Remove this!
- @SuppressWarnings("unchecked")
- public void assembleBuildInheritance( Build childBuild,
- Build parentBuild,
- boolean handleAsInheritance )
+ private static void mergeReportSetDefinitions( ReportSet child, ReportSet parent )
{
- // The build has been set but we want to step in here and fill in
- // values that have not been set by the child.
+ List parentReports = parent.getReports();
+ List childReports = child.getReports();
- if ( childBuild.getSourceDirectory() == null )
- {
- childBuild.setSourceDirectory( parentBuild.getSourceDirectory() );
- }
+ List reports = new ArrayList();
- if ( childBuild.getScriptSourceDirectory() == null )
+ if ( ( childReports != null ) && !childReports.isEmpty() )
{
- childBuild.setScriptSourceDirectory( parentBuild.getScriptSourceDirectory() );
+ reports.addAll( childReports );
}
- if ( childBuild.getTestSourceDirectory() == null )
+ if ( parentReports != null )
{
- childBuild.setTestSourceDirectory( parentBuild.getTestSourceDirectory() );
- }
+ for ( Iterator i = parentReports.iterator(); i.hasNext(); )
+ {
+ String report = (String) i.next();
- if ( childBuild.getOutputDirectory() == null )
- {
- childBuild.setOutputDirectory( parentBuild.getOutputDirectory() );
+ if ( !reports.contains( report ) )
+ {
+ reports.add( report );
+ }
+ }
}
- if ( childBuild.getTestOutputDirectory() == null )
- {
- childBuild.setTestOutputDirectory( parentBuild.getTestOutputDirectory() );
- }
+ child.setReports( reports );
- // Extensions are accumlated
- ModelUtils.mergeExtensionLists( childBuild, parentBuild );
+ Xpp3Dom childConfiguration = (Xpp3Dom) child.getConfiguration();
+ Xpp3Dom parentConfiguration = (Xpp3Dom) parent.getConfiguration();
- if ( childBuild.getDirectory() == null )
- {
- childBuild.setDirectory( parentBuild.getDirectory() );
- }
+ childConfiguration = Xpp3Dom.mergeXpp3Dom( childConfiguration, parentConfiguration );
- if ( childBuild.getDefaultGoal() == null )
+ child.setConfiguration( childConfiguration );
+ }
+
+
+ public static void mergeReportPluginDefinitions( ReportPlugin child, ReportPlugin parent,
+ boolean handleAsInheritance )
+ {
+ if ( ( child == null ) || ( parent == null ) )
{
- childBuild.setDefaultGoal( parentBuild.getDefaultGoal() );
+ // nothing to do.
+ return;
}
- if ( childBuild.getFinalName() == null )
+ if ( ( child.getVersion() == null ) && ( parent.getVersion() != null ) )
{
- childBuild.setFinalName( parentBuild.getFinalName() );
+ child.setVersion( parent.getVersion() );
}
- ModelUtils.mergeFilterLists( childBuild.getFilters(), parentBuild.getFilters() );
+ // from here to the end of the method is dealing with merging of the <executions/> section.
+ String parentInherited = parent.getInherited();
- List<Resource> resources = childBuild.getResources();
- if ( ( resources == null ) || resources.isEmpty() )
- {
- childBuild.setResources( parentBuild.getResources() );
- }
+ boolean parentIsInherited = ( parentInherited == null ) || Boolean.valueOf( parentInherited ).booleanValue();
- resources = childBuild.getTestResources();
- if ( ( resources == null ) || resources.isEmpty() )
+ List parentReportSets = parent.getReportSets();
+
+ if ( ( parentReportSets != null ) && !parentReportSets.isEmpty() )
{
- childBuild.setTestResources( parentBuild.getTestResources() );
- }
+ Map assembledReportSets = new TreeMap();
- // Plugins are aggregated if Plugin.inherit != false
- ModelUtils.mergePluginLists( childBuild, parentBuild, handleAsInheritance );
+ Map childReportSets = child.getReportSetsAsMap();
- // Plugin management :: aggregate
- PluginManagement dominantPM = childBuild.getPluginManagement();
- PluginManagement recessivePM = parentBuild.getPluginManagement();
+ for ( Iterator it = parentReportSets.iterator(); it.hasNext(); )
+ {
+ ReportSet parentReportSet = (ReportSet) it.next();
- if ( ( dominantPM == null ) && ( recessivePM != null ) )
- {
- // FIXME: Filter out the inherited == false stuff!
- childBuild.setPluginManagement( recessivePM );
- }
- else
- {
- ModelUtils.mergePluginLists( childBuild.getPluginManagement(), parentBuild.getPluginManagement(),
- false );
- }
- }
+ if ( !handleAsInheritance || parentIsInherited )
+ {
+ ReportSet assembledReportSet = parentReportSet;
- private void assembleScmInheritance( Model child, Model parent, String childPathAdjustment, boolean appendPaths )
- {
- if ( parent.getScm() != null )
- {
- Scm parentScm = parent.getScm();
+ ReportSet childReportSet = (ReportSet) childReportSets.get( parentReportSet.getId() );
- Scm childScm = child.getScm();
+ if ( childReportSet != null )
+ {
+ mergeReportSetDefinitions( childReportSet, parentReportSet );
- if ( childScm == null )
+ assembledReportSet = childReportSet;
+ }
+ else if ( handleAsInheritance && ( parentInherited == null ) )
+ {
+ parentReportSet.unsetInheritanceApplied();
+ }
+
+ assembledReportSets.put( assembledReportSet.getId(), assembledReportSet );
+ }
+ }
+
+ for ( Iterator it = childReportSets.entrySet().iterator(); it.hasNext(); )
{
- childScm = new Scm();
+ Map.Entry entry = (Map.Entry) it.next();
- child.setScm( childScm );
+ String id = (String) entry.getKey();
+
+ if ( !assembledReportSets.containsKey( id ) )
+ {
+ assembledReportSets.put( id, entry.getValue() );
+ }
}
- if ( StringUtils.isEmpty( childScm.getConnection() ) && !StringUtils.isEmpty( parentScm.getConnection() ) )
+ child.setReportSets( new ArrayList( assembledReportSets.values() ) );
+
+ child.flushReportSetMap();
+ }
+
+ }
+
+ // TODO: Remove this!
+ @SuppressWarnings("unchecked")
+ private void assembleDependencyInheritance( Model child, Model parent )
+ {
+ Map<String, Dependency> depsMap = new LinkedHashMap<String, Dependency>();
+
+ List<Dependency> deps = parent.getDependencies();
+
+ if ( deps != null )
+ {
+ for ( Iterator<Dependency> it = deps.iterator(); it.hasNext(); )
{
- childScm.setConnection(
- appendPath( parentScm.getConnection(), child.getArtifactId(), childPathAdjustment, appendPaths ) );
+ Dependency dependency = it.next();
+ depsMap.put( dependency.getManagementKey(), dependency );
}
+ }
- if ( StringUtils.isEmpty( childScm.getDeveloperConnection() ) &&
- !StringUtils.isEmpty( parentScm.getDeveloperConnection() ) )
+ deps = child.getDependencies();
+
+ if ( deps != null )
+ {
+ for ( Iterator<Dependency> it = deps.iterator(); it.hasNext(); )
{
- childScm
- .setDeveloperConnection( appendPath( parentScm.getDeveloperConnection(), child.getArtifactId(),
- childPathAdjustment, appendPaths ) );
+ Dependency dependency = it.next();
+ depsMap.put( dependency.getManagementKey(), dependency );
}
+ }
- if ( StringUtils.isEmpty( childScm.getUrl() ) && !StringUtils.isEmpty( parentScm.getUrl() ) )
+ child.setDependencies( new ArrayList<Dependency>( depsMap.values() ) );
+ }
+
+ private void assembleBuildInheritance( Model child, Model parent )
+ {
+ Build childBuild = child.getBuild();
+ Build parentBuild = parent.getBuild();
+
+ if ( parentBuild != null )
+ {
+ if ( childBuild == null )
{
- childScm.setUrl(
- appendPath( parentScm.getUrl(), child.getArtifactId(), childPathAdjustment, appendPaths ) );
+ childBuild = new Build();
+ child.setBuild( childBuild );
}
+
+ assembleBuildInheritance( childBuild, parentBuild, true );
}
}
- private void assembleDistributionInheritence( Model child, Model parent, String childPathAdjustment, boolean appendPaths )
+ private void assembleDistributionInheritence( Model child, Model parent, String childPathAdjustment,
+ boolean appendPaths )
{
if ( parent.getDistributionManagement() != null )
{
@@ -570,7 +731,6 @@
}
}
-
StringBuffer cleanedPath = new StringBuffer();
while ( !pathElements.isEmpty() )
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/inheritance/ModelInheritanceAssembler.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/inheritance/ModelInheritanceAssembler.java?rev=693332&r1=693331&r2=693332&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/inheritance/ModelInheritanceAssembler.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/inheritance/ModelInheritanceAssembler.java Mon Sep 8 18:04:17 2008
@@ -30,13 +30,7 @@
{
String ROLE = ModelInheritanceAssembler.class.getName();
- void assembleModelInheritance( Model child, Model parent, String childPathAdjustment );
-
- void assembleModelInheritance( Model child, Model parent );
-
- void assembleBuildInheritance( Build childBuild,
- Build parentBuild,
- boolean handleAsInheriance );
+ void assembleBuildInheritance( Build childBuild, Build parentBuild, boolean handleAsInheriance );
void copyModel( Model dest, Model source );
}
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/ModelInterpolator.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/ModelInterpolator.java?rev=693332&r1=693331&r2=693332&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/ModelInterpolator.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/ModelInterpolator.java Mon Sep 8 18:04:17 2008
@@ -42,29 +42,20 @@
* @deprecated Use {@link ModelInterpolator#interpolate(Model, File, ProjectBuilderConfiguration, boolean)} instead.
*/
@Deprecated
- Model interpolate( Model project,
- Map<String, ?> context )
+ Model interpolate( Model project, Map<String, ?> context )
throws ModelInterpolationException;
/**
* @deprecated Use {@link ModelInterpolator#interpolate(Model, File, ProjectBuilderConfiguration, boolean)} instead.
*/
@Deprecated
- Model interpolate( Model model,
- Map<String, ?> context,
- boolean strict )
+ Model interpolate( Model model, Map<String, ?> context, boolean strict )
throws ModelInterpolationException;
- Model interpolate( Model model,
- File projectDir,
- ProjectBuilderConfiguration config,
- boolean debugEnabled )
+ Model interpolate( Model model, File projectDir, ProjectBuilderConfiguration config, boolean debugEnabled )
throws ModelInterpolationException;
- String interpolate( String src,
- Model model,
- File projectDir,
- ProjectBuilderConfiguration config,
+ String interpolate( String src, Model model, File projectDir, ProjectBuilderConfiguration config,
boolean debugEnabled )
throws ModelInterpolationException;
}
\ No newline at end of file
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/PathTranslatingPostProcessor.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/PathTranslatingPostProcessor.java?rev=693332&r1=693331&r2=693332&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/PathTranslatingPostProcessor.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/PathTranslatingPostProcessor.java Mon Sep 8 18:04:17 2008
@@ -20,15 +20,12 @@
*/
import org.apache.maven.project.path.PathTranslator;
-import org.codehaus.plexus.interpolation.AbstractFunctionValueSourceWrapper;
import org.codehaus.plexus.interpolation.InterpolationPostProcessor;
-import org.codehaus.plexus.interpolation.ValueSource;
import java.io.File;
import java.util.List;
/**
- *
* @version $Id: PathTranslatingPostProcessor.java 677447 2008-07-16 22:15:57Z jdcasey $
*/
public class PathTranslatingPostProcessor
@@ -36,7 +33,9 @@
{
private final List unprefixedPathKeys;
+
private final File projectDir;
+
private final PathTranslator pathTranslator;
public PathTranslatingPostProcessor( List unprefixedPathKeys, File projectDir, PathTranslator pathTranslator )
@@ -46,8 +45,7 @@
this.pathTranslator = pathTranslator;
}
- public Object execute( String expression,
- Object value )
+ public Object execute( String expression, Object value )
{
if ( projectDir != null && value != null && unprefixedPathKeys.contains( expression ) )
{
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java?rev=693332&r1=693331&r2=693332&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/interpolation/RegexBasedModelInterpolator.java Mon Sep 8 18:04:17 2008
@@ -61,7 +61,8 @@
implements ModelInterpolator
{
- private static final List<String> PROJECT_PREFIXES = Arrays.asList( new String[]{ "pom.", "project." } );
+ private static final List<String> PROJECT_PREFIXES = Arrays.asList( new String[]{"pom.", "project."} );
+
private static final List<String> TRANSLATED_PATH_EXPRESSIONS;
static
@@ -88,7 +89,7 @@
throws IOException
{
}
-
+
// for testing.
protected RegexBasedModelInterpolator( PathTranslator pathTranslator )
{
@@ -101,9 +102,7 @@
Properties props = new Properties();
props.putAll( context );
- return interpolate( model,
- null,
- new DefaultProjectBuilderConfiguration().setExecutionProperties( props ),
+ return interpolate( model, null, new DefaultProjectBuilderConfiguration().setExecutionProperties( props ),
true );
}
@@ -113,9 +112,7 @@
Properties props = new Properties();
props.putAll( context );
- return interpolate( model,
- null,
- new DefaultProjectBuilderConfiguration().setExecutionProperties( props ),
+ return interpolate( model, null, new DefaultProjectBuilderConfiguration().setExecutionProperties( props ),
true );
}
@@ -125,14 +122,14 @@
* <br/>
* <b>NOTE:</b> This will result in a different instance of Model being returned!!!
*
- * @param model The inbound Model instance, to serialize and reference for expression resolution
- * @param context The other context map to be used during resolution
+ * @param model The inbound Model instance, to serialize and reference for expression resolution
+ * @param context The other context map to be used during resolution
* @param overrideContext The context map which should be used to OVERRIDE
* values from everything else. This will come from the CLI
* or userProperties in the execution request.
- * @param projectDir The directory from which the current model's pom was read.
- * @param strict This parameter is ignored!
- * @param debugMessages If true, print any feedback from the interpolator out to the DEBUG log-level.
+ * @param projectDir The directory from which the current model's pom was read.
+ * @param strict This parameter is ignored!
+ * @param debugMessages If true, print any feedback from the interpolator out to the DEBUG log-level.
* @return The resolved instance of the inbound Model. This is a different instance!
*/
public Model interpolate( Model model, File projectDir, ProjectBuilderConfiguration config, boolean debugMessages )
@@ -176,23 +173,21 @@
/**
* Interpolates all expressions in the src parameter.
- * <p>
+ * <p/>
* The algorithm used for each expression is:
* <ul>
- * <li>If it starts with either "pom." or "project.", the expression is evaluated against the model.</li>
- * <li>If the value is null, get the value from the context.</li>
- * <li>If the value is null, but the context contains the expression, don't replace the expression string
- * with the value, and continue to find other expressions.</li>
- * <li>If the value is null, get it from the model properties.</li>
- * <li>
+ * <li>If it starts with either "pom." or "project.", the expression is evaluated against the model.</li>
+ * <li>If the value is null, get the value from the context.</li>
+ * <li>If the value is null, but the context contains the expression, don't replace the expression string
+ * with the value, and continue to find other expressions.</li>
+ * <li>If the value is null, get it from the model properties.</li>
+ * <li>
+ *
* @param overrideContext
* @param debugMessages
*/
- public String interpolate( String src,
- Model model,
- final File projectDir,
- ProjectBuilderConfiguration config,
- boolean debugMessages )
+ public String interpolate( String src, Model model, final File projectDir, ProjectBuilderConfiguration config,
+ boolean debugMessages )
throws ModelInterpolationException
{
Logger logger = getLogger();
@@ -208,7 +203,8 @@
ValueSource modelValueSource1 = new PrefixedObjectValueSource( PROJECT_PREFIXES, model, false );
ValueSource modelValueSource2 = new ObjectBasedValueSource( model );
- ValueSource basedirValueSource = new PrefixedValueSourceWrapper( new ValueSource(){
+ ValueSource basedirValueSource = new PrefixedValueSourceWrapper( new ValueSource()
+ {
public Object getValue( String expression )
{
if ( projectDir != null && "basedir".equals( expression ) )
@@ -218,8 +214,7 @@
return null;
}
- },
- PROJECT_PREFIXES, true );
+ }, PROJECT_PREFIXES, true );
RegexBasedInterpolator interpolator = new RegexBasedInterpolator();
@@ -228,13 +223,14 @@
interpolator.addValueSource( new BuildTimestampValueSource( config.getBuildStartTime(), timestampFormat ) );
interpolator.addValueSource( new MapBasedValueSource( config.getExecutionProperties() ) );
interpolator.addValueSource( modelValueSource1 );
- interpolator.addValueSource( new PrefixedValueSourceWrapper( new MapBasedValueSource( modelProperties ), PROJECT_PREFIXES, true ) );
+ interpolator.addValueSource(
+ new PrefixedValueSourceWrapper( new MapBasedValueSource( modelProperties ), PROJECT_PREFIXES, true ) );
interpolator.addValueSource( modelValueSource2 );
interpolator.addValueSource( new MapBasedValueSource( config.getUserProperties() ) );
-
+
PathTranslatingPostProcessor pathTranslatingPostProcessor =
new PathTranslatingPostProcessor( TRANSLATED_PATH_EXPRESSIONS, projectDir, pathTranslator );
-
+
interpolator.addPostProcessor( pathTranslatingPostProcessor );
RecursionInterceptor recursionInterceptor = new PrefixAwareRecursionInterceptor( PROJECT_PREFIXES );
@@ -244,7 +240,7 @@
{
result = interpolator.interpolate( result, "", recursionInterceptor );
}
- catch( InterpolationException e )
+ catch ( InterpolationException e )
{
throw new ModelInterpolationException( e.getMessage(), e );
}
Modified: maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java
URL: http://svn.apache.org/viewvc/maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java?rev=693332&r1=693331&r2=693332&view=diff
==============================================================================
--- maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java (original)
+++ maven/components/trunk/maven-project/src/main/java/org/apache/maven/project/path/DefaultPathTranslator.java Mon Sep 8 18:04:17 2008
@@ -31,11 +31,7 @@
public class DefaultPathTranslator
implements PathTranslator
{
- private static final String[] BASEDIR_EXPRESSIONS = {
- "${basedir}",
- "${pom.basedir}",
- "${project.basedir}"
- };
+ private static final String[] BASEDIR_EXPRESSIONS = {"${basedir}", "${pom.basedir}", "${project.basedir}"};
private String FILE_SEPARATOR = "/";