o improving the ease of use of metadata:

http://jira.codehaus.org/browse/MNG-395



git-svn-id: https://svn.apache.org/repos/asf/maven/components/trunk@170292 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason van Zyl 2005-05-16 01:10:04 +00:00
parent 6cd5fd4593
commit a7511710b8
1 changed files with 48 additions and 1 deletions

View File

@ -26,9 +26,12 @@
import java.io.File;
import java.io.IOException;
import java.io.OutputStream;
import java.io.FileOutputStream;
import java.util.Iterator;
import java.util.Set;
import java.util.List;
import java.util.Properties;
/**
* @author <a href="evenisse@apache.org">Emmanuel Venisse</a>
@ -198,12 +201,50 @@ public void createArchive( MavenProject project, MavenArchiveConfiguration archi
throws ArchiverException, ManifestException, IOException, DependencyResolutionRequiredException
{
// ----------------------------------------------------------------------
// We want to add the metadata for the project to the JAR in two forms:
//
// The first form is that of the POM itself. Applications that wish to
// access the POM for an artifact using maven tools they can.
//
// The second form is that of a properties file containing the basic
// top-level POM elements so that applications that wish to access
// POM information without the use of maven tools can do so.
// ----------------------------------------------------------------------
archiver.addFile( project.getFile(), "META-INF/maven/pom.xml" );
String groupId = project.getGroupId();
String artifactId = project.getArtifactId();
archiver.addFile( project.getFile(), "META-INF/maven/" + groupId + "/" + artifactId + "/pom.xml" );
// ----------------------------------------------------------------------
// Create pom.properties file
// ----------------------------------------------------------------------
Properties p = new Properties();
p.setProperty( "groupId", project.getGroupId() );
p.setProperty( "artifactId", project.getArtifactId() );
p.setProperty( "version", project.getVersion() );
File pomPropertiesFile = new File( project.getFile().getParentFile(), "pom.properties" );
OutputStream os = new FileOutputStream( pomPropertiesFile );
p.store( os, "Generated by Maven" );
os.close(); // stream is flushed but not closed by Properties.store()
archiver.addFile( pomPropertiesFile, "META-INF/maven/" + groupId + "/" + artifactId + "/pom.properties" );
// ----------------------------------------------------------------------
// Create the manifest
// ----------------------------------------------------------------------
String manifestFile = archiveConfiguration.getManifestFile();
if ( manifestFile != null && !"".equals( manifestFile ) )
{
archiver.setManifest( new File( manifestFile ) );
@ -215,10 +256,16 @@ public void createArchive( MavenProject project, MavenArchiveConfiguration archi
archiver.addConfiguredManifest( manifest );
archiver.setCompress( archiveConfiguration.isCompress() );
archiver.setIndex( archiveConfiguration.isIndex() );
archiver.setDestFile( archiveFile );
// create archive
archiver.createArchive();
// Cleanup
pomPropertiesFile.delete();
}
}