svn commit: r566600 - in /activemq/camel/trunk: examples/camel-example-spring/ examples/camel-example-spring/src/test/ examples/camel-example-spring/src/test/java/ examples/camel-example-spring/src/test/java/org/ examples/camel-example-spring/src/test/...

classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

svn commit: r566600 - in /activemq/camel/trunk: examples/camel-example-spring/ examples/camel-example-spring/src/test/ examples/camel-example-spring/src/test/java/ examples/camel-example-spring/src/test/java/org/ examples/camel-example-spring/src/test/...

jstrachan-2
Author: jstrachan
Date: Thu Aug 16 02:28:11 2007
New Revision: 566600

URL: http://svn.apache.org/viewvc?view=rev&rev=566600
Log:
got the maven plugin working as a reporting plugin; also made the examples generate a DOT file as part of the unit tests

Added:
    activemq/camel/trunk/examples/camel-example-spring/src/test/
    activemq/camel/trunk/examples/camel-example-spring/src/test/java/
    activemq/camel/trunk/examples/camel-example-spring/src/test/java/org/
    activemq/camel/trunk/examples/camel-example-spring/src/test/java/org/apache/
    activemq/camel/trunk/examples/camel-example-spring/src/test/java/org/apache/camel/
    activemq/camel/trunk/examples/camel-example-spring/src/test/java/org/apache/camel/example/
    activemq/camel/trunk/examples/camel-example-spring/src/test/java/org/apache/camel/example/spring/
    activemq/camel/trunk/examples/camel-example-spring/src/test/java/org/apache/camel/example/spring/IntegrationTest.java   (with props)
    activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/resources/camel-maven-plugin.properties   (with props)
Modified:
    activemq/camel/trunk/examples/camel-example-spring/pom.xml
    activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DotMojo.java

Modified: activemq/camel/trunk/examples/camel-example-spring/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-spring/pom.xml?view=diff&rev=566600&r1=566599&r2=566600
==============================================================================
--- activemq/camel/trunk/examples/camel-example-spring/pom.xml (original)
+++ activemq/camel/trunk/examples/camel-example-spring/pom.xml Thu Aug 16 02:28:11 2007
@@ -42,6 +42,14 @@
       <groupId>org.apache.camel</groupId>
       <artifactId>camel-activemq</artifactId>
     </dependency>
+
+    <!-- for testing -->
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
+    </dependency>
+    
   </dependencies>
 
   <build>
@@ -52,5 +60,16 @@
         <artifactId>camel-maven-plugin</artifactId>
       </plugin>
     </plugins>
+
   </build>
+
+  <reporting>
+    <plugins>
+      <!-- lets generate nice PNG / SVG diagrams from our routes -->
+      <plugin>
+        <groupId>org.apache.camel</groupId>
+        <artifactId>camel-maven-plugin</artifactId>
+      </plugin>
+    </plugins>
+  </reporting>
 </project>

Added: activemq/camel/trunk/examples/camel-example-spring/src/test/java/org/apache/camel/example/spring/IntegrationTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/examples/camel-example-spring/src/test/java/org/apache/camel/example/spring/IntegrationTest.java?view=auto&rev=566600
==============================================================================
--- activemq/camel/trunk/examples/camel-example-spring/src/test/java/org/apache/camel/example/spring/IntegrationTest.java (added)
+++ activemq/camel/trunk/examples/camel-example-spring/src/test/java/org/apache/camel/example/spring/IntegrationTest.java Thu Aug 16 02:28:11 2007
@@ -0,0 +1,32 @@
+/**
+ *
+ * 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.camel.example.spring;
+
+import junit.framework.TestCase;
+import org.apache.camel.spring.Main;
+
+/**
+ * @version $Revision: 1.1 $
+ */
+public class IntegrationTest extends TestCase {
+
+    public void testCamelRulesDeployCorrectlyInSpring() throws Exception {
+        // lets boot up the Spring application context for 2 seconds to check it works OK
+        Main.main("-duration", "2s", "-file", "target/site/cameldoc/routes.dot");
+    }
+}

