You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@tiles.apache.org by ap...@apache.org on 2010/03/03 21:46:25 UTC

svn commit: r918676 - in /tiles/sandbox/trunk/tiles-autotag: maven-autotag-plugin/ maven-autotag-plugin/src/main/java/org/apache/tiles/autotag/plugin/ tiles-autotag-core/src/main/java/org/apache/tiles/autotag/core/ tiles-autotag-core/src/main/java/org/...

Author: apetrelli
Date: Wed Mar  3 20:46:25 2010
New Revision: 918676

URL: http://svn.apache.org/viewvc?rev=918676&view=rev
Log:
TILESSB-25
Added generation of JSP code. Fixed other places accordingly.

Added:
    tiles/sandbox/trunk/tiles-autotag/maven-autotag-plugin/src/main/java/org/apache/tiles/autotag/plugin/GenerateJspMojo.java   (with props)
Modified:
    tiles/sandbox/trunk/tiles-autotag/maven-autotag-plugin/pom.xml
    tiles/sandbox/trunk/tiles-autotag/maven-autotag-plugin/src/main/java/org/apache/tiles/autotag/plugin/CreateDescriptorMojo.java
    tiles/sandbox/trunk/tiles-autotag/tiles-autotag-core/src/main/java/org/apache/tiles/autotag/core/QDoxTemplateSuiteFactory.java
    tiles/sandbox/trunk/tiles-autotag/tiles-autotag-core/src/main/java/org/apache/tiles/autotag/tool/StringTool.java

Modified: tiles/sandbox/trunk/tiles-autotag/maven-autotag-plugin/pom.xml
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/maven-autotag-plugin/pom.xml?rev=918676&r1=918675&r2=918676&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-autotag/maven-autotag-plugin/pom.xml (original)
+++ tiles/sandbox/trunk/tiles-autotag/maven-autotag-plugin/pom.xml Wed Mar  3 20:46:25 2010
@@ -39,5 +39,10 @@
     	<artifactId>xstream</artifactId>
     	<version>1.3.1</version>
     </dependency>
+    <dependency>
+    	<groupId>org.apache.tiles</groupId>
+    	<artifactId>tiles-autotag-jsp</artifactId>
+    	<version>1.0-SNAPSHOT</version>
+    </dependency>
   </dependencies>
 </project>

Modified: tiles/sandbox/trunk/tiles-autotag/maven-autotag-plugin/src/main/java/org/apache/tiles/autotag/plugin/CreateDescriptorMojo.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/maven-autotag-plugin/src/main/java/org/apache/tiles/autotag/plugin/CreateDescriptorMojo.java?rev=918676&r1=918675&r2=918676&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-autotag/maven-autotag-plugin/src/main/java/org/apache/tiles/autotag/plugin/CreateDescriptorMojo.java (original)
+++ tiles/sandbox/trunk/tiles-autotag/maven-autotag-plugin/src/main/java/org/apache/tiles/autotag/plugin/CreateDescriptorMojo.java Wed Mar  3 20:46:25 2010
@@ -66,6 +66,21 @@
     private Set<String> includes;
 
     /**
+     * The name of the template.
+     *
+     * @parameter
+     * @required
+     */
+    private String name;
+
+    /**
+     * The documentation of the suite
+     *
+     * @parameter
+     */
+    private String documentation;
+
+    /**
      * @parameter
      */
     private Set<String> excludes;
@@ -76,7 +91,9 @@
             Set<File> filesSet = getSourceInclusionScanner().getIncludedSources(
                     sourceDirectory, outputDirectory);
             File[] files = new File[filesSet.size()];
-            TemplateSuiteFactory factory = new QDoxTemplateSuiteFactory(filesSet.toArray(files));
+            QDoxTemplateSuiteFactory factory = new QDoxTemplateSuiteFactory(filesSet.toArray(files));
+            factory.setSuiteName(name);
+            factory.setSuiteDocumentation(documentation);
             TemplateSuite suite = factory.createTemplateSuite();
             XStream xstream = new XStream();
             File dir = new File(outputDirectory, "META-INF");

