Refactored out more uses of modello and moved classes from maven-project to maven-project-builder. Doing this so that maven-mercury will not have direct dependency on modello or maven model.

git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@746002 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Britton Isbell 2009-02-19 21:22:46 +00:00
parent 45b99d20cf
commit c327c94443
23 changed files with 307 additions and 362 deletions

View File

@ -21,6 +21,7 @@ package org.apache.maven.plugin;
import java.io.IOException;
import java.io.StringReader;
import java.io.ByteArrayInputStream;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -65,20 +66,19 @@ import org.apache.maven.plugin.descriptor.PluginDescriptorBuilder;
import org.apache.maven.plugin.version.PluginVersionManager;
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
import org.apache.maven.plugin.version.PluginVersionResolutionException;
import org.apache.maven.project.DuplicateArtifactAttachmentException;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuildingException;
import org.apache.maven.project.*;
import org.apache.maven.project.builder.*;
import org.apache.maven.project.ProjectBuilder;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
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.path.PathTranslator;
import org.apache.maven.realm.MavenRealmManager;
import org.apache.maven.realm.RealmManagementException;
import org.apache.maven.reporting.MavenReport;
import org.apache.maven.shared.model.InterpolatorProperty;
import org.apache.maven.shared.model.ModelProperty;
import org.apache.maven.shared.model.ModelMarshaller;
import org.apache.maven.shared.model.ModelTransformerContext;
import org.codehaus.plexus.PlexusContainer;
import org.codehaus.plexus.classworlds.realm.ClassRealm;
import org.codehaus.plexus.component.annotations.Component;
@ -575,7 +575,7 @@ public class DefaultPluginManager
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getUserProperties(),
PomInterpolatorTag.USER_PROPERTIES.name()));
String interpolatedDom =
Interpolator.interpolateXmlString( String.valueOf( dom ), interpolatorProperties );
interpolateXmlString( String.valueOf( dom ), interpolatorProperties );
dom = Xpp3DomBuilder.build( new StringReader( interpolatedDom ) );
}
catch ( XmlPullParserException e )
@ -1685,4 +1685,28 @@ public class DefaultPluginManager
}
}
}
private static String interpolateXmlString( String xml, List<InterpolatorProperty> interpolatorProperties )
throws IOException
{
List<ModelProperty> modelProperties = ModelMarshaller.marshallXmlToModelProperties( new ByteArrayInputStream( xml.getBytes() ), ProjectUri.baseUri, PomTransformer.URIS );
Map<String, String> aliases = new HashMap<String, String>();
aliases.put( "project.", "pom." );
List<InterpolatorProperty> ips = new ArrayList<InterpolatorProperty>( interpolatorProperties );
ips.addAll( ModelTransformerContext.createInterpolatorProperties( modelProperties, ProjectUri.baseUri, aliases, PomInterpolatorTag.PROJECT_PROPERTIES.name(), false, false ) );
for ( ModelProperty mp : modelProperties )
{
if ( mp.getUri().startsWith( ProjectUri.properties ) && mp.getValue() != null )
{
String uri = mp.getUri();
ips.add( new InterpolatorProperty( "${" + uri.substring( uri.lastIndexOf( "/" ) + 1, uri.length() ) + "}", mp.getValue() ) );
}
}
ModelTransformerContext.interpolateModelProperties( modelProperties, ips );
return ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri );
}
}

View File

@ -62,7 +62,6 @@ import org.apache.maven.project.MavenProject;
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.plugin.PluginRepository;
import org.apache.maven.reactor.MavenExecutionException;
import org.apache.maven.reactor.MissingModuleException;

View File

@ -26,6 +26,10 @@
<groupId>org.sonatype.spice</groupId>
<artifactId>model-builder</artifactId>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-utils</artifactId>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>

View File

@ -1,12 +0,0 @@
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();
}

View File

@ -1,6 +0,0 @@
package org.apache.maven.project.builder;
public interface IProjectBuilder
{
}

