mirror of https://github.com/apache/maven.git
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
This commit is contained in:
parent
c53466f406
commit
73c0f41e3b
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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()
|
||||
|
|
|
@ -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();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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();
|
||||
}
|
|
@ -1,4 +1,6 @@
|
|||
package org.apache.maven.project.builder;
|
||||
|
||||
public class PluginBuilderTest {
|
||||
public interface IProjectBuilder
|
||||
{
|
||||
|
||||
}
|
|
@ -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<ModelContainer> 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<ModelProperty> removeProperties = new HashSet<ModelProperty>();
|
||||
|
||||
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<TransformerRule> transformerRules = Arrays.asList(new MissingVersionTransformerRule(),
|
||||
new DefaultDependencyScopeTransformerRule());
|
||||
|
||||
List<TransformerRemovalRule> transformerRemovalRules = Arrays.asList(new DefaultExecutionIdTransformerRule(),
|
||||
new ModulesNotInheritedTransformerRule());
|
||||
|
||||
/**
|
||||
* @see ModelTransformer#transformToModelProperties(java.util.List)
|
||||
|
@ -528,63 +537,19 @@ public class PomTransformer
|
|||
List<ModelProperty> tmp = domainModel.getModelProperties();
|
||||
|
||||
List clearedProperties = new ArrayList<ModelProperty>();
|
||||
|
||||
//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<ModelProperty> replace = new ArrayList<ModelProperty>();
|
||||
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<ModelProperty> removedProperties = new ArrayList<ModelProperty>();
|
||||
List<String> filters = new ArrayList<String>();
|
||||
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<ModelContainer> reportContainers = source.queryFor( ProjectUri.Reporting.Plugins.Plugin.xUri );
|
||||
|
@ -797,61 +763,96 @@ public class PomTransformer
|
|||
* @param domainModel
|
||||
* @throws IOException
|
||||
*/
|
||||
public void interpolateModelProperties(List<ModelProperty> modelProperties,
|
||||
List<InterpolatorProperty> interpolatorProperties,
|
||||
DomainModel domainModel)
|
||||
throws IOException
|
||||
private static final Map<String, String> aliases = new HashMap<String, String>();
|
||||
|
||||
private static void addProjectAlias( String element, boolean leaf )
|
||||
{
|
||||
String suffix = leaf ? "\\}" : "\\.";
|
||||
aliases.put( "\\$\\{project\\." + element + suffix, "\\$\\{" + element + suffix );
|
||||
}
|
||||
|
||||
Map<String, String> aliases = new HashMap<String, String>();
|
||||
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<ModelProperty> modelProperties,
|
||||
List<InterpolatorProperty> interpolatorProperties,
|
||||
DomainModel domainModel )
|
||||
throws IOException
|
||||
{
|
||||
IPomClassicDomainModel dm = (IPomClassicDomainModel) domainModel;
|
||||
|
||||
if ( !containsProjectVersion( interpolatorProperties ) )
|
||||
{
|
||||
aliases.put("\\$\\{project.version\\}", "\\$\\{version\\}");
|
||||
aliases.put( "\\$\\{project.version\\}", "\\$\\{version\\}" );
|
||||
}
|
||||
|
||||
List<ModelProperty> firstPassModelProperties = new ArrayList<ModelProperty>();
|
||||
List<ModelProperty> secondPassModelProperties = new ArrayList<ModelProperty>();
|
||||
|
||||
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<InterpolatorProperty> standardInterpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
|
||||
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<InterpolatorProperty> ips1 = new ArrayList<InterpolatorProperty>(interpolatorProperties);
|
||||
ips1.addAll(standardInterpolatorProperties);
|
||||
ips1.addAll(ModelTransformerContext.createInterpolatorProperties(firstPassModelProperties, ProjectUri.baseUri, aliases,
|
||||
PomInterpolatorTag.PROJECT_PROPERTIES.name(), false, false));
|
||||
Collections.sort(ips1, new Comparator<InterpolatorProperty>()
|
||||
List<InterpolatorProperty> ips1 = new ArrayList<InterpolatorProperty>( interpolatorProperties );
|
||||
ips1.addAll( standardInterpolatorProperties );
|
||||
ips1.addAll( ModelTransformerContext.createInterpolatorProperties( firstPassModelProperties, ProjectUri.baseUri, aliases, PomInterpolatorTag.PROJECT_PROPERTIES.name(), false, false ) );
|
||||
Collections.sort( ips1, new Comparator<InterpolatorProperty>()
|
||||
{
|
||||
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<ModelProperty, ModelProperty> buildDirectories = new HashMap<ModelProperty, ModelProperty>();
|
||||
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<ModelProperty, ModelProperty> e : buildDirectories.entrySet() )
|
||||
{
|
||||
secondPassModelProperties.remove( e.getKey() );
|
||||
secondPassModelProperties.add( e.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
//THIRD PASS - Use build directories as interpolator properties
|
||||
List<InterpolatorProperty> ips2 = new ArrayList<InterpolatorProperty>( 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<InterpolatorProperty>()
|
||||
{
|
||||
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<ModelProperty> getPropertiesFor( String uri, List<ModelProperty> properties )
|
||||
public static List<ModelProperty> getPropertiesFor( String uri, List<ModelProperty> properties )
|
||||
{
|
||||
List<ModelProperty> modelProperties = new ArrayList<ModelProperty>();
|
||||
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<ModelProperty> properties )
|
||||
public static ModelProperty getPropertyFor( String uri, List<ModelProperty> properties )
|
||||
{
|
||||
for ( ModelProperty mp : properties )
|
||||
{
|
||||
|
|
|
@ -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<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, int domainIndex)
|
||||
throws DataSourceException;
|
||||
}
|
|
@ -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<ModelProperty> modelProperties, int domainIndex) throws DataSourceException;
|
||||
|
||||
}
|
|
@ -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.*;
|
||||
|
|
@ -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;
|
|
@ -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.*;
|
||||
|
|
@ -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;
|
|
@ -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.*;
|
||||
|
|
@ -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.*;
|
||||
|
|
@ -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<ModelProperty> 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"));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> modelProperties, int domainIndex)
|
||||
throws DataSourceException
|
||||
{
|
||||
List<ModelProperty> replace = new ArrayList<ModelProperty>();
|
||||
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;
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
||||
|
|
|
@ -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<ModelProperty> modelProperties, int domainIndex) throws DataSourceException
|
||||
{
|
||||
|
||||
}
|
||||
}
|
|
@ -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<ModelProperty> 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() ) );
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<ModelProperty> executeWithReturnPropertiesToRemove(List<ModelProperty> 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<ModelProperty>();//todo: fix
|
||||
}
|
||||
}
|
|
@ -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<ModelProperty> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
|
Binary file not shown.
|
@ -43,169 +43,4 @@ public class Interpolator
|
|||
ModelTransformerContext.interpolateModelProperties( modelProperties, ips );
|
||||
return ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri );
|
||||
}
|
||||
|
||||
private static String interpolateModelAsString( Model model, List<InterpolatorProperty> interpolatorProperties, File projectDirectory )
|
||||
throws IOException
|
||||
{
|
||||
PomClassicDomainModel domainModel = new PomClassicDomainModel( model );
|
||||
domainModel.setProjectDirectory( projectDirectory );
|
||||
List<ModelProperty> 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<InterpolatorProperty> 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<String, String> aliases = new HashMap<String, String>();
|
||||
|
||||
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<ModelProperty> modelProperties, List<InterpolatorProperty> interpolatorProperties, PomClassicDomainModel domainModel )
|
||||
throws IOException
|
||||
{
|
||||
if ( !containsProjectVersion( interpolatorProperties ) )
|
||||
{
|
||||
aliases.put( "\\$\\{project.version\\}", "\\$\\{version\\}" );
|
||||
}
|
||||
|
||||
List<ModelProperty> firstPassModelProperties = new ArrayList<ModelProperty>();
|
||||
List<ModelProperty> secondPassModelProperties = new ArrayList<ModelProperty>();
|
||||
|
||||
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<InterpolatorProperty> standardInterpolatorProperties = new ArrayList<InterpolatorProperty>();
|
||||
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<InterpolatorProperty> ips1 = new ArrayList<InterpolatorProperty>( interpolatorProperties );
|
||||
ips1.addAll( standardInterpolatorProperties );
|
||||
ips1.addAll( ModelTransformerContext.createInterpolatorProperties( firstPassModelProperties, ProjectUri.baseUri, aliases, PomInterpolatorTag.PROJECT_PROPERTIES.name(), false, false ) );
|
||||
Collections.sort( ips1, new Comparator<InterpolatorProperty>()
|
||||
{
|
||||
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<ModelProperty, ModelProperty> buildDirectories = new HashMap<ModelProperty, ModelProperty>();
|
||||
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<ModelProperty, ModelProperty> e : buildDirectories.entrySet() )
|
||||
{
|
||||
secondPassModelProperties.remove( e.getKey() );
|
||||
secondPassModelProperties.add( e.getValue() );
|
||||
}
|
||||
}
|
||||
|
||||
//THIRD PASS - Use build directories as interpolator properties
|
||||
List<InterpolatorProperty> ips2 = new ArrayList<InterpolatorProperty>( 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<InterpolatorProperty>()
|
||||
{
|
||||
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<InterpolatorProperty> interpolatorProperties )
|
||||
{
|
||||
InterpolatorProperty versionInterpolatorProperty = new ModelProperty( ProjectUri.version, "" ).asInterpolatorProperty( ProjectUri.baseUri );
|
||||
for ( InterpolatorProperty ip : interpolatorProperties )
|
||||
{
|
||||
if ( ip.equals( versionInterpolatorProperty ) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -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<InterpolatorProperty> props)
|
||||
throws IOException, XmlPullParserException;
|
||||
|
||||
Object mixPluginAndReturnConfigAsDom(Plugin plugin, Model model) throws IOException,
|
||||
XmlPullParserException;
|
||||
|
||||
Object mixPluginAndReturnConfigAsDom(Plugin plugin, Model model, String xpathExpression) throws IOException,
|
||||
XmlPullParserException;
|
||||
}
|
|
@ -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<ModelProperty> 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<ModelProperty> getModelProperties() throws IOException {
|
||||
if(modelProperties == null)
|
||||
{
|
||||
Set<String> s = new HashSet<String>();
|
||||
//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<ModelProperty>(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 "";
|
||||
}
|
||||
}
|
||||
}
|
|
@ -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<ModelProperty> 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 )
|
||||
{
|
||||
|
|
|
@ -15,15 +15,6 @@ public class PomClassicDomainModelFactory implements DomainModelFactory
|
|||
{
|
||||
public DomainModel createDomainModel(List<ModelProperty> 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);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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<ModelProperty> modelProperties,
|
||||
List<InterpolatorProperty> interpolatorProperties,
|
||||
DomainModel domainModel)
|
||||
throws IOException
|
||||
{
|
||||
if(! ( domainModel instanceof PomClassicDomainModel ) )
|
||||
{
|
||||
return;
|
||||
}
|
||||
Interpolator.interpolateModelProperties( modelProperties, interpolatorProperties, (PomClassicDomainModel) domainModel);
|
||||
}
|
||||
}
|
|
@ -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<InterpolatorProperty> interpolatorProperties,
|
||||
PomArtifactResolver resolver )
|
||||
throws IOException;
|
||||
PomArtifactResolver resolver )
|
||||
throws IOException;
|
||||
|
||||
/**
|
||||
* Returns a maven project for the specified input stream.
|
||||
|
|
|
@ -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<Model> mixins,
|
||||
Collection<InterpolatorProperty> interpolatorProperties,
|
||||
Collection<String> activeProfileIds, Collection<String> 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<DomainModel> domainModels = new ArrayList<DomainModel>();
|
||||
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<InterpolatorProperty> props)
|
||||
throws IOException, XmlPullParserException
|
||||
{
|
||||
List<ModelProperty> 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<ModelProperty> 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<ModelProperty> mixPluginAndReturnConfigAsProperties(Plugin plugin, Xpp3Dom dom, Model model,
|
||||
List<InterpolatorProperty> props) throws IOException
|
||||
{
|
||||
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
||||
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<ModelProperty> config = new ArrayList<ModelProperty>();
|
||||
for(ModelProperty mp : pluginContainer.getProperties())
|
||||
{
|
||||
if(mp.getUri().startsWith(ProjectUri.Build.Plugins.Plugin.configuration))
|
||||
{
|
||||
config.add(mp);
|
||||
}
|
||||
}
|
||||
return config;
|
||||
|
||||
}
|
||||
}
|
||||
return new ArrayList<ModelProperty>();
|
||||
}
|
||||
|
||||
private static boolean matchesIdOfPlugin(ModelContainer mc, Plugin plugin)
|
||||
{
|
||||
List<ModelProperty> 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<ModelProperty> modelProperties)
|
||||
{
|
||||
for(ModelProperty mp : modelProperties)
|
||||
{
|
||||
if(mp.getUri().equals(uri))
|
||||
{
|
||||
return mp.getResolvedValue();
|
||||
}
|
||||
}
|
||||
return "";
|
||||
}
|
||||
|
||||
private static List<DomainModel> getParentsOfDomainModel( MavenDomainModel domainModel, MetadataReader mdReader )
|
||||
throws IOException, MetadataReaderException, PomProcessorException
|
||||
{
|
||||
|
|
|
@ -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 )
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
|
Loading…
Reference in New Issue