You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by jv...@apache.org on 2008/02/14 20:18:33 UTC

svn commit: r627847 - /maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java

Author: jvanzyl
Date: Thu Feb 14 11:18:30 2008
New Revision: 627847

URL: http://svn.apache.org/viewvc?rev=627847&view=rev
Log:
ARCHETYPE-133: Making sure that the version is taken from the actual pom.properties and not hardcoded values in the code.

Modified:
    maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java

Modified: maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java
URL: http://svn.apache.org/viewvc/maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java?rev=627847&r1=627846&r2=627847&view=diff
==============================================================================
--- maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java (original)
+++ maven/archetype/trunk/archetype-common/src/main/java/org/apache/maven/archetype/creator/FilesetArchetypeCreator.java Thu Feb 14 11:18:30 2008
@@ -56,6 +56,7 @@
 import org.codehaus.plexus.logging.AbstractLogEnabled;
 import org.codehaus.plexus.util.DirectoryScanner;
 import org.codehaus.plexus.util.FileUtils;
+import org.codehaus.plexus.util.IOUtil;
 import org.codehaus.plexus.util.StringUtils;
 import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
@@ -65,6 +66,7 @@
 import java.io.FileOutputStream;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.InputStream;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.HashMap;
@@ -229,13 +231,13 @@
         Extension extension = new Extension();
         extension.setGroupId( "org.apache.maven.archetype" );
         extension.setArtifactId( "archetype-packaging" );
-        extension.setVersion( "2.0-SNAPSHOT" );
+        extension.setVersion( getArchetypeVersion() );
         model.getBuild().addExtension( extension );
 
         Plugin plugin = new Plugin();
         plugin.setGroupId( "org.apache.maven.plugins" );
         plugin.setArtifactId( "maven-archetype-plugin" );
-        plugin.setVersion( "2.0-SNAPSHOT" );
+        plugin.setVersion( getArchetypeVersion() );
         plugin.setExtensions( true );
         model.getBuild().addPlugin( plugin );
         getLogger().debug( "Creating archetype's pom" );
@@ -2228,5 +2230,45 @@
     {
         OldArchetypeDescriptorXpp3Writer writer = new OldArchetypeDescriptorXpp3Writer();
         writer.write( new FileWriter( oldDescriptorFile ), oldDescriptor );
+    }
+    
+    private static final String MAVEN_PROPERTIES = "META-INF/maven/org.apache.maven.archetype/archetype-common/pom.properties";
+    
+    public String getArchetypeVersion()
+    {
+        InputStream is = null;
+        
+        // This should actually come from the pom.properties at testing but it's not generated and put into the JAR, it happens
+        // as part of the JAR plugin which is crap as it makes testing inconsistent.
+        String version = "version";
+        
+        try
+        {
+            Properties properties = new Properties();
+
+            is = getClass().getClassLoader().getResourceAsStream( MAVEN_PROPERTIES );
+
+            if ( is != null )
+            {
+                properties.load( is );
+
+                String property = properties.getProperty( "version" );
+
+                if ( property != null )
+                {
+                    return property;
+                }
+            }
+
+            return version;
+        }
+        catch ( IOException e )
+        {
+            return version;
+        }
+        finally
+        {
+            IOUtil.close( is );
+        }
     }
 }