View File

@ -19,25 +19,17 @@ package org.apache.maven.project.builder;
* under the License.
*/
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
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.shared.model.InputStreamDomainModel;
import org.codehaus.plexus.util.IOUtil;
import org.codehaus.plexus.util.ReaderFactory;
import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.Writer;
import java.util.List;
import java.util.ArrayList;
import java.util.Set;
@ -46,8 +38,7 @@ import java.util.HashSet;
/**
* Provides a wrapper for the maven model.
*/
public final class PomClassicDomainModel
implements IPomClassicDomainModel
public class PomClassicDomainModel implements InputStreamDomainModel
{
/**
@ -60,11 +51,6 @@ public final class PomClassicDomainModel
*/
private String eventHistory;
/**
* Maven model
*/
private Model model;
private String id;
private File file;
@ -77,44 +63,18 @@ public final class PomClassicDomainModel
private int lineageCount;
public PomClassicDomainModel( List<ModelProperty> modelProperties)
private String parentGroupId = null, parentArtifactId = null, parentVersion = null, parentId = null, parentRelativePath;
public PomClassicDomainModel( List<ModelProperty> modelProperties )
{
this.modelProperties = modelProperties;
try {
inputBytes = IOUtil.toByteArray( ModelMarshaller.unmarshalModelPropertiesToXml(modelProperties, ProjectUri.baseUri));
} catch (IOException e) {
}
}
/**
* Constructor
*
* @param model maven model
* @throws IOException if there is a problem constructing the model
*/
public PomClassicDomainModel( Model model )
throws IOException
{
if ( model == null )
{
throw new IllegalArgumentException( "model: null" );
}
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();
initializeProperties( modelProperties );
}
/**
@ -131,6 +91,76 @@ public final class PomClassicDomainModel
throw new IllegalArgumentException( "inputStream: null" );
}
this.inputBytes = IOUtil.toByteArray( inputStream );
modelProperties = getModelProperties();
initializeProperties( modelProperties );
}
private void initializeProperties(List<ModelProperty> modelProperties)
{
String groupId = null, artifactId = null, version = null;
for(ModelProperty mp : modelProperties)
{
if(mp.getUri().equals(ProjectUri.groupId))
{
groupId = mp.getResolvedValue();
}
else if(mp.getUri().equals(ProjectUri.artifactId))
{
artifactId = mp.getResolvedValue();
}
else if(mp.getUri().equals(ProjectUri.version))
{
version = mp.getResolvedValue();
}
else if(mp.getUri().equals(ProjectUri.Parent.artifactId))
{
parentArtifactId = mp.getResolvedValue();
}
else if(mp.getUri().equals(ProjectUri.Parent.groupId))
{
parentGroupId = mp.getResolvedValue();
}
else if(mp.getUri().equals(ProjectUri.Parent.version))
{
parentVersion = mp.getResolvedValue();
}
else if(mp.getUri().equals(ProjectUri.Parent.relativePath))
{
parentRelativePath = mp.getResolvedValue();
}
if(groupId != null && artifactId != null && version != null && parentGroupId != null &&
parentArtifactId != null && parentVersion != null & parentRelativePath != null)
{
break;
}
}
if( groupId == null && parentGroupId != null)
{
groupId = parentGroupId;
}
if( artifactId == null && parentArtifactId != null)
{
artifactId = parentArtifactId;
}
if( version == null && parentVersion != null )
{
version = parentVersion;
}
if(parentGroupId != null && parentArtifactId != null && parentVersion != null)
{
parentId = parentGroupId + ":" + parentArtifactId + ":" + parentVersion;
}
if(parentRelativePath == null)
{
parentRelativePath = ".." + File.separator + "pom.xml";
}
id = groupId + ":" + artifactId + ":" + version;
}
public PomClassicDomainModel( File file )
@ -149,7 +179,19 @@ public final class PomClassicDomainModel
{
this.parentFile = parentFile;
}
public String getParentGroupId() {
return parentGroupId;
}
public String getParentArtifactId() {
return parentArtifactId;
}
public String getParentVersion() {
return parentVersion;
}
/**
* This should only be set for projects that are in the build. Setting for poms in the repo may cause unstable behavior.
*
@ -170,72 +212,30 @@ public final class PomClassicDomainModel
return projectDirectory != null;
}
/**
* Returns true if groupId.equals(a.groupId) && artifactId.equals(a.artifactId) && version.equals(a.version),
* otherwise returns false.
*
* @param a model to compare
* @return true if groupId.equals(a.groupId) && artifactId.equals(a.artifactId) && version.equals(a.version),
* otherwise returns false.
*/
public boolean matchesModel( Model a )
public String getParentId() throws IOException
{
if ( a == null )
{
throw new IllegalArgumentException( "a: null" );
}
if ( model == null )
{
try
{
model = getModel();
}
catch ( IOException e )
{
return false;
}
}
return a.getId().equals( this.getId() );
return parentId;
}
public String getId()
public String getRelativePathOfParent()
{
if ( id == null )
{
if ( model == null )
{
try
{
model = getModel();
}
catch ( IOException e )
{
return "";
}
}
String groupId = ( model.getGroupId() == null && model.getParent() != null )
? model.getParent().getGroupId()
: model.getGroupId();
String artifactId = ( model.getArtifactId() == null && model.getParent() != null )
? model.getParent().getArtifactId()
: model.getArtifactId();
String version = ( model.getVersion() == null && model.getParent() != null )
? model.getParent().getVersion()
: model.getVersion();
return parentRelativePath;
}
id = groupId + ":" + artifactId + ":" + version;
}
public String getId() throws IOException
{
return id;
}
public boolean matchesParent( Parent parent )
public boolean matchesParentOf( PomClassicDomainModel domainModel ) throws IOException
{
if ( parent == null )
if ( domainModel == null )
{
throw new IllegalArgumentException( "parent: null" );
throw new IllegalArgumentException( "domainModel: null" );
}
return getId().equals( parent.getGroupId() + ":" + parent.getArtifactId() + ":" + parent.getVersion() );
return getId().equals(domainModel.getParentId());
}
/**
@ -256,29 +256,6 @@ public final class PomClassicDomainModel
}
}
/**
* Returns maven model
*
* @return maven model
*/
public Model getModel()
throws IOException
{
if ( model != null )
{
return model;
}
try
{
model = new MavenXpp3Reader().read( ReaderFactory.newXmlReader( new ByteArrayInputStream( inputBytes ) ) );
return model;
}
catch ( XmlPullParserException e )
{
throw new IOException( e.getMessage() );
}
}
/**
* @see org.apache.maven.shared.model.InputStreamDomainModel#getInputStream()
*/
@ -370,7 +347,11 @@ public final class PomClassicDomainModel
*/
public boolean equals( Object o )
{
return o instanceof PomClassicDomainModel && getId().equals( ( (PomClassicDomainModel) o ).getId() );
try {
return o instanceof PomClassicDomainModel && getId().equals( ( (PomClassicDomainModel) o ).getId() );
} catch (IOException e) {
return false;
}
}
}

