Return-Path: X-Original-To: apmail-camel-commits-archive@www.apache.org Delivered-To: apmail-camel-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 7D7F8C18A for ; Fri, 14 Nov 2014 08:29:33 +0000 (UTC) Received: (qmail 75900 invoked by uid 500); 14 Nov 2014 08:29:33 -0000 Delivered-To: apmail-camel-commits-archive@camel.apache.org Received: (qmail 75750 invoked by uid 500); 14 Nov 2014 08:29:33 -0000 Mailing-List: contact commits-help@camel.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@camel.apache.org Delivered-To: mailing list commits@camel.apache.org Received: (qmail 75716 invoked by uid 99); 14 Nov 2014 08:29:33 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 14 Nov 2014 08:29:33 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 13B9A93AF43; Fri, 14 Nov 2014 08:29:33 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: davsclaus@apache.org To: commits@camel.apache.org Date: Fri, 14 Nov 2014 08:29:35 -0000 Message-Id: In-Reply-To: <65d123cbac7d44f6b32efbf0759943e4@git.apache.org> References: <65d123cbac7d44f6b32efbf0759943e4@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [04/11] camel git commit: CAMEL-7999: Maven plugin to generate a list of all Camel components. CAMEL-7999: Maven plugin to generate a list of all Camel components. Project: http://git-wip-us.apache.org/repos/asf/camel/repo Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/251010ef Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/251010ef Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/251010ef Branch: refs/heads/master Commit: 251010efd3fedb87ce693f0e3fcf9deefbb4a0c4 Parents: 908b575 Author: Claus Ibsen Authored: Thu Nov 13 18:13:41 2014 +0100 Committer: Claus Ibsen Committed: Thu Nov 13 18:13:41 2014 +0100 ---------------------------------------------------------------------- components/pom.xml | 9 -- platforms/commands/commands-core/pom.xml | 32 +------ .../apache/camel/commands/CamelController.java | 2 +- .../commands/catalog/CamelComponentCatalog.java | 3 + .../maven/packaging/CommandsPrepareMojo.java | 91 ++++++++++++++++++-- 5 files changed, 91 insertions(+), 46 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/251010ef/components/pom.xml ---------------------------------------------------------------------- diff --git a/components/pom.xml b/components/pom.xml index f18e37c..d761d6f 100644 --- a/components/pom.xml +++ b/components/pom.xml @@ -270,15 +270,6 @@ - - - - org.apache.camel - camel-package-maven-plugin - ${project.version} - - - http://git-wip-us.apache.org/repos/asf/camel/blob/251010ef/platforms/commands/commands-core/pom.xml ---------------------------------------------------------------------- diff --git a/platforms/commands/commands-core/pom.xml b/platforms/commands/commands-core/pom.xml index bb616c7..03f9bdb 100644 --- a/platforms/commands/commands-core/pom.xml +++ b/platforms/commands/commands-core/pom.xml @@ -33,8 +33,6 @@ org.apache.camel.commands.* - ../../../camel-core/ - ../../../components/ @@ -81,35 +79,7 @@ - - maven-antrun-plugin - 1.7 - - - process-resources - - - Copying component json descriptors - - - - - - - - - - - - - - - run - - - - - + org.apache.camel camel-package-maven-plugin http://git-wip-us.apache.org/repos/asf/camel/blob/251010ef/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java ---------------------------------------------------------------------- diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java index 645f865..199f58e 100644 --- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java +++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/CamelController.java @@ -117,7 +117,7 @@ public interface CamelController { String explainEndpoint(String camelContextName, String uri, boolean allOptions) throws Exception; /** - * Lists all components and include information + * Lists Components which are in use or available on the classpath and include information * * @param camelContextName the Camel context. * @return a list of key/value pairs with component information http://git-wip-us.apache.org/repos/asf/camel/blob/251010ef/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/catalog/CamelComponentCatalog.java ---------------------------------------------------------------------- diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/catalog/CamelComponentCatalog.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/catalog/CamelComponentCatalog.java index 65ba2af..7bac695 100644 --- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/catalog/CamelComponentCatalog.java +++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/catalog/CamelComponentCatalog.java @@ -18,6 +18,9 @@ package org.apache.camel.commands.catalog; import java.util.List; +/** + * Catalog of all the Camel components from this Apache Camel release. + */ public interface CamelComponentCatalog { /** http://git-wip-us.apache.org/repos/asf/camel/blob/251010ef/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/CommandsPrepareMojo.java ---------------------------------------------------------------------- diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/CommandsPrepareMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/CommandsPrepareMojo.java index 6f2ff69..b807a54 100644 --- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/CommandsPrepareMojo.java +++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/CommandsPrepareMojo.java @@ -17,11 +17,16 @@ package org.apache.camel.maven.packaging; import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; import java.io.FileOutputStream; import java.io.IOException; +import java.nio.channels.FileChannel; import java.util.ArrayList; import java.util.Collections; +import java.util.LinkedHashSet; import java.util.List; +import java.util.Set; import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; @@ -37,6 +42,8 @@ import org.apache.maven.project.MavenProjectHelper; */ public class CommandsPrepareMojo extends AbstractMojo { + public static final int BUFFER_SIZE = 128 * 1024; + /** * The maven project. * @@ -56,14 +63,14 @@ public class CommandsPrepareMojo extends AbstractMojo { /** * The components directory where all the Apache Camel components are * - * @parameter default-value="${project.build.directory}/../../../components" + * @parameter default-value="${project.build.directory}/../../../../components" */ protected File componentsDir; /** * The camel-core directory where camel-core components are * - * @parameter default-value="${project.build.directory}/../../../camel-core" + * @parameter default-value="${project.build.directory}/../../../../camel-core" */ protected File coreDir; @@ -85,7 +92,38 @@ public class CommandsPrepareMojo extends AbstractMojo { public void execute() throws MojoExecutionException, MojoFailureException { getLog().info("Copying all Camel component json descriptors"); - // TODO: add the scan and copy code here + Set files = new LinkedHashSet(); + + // find all json files in components and camel-core + if (componentsDir != null && componentsDir.isDirectory()) { + File[] components = componentsDir.listFiles(); + if (components != null) { + for (File dir : components) { + if (dir.isDirectory()) { + File target = new File(dir, "target/classes"); + findFilesRecursive(target, files, new JsonAndDirFileFilter()); + } + } + } + } + if (coreDir != null && coreDir.isDirectory()) { + File target = new File(coreDir, "target/classes"); + findFilesRecursive(target, files, new JsonAndDirFileFilter()); + } + + getLog().info("Found " + files.size() + " component json files"); + + // make sure to create out dir + outDir.mkdirs(); + + for (File file : files) { + File to = new File(outDir, file.getName()); + try { + copyFile(file, to); + } catch (IOException e) { + throw new MojoFailureException("Cannot copy file from " + file + " -> " + to, e); + } + } File all = new File(outDir, "../components-catalog"); try { @@ -110,11 +148,54 @@ public class CommandsPrepareMojo extends AbstractMojo { fos.close(); - getLog().info("Found " + components.size() + " components to include in file: " + all); - + getLog().info("Camel components catalog includes " + files.size() + " components"); } catch (IOException e) { throw new MojoFailureException("Error writing to file " + all); } } + private void findFilesRecursive(File dir, Set found, FileFilter filter) { + File[] files = dir.listFiles(filter); + if (files != null) { + for (File file : files) { + if (file.isFile()) { + found.add(file); + } else if (file.isDirectory()) { + findFilesRecursive(file, found, filter); + } + } + } + } + + private class JsonAndDirFileFilter implements FileFilter { + + @Override + public boolean accept(File pathname) { + return pathname.isDirectory() || pathname.getName().endsWith(".json"); + } + } + + public static void copyFile(File from, File to) throws IOException { + FileChannel in = null; + FileChannel out = null; + try { + in = new FileInputStream(from).getChannel(); + out = new FileOutputStream(to).getChannel(); + + long size = in.size(); + long position = 0; + while (position < size) { + position += in.transferTo(position, BUFFER_SIZE, out); + } + } finally { + if (in != null) { + in.close(); + } + if (out != null) { + out.close(); + } + } + } + + } \ No newline at end of file