mirror of https://github.com/apache/maven.git
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:
parent
45b99d20cf
commit
c327c94443
|
@ -21,6 +21,7 @@ package org.apache.maven.plugin;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
import java.io.StringReader;
|
||||||
|
import java.io.ByteArrayInputStream;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
import java.util.Collections;
|
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.PluginVersionManager;
|
||||||
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
|
import org.apache.maven.plugin.version.PluginVersionNotFoundException;
|
||||||
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
import org.apache.maven.plugin.version.PluginVersionResolutionException;
|
||||||
import org.apache.maven.project.DuplicateArtifactAttachmentException;
|
import org.apache.maven.project.*;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.builder.*;
|
||||||
import org.apache.maven.project.MavenProjectBuilder;
|
import org.apache.maven.project.ProjectBuilder;
|
||||||
import org.apache.maven.project.ProjectBuildingException;
|
|
||||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||||
import org.apache.maven.project.artifact.MavenMetadataSource;
|
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.project.path.PathTranslator;
|
||||||
import org.apache.maven.realm.MavenRealmManager;
|
import org.apache.maven.realm.MavenRealmManager;
|
||||||
import org.apache.maven.realm.RealmManagementException;
|
import org.apache.maven.realm.RealmManagementException;
|
||||||
import org.apache.maven.reporting.MavenReport;
|
import org.apache.maven.reporting.MavenReport;
|
||||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
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.PlexusContainer;
|
||||||
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
import org.codehaus.plexus.classworlds.realm.ClassRealm;
|
||||||
import org.codehaus.plexus.component.annotations.Component;
|
import org.codehaus.plexus.component.annotations.Component;
|
||||||
|
@ -575,7 +575,7 @@ public class DefaultPluginManager
|
||||||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getUserProperties(),
|
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( session.getProjectBuilderConfiguration().getUserProperties(),
|
||||||
PomInterpolatorTag.USER_PROPERTIES.name()));
|
PomInterpolatorTag.USER_PROPERTIES.name()));
|
||||||
String interpolatedDom =
|
String interpolatedDom =
|
||||||
Interpolator.interpolateXmlString( String.valueOf( dom ), interpolatorProperties );
|
interpolateXmlString( String.valueOf( dom ), interpolatorProperties );
|
||||||
dom = Xpp3DomBuilder.build( new StringReader( interpolatedDom ) );
|
dom = Xpp3DomBuilder.build( new StringReader( interpolatedDom ) );
|
||||||
}
|
}
|
||||||
catch ( XmlPullParserException e )
|
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 );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,7 +62,6 @@ import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.project.MavenProjectBuilder;
|
import org.apache.maven.project.MavenProjectBuilder;
|
||||||
import org.apache.maven.project.MavenProjectBuildingResult;
|
import org.apache.maven.project.MavenProjectBuildingResult;
|
||||||
import org.apache.maven.project.ProjectBuildingException;
|
import org.apache.maven.project.ProjectBuildingException;
|
||||||
import org.apache.maven.project.builder.ProjectBuilder;
|
|
||||||
import org.apache.maven.plugin.PluginRepository;
|
import org.apache.maven.plugin.PluginRepository;
|
||||||
import org.apache.maven.reactor.MavenExecutionException;
|
import org.apache.maven.reactor.MavenExecutionException;
|
||||||
import org.apache.maven.reactor.MissingModuleException;
|
import org.apache.maven.reactor.MissingModuleException;
|
||||||
|
|
|
@ -26,6 +26,10 @@
|
||||||
<groupId>org.sonatype.spice</groupId>
|
<groupId>org.sonatype.spice</groupId>
|
||||||
<artifactId>model-builder</artifactId>
|
<artifactId>model-builder</artifactId>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.codehaus.plexus</groupId>
|
||||||
|
<artifactId>plexus-utils</artifactId>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>junit</groupId>
|
<groupId>junit</groupId>
|
||||||
<artifactId>junit</artifactId>
|
<artifactId>junit</artifactId>
|
||||||
|
|
|
@ -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();
|
|
||||||
}
|
|
|
@ -1,6 +0,0 @@
|
||||||
package org.apache.maven.project.builder;
|
|
||||||
|
|
||||||
public interface IProjectBuilder
|
|
||||||
{
|
|
||||||
|
|
||||||
}
|
|
|
@ -19,25 +19,17 @@ package org.apache.maven.project.builder;
|
||||||
* under the License.
|
* 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.ModelProperty;
|
||||||
import org.apache.maven.shared.model.ModelMarshaller;
|
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.IOUtil;
|
||||||
import org.codehaus.plexus.util.ReaderFactory;
|
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.ByteArrayInputStream;
|
||||||
import java.io.ByteArrayOutputStream;
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileInputStream;
|
import java.io.FileInputStream;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.Writer;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Set;
|
import java.util.Set;
|
||||||
|
@ -46,8 +38,7 @@ import java.util.HashSet;
|
||||||
/**
|
/**
|
||||||
* Provides a wrapper for the maven model.
|
* Provides a wrapper for the maven model.
|
||||||
*/
|
*/
|
||||||
public final class PomClassicDomainModel
|
public class PomClassicDomainModel implements InputStreamDomainModel
|
||||||
implements IPomClassicDomainModel
|
|
||||||
{
|
{
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -60,11 +51,6 @@ public final class PomClassicDomainModel
|
||||||
*/
|
*/
|
||||||
private String eventHistory;
|
private String eventHistory;
|
||||||
|
|
||||||
/**
|
|
||||||
* Maven model
|
|
||||||
*/
|
|
||||||
private Model model;
|
|
||||||
|
|
||||||
private String id;
|
private String id;
|
||||||
|
|
||||||
private File file;
|
private File file;
|
||||||
|
@ -77,44 +63,18 @@ public final class PomClassicDomainModel
|
||||||
|
|
||||||
private int lineageCount;
|
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;
|
this.modelProperties = modelProperties;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
inputBytes = IOUtil.toByteArray( ModelMarshaller.unmarshalModelPropertiesToXml(modelProperties, ProjectUri.baseUri));
|
inputBytes = IOUtil.toByteArray( ModelMarshaller.unmarshalModelPropertiesToXml(modelProperties, ProjectUri.baseUri));
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
initializeProperties( modelProperties );
|
||||||
/**
|
|
||||||
* 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();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -131,6 +91,76 @@ public final class PomClassicDomainModel
|
||||||
throw new IllegalArgumentException( "inputStream: null" );
|
throw new IllegalArgumentException( "inputStream: null" );
|
||||||
}
|
}
|
||||||
this.inputBytes = IOUtil.toByteArray( inputStream );
|
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 )
|
public PomClassicDomainModel( File file )
|
||||||
|
@ -149,7 +179,19 @@ public final class PomClassicDomainModel
|
||||||
{
|
{
|
||||||
this.parentFile = parentFile;
|
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.
|
* 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;
|
return projectDirectory != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
public String getParentId() throws IOException
|
||||||
* 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 )
|
|
||||||
{
|
{
|
||||||
if ( a == null )
|
return parentId;
|
||||||
{
|
|
||||||
throw new IllegalArgumentException( "a: null" );
|
|
||||||
}
|
|
||||||
if ( model == null )
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
model = getModel();
|
|
||||||
}
|
|
||||||
catch ( IOException e )
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return a.getId().equals( this.getId() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getId()
|
public String getRelativePathOfParent()
|
||||||
{
|
{
|
||||||
if ( id == null )
|
return parentRelativePath;
|
||||||
{
|
}
|
||||||
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();
|
|
||||||
|
|
||||||
id = groupId + ":" + artifactId + ":" + version;
|
public String getId() throws IOException
|
||||||
}
|
{
|
||||||
return id;
|
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()
|
* @see org.apache.maven.shared.model.InputStreamDomainModel#getInputStream()
|
||||||
*/
|
*/
|
||||||
|
@ -370,7 +347,11 @@ public final class PomClassicDomainModel
|
||||||
*/
|
*/
|
||||||
public boolean equals( Object o )
|
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;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -3,13 +3,9 @@ package org.apache.maven.project.builder;
|
||||||
import org.apache.maven.shared.model.DomainModelFactory;
|
import org.apache.maven.shared.model.DomainModelFactory;
|
||||||
import org.apache.maven.shared.model.DomainModel;
|
import org.apache.maven.shared.model.DomainModel;
|
||||||
import org.apache.maven.shared.model.ModelProperty;
|
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.util.List;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.StringReader;
|
|
||||||
|
|
||||||
public class PomClassicDomainModelFactory implements DomainModelFactory
|
public class PomClassicDomainModelFactory implements DomainModelFactory
|
||||||
{
|
{
|
|
@ -799,7 +799,7 @@ public class PomTransformer
|
||||||
DomainModel domainModel )
|
DomainModel domainModel )
|
||||||
throws IOException
|
throws IOException
|
||||||
{
|
{
|
||||||
IPomClassicDomainModel dm = (IPomClassicDomainModel) domainModel;
|
PomClassicDomainModel dm = (PomClassicDomainModel) domainModel;
|
||||||
|
|
||||||
if ( !containsProjectVersion( interpolatorProperties ) )
|
if ( !containsProjectVersion( interpolatorProperties ) )
|
||||||
{
|
{
|
||||||
|
|
|
@ -2,17 +2,19 @@ package org.apache.maven.project.builder;
|
||||||
|
|
||||||
import org.apache.maven.shared.model.DomainModel;
|
import org.apache.maven.shared.model.DomainModel;
|
||||||
import org.apache.maven.shared.model.ModelProperty;
|
import org.apache.maven.shared.model.ModelProperty;
|
||||||
|
import org.apache.maven.shared.model.InputStreamDomainModel;
|
||||||
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
|
||||||
public class DefaultDomainModel implements IPomClassicDomainModel {
|
public class DefaultDomainModel extends PomClassicDomainModel {
|
||||||
|
|
||||||
private List<ModelProperty> modelProperties;
|
private List<ModelProperty> modelProperties;
|
||||||
|
|
||||||
public DefaultDomainModel(List<ModelProperty> modelProperties) {
|
public DefaultDomainModel(List<ModelProperty> modelProperties) {
|
||||||
|
super( modelProperties);
|
||||||
this.modelProperties = modelProperties;
|
this.modelProperties = modelProperties;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,8 +19,7 @@ package org.apache.maven.project;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.text.SimpleDateFormat;
|
import java.text.SimpleDateFormat;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
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.Build;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Profile;
|
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.MavenProfilesBuilder;
|
||||||
import org.apache.maven.profiles.ProfileManager;
|
import org.apache.maven.profiles.ProfileManager;
|
||||||
import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
|
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.activation.ProfileActivationException;
|
||||||
import org.apache.maven.profiles.build.ProfileAdvisor;
|
import org.apache.maven.profiles.build.ProfileAdvisor;
|
||||||
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
import org.apache.maven.project.artifact.InvalidDependencyVersionException;
|
||||||
import org.apache.maven.project.builder.DefaultPomArtifactResolver;
|
import org.apache.maven.project.builder.*;
|
||||||
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.validation.ModelValidationResult;
|
import org.apache.maven.project.validation.ModelValidationResult;
|
||||||
import org.apache.maven.project.validation.ModelValidator;
|
import org.apache.maven.project.validation.ModelValidator;
|
||||||
import org.apache.maven.shared.model.InterpolatorProperty;
|
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.LogEnabled;
|
||||||
import org.codehaus.plexus.logging.Logger;
|
import org.codehaus.plexus.logging.Logger;
|
||||||
import org.codehaus.plexus.util.StringUtils;
|
import org.codehaus.plexus.util.StringUtils;
|
||||||
|
import org.codehaus.plexus.util.WriterFactory;
|
||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.apache.maven.project.builder;
|
package org.apache.maven.project;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* 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.ArtifactNotFoundException;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
import org.apache.maven.artifact.resolver.ArtifactResolutionException;
|
||||||
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
import org.apache.maven.artifact.resolver.ArtifactResolver;
|
||||||
|
import org.apache.maven.project.PomArtifactResolver;
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
|
@ -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
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
@ -19,9 +19,7 @@ package org.apache.maven.project.builder.impl;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.io.Reader;
|
|
||||||
import java.util.*;
|
import java.util.*;
|
||||||
|
|
||||||
import org.apache.maven.MavenTools;
|
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.InvalidRepositoryException;
|
||||||
import org.apache.maven.artifact.factory.ArtifactFactory;
|
import org.apache.maven.artifact.factory.ArtifactFactory;
|
||||||
import org.apache.maven.model.Model;
|
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.MavenXpp3Reader;
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
import org.apache.maven.project.*;
|
||||||
import org.apache.maven.project.MavenProjectBuilder;
|
|
||||||
import org.apache.maven.project.builder.*;
|
import org.apache.maven.project.builder.*;
|
||||||
import org.apache.maven.project.builder.ProjectUri;
|
import org.apache.maven.project.builder.ProjectUri;
|
||||||
import org.apache.maven.project.builder.profile.ProfileContext;
|
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.logging.Logger;
|
||||||
import org.codehaus.plexus.util.IOUtil;
|
import org.codehaus.plexus.util.IOUtil;
|
||||||
import org.codehaus.plexus.util.ReaderFactory;
|
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.
|
* Default implementation of the project builder.
|
||||||
|
@ -233,10 +231,10 @@ public class DefaultProjectBuilder
|
||||||
|
|
||||||
File parentFile = null;
|
File parentFile = null;
|
||||||
int lineageCount = 0;
|
int lineageCount = 0;
|
||||||
if ( domainModel.getModel().getParent() != null )
|
if ( domainModel.getParentId() != null )
|
||||||
{
|
{
|
||||||
List<DomainModel> mavenParents;
|
List<DomainModel> mavenParents;
|
||||||
if ( isParentLocal( domainModel.getModel().getParent(), pom.getParentFile() ) )
|
if ( isParentLocal( domainModel.getRelativePathOfParent(), pom.getParentFile() ) )
|
||||||
{
|
{
|
||||||
mavenParents =
|
mavenParents =
|
||||||
getDomainModelParentsFromLocalPath( domainModel, resolver, pom.getParentFile(), properties,
|
getDomainModelParentsFromLocalPath( domainModel, resolver, pom.getParentFile(), properties,
|
||||||
|
@ -262,7 +260,7 @@ public class DefaultProjectBuilder
|
||||||
|
|
||||||
for ( Model model : mixins )
|
for ( Model model : mixins )
|
||||||
{
|
{
|
||||||
domainModels.add( new PomClassicDomainModel( model ) );
|
domainModels.add( convertToDomainModel( model ) );
|
||||||
}
|
}
|
||||||
|
|
||||||
PomTransformer transformer = new PomTransformer( new PomClassicDomainModelFactory() );
|
PomTransformer transformer = new PomTransformer( new PomClassicDomainModelFactory() );
|
||||||
|
@ -281,6 +279,30 @@ public class DefaultProjectBuilder
|
||||||
|
|
||||||
return transformedDomainModel;
|
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,
|
public MavenProject buildFromLocalPath( File pom,
|
||||||
List<Model> mixins,
|
List<Model> mixins,
|
||||||
|
@ -309,7 +331,7 @@ public class DefaultProjectBuilder
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
MavenProject mavenProject = new MavenProject( domainModel.getModel(),
|
MavenProject mavenProject = new MavenProject( convertFromInputStreamToModel(domainModel.getInputStream()),
|
||||||
artifactFactory,
|
artifactFactory,
|
||||||
mavenTools,
|
mavenTools,
|
||||||
mavenProjectBuilder,
|
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.
|
* 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
|
* @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
|
* @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
|
try
|
||||||
{
|
{
|
||||||
File f = new File( projectDirectory, parent.getRelativePath() ).getCanonicalFile();
|
File f = new File( projectDirectory, relativePath ).getCanonicalFile();
|
||||||
|
|
||||||
if ( f.isDirectory() )
|
if ( f.isDirectory() )
|
||||||
{
|
{
|
||||||
|
@ -360,23 +396,24 @@ public class DefaultProjectBuilder
|
||||||
{
|
{
|
||||||
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
||||||
|
|
||||||
Parent parent = domainModel.getModel().getParent();
|
String parentId = domainModel.getParentId();
|
||||||
|
|
||||||
if ( parent == null )
|
if ( parentId == null )
|
||||||
{
|
{
|
||||||
return domainModels;
|
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 );
|
artifactResolver.resolve( artifactParent );
|
||||||
|
|
||||||
PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( artifactParent.getFile() );
|
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() +
|
logger.debug( "Parent pom ids do not match: Parent File = " + artifactParent.getFile().getAbsolutePath() +
|
||||||
": Child ID = " + domainModel.getModel().getId() );
|
": Child ID = " + domainModel.getId() );
|
||||||
return domainModels;
|
return domainModels;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -428,16 +465,16 @@ public class DefaultProjectBuilder
|
||||||
{
|
{
|
||||||
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
||||||
|
|
||||||
Parent parent = domainModel.getModel().getParent();
|
String parentId = domainModel.getParentId();
|
||||||
|
|
||||||
if ( parent == null )
|
if ( parentId == null )
|
||||||
{
|
{
|
||||||
return domainModels;
|
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() )
|
if ( parentFile.isDirectory() )
|
||||||
{
|
{
|
||||||
parentFile = new File( parentFile.getAbsolutePath(), "pom.xml" );
|
parentFile = new File( parentFile.getAbsolutePath(), "pom.xml" );
|
||||||
|
@ -472,11 +509,11 @@ public class DefaultProjectBuilder
|
||||||
domainModels.add(new PomClassicDomainModel(transformed));
|
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 = "
|
+ parentDomainModel.getId() + ", Child ID = " + domainModel.getId() + ", Expected Parent ID = "
|
||||||
+ domainModel.getModel().getParent().getId() );
|
+ domainModel.getParentId() );
|
||||||
|
|
||||||
List<DomainModel> parentDomainModels =
|
List<DomainModel> parentDomainModels =
|
||||||
getDomainModelParentsFromRepository( domainModel, artifactResolver, properties, activeProfileIds,
|
getDomainModelParentsFromRepository( domainModel, artifactResolver, properties, activeProfileIds,
|
||||||
|
@ -485,7 +522,7 @@ public class DefaultProjectBuilder
|
||||||
if(parentDomainModels.size() == 0)
|
if(parentDomainModels.size() == 0)
|
||||||
{
|
{
|
||||||
throw new IOException("Unable to find parent pom on local path or repo: "
|
throw new IOException("Unable to find parent pom on local path or repo: "
|
||||||
+ domainModel.getModel().getParent().getId());
|
+ domainModel.getParentId());
|
||||||
}
|
}
|
||||||
|
|
||||||
domainModels.addAll( parentDomainModels );
|
domainModels.addAll( parentDomainModels );
|
||||||
|
@ -493,9 +530,9 @@ public class DefaultProjectBuilder
|
||||||
}
|
}
|
||||||
|
|
||||||
domainModels.add( parentDomainModel );
|
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,
|
domainModels.addAll( getDomainModelParentsFromLocalPath( parentDomainModel, artifactResolver,
|
||||||
parentFile.getParentFile(), properties,
|
parentFile.getParentFile(), properties,
|
|
@ -1,4 +1,4 @@
|
||||||
package org.apache.maven.project.builder;
|
package org.apache.maven.project;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
package org.apache.maven.project.builder;
|
package org.apache.maven.project;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
@ -25,17 +25,15 @@ import java.util.Collection;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.maven.model.Model;
|
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.shared.model.InterpolatorProperty;
|
||||||
|
import org.apache.maven.project.builder.PomClassicDomainModel;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Provides services for building maven projects from models.
|
* Provides services for building maven projects from models.
|
||||||
*/
|
*/
|
||||||
public interface ProjectBuilder
|
public interface ProjectBuilder
|
||||||
{
|
{
|
||||||
public IPomClassicDomainModel buildModel( File pom,
|
public PomClassicDomainModel buildModel( File pom,
|
||||||
Collection<InterpolatorProperty> interpolatorProperties,
|
Collection<InterpolatorProperty> interpolatorProperties,
|
||||||
PomArtifactResolver resolver )
|
PomArtifactResolver resolver )
|
||||||
throws IOException;
|
throws IOException;
|
|
@ -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 );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -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 );
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -29,15 +29,12 @@ import org.apache.maven.profiles.DefaultProfileManager;
|
||||||
import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
|
import org.apache.maven.profiles.activation.DefaultProfileActivationContext;
|
||||||
import org.apache.maven.profiles.activation.ProfileActivationContext;
|
import org.apache.maven.profiles.activation.ProfileActivationContext;
|
||||||
import org.apache.maven.model.Model;
|
import org.apache.maven.model.Model;
|
||||||
import org.apache.maven.model.Plugin;
|
|
||||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||||
import org.apache.maven.artifact.Artifact;
|
import org.apache.maven.artifact.Artifact;
|
||||||
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
|
import org.apache.maven.artifact.repository.DefaultArtifactRepository;
|
||||||
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
|
import org.apache.maven.artifact.repository.layout.DefaultRepositoryLayout;
|
||||||
import org.apache.maven.project.harness.PomTestWrapper;
|
import org.apache.maven.project.harness.PomTestWrapper;
|
||||||
import org.apache.maven.project.MavenProjectBuilder;
|
import org.apache.maven.project.*;
|
||||||
import org.apache.maven.project.ProjectBuilderConfiguration;
|
|
||||||
import org.apache.maven.project.DefaultProjectBuilderConfiguration;
|
|
||||||
import org.codehaus.plexus.PlexusTestCase;
|
import org.codehaus.plexus.PlexusTestCase;
|
||||||
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
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*/
|
/*MNG-3995*/
|
||||||
public void testExecutionConfigurationJoin()
|
public void testExecutionConfigurationJoin()
|
||||||
throws Exception
|
throws Exception
|
||||||
|
@ -112,7 +120,7 @@ public class PomConstructionTest
|
||||||
{
|
{
|
||||||
File pom = new File( testDirectory, "micromailer/micromailer-1.0.3.pom" );
|
File pom = new File( testDirectory, "micromailer/micromailer-1.0.3.pom" );
|
||||||
PomArtifactResolver resolver = artifactResolver( "micromailer" );
|
PomArtifactResolver resolver = artifactResolver( "micromailer" );
|
||||||
IPomClassicDomainModel model = projectBuilder.buildModel( pom, null, resolver );
|
PomClassicDomainModel model = projectBuilder.buildModel( pom, null, resolver );
|
||||||
// This should be 2
|
// This should be 2
|
||||||
//assertEquals( 2, model.getLineageCount() );
|
//assertEquals( 2, model.getLineageCount() );
|
||||||
PomTestWrapper tester = new PomTestWrapper( (PomClassicDomainModel) model );
|
PomTestWrapper tester = new PomTestWrapper( (PomClassicDomainModel) model );
|
||||||
|
|
|
@ -19,8 +19,7 @@ package org.apache.maven.project.harness;
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.io.File;
|
import java.io.*;
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
@ -29,10 +28,13 @@ import java.util.Map;
|
||||||
import org.apache.commons.jxpath.JXPathContext;
|
import org.apache.commons.jxpath.JXPathContext;
|
||||||
import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl;
|
import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl;
|
||||||
import org.apache.maven.model.Model;
|
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.PomClassicDomainModel;
|
||||||
import org.apache.maven.project.builder.IPomClassicDomainModel;
|
|
||||||
import org.apache.maven.project.MavenProject;
|
import org.apache.maven.project.MavenProject;
|
||||||
import org.apache.maven.shared.model.ModelProperty;
|
import org.apache.maven.shared.model.ModelProperty;
|
||||||
|
import org.codehaus.plexus.util.WriterFactory;
|
||||||
|
import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
|
||||||
|
|
||||||
public class PomTestWrapper
|
public class PomTestWrapper
|
||||||
{
|
{
|
||||||
|
@ -65,7 +67,11 @@ public class PomTestWrapper
|
||||||
}
|
}
|
||||||
this.domainModel = domainModel;
|
this.domainModel = domainModel;
|
||||||
this.pomFile = pomFile;
|
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 )
|
public PomTestWrapper( File pomFile, MavenProject mavenProject )
|
||||||
|
@ -100,19 +106,11 @@ public class PomTestWrapper
|
||||||
}
|
}
|
||||||
|
|
||||||
this.domainModel = new PomClassicDomainModel( file );
|
this.domainModel = new PomClassicDomainModel( file );
|
||||||
context = JXPathContext.newContext( domainModel.getModel() );
|
try {
|
||||||
}
|
context = JXPathContext.newContext( new MavenXpp3Reader().read(domainModel.getInputStream()));
|
||||||
|
} catch (XmlPullParserException e) {
|
||||||
public PomTestWrapper( Model model )
|
throw new IOException(e.getMessage());
|
||||||
throws IOException
|
|
||||||
{
|
|
||||||
if ( model == null )
|
|
||||||
{
|
|
||||||
throw new IllegalArgumentException( "model: null" );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.domainModel = new PomClassicDomainModel( model );
|
|
||||||
context = JXPathContext.newContext( domainModel.getModel() );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public MavenProject getMavenProject()
|
public MavenProject getMavenProject()
|
||||||
|
@ -125,7 +123,7 @@ public class PomTestWrapper
|
||||||
if(domainModel == null && mavenProject != null)
|
if(domainModel == null && mavenProject != null)
|
||||||
{
|
{
|
||||||
try {
|
try {
|
||||||
return new PomClassicDomainModel(mavenProject.getModel());
|
return convertToDomainModel(mavenProject.getModel());
|
||||||
} catch (IOException e) {
|
} catch (IOException e) {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -134,6 +132,30 @@ public class PomTestWrapper
|
||||||
return this.domainModel;
|
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()
|
public File getBasedir()
|
||||||
{
|
{
|
||||||
return ( pomFile != null ) ? pomFile.getParentFile() : null;
|
return ( pomFile != null ) ? pomFile.getParentFile() : null;
|
||||||
|
|
|
@ -0,0 +1,6 @@
|
||||||
|
<project>
|
||||||
|
<groupId>gid</groupId>
|
||||||
|
<artifactId>child-3</artifactId>
|
||||||
|
<version>1.0</version>
|
||||||
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
</project>
|
|
@ -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>
|
|
@ -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>
|
|
@ -57,9 +57,9 @@ under the License.
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
<component>
|
<component>
|
||||||
<role>org.apache.maven.project.builder.ProjectBuilder</role>
|
<role>org.apache.maven.project.ProjectBuilder</role>
|
||||||
<role-hint>default</role-hint>
|
<role-hint>default</role-hint>
|
||||||
<implementation>org.apache.maven.project.builder.impl.DefaultProjectBuilder</implementation>
|
<implementation>org.apache.maven.project.DefaultProjectBuilder</implementation>
|
||||||
<requirements>
|
<requirements>
|
||||||
<requirement>
|
<requirement>
|
||||||
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
||||||
|
@ -75,7 +75,7 @@ under the License.
|
||||||
<implementation>org.apache.maven.project.TestProjectBuilder</implementation>
|
<implementation>org.apache.maven.project.TestProjectBuilder</implementation>
|
||||||
<requirements>
|
<requirements>
|
||||||
<requirement>
|
<requirement>
|
||||||
<role>org.apache.maven.project.builder.ProjectBuilder</role>
|
<role>org.apache.maven.project.ProjectBuilder</role>
|
||||||
</requirement>
|
</requirement>
|
||||||
<requirement>
|
<requirement>
|
||||||
<role>org.apache.maven.profiles.build.ProfileAdvisor</role>
|
<role>org.apache.maven.profiles.build.ProfileAdvisor</role>
|
||||||
|
|
|
@ -60,9 +60,9 @@ under the License.
|
||||||
</requirements>
|
</requirements>
|
||||||
</component>
|
</component>
|
||||||
<component>
|
<component>
|
||||||
<role>org.apache.maven.project.builder.ProjectBuilder</role>
|
<role>org.apache.maven.project.ProjectBuilder</role>
|
||||||
<role-hint>default</role-hint>
|
<role-hint>default</role-hint>
|
||||||
<implementation>org.apache.maven.project.builder.impl.DefaultProjectBuilder</implementation>
|
<implementation>org.apache.maven.project.DefaultProjectBuilder</implementation>
|
||||||
<requirements>
|
<requirements>
|
||||||
<requirement>
|
<requirement>
|
||||||
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
<role>org.apache.maven.artifact.factory.ArtifactFactory</role>
|
||||||
|
@ -78,7 +78,7 @@ under the License.
|
||||||
<implementation>org.apache.maven.project.TestProjectBuilder</implementation>
|
<implementation>org.apache.maven.project.TestProjectBuilder</implementation>
|
||||||
<requirements>
|
<requirements>
|
||||||
<requirement>
|
<requirement>
|
||||||
<role>org.apache.maven.project.builder.ProjectBuilder</role>
|
<role>org.apache.maven.project.ProjectBuilder</role>
|
||||||
</requirement>
|
</requirement>
|
||||||
<requirement>
|
<requirement>
|
||||||
<role>org.apache.maven.profiles.build.ProfileAdvisor</role>
|
<role>org.apache.maven.profiles.build.ProfileAdvisor</role>
|
||||||
|
|
Loading…
Reference in New Issue