View File

@ -3,13 +3,9 @@ package org.apache.maven.project.builder;
import org.apache.maven.shared.model.DomainModelFactory;
import org.apache.maven.shared.model.DomainModel;
import org.apache.maven.shared.model.ModelProperty;
import org.apache.maven.shared.model.ModelMarshaller;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
import java.util.List;
import java.io.IOException;
import java.io.StringReader;
public class PomClassicDomainModelFactory implements DomainModelFactory
{

View File

@ -799,7 +799,7 @@ public class PomTransformer
DomainModel domainModel )
throws IOException
{
IPomClassicDomainModel dm = (IPomClassicDomainModel) domainModel;
PomClassicDomainModel dm = (PomClassicDomainModel) domainModel;
if ( !containsProjectVersion( interpolatorProperties ) )
{

View File

@ -2,17 +2,19 @@ package org.apache.maven.project.builder;
import org.apache.maven.shared.model.DomainModel;
import org.apache.maven.shared.model.ModelProperty;
import org.apache.maven.shared.model.InputStreamDomainModel;
import java.util.List;
import java.io.IOException;
import java.io.File;
import java.io.InputStream;
public class DefaultDomainModel implements IPomClassicDomainModel {
public class DefaultDomainModel extends PomClassicDomainModel {
private List<ModelProperty> modelProperties;
public DefaultDomainModel(List<ModelProperty> modelProperties) {
super( modelProperties);
this.modelProperties = modelProperties;
}

View File

@ -19,8 +19,7 @@ package org.apache.maven.project;
* under the License.
*/
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.HashMap;
@ -40,6 +39,7 @@ import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.model.Build;
import org.apache.maven.model.Model;
import org.apache.maven.model.Profile;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.profiles.MavenProfilesBuilder;
import org.apache.maven.profiles.ProfileManager;
import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
@ -47,10 +47,7 @@ import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationException;
import org.apache.maven.profiles.build.ProfileAdvisor;
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
import org.apache.maven.project.builder.DefaultPomArtifactResolver;
import org.apache.maven.project.builder.PomArtifactResolver;
import org.apache.maven.project.builder.PomInterpolatorTag;
import org.apache.maven.project.builder.ProjectBuilder;
import org.apache.maven.project.builder.*;
import org.apache.maven.project.validation.ModelValidationResult;
import org.apache.maven.project.validation.ModelValidator;
import org.apache.maven.shared.model.InterpolatorProperty;
@ -59,6 +56,7 @@ import org.codehaus.plexus.component.annotations.Requirement;
import org.codehaus.plexus.logging.LogEnabled;
import org.codehaus.plexus.logging.Logger;
import org.codehaus.plexus.util.StringUtils;
import org.codehaus.plexus.util.WriterFactory;
/**

View File

@ -1,4 +1,4 @@
package org.apache.maven.project.builder;
package org.apache.maven.project;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -24,6 +24,7 @@ import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.artifact.resolver.ArtifactNotFoundException;
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
import org.apache.maven.artifact.resolver.ArtifactResolver;
import org.apache.maven.project.PomArtifactResolver;
import java.io.File;
import java.io.IOException;

View File

@ -1,4 +1,4 @@
package org.apache.maven.project.builder.impl;
package org.apache.maven.project;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -19,9 +19,7 @@ package org.apache.maven.project.builder.impl;
* under the License.
*/
import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.io.*;
import java.util.*;
import org.apache.maven.MavenTools;
@ -36,11 +34,9 @@ import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.InvalidRepositoryException;
import org.apache.maven.artifact.factory.ArtifactFactory;
import org.apache.maven.model.Model;
import org.apache.maven.model.Parent;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.project.*;
import org.apache.maven.project.builder.*;
import org.apache.maven.project.builder.ProjectUri;
import org.apache.maven.project.builder.profile.ProfileContext;
@ -52,6 +48,8 @@ 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.WriterFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
/**
* Default implementation of the project builder.
@ -233,10 +231,10 @@ public class DefaultProjectBuilder
File parentFile = null;
int lineageCount = 0;
if ( domainModel.getModel().getParent() != null )
if ( domainModel.getParentId() != null )
{
List<DomainModel> mavenParents;
if ( isParentLocal( domainModel.getModel().getParent(), pom.getParentFile() ) )
if ( isParentLocal( domainModel.getRelativePathOfParent(), pom.getParentFile() ) )
{
mavenParents =
getDomainModelParentsFromLocalPath( domainModel, resolver, pom.getParentFile(), properties,
@ -262,7 +260,7 @@ public class DefaultProjectBuilder
for ( Model model : mixins )
{
domainModels.add( new PomClassicDomainModel( model ) );
domainModels.add( convertToDomainModel( model ) );
}
PomTransformer transformer = new PomTransformer( new PomClassicDomainModelFactory() );
@ -281,6 +279,30 @@ public class DefaultProjectBuilder
return transformedDomainModel;
}
private PomClassicDomainModel convertToDomainModel(Model model) throws IOException
{
if ( model == null )
{
throw new IllegalArgumentException( "model: null" );
}
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();
}
}
return new PomClassicDomainModel(new ByteArrayInputStream(baos.toByteArray()));
}
public MavenProject buildFromLocalPath( File pom,
List<Model> mixins,
@ -309,7 +331,7 @@ public class DefaultProjectBuilder
try
{
MavenProject mavenProject = new MavenProject( domainModel.getModel(),
MavenProject mavenProject = new MavenProject( convertFromInputStreamToModel(domainModel.getInputStream()),
artifactFactory,
mavenTools,
mavenProjectBuilder,
@ -325,18 +347,32 @@ public class DefaultProjectBuilder
}
}
private static Model convertFromInputStreamToModel(InputStream inputStream) throws IOException
{
try
{
return new MavenXpp3Reader().read( ReaderFactory.newXmlReader( inputStream ) );
}
catch ( XmlPullParserException e )
{
throw new IOException( e.getMessage() );
}
}
/**
* Returns true if the relative path of the specified parent references a pom, otherwise returns false.
*
* @param parent the parent model info
* @param relativePath the parent model info
* @param projectDirectory the project directory of the child pom
* @return true if the relative path of the specified parent references a pom, otherwise returns fals
*/
private boolean isParentLocal( Parent parent, File projectDirectory )
private boolean isParentLocal( String relativePath, File projectDirectory )
{
try
{
File f = new File( projectDirectory, parent.getRelativePath() ).getCanonicalFile();
File f = new File( projectDirectory, relativePath ).getCanonicalFile();
if ( f.isDirectory() )
{
@ -360,23 +396,24 @@ public class DefaultProjectBuilder
{
List<DomainModel> domainModels = new ArrayList<DomainModel>();
Parent parent = domainModel.getModel().getParent();
String parentId = domainModel.getParentId();
if ( parent == null )
if ( parentId == null )
{
return domainModels;
}
Artifact artifactParent = artifactFactory.createParentArtifact( parent.getGroupId(), parent.getArtifactId(), parent.getVersion() );
Artifact artifactParent = artifactFactory.createParentArtifact( domainModel.getParentGroupId(),
domainModel.getParentArtifactId(), domainModel.getParentVersion() );
artifactResolver.resolve( artifactParent );
PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( artifactParent.getFile() );
if ( !parentDomainModel.matchesParent( domainModel.getModel().getParent() ) )
if ( !parentDomainModel.matchesParentOf( domainModel ) )
{
logger.debug( "Parent pom ids do not match: Parent File = " + artifactParent.getFile().getAbsolutePath() +
": Child ID = " + domainModel.getModel().getId() );
": Child ID = " + domainModel.getId() );
return domainModels;
}
@ -428,16 +465,16 @@ public class DefaultProjectBuilder
{
List<DomainModel> domainModels = new ArrayList<DomainModel>();
Parent parent = domainModel.getModel().getParent();
String parentId = domainModel.getParentId();
if ( parent == null )
if ( parentId == null )
{
return domainModels;
}
Model model = domainModel.getModel();
// Model model = domainModel.getModel();
File parentFile = new File( projectDirectory, model.getParent().getRelativePath() ).getCanonicalFile();
File parentFile = new File( projectDirectory, domainModel.getRelativePathOfParent() ).getCanonicalFile();
if ( parentFile.isDirectory() )
{
parentFile = new File( parentFile.getAbsolutePath(), "pom.xml" );
@ -472,11 +509,11 @@ public class DefaultProjectBuilder
domainModels.add(new PomClassicDomainModel(transformed));
}
if ( !parentDomainModel.matchesParent( domainModel.getModel().getParent() ) )
if ( !parentDomainModel.matchesParentOf( domainModel ) )
{
logger.debug( "Parent pom ids do not match: Parent File = " + parentFile.getAbsolutePath() + ", Parent ID = "
logger.info( "Parent pom ids do not match: Parent File = " + parentFile.getAbsolutePath() + ", Parent ID = "
+ parentDomainModel.getId() + ", Child ID = " + domainModel.getId() + ", Expected Parent ID = "
+ domainModel.getModel().getParent().getId() );
+ domainModel.getParentId() );
List<DomainModel> parentDomainModels =
getDomainModelParentsFromRepository( domainModel, artifactResolver, properties, activeProfileIds,
@ -485,7 +522,7 @@ public class DefaultProjectBuilder
if(parentDomainModels.size() == 0)
{
throw new IOException("Unable to find parent pom on local path or repo: "
+ domainModel.getModel().getParent().getId());
+ domainModel.getParentId());
}
domainModels.addAll( parentDomainModels );
@ -493,9 +530,9 @@ public class DefaultProjectBuilder
}
domainModels.add( parentDomainModel );
if ( parentDomainModel.getModel().getParent() != null )
if ( domainModel.getParentId() != null )
{
if ( isParentLocal( parentDomainModel.getModel().getParent(), parentFile.getParentFile() ) )
if ( isParentLocal(parentDomainModel.getRelativePathOfParent(), parentFile.getParentFile() ) )
{
domainModels.addAll( getDomainModelParentsFromLocalPath( parentDomainModel, artifactResolver,
parentFile.getParentFile(), properties,

View File

@ -1,4 +1,4 @@
package org.apache.maven.project.builder;
package org.apache.maven.project;
import java.io.IOException;

View File

@ -1,4 +1,4 @@
package org.apache.maven.project.builder;
package org.apache.maven.project;
/*
* Licensed to the Apache Software Foundation (ASF) under one
@ -25,17 +25,15 @@ import java.util.Collection;
import java.util.List;
import org.apache.maven.model.Model;
import org.apache.maven.project.MavenProject;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.shared.model.InterpolatorProperty;
import org.apache.maven.project.builder.PomClassicDomainModel;
/**
* Provides services for building maven projects from models.
*/
public interface ProjectBuilder
{
public IPomClassicDomainModel buildModel( File pom,
public PomClassicDomainModel buildModel( File pom,
Collection<InterpolatorProperty> interpolatorProperties,
PomArtifactResolver resolver )
throws IOException;

View File

@ -1,46 +0,0 @@
package org.apache.maven.project.builder;
import java.io.ByteArrayInputStream;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.apache.maven.model.Model;
import org.apache.maven.shared.model.InterpolatorProperty;
import org.apache.maven.shared.model.ModelMarshaller;
import org.apache.maven.shared.model.ModelProperty;
import org.apache.maven.shared.model.ModelTransformerContext;
public class Interpolator
{
// Only used by the plugin manager
public static String interpolateXmlString( String xml, List<InterpolatorProperty> interpolatorProperties )
throws IOException
{
List<ModelProperty> modelProperties = ModelMarshaller.marshallXmlToModelProperties( new ByteArrayInputStream( xml.getBytes() ), ProjectUri.baseUri, PomTransformer.URIS );
Map<String, String> aliases = new HashMap<String, String>();
aliases.put( "project.", "pom." );
List<InterpolatorProperty> ips = new ArrayList<InterpolatorProperty>( interpolatorProperties );
ips.addAll( ModelTransformerContext.createInterpolatorProperties( modelProperties, ProjectUri.baseUri, aliases, PomInterpolatorTag.PROJECT_PROPERTIES.name(), false, false ) );
for ( ModelProperty mp : modelProperties )
{
if ( mp.getUri().startsWith( ProjectUri.properties ) && mp.getValue() != null )
{
String uri = mp.getUri();
ips.add( new InterpolatorProperty( "${" + uri.substring( uri.lastIndexOf( "/" ) + 1, uri.length() ) + "}", mp.getValue() ) );
}
}
ModelTransformerContext.interpolateModelProperties( modelProperties, ips );
return ModelMarshaller.unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri );
}
}

View File

@ -1,86 +0,0 @@
package org.apache.maven.project.builder.impl;
/*
* 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 org.apache.maven.shared.model.ImportModel;
import org.apache.maven.shared.model.ModelProperty;
import java.util.ArrayList;
import java.util.List;
public final class DefaultImportModel
implements ImportModel
{
private final String id;
private final List<ModelProperty> modelProperties;
public DefaultImportModel( String id, List<ModelProperty> modelProperties )
{
if ( id == null )
{
throw new IllegalArgumentException( "id: null" );
}
if ( modelProperties == null )
{
throw new IllegalArgumentException( "modelProperties: null" );
}
this.id = id;
this.modelProperties = new ArrayList<ModelProperty>( modelProperties );
}
public String getId()
{
return id;
}
public List<ModelProperty> getModelProperties()
{
return new ArrayList<ModelProperty>( modelProperties );
}
public boolean equals( Object o )
{
if ( this == o )
{
return true;
}
if ( o == null || getClass() != o.getClass() )
{
return false;
}
ImportModel that = (ImportModel) o;
if ( id != null ? !id.equals( that.getId() ) : that.getId() != null )
{
return false;
}
return true;
}
public int hashCode()
{
return ( id != null ? id.hashCode() : 0 );
}
}

View File

@ -29,15 +29,12 @@ import org.apache.maven.profiles.DefaultProfileManager;
import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
import org.apache.maven.profiles.activation.ProfileActivationContext;
import org.apache.maven.model.Model;
import org.apache.maven.model.Plugin;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
import org.apache.maven.project.harness.PomTestWrapper;
import org.apache.maven.project.MavenProjectBuilder;
import org.apache.maven.project.ProjectBuilderConfiguration;
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
import org.apache.maven.project.*;
import org.codehaus.plexus.PlexusTestCase;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
@ -83,6 +80,17 @@ public class PomConstructionTest
};
}
/**
* Will throw exception if doesn't find parent(s) in build
*
* @throws Exception
*/
public void testParentInheritance()
throws Exception
{
buildPom( "parent-inheritance/sub" );
}
/*MNG-3995*/
public void testExecutionConfigurationJoin()
throws Exception
@ -112,7 +120,7 @@ public class PomConstructionTest
{
File pom = new File( testDirectory, "micromailer/micromailer-1.0.3.pom" );
PomArtifactResolver resolver = artifactResolver( "micromailer" );
IPomClassicDomainModel model = projectBuilder.buildModel( pom, null, resolver );
PomClassicDomainModel model = projectBuilder.buildModel( pom, null, resolver );
// This should be 2
//assertEquals( 2, model.getLineageCount() );
PomTestWrapper tester = new PomTestWrapper( (PomClassicDomainModel) model );

View File

@ -19,8 +19,7 @@ package org.apache.maven.project.harness;
* under the License.
*/
import java.io.File;
import java.io.IOException;
import java.io.*;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@ -29,10 +28,13 @@ import java.util.Map;
import org.apache.commons.jxpath.JXPathContext;
import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl;
import org.apache.maven.model.Model;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
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;
import org.codehaus.plexus.util.WriterFactory;
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
public class PomTestWrapper
{
@ -65,7 +67,11 @@ public class PomTestWrapper
}
this.domainModel = domainModel;
this.pomFile = pomFile;
context = JXPathContext.newContext( domainModel.getModel() );
try {
context = JXPathContext.newContext( new MavenXpp3Reader().read(domainModel.getInputStream()));
} catch (XmlPullParserException e) {
throw new IOException(e.getMessage());
}
}
public PomTestWrapper( File pomFile, MavenProject mavenProject )
@ -100,19 +106,11 @@ public class PomTestWrapper
}
this.domainModel = new PomClassicDomainModel( file );
context = JXPathContext.newContext( domainModel.getModel() );
}
public PomTestWrapper( Model model )
throws IOException
{
if ( model == null )
{
throw new IllegalArgumentException( "model: null" );
try {
context = JXPathContext.newContext( new MavenXpp3Reader().read(domainModel.getInputStream()));
} catch (XmlPullParserException e) {
throw new IOException(e.getMessage());
}
this.domainModel = new PomClassicDomainModel( model );
context = JXPathContext.newContext( domainModel.getModel() );
}
public MavenProject getMavenProject()
@ -125,7 +123,7 @@ public class PomTestWrapper
if(domainModel == null && mavenProject != null)
{
try {
return new PomClassicDomainModel(mavenProject.getModel());
return convertToDomainModel(mavenProject.getModel());
} catch (IOException e) {
}
@ -134,6 +132,30 @@ public class PomTestWrapper
return this.domainModel;
}
private PomClassicDomainModel convertToDomainModel(Model model) throws IOException
{
if ( model == null )
{
throw new IllegalArgumentException( "model: null" );
}
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();
}
}
return new PomClassicDomainModel(new ByteArrayInputStream(baos.toByteArray()));
}
public File getBasedir()
{
return ( pomFile != null ) ? pomFile.getParentFile() : null;

View File

@ -0,0 +1,6 @@
<project>
<groupId>gid</groupId>
<artifactId>child-3</artifactId>
<version>1.0</version>
<modelVersion>4.0.0</modelVersion>
</project>

View File

@ -0,0 +1,10 @@
<project>
<parent>
<groupId>gid</groupId>
<artifactId>child-3</artifactId>
<version>1.0</version>
<relativePath>child3.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>child-2</artifactId>
</project>

View File

@ -0,0 +1,9 @@
<project>
<parent>
<groupId>gid</groupId>
<artifactId>child-2</artifactId>
<version>1.0</version>
</parent>
<modelVersion>4.0.0</modelVersion>
<artifactId>child-1</artifactId>
</project>

View File

@ -57,9 +57,9 @@ under the License.
</requirements>
</component>
<component>
<role>org.apache.maven.project.builder.ProjectBuilder</role>
<role>org.apache.maven.project.ProjectBuilder</role>
<role-hint>default</role-hint>
<implementation>org.apache.maven.project.builder.impl.DefaultProjectBuilder</implementation>
<implementation>org.apache.maven.project.DefaultProjectBuilder</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
@ -75,7 +75,7 @@ under the License.
<implementation>org.apache.maven.project.TestProjectBuilder</implementation>
<requirements>
<requirement>
<role>org.apache.maven.project.builder.ProjectBuilder</role>
<role>org.apache.maven.project.ProjectBuilder</role>
</requirement>
<requirement>
<role>org.apache.maven.profiles.build.ProfileAdvisor</role>

View File

@ -60,9 +60,9 @@ under the License.
</requirements>
</component>
<component>
<role>org.apache.maven.project.builder.ProjectBuilder</role>
<role>org.apache.maven.project.ProjectBuilder</role>
<role-hint>default</role-hint>
<implementation>org.apache.maven.project.builder.impl.DefaultProjectBuilder</implementation>
<implementation>org.apache.maven.project.DefaultProjectBuilder</implementation>
<requirements>
<requirement>
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
@ -78,7 +78,7 @@ under the License.
<implementation>org.apache.maven.project.TestProjectBuilder</implementation>
<requirements>
<requirement>
<role>org.apache.maven.project.builder.ProjectBuilder</role>
<role>org.apache.maven.project.ProjectBuilder</role>
</requirement>
<requirement>
<role>org.apache.maven.profiles.build.ProfileAdvisor</role>