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/03 01:02:09 UTC

svn commit: r644103 - in /myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder: ./ model/ qdox/ utils/

Author: lu4242
Date: Wed Apr  2 16:02:06 2008
New Revision: 644103

URL: http://svn.apache.org/viewvc?rev=644103&view=rev
Log:
metadata concatenation and velocity fixes on MakeTagsMojo.java done

Added:
    myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/utils/RelativeClasspathResourceLoader.java   (with props)
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/MakeTagsMojo.java
    myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ClassMeta.java
    myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/Model.java
    myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/QdoxModelBuilder.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=644103&r1=644102&r2=644103&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 Wed Apr  2 16:02:06 2008
@@ -19,12 +19,16 @@
 package org.apache.myfaces.buildtools.maven2.plugin.builder;
 
 import java.io.File;
+import java.util.Iterator;
+import java.util.List;
 
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.maven.plugin.AbstractMojo;
 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;
@@ -67,11 +71,23 @@
     private String outputFile = "classes/META-INF/myfaces-metadata.xml";
 
     /**
+     * 
+     * @parameter expression="${project.artifactId}"
+     */
+    private String modelId;
+    /**
      * Execute the Mojo.
      */
     public void execute() throws MojoExecutionException
     {
         Model model = buildModel(project);
+        List models = IOUtils.getModelsFromArtifacts(project);
+        
+        for (Iterator it = models.iterator(); it.hasNext();){
+            Model artifactModel = (Model) it.next();
+            model.merge(artifactModel);
+        }
+        
         IOUtils.saveModel(model, new File(targetDirectory, outputFile));
     }
 
@@ -85,7 +101,8 @@
         {
             Model model = new Model();
             QdoxModelBuilder builder = new QdoxModelBuilder();
-            builder.buildModel(model, project);
+            model.setModelId(modelId);
+            builder.buildModel(model, project);            
             return model;
         }
         catch (BuildException e)

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=644103&r1=644102&r2=644103&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 Wed Apr  2 16:02:06 2008
@@ -24,7 +24,6 @@
 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;
 
@@ -129,7 +128,7 @@
         {            
             Model model = IOUtils.loadModel(new File(buildDirectory,
                     metadataFile));
-            List models = IOUtils.getModelsFromArtifacts(project);
+            //List models = IOUtils.getModelsFromArtifacts(project);
             new Flattener(model).flatten();
             generateComponents(model);
         }
@@ -147,16 +146,16 @@
     {
 
         Properties p = new Properties();
-            
+
         p.setProperty( "resource.loader", "file, class" );
-        p.setProperty( "velocimacro.library", "META-INF/tagClassMacros11.vm");
         p.setProperty( "file.resource.loader.class", "org.apache.velocity.runtime.resource.loader.FileResourceLoader");
         p.setProperty( "file.resource.loader.path", templateSourceDirectory.getPath());
-        p.setProperty( "class.resource.loader.class", "org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader" );
-        p.setProperty( "class.resource.loader.path", "src/main/resources/META-INF");
+        p.setProperty( "class.resource.loader.class", "org.apache.myfaces.buildtools.maven2.plugin.builder.utils.RelativeClasspathResourceLoader" );
+        p.setProperty( "class.resource.loader.path", "META-INF");            
+        p.setProperty( "velocimacro.library", "tagClassMacros11.vm");
         p.setProperty( "velocimacro.permissions.allow.inline","true");
         p.setProperty( "velocimacro.permissions.allow.inline.local.scope", "true");
-
+                        
         File template = new File(templateSourceDirectory, _getTemplateTagName());
         
         if (template.exists())
@@ -165,11 +164,11 @@
         }
         else
         {
-            log.info("Using template from class loader: src/main/resources/META-INF/"+_getTemplateTagName());
+            log.info("Using template from class loader: META-INF/"+_getTemplateTagName());
         }
-        
+                
         VelocityEngine velocityEngine = new VelocityEngine();
