Return-Path: Delivered-To: apmail-activemq-camel-commits-archive@locus.apache.org Received: (qmail 33949 invoked from network); 16 Aug 2007 06:48:32 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 16 Aug 2007 06:48:32 -0000 Received: (qmail 18780 invoked by uid 500); 16 Aug 2007 06:48:30 -0000 Delivered-To: apmail-activemq-camel-commits-archive@activemq.apache.org Received: (qmail 18760 invoked by uid 500); 16 Aug 2007 06:48:30 -0000 Mailing-List: contact camel-commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: camel-dev@activemq.apache.org Delivered-To: mailing list camel-commits@activemq.apache.org Received: (qmail 18751 invoked by uid 99); 16 Aug 2007 06:48:30 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 15 Aug 2007 23:48:30 -0700 X-ASF-Spam-Status: No, hits=-100.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.3] (HELO eris.apache.org) (140.211.11.3) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 16 Aug 2007 06:48:29 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3C9241A981C; Wed, 15 Aug 2007 23:48:09 -0700 (PDT) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit 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 -0000 To: camel-commits@activemq.apache.org From: jstrachan@apache.org X-Mailer: svnmailer-1.1.0 Message-Id: <20070816064809.3C9241A981C@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org 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 @@ 1.0-alpha-9 + + org.apache.maven.reporting + maven-reporting-api + 2.0.2 + + + org.apache.maven.reporting + maven-reporting-impl + 2.0.2 + + @@ -67,6 +78,13 @@ commons-logging commons-logging + + + + + commons-collections + commons-collections + 3.1 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 GraphViz + */ +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 files = new ArrayList(); + 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 output, File file) { + if (file.isDirectory()) { + appendDirectory(output, file); + } + else { + if (isValid(file)) { + output.add(file); + } + } + } + + private void appendDirectory(List 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;