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 20:50:00 UTC
svn commit: r643513 - in
/myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin: ./
src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/
src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/
src/main/res...
Author: lu4242
Date: Tue Apr 1 11:49:55 2008
New Revision: 643513
URL: http://svn.apache.org/viewvc?rev=643513&view=rev
Log:
Generate Tag classes with velocity, step 1
Added:
myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/resources/META-INF/tagClass11.vm
myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/resources/META-INF/tagClassMacros11.vm
Modified:
myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/pom.xml
myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java
myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ComponentMeta.java
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=643513&r1=643512&r2=643513&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 Tue Apr 1 11:49:55 2008
@@ -134,12 +134,19 @@
<artifactId>velocity</artifactId>
<version>1.5</version>
</dependency>
-
+
+ <dependency>
+ <groupId>commons-collections</groupId>
+ <artifactId>commons-collections</artifactId>
+ <version>3.1</version>
+ </dependency>
+ <!--
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-velocity</artifactId>
<version>1.1.7</version>
</dependency>
+ -->
<dependency>
<groupId>log4j</groupId>
Modified: 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=643513&r1=643512&r2=643513&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java (original)
+++ myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java Tue Apr 1 11:49:55 2008
@@ -24,19 +24,21 @@
import java.io.OutputStreamWriter;
import java.io.Writer;
import java.util.Iterator;
+import java.util.Properties;
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.Template;
import org.apache.velocity.VelocityContext;
+import org.apache.velocity.app.VelocityEngine;
import org.apache.velocity.context.Context;
import org.codehaus.plexus.util.IOUtil;
-import org.codehaus.plexus.velocity.VelocityComponent;
+import org.codehaus.plexus.util.StringUtils;
/**
* Maven goal to generate java source code for Component tag classes.
@@ -72,10 +74,14 @@
private String metadataFile = "classes/META-INF/myfaces-metadata.xml";
/**
- * @parameter expression="src/main/java-templates"
- * @required
+ * @parameter expression="src/main/resources/META-INF"
*/
private File templateSourceDirectory;
+
+ /**
+ * @parameter
+ */
+ private String templateTagName;
/**
* @parameter expression="${project.build.directory}/maven-faces-plugin/main/java"
@@ -109,11 +115,6 @@
* @parameter
*/
private String jsfVersion;
-
- /**
- * @component
- */
- private VelocityComponent velocity;
/**
* Execute the Mojo.
@@ -139,18 +140,64 @@
}
}
+ private VelocityEngine initVelocity() throws MojoExecutionException
+ {
+
+ Properties p = new Properties();
+
+ p.setProperty( "resource.loader", "file, class" );
+ p.setProperty( "velocimacro.library", "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( "velocimacro.permissions.allow.inline","true");
+ p.setProperty( "velocimacro.permissions.allow.inline.local.scope", "true");
+
+ File template = new File(templateSourceDirectory, _getTemplateTagName());
+
+ if (template.exists())
+ {
+ log.info("Using template from file loader: "+template.getPath());
+ }
+ else
+ {
+ log.info("Using template from class loader: src/main/resources/META-INF/"+_getTemplateTagName());
+ }
+
+ VelocityEngine velocityEngine = new VelocityEngine();
+
+ try
+ {
+ velocityEngine.init(p);
+ }
+ catch (Exception e)
+ {
+ throw new MojoExecutionException("Error creating VelocityEngine", e);
+ }
+
+ return velocityEngine;
+ }
+
/**
* 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();){
+ VelocityEngine velocityEngine = initVelocity();
+
+ for (Iterator it = model.getComponents().iterator(); it.hasNext();)
+ {
ComponentMeta component = (ComponentMeta) it.next();
- _generateComponent(component);
+
+ if (component.getTagClass() != null)
+ {
+ log.info("Generating tag class:"+component.getTagClass());
+ _generateComponent(velocityEngine, component);
+ }
}
- //throw new MojoExecutionException("stopping..");
+ throw new MojoExecutionException("stopping..");
}
/**
@@ -159,35 +206,55 @@
* @param component
* the parsed component metadata
*/
- private void _generateComponent(ComponentMeta component)
+ private void _generateComponent(VelocityEngine velocityEngine, ComponentMeta component)
throws MojoExecutionException
{
+
Context context = new VelocityContext();
- context.put("component",component);
-
+ context.put("component", component);
+
Writer writer = null;
+ File outFile = null;
try
{
- //writer = new OutputStreamWriter( new FileOutputStream( outFile ), encoding );
+ outFile = new File(generatedSourceDirectory, StringUtils.replace(
+ component.getTagClass(), ".", "/")+".java");
- //velocity.getEngine().mergeTemplate( templateFileName, encoding, context, writer );
+ if ( !outFile.getParentFile().exists() )
+ {
+ outFile.getParentFile().mkdirs();
+ }
+
+ writer = new OutputStreamWriter(new FileOutputStream(outFile));
+
+ Template template = velocityEngine.getTemplate(_getTemplateTagName());
+
+ template.merge(context, writer);
writer.flush();
}
- catch ( Exception e )
+ catch (Exception e)
{
- throw new Exception(
- "Error merging velocity templates: " + e.getMessage(),
- e
- );
+ throw new MojoExecutionException(
+ "Error merging velocity templates: " + e.getMessage(), e);
}
finally
{
- IOUtil.close( writer );
+ IOUtil.close(writer);
writer = null;
}
-
+ }
+
+ private String _getTemplateTagName(){
+ if (templateTagName != null){
+ if (_is12()){
+ return "tagClass12.vm";
+ }else{
+ return "tagClass11.vm";
+ }
+ }
+ return "tagClass11.vm";
}
private boolean _is12()
Modified: myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ComponentMeta.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/model/ComponentMeta.java?rev=643513&r1=643512&r2=643513&view=diff
==============================================================================
--- myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ComponentMeta.java (original)
+++ myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ComponentMeta.java Tue Apr 1 11:49:55 2008
@@ -63,6 +63,7 @@
out.writeElement("name", cm._name);
out.writeElement("type", cm._type);
out.writeElement("family", cm._family);
+ out.writeElement("tagClass", cm._tagClass);
out.writeElement("rendererType", cm._rendererType);
out.writeElement("desc", cm._description);
@@ -93,6 +94,7 @@
digester.addBeanPropertySetter(newPrefix + "/name");
digester.addBeanPropertySetter(newPrefix + "/type");
digester.addBeanPropertySetter(newPrefix + "/family");
+ digester.addBeanPropertySetter(newPrefix + "/tagClass");
digester.addBeanPropertySetter(newPrefix + "/rendererType");
digester.addBeanPropertySetter(newPrefix + "/desc", "description");
digester.addBeanPropertySetter(newPrefix + "/longDesc",
Added: myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/resources/META-INF/tagClass11.vm
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/resources/META-INF/tagClass11.vm?rev=643513&view=auto
==============================================================================
--- myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/resources/META-INF/tagClass11.vm (added)
+++ myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/resources/META-INF/tagClass11.vm Tue Apr 1 11:49:55 2008
@@ -0,0 +1 @@
+Hola class
\ No newline at end of file
Added: myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/resources/META-INF/tagClassMacros11.vm
URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/resources/META-INF/tagClassMacros11.vm?rev=643513&view=auto
==============================================================================
(empty)
Re: svn commit: r643513 - in /myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin
Posted by Leonardo Uribe <lu...@gmail.com>.
Hi Simon
Ok, I have renamed as builder_plugin. The idea is finish this plugin as fast
as we can.
I have some questions but I will do this on another mail.
regards
Leonardo Uribe
Re: svn commit: r643513 - in
/myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin
Posted by simon <si...@chello.at>.
Hi Leonardo,
As I'm no longer the only person committing to the builder-plugin
project, feel free to rename the branch if you want.
Regards, Simon
On Tue, 2008-04-01 at 18:50 +0000, lu4242@apache.org wrote:
> Author: lu4242
> Date: Tue Apr 1 11:49:55 2008
> New Revision: 643513
>
> URL: http://svn.apache.org/viewvc?rev=643513&view=rev
> Log:
> Generate Tag classes with velocity, step 1
>
> Added:
> myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/resources/META-INF/tagClass11.vm
> myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/resources/META-INF/tagClassMacros11.vm
> Modified:
> myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/pom.xml
> myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java
> myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ComponentMeta.java
>
> 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=643513&r1=643512&r2=643513&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 Tue Apr 1 11:49:55 2008
> @@ -134,12 +134,19 @@
> <artifactId>velocity</artifactId>
> <version>1.5</version>
> </dependency>
> -
> +
> + <dependency>
> + <groupId>commons-collections</groupId>
> + <artifactId>commons-collections</artifactId>
> + <version>3.1</version>
> + </dependency>
> + <!--
> <dependency>
> <groupId>org.codehaus.plexus</groupId>
> <artifactId>plexus-velocity</artifactId>
> <version>1.1.7</version>
> </dependency>
> + -->
>
> <dependency>
> <groupId>log4j</groupId>
>
> Modified: 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=643513&r1=643512&r2=643513&view=diff
> ==============================================================================
> --- myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java (original)
> +++ myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/MakeTagsMojo.java Tue Apr 1 11:49:55 2008
> @@ -24,19 +24,21 @@
> import java.io.OutputStreamWriter;
> import java.io.Writer;
> import java.util.Iterator;
> +import java.util.Properties;
> 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.Template;
> import org.apache.velocity.VelocityContext;
> +import org.apache.velocity.app.VelocityEngine;
> import org.apache.velocity.context.Context;
> import org.codehaus.plexus.util.IOUtil;
> -import org.codehaus.plexus.velocity.VelocityComponent;
> +import org.codehaus.plexus.util.StringUtils;
>
> /**
> * Maven goal to generate java source code for Component tag classes.
> @@ -72,10 +74,14 @@
> private String metadataFile = "classes/META-INF/myfaces-metadata.xml";
>
> /**
> - * @parameter expression="src/main/java-templates"
> - * @required
> + * @parameter expression="src/main/resources/META-INF"
> */
> private File templateSourceDirectory;
> +
> + /**
> + * @parameter
> + */
> + private String templateTagName;
>
> /**
> * @parameter expression="${project.build.directory}/maven-faces-plugin/main/java"
> @@ -109,11 +115,6 @@
> * @parameter
> */
> private String jsfVersion;
> -
> - /**
> - * @component
> - */
> - private VelocityComponent velocity;
>
> /**
> * Execute the Mojo.
> @@ -139,18 +140,64 @@
> }
> }
>
> + private VelocityEngine initVelocity() throws MojoExecutionException
> + {
> +
> + Properties p = new Properties();
> +
> + p.setProperty( "resource.loader", "file, class" );
> + p.setProperty( "velocimacro.library", "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( "velocimacro.permissions.allow.inline","true");
> + p.setProperty( "velocimacro.permissions.allow.inline.local.scope", "true");
> +
> + File template = new File(templateSourceDirectory, _getTemplateTagName());
> +
> + if (template.exists())
> + {
> + log.info("Using template from file loader: "+template.getPath());
> + }
> + else
> + {
> + log.info("Using template from class loader: src/main/resources/META-INF/"+_getTemplateTagName());
> + }
> +
> + VelocityEngine velocityEngine = new VelocityEngine();
> +
> + try
> + {
> + velocityEngine.init(p);
> + }
> + catch (Exception e)
> + {
> + throw new MojoExecutionException("Error creating VelocityEngine", e);
> + }
> +
> + return velocityEngine;
> + }
> +
> /**
> * 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();){
> + VelocityEngine velocityEngine = initVelocity();
> +
> + for (Iterator it = model.getComponents().iterator(); it.hasNext();)
> + {
> ComponentMeta component = (ComponentMeta) it.next();
> - _generateComponent(component);
> +
> + if (component.getTagClass() != null)
> + {
> + log.info("Generating tag class:"+component.getTagClass());
> + _generateComponent(velocityEngine, component);
> + }
> }
> - //throw new MojoExecutionException("stopping..");
> + throw new MojoExecutionException("stopping..");
> }
>
> /**
> @@ -159,35 +206,55 @@
> * @param component
> * the parsed component metadata
> */
> - private void _generateComponent(ComponentMeta component)
> + private void _generateComponent(VelocityEngine velocityEngine, ComponentMeta component)
> throws MojoExecutionException
> {
> +
> Context context = new VelocityContext();
> - context.put("component",component);
> -
> + context.put("component", component);
> +
> Writer writer = null;
> + File outFile = null;
>
> try
> {
> - //writer = new OutputStreamWriter( new FileOutputStream( outFile ), encoding );
> + outFile = new File(generatedSourceDirectory, StringUtils.replace(
> + component.getTagClass(), ".", "/")+".java");
>
> - //velocity.getEngine().mergeTemplate( templateFileName, encoding, context, writer );
> + if ( !outFile.getParentFile().exists() )
> + {
> + outFile.getParentFile().mkdirs();
> + }
> +
> + writer = new OutputStreamWriter(new FileOutputStream(outFile));
> +
> + Template template = velocityEngine.getTemplate(_getTemplateTagName());
> +
> + template.merge(context, writer);
>
> writer.flush();
> }
> - catch ( Exception e )
> + catch (Exception e)
> {
> - throw new Exception(
> - "Error merging velocity templates: " + e.getMessage(),
> - e
> - );
> + throw new MojoExecutionException(
> + "Error merging velocity templates: " + e.getMessage(), e);
> }
> finally
> {
> - IOUtil.close( writer );
> + IOUtil.close(writer);
> writer = null;
> }
> -
> + }
> +
> + private String _getTemplateTagName(){
> + if (templateTagName != null){
> + if (_is12()){
> + return "tagClass12.vm";
> + }else{
> + return "tagClass11.vm";
> + }
> + }
> + return "tagClass11.vm";
> }
>
> private boolean _is12()
>
> Modified: myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ComponentMeta.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/model/ComponentMeta.java?rev=643513&r1=643512&r2=643513&view=diff
> ==============================================================================
> --- myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ComponentMeta.java (original)
> +++ myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/java/org/apache/myfaces/buildtools/maven2/plugin/builder/model/ComponentMeta.java Tue Apr 1 11:49:55 2008
> @@ -63,6 +63,7 @@
> out.writeElement("name", cm._name);
> out.writeElement("type", cm._type);
> out.writeElement("family", cm._family);
> + out.writeElement("tagClass", cm._tagClass);
> out.writeElement("rendererType", cm._rendererType);
>
> out.writeElement("desc", cm._description);
> @@ -93,6 +94,7 @@
> digester.addBeanPropertySetter(newPrefix + "/name");
> digester.addBeanPropertySetter(newPrefix + "/type");
> digester.addBeanPropertySetter(newPrefix + "/family");
> + digester.addBeanPropertySetter(newPrefix + "/tagClass");
> digester.addBeanPropertySetter(newPrefix + "/rendererType");
> digester.addBeanPropertySetter(newPrefix + "/desc", "description");
> digester.addBeanPropertySetter(newPrefix + "/longDesc",
>
> Added: myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/resources/META-INF/tagClass11.vm
> URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/resources/META-INF/tagClass11.vm?rev=643513&view=auto
> ==============================================================================
> --- myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/resources/META-INF/tagClass11.vm (added)
> +++ myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/resources/META-INF/tagClass11.vm Tue Apr 1 11:49:55 2008
> @@ -0,0 +1 @@
> +Hola class
> \ No newline at end of file
>
> Added: myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/resources/META-INF/tagClassMacros11.vm
> URL: http://svn.apache.org/viewvc/myfaces/myfaces-build-tools/branches/skitching/myfaces-builder-plugin/src/main/resources/META-INF/tagClassMacros11.vm?rev=643513&view=auto
> ==============================================================================
> (empty)
>
>