You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@maven.apache.org by jv...@apache.org on 2005/05/16 03:10:07 UTC

svn commit: r170292 - /maven/components/trunk/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java

Author: jvanzyl
Date: Sun May 15 18:10:04 2005
New Revision: 170292

URL: http://svn.apache.org/viewcvs?rev=170292&view=rev
Log:
o improving the ease of use of metadata:

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


Modified:
    maven/components/trunk/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java

Modified: maven/components/trunk/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java
URL: http://svn.apache.org/viewcvs/maven/components/trunk/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java?rev=170292&r1=170291&r2=170292&view=diff
==============================================================================
--- maven/components/trunk/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java (original)
+++ maven/components/trunk/maven-archiver/src/main/java/org/apache/maven/archiver/MavenArchiver.java Sun May 15 18:10:04 2005
@@ -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 @@
         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.
+        // ----------------------------------------------------------------------
+
+        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" );
 
-        archiver.addFile( project.getFile(), "META-INF/maven/pom.xml" );
+        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 @@
         archiver.addConfiguredManifest( manifest );
 
         archiver.setCompress( archiveConfiguration.isCompress() );
+
         archiver.setIndex( archiveConfiguration.isIndex() );
+
         archiver.setDestFile( archiveFile );
 
         // create archive
         archiver.createArchive();
+
+        // Cleanup
+
+        pomPropertiesFile.delete();
     }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@maven.apache.org
For additional commands, e-mail: dev-help@maven.apache.org