myfaces-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lu4...@apache.org
Subject svn commit: r643636 - in /myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder: IOUtils.java MakeTagsMojo.java
Date Tue, 01 Apr 2008 23:01:21 GMT
Author: lu4242
Date: Tue Apr  1 16:01:17 2008
New Revision: 643636

URL: http://svn.apache.org/viewvc?rev=643636&view=rev
Log:
get metadata from artifacts

Modified:
    myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/IOUtils.java
    myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java

Modified: myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/IOUtils.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/IOUtils.java?rev=643636&r1=643635&r2=643636&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/IOUtils.java
(original)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/IOUtils.java
Tue Apr  1 16:01:17 2008
@@ -23,15 +23,24 @@
 import java.io.FileReader;
 import java.io.FileWriter;
 import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
 import java.io.PrintWriter;
 import java.io.Reader;
 import java.io.Writer;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
 
 import javax.xml.parsers.ParserConfigurationException;
 import javax.xml.parsers.SAXParserFactory;
 
 import org.apache.commons.digester.Digester;
+import org.apache.maven.artifact.Artifact;
 import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.project.MavenProject;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.io.XmlWriter;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.model.Model;
 import org.xml.sax.SAXException;
@@ -41,6 +50,9 @@
  */
 public class IOUtils
 {
+    
+    private final static String MYFACES_METADATA = "META-INF/myfaces-metadata.xml";
+    
     /**
      * Write the contents of the model to an xml file.
      */
@@ -125,7 +137,96 @@
             }
         }
     }
+    
+    public static List getModelsFromArtifacts(MavenProject project)
+            throws MojoExecutionException
+    {
+        List models = new ArrayList();
+
+        for (Iterator it = project.getArtifacts().iterator(); it.hasNext();)
+        {
+
+            Artifact artifact = (Artifact) it.next();
+
+            //This is safe since we have all depencencies on the
+            //pom, so they are downloaded first by maven.
+            File jarFile = artifact.getFile();
+
+            URLClassLoader archetypeJarLoader;
 
+            InputStream is = null;
+            try
+            {
+                URL[] urls = new URL[1];
+                urls[0] = jarFile.toURL();
+                archetypeJarLoader = new URLClassLoader(urls);
+
+                 is = getStream(MYFACES_METADATA, archetypeJarLoader);
+
+                if (is == null)
+                {
+                    
+                    //System.out.println("Artifact: "
+                    //        + artifact.getFile().getName()
+                    //        + " does not have META-INF/myfaces-metadata.xml");
+                }
+                else
+                {
+                    Reader r = null;
+                    try {
+                        r = new InputStreamReader(is);
+                        Model m = readModel(r);
+                        models.add(m);
+                        r.close();
+                    }catch(IOException e){
+                        throw new MojoExecutionException(
+                                "Error reading myfaces-metadata.xml form "
+                                        + artifact.getFile().getName(), e);             
          
+                    }finally{
+                        if (r != null){
+                            try {
+                                r.close();
+                            }catch(IOException e){
+                                //ignore
+                            }
+                        }
+                    }
+                   
+                    System.out.println("Artifact: "
+                            + artifact.getFile().getName()
+                            + " have META-INF/myfaces-metadata.xml");
+                }
+            }
+            catch (IOException e)
+            {
+                throw new MojoExecutionException(
+                        "Error reading myfaces-metadata.xml form "
+                                + artifact.getFile().getName(), e);
+            }
+            finally
+            {
+                if (is != null){
+                    try {
+                        is.close();
+                    }catch(IOException ex){
+                        //ignore
+                    }
+                }
+            }
+        }
+        return models;
+    }
+        
+    private static InputStream getStream( String name,
+            ClassLoader loader )
+    {
+        if ( loader == null )
+        {
+            return Thread.currentThread().getContextClassLoader().getResourceAsStream( name
);
+        }
+        return loader.getResourceAsStream( name );
+    }
+    
     /**
      * Read the contents of the model from a provided Reader object.
      */

Modified: myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java?rev=643636&r1=643635&r2=643636&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java
(original)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java
Tue Apr  1 16:01:17 2008
@@ -24,6 +24,7 @@
 import java.io.OutputStreamWriter;
 import java.io.Writer;
 import java.util.Iterator;
+import java.util.List;
 import java.util.Properties;
 import java.util.logging.Logger;
 
@@ -115,7 +116,7 @@
      * @parameter
      */
     private String jsfVersion;
-
+    
     /**
      * Execute the Mojo.
      */
@@ -123,10 +124,12 @@
     {
         // This command makes Maven compile the generated source:
         // getProject().addCompileSourceRoot( absoluteGeneratedPath.getPath() );
+        
         try
-        {
+        {            
             Model model = IOUtils.loadModel(new File(buildDirectory,
                     metadataFile));
+            List models = IOUtils.getModelsFromArtifacts(project);
             new Flattener(model).flatten();
             generateComponents(model);
         }
@@ -139,7 +142,7 @@
             throw new MojoExecutionException("Error generating components", e);
         }
     }
-
+    
     private VelocityEngine initVelocity() throws MojoExecutionException
     {
 
@@ -197,7 +200,7 @@
                 _generateComponent(velocityEngine, component);
             }
         }
-        throw new MojoExecutionException("stopping..");
+        //throw new MojoExecutionException("stopping..");
     }
 
     /**



Mime
View raw message