Propchange: activemq/camel/trunk/examples/camel-example-spring/src/test/java/org/apache/camel/example/spring/IntegrationTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DotMojo.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DotMojo.java?view=diff&rev=566600&r1=566599&r2=566600
==============================================================================
--- activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DotMojo.java (original)
+++ activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DotMojo.java Thu Aug 16 02:28:11 2007
@@ -27,7 +27,14 @@
 import org.codehaus.plexus.util.cli.CommandLineUtils;
 import org.codehaus.plexus.util.cli.Commandline;
 
+import java.io.BufferedReader;
+import java.io.Closeable;
 import java.io.File;
+import java.io.FileReader;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.PrintWriter;
+import java.io.StringWriter;
 import java.util.ArrayList;
 import java.util.List;
 import java.util.Locale;
@@ -42,8 +49,7 @@
  * @see <a href="http://www.graphviz.org/">GraphViz</a>
  */
 public class DotMojo extends AbstractMavenReport {
-    public static final String[] DEFAULT_GRAPHVIZ_OUTPUT_TYPES = { "png", "svg", "cmapx" };
-
+    public static final String[] DEFAULT_GRAPHVIZ_OUTPUT_TYPES = {"png", "svg", "cmapx"};
     /**
      * Subdirectory for report.
      */
@@ -126,7 +132,7 @@
      * @see org.apache.maven.reporting.MavenReport#getOutputName()
      */
     public String getOutputName() {
-        return SUBDIRECTORY + "/index.html";
+        return SUBDIRECTORY + "/index";
     }
 
     /**
@@ -137,13 +143,27 @@
     }
 
     /**
+     * @see org.apache.maven.reporting.AbstractMavenReport#executeReport(Locale)
+     */
+    protected void executeReport(final Locale locale) throws MavenReportException {
+        try {
+            this.execute(this.outputDirectory, locale);
+        }
+        catch (MojoExecutionException e) {
+            final MavenReportException ex = new MavenReportException(e.getMessage());
+            ex.initCause(e.getCause());
+            throw ex;
+        }
+    }
+
+    /**
      * Executes DOT generator.
      *
      * @param outputDir report output directory.
      * @param locale    report locale.
      * @throws MojoExecutionException if there were any execution errors.
      */
-    private void execute(final File outputDir, final Locale locale) throws MojoExecutionException {
+    protected void execute(final File outputDir, final Locale locale) throws MojoExecutionException {
         outputDir.mkdirs();
 
         List<File> files = new ArrayList<File>();
@@ -154,32 +174,99 @@
                 graphvizOutputTypes = DEFAULT_GRAPHVIZ_OUTPUT_TYPES;
             }
             else {
-            graphvizOutputTypes = new String[]{graphvizOutputType};
+                graphvizOutputTypes = new String[]{graphvizOutputType};
             }
         }
+        StringWriter htmlBuffer = new StringWriter();
         try {
+            PrintWriter out = new PrintWriter(htmlBuffer);
+            printHtmlHeader(out);
+
             for (int i = 0; i < files.size(); i++) {
                 File file = (File) ((List) files).get(i);
+                printHtmlFileHeader(out, file);
                 for (int j = 0; j < graphvizOutputTypes.length; j++) {
                     String format = graphvizOutputTypes[j];
-                    convertFile(file, format, getLog());
+                    String generated = convertFile(file, format);
+
+                    if (format.equals("cmapx")) {
+                        // lets include the generated file inside the html
+                        addFileToBuffer(out, new File(generated));
+                    }
                 }
+                printHtmlFileFooter(out, file);
             }
+
+            printHtmlFooter(out);
         }
         catch (CommandLineException e) {
             throw new MojoExecutionException("Failed: " + e, e);
         }
+        File html = new File(new File(outputDirectory, SUBDIRECTORY), "eip.html");
+        FileWriter htmlOut = null;
+        try {
+            htmlOut = new FileWriter(html);
+            htmlOut.write(htmlBuffer.toString());
+        }
+        catch (IOException e) {
+            throw new MojoExecutionException("Failed: " + e, e);
+        }
+        finally {
+            String description = "Failed to close html output file";
+            close(htmlOut, description);
+        }
+    }
+
+    protected void printHtmlHeader(PrintWriter out) {
+        out.println("<html>");
+        out.println("<head>");
+        out.println("</head>");
+        out.println("<body>");
+        out.println();
+        out.println("<h1>Camel EIP Patterns</h1>");
+        out.println();
+    }
+
+    protected void printHtmlFileHeader(PrintWriter out, File file) {
+        out.println("<p>");
+        out.println("  <img src='" + removeFileExtension(file.getName()) + ".png' usemap='#G'>");
+    }
+
+    protected void printHtmlFileFooter(PrintWriter out, File file) {
+        out.println("  </img>");
+        out.println("</p>");
+        out.println();
+    }
+
+    protected void printHtmlFooter(PrintWriter out) {
+        out.println();
+        out.println("</body>");
+        out.println("</html>");
+    }
+
+    protected void close(Closeable closeable, String description) {
+        if (closeable != null) {
+            try {
+                closeable.close();
+            }
+            catch (IOException e) {
+                getLog().warn(description + ": " + e);
+            }
+        }
     }
 
