camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jstrac...@apache.org
Subject svn commit: r566503 - in /activemq/camel/trunk/tooling/maven/camel-maven-plugin: pom.xml src/main/java/org/apache/camel/maven/DotMojo.java src/main/java/org/apache/camel/maven/RunCamelMojo.java
Date Thu, 16 Aug 2007 06:48:09 GMT
Author: jstrachan
Date: Wed Aug 15 23:48:08 2007
New Revision: 566503

URL: http://svn.apache.org/viewvc?view=rev&rev=566503
Log:
added a DOT plugin so that we can convert the DOT files into PNG/SVG files as part of the
build process

Added:
    activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DotMojo.java
  (with props)
Modified:
    activemq/camel/trunk/tooling/maven/camel-maven-plugin/pom.xml
    activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RunCamelMojo.java

Modified: activemq/camel/trunk/tooling/maven/camel-maven-plugin/pom.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tooling/maven/camel-maven-plugin/pom.xml?view=diff&rev=566503&r1=566502&r2=566503
==============================================================================
--- activemq/camel/trunk/tooling/maven/camel-maven-plugin/pom.xml (original)
+++ activemq/camel/trunk/tooling/maven/camel-maven-plugin/pom.xml Wed Aug 15 23:48:08 2007
@@ -58,6 +58,17 @@
       <version>1.0-alpha-9</version>
     </dependency>
 
+    <dependency>
+      <groupId>org.apache.maven.reporting</groupId>
+      <artifactId>maven-reporting-api</artifactId>
+      <version>2.0.2</version>
+    </dependency>
+    <dependency>
+      <groupId>org.apache.maven.reporting</groupId>
+      <artifactId>maven-reporting-impl</artifactId>
+      <version>2.0.2</version>
+    </dependency>
+
 
     <!-- add some logging to the classpath -->
     <dependency>
@@ -67,6 +78,13 @@
     <dependency>
       <groupId>commons-logging</groupId>
       <artifactId>commons-logging</artifactId>
+    </dependency>
+
+    <!-- do we need all these? -->
+    <dependency>
+      <groupId>commons-collections</groupId>
+      <artifactId>commons-collections</artifactId>
+      <version>3.1</version>
     </dependency>
   </dependencies>
 </project>

