You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2008/04/09 04:23:36 UTC
svn commit: r646179 - in
/myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder:
BuildMetaDataMojo.java IOUtils.java model/Model.java
Author: lu4242
Date: Tue Apr 8 19:23:34 2008
New Revision: 646179
URL: http://svn.apache.org/viewvc?rev=646179&view=rev
Log:
added orderModelIds and dependencyModelIds params to build metadata
Modified:
myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/BuildMetaDataMojo.java
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/model/Model.java
Modified: myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/BuildMetaDataMojo.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/BuildMetaDataMojo.java?rev=646179&r1=646178&r2=646179&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/BuildMetaDataMojo.java (original)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/BuildMetaDataMojo.java Tue Apr 8 19:23:34 2008
@@ -19,8 +19,11 @@
package org.apache.myfaces.buildtools.maven2.plugin.builder;
import java.io.File;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
@@ -28,7 +31,6 @@
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.project.MavenProject;
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.ComponentMeta;
-import org.apache.myfaces.buildtools.maven2.plugin.builder.model.ConverterMeta;
import org.apache.myfaces.buildtools.maven2.plugin.builder.model.Model;
import org.apache.myfaces.buildtools.maven2.plugin.builder.qdox.QdoxModelBuilder;
import org.apache.myfaces.buildtools.maven2.plugin.builder.utils.BuildException;
@@ -92,12 +94,33 @@
private String replacePackagePrefixTagTo;
/**
+ *
+ * @parameter
+ */
+ private List orderModelIds;
+
+ /**
+ * @parameter
+ */
+ private List dependencyModelIds;
+
+ /**
* Execute the Mojo.
*/
public void execute() throws MojoExecutionException
{
Model model = buildModel(project);
- List models = IOUtils.getModelsFromArtifacts(project);
+ List models = null;
+ if (dependencyModelIds != null)
+ {
+ models = IOUtils.getModelsFromArtifacts(project,dependencyModelIds);
+ }
+ else
+ {
+ models = IOUtils.getModelsFromArtifacts(project);
+ }
+
+ models = sortModels(models);
for (Iterator it = models.iterator(); it.hasNext();){
Model artifactModel = (Model) it.next();
@@ -107,6 +130,47 @@
resolveReplacePackage(model);
IOUtils.saveModel(model, new File(targetDirectory, outputFile));
+ }
+
+ /**
+ * This function order the models as suggested by the modelIdOrder.
+ * Tomahawk sandbox depends from myfaces-api and tomahawk core, so
+ * the myfaces-metadata.xml of tomahawk core must be merged first
+ * and then myfaces-api.
+ *
+ * @param models
+ * @return
+ */
+ private List sortModels(List models)
+ {
+ if (orderModelIds == null)
+ {
+ //No changes
+ return models;
+ }
+
+ Map modelsMap = new HashMap();
+ List modelsSorted = new ArrayList();
+
+ for (Iterator it = models.iterator(); it.hasNext();){
+ Model artifactModel = (Model) it.next();
+ modelsMap.put(artifactModel.getModelId(), artifactModel);
+ }
+
+ for (Iterator it = orderModelIds.iterator(); it.hasNext();){
+ String modelId = (String) it.next();
+
+ Model artifactModel = null;
+ if ( (artifactModel = (Model) modelsMap.get(modelId)) != null)
+ {
+ modelsMap.remove(modelId);
+ modelsSorted.add(artifactModel);
+ }
+ }
+
+ modelsSorted.addAll(modelsMap.values());
+
+ return modelsSorted;
}
private void resolveReplacePackage(Model model)
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=646179&r1=646178&r2=646179&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 8 19:23:34 2008
@@ -33,6 +33,7 @@
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
+import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.parsers.SAXParserFactory;
@@ -142,80 +143,199 @@
throws MojoExecutionException
{
List models = new ArrayList();
-
+
for (Iterator it = project.getArtifacts().iterator(); it.hasNext();)
{
Artifact artifact = (Artifact) it.next();
+
+ if ("compile".equals(artifact.getScope())
+ || "provided".equals(artifact.getScope())
+ || "system".equals(artifact.getScope()))
+ {
+ //This is safe since we have all depencencies on the
+ //pom, so they are downloaded first by maven.
+ File jarFile = artifact.getFile();
- //This is safe since we have all depencencies on the
- //pom, so they are downloaded first by maven.
- File jarFile = artifact.getFile();
-
- URLClassLoader archetypeJarLoader;
+ 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
+ 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
+ }
}
-
- 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
+ }
+ return models;
+ }
+
+ public static List getModelsFromArtifacts(MavenProject project,
+ List dependencyModelIds) throws MojoExecutionException
+ {
+ List models = new ArrayList();
+
+ for (Iterator it = project.getArtifacts().iterator(); it.hasNext();)
+ {
+
+ Artifact artifact = (Artifact) it.next();
+
+ if ("compile".equals(artifact.getScope())
+ || "provided".equals(artifact.getScope())
+ || "system".equals(artifact.getScope()))
{
- if (is != null){
- try {
- is.close();
- }catch(IOException ex){
- //ignore
+ //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);
+ if (dependencyModelIds.contains(m.getModelId()))
+ {
+ 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 )
Modified: myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/Model.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/model/Model.java?rev=646179&r1=646178&r2=646179&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/Model.java (original)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/Model.java Tue Apr 8 19:23:34 2008
@@ -111,7 +111,11 @@
for (Iterator it = other.getComponents().iterator(); it.hasNext();)
{
ComponentMeta component = (ComponentMeta) it.next();
- this.addComponent(component);
+ //If the component is present, the actual takes precedence.
+ if (this.findComponentByClassName(component.getClassName())== null)
+ {
+ this.addComponent(component);
+ }
}
}