Added: tiles/sandbox/trunk/tiles-autotag/maven-autotag-plugin/src/main/java/org/apache/tiles/autotag/plugin/GenerateJspMojo.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/maven-autotag-plugin/src/main/java/org/apache/tiles/autotag/plugin/GenerateJspMojo.java?rev=918676&view=auto
==============================================================================
--- tiles/sandbox/trunk/tiles-autotag/maven-autotag-plugin/src/main/java/org/apache/tiles/autotag/plugin/GenerateJspMojo.java (added)
+++ tiles/sandbox/trunk/tiles-autotag/maven-autotag-plugin/src/main/java/org/apache/tiles/autotag/plugin/GenerateJspMojo.java Wed Mar  3 20:46:25 2010
@@ -0,0 +1,128 @@
+package org.apache.tiles.autotag.plugin;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed 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.
+ */
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.List;
+import java.util.Properties;
+import java.util.jar.JarFile;
+import java.util.zip.ZipEntry;
+
+import org.apache.maven.plugin.AbstractMojo;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.tiles.autotag.generate.BasicTemplateGenerator;
+import org.apache.tiles.autotag.jsp.TLDGenerator;
+import org.apache.tiles.autotag.jsp.TagClassGenerator;
+import org.apache.tiles.autotag.model.TemplateSuite;
+import org.apache.velocity.app.Velocity;
+
+import com.thoughtworks.xstream.XStream;
+
+/**
+ * Goal which touches a timestamp file.
+ *
+ * @goal generate-jsp
+ *
+ * @phase generate-sources
+ * @requiresDependencyResolution compile
+ */
+public class GenerateJspMojo extends AbstractMojo {
+    private static final String META_INF_TEMPLATE_SUITE_XML = "META-INF/template-suite.xml";
+
+    /**
+     * Location of the file.
+     *
+     * @parameter expression="${project.build.directory}/autotag-jsp"
+     * @required
+     */
+    private File outputDirectory;
+
+    /**
+     * Name of the package.
+     * @parameter expression="sample"
+     * @required
+     */
+    private String packageName;
+
+    /**
+     * URI of the tag library.
+     *
+     * @parameter expression="http://www.example.com/tags/example"
+     */
+    private String taglibURI;
+
+    /**
+     * The project
+     *
+     * @parameter expression="${project.compileClasspathElements}"
+     * @required
+     * @readonly
+     */
+    private List<String> classpathElements;
+
+    public void execute() throws MojoExecutionException {
+        try {
+            InputStream stream = findTemplateSuiteDescriptor();
+            XStream xstream = new XStream();
+            TemplateSuite suite = (TemplateSuite) xstream.fromXML(stream);
+            stream.close();
+            BasicTemplateGenerator generator = new BasicTemplateGenerator();
+            generator.addTemplateSuiteGenerator(new TLDGenerator());
+            generator.addTemplateClassGenerator(new TagClassGenerator());
+            suite.getCustomVariables().put("taglibURI", taglibURI);
+
+            Properties props = new Properties();
+            InputStream propsStream = getClass().getResourceAsStream("/org/apache/tiles/autotag/jsp/velocity.properties");
+            props.load(propsStream);
+            propsStream.close();
+            Velocity.init(props);
+
+            generator.generate(outputDirectory, packageName, suite);
+        } catch (IOException e) {
+            throw new MojoExecutionException("error", e);
+        } catch (RuntimeException e) {
+            throw e;
+        } catch (Exception e) {
+            throw new MojoExecutionException("error", e);
+        }
+    }
+
+    private InputStream findTemplateSuiteDescriptor() throws IOException {
+        InputStream retValue = null;
+
+        for (String path: classpathElements) {
+            File file = new File(path);
+            if (file.isDirectory()) {
+                File candidate = new File(file, META_INF_TEMPLATE_SUITE_XML);
+                if (candidate.exists()) {
+                    return new FileInputStream(candidate);
+                }
+            } else if (file.getPath().endsWith(".jar")) {
+                JarFile jar = new JarFile(file);
+                ZipEntry entry = jar.getEntry(META_INF_TEMPLATE_SUITE_XML);
+                if (entry != null) {
+                    return jar.getInputStream(entry);
+                }
+            }
+        }
+
+        return retValue;
+    }
+}

Propchange: tiles/sandbox/trunk/tiles-autotag/maven-autotag-plugin/src/main/java/org/apache/tiles/autotag/plugin/GenerateJspMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: tiles/sandbox/trunk/tiles-autotag/maven-autotag-plugin/src/main/java/org/apache/tiles/autotag/plugin/GenerateJspMojo.java
------------------------------------------------------------------------------
    svn:keywords = Date Author Id Revision HeadURL

Modified: tiles/sandbox/trunk/tiles-autotag/tiles-autotag-core/src/main/java/org/apache/tiles/autotag/core/QDoxTemplateSuiteFactory.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-core/src/main/java/org/apache/tiles/autotag/core/QDoxTemplateSuiteFactory.java?rev=918676&r1=918675&r2=918676&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-autotag/tiles-autotag-core/src/main/java/org/apache/tiles/autotag/core/QDoxTemplateSuiteFactory.java (original)
+++ tiles/sandbox/trunk/tiles-autotag/tiles-autotag-core/src/main/java/org/apache/tiles/autotag/core/QDoxTemplateSuiteFactory.java Wed Mar  3 20:46:25 2010
@@ -94,7 +94,7 @@
         String simpleClassName = clazz.getName();
         if (simpleClassName.endsWith(TEMPLATE_SUFFIX)
                 && simpleClassName.length() > TEMPLATE_SUFFIX.length()) {
-            tagName = simpleClassName.substring(0, 1).toLowerCase()
+            tagName = simpleClassName.substring(0, 1).toUpperCase()
                     + simpleClassName.substring(1, simpleClassName.length()
                             - TEMPLATE_SUFFIX.length());
         } else {

Modified: tiles/sandbox/trunk/tiles-autotag/tiles-autotag-core/src/main/java/org/apache/tiles/autotag/tool/StringTool.java
URL: http://svn.apache.org/viewvc/tiles/sandbox/trunk/tiles-autotag/tiles-autotag-core/src/main/java/org/apache/tiles/autotag/tool/StringTool.java?rev=918676&r1=918675&r2=918676&view=diff
==============================================================================
--- tiles/sandbox/trunk/tiles-autotag/tiles-autotag-core/src/main/java/org/apache/tiles/autotag/tool/StringTool.java (original)
+++ tiles/sandbox/trunk/tiles-autotag/tiles-autotag-core/src/main/java/org/apache/tiles/autotag/tool/StringTool.java Wed Mar  3 20:46:25 2010
@@ -13,6 +13,9 @@
 
     public List<String> splitOnNewlines(String toSplit) {
         List<String> retValue = new ArrayList<String>();
+        if (toSplit == null) {
+            return retValue;
+        }
         Reader reader = new StringReader(toSplit);
         BufferedReader bufReader = new BufferedReader(reader);
         try {