-        
+                
         try
         {
             velocityEngine.init(p);

Modified: myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ClassMeta.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/ClassMeta.java?rev=644103&r1=644102&r2=644103&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ClassMeta.java (original)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ClassMeta.java Wed Apr  2 16:02:06 2008
@@ -35,8 +35,10 @@
 public class ClassMeta
 {
     private String _className;
+    private String _packageName;
     private String _parentClassName;
     private List _interfaceClassNames = new ArrayList();
+    private String _modelId;
 
     /**
      * Write this model out as xml.
@@ -44,7 +46,9 @@
     public static void writeXml(XmlWriter out, ClassMeta mi)
     {
         out.writeElement("className", mi._className);
+        out.writeElement("packageName", mi._packageName);
         out.writeElement("parentClassName", mi._parentClassName);
+        out.writeElement("modelId", mi._modelId);
 
         if (!mi._interfaceClassNames.isEmpty())
         {
@@ -67,7 +71,9 @@
     public static void addXmlRules(Digester digester, String prefix)
     {
         digester.addBeanPropertySetter(prefix + "/className");
+        digester.addBeanPropertySetter(prefix + "/packageName");
         digester.addBeanPropertySetter(prefix + "/parentClassName");
+        digester.addBeanPropertySetter(prefix + "/modelId");
         digester.addCallMethod(prefix + "/interfaces/interface",
                 "addInterfaceClassName", 1);
         digester.addCallParam(prefix + "/interfaces/interface", 0, "name");
@@ -125,5 +131,25 @@
     public void addInterfaceClassName(String name)
     {
         _interfaceClassNames.add(name);
+    }
+
+    public void setModelId(String _modelId)
+    {
+        this._modelId = _modelId;
+    }
+
+    public String getModelId()
+    {
+        return _modelId;
+    }
+
+    public void setPackageName(String _packageName)
+    {
+        this._packageName = _packageName;
+    }
+
+    public String getPackageName()
+    {
+        return _packageName;
     }
 }

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=644103&r1=644102&r2=644103&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 Wed Apr  2 16:02:06 2008
@@ -44,6 +44,8 @@
     private Map _convertersByClass = new TreeMap();
     private Map _validatorsByClass = new TreeMap();
     private Map _renderKitsByClass = new TreeMap();
+    
+    private String _modelId;
 
     /**
      * Write this model out as xml.
@@ -55,6 +57,7 @@
     public static void writeXml(XmlWriter out, Model model)
     {
         out.beginElement("model");
+        out.writeElement("modelId", model._modelId);
 
         for (Iterator i = model._components.iterator(); i.hasNext();)
         {
@@ -89,10 +92,28 @@
         String prefix = "model";
 
         digester.addObjectCreate(prefix, Model.class);
+        digester.addBeanPropertySetter(prefix + "/modelId");
         ComponentMeta.addXmlRules(digester, prefix);
         ConverterMeta.addXmlRules(digester, prefix);
         ValidatorMeta.addXmlRules(digester, prefix);
     }
+    
+    /**
+     * Adds all components from the other model to this model, because
+     * only this info is necessary from construct a full model of 
+     * components and build correctly faces-config.xml, .tld, and
+     * component and tag classes.
+     * 
+     * @param other
+     */
+    public void merge(Model other){
+        
+        for (Iterator it = other.getComponents().iterator(); it.hasNext();)
+        {
+            ComponentMeta component = (ComponentMeta) it.next();
+            this.addComponent(component);
+        }
+    }
 
     /**
      * Adds a component to this faces config document.
@@ -223,5 +244,21 @@
     private RenderKitMeta findRenderKitByClassName(String className)
     {
         return (RenderKitMeta) _renderKitsByClass.get(className);
+    }
+
+    public void setModelId(String _modelId)
+    {
+        this._modelId = _modelId;
+    }
+
+    /**
+     * Obtain a value that indicate from where this model
+     * comes from.
+     * 
+     * @return
+     */
+    public String getModelId()
+    {
+        return _modelId;
     }
 }

Modified: myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/QdoxModelBuilder.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/qdox/QdoxModelBuilder.java?rev=644103&r1=644102&r2=644103&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/QdoxModelBuilder.java (original)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/qdox/QdoxModelBuilder.java Wed Apr  2 16:02:06 2008
@@ -20,6 +20,7 @@
 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.model.PropertyMeta;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.model.RenderKitMeta;
 import org.apache.myfaces.buildtools.maven2.plugin.builder.model.ValidatorMeta;
 
 import com.thoughtworks.qdox.JavaDocBuilder;
@@ -104,6 +105,22 @@
             JavaClass clazz = classes[i];
             processClass(processedClasses, clazz, model);
         }
