maven-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ma...@apache.org
Subject svn commit: r632036 - in /maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime: ClassLoaderHelper.java MavenRuntimeVisitor.java PropertiesMavenRuntimeVisitor.java XMLMavenRuntimeVisitor.java
Date Thu, 28 Feb 2008 16:07:55 GMT
Author: markh
Date: Thu Feb 28 08:07:44 2008
New Revision: 632036

URL: http://svn.apache.org/viewvc?rev=632036&view=rev
Log:
Changed visitor API to use URLs rather than InputStreams to save always opening a stream

Modified:
    maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/ClassLoaderHelper.java
    maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/MavenRuntimeVisitor.java
    maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/PropertiesMavenRuntimeVisitor.java
    maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/XMLMavenRuntimeVisitor.java

Modified: maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/ClassLoaderHelper.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/ClassLoaderHelper.java?rev=632036&r1=632035&r2=632036&view=diff
==============================================================================
--- maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/ClassLoaderHelper.java
(original)
+++ maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/ClassLoaderHelper.java
Thu Feb 28 08:07:44 2008
@@ -20,6 +20,7 @@
  */
 
 import java.io.IOException;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.jar.JarEntry;
@@ -163,7 +164,7 @@
             
             while ( ( entry = in.getNextJarEntry() ) != null )
             {
-                acceptJarEntry( in, entry, visitor );
+                acceptJarEntry( url, entry, visitor );
             }
         }
         catch ( IOException exception )
@@ -190,8 +191,8 @@
      * Invokes the specified visitor on the specified Jar entry if it corresponds to a Maven
project XML or properties
      * file.
      * 
-     * @param in
-     *            an input stream to the Jar file for this entry
+     * @param jarURL
+     *            a URL to the Jar file for this entry
      * @param entry
      *            the Jar entry to introspect
      * @param visitor
@@ -199,18 +200,27 @@
      * @throws MavenRuntimeException
      *             if an error occurs visiting the projects
      */
-    private void acceptJarEntry( JarInputStream in, JarEntry entry, MavenRuntimeVisitor visitor
)
+    private void acceptJarEntry( URL jarURL, JarEntry entry, MavenRuntimeVisitor visitor
)
         throws MavenRuntimeException
     {
         String name = entry.getName();
 
-        if ( isProjectPropertiesPath( name ) )
+        try
         {
-            visitor.visitProjectProperties( in );
+            URL url = new URL("jar:" + jarURL + "!/" + entry.getName());
+            
+            if ( isProjectPropertiesPath( name ) )
+            {
+                visitor.visitProjectProperties( url );
+            }
+            else if ( isProjectXMLPath( name ) )
+            {
+                visitor.visitProjectXML( url );
+            }
         }
-        else if ( isProjectXMLPath( name ) )
+        catch ( MalformedURLException exception )
         {
-            visitor.visitProjectXML( in );
+            throw new MavenRuntimeException( "Cannot read jar entry", exception );
         }
     }
 

Modified: maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/MavenRuntimeVisitor.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/MavenRuntimeVisitor.java?rev=632036&r1=632035&r2=632036&view=diff
==============================================================================
--- maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/MavenRuntimeVisitor.java
(original)
+++ maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/MavenRuntimeVisitor.java
Thu Feb 28 08:07:44 2008
@@ -19,7 +19,7 @@
  * under the License.
  */
 
-import java.io.InputStream;
+import java.net.URL;
 
 /**
  * Defines a visitor for the Maven runtime environment.
@@ -32,20 +32,20 @@
     /**
      * Visits the specified Maven project properties.
      * 
-     * @param in
-     *            an input stream to the properties
+     * @param url
+     *            a URL to the properties
      * @throws MavenRuntimeException
      *             if an error occurs visiting the stream
      */
-    void visitProjectProperties( InputStream in ) throws MavenRuntimeException;
+    void visitProjectProperties( URL url ) throws MavenRuntimeException;
 
     /**
      * Visits the specified Maven project XML.
      * 
-     * @param in
-     *            an input stream to the XML
+     * @param url
+     *            a URL to the XML
      * @throws MavenRuntimeException
      *             if an error occurs visiting the stream
      */
-    void visitProjectXML( InputStream in ) throws MavenRuntimeException;
+    void visitProjectXML( URL url ) throws MavenRuntimeException;
 }