Added: 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=auto&rev=566503
==============================================================================
--- activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DotMojo.java
(added)
+++ activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DotMojo.java
Wed Aug 15 23:48:08 2007
@@ -0,0 +1,264 @@
+/**
+ *
+ * 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.maven;
+
+import org.apache.maven.doxia.siterenderer.Renderer;
+import org.apache.maven.plugin.MojoExecutionException;
+import org.apache.maven.plugin.logging.Log;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.reporting.AbstractMavenReport;
+import org.apache.maven.reporting.MavenReportException;
+import org.codehaus.plexus.util.cli.CommandLineException;
+import org.codehaus.plexus.util.cli.CommandLineUtils;
+import org.codehaus.plexus.util.cli.Commandline;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.ResourceBundle;
+
+/**
+ * Converts the DOT files into another format such as PNG
+ *
+ * @version $Revision: 1.1 $
+ * @goal dot
+ * @phase prepare-package
+ * @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"
};
+
+    /**
+     * Subdirectory for report.
+     */
+    protected static final String SUBDIRECTORY = "cameldoc";
+    /**
+     * Reference to Maven 2 Project.
+     *
+     * @parameter expression="${project}"
+     * @required
+     * @readonly
+     */
+    private MavenProject project;
+    /**
+     * Base output directory.
+     *
+     * @parameter expression="${project.build.directory}"
+     * @required
+     * @readonly
+     */
+    private File buildDirectory;
+    /**
+     * Base output directory for reports.
+     *
+     * @parameter expression="${project.reporting.outputDirectory}"
+     * @readonly
+     * @required
+     */
+    private File outputDirectory;
+    /**
+     * The input directory used to find the dot files
+     *
+     * @parameter default-value="${project.build.directory}/site/cameldoc"
+     * @required
+     */
+    private File resources;
+    /**
+     * GraphViz executable location; visualization (images) will be
+     * generated only if you install this program and set this property to the
+     * executable dot (dot.exe on Win).
+     *
+     * @parameter expression="dot"
+     */
+    private String executable;
+    /**
+     * Graphviz output types. Default is png. Possible values: png, jpg, gif, svg.
+     *
+     * @required
+     */
+    private String graphvizOutputType;
+    /**
+     * Graphviz output types. Possible values: png, jpg, gif, svg.
+     *
+     * @parameter
+     */
+    private String[] graphvizOutputTypes;
+    /**
+     * Doxia SiteRender.
+     *
+     * @component
+     */
+    private Renderer renderer;
+
+    /**
+     * @param locale report locale.
+     * @return report description.
+     * @see org.apache.maven.reporting.MavenReport#getDescription(Locale)
+     */
+    public String getDescription(final Locale locale) {
+        return getBundle(locale).getString("report.description");
+    }
+
+    /**
+     * @see org.apache.maven.reporting.MavenReport#getName(Locale)
+     */
+    public String getName(final Locale locale) {
+        return getBundle(locale).getString("report.name");
+    }
+
+    /**
+     * @see org.apache.maven.reporting.MavenReport#getOutputName()
+     */
+    public String getOutputName() {
+        return SUBDIRECTORY + "/index.html";
+    }
+
+    /**
+     * @see org.apache.maven.plugin.Mojo#execute()
+     */
+    public void execute() throws MojoExecutionException {
+        this.execute(this.buildDirectory, Locale.getDefault());
+    }
+
+    /**
+     * 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
{
+        outputDir.mkdirs();
+
+        List<File> files = new ArrayList<File>();
+        appendFiles(files, resources);
+
+        if (graphvizOutputTypes == null) {
+            if (graphvizOutputType == null) {
+                graphvizOutputTypes = DEFAULT_GRAPHVIZ_OUTPUT_TYPES;
+            }
+            else {
+            graphvizOutputTypes = new String[]{graphvizOutputType};
+            }
+        }
+        try {
+            for (int i = 0; i < files.size(); i++) {
+                File file = (File) ((List) files).get(i);
+                for (int j = 0; j < graphvizOutputTypes.length; j++) {
+                    String format = graphvizOutputTypes[j];
+                    convertFile(file, format, getLog());
+                }
+            }
+        }
+        catch (CommandLineException e) {
+            throw new MojoExecutionException("Failed: " + e, e);
+        }
+    }
+
+    protected int convertFile(File file, String format, Log log1) throws CommandLineException
{
+        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(file.getAbsolutePath());
+
+        log1.debug("executing: " + cl.toString());
+
+        CommandLineUtils.StringStreamConsumer stdout = new CommandLineUtils.StringStreamConsumer();
+        CommandLineUtils.StringStreamConsumer stderr = new CommandLineUtils.StringStreamConsumer();
+
+        int exitCode = CommandLineUtils.executeCommandLine(cl, stdout, stderr);
+
+        String output = stdout.getOutput();
+        if (output.length() > 0) {
+            log1.debug(output);
+        }
+        String errOutput = stderr.getOutput();
+        if (errOutput.length() > 0) {
+            log1.warn(errOutput);
+        }
+        return exitCode;
+    }
+
+    private void appendFiles(List<File> output, File file) {
+        if (file.isDirectory()) {
+            appendDirectory(output, file);
+        }
+        else {
+            if (isValid(file)) {
+                output.add(file);
+            }
+        }
+    }
+
+    private void appendDirectory(List<File> output, File dir) {
+        File[] files = dir.listFiles();
+        for (File file : files) {
+            appendFiles(output, file);
+        }
+    }
+
+    private boolean isValid(File file) {
+        String name = file.getName().toLowerCase();
+        return name.endsWith(".dot");
+    }
+
+    /**
+     * @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;
+        }
+    }
+
+    /**
+     * Gets resource bundle for given locale.
+     *
+     * @param locale locale
+     * @return resource bundle
+     */
+    protected ResourceBundle getBundle(final Locale locale) {
+        return ResourceBundle.getBundle(
+                "camel-dot-maven-plugin",
+                locale,
+                this.getClass().getClassLoader());
+    }
+
+    protected Renderer getSiteRenderer() {
+        return this.renderer;
+    }
+
+    /**
+     * @see org.apache.maven.reporting.AbstractMavenReport#getOutputDirectory()
+     */
+    protected String getOutputDirectory() {
+        return this.outputDirectory.getAbsolutePath();
+    }
+
+    protected MavenProject getProject() {
+        return this.project;
+    }
+}
\ No newline at end of file

Propchange: activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DotMojo.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RunCamelMojo.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RunCamelMojo.java?view=diff&rev=566503&r1=566502&r2=566503
==============================================================================
--- activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RunCamelMojo.java
(original)
+++ activemq/camel/trunk/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/RunCamelMojo.java
Wed Aug 15 23:48:08 2007
@@ -90,7 +90,7 @@
     /**
      * The DOT File name used to generate the DOT diagram of the route definitions
      *
-     * @parameter expression="${project.build.directory}/site/camel-dot/Routes.dot"
+     * @parameter expression="${project.build.directory}/site/cameldoc/Routes.dot"
      * @readonly
      */
     protected String dotFile;



Mime
View raw message