mirror of https://github.com/apache/maven.git
o Deleted DomainModel
git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@778500 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
3446be4828
commit
1e2d19ab1a
|
@ -138,7 +138,6 @@ public class PomConstructionTest
|
|||
throws Exception
|
||||
{
|
||||
PomTestWrapper tester = buildPom("micromailer");
|
||||
assertEquals( 2, tester.getDomainModel().getLineageCount() );
|
||||
assertModelEquals( tester, "child-descriptor", "build/plugins[1]/executions[1]/goals[1]" );
|
||||
}
|
||||
|
||||
|
@ -147,7 +146,6 @@ public class PomConstructionTest
|
|||
throws Exception
|
||||
{
|
||||
PomTestWrapper pom = buildPom( "dependency-scope/sub" );
|
||||
System.out.println(pom.getDomainModel().asString());
|
||||
|
||||
}
|
||||
|
||||
|
@ -278,7 +276,6 @@ public class PomConstructionTest
|
|||
throws Exception
|
||||
{
|
||||
PomTestWrapper pom = buildPom( "plugin-config-duplicate/dup" );
|
||||
System.out.println(pom.getDomainModel().asString());
|
||||
}
|
||||
*/
|
||||
|
||||
|
@ -331,7 +328,6 @@ public class PomConstructionTest
|
|||
throws Exception
|
||||
{
|
||||
PomTestWrapper pom = buildPom( "consecutive_empty_elements" );
|
||||
pom.getDomainModel().asString();
|
||||
}
|
||||
|
||||
public void testOrderOfGoalsFromPluginExecutionWithoutPluginManagement()
|
||||
|
@ -1289,7 +1285,7 @@ public class PomConstructionTest
|
|||
{
|
||||
PomTestWrapper pom = buildPom( "inherited-properties-interpolation/active-profile/sub" );
|
||||
|
||||
assertEquals(1, pom.getDomainModel().getModel().getProfiles().size());
|
||||
assertEquals(1, pom.getMavenProject().getModel().getProfiles().size());
|
||||
|
||||
buildPom( "inherited-properties-interpolation/active-profile/sub", "it-parent", "it-child" );
|
||||
assertEquals( "CHILD", pom.getValue( "properties/overridden" ) );
|
||||
|
@ -1411,7 +1407,6 @@ public class PomConstructionTest
|
|||
PomTestWrapper pom = buildPom( "dependency-scope-inheritance/sub" );
|
||||
String scope = (String) pom.getValue("dependencies[1]/scope");
|
||||
assertNull("Scope not null: " + scope, scope);
|
||||
System.out.println(pom.getDomainModel().asString());
|
||||
|
||||
}
|
||||
|
||||
|
@ -1419,7 +1414,6 @@ public class PomConstructionTest
|
|||
throws Exception
|
||||
{
|
||||
PomTestWrapper pom = buildPom( "dependency-scope/sub" );
|
||||
// System.out.println(pom.getDomainModel().asString());
|
||||
}
|
||||
|
||||
//This will fail on a validation error if incorrect
|
||||
|
|
|
@ -26,14 +26,11 @@ 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.DomainModel;
|
||||
import org.apache.maven.project.MavenProject;
|
||||
|
||||
public class PomTestWrapper
|
||||
{
|
||||
|
||||
private DomainModel domainModel;
|
||||
|
||||
private File pomFile;
|
||||
|
||||
private JXPathContext context;
|
||||
|
@ -45,24 +42,6 @@ public class PomTestWrapper
|
|||
JXPathContextReferenceImpl.addNodePointerFactory( new Xpp3DomPointerFactory() );
|
||||
}
|
||||
|
||||
public PomTestWrapper( DomainModel domainModel )
|
||||
throws IOException
|
||||
{
|
||||
this( null, domainModel );
|
||||
}
|
||||
|
||||
public PomTestWrapper( File pomFile, DomainModel domainModel )
|
||||
throws IOException
|
||||
{
|
||||
if ( domainModel == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "domainModel: null" );
|
||||
}
|
||||
this.domainModel = domainModel;
|
||||
this.pomFile = pomFile;
|
||||
context = JXPathContext.newContext( domainModel.getModel());
|
||||
}
|
||||
|
||||
public PomTestWrapper( File pomFile, MavenProject mavenProject )
|
||||
throws IOException
|
||||
{
|
||||
|
@ -86,39 +65,11 @@ public class PomTestWrapper
|
|||
context = JXPathContext.newContext( mavenProject.getModel() );
|
||||
}
|
||||
|
||||
public PomTestWrapper( File file )
|
||||
throws IOException
|
||||
{
|
||||
if ( file == null )
|
||||
{
|
||||
throw new IllegalArgumentException( "file: null" );
|
||||
}
|
||||
|
||||
this.domainModel = new DomainModel( file );
|
||||
context = JXPathContext.newContext( domainModel.getModel() );
|
||||
}
|
||||
|
||||
public MavenProject getMavenProject()
|
||||
{
|
||||
return mavenProject;
|
||||
}
|
||||
|
||||
public DomainModel getDomainModel()
|
||||
throws IOException {
|
||||
if ( domainModel == null && mavenProject != null )
|
||||
{
|
||||
domainModel = new DomainModel( mavenProject.getModel() );
|
||||
int lineageCount = 1;
|
||||
for ( MavenProject parent = mavenProject.getParent(); parent != null; parent = parent.getParent() )
|
||||
{
|
||||
lineageCount++;
|
||||
}
|
||||
domainModel.setLineageCount( lineageCount );
|
||||
}
|
||||
|
||||
return this.domainModel;
|
||||
}
|
||||
|
||||
public File getBasedir()
|
||||
{
|
||||
return ( pomFile != null ) ? pomFile.getParentFile() : null;
|
||||
|
|
|
@ -69,7 +69,6 @@ public class PomConstructionWithSettingsTest
|
|||
{
|
||||
PomTestWrapper pom = buildPom( "repositories" );
|
||||
assertEquals("maven-core-it-0", pom.getValue( "repositories[1]/id" ));
|
||||
System.out.println(pom.getDomainModel().asString());
|
||||
}
|
||||
|
||||
private PomTestWrapper buildPom( String pomPath )
|
||||
|
|
|
@ -1,289 +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.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;
|
||||
|
||||
// TODO: Delete this class
|
||||
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()
|
||||
{
|
||||
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;
|
||||
this.model.setPomFile( 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 );
|
||||
}
|
||||
|
||||
|
||||
}
|
Loading…
Reference in New Issue