+        
+        for (Iterator it = model.getComponents().iterator(); it.hasNext();)
+        {
+            ComponentMeta component = (ComponentMeta) it.next();
+            component.setModelId(model.getModelId());
+        }
+        for (Iterator it = model.getConverters().iterator(); it.hasNext();)
+        {
+            ConverterMeta converter = (ConverterMeta) it.next();
+            converter.setModelId(model.getModelId());
+        }
+        for (Iterator it = model.getValidators().iterator(); it.hasNext();)
+        {
+            ValidatorMeta validator = (ValidatorMeta) it.next();
+            validator.setModelId(model.getModelId());
+        }
     }
 
     /**
@@ -342,9 +359,12 @@
         String shortDescription = getString(clazz, "desc", props, descDflt);
 
         String converterId = getString(clazz, "id", props, null);
+        String packageClass = getString(clazz, "class", props, clazz
+                .getPackage());
 
         ConverterMeta converter = new ConverterMeta();
         converter.setClassName(clazz.getName());
+        converter.setPackageName(packageClass);
         converter.setConverterId(converterId);
         converter.setDescription(shortDescription);
         converter.setLongDescription(longDescription);
@@ -361,11 +381,14 @@
             descDflt = "no description";
         }
         String shortDescription = getString(clazz, "desc", props, descDflt);
+        String packageClass = getString(clazz, "class", props, clazz
+                .getPackage());
 
         String validatorId = getString(clazz, "id", props, null);
 
         ValidatorMeta validator = new ValidatorMeta();
         validator.setClassName(clazz.getName());
+        validator.setPackageName(packageClass);
         validator.setValidatorId(validatorId);
         validator.setDescription(shortDescription);
         validator.setLongDescription(longDescription);
@@ -404,6 +427,8 @@
         String componentName = getString(clazz, "name", props, null);
         String componentClass = getString(clazz, "class", props, clazz
                 .getName());
+        String packageClass = getString(clazz, "class", props, clazz
+                .getPackage());
 
         String longDescription = clazz.getComment();
         String descDflt = getFirstSentence(longDescription);
@@ -429,6 +454,7 @@
         initAncestry(model, clazz, component);
         component.setName(componentName);
         component.setClassName(componentClass);
+        component.setPackageName(packageClass);
         component.setDescription(shortDescription);
         component.setLongDescription(longDescription);
         component.setType(componentType);

Added: myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/utils/RelativeClasspathResourceLoader.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/utils/RelativeClasspathResourceLoader.java?rev=644103&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/utils/RelativeClasspathResourceLoader.java (added)
+++ myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/utils/RelativeClasspathResourceLoader.java Wed Apr  2 16:02:06 2008
@@ -0,0 +1,149 @@
+/*
+ *  Licensed to the Apache Software Foundation (ASF) under one
+ *  or more contributor license agreements.  See the NOTICE file
+ *  distributed with this work for additional information
+ *  regarding copyright ownership.  The ASF licenses this file
+ *  to you under the Apache License, Version 2.0 (the
+ *  "License"); you may not use this file except in compliance
+ *  with the License.  You may obtain a copy of the License at
+ * 
+ *  http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing,
+ *  software distributed under the License is distributed on an
+ *  "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ *  KIND, either express or implied.  See the License for the
+ *  specific language governing permissions and limitations
+ *  under the License.
+ */
+package org.apache.myfaces.buildtools.maven2.plugin.builder.utils;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.collections.ExtendedProperties;
+import org.apache.commons.lang.StringUtils;
+import org.apache.velocity.exception.ResourceNotFoundException;
+import org.apache.velocity.runtime.resource.Resource;
+import org.apache.velocity.runtime.resource.loader.ResourceLoader;
+import org.apache.velocity.util.ClassUtils;
+import org.apache.velocity.util.ExceptionUtils;
+
+/**
+ * This class extends ClasspathResourceLoader adding the feature
+ * of configure a path inside the classpath for load resources.
+ * 
+ * @author Leonardo
+ *
+ */
+public class RelativeClasspathResourceLoader extends ResourceLoader
+{
+
+    private List paths = new ArrayList();
+
+    public void init(ExtendedProperties configuration)
+    {
+        if (log.isTraceEnabled())
+        {
+            log
+                    .trace("RelativeClasspathResourceLoader : initialization complete.");
+        }
+
+        paths.addAll(configuration.getVector("path"));
+
+        // trim spaces from all paths
+        org.apache.velocity.util.StringUtils.trimStrings(paths);
+        if (log.isInfoEnabled())
+        {
+            // this section lets tell people what paths we will be using
+            int sz = paths.size();
+            for (int i = 0; i < sz; i++)
+            {
+                log.info("RelativeClasspathResourceLoader : adding path '"
+                        + (String) paths.get(i) + "'");
+            }
+            log
+                    .trace("RelativeClasspathResourceLoader : initialization complete.");
+        }
+    }
+
+    public InputStream getResourceStream(String name)
+            throws ResourceNotFoundException
+    {
+        if (StringUtils.isEmpty(name))
+        {
+            throw new ResourceNotFoundException("No template name provided");
+        }
+
+        /**
+         * look for resource in thread classloader first (e.g. WEB-INF\lib in
+         * a servlet container) then fall back to the system classloader.
+         */
+
+        int size = paths.size();
+        for (int i = 0; i < size; i++)
+        {
+            String path = (String) paths.get(i);
+            InputStream inputStream = null;
+
+            try
+            {
+                inputStream = findTemplate(path, name);
+            }
+            catch (IOException ioe)
+            {
+                log.error("While loading Template " + name + ": ", ioe);
+            }
+
+            if (inputStream != null)
+            {
+                return inputStream;
+            }
+        }
+        String msg = "ClasspathResourceLoader Error: cannot find resource "
+                + name;
+
+        throw new ResourceNotFoundException(msg);
+    }
+
+    private InputStream findTemplate(final String path, final String name)
+            throws IOException
+    {
+        InputStream result = null;
+
+        try
+        {
+            result = ClassUtils.getResourceAsStream(getClass(), path + "/"
+                    + name);
+        }
+        catch (Exception fnfe)
+        {
+            throw (ResourceNotFoundException) ExceptionUtils.createWithCause(
+                    ResourceNotFoundException.class, "problem with template: "
+                            + name, fnfe);
+        }
+
+        if (result == null)
+        {
+            String msg = "ClasspathResourceLoader Error: cannot find resource "
+                    + name;
+
+            throw new ResourceNotFoundException(msg);
+        }
+
+        return result;
+    }
+
+    public boolean isSourceModified(Resource resource)
+    {
+        return false;
+    }
+
+    public long getLastModified(Resource resource)
+    {
+        return 0;
+    }
+
+}

Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/utils/RelativeClasspathResourceLoader.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: myfaces/myfaces-build-tools/branches/builder_plugin/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/utils/RelativeClasspathResourceLoader.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL