mirror of https://github.com/apache/maven.git
Having a DomainModel interface doesn't makes sense in the current context. We no longer have general transforms.
git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@769836 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
baf09a4148
commit
a6d2ac847a
|
@ -38,7 +38,7 @@ import org.apache.maven.model.Build;
|
|||
import org.apache.maven.model.DomainModel;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.ModelEventListener;
|
||||
import org.apache.maven.model.PomClassicDomainModel;
|
||||
import org.apache.maven.model.DomainModel;
|
||||
import org.apache.maven.model.ProcessorContext;
|
||||
import org.apache.maven.model.Profile;
|
||||
import org.apache.maven.model.interpolator.Interpolator;
|
||||
|
@ -116,7 +116,7 @@ public class DefaultMavenProjectBuilder
|
|||
throws ProjectBuildingException
|
||||
{
|
||||
//Do inheritance
|
||||
PomClassicDomainModel domainModel;
|
||||
DomainModel domainModel;
|
||||
try
|
||||
{
|
||||
domainModel = build( "unknown", pomFile, configuration );
|
||||
|
@ -242,7 +242,7 @@ public class DefaultMavenProjectBuilder
|
|||
{
|
||||
throw new ProjectBuildingException( artifact.getId(), "Error resolving project artifact.", e );
|
||||
}
|
||||
PomClassicDomainModel domainModel;
|
||||
DomainModel domainModel;
|
||||
try
|
||||
{
|
||||
domainModel = build( "unknown", artifact.getFile(), configuration );
|
||||
|
@ -392,7 +392,7 @@ public class DefaultMavenProjectBuilder
|
|||
return new MavenProjectBuildingResult( project, result );
|
||||
}
|
||||
|
||||
private Model interpolateDomainModel( PomClassicDomainModel domainModel, ProjectBuilderConfiguration config, File projectDescriptor )
|
||||
private Model interpolateDomainModel( DomainModel domainModel, ProjectBuilderConfiguration config, File projectDescriptor )
|
||||
throws ProjectBuildingException
|
||||
{
|
||||
Model model;
|
||||
|
@ -453,7 +453,7 @@ public class DefaultMavenProjectBuilder
|
|||
return project;
|
||||
}
|
||||
|
||||
private PomClassicDomainModel build( String projectId, File pomFile, ProjectBuilderConfiguration projectBuilderConfiguration )
|
||||
private DomainModel build( String projectId, File pomFile, ProjectBuilderConfiguration projectBuilderConfiguration )
|
||||
throws ProjectBuildingException, IOException
|
||||
{
|
||||
List<String> activeProfileIds = ( projectBuilderConfiguration != null && projectBuilderConfiguration.getGlobalProfileManager() != null && projectBuilderConfiguration.getGlobalProfileManager()
|
||||
|
@ -467,7 +467,7 @@ public class DefaultMavenProjectBuilder
|
|||
interpolatorProperties.addAll( InterpolatorProperty.toInterpolatorProperties( projectBuilderConfiguration.getExecutionProperties(), PomInterpolatorTag.EXECUTION_PROPERTIES.name() ) );
|
||||
|
||||
ProfileManagerInfo profileInfo = new ProfileManagerInfo(interpolatorProperties, activeProfileIds, inactiveProfileIds);
|
||||
PomClassicDomainModel domainModel = new PomClassicDomainModel( pomFile );
|
||||
DomainModel domainModel = new DomainModel( pomFile );
|
||||
domainModel.setProjectDirectory( pomFile.getParentFile() );
|
||||
domainModel.setMostSpecialized( true );
|
||||
|
||||
|
@ -498,7 +498,7 @@ public class DefaultMavenProjectBuilder
|
|||
|
||||
if ( mavenParents.size() > 0 )
|
||||
{
|
||||
PomClassicDomainModel dm = (PomClassicDomainModel) mavenParents.get( 0 );
|
||||
DomainModel dm = (DomainModel) mavenParents.get( 0 );
|
||||
parentFile = dm.getFile();
|
||||
domainModel.setParentFile( parentFile );
|
||||
lineageCount = mavenParents.size();
|
||||
|
@ -507,12 +507,12 @@ public class DefaultMavenProjectBuilder
|
|||
domainModels.addAll( mavenParents );
|
||||
}
|
||||
|
||||
domainModels.add( new PomClassicDomainModel( getSuperModel(), false ) );
|
||||
domainModels.add( new DomainModel( getSuperModel(), false ) );
|
||||
List<DomainModel> profileModels = new ArrayList<DomainModel>();
|
||||
//Process Profiles
|
||||
for(DomainModel domain : domainModels)
|
||||
{
|
||||
PomClassicDomainModel dm = (PomClassicDomainModel) domain;
|
||||
DomainModel dm = (DomainModel) domain;
|
||||
|
||||
if(!dm.getModel().getProfiles().isEmpty())
|
||||
{
|
||||
|
@ -536,7 +536,7 @@ public class DefaultMavenProjectBuilder
|
|||
}
|
||||
}
|
||||
|
||||
PomClassicDomainModel transformedDomainModel = ProcessorContext.build(profileModels, listeners);
|
||||
DomainModel transformedDomainModel = ProcessorContext.build(profileModels, listeners);
|
||||
|
||||
// Lineage count is inclusive to add the POM read in itself.
|
||||
transformedDomainModel.setLineageCount( lineageCount + 1 );
|
||||
|
@ -545,7 +545,7 @@ public class DefaultMavenProjectBuilder
|
|||
return transformedDomainModel;
|
||||
}
|
||||
|
||||
private static boolean useTopLevelProjectForParent(PomClassicDomainModel currentModel, MavenProject topProject) throws IOException
|
||||
private static boolean useTopLevelProjectForParent(DomainModel currentModel, MavenProject topProject) throws IOException
|
||||
{
|
||||
if(topProject == null || currentModel.getModel().getParent() == null)
|
||||
{
|
||||
|
@ -633,7 +633,7 @@ public class DefaultMavenProjectBuilder
|
|||
}
|
||||
}
|
||||
|
||||
private List<DomainModel> getDomainModelParentsFromRepository( PomClassicDomainModel domainModel, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
||||
private List<DomainModel> getDomainModelParentsFromRepository( DomainModel domainModel, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories )
|
||||
throws IOException
|
||||
{
|
||||
List<DomainModel> domainModels = new ArrayList<DomainModel>();
|
||||
|
@ -659,7 +659,7 @@ public class DefaultMavenProjectBuilder
|
|||
+ " could not be retrieved from any repository" ).initCause( e );
|
||||
}
|
||||
|
||||
PomClassicDomainModel parentDomainModel = new PomClassicDomainModel( artifactParent.getFile() );
|
||||
DomainModel parentDomainModel = new DomainModel( artifactParent.getFile() );
|
||||
|
||||
if ( !parentDomainModel.matchesParentOf( domainModel ) )
|
||||
{
|
||||
|
@ -684,7 +684,7 @@ public class DefaultMavenProjectBuilder
|
|||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
private List<DomainModel> getDomainModelParentsFromLocalPath( PomClassicDomainModel domainModel, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
|
||||
private List<DomainModel> getDomainModelParentsFromLocalPath( DomainModel domainModel, ArtifactRepository localRepository, List<ArtifactRepository> remoteRepositories,
|
||||
File projectDirectory, ProjectBuilderConfiguration projectBuilderConfiguration )
|
||||
throws IOException
|
||||
{
|
||||
|
@ -704,19 +704,19 @@ public class DefaultMavenProjectBuilder
|
|||
}
|
||||
MavenProject topProject = projectBuilderConfiguration.getTopLevelProjectFromReactor();
|
||||
boolean isTop = useTopLevelProjectForParent(domainModel, topProject);
|
||||
PomClassicDomainModel parentDomainModel = null;
|
||||
DomainModel parentDomainModel = null;
|
||||
if ( !isTop )
|
||||
{
|
||||
if(!parentFile.isFile())
|
||||
{
|
||||
throw new IOException( "File does not exist: File = " + parentFile.getAbsolutePath() );
|
||||
}
|
||||
parentDomainModel = new PomClassicDomainModel( parentFile );
|
||||
parentDomainModel = new DomainModel( parentFile );
|
||||
parentDomainModel.setProjectDirectory( parentFile.getParentFile() );
|
||||
}
|
||||
else
|
||||
{
|
||||
parentDomainModel = new PomClassicDomainModel(projectBuilderConfiguration.getTopLevelProjectFromReactor().getFile());
|
||||
parentDomainModel = new DomainModel(projectBuilderConfiguration.getTopLevelProjectFromReactor().getFile());
|
||||
}
|
||||
|
||||
if ( !parentDomainModel.matchesParentOf( domainModel ) )
|
||||
|
|
|
@ -25,13 +25,13 @@ import java.util.Iterator;
|
|||
import org.apache.commons.jxpath.JXPathContext;
|
||||
import org.apache.commons.jxpath.JXPathNotFoundException;
|
||||
import org.apache.commons.jxpath.ri.JXPathContextReferenceImpl;
|
||||
import org.apache.maven.model.PomClassicDomainModel;
|
||||
import org.apache.maven.model.DomainModel;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
public class PomTestWrapper
|
||||
{
|
||||
|
||||
private PomClassicDomainModel domainModel;
|
||||
private DomainModel domainModel;
|
||||
|
||||
private File pomFile;
|
||||
|
||||
|
@ -44,13 +44,13 @@ public class PomTestWrapper
|
|||
JXPathContextReferenceImpl.addNodePointerFactory( new Xpp3DomPointerFactory() );
|
||||
}
|
||||
|
||||
public PomTestWrapper( PomClassicDomainModel domainModel )
|
||||
public PomTestWrapper( DomainModel domainModel )
|
||||
throws IOException
|
||||
{
|
||||
this( null, domainModel );
|
||||
}
|
||||
|
||||
public PomTestWrapper( File pomFile, PomClassicDomainModel domainModel )
|
||||
public PomTestWrapper( File pomFile, DomainModel domainModel )
|
||||
throws IOException
|
||||
{
|
||||
if ( domainModel == null )
|
||||
|
@ -93,7 +93,7 @@ public class PomTestWrapper
|
|||
throw new IllegalArgumentException( "file: null" );
|
||||
}
|
||||
|
||||
this.domainModel = new PomClassicDomainModel( file );
|
||||
this.domainModel = new DomainModel( file );
|
||||
context = JXPathContext.newContext( domainModel.getModel() );
|
||||
}
|
||||
|
||||
|
@ -102,11 +102,11 @@ public class PomTestWrapper
|
|||
return mavenProject;
|
||||
}
|
||||
|
||||
public PomClassicDomainModel getDomainModel()
|
||||
public DomainModel getDomainModel()
|
||||
throws IOException {
|
||||
if ( domainModel == null && mavenProject != null )
|
||||
{
|
||||
domainModel = new PomClassicDomainModel( mavenProject.getModel() );
|
||||
domainModel = new DomainModel( mavenProject.getModel() );
|
||||
int lineageCount = 1;
|
||||
for ( MavenProject parent = mavenProject.getParent(); parent != null; parent = parent.getParent() )
|
||||
{
|
||||
|
|
|
@ -1,8 +1,288 @@
|
|||
package org.apache.maven.model;
|
||||
|
||||
public interface DomainModel {
|
||||
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 org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||
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;
|
||||
|
||||
public class DomainModel
|
||||
{
|
||||
|
||||
/**
|
||||
* Bytes containing the underlying model
|
||||
*/
|
||||
private byte[] inputBytes;
|
||||
|
||||
private String id;
|
||||
|
||||
private File file;
|
||||
|
||||
private File parentFile;
|
||||
|
||||
private File projectDirectory;
|
||||
|
||||
private int lineageCount;
|
||||
|
||||
private boolean isMostSpecialized = false;
|
||||
|
||||
private String parentGroupId = null, parentArtifactId = null, parentVersion = null, parentId = null, parentRelativePath;
|
||||
|
||||
protected Model model;
|
||||
|
||||
public Model getModel() throws IOException
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
private void initializeProperties(Model model)
|
||||
{
|
||||
String groupId = null, artifactId = null, version = null;
|
||||
|
||||
groupId = model.getGroupId();
|
||||
artifactId = model.getArtifactId();
|
||||
version = model.getVersion();
|
||||
|
||||
if( model.getParent() != null)
|
||||
{
|
||||
parentArtifactId =model.getParent().getArtifactId();
|
||||
parentGroupId = model.getParent().getGroupId();
|
||||
parentVersion = model.getParent().getVersion();
|
||||
parentRelativePath = model.getParent().getRelativePath();
|
||||
|
||||
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 DomainModel( File file )
|
||||
throws IOException
|
||||
{
|
||||
this( new FileInputStream( file ) );
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public DomainModel( InputStream is )
|
||||
throws IOException
|
||||
{
|
||||
this.inputBytes = IOUtil.toByteArray( is);
|
||||
|
||||
MavenXpp3Reader reader = new MavenXpp3Reader();
|
||||
try
|
||||
{
|
||||
model = reader.read( new ByteArrayInputStream( inputBytes ), false ) ;
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
throw new IOException( e.getMessage() );
|
||||
}
|
||||
|
||||
initializeProperties( model );
|
||||
}
|
||||
|
||||
public DomainModel(Model model) throws IOException {
|
||||
this (model, false);
|
||||
}
|
||||
|
||||
public DomainModel(Model model, boolean b) throws IOException {
|
||||
this.model = model;
|
||||
this.isMostSpecialized = b;
|
||||
|
||||
|
||||
initializeProperties( model );
|
||||
|
||||
}
|
||||
|
||||
public File getParentFile()
|
||||
{
|
||||
return parentFile;
|
||||
}
|
||||
|
||||
public void setParentFile( File 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.
|
||||
*
|
||||
* @param projectDirectory
|
||||
*/
|
||||
public void setProjectDirectory(File projectDirectory)
|
||||
{
|
||||
this.projectDirectory = projectDirectory;
|
||||
}
|
||||
|
||||
public File getProjectDirectory()
|
||||
{
|
||||
return projectDirectory;
|
||||
}
|
||||
|
||||
public boolean isPomInBuild()
|
||||
{
|
||||
return projectDirectory != null;
|
||||
}
|
||||
|
||||
public String getParentId() throws IOException
|
||||
{
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public String getRelativePathOfParent()
|
||||
{
|
||||
return parentRelativePath;
|
||||
}
|
||||
|
||||
public String getId() throws IOException
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean matchesParentOf( DomainModel domainModel ) throws IOException
|
||||
{
|
||||
if ( domainModel == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "domainModel: null" );
|
||||
}
|
||||
|
||||
return getId().equals(domainModel.getParentId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns XML model as string
|
||||
*
|
||||
* @return XML model as string
|
||||
*/
|
||||
public String asString() throws IOException
|
||||
{
|
||||
return IOUtil.toString( ReaderFactory.newXmlReader( getInputStream() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.shared.model.InputStreamDomainModel#getInputStream()
|
||||
*/
|
||||
public InputStream getInputStream() throws IOException
|
||||
{
|
||||
if(inputBytes != null)
|
||||
{
|
||||
byte[] copy = new byte[inputBytes.length];
|
||||
System.arraycopy( inputBytes, 0, copy, 0, inputBytes.length );
|
||||
return new ByteArrayInputStream( copy );
|
||||
}
|
||||
else
|
||||
{
|
||||
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();
|
||||
return new ByteArrayInputStream(inputBytes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return file of pom. May be null.
|
||||
*/
|
||||
public File getFile()
|
||||
{
|
||||
return file;
|
||||
}
|
||||
|
||||
public int getLineageCount()
|
||||
{
|
||||
return lineageCount;
|
||||
}
|
||||
|
||||
public void setLineageCount( int lineageCount )
|
||||
{
|
||||
this.lineageCount = lineageCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this.asString.equals(o.asString()), otherwise false.
|
||||
*
|
||||
* @param o domain model
|
||||
* @return true if this.asString.equals(o.asString()), otherwise false.
|
||||
*/
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
try {
|
||||
return o instanceof DomainModel && getId().equals( ( (DomainModel) o ).getId() );
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMostSpecialized()
|
||||
{
|
||||
return isMostSpecialized;
|
||||
}
|
||||
|
||||
public void setMostSpecialized( boolean isMostSpecialized )
|
||||
{
|
||||
this.isMostSpecialized = isMostSpecialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.valueOf( id );
|
||||
}
|
||||
|
||||
boolean isMostSpecialized();
|
||||
|
||||
void setMostSpecialized(boolean isMostSpecialized);
|
||||
}
|
||||
|
|
|
@ -1,288 +0,0 @@
|
|||
package org.apache.maven.model;
|
||||
|
||||
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 org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Reader;
|
||||
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
|
||||
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;
|
||||
|
||||
public class PomClassicDomainModel implements DomainModel
|
||||
{
|
||||
|
||||
/**
|
||||
* Bytes containing the underlying model
|
||||
*/
|
||||
private byte[] inputBytes;
|
||||
|
||||
private String id;
|
||||
|
||||
private File file;
|
||||
|
||||
private File parentFile;
|
||||
|
||||
private File projectDirectory;
|
||||
|
||||
private int lineageCount;
|
||||
|
||||
private boolean isMostSpecialized = false;
|
||||
|
||||
private String parentGroupId = null, parentArtifactId = null, parentVersion = null, parentId = null, parentRelativePath;
|
||||
|
||||
protected Model model;
|
||||
|
||||
public Model getModel() throws IOException
|
||||
{
|
||||
return model;
|
||||
}
|
||||
|
||||
private void initializeProperties(Model model)
|
||||
{
|
||||
String groupId = null, artifactId = null, version = null;
|
||||
|
||||
groupId = model.getGroupId();
|
||||
artifactId = model.getArtifactId();
|
||||
version = model.getVersion();
|
||||
|
||||
if( model.getParent() != null)
|
||||
{
|
||||
parentArtifactId =model.getParent().getArtifactId();
|
||||
parentGroupId = model.getParent().getGroupId();
|
||||
parentVersion = model.getParent().getVersion();
|
||||
parentRelativePath = model.getParent().getRelativePath();
|
||||
|
||||
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 )
|
||||
throws IOException
|
||||
{
|
||||
this( new FileInputStream( file ) );
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public PomClassicDomainModel( InputStream is )
|
||||
throws IOException
|
||||
{
|
||||
this.inputBytes = IOUtil.toByteArray( is);
|
||||
|
||||
MavenXpp3Reader reader = new MavenXpp3Reader();
|
||||
try
|
||||
{
|
||||
model = reader.read( new ByteArrayInputStream( inputBytes ), false ) ;
|
||||
}
|
||||
catch ( XmlPullParserException e )
|
||||
{
|
||||
throw new IOException( e.getMessage() );
|
||||
}
|
||||
|
||||
initializeProperties( model );
|
||||
}
|
||||
|
||||
public PomClassicDomainModel(Model model) throws IOException {
|
||||
this (model, false);
|
||||
}
|
||||
|
||||
public PomClassicDomainModel(Model model, boolean b) throws IOException {
|
||||
this.model = model;
|
||||
this.isMostSpecialized = b;
|
||||
|
||||
|
||||
initializeProperties( model );
|
||||
|
||||
}
|
||||
|
||||
public File getParentFile()
|
||||
{
|
||||
return parentFile;
|
||||
}
|
||||
|
||||
public void setParentFile( File 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.
|
||||
*
|
||||
* @param projectDirectory
|
||||
*/
|
||||
public void setProjectDirectory(File projectDirectory)
|
||||
{
|
||||
this.projectDirectory = projectDirectory;
|
||||
}
|
||||
|
||||
public File getProjectDirectory()
|
||||
{
|
||||
return projectDirectory;
|
||||
}
|
||||
|
||||
public boolean isPomInBuild()
|
||||
{
|
||||
return projectDirectory != null;
|
||||
}
|
||||
|
||||
public String getParentId() throws IOException
|
||||
{
|
||||
return parentId;
|
||||
}
|
||||
|
||||
public String getRelativePathOfParent()
|
||||
{
|
||||
return parentRelativePath;
|
||||
}
|
||||
|
||||
public String getId() throws IOException
|
||||
{
|
||||
return id;
|
||||
}
|
||||
|
||||
public boolean matchesParentOf( PomClassicDomainModel domainModel ) throws IOException
|
||||
{
|
||||
if ( domainModel == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "domainModel: null" );
|
||||
}
|
||||
|
||||
return getId().equals(domainModel.getParentId());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns XML model as string
|
||||
*
|
||||
* @return XML model as string
|
||||
*/
|
||||
public String asString() throws IOException
|
||||
{
|
||||
return IOUtil.toString( ReaderFactory.newXmlReader( getInputStream() ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* @see org.apache.maven.shared.model.InputStreamDomainModel#getInputStream()
|
||||
*/
|
||||
public InputStream getInputStream() throws IOException
|
||||
{
|
||||
if(inputBytes != null)
|
||||
{
|
||||
byte[] copy = new byte[inputBytes.length];
|
||||
System.arraycopy( inputBytes, 0, copy, 0, inputBytes.length );
|
||||
return new ByteArrayInputStream( copy );
|
||||
}
|
||||
else
|
||||
{
|
||||
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();
|
||||
return new ByteArrayInputStream(inputBytes);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return file of pom. May be null.
|
||||
*/
|
||||
public File getFile()
|
||||
{
|
||||
return file;
|
||||
}
|
||||
|
||||
public int getLineageCount()
|
||||
{
|
||||
return lineageCount;
|
||||
}
|
||||
|
||||
public void setLineageCount( int lineageCount )
|
||||
{
|
||||
this.lineageCount = lineageCount;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true if this.asString.equals(o.asString()), otherwise false.
|
||||
*
|
||||
* @param o domain model
|
||||
* @return true if this.asString.equals(o.asString()), otherwise false.
|
||||
*/
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
try {
|
||||
return o instanceof PomClassicDomainModel && getId().equals( ( (PomClassicDomainModel) o ).getId() );
|
||||
} catch (IOException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isMostSpecialized()
|
||||
{
|
||||
return isMostSpecialized;
|
||||
}
|
||||
|
||||
public void setMostSpecialized( boolean isMostSpecialized )
|
||||
{
|
||||
this.isMostSpecialized = isMostSpecialized;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.valueOf( id );
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -71,15 +71,15 @@ public class ProcessorContext
|
|||
* @return
|
||||
* @throws IOException
|
||||
*/
|
||||
public static PomClassicDomainModel build( List<DomainModel> domainModels, List<ModelEventListener> listeners )
|
||||
public static DomainModel build( List<DomainModel> domainModels, List<ModelEventListener> listeners )
|
||||
throws IOException
|
||||
{
|
||||
PomClassicDomainModel child = null;
|
||||
DomainModel child = null;
|
||||
for ( DomainModel domainModel : domainModels )
|
||||
{
|
||||
if(domainModel.isMostSpecialized())
|
||||
{
|
||||
child = (PomClassicDomainModel) domainModel;
|
||||
child = (DomainModel) domainModel;
|
||||
}
|
||||
}
|
||||
if(child == null)
|
||||
|
@ -103,14 +103,14 @@ public class ProcessorContext
|
|||
listener.fire(target);
|
||||
}
|
||||
}
|
||||
PomClassicDomainModel domainModel = new PomClassicDomainModel( target, child.isMostSpecialized() );
|
||||
DomainModel domainModel = new DomainModel( target, child.isMostSpecialized() );
|
||||
domainModel.setProjectDirectory(child.getProjectDirectory());
|
||||
domainModel.setParentFile(child.getParentFile());
|
||||
|
||||
return domainModel;
|
||||
}
|
||||
|
||||
public static PomClassicDomainModel mergeProfilesIntoModel(Collection<Profile> profiles, PomClassicDomainModel domainModel) throws IOException
|
||||
public static DomainModel mergeProfilesIntoModel(Collection<Profile> profiles, DomainModel domainModel) throws IOException
|
||||
{
|
||||
List<Model> profileModels = new ArrayList<Model>();
|
||||
List<Model> externalProfileModels = new ArrayList<Model>();
|
||||
|
@ -168,7 +168,7 @@ public class ProcessorContext
|
|||
//TODO: Merge Dependency Management
|
||||
target.setDependencyManagement( depMng );
|
||||
|
||||
PomClassicDomainModel targetModel = new PomClassicDomainModel( target, domainModel.isMostSpecialized());
|
||||
DomainModel targetModel = new DomainModel( target, domainModel.isMostSpecialized());
|
||||
targetModel.setParentFile(domainModel.getParentFile());
|
||||
targetModel.setProjectDirectory(domainModel.getProjectDirectory());
|
||||
return targetModel;
|
||||
|
@ -198,7 +198,7 @@ public class ProcessorContext
|
|||
List<Model> models = new ArrayList<Model>();
|
||||
for(DomainModel domainModel : domainModels)
|
||||
{
|
||||
PomClassicDomainModel dm = (PomClassicDomainModel) domainModel;
|
||||
DomainModel dm = (DomainModel) domainModel;
|
||||
if(dm.getModel() != null)
|
||||
{
|
||||
if(dm.isMostSpecialized())
|
||||
|
|
|
@ -27,7 +27,7 @@ import javax.xml.stream.XMLStreamReader;
|
|||
|
||||
import org.apache.maven.model.Build;
|
||||
import org.apache.maven.model.Model;
|
||||
import org.apache.maven.model.PomClassicDomainModel;
|
||||
import org.apache.maven.model.DomainModel;
|
||||
import org.apache.maven.model.ProjectUri;
|
||||
import org.apache.maven.model.Reporting;
|
||||
import org.apache.maven.model.Resource;
|
||||
|
@ -172,7 +172,7 @@ public class DefaultInterpolator
|
|||
try
|
||||
{
|
||||
String xml = unmarshalModelPropertiesToXml( modelProperties, ProjectUri.baseUri );
|
||||
Model m = new PomClassicDomainModel( new ByteArrayInputStream( xml.getBytes( "UTF-8" ) ) ).getModel();
|
||||
Model m = new DomainModel( new ByteArrayInputStream( xml.getBytes( "UTF-8" ) ) ).getModel();
|
||||
if ( projectDirectory != null )
|
||||
{
|
||||
alignPaths( m, projectDirectory );
|
||||
|
|
Loading…
Reference in New Issue