You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2014/11/14 09:29:38 UTC
[07/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/44a18c6b
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/44a18c6b
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/44a18c6b
Branch: refs/heads/master
Commit: 44a18c6b62e89de640067276141d159ed03b3022
Parents: 7e552e8
Author: Claus Ibsen <da...@apache.org>
Authored: Thu Nov 13 18:54:32 2014 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Thu Nov 13 18:54:32 2014 +0100
----------------------------------------------------------------------
platforms/catalog/pom.xml | 3 +-
.../catalog/DefaultCamelComponentCatalog.java | 7 +-
platforms/commands/commands-core/pom.xml | 15 --
.../maven/packaging/CommandsPrepareMojo.java | 201 -------------------
.../maven/packaging/PrepareCatalogMojo.java | 201 +++++++++++++++++++
5 files changed, 208 insertions(+), 219 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/44a18c6b/platforms/catalog/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/catalog/pom.xml b/platforms/catalog/pom.xml
index 2cb1ce2..fd22cde 100644
--- a/platforms/catalog/pom.xml
+++ b/platforms/catalog/pom.xml
@@ -54,7 +54,7 @@
<executions>
<execution>
<goals>
- <goal>include-components-list</goal>
+ <goal>prepare-catalog</goal>
</goals>
<phase>process-resources</phase>
</execution>
@@ -67,6 +67,7 @@
<extensions>true</extensions>
</plugin>
</plugins>
+
</build>
</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/44a18c6b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelComponentCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelComponentCatalog.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelComponentCatalog.java
index 28e4f0c..5d9902d 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelComponentCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelComponentCatalog.java
@@ -24,10 +24,13 @@ import java.io.LineNumberReader;
import java.util.ArrayList;
import java.util.List;
+/**
+ * Default {@link org.apache.camel.catalog.CamelComponentCatalog}.
+ */
public class DefaultCamelComponentCatalog implements CamelComponentCatalog {
- private static String COMPONENTS_CATALOG = "org/apache/camel/catalog/components.properties";
- private static String COMPONENTS_JSON = "org/apache/camel/catalog/components";
+ private static final String COMPONENTS_CATALOG = "org/apache/camel/catalog/components.properties";
+ private static final String COMPONENTS_JSON = "org/apache/camel/catalog/components";
@Override
public List<String> findComponentNames() {
http://git-wip-us.apache.org/repos/asf/camel/blob/44a18c6b/platforms/commands/commands-core/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/commands/commands-core/pom.xml b/platforms/commands/commands-core/pom.xml
index 1650572..a750f13 100644
--- a/platforms/commands/commands-core/pom.xml
+++ b/platforms/commands/commands-core/pom.xml
@@ -73,21 +73,6 @@
<build>
<plugins>
- <!-- generate and include all components in the catalog -->
- <plugin>
- <groupId>org.apache.camel</groupId>
- <artifactId>camel-package-maven-plugin</artifactId>
- <version>${project.version}</version>
- <executions>
- <execution>
- <goals>
- <goal>include-components-list</goal>
- </goals>
- <phase>process-resources</phase>
- </execution>
- </executions>
- </plugin>
-
<plugin>
<groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId>
http://git-wip-us.apache.org/repos/asf/camel/blob/44a18c6b/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
deleted file mode 100644
index 54a779d..0000000
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/CommandsPrepareMojo.java
+++ /dev/null
@@ -1,201 +0,0 @@
-/**
- * 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.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;
-import org.apache.maven.plugin.MojoFailureException;
-import org.apache.maven.project.MavenProject;
-import org.apache.maven.project.MavenProjectHelper;
-
-/**
- * Analyses the Camel plugins in a project and generates extra descriptor information for easier auto-discovery in Camel.
- *
- * @goal include-components-list
- * @execute phase="process-resources"
- */
-public class CommandsPrepareMojo extends AbstractMojo {
-
- public static final int BUFFER_SIZE = 128 * 1024;
-
- /**
- * The maven project.
- *
- * @parameter property="project"
- * @required
- * @readonly
- */
- protected MavenProject project;
-
- /**
- * The output directory for components catalog
- *
- * @parameter default-value="${project.build.directory}/classes/org/apache/camel/catalog/components"
- */
- protected File outDir;
-
- /**
- * The components directory where all the Apache Camel components are
- *
- * @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"
- */
- protected File coreDir;
-
- /**
- * Maven ProjectHelper.
- *
- * @component
- * @readonly
- */
- private MavenProjectHelper projectHelper;
-
- /**
- * Execute goal.
- *
- * @throws org.apache.maven.plugin.MojoExecutionException execution of the main class or one of the
- * threads it generated failed.
- * @throws org.apache.maven.plugin.MojoFailureException something bad happened...
- */
- public void execute() throws MojoExecutionException, MojoFailureException {
- getLog().info("Copying all Camel component json descriptors");
-
- Set<File> files = new LinkedHashSet<File>();
-
- // 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.properties");
- try {
- FileOutputStream fos = new FileOutputStream(all, false);
-
- String[] names = outDir.list();
- List<String> components = new ArrayList<String>();
- // sort the names
- for (String name : names) {
- if (name.endsWith(".json")) {
- // strip out .json from the name
- String componentName = name.substring(0, name.length() - 5);
- components.add(componentName);
- }
- }
-
- Collections.sort(components);
- for (String name : components) {
- fos.write(name.getBytes());
- fos.write("\n".getBytes());
- }
-
- fos.close();
-
- 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<File> 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
http://git-wip-us.apache.org/repos/asf/camel/blob/44a18c6b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
new file mode 100644
index 0000000..70d8e11
--- /dev/null
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogMojo.java
@@ -0,0 +1,201 @@
+/**
+ * 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.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;
+import org.apache.maven.plugin.MojoFailureException;
+import org.apache.maven.project.MavenProject;
+import org.apache.maven.project.MavenProjectHelper;
+
+/**
+ * Analyses the Camel plugins in a project and generates extra descriptor information for easier auto-discovery in Camel.
+ *
+ * @goal prepare-catalog
+ * @execute phase="process-resources"
+ */
+public class PrepareCatalogMojo extends AbstractMojo {
+
+ public static final int BUFFER_SIZE = 128 * 1024;
+
+ /**
+ * The maven project.
+ *
+ * @parameter property="project"
+ * @required
+ * @readonly
+ */
+ protected MavenProject project;
+
+ /**
+ * The output directory for components catalog
+ *
+ * @parameter default-value="${project.build.directory}/classes/org/apache/camel/catalog/components"
+ */
+ protected File outDir;
+
+ /**
+ * The components directory where all the Apache Camel components are
+ *
+ * @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"
+ */
+ protected File coreDir;
+
+ /**
+ * Maven ProjectHelper.
+ *
+ * @component
+ * @readonly
+ */
+ private MavenProjectHelper projectHelper;
+
+ /**
+ * Execute goal.
+ *
+ * @throws org.apache.maven.plugin.MojoExecutionException execution of the main class or one of the
+ * threads it generated failed.
+ * @throws org.apache.maven.plugin.MojoFailureException something bad happened...
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ getLog().info("Copying all Camel component json descriptors");
+
+ Set<File> files = new LinkedHashSet<File>();
+
+ // 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.properties");
+ try {
+ FileOutputStream fos = new FileOutputStream(all, false);
+
+ String[] names = outDir.list();
+ List<String> components = new ArrayList<String>();
+ // sort the names
+ for (String name : names) {
+ if (name.endsWith(".json")) {
+ // strip out .json from the name
+ String componentName = name.substring(0, name.length() - 5);
+ components.add(componentName);
+ }
+ }
+
+ Collections.sort(components);
+ for (String name : components) {
+ fos.write(name.getBytes());
+ fos.write("\n".getBytes());
+ }
+
+ fos.close();
+
+ 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<File> 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