Modified: maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/PropertiesMavenRuntimeVisitor.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/PropertiesMavenRuntimeVisitor.java?rev=632036&r1=632035&r2=632036&view=diff
==============================================================================
--- maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/PropertiesMavenRuntimeVisitor.java
(original)
+++ maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/PropertiesMavenRuntimeVisitor.java
Thu Feb 28 08:07:44 2008
@@ -21,6 +21,7 @@
 
 import java.io.IOException;
 import java.io.InputStream;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -73,9 +74,9 @@
     /**
      * {@inheritDoc}
      */
-    public void visitProjectProperties( InputStream in ) throws MavenRuntimeException
+    public void visitProjectProperties( URL url ) throws MavenRuntimeException
     {
-        MavenProjectProperties project = parseProjectProperties( in );
+        MavenProjectProperties project = parseProjectProperties( url );
 
         projects.add( project );
     }
@@ -83,7 +84,7 @@
     /**
      * {@inheritDoc}
      */
-    public void visitProjectXML( InputStream in ) throws MavenRuntimeException
+    public void visitProjectXML( URL url ) throws MavenRuntimeException
     {
         // no-op
     }
@@ -105,23 +106,41 @@
     /**
      * Parses the specified Maven project properties into a <code>MavenProjectProperties</code>
object.
      * 
-     * @param in
-     *            an input stream to the Maven project properties
+     * @param url
+     *            a URL to the Maven project properties
      * @return a <code>MavenProjectProperties</code> object that represents the
properties
      * @throws MavenRuntimeException
      *             if an error occurs parsing the properties
      */
-    private MavenProjectProperties parseProjectProperties( InputStream in ) throws MavenRuntimeException
+    private MavenProjectProperties parseProjectProperties( URL url ) throws MavenRuntimeException
     {
         Properties properties = new Properties();
 
+        InputStream in = null;
+        
         try
         {
+            in = url.openStream();
+
             properties.load( in );
         }
         catch ( IOException exception )
         {
             throw new MavenRuntimeException( "Cannot read project properties", exception
);
+        }
+        finally
+        {
+            if ( in != null )
+            {
+                try
+                {
+                    in.close();
+                }
+                catch ( IOException exception )
+                {
+                    throw new MavenRuntimeException( "Cannot close project properties", exception
);
+                }
+            }
         }
 
         String groupId = properties.getProperty( GROUP_ID_PROPERTY );

Modified: maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/XMLMavenRuntimeVisitor.java
URL: http://svn.apache.org/viewvc/maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/XMLMavenRuntimeVisitor.java?rev=632036&r1=632035&r2=632036&view=diff
==============================================================================
--- maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/XMLMavenRuntimeVisitor.java
(original)
+++ maven/sandbox/trunk/shared/maven-runtime/src/main/java/org/apache/maven/shared/runtime/XMLMavenRuntimeVisitor.java
Thu Feb 28 08:07:44 2008
@@ -20,7 +20,7 @@
  */
 
 import java.io.IOException;
-import java.io.InputStream;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.List;
@@ -64,7 +64,7 @@
     /**
      * {@inheritDoc}
      */
-    public void visitProjectProperties( InputStream in ) throws MavenRuntimeException
+    public void visitProjectProperties( URL url ) throws MavenRuntimeException
     {
         // no-op
     }
@@ -72,9 +72,9 @@
     /**
      * {@inheritDoc}
      */
-    public void visitProjectXML( InputStream in ) throws MavenRuntimeException
+    public void visitProjectXML( URL url ) throws MavenRuntimeException
     {
-        MavenProject project = parseProjectXML( in );
+        MavenProject project = parseProjectXML( url );
 
         projects.add( project );
     }
@@ -121,19 +121,19 @@
     /**
      * Parses the specified Maven project XML into a <code>MavenProject</code>
object.
      * 
-     * @param in
-     *            an input stream to the Maven project XML
+     * @param url
+     *            a URL to the Maven project XML
      * @return a <code>MavenProject</code> object that represents the XML
      * @throws MavenRuntimeException
      *             if an error occurs parsing the XML
      */
-    private MavenProject parseProjectXML( InputStream in ) throws MavenRuntimeException
+    private MavenProject parseProjectXML( URL url ) throws MavenRuntimeException
     {
         MavenXpp3Reader reader = new MavenXpp3Reader();
 
         try
         {
-            Model model = reader.read( ReaderFactory.newXmlReader( in ) );
+            Model model = reader.read( ReaderFactory.newXmlReader( url ) );
 
             MavenProject project = new MavenProject( model );
 



Mime
View raw message