-    protected int convertFile(File file, String format, Log log1) throws CommandLineException {
+    protected String convertFile(File file, String format) throws CommandLineException {
+        String generatedFileName = removeFileExtension(file.getAbsolutePath()) + "." + format;
+        Log log = getLog();
+
         Commandline cl = new Commandline();
         cl.setExecutable(executable);
         cl.createArgument().setValue("-T" + format);
         cl.createArgument().setValue("-o");
-        cl.createArgument().setValue(file.getAbsolutePath().replace(".dot", "." + format));
+        cl.createArgument().setValue(generatedFileName);
         cl.createArgument().setValue(file.getAbsolutePath());
 
-        log1.debug("executing: " + cl.toString());
+        log.debug("executing: " + cl.toString());
 
         CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
         CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
@@ -188,13 +275,23 @@
 
         String output = stdout.getOutput();
         if (output.length() > 0) {
-            log1.debug(output);
+            log.debug(output);
         }
         String errOutput = stderr.getOutput();
         if (errOutput.length() > 0) {
-            log1.warn(errOutput);
+            log.warn(errOutput);
+        }
+        return generatedFileName;
+    }
+
+    protected String removeFileExtension(String name) {
+        int idx = name.lastIndexOf(".");
+        if (idx > 0) {
+            return name.substring(0, idx);
+        }
+        else {
+            return name;
         }
-        return exitCode;
     }
 
     private void appendFiles(List<File> output, File file) {
@@ -220,17 +317,25 @@
         return name.endsWith(".dot");
     }
 
-    /**
-     * @see org.apache.maven.reporting.AbstractMavenReport#executeReport(Locale)
-     */
-    protected void executeReport(final Locale locale) throws MavenReportException {
+    private void addFileToBuffer(PrintWriter out, File file) throws MojoExecutionException {
+        BufferedReader reader = null;
         try {
-            this.execute(this.outputDirectory, locale);
+            reader = new BufferedReader(new FileReader(file));
+            while (true) {
+                String line = reader.readLine();
+                if (line == null) {
+                    break;
+                }
+                else {
+                    out.println(line);
+                }
+            }
         }
-        catch (MojoExecutionException e) {
-            final MavenReportException ex = new MavenReportException(e.getMessage());
-            ex.initCause(e.getCause());
-            throw ex;
+        catch (IOException e) {
+            throw new MojoExecutionException("Failed: " + e, e);
+        }
+        finally {
+            close(reader, "cmapx file");
         }
     }
 
@@ -242,7 +347,7 @@
      */
     protected ResourceBundle getBundle(final Locale locale) {
         return ResourceBundle.getBundle(
-                "camel-dot-maven-plugin",
+                "camel-maven-plugin",
                 locale,
                 this.getClass().getClassLoader());
     }

Added: activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/resources/camel-maven-plugin.properties
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/resources/camel-maven-plugin.properties?view=auto&rev=566600
==============================================================================
--- activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/resources/camel-maven-plugin.properties (added)
+++ activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/resources/camel-maven-plugin.properties Thu Aug 16 02:28:11 2007
@@ -0,0 +1,19 @@
+# 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.
+
+report.name = Camel EIP Diagram
+report.description = This report generates a graphical diagram of all the Enterprise Integration Patterns in this project
\ No newline at end of file

Propchange: activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/resources/camel-maven-plugin.properties
------------------------------------------------------------------------------
    svn:eol-style = native