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/01 08:11:53 UTC

svn commit: r643289 - in /myfaces/myfaces-build-tools/branches/skitching: myfaces-builder-plugin/pom.xml myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java test/api/pom.xml

Author: lu4242
Date: Mon Mar 31 23:11:51 2008
New Revision: 643289

URL: http://svn.apache.org/viewvc?rev=643289&view=rev
Log:
basic structure for generate code using velocity (the idea is follow something similar to maven archetypes project)

Added:
    myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java   (with props)
Modified:
    myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/pom.xml
    myfaces/myfaces-build-tools/branches/skitching/test/api/pom.xml

Modified: myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/pom.xml?rev=643289&r1=643288&r2=643289&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/pom.xml (original)
+++ myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/pom.xml Mon Mar 31 23:11:51 2008
@@ -38,6 +38,12 @@
   <build>
     <plugins>
       <plugin>
+        <artifactId>maven-plugin-plugin</artifactId>
+        <configuration>
+          <goalPrefix>myfaces-builder</goalPrefix>
+        </configuration>
+      </plugin>    
+      <plugin>
         <artifactId>maven-compiler-plugin</artifactId>
         <version>2.0.2</version>
         <inherited>true</inherited>
@@ -123,6 +129,18 @@
     	<!-- <scope>runtime</scope>  -->
     </dependency>
 
+    <dependency>
+      <groupId>velocity</groupId>
+      <artifactId>velocity</artifactId>
+      <version>1.5</version>
+    </dependency>
+    
+    <dependency>
+      <groupId>org.codehaus.plexus</groupId>
+      <artifactId>plexus-velocity</artifactId>
+      <version>1.1.7</version>
+    </dependency>
+        
     <dependency>
       <groupId>log4j</groupId>
       <artifactId>log4j</artifactId>

Added: myfaces/myfaces-build-tools/branches/skitching/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/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java?rev=643289&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java (added)
+++ myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java Mon Mar 31 23:11:51 2008
@@ -0,0 +1,198 @@
+/*
+ *  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;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.OutputStreamWriter;
+import java.io.Writer;
+import java.util.Iterator;
+import java.util.logging.Logger;
+
+import org.apache.maven.archetype.exception.ArchetypeGenerationFailure;
+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.Model;
+import org.apache.myfaces.buildtools.maven2.plugin.builder.utils.BuildException;
+import org.apache.velocity.VelocityContext;
+import org.apache.velocity.context.Context;
+import org.codehaus.plexus.util.IOUtil;
+import org.codehaus.plexus.velocity.VelocityComponent;
+
+/**
+ * Maven goal to generate java source code for Component tag classes.
+ * 
+ * @version $Id$
+ * @requiresDependencyResolution compile
+ * @goal make-tags
+ * @phase generate-sources
+ */
+public class MakeTagsMojo extends AbstractMojo
+{
+    final Logger log = Logger.getLogger(MakeTagsMojo.class.getName());
+
+    /**
+     * Injected Maven project.
+     * 
+     * @parameter expression="${project}"
+     * @readonly
+     */
+    private MavenProject project;
+
+    /**
+     * @parameter expression="${project.build.directory}"
+     * @readonly
+     */
+    private File buildDirectory;
+
+    /**
+     * Injected name of file generated by earlier run of BuildMetaDataMojo goal.
+     * 
+     * @parameter
+     */
+    private String metadataFile = "classes/META-INF/myfaces-metadata.xml";
+
+    /**
+     * @parameter expression="src/main/java-templates"
+     * @required
+     */
+    private File templateSourceDirectory;
+
+    /**
+     * @parameter expression="${project.build.directory}/maven-faces-plugin/main/java"
+     * @required
+     */
+    private File generatedSourceDirectory;
+
+    /**
+     * @parameter
+     * @required
+     */
+    private String packageContains;
+
+    /**
+     * @parameter
+     * @required
+     */
+    private String typePrefix;
+
+    /**
+     * @parameter
+     */
+    private boolean force;
+
+    /**
+     * @parameter
+     */
+    private boolean suppressListenerMethods;
+
+    /**
+     * @parameter
+     */
+    private String jsfVersion;
+    
+    /**
+     * @component
+     */
+    private VelocityComponent velocity;    
+
+    /**
+     * Execute the Mojo.
+     */
+    public void execute() throws MojoExecutionException
+    {
+        // This command makes Maven compile the generated source:
+        // getProject().addCompileSourceRoot( absoluteGeneratedPath.getPath() );
+        try
+        {
+            Model model = IOUtils.loadModel(new File(buildDirectory,
+                    metadataFile));
+            new Flattener(model).flatten();
+            generateComponents(model);
+        }
+        catch (IOException e)
+        {
+            throw new MojoExecutionException("Error generating components", e);
+        }
+        catch (BuildException e)
+        {
+            throw new MojoExecutionException("Error generating components", e);
+        }
+    }
+
+    /**
+     * Generates parsed components.
+     */
+    private void generateComponents(Model model) throws IOException,
+            MojoExecutionException
+    {
+        System.out.println("Velocity:"+velocity.toString());
+        for (Iterator it = model.getComponents().iterator(); it.hasNext();){
+            ComponentMeta component = (ComponentMeta) it.next();
+            _generateComponent(component);
+        }
+        //throw new MojoExecutionException("stopping..");
+    }
+
+    /**
+     * Generates a parsed component.
+     * 
+     * @param component
+     *            the parsed component metadata
+     */
+    private void _generateComponent(ComponentMeta component)
+            throws MojoExecutionException
+    {
+        Context context = new VelocityContext();
+        context.put("component",component);
+        
+        Writer writer = null;
+
+        try
+        {
+            //writer = new OutputStreamWriter( new FileOutputStream( outFile ), encoding );
+
+            //velocity.getEngine().mergeTemplate( templateFileName, encoding, context, writer );
+
+            writer.flush();
+        }
+        catch ( Exception e )
+        {
+            throw new Exception(
+                "Error merging velocity templates: " + e.getMessage(),
+                e
+            );
+        }
+        finally
+        {
+            IOUtil.close( writer );
+            writer = null;
+        }
+
+    }
+
+    private boolean _is12()
+    {
+        return "1.2".equals(jsfVersion) || "12".equals(jsfVersion);
+    }
+
+}

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

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

Modified: myfaces/myfaces-build-tools/branches/skitching/test/api/pom.xml
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/skitching/test/api/pom.xml?rev=643289&r1=643288&r2=643289&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/branches/skitching/test/api/pom.xml (original)
+++ myfaces/myfaces-build-tools/branches/skitching/test/api/pom.xml Mon Mar 31 23:11:51 2008
@@ -24,11 +24,15 @@
         <groupId>org.apache.myfaces.buildtools</groupId>
         <artifactId>myfaces-builder-plugin</artifactId>
         <version>1.0.0-SNAPSHOT</version>
+        <configuration>
+            <packageContains>org.apache</packageContains>
+	    <typePrefix>org.apache</typePrefix>
+        </configuration>
 	<executions>
 	  <execution>
             <goals>
               <goal>build-metadata</goal>             
-              <goal>make-config</goal>
+              <goal>make-tags</goal>
             </goals>
 	  </execution>
 	</executions>