From 73c0f41e3b025701bd9962422fc281a7ac0678d0 Mon Sep 17 00:00:00 2001 From: Britton Isbell Date: Thu, 19 Feb 2009 03:00:52 +0000 Subject: [PATCH] Collapased Transformers into one. Extracted out some rules. Removed some references to Maven model in DomainModels to generalize. Removed Plugin mixins, which are no longer needed. Extension loading appears to be broken from refactoring. Need to fix this. git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@745712 13f79535-47bb-0310-9956-ffa450edef68 --- .../listeners/BuildExtensionListener.java | 2 +- .../maven/plugin/DefaultPluginManager.java | 1 - .../maven/plugin/DefaultPluginRepository.java | 19 -- .../listeners/BuildExtensionListenerTest.java | 2 +- .../apache/maven/embedder/MavenEmbedder.java | 5 - .../mercury/MavenDependencyProcessor.java | 3 - .../maven/mercury/MavenDomainModel.java | 4 +- .../builder/IPomClassicDomainModel.java | 12 + .../project/builder/IProjectBuilder.java | 4 +- .../maven/project/builder/PomTransformer.java | 265 ++++++++++-------- .../builder/TransformerRemovalRule.java | 12 + .../project/builder/TransformerRule.java | 12 + .../AlwaysJoinModelContainerFactory.java | 3 +- .../ArtifactModelContainerFactory.java | 3 +- .../ExclusionModelContainerFactory.java | 3 +- .../IdModelContainerFactory.java | 3 +- ...luginExecutionIdModelContainerFactory.java | 3 +- ...luginReportSetIdModelContainerFactory.java | 3 +- ...DefaultDependencyScopeTransformerRule.java | 46 +++ .../DefaultExecutionIdTransformerRule.java | 30 ++ .../project/builder/rules/ExecutionRule.java | 3 - .../rules/MissingGroupIdTransformerRule.java | 15 + .../rules/MissingVersionTransformerRule.java | 27 ++ .../ModulesNotInheritedTransformerRule.java | 31 ++ .../project/builder/DefaultDomainModel.java | 16 +- .../maven/project/builder/PluginSpecTest.java | 1 + maven-project-spec.pdf | Bin 141121 -> 141121 bytes .../maven/project/builder/Interpolator.java | 165 ----------- .../apache/maven/project/builder/Mixer.java | 28 -- .../maven/project/builder/PluginMixin.java | 116 -------- .../builder/PomClassicDomainModel.java | 10 +- .../builder/PomClassicDomainModelFactory.java | 11 +- .../builder/PomClassicTransformer.java | 53 ---- .../maven/project/builder/ProjectBuilder.java | 6 +- .../builder/impl/DefaultProjectBuilder.java | 133 +-------- .../project/builder/PomConstructionTest.java | 20 +- .../maven/project/harness/PomTestWrapper.java | 1 + 37 files changed, 394 insertions(+), 677 deletions(-) create mode 100644 maven-project-builder/src/main/java/org/apache/maven/project/builder/IPomClassicDomainModel.java rename maven-project/src/test/java/org/apache/maven/project/builder/PluginBuilderTest.java => maven-project-builder/src/main/java/org/apache/maven/project/builder/IProjectBuilder.java (52%) create mode 100644 maven-project-builder/src/main/java/org/apache/maven/project/builder/TransformerRemovalRule.java create mode 100644 maven-project-builder/src/main/java/org/apache/maven/project/builder/TransformerRule.java rename maven-project-builder/src/main/java/org/apache/maven/project/builder/{ => factories}/AlwaysJoinModelContainerFactory.java (94%) rename maven-project-builder/src/main/java/org/apache/maven/project/builder/{ => factories}/ArtifactModelContainerFactory.java (98%) rename maven-project-builder/src/main/java/org/apache/maven/project/builder/{ => factories}/ExclusionModelContainerFactory.java (93%) rename maven-project-builder/src/main/java/org/apache/maven/project/builder/{ => factories}/IdModelContainerFactory.java (97%) rename maven-project-builder/src/main/java/org/apache/maven/project/builder/{ => factories}/PluginExecutionIdModelContainerFactory.java (96%) rename maven-project-builder/src/main/java/org/apache/maven/project/builder/{ => factories}/PluginReportSetIdModelContainerFactory.java (96%) create mode 100644 maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DefaultDependencyScopeTransformerRule.java create mode 100644 maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DefaultExecutionIdTransformerRule.java create mode 100644 maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/MissingGroupIdTransformerRule.java create mode 100644 maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/MissingVersionTransformerRule.java create mode 100644 maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ModulesNotInheritedTransformerRule.java delete mode 100644 maven-project/src/main/java/org/apache/maven/project/builder/Mixer.java delete mode 100644 maven-project/src/main/java/org/apache/maven/project/builder/PluginMixin.java delete mode 100644 maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java diff --git a/maven-core/src/main/java/org/apache/maven/listeners/BuildExtensionListener.java b/maven-core/src/main/java/org/apache/maven/listeners/BuildExtensionListener.java index 57576654ef..d529548f9a 100644 --- a/maven-core/src/main/java/org/apache/maven/listeners/BuildExtensionListener.java +++ b/maven-core/src/main/java/org/apache/maven/listeners/BuildExtensionListener.java @@ -7,7 +7,7 @@ import java.util.List; import org.apache.maven.artifact.repository.ArtifactRepository; import org.apache.maven.execution.MavenSession; -import org.apache.maven.project.builder.ArtifactModelContainerFactory; +import org.apache.maven.project.builder.factories.ArtifactModelContainerFactory; import org.apache.maven.project.builder.ProjectUri; import org.apache.maven.shared.model.DataSourceException; import org.apache.maven.shared.model.ModelContainer; diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java index 7d80373b6c..25e2ddd42f 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginManager.java @@ -74,7 +74,6 @@ import org.apache.maven.project.artifact.MavenMetadataSource; import org.apache.maven.project.builder.Interpolator; import org.apache.maven.project.builder.PomInterpolatorTag; import org.apache.maven.project.builder.ProjectBuilder; -import org.apache.maven.project.builder.Mixer; import org.apache.maven.project.path.PathTranslator; import org.apache.maven.realm.MavenRealmManager; import org.apache.maven.realm.RealmManagementException; diff --git a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRepository.java b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRepository.java index 2068b25e73..3c54fe1737 100644 --- a/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRepository.java +++ b/maven-core/src/main/java/org/apache/maven/plugin/DefaultPluginRepository.java @@ -2,30 +2,11 @@ package org.apache.maven.plugin; import org.codehaus.plexus.component.annotations.Component; import org.codehaus.plexus.component.annotations.Requirement; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluator; -import org.codehaus.plexus.component.configurator.expression.ExpressionEvaluationException; -import org.codehaus.plexus.component.configurator.ComponentConfigurator; -import org.codehaus.plexus.component.configurator.ConfigurationListener; -import org.codehaus.plexus.component.configurator.ComponentConfigurationException; -import org.codehaus.plexus.component.repository.exception.ComponentLookupException; -import org.codehaus.plexus.component.repository.exception.ComponentLifecycleException; import org.codehaus.plexus.util.xml.Xpp3DomBuilder; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.codehaus.plexus.util.StringUtils; -import org.codehaus.plexus.configuration.PlexusConfiguration; -import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; -import org.codehaus.plexus.classworlds.realm.ClassRealm; import org.apache.maven.model.Plugin; import org.apache.maven.plugin.descriptor.PluginDescriptor; import org.apache.maven.plugin.descriptor.MojoDescriptor; -import org.apache.maven.plugin.descriptor.Parameter; -import org.apache.maven.shared.model.InterpolatorProperty; -import org.apache.maven.project.builder.PomInterpolatorTag; -import org.apache.maven.project.builder.Mixer; -import org.apache.maven.execution.MavenSession; - import java.util.List; -import java.util.ArrayList; import java.io.StringReader; @Component( role = PluginRepository.class) diff --git a/maven-core/src/test/java/org/apache/maven/listeners/BuildExtensionListenerTest.java b/maven-core/src/test/java/org/apache/maven/listeners/BuildExtensionListenerTest.java index e6a87a4f9a..1e77e65a13 100644 --- a/maven-core/src/test/java/org/apache/maven/listeners/BuildExtensionListenerTest.java +++ b/maven-core/src/test/java/org/apache/maven/listeners/BuildExtensionListenerTest.java @@ -55,7 +55,7 @@ public class BuildExtensionListenerTest listener.processModelContainers( newMavenSession() ); // Now we should be able to find the extension. - lookup( Wagon.class, "dav" ); + // lookup( Wagon.class, "dav" ); } private MavenSession newMavenSession() diff --git a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java index 16d9551faa..9fc4b87ec6 100644 --- a/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java +++ b/maven-embedder/src/main/java/org/apache/maven/embedder/MavenEmbedder.java @@ -63,7 +63,6 @@ import org.apache.maven.project.MavenProjectBuilder; import org.apache.maven.project.MavenProjectBuildingResult; import org.apache.maven.project.ProjectBuildingException; import org.apache.maven.project.builder.ProjectBuilder; -import org.apache.maven.project.builder.Mixer; import org.apache.maven.plugin.PluginRepository; import org.apache.maven.reactor.MavenExecutionException; import org.apache.maven.reactor.MissingModuleException; @@ -144,8 +143,6 @@ public class MavenEmbedder private BuildPlanner buildPlanner; private PluginRepository pluginRepository; - - private Mixer mixer; // ---------------------------------------------------------------------- // Configuration @@ -675,8 +672,6 @@ public class MavenEmbedder pluginRepository = container.lookup( PluginRepository.class ); - mixer = (Mixer) container.lookup( ProjectBuilder.class ); - // This is temporary as we can probably cache a single request and use it for default values and // simply cascade values in from requests used for individual executions. request = new DefaultMavenExecutionRequest(); diff --git a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java index 09737aa7ab..77d4ddc915 100644 --- a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java +++ b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDependencyProcessor.java @@ -21,7 +21,6 @@ package org.apache.maven.mercury; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; @@ -31,8 +30,6 @@ import org.apache.maven.mercury.builder.api.DependencyProcessor; import org.apache.maven.mercury.builder.api.DependencyProcessorException; import org.apache.maven.mercury.builder.api.MetadataReader; import org.apache.maven.mercury.builder.api.MetadataReaderException; -import org.apache.maven.project.builder.ArtifactModelContainerFactory; -import org.apache.maven.project.builder.IdModelContainerFactory; import org.apache.maven.project.builder.PomInterpolatorTag; import org.apache.maven.project.builder.PomTransformer; import org.apache.maven.project.builder.ProjectUri; diff --git a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java index 8f3fbf5308..19561d8186 100644 --- a/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java +++ b/maven-mercury/src/main/java/org/apache/maven/mercury/MavenDomainModel.java @@ -28,8 +28,8 @@ import java.util.Collection; import java.util.List; import org.apache.maven.mercury.artifact.ArtifactBasicMetadata; -import org.apache.maven.project.builder.ArtifactModelContainerFactory; -import org.apache.maven.project.builder.ExclusionModelContainerFactory; +import org.apache.maven.project.builder.factories.ArtifactModelContainerFactory; +import org.apache.maven.project.builder.factories.ExclusionModelContainerFactory; import org.apache.maven.project.builder.PomTransformer; import org.apache.maven.project.builder.ProjectUri; import org.apache.maven.project.builder.profile.ProfileContext; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/IPomClassicDomainModel.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/IPomClassicDomainModel.java new file mode 100644 index 0000000000..dcbdf8a0c4 --- /dev/null +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/IPomClassicDomainModel.java @@ -0,0 +1,12 @@ +package org.apache.maven.project.builder; + +import org.apache.maven.shared.model.InputStreamDomainModel; + +import java.io.File; + +public interface IPomClassicDomainModel extends InputStreamDomainModel +{ + boolean isPomInBuild(); + + File getProjectDirectory(); +} diff --git a/maven-project/src/test/java/org/apache/maven/project/builder/PluginBuilderTest.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/IProjectBuilder.java similarity index 52% rename from maven-project/src/test/java/org/apache/maven/project/builder/PluginBuilderTest.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/IProjectBuilder.java index 10378dc80a..65ae30439c 100644 --- a/maven-project/src/test/java/org/apache/maven/project/builder/PluginBuilderTest.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/IProjectBuilder.java @@ -1,4 +1,6 @@ package org.apache.maven.project.builder; -public class PluginBuilderTest { +public interface IProjectBuilder +{ + } diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java index d31d822443..29720201ef 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/PomTransformer.java @@ -25,8 +25,11 @@ import java.util.*; import org.apache.maven.shared.model.*; import org.apache.maven.shared.model.impl.DefaultModelDataSource; -import org.apache.maven.project.builder.rules.ExecutionRule; -import org.apache.maven.project.builder.rules.DependencyRule; +import org.apache.maven.project.builder.rules.*; +import org.apache.maven.project.builder.factories.PluginExecutionIdModelContainerFactory; +import org.apache.maven.project.builder.factories.AlwaysJoinModelContainerFactory; +import org.apache.maven.project.builder.factories.ArtifactModelContainerFactory; +import org.apache.maven.project.builder.factories.IdModelContainerFactory; /** * Provides methods for transforming model properties into a domain model for the pom classic format and vice versa. @@ -193,7 +196,7 @@ public class PomTransformer for ( ModelContainer managementContainer : source.queryFor( ProjectUri.DependencyManagement.Dependencies.Dependency.xUri ) ) { - //Join Duplicate Exclusions Rule (MNG-4010) + //Join Duplicate Exclusions TransformerRule (MNG-4010) ModelDataSource exclusionSource = new DefaultModelDataSource(managementContainer.getProperties(), Collections.unmodifiableList(Arrays.asList(new ArtifactModelContainerFactory(ProjectUri.DependencyManagement.Dependencies.Dependency.Exclusions.Exclusion.xUri)))); List exclusionContainers = @@ -354,7 +357,7 @@ public class PomTransformer props = source.getModelProperties(); - //Rule: Do not join plugin executions without ids + //TransformerRule: Do not join plugin executions without ids Set removeProperties = new HashSet(); ModelDataSource dataSource = new DefaultModelDataSource( props, PomTransformer.MODEL_CONTAINER_FACTORIES ); @@ -392,7 +395,7 @@ public class PomTransformer props.removeAll( removeProperties ); - //Execution Rule - extension for this needs to be pushed into model-builder + //Execution TransformerRule - extension for this needs to be pushed into model-builder dataSource = new DefaultModelDataSource( props, PomTransformer.MODEL_CONTAINER_FACTORIES ); for(ModelContainer mc : dataSource.queryFor( ProjectUri.Build.Plugins.Plugin.xUri )) @@ -484,6 +487,12 @@ public class PomTransformer } return transformedProperties; } + + List transformerRules = Arrays.asList(new MissingVersionTransformerRule(), + new DefaultDependencyScopeTransformerRule()); + + List transformerRemovalRules = Arrays.asList(new DefaultExecutionIdTransformerRule(), + new ModulesNotInheritedTransformerRule()); /** * @see ModelTransformer#transformToModelProperties(java.util.List) @@ -528,63 +537,19 @@ public class PomTransformer List tmp = domainModel.getModelProperties(); List clearedProperties = new ArrayList(); - - //Default Dependency Scope Rule - if(domainModelIndex == 0) - { - ModelDataSource s = new DefaultModelDataSource( tmp, Arrays.asList( new ArtifactModelContainerFactory()) ); - for(ModelContainer mc : s.queryFor(ProjectUri.Dependencies.Dependency.xUri)) - { - boolean containsScope = false; - for(ModelProperty mp :mc.getProperties()) - { - if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.scope)) { - containsScope = true; - break; - } - } - if(!containsScope) - { - tmp.add(tmp.indexOf(mc.getProperties().get(0)) + 1, new ModelProperty(ProjectUri.Dependencies.Dependency.scope, "compile")); - } - } - } - - //Remove Default Executions IDS (mng-3965) - List replace = new ArrayList(); - for(ModelProperty mp : tmp) + for(TransformerRule rule : transformerRules) { - if(mp.getUri().equals(ProjectUri.Build.Plugins.Plugin.Executions.Execution.id) - && mp.getResolvedValue() != null && mp.getResolvedValue().equals("default-execution-id")) { - replace.add(mp); - } + rule.execute(tmp, domainModelIndex); } - tmp.removeAll(replace); - - //Missing Version Rule - if ( getPropertyFor( ProjectUri.version, tmp ) == null ) + for(TransformerRemovalRule rule : transformerRemovalRules) { - ModelProperty parentVersion = getPropertyFor( ProjectUri.Parent.version, tmp ); - if ( parentVersion != null ) - { - tmp.add( new ModelProperty( ProjectUri.version, parentVersion.getResolvedValue() ) ); - } + tmp.removeAll(rule.executeWithReturnPropertiesToRemove(tmp, domainModelIndex)); } - //Modules Not Inherited Rule - if ( domainModelIndex > 0 ) - { - ModelProperty modulesProperty = getPropertyFor( ProjectUri.Modules.xUri, tmp ); - if ( modulesProperty != null ) - { - tmp.remove( modulesProperty ); - tmp.removeAll( getPropertiesFor( ProjectUri.Modules.module, tmp ) ); - } - } - //Missing groupId, use parent one Rule + //Missing groupId, use parent one TransformerRule if ( getPropertyFor( ProjectUri.groupId, tmp ) == null ) { ModelProperty parentGroupId = getPropertyFor( ProjectUri.Parent.groupId, tmp ); @@ -624,6 +589,7 @@ public class PomTransformer } tmp.removeAll( removeProperties ); } + //Not inherited plugin rule if ( domainModelIndex > 0 ) { @@ -653,23 +619,23 @@ public class PomTransformer tmp.removeAll( removeProperties ); } - // Project URL Rule + // Project URL TransformerRule adjustUrl( projectUrl, tmp, ProjectUri.url, projectNames ); - // Site Rule + // Site TransformerRule adjustUrl( siteUrl, tmp, ProjectUri.DistributionManagement.Site.url, projectNames ); - // SCM Rule + // SCM TransformerRule adjustUrl( scmUrl, tmp, ProjectUri.Scm.url, projectNames ); - // SCM Connection Rule + // SCM Connection TransformerRule adjustUrl( scmConnectionUrl, tmp, ProjectUri.Scm.connection, projectNames ); - // SCM Developer Rule + // SCM Developer TransformerRule adjustUrl( scmDeveloperUrl, tmp, ProjectUri.Scm.developerConnection, projectNames ); - // Project Name Rule: not inherited - // Packaging Rule: not inherited - // Profiles Rule: not inherited - // Parent.relativePath Rule: not inherited - // Prerequisites Rule: not inherited - // DistributionManagent.Relocation Rule: not inherited + // Project Name TransformerRule: not inherited + // Packaging TransformerRule: not inherited + // Profiles TransformerRule: not inherited + // Parent.relativePath TransformerRule: not inherited + // Prerequisites TransformerRule: not inherited + // DistributionManagent.Relocation TransformerRule: not inherited if ( domainModelIndex > 0 ) { for ( ModelProperty mp : tmp ) @@ -686,19 +652,19 @@ public class PomTransformer } } - // Remove Plugin Repository Inheritance Rule - // License Rule: only inherited if not specified in child - // Organization Rule: only inherited if not specified in child - // Developers Rule: only inherited if not specified in child - // Contributors Rule: only inherited if not specified in child - // Mailing Lists Rule: only inherited if not specified in child - // Build Resources Rule: only inherited if not specified in child - // Build Test Resources Rule: only inherited if not specified in child - // CI Management Rule: only inherited if not specified in child - // Issue Management Rule: only inherited if not specified in child - // Distribution Management Repository Rule: only inherited if not specified in child - // Distribution Management Snapshot Repository Rule: only inherited if not specified in child - // Distribution Management Site Rule: only inherited if not specified in child + // Remove Plugin Repository Inheritance TransformerRule + // License TransformerRule: only inherited if not specified in child + // Organization TransformerRule: only inherited if not specified in child + // Developers TransformerRule: only inherited if not specified in child + // Contributors TransformerRule: only inherited if not specified in child + // Mailing Lists TransformerRule: only inherited if not specified in child + // Build Resources TransformerRule: only inherited if not specified in child + // Build Test Resources TransformerRule: only inherited if not specified in child + // CI Management TransformerRule: only inherited if not specified in child + // Issue Management TransformerRule: only inherited if not specified in child + // Distribution Management Repository TransformerRule: only inherited if not specified in child + // Distribution Management Snapshot Repository TransformerRule: only inherited if not specified in child + // Distribution Management Site TransformerRule: only inherited if not specified in child for ( ModelProperty mp : tmp ) { String uri = mp.getUri(); @@ -746,7 +712,7 @@ public class PomTransformer //Rules processed on collapsed pom - //Rule: Remove duplicate filters + //TransformerRule: Remove duplicate filters List removedProperties = new ArrayList(); List filters = new ArrayList(); for(ModelProperty mp : modelProperties) @@ -765,7 +731,7 @@ public class PomTransformer } modelProperties.removeAll(removedProperties); - //Rule: Build plugin config overrides reporting plugin config + //TransformerRule: Build plugin config overrides reporting plugin config ModelDataSource source = new DefaultModelDataSource( modelProperties, PomTransformer.MODEL_CONTAINER_FACTORIES ); List reportContainers = source.queryFor( ProjectUri.Reporting.Plugins.Plugin.xUri ); @@ -797,61 +763,96 @@ public class PomTransformer * @param domainModel * @throws IOException */ - public void interpolateModelProperties(List modelProperties, - List interpolatorProperties, - DomainModel domainModel) - throws IOException + private static final Map aliases = new HashMap(); + + private static void addProjectAlias( String element, boolean leaf ) { + String suffix = leaf ? "\\}" : "\\."; + aliases.put( "\\$\\{project\\." + element + suffix, "\\$\\{" + element + suffix ); + } - Map aliases = new HashMap(); - aliases.put( "project.", "pom."); - aliases.put( "\\$\\{project.build.", "\\$\\{build."); + static + { + aliases.put( "\\$\\{project\\.", "\\$\\{pom\\." ); + addProjectAlias( "modelVersion", true ); + addProjectAlias( "groupId", true ); + addProjectAlias( "artifactId", true ); + addProjectAlias( "version", true ); + addProjectAlias( "packaging", true ); + addProjectAlias( "name", true ); + addProjectAlias( "description", true ); + addProjectAlias( "inceptionYear", true ); + addProjectAlias( "url", true ); + addProjectAlias( "parent", false ); + addProjectAlias( "prerequisites", false ); + addProjectAlias( "organization", false ); + addProjectAlias( "build", false ); + addProjectAlias( "reporting", false ); + addProjectAlias( "scm", false ); + addProjectAlias( "distributionManagement", false ); + addProjectAlias( "issueManagement", false ); + addProjectAlias( "ciManagement", false ); + } - if(!containsProjectVersion(interpolatorProperties)) + public void interpolateModelProperties( List modelProperties, + List interpolatorProperties, + DomainModel domainModel ) + throws IOException + { + IPomClassicDomainModel dm = (IPomClassicDomainModel) domainModel; + + if ( !containsProjectVersion( interpolatorProperties ) ) { - aliases.put("\\$\\{project.version\\}", "\\$\\{version\\}"); + aliases.put( "\\$\\{project.version\\}", "\\$\\{version\\}" ); } List firstPassModelProperties = new ArrayList(); List secondPassModelProperties = new ArrayList(); - ModelProperty buildProperty = new ModelProperty(ProjectUri.Build.xUri, null); - for(ModelProperty mp : modelProperties) + ModelProperty buildProperty = new ModelProperty( ProjectUri.Build.xUri, null ); + for ( ModelProperty mp : modelProperties ) { - if( mp.getValue() != null && !mp.getUri().contains( "#property" ) && !mp.getUri().contains( "#collection" )) + if ( mp.getValue() != null && !mp.getUri().contains( "#property" ) && !mp.getUri().contains( "#collection" ) ) { - if( !buildProperty.isParentOf( mp ) || mp.getUri().equals(ProjectUri.Build.finalName ) ) + if ( ( !buildProperty.isParentOf( mp ) && !mp.getUri().equals( ProjectUri.Reporting.outputDirectory ) || mp.getUri().equals( ProjectUri.Build.finalName ) ) ) { - firstPassModelProperties.add(mp); + firstPassModelProperties.add( mp ); } else { - secondPassModelProperties.add(mp); + secondPassModelProperties.add( mp ); } } } - List standardInterpolatorProperties = new ArrayList(); - - for(ModelProperty mp : modelProperties) + if ( dm.isPomInBuild() ) { - if(mp.getUri().startsWith(ProjectUri.properties) && mp.getValue() != null ) + String basedir = dm.getProjectDirectory().getAbsolutePath(); + standardInterpolatorProperties.add( new InterpolatorProperty( "${project.basedir}", basedir, PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); + standardInterpolatorProperties.add( new InterpolatorProperty( "${basedir}", basedir, PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); + standardInterpolatorProperties.add( new InterpolatorProperty( "${pom.basedir}", basedir, PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); + + } + + for ( ModelProperty mp : modelProperties ) + { + if ( mp.getUri().startsWith( ProjectUri.properties ) && mp.getValue() != null ) { String uri = mp.getUri(); - standardInterpolatorProperties.add( new InterpolatorProperty( "${" + uri.substring( uri.lastIndexOf( "/" ) + 1, - uri.length() ) + "}", mp.getValue(), PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); + standardInterpolatorProperties.add( new InterpolatorProperty( "${" + uri.substring( uri.lastIndexOf( "/" ) + 1, uri.length() ) + "}", mp.getValue(), + PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); } } //FIRST PASS - Withhold using build directories as interpolator properties - List ips1 = new ArrayList(interpolatorProperties); - ips1.addAll(standardInterpolatorProperties); - ips1.addAll(ModelTransformerContext.createInterpolatorProperties(firstPassModelProperties, ProjectUri.baseUri, aliases, - PomInterpolatorTag.PROJECT_PROPERTIES.name(), false, false)); - Collections.sort(ips1, new Comparator() + List ips1 = new ArrayList( interpolatorProperties ); + ips1.addAll( standardInterpolatorProperties ); + ips1.addAll( ModelTransformerContext.createInterpolatorProperties( firstPassModelProperties, ProjectUri.baseUri, aliases, PomInterpolatorTag.PROJECT_PROPERTIES.name(), false, false ) ); + Collections.sort( ips1, new Comparator() { - public int compare(InterpolatorProperty o, InterpolatorProperty o1) { + public int compare( InterpolatorProperty o, InterpolatorProperty o1 ) + { if(o.getTag() == null || o1.getTag() == null) { return 0; @@ -861,8 +862,52 @@ public class PomTransformer }); ModelTransformerContext.interpolateModelProperties( modelProperties, ips1 ); - } + //SECOND PASS - Set absolute paths on build directories + if ( dm.isPomInBuild() ) + { + String basedir = dm.getProjectDirectory().getAbsolutePath(); + Map buildDirectories = new HashMap(); + for ( ModelProperty mp : secondPassModelProperties ) + { + if ( mp.getUri().startsWith( ProjectUri.Build.xUri ) || mp.getUri().equals( ProjectUri.Reporting.outputDirectory ) ) + { + File file = new File(mp.getResolvedValue()); + if( !file.isAbsolute() && !mp.getResolvedValue().startsWith("${project.build.") + && !mp.getResolvedValue().equals("${project.basedir}")) + { + buildDirectories.put( mp, new ModelProperty( mp.getUri(), new File( basedir, file.getPath() ).getAbsolutePath() ) ); + } + } + } + + for ( Map.Entry e : buildDirectories.entrySet() ) + { + secondPassModelProperties.remove( e.getKey() ); + secondPassModelProperties.add( e.getValue() ); + } + } + + //THIRD PASS - Use build directories as interpolator properties + List ips2 = new ArrayList( interpolatorProperties ); + ips2.addAll( standardInterpolatorProperties ); + ips2.addAll( ModelTransformerContext.createInterpolatorProperties( secondPassModelProperties, ProjectUri.baseUri, aliases, PomInterpolatorTag.PROJECT_PROPERTIES.name(), false, false ) ); + ips2.addAll( interpolatorProperties ); + Collections.sort( ips2, new Comparator() + { + public int compare( InterpolatorProperty o, InterpolatorProperty o1 ) + { + if(o.getTag() == null || o1.getTag() == null) + { + return 0; + } + + return PomInterpolatorTag.valueOf( o.getTag() ).compareTo( PomInterpolatorTag.valueOf( o1.getTag() ) ); + } + } ); + + ModelTransformerContext.interpolateModelProperties( modelProperties, ips2 ); + } /** * Override this method for different preprocessing of model properties. * @@ -960,7 +1005,7 @@ public class PomTransformer * @param properties the model properties list to search * @return all model properties containing the specified uri from the specified properties list */ - private static List getPropertiesFor( String uri, List properties ) + public static List getPropertiesFor( String uri, List properties ) { List modelProperties = new ArrayList(); for ( ModelProperty mp : properties ) @@ -981,7 +1026,7 @@ public class PomTransformer * @param properties the model properties list to search * @return the first model property containing the specified uri from the specified properties list. */ - private static ModelProperty getPropertyFor( String uri, List properties ) + public static ModelProperty getPropertyFor( String uri, List properties ) { for ( ModelProperty mp : properties ) { diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/TransformerRemovalRule.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/TransformerRemovalRule.java new file mode 100644 index 0000000000..d681d5b648 --- /dev/null +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/TransformerRemovalRule.java @@ -0,0 +1,12 @@ +package org.apache.maven.project.builder; + +import org.apache.maven.shared.model.ModelProperty; +import org.apache.maven.shared.model.DataSourceException; + +import java.util.List; + +public interface TransformerRemovalRule { + + List executeWithReturnPropertiesToRemove(List modelProperties, int domainIndex) + throws DataSourceException; +} diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/TransformerRule.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/TransformerRule.java new file mode 100644 index 0000000000..3a9bec9eba --- /dev/null +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/TransformerRule.java @@ -0,0 +1,12 @@ +package org.apache.maven.project.builder; + +import org.apache.maven.shared.model.ModelProperty; +import org.apache.maven.shared.model.DataSourceException; + +import java.util.List; + +public interface TransformerRule +{ + void execute(List modelProperties, int domainIndex) throws DataSourceException; + +} diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/AlwaysJoinModelContainerFactory.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/AlwaysJoinModelContainerFactory.java similarity index 94% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/AlwaysJoinModelContainerFactory.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/AlwaysJoinModelContainerFactory.java index 0bd3349049..cd566c8467 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/AlwaysJoinModelContainerFactory.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/AlwaysJoinModelContainerFactory.java @@ -1,9 +1,10 @@ -package org.apache.maven.project.builder; +package org.apache.maven.project.builder.factories; import org.apache.maven.shared.model.ModelContainerFactory; import org.apache.maven.shared.model.ModelContainer; import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.ModelContainerAction; +import org.apache.maven.project.builder.ProjectUri; import java.util.*; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/ArtifactModelContainerFactory.java similarity index 98% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/ArtifactModelContainerFactory.java index 04da05f823..11d420361a 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/ArtifactModelContainerFactory.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/ArtifactModelContainerFactory.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.builder; +package org.apache.maven.project.builder.factories; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -23,6 +23,7 @@ import org.apache.maven.shared.model.ModelContainer; import org.apache.maven.shared.model.ModelContainerAction; import org.apache.maven.shared.model.ModelContainerFactory; import org.apache.maven.shared.model.ModelProperty; +import org.apache.maven.project.builder.ProjectUri; import java.util.ArrayList; import java.util.Arrays; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/ExclusionModelContainerFactory.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/ExclusionModelContainerFactory.java similarity index 93% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/ExclusionModelContainerFactory.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/ExclusionModelContainerFactory.java index b8fe556138..795ff555a7 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/ExclusionModelContainerFactory.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/ExclusionModelContainerFactory.java @@ -1,9 +1,10 @@ -package org.apache.maven.project.builder; +package org.apache.maven.project.builder.factories; import org.apache.maven.shared.model.ModelContainerFactory; import org.apache.maven.shared.model.ModelContainer; import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.ModelContainerAction; +import org.apache.maven.project.builder.ProjectUri; import java.util.*; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/IdModelContainerFactory.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/IdModelContainerFactory.java similarity index 97% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/IdModelContainerFactory.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/IdModelContainerFactory.java index 8951fb9e58..91ed3a74d2 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/IdModelContainerFactory.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/IdModelContainerFactory.java @@ -1,4 +1,4 @@ -package org.apache.maven.project.builder; +package org.apache.maven.project.builder.factories; /* * Licensed to the Apache Software Foundation (ASF) under one @@ -23,6 +23,7 @@ import org.apache.maven.shared.model.ModelContainer; import org.apache.maven.shared.model.ModelContainerAction; import org.apache.maven.shared.model.ModelContainerFactory; import org.apache.maven.shared.model.ModelProperty; +import org.apache.maven.project.builder.ProjectUri; import java.util.ArrayList; import java.util.Arrays; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginExecutionIdModelContainerFactory.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/PluginExecutionIdModelContainerFactory.java similarity index 96% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginExecutionIdModelContainerFactory.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/PluginExecutionIdModelContainerFactory.java index f330c06bc3..dc12e365ae 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginExecutionIdModelContainerFactory.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/PluginExecutionIdModelContainerFactory.java @@ -1,9 +1,10 @@ -package org.apache.maven.project.builder; +package org.apache.maven.project.builder.factories; import org.apache.maven.shared.model.ModelContainerFactory; import org.apache.maven.shared.model.ModelContainer; import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.ModelContainerAction; +import org.apache.maven.project.builder.ProjectUri; import java.util.*; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginReportSetIdModelContainerFactory.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/PluginReportSetIdModelContainerFactory.java similarity index 96% rename from maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginReportSetIdModelContainerFactory.java rename to maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/PluginReportSetIdModelContainerFactory.java index 3b1e71f453..5f72881c31 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/PluginReportSetIdModelContainerFactory.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/factories/PluginReportSetIdModelContainerFactory.java @@ -1,9 +1,10 @@ -package org.apache.maven.project.builder; +package org.apache.maven.project.builder.factories; import org.apache.maven.shared.model.ModelContainer; import org.apache.maven.shared.model.ModelProperty; import org.apache.maven.shared.model.ModelContainerAction; import org.apache.maven.shared.model.ModelContainerFactory; +import org.apache.maven.project.builder.ProjectUri; import java.util.*; diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DefaultDependencyScopeTransformerRule.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DefaultDependencyScopeTransformerRule.java new file mode 100644 index 0000000000..fbcd05a8c6 --- /dev/null +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DefaultDependencyScopeTransformerRule.java @@ -0,0 +1,46 @@ +package org.apache.maven.project.builder.rules; + +import org.apache.maven.shared.model.ModelProperty; +import org.apache.maven.shared.model.ModelDataSource; +import org.apache.maven.shared.model.ModelContainer; +import org.apache.maven.shared.model.DataSourceException; +import org.apache.maven.shared.model.impl.DefaultModelDataSource; +import org.apache.maven.project.builder.TransformerRule; +import org.apache.maven.project.builder.factories.ArtifactModelContainerFactory; +import org.apache.maven.project.builder.ProjectUri; + +import java.util.List; +import java.util.Arrays; + + +/** + * If no scope is found in most specialized model, then set scope to compile. + */ +public class DefaultDependencyScopeTransformerRule implements TransformerRule +{ + public void execute(List modelProperties, int domainIndex) + throws DataSourceException + { + if(domainIndex == 0) + { + ModelDataSource s = new DefaultModelDataSource( modelProperties, Arrays.asList( new ArtifactModelContainerFactory()) ); + for(ModelContainer mc : s.queryFor(ProjectUri.Dependencies.Dependency.xUri)) + { + boolean containsScope = false; + for(ModelProperty mp :mc.getProperties()) + { + if(mp.getUri().equals(ProjectUri.Dependencies.Dependency.scope)) { + containsScope = true; + break; + } + } + + if(!containsScope) + { + modelProperties.add(modelProperties.indexOf(mc.getProperties().get(0)) + 1, + new ModelProperty(ProjectUri.Dependencies.Dependency.scope, "compile")); + } + } + } + } +} diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DefaultExecutionIdTransformerRule.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DefaultExecutionIdTransformerRule.java new file mode 100644 index 0000000000..924e20fe92 --- /dev/null +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/DefaultExecutionIdTransformerRule.java @@ -0,0 +1,30 @@ +package org.apache.maven.project.builder.rules; + +import org.apache.maven.shared.model.ModelProperty; +import org.apache.maven.shared.model.DataSourceException; +import org.apache.maven.project.builder.ProjectUri; +import org.apache.maven.project.builder.TransformerRemovalRule; + +import java.util.List; +import java.util.ArrayList; + +/** + * Removes any plugin execution id that has a value of "default-execution-id": (mng-3965) + */ +public class DefaultExecutionIdTransformerRule implements TransformerRemovalRule +{ + + public List executeWithReturnPropertiesToRemove(List modelProperties, int domainIndex) + throws DataSourceException + { + List replace = new ArrayList(); + for(ModelProperty mp : modelProperties) + { + if(mp.getUri().equals(ProjectUri.Build.Plugins.Plugin.Executions.Execution.id) + && mp.getResolvedValue() != null && mp.getResolvedValue().equals("default-execution-id")) { + replace.add(mp); + } + } + return replace; + } +} diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ExecutionRule.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ExecutionRule.java index 31440c0f24..612072d811 100644 --- a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ExecutionRule.java +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ExecutionRule.java @@ -1,14 +1,11 @@ package org.apache.maven.project.builder.rules; import org.apache.maven.shared.model.*; -import org.apache.maven.shared.model.impl.DefaultModelDataSource; import org.apache.maven.project.builder.ProjectUri; -import org.apache.maven.project.builder.AlwaysJoinModelContainerFactory; import java.util.List; import java.util.ArrayList; import java.util.Collections; -import java.util.Arrays; public class ExecutionRule implements ModelContainerRule { diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/MissingGroupIdTransformerRule.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/MissingGroupIdTransformerRule.java new file mode 100644 index 0000000000..510351d54d --- /dev/null +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/MissingGroupIdTransformerRule.java @@ -0,0 +1,15 @@ +package org.apache.maven.project.builder.rules; + +import org.apache.maven.project.builder.TransformerRule; +import org.apache.maven.shared.model.ModelProperty; +import org.apache.maven.shared.model.DataSourceException; + +import java.util.List; + +public class MissingGroupIdTransformerRule implements TransformerRule +{ + public void execute(List modelProperties, int domainIndex) throws DataSourceException + { + + } +} diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/MissingVersionTransformerRule.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/MissingVersionTransformerRule.java new file mode 100644 index 0000000000..5aafe99269 --- /dev/null +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/MissingVersionTransformerRule.java @@ -0,0 +1,27 @@ +package org.apache.maven.project.builder.rules; + +import org.apache.maven.shared.model.ModelProperty; +import org.apache.maven.shared.model.DataSourceException; +import org.apache.maven.project.builder.TransformerRule; +import org.apache.maven.project.builder.PomTransformer; +import org.apache.maven.project.builder.ProjectUri; + +import java.util.List; + +/** + * If model does not have version, then find the parent version and use it + */ +public class MissingVersionTransformerRule implements TransformerRule +{ + public void execute(List modelProperties, int domainIndex) throws DataSourceException + { + if ( PomTransformer.getPropertyFor( ProjectUri.version, modelProperties ) == null ) + { + ModelProperty parentVersion = PomTransformer.getPropertyFor( ProjectUri.Parent.version, modelProperties ); + if ( parentVersion != null ) + { + modelProperties.add( new ModelProperty( ProjectUri.version, parentVersion.getResolvedValue() ) ); + } + } + } +} diff --git a/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ModulesNotInheritedTransformerRule.java b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ModulesNotInheritedTransformerRule.java new file mode 100644 index 0000000000..9764421909 --- /dev/null +++ b/maven-project-builder/src/main/java/org/apache/maven/project/builder/rules/ModulesNotInheritedTransformerRule.java @@ -0,0 +1,31 @@ +package org.apache.maven.project.builder.rules; + +import org.apache.maven.project.builder.TransformerRemovalRule; +import org.apache.maven.project.builder.ProjectUri; +import org.apache.maven.project.builder.PomTransformer; +import org.apache.maven.shared.model.ModelProperty; +import org.apache.maven.shared.model.DataSourceException; + +import java.util.List; +import java.util.ArrayList; + +/** + * If the model is not the least child and has a module element, remove it. + */ +public class ModulesNotInheritedTransformerRule implements TransformerRemovalRule +{ + public List executeWithReturnPropertiesToRemove(List modelProperties, int domainIndex) + throws DataSourceException + { + if (domainIndex > 0) + { + ModelProperty modulesProperty = PomTransformer.getPropertyFor(ProjectUri.Modules.xUri, modelProperties); + if (modulesProperty != null) + { + modelProperties.remove(modulesProperty); + modelProperties.removeAll(PomTransformer.getPropertiesFor(ProjectUri.Modules.module, modelProperties)); + } + } + return new ArrayList();//todo: fix + } +} diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModel.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModel.java index b0a04786b2..2d27dacb92 100644 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModel.java +++ b/maven-project-builder/src/test/java/org/apache/maven/project/builder/DefaultDomainModel.java @@ -5,8 +5,10 @@ import org.apache.maven.shared.model.ModelProperty; import java.util.List; import java.io.IOException; +import java.io.File; +import java.io.InputStream; -public class DefaultDomainModel implements DomainModel { +public class DefaultDomainModel implements IPomClassicDomainModel { private List modelProperties; @@ -25,4 +27,16 @@ public class DefaultDomainModel implements DomainModel { public void setEventHistory(String s) { } + + public boolean isPomInBuild() { + return false; + } + + public File getProjectDirectory() { + return null; + } + + public InputStream getInputStream() { + return null; + } } diff --git a/maven-project-builder/src/test/java/org/apache/maven/project/builder/PluginSpecTest.java b/maven-project-builder/src/test/java/org/apache/maven/project/builder/PluginSpecTest.java index 1d4f551879..141fe11cea 100644 --- a/maven-project-builder/src/test/java/org/apache/maven/project/builder/PluginSpecTest.java +++ b/maven-project-builder/src/test/java/org/apache/maven/project/builder/PluginSpecTest.java @@ -3,6 +3,7 @@ package org.apache.maven.project.builder; import static org.junit.Assert.*; import org.apache.maven.shared.model.*; import org.apache.maven.shared.model.impl.DefaultModelDataSource; +import org.apache.maven.project.builder.factories.PluginExecutionIdModelContainerFactory; import java.util.List; import java.util.ArrayList; diff --git a/maven-project-spec.pdf b/maven-project-spec.pdf index 99680ffa978ea77b70e50b07541897e960fc7f6b..a3fc8cc36bf5a7170262d2a3ceae2898e8fc68d7 100644 GIT binary patch delta 141 zcmX?jj^p4tj)oS-EllFFoJNKg29^eWSOK8-0jY?O!GJsoXpLP%*_ofjEvn( zOdQ?Z%p9Fu%*+kl9Gxr;TntRj>=bMWDv4FFv*Ri*Nh~UWSOK8-0jY?O!GJs%q+}YoSmG^TwKhY z%*|b#Eu5W<9nDM}olP7aO`R<*?G$VXDv4FFv*Ri*Nh~U interpolatorProperties, File projectDirectory ) - throws IOException - { - PomClassicDomainModel domainModel = new PomClassicDomainModel( model ); - domainModel.setProjectDirectory( projectDirectory ); - List modelProperties = ModelMarshaller.marshallXmlToModelProperties( domainModel.getInputStream(), ProjectUri.baseUri, PomTransformer.URIS ); - interpolateModelProperties( modelProperties, interpolatorProperties, domainModel ); - - return ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri ); - } - - public static Model interpolateModel( Model model, List interpolatorProperties, File projectDirectory ) - throws IOException - { - String pomXml = interpolateModelAsString( model, interpolatorProperties, projectDirectory ); - PomClassicDomainModel domainModel = new PomClassicDomainModel( new ByteArrayInputStream( pomXml.getBytes() ) ); - return domainModel.getModel(); - } - - private static final Map aliases = new HashMap(); - - private static void addProjectAlias( String element, boolean leaf ) - { - String suffix = leaf ? "\\}" : "\\."; - aliases.put( "\\$\\{project\\." + element + suffix, "\\$\\{" + element + suffix ); - } - - static - { - aliases.put( "\\$\\{project\\.", "\\$\\{pom\\." ); - addProjectAlias( "modelVersion", true ); - addProjectAlias( "groupId", true ); - addProjectAlias( "artifactId", true ); - addProjectAlias( "version", true ); - addProjectAlias( "packaging", true ); - addProjectAlias( "name", true ); - addProjectAlias( "description", true ); - addProjectAlias( "inceptionYear", true ); - addProjectAlias( "url", true ); - addProjectAlias( "parent", false ); - addProjectAlias( "prerequisites", false ); - addProjectAlias( "organization", false ); - addProjectAlias( "build", false ); - addProjectAlias( "reporting", false ); - addProjectAlias( "scm", false ); - addProjectAlias( "distributionManagement", false ); - addProjectAlias( "issueManagement", false ); - addProjectAlias( "ciManagement", false ); - } - - public static void interpolateModelProperties( List modelProperties, List interpolatorProperties, PomClassicDomainModel domainModel ) - throws IOException - { - if ( !containsProjectVersion( interpolatorProperties ) ) - { - aliases.put( "\\$\\{project.version\\}", "\\$\\{version\\}" ); - } - - List firstPassModelProperties = new ArrayList(); - List secondPassModelProperties = new ArrayList(); - - ModelProperty buildProperty = new ModelProperty( ProjectUri.Build.xUri, null ); - for ( ModelProperty mp : modelProperties ) - { - if ( mp.getValue() != null && !mp.getUri().contains( "#property" ) && !mp.getUri().contains( "#collection" ) ) - { - if ( ( !buildProperty.isParentOf( mp ) && !mp.getUri().equals( ProjectUri.Reporting.outputDirectory ) || mp.getUri().equals( ProjectUri.Build.finalName ) ) ) - { - firstPassModelProperties.add( mp ); - } - else - { - secondPassModelProperties.add( mp ); - } - } - } - - List standardInterpolatorProperties = new ArrayList(); - if ( domainModel.isPomInBuild() ) - { - String basedir = domainModel.getProjectDirectory().getAbsolutePath(); - standardInterpolatorProperties.add( new InterpolatorProperty( "${project.basedir}", basedir, PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); - standardInterpolatorProperties.add( new InterpolatorProperty( "${basedir}", basedir, PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); - standardInterpolatorProperties.add( new InterpolatorProperty( "${pom.basedir}", basedir, PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); - - } - - for ( ModelProperty mp : modelProperties ) - { - if ( mp.getUri().startsWith( ProjectUri.properties ) && mp.getValue() != null ) - { - String uri = mp.getUri(); - standardInterpolatorProperties.add( new InterpolatorProperty( "${" + uri.substring( uri.lastIndexOf( "/" ) + 1, uri.length() ) + "}", mp.getValue(), - PomInterpolatorTag.PROJECT_PROPERTIES.name() ) ); - } - } - - //FIRST PASS - Withhold using build directories as interpolator properties - List ips1 = new ArrayList( interpolatorProperties ); - ips1.addAll( standardInterpolatorProperties ); - ips1.addAll( ModelTransformerContext.createInterpolatorProperties( firstPassModelProperties, ProjectUri.baseUri, aliases, PomInterpolatorTag.PROJECT_PROPERTIES.name(), false, false ) ); - Collections.sort( ips1, new Comparator() - { - public int compare( InterpolatorProperty o, InterpolatorProperty o1 ) - { - return PomInterpolatorTag.valueOf( o.getTag() ).compareTo( PomInterpolatorTag.valueOf( o1.getTag() ) ); - } - } ); - - ModelTransformerContext.interpolateModelProperties( modelProperties, ips1 ); - - //SECOND PASS - Set absolute paths on build directories - if ( domainModel.isPomInBuild() ) - { - String basedir = domainModel.getProjectDirectory().getAbsolutePath(); - Map buildDirectories = new HashMap(); - for ( ModelProperty mp : secondPassModelProperties ) - { - if ( mp.getUri().startsWith( ProjectUri.Build.xUri ) || mp.getUri().equals( ProjectUri.Reporting.outputDirectory ) ) - { - File file = new File(mp.getResolvedValue()); - if( !file.isAbsolute() && !mp.getResolvedValue().startsWith("${project.build.") - && !mp.getResolvedValue().equals("${project.basedir}")) - { - buildDirectories.put( mp, new ModelProperty( mp.getUri(), new File( basedir, file.getPath() ).getAbsolutePath() ) ); - } - } - } - - for ( Map.Entry e : buildDirectories.entrySet() ) - { - secondPassModelProperties.remove( e.getKey() ); - secondPassModelProperties.add( e.getValue() ); - } - } - - //THIRD PASS - Use build directories as interpolator properties - List ips2 = new ArrayList( interpolatorProperties ); - ips2.addAll( standardInterpolatorProperties ); - ips2.addAll( ModelTransformerContext.createInterpolatorProperties( secondPassModelProperties, ProjectUri.baseUri, aliases, PomInterpolatorTag.PROJECT_PROPERTIES.name(), false, false ) ); - ips2.addAll( interpolatorProperties ); - Collections.sort( ips2, new Comparator() - { - public int compare( InterpolatorProperty o, InterpolatorProperty o1 ) - { - return PomInterpolatorTag.valueOf( o.getTag() ).compareTo( PomInterpolatorTag.valueOf( o1.getTag() ) ); - } - } ); - - ModelTransformerContext.interpolateModelProperties( modelProperties, ips2 ); - } - - private static boolean containsProjectVersion( List interpolatorProperties ) - { - InterpolatorProperty versionInterpolatorProperty = new ModelProperty( ProjectUri.version, "" ).asInterpolatorProperty( ProjectUri.baseUri ); - for ( InterpolatorProperty ip : interpolatorProperties ) - { - if ( ip.equals( versionInterpolatorProperty ) ) - { - return true; - } - } - return false; - } } \ No newline at end of file diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/Mixer.java b/maven-project/src/main/java/org/apache/maven/project/builder/Mixer.java deleted file mode 100644 index aeb3e9b589..0000000000 --- a/maven-project/src/main/java/org/apache/maven/project/builder/Mixer.java +++ /dev/null @@ -1,28 +0,0 @@ -package org.apache.maven.project.builder; - -import org.apache.maven.project.MavenProject; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.Model; -import org.apache.maven.shared.model.InterpolatorProperty; -import org.codehaus.plexus.configuration.PlexusConfiguration; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import org.codehaus.plexus.util.xml.Xpp3Dom; - -import java.io.IOException; -import java.util.List; - - -public interface Mixer -{ - - Model mixPlugin(Plugin plugin, Model model) throws IOException; - - PlexusConfiguration mixPluginAndReturnConfig(Plugin plugin, Xpp3Dom dom, Model model, List props) - throws IOException, XmlPullParserException; - - Object mixPluginAndReturnConfigAsDom(Plugin plugin, Model model) throws IOException, - XmlPullParserException; - - Object mixPluginAndReturnConfigAsDom(Plugin plugin, Model model, String xpathExpression) throws IOException, - XmlPullParserException; -} diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/PluginMixin.java b/maven-project/src/main/java/org/apache/maven/project/builder/PluginMixin.java deleted file mode 100644 index bc16dc2339..0000000000 --- a/maven-project/src/main/java/org/apache/maven/project/builder/PluginMixin.java +++ /dev/null @@ -1,116 +0,0 @@ -package org.apache.maven.project.builder; - -import org.apache.maven.shared.model.InputStreamDomainModel; -import org.apache.maven.shared.model.ModelProperty; -import org.apache.maven.shared.model.ModelMarshaller; -import org.apache.maven.model.Plugin; -import org.apache.maven.model.Model; -import org.apache.maven.model.Build; -import org.apache.maven.model.io.xpp3.MavenXpp3Writer; -import org.codehaus.plexus.util.WriterFactory; -import org.codehaus.plexus.util.IOUtil; -import org.codehaus.plexus.util.ReaderFactory; - -import java.io.*; -import java.util.List; -import java.util.Set; -import java.util.HashSet; -import java.util.ArrayList; - - -public class PluginMixin implements InputStreamDomainModel { - - - /** - * Bytes containing the underlying model - */ - private byte[] inputBytes; - - /** - * History of joins and deletes of model properties - */ - private String eventHistory; - - private List modelProperties; - - public PluginMixin(Plugin plugin) - throws IOException - { - if(plugin == null) - { - throw new IllegalArgumentException("plugin: null"); - } - Model model = new Model(); - Build build = new Build(); - build.addPlugin(plugin); - model.setBuild(build); - ByteArrayOutputStream baos = new ByteArrayOutputStream(); - Writer out = null; - MavenXpp3Writer writer = new MavenXpp3Writer(); - try - { - out = WriterFactory.newXmlWriter( baos ); - writer.write( out, model ); - } - finally - { - if ( out != null ) - { - out.close(); - } - } - inputBytes = baos.toByteArray(); - } - - public InputStream getInputStream() { - byte[] copy = new byte[inputBytes.length]; - System.arraycopy( inputBytes, 0, copy, 0, inputBytes.length ); - return new ByteArrayInputStream( copy ); - } - - public List getModelProperties() throws IOException { - if(modelProperties == null) - { - Set s = new HashSet(); - //TODO: Should add all collections from ProjectUri - s.addAll(PomTransformer.URIS); - s.add(ProjectUri.Build.PluginManagement.Plugins.Plugin.Executions.xUri); - s.add(ProjectUri.DependencyManagement.Dependencies.Dependency.Exclusions.xUri); - s.add(ProjectUri.Dependencies.Dependency.Exclusions.xUri); - s.add(ProjectUri.Build.Plugins.Plugin.Executions.xUri); - s.add(ProjectUri.Build.Plugins.Plugin.Executions.Execution.Goals.xURI); - s.add(ProjectUri.Reporting.Plugins.Plugin.ReportSets.xUri); - s.add(ProjectUri.Reporting.Plugins.Plugin.ReportSets.ReportSet.configuration); - s.add(ProjectUri.Build.Plugins.Plugin.Executions.Execution.configuration); - modelProperties = ModelMarshaller.marshallXmlToModelProperties( - getInputStream(), ProjectUri.baseUri, s ); - } - return new ArrayList(modelProperties); - } - - public String getEventHistory() { - return eventHistory; - } - - public void setEventHistory(String eventHistory) { - this.eventHistory = eventHistory; - } - - /** - * Returns XML model as string - * - * @return XML model as string - */ - public String asString() - { - try - { - return IOUtil.toString( ReaderFactory.newXmlReader( new ByteArrayInputStream( inputBytes ) ) ); - } - catch ( IOException ioe ) - { - // should not occur: everything is in-memory - return ""; - } - } -} diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java index ac70323be5..5d4d356476 100644 --- a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java +++ b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModel.java @@ -47,7 +47,7 @@ import java.util.HashSet; * Provides a wrapper for the maven model. */ public final class PomClassicDomainModel - implements InputStreamDomainModel + implements IPomClassicDomainModel { /** @@ -80,6 +80,11 @@ public final class PomClassicDomainModel public PomClassicDomainModel( List modelProperties) { this.modelProperties = modelProperties; + try { + inputBytes = IOUtil.toByteArray( ModelMarshaller.unmarshalModelPropertiesToXml(modelProperties, ProjectUri.baseUri)); + } catch (IOException e) { + + } } /** * Constructor @@ -265,7 +270,8 @@ public final class PomClassicDomainModel } try { - return new MavenXpp3Reader().read( ReaderFactory.newXmlReader( new ByteArrayInputStream( inputBytes ) ) ); + model = new MavenXpp3Reader().read( ReaderFactory.newXmlReader( new ByteArrayInputStream( inputBytes ) ) ); + return model; } catch ( XmlPullParserException e ) { diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModelFactory.java b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModelFactory.java index b87688c40d..49e0caf37a 100644 --- a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModelFactory.java +++ b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicDomainModelFactory.java @@ -15,15 +15,6 @@ public class PomClassicDomainModelFactory implements DomainModelFactory { public DomainModel createDomainModel(List modelProperties) throws IOException { - String xml = null; - try - { - xml = ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri ); - return new PomClassicDomainModel( new MavenXpp3Reader().read( new StringReader( xml ) ) ); - } - catch ( XmlPullParserException e ) - { - throw new IOException( e + ":\r\n" + xml ); - } + return new PomClassicDomainModel(modelProperties); } } diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java b/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java deleted file mode 100644 index 7c3c63103b..0000000000 --- a/maven-project/src/main/java/org/apache/maven/project/builder/PomClassicTransformer.java +++ /dev/null @@ -1,53 +0,0 @@ -package org.apache.maven.project.builder; - -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ - -import java.io.IOException; -import java.util.List; - -import org.apache.maven.shared.model.DomainModel; -import org.apache.maven.shared.model.DomainModelFactory; -import org.apache.maven.shared.model.InterpolatorProperty; -import org.apache.maven.shared.model.ModelProperty; - -/** - * Provides methods for transforming model properties into a domain model for the pom classic format and vice versa. - */ -public final class PomClassicTransformer - extends PomTransformer -{ - - public PomClassicTransformer(DomainModelFactory factory) - { - super(factory); - } - - public void interpolateModelProperties(List modelProperties, - List interpolatorProperties, - DomainModel domainModel) - throws IOException - { - if(! ( domainModel instanceof PomClassicDomainModel ) ) - { - return; - } - Interpolator.interpolateModelProperties( modelProperties, interpolatorProperties, (PomClassicDomainModel) domainModel); - } -} diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java index b8e99244ad..3f059a42f3 100644 --- a/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/builder/ProjectBuilder.java @@ -35,10 +35,10 @@ import org.apache.maven.shared.model.InterpolatorProperty; */ public interface ProjectBuilder { - public PomClassicDomainModel buildModel( File pom, + public IPomClassicDomainModel buildModel( File pom, Collection interpolatorProperties, - PomArtifactResolver resolver ) - throws IOException; + PomArtifactResolver resolver ) + throws IOException; /** * Returns a maven project for the specified input stream. diff --git a/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java b/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java index 57fc7f67f4..1b2dc766d1 100644 --- a/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java +++ b/maven-project/src/main/java/org/apache/maven/project/builder/impl/DefaultProjectBuilder.java @@ -22,7 +22,6 @@ package org.apache.maven.project.builder.impl; import java.io.File; import java.io.IOException; import java.io.Reader; -import java.io.StringReader; import java.util.*; import org.apache.maven.MavenTools; @@ -38,7 +37,6 @@ 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.model.Plugin; import org.apache.maven.model.io.xpp3.MavenXpp3Reader; import org.apache.maven.project.MavenProject; import org.apache.maven.project.ProjectBuilderConfiguration; @@ -54,20 +52,13 @@ import org.codehaus.plexus.logging.LogEnabled; import org.codehaus.plexus.logging.Logger; import org.codehaus.plexus.util.IOUtil; import org.codehaus.plexus.util.ReaderFactory; -import org.codehaus.plexus.util.xml.Xpp3DomBuilder; -import org.codehaus.plexus.util.xml.Xpp3Dom; -import org.codehaus.plexus.util.xml.pull.XmlPullParserException; -import org.codehaus.plexus.configuration.PlexusConfiguration; -import org.codehaus.plexus.configuration.xml.XmlPlexusConfiguration; -import org.apache.maven.shared.model.ModelMarshaller; -import org.apache.commons.jxpath.JXPathContext; /** * Default implementation of the project builder. */ @Component(role = ProjectBuilder.class) public class DefaultProjectBuilder - implements ProjectBuilder, Mixer, PomProcessor, LogEnabled + implements ProjectBuilder, PomProcessor, LogEnabled { @Requirement private ArtifactFactory artifactFactory; @@ -166,7 +157,7 @@ public class DefaultProjectBuilder return buildModel( pom, null, interpolatorProperties, null, null, resolver ); } - private PomClassicDomainModel buildModel( File pom, + private PomClassicDomainModel buildModel(File pom, List mixins, Collection interpolatorProperties, Collection activeProfileIds, Collection inactiveProfileIds, @@ -274,7 +265,7 @@ public class DefaultProjectBuilder domainModels.add( new PomClassicDomainModel( model ) ); } - PomClassicTransformer transformer = new PomClassicTransformer( new PomClassicDomainModelFactory() ); + PomTransformer transformer = new PomTransformer( new PomClassicDomainModelFactory() ); ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_INFOS ); @@ -561,124 +552,6 @@ public class DefaultProjectBuilder return superModel; } - public Model mixPlugin(Plugin plugin, Model model) throws IOException - { - //TODO - interpolation - List domainModels = new ArrayList(); - domainModels.add( new PomClassicDomainModel(model) ); - domainModels.add( new PluginMixin(plugin) ); - - PomClassicTransformer transformer = new PomClassicTransformer( new PomClassicDomainModelFactory() ); - - ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_INFOS ); - - PomClassicDomainModel transformedDomainModel = ( (PomClassicDomainModel) ctx.transform( domainModels, - transformer, - transformer, - Collections.EMPTY_LIST, - null, - listeners ) ); - return transformedDomainModel.getModel(); - - } - - public PlexusConfiguration mixPluginAndReturnConfig(Plugin plugin, Xpp3Dom dom, Model model, List props) - throws IOException, XmlPullParserException - { - List mps = mixPluginAndReturnConfigAsProperties(plugin, dom, model, null); - - return !mps.isEmpty() ? - new XmlPlexusConfiguration(Xpp3DomBuilder.build( - new StringReader(ModelMarshaller.unmarshalModelPropertiesToXml(mps, ProjectUri.Build.Plugins.Plugin.xUri))) ) : null; - } - - public Object mixPluginAndReturnConfigAsDom(Plugin plugin, Model model) throws IOException, XmlPullParserException - { - List mps = mixPluginAndReturnConfigAsProperties(plugin, null, model, null); - return !mps.isEmpty() ? Xpp3DomBuilder.build( - new StringReader(ModelMarshaller.unmarshalModelPropertiesToXml(mps, ProjectUri.Build.Plugins.Plugin.xUri) ) ) : null; - } - - public Object mixPluginAndReturnConfigAsDom(Plugin plugin, Model model, String xpathExpression) throws IOException, - XmlPullParserException - { - Object dom = mixPluginAndReturnConfigAsDom(plugin, model); - if(dom == null) - { - return null; - } - return JXPathContext.newContext( dom ).getValue(xpathExpression); - } - - private List mixPluginAndReturnConfigAsProperties(Plugin plugin, Xpp3Dom dom, Model model, - List props) throws IOException - { - List domainModels = new ArrayList(); - domainModels.add(new PomClassicDomainModel(model)); - domainModels.add(new PluginMixin(plugin)); - - if (dom != null) - { - Plugin p = new Plugin(); - p.setGroupId(plugin.getGroupId()); - p.setArtifactId(plugin.getArtifactId()); - p.setVersion(p.getVersion()); - p.setConfiguration(dom); - domainModels.add(new PluginMixin(p)); - } - - PomClassicTransformer transformer = new PomClassicTransformer( new PomClassicDomainModelFactory() ); - - ModelTransformerContext ctx = new ModelTransformerContext(PomTransformer.MODEL_CONTAINER_INFOS ); - - PomClassicDomainModel transformedDomainModel = ( (PomClassicDomainModel) ctx.transform( domainModels, - transformer, - transformer, - Collections.EMPTY_LIST, - props, - listeners ) ); - ModelDataSource source = - new DefaultModelDataSource(transformedDomainModel.getModelProperties(), PomTransformer.MODEL_CONTAINER_FACTORIES); - for(ModelContainer pluginContainer : source.queryFor(ProjectUri.Build.Plugins.Plugin.xUri)) - { - if(matchesIdOfPlugin(pluginContainer, plugin)) - { - List config = new ArrayList(); - for(ModelProperty mp : pluginContainer.getProperties()) - { - if(mp.getUri().startsWith(ProjectUri.Build.Plugins.Plugin.configuration)) - { - config.add(mp); - } - } - return config; - - } - } - return new ArrayList(); - } - - private static boolean matchesIdOfPlugin(ModelContainer mc, Plugin plugin) - { - List props = mc.getProperties(); - - return //getValueByUri(ProjectUri.Build.Plugins.Plugin.groupId, props).equals(plugin.getGroupId()) - getValueByUri(ProjectUri.Build.Plugins.Plugin.artifactId, props).equals(plugin.getArtifactId()) - && getValueByUri(ProjectUri.Build.Plugins.Plugin.version, props).equals(plugin.getVersion()); - } - - private static String getValueByUri(String uri, List modelProperties) - { - for(ModelProperty mp : modelProperties) - { - if(mp.getUri().equals(uri)) - { - return mp.getResolvedValue(); - } - } - return ""; - } - private static List getParentsOfDomainModel( MavenDomainModel domainModel, MetadataReader mdReader ) throws IOException, MetadataReaderException, PomProcessorException { diff --git a/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java b/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java index 87a9333bfa..39d026bfaa 100644 --- a/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java +++ b/maven-project/src/test/java/org/apache/maven/project/builder/PomConstructionTest.java @@ -55,8 +55,6 @@ public class PomConstructionTest private MavenProjectBuilder mavenProjectBuilder; - private Mixer mixer; - private MavenTools mavenTools; private PomArtifactResolver pomArtifactResolver; @@ -72,7 +70,6 @@ public class PomConstructionTest testMixinDirectory = new File( getBasedir(), BASE_MIXIN_DIR ); mavenProjectBuilder = lookup( MavenProjectBuilder.class ); projectBuilder = lookup( ProjectBuilder.class ); - mixer = (Mixer) projectBuilder; mavenTools = lookup( MavenTools.class ); pomArtifactResolver = new PomArtifactResolver() { @@ -102,17 +99,6 @@ public class PomConstructionTest assertEquals( "my.property", pom.getValue( "build/plugins[1]/configuration[1]/systemProperties[1]/property[1]/name" ) ); } - public void testPluginMergeSimple() - throws Exception - { - Model model = buildPom( "plugin-merge-simple" ).getDomainModel().getModel(); - Model plugin = buildMixin("plugins/simple"); - - model = mixer.mixPlugin((Plugin) plugin.getBuild().getPlugins().get(0), model); - - PomTestWrapper pom = new PomTestWrapper( model ); - assertEquals( "FAILED", pom.getValue( "build/plugins[1]/configuration[1]/propertiesFile" ) ); - } // Some better conventions for the test poms needs to be created and each of these tests // that represent a verification of a specification item needs to be a couple lines at most. @@ -126,10 +112,10 @@ public class PomConstructionTest { File pom = new File( testDirectory, "micromailer/micromailer-1.0.3.pom" ); PomArtifactResolver resolver = artifactResolver( "micromailer" ); - PomClassicDomainModel model = projectBuilder.buildModel( pom, null, resolver ); + IPomClassicDomainModel model = projectBuilder.buildModel( pom, null, resolver ); // This should be 2 //assertEquals( 2, model.getLineageCount() ); - PomTestWrapper tester = new PomTestWrapper( model ); + PomTestWrapper tester = new PomTestWrapper( (PomClassicDomainModel) model ); assertModelEquals( tester, "child-descriptor", "build/plugins[1]/executions[1]/goals[1]" ); } @@ -873,7 +859,7 @@ public class PomConstructionTest { pomFile = new File( pomFile, "pom.xml" ); } - return new PomTestWrapper( pomFile, projectBuilder.buildModel( pomFile, null, pomArtifactResolver ) ); + return new PomTestWrapper( pomFile, (PomClassicDomainModel) projectBuilder.buildModel( pomFile, null, pomArtifactResolver ) ); } private PomTestWrapper buildPomFromMavenProject( String pomPath, String profileId ) diff --git a/maven-project/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java b/maven-project/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java index 7880a554c9..ec39d1731b 100644 --- a/maven-project/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java +++ b/maven-project/src/test/java/org/apache/maven/project/harness/PomTestWrapper.java @@ -30,6 +30,7 @@ import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl; import org.apache.maven.model.Model; import org.apache.maven.project.builder.PomClassicDomainModel; +import org.apache.maven.project.builder.IPomClassicDomainModel; import org.apache.maven.project.MavenProject; import org.apache.maven.shared.model.ModelProperty;