Resolving issue: MNG-271

o Added method to MavenProject called writeModel( Writer ) 
o Added code in MavenArchiver to export the full effective POM to ${project.build.directory}/exported-pom.xml and then embed that in the archive, rather than simply embedding ${project.file}.



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@191588 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
John Dennis Casey 2005-06-20 23:34:34 +00:00
parent 1c58065c2a
commit 07dda3c3ae
2 changed files with 39 additions and 1 deletions

View File

@ -18,13 +18,16 @@ package org.apache.maven.archiver;
import org.apache.maven.artifact.Artifact;
import org.apache.maven.artifact.DependencyResolutionRequiredException;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.apache.maven.project.MavenProject;
import org.codehaus.plexus.archiver.ArchiverException;
import org.codehaus.plexus.archiver.jar.JarArchiver;
import org.codehaus.plexus.archiver.jar.Manifest;
import org.codehaus.plexus.archiver.jar.ManifestException;
import org.codehaus.plexus.util.IOUtil;
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.io.OutputStream;
import java.io.FileOutputStream;
@ -216,7 +219,10 @@ public class MavenArchiver
String artifactId = project.getArtifactId();
archiver.addFile( project.getFile(), "META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml" );
File exportReadyPom = writeExportReadyPom( project );
archiver.addFile( exportReadyPom, "META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml" );
// ----------------------------------------------------------------------
// Create pom.properties file
@ -269,4 +275,26 @@ public class MavenArchiver
pomPropertiesFile.delete();
}
private File writeExportReadyPom( MavenProject project ) throws IOException
{
String buildDirectory = project.getBuild().getDirectory();
File fullPom = new File( buildDirectory, "exported-pom.xml" );
FileWriter fWriter = null;
try
{
fWriter = new FileWriter( fullPom );
project.writeModel( fWriter );
}
finally
{
IOUtil.close( fWriter );
}
return fullPom;
}
}

View File

@ -40,9 +40,12 @@ import org.apache.maven.model.Scm;
import org.apache.maven.model.PluginExecution;
import org.apache.maven.model.ReportPlugin;
import org.apache.maven.model.ReportSet;
import org.apache.maven.model.io.xpp3.MavenXpp3Writer;
import org.codehaus.plexus.util.xml.Xpp3Dom;
import java.io.File;
import java.io.IOException;
import java.io.Writer;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -1033,4 +1036,11 @@ public class MavenProject
{
this.executionProject = executionProject;
}
public void writeModel( Writer writer ) throws IOException
{
MavenXpp3Writer pomWriter = new MavenXpp3Writer();
pomWriter.write( writer, getModel() );
}
}