Index: src/main/java/org/apache/camel/maven/EmbeddedMojo.java =================================================================== --- src/main/java/org/apache/camel/maven/EmbeddedMojo.java (revision 643008) +++ src/main/java/org/apache/camel/maven/EmbeddedMojo.java (working copy) @@ -22,6 +22,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLClassLoader; +import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -61,6 +62,13 @@ */ protected boolean dotEnabled; /** + * Allows the routes from multiple contexts to be aggregated into one DOT file (in addition to the individual files) + * + * @parameter expression="false" + * @readonly + */ + protected boolean dotAggregationEnabled; + /** * Project classpath. * * @parameter expression="${project.testClasspathElements}" @@ -158,13 +166,27 @@ } protected String[] createArguments() { - if (dotEnabled) { - return new String[] {"-duration", duration, "-outdir", outputDirectory}; - } else { - return new String[] {"-duration", duration}; + + ArrayList args = new ArrayList( 5 ); + if (isDotEnabled()) { + + args.add( "-outdir" ); + args.add( getOutputDirectory() ); + } + + if (isDotAggregationEnabled()) { + + args.add( "-aggregate-dot" ); + args.add( "true" ); } + + args.add( "-duration" ); + args.add( getDuration() ); + + return (String[]) args.toArray( new String[0] ); } + protected ClassLoader createClassLoader(ClassLoader parent) throws MalformedURLException { getLog().debug("Using classpath: " + classpathElements); @@ -179,4 +201,14 @@ URLClassLoader loader = new URLClassLoader(urls, parent); return loader; } + + public boolean isDotAggregationEnabled() { + + return dotAggregationEnabled; + } + + public void setDotAggregationEnabled( boolean dotAggregationEnabled ) { + + this.dotAggregationEnabled = dotAggregationEnabled; + } } Index: src/main/java/org/apache/camel/maven/DotMojo.java =================================================================== --- src/main/java/org/apache/camel/maven/DotMojo.java (revision 643008) +++ src/main/java/org/apache/camel/maven/DotMojo.java (working copy) @@ -113,6 +113,13 @@ */ private File outputDirectory; /** + * In the case of multiple camel contexts, setting aggregate == true will aggregate all + * into a monolithic context, otherwise they will be processed independently. + * + * @parameter + */ + private String aggregate; + /** * 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). @@ -204,12 +211,13 @@ * @param locale report locale. * @throws MojoExecutionException if there were any execution errors. */ - protected void execute(final File outputDir, final Locale locale) throws MojoExecutionException { + protected void execute( final File outputDir, final Locale locale ) throws MojoExecutionException { + try { - runCamelEmbedded(outputDir); + runCamelEmbedded( outputDir ); } catch (DependencyResolutionRequiredException e) { - throw new MojoExecutionException("Failed: " + e, e); + throw new MojoExecutionException( "Failed: " + e, e ); } outputDir.mkdirs(); @@ -214,7 +222,7 @@ outputDir.mkdirs(); List files = new ArrayList(); - appendFiles(files, outputDirectory); + appendFiles( files, outputDirectory ); if (graphvizOutputTypes == null) { if (graphvizOutputType == null) { @@ -221,7 +229,7 @@ graphvizOutputTypes = DEFAULT_GRAPHVIZ_OUTPUT_TYPES; } else { - graphvizOutputTypes = new String[]{graphvizOutputType}; + graphvizOutputTypes = new String[] { graphvizOutputType }; } } try { @@ -228,13 +236,13 @@ Set contextNames = new HashSet(); for (File file : files) { String contextName = file.getParentFile().getName(); - contextNames.add(contextName); + contextNames.add( contextName ); } + boolean multipleCamelContexts = contextNames.size() > 1; for (int i = 0, size = files.size(); i < size; i++) { - File file = files.get(i); - + File file = files.get( i ); String contextName = null; if (multipleCamelContexts) { contextName = file.getParentFile().getName(); @@ -239,33 +247,10 @@ if (multipleCamelContexts) { contextName = file.getParentFile().getName(); } - StringWriter buffer = new StringWriter(); - PrintWriter out = new PrintWriter(buffer); - printHtmlHeader(out, contextName); - printHtmlFileHeader(out, file); - for (int j = 0; j < graphvizOutputTypes.length; j++) { - String format = graphvizOutputTypes[j]; - String generated = convertFile(file, format); - if (generated != null && format.equals("cmapx")) { - // lets include the generated file inside the html - addFileToBuffer(out, new File(generated)); - } - } - printHtmlFileFooter(out, file); - printHtmlFooter(out); + getLog().info( "Generating contextName: " + contextName + " file: " + file + "" ); - String content = buffer.toString(); - String name = file.getName(); - if (name.equalsIgnoreCase("routes.dot") || i == 0) { - indexHtmlContent = content; - } - int idx = name.lastIndexOf("."); - if (idx >= 0) { - name = name.substring(0, idx); - name += ".html"; - } - writeIndexHtmlFile(file.getParentFile(), name, content); + generate( i, file, contextName ); } if (multipleCamelContexts) { @@ -272,20 +257,20 @@ // lets generate an index page which lists each indiviual // CamelContext file StringWriter buffer = new StringWriter(); - PrintWriter out = new PrintWriter(buffer); + PrintWriter out = new PrintWriter( buffer ); - out.println("

Camel Contexts

"); + out.println( "

Camel Contexts

" ); out.println(); - out.println("" ); indexHtmlContent = buffer.toString(); } } @@ -290,13 +275,44 @@ } } catch (CommandLineException e) { - throw new MojoExecutionException("Failed: " + e, e); + throw new MojoExecutionException( "Failed: " + e, e ); } catch (IOException e) { - throw new MojoExecutionException("Failed: " + e, e); + throw new MojoExecutionException( "Failed: " + e, e ); } } + private void generate( int index, File file, String contextName ) throws CommandLineException, MojoExecutionException, IOException { + + StringWriter buffer = new StringWriter(); + PrintWriter out = new PrintWriter( buffer ); + printHtmlHeader( out, contextName ); + printHtmlFileHeader( out, file ); + for (int j = 0; j < graphvizOutputTypes.length; j++) { + String format = graphvizOutputTypes[j]; + String generated = convertFile( file, format ); + + if (format.equals( "cmapx" ) && generated != null) { + // lets include the generated file inside the html + addFileToBuffer( out, new File( generated ) ); + } + } + printHtmlFileFooter( out, file ); + printHtmlFooter( out ); + + String content = buffer.toString(); + String name = file.getName(); + if (name.equalsIgnoreCase( "routes.dot" ) || index == 0) { + indexHtmlContent = content; + } + int idx = name.lastIndexOf( "." ); + if (idx >= 0) { + name = name.substring( 0, idx ); + name += ".html"; + } + writeIndexHtmlFile( file.getParentFile(), name, content ); + } + protected void runCamelEmbedded(File outputDir) throws DependencyResolutionRequiredException { if (runCamel) { getLog().info("Running Camel embedded to load META-INF/spring/*.xml files"); @@ -307,6 +323,10 @@ EmbeddedMojo mojo = new EmbeddedMojo(); mojo.setClasspathElements(list); mojo.setDotEnabled(true); + if ("true".equals( getAggregate() )) { + + mojo.setDotAggregationEnabled( true ); + } mojo.setOutputDirectory(outputDirectory.getAbsolutePath()); mojo.setDuration(duration); mojo.setLog(getLog()); @@ -499,4 +519,14 @@ protected MavenProject getProject() { return this.project; } + + public String getAggregate() { + + return aggregate; + } + + public void setAggregate( String aggregate ) { + + this.aggregate = aggregate; + } }