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/7e552e81 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7e552e81 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7e552e81 Branch: refs/heads/master Commit: 7e552e817691291c1e6d614a8b28c1b7a5a21e62 Parents: a6f335b Author: Claus Ibsen <davscl...@apache.org> Authored: Thu Nov 13 18:50:43 2014 +0100 Committer: Claus Ibsen <davscl...@apache.org> Committed: Thu Nov 13 18:50:43 2014 +0100 ---------------------------------------------------------------------- parent/pom.xml | 5 + platforms/catalog/pom.xml | 72 +++++++++++ .../camel/catalog/CamelComponentCatalog.java | 38 ++++++ .../catalog/DefaultCamelComponentCatalog.java | 118 ++++++++++++++++++ platforms/commands/commands-core/pom.xml | 8 +- .../camel/commands/AbstractCamelController.java | 7 +- .../commands/catalog/CamelComponentCatalog.java | 38 ------ .../catalog/CamelComponentCatalogService.java | 120 ------------------- .../catalog/CamelComponentCatalogTest.java | 8 +- .../features/src/main/resources/features.xml | 1 + platforms/pom.xml | 1 + .../maven/packaging/CommandsPrepareMojo.java | 10 +- 12 files changed, 249 insertions(+), 177 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/camel/blob/7e552e81/parent/pom.xml ---------------------------------------------------------------------- diff --git a/parent/pom.xml b/parent/pom.xml index 9153c05..be9775e 100644 --- a/parent/pom.xml +++ b/parent/pom.xml @@ -1489,6 +1489,11 @@ <!-- camel commands --> <dependency> <groupId>org.apache.camel</groupId> + <artifactId>camel-catalog</artifactId> + <version>${project.version}</version> + </dependency> + <dependency> + <groupId>org.apache.camel</groupId> <artifactId>camel-commands-core</artifactId> <version>${project.version}</version> </dependency> http://git-wip-us.apache.org/repos/asf/camel/blob/7e552e81/platforms/catalog/pom.xml ---------------------------------------------------------------------- diff --git a/platforms/catalog/pom.xml b/platforms/catalog/pom.xml new file mode 100644 index 0000000..2cb1ce2 --- /dev/null +++ b/platforms/catalog/pom.xml @@ -0,0 +1,72 @@ +<?xml version="1.0" encoding="UTF-8"?> +<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + <!-- + 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. + --> + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.camel</groupId> + <artifactId>platforms</artifactId> + <version>2.15-SNAPSHOT</version> + </parent> + + <artifactId>camel-catalog</artifactId> + <packaging>bundle</packaging> + <name>Camel :: Platforms :: Catalog</name> + <description>Camel Catalog</description> + + <properties> + <camel.osgi.export.pkg> + org.apache.camel.catalog, + org.apache.camel.catalog.components + </camel.osgi.export.pkg> + </properties> + + <dependencies> + + <!-- no dependency --> + + </dependencies> + + <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> + <extensions>true</extensions> + </plugin> + </plugins> + </build> + +</project> http://git-wip-us.apache.org/repos/asf/camel/blob/7e552e81/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelComponentCatalog.java ---------------------------------------------------------------------- diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelComponentCatalog.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelComponentCatalog.java new file mode 100644 index 0000000..721ca51 --- /dev/null +++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelComponentCatalog.java @@ -0,0 +1,38 @@ +/** + * 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.catalog; + +import java.util.List; + +/** + * Catalog of all the Camel components from this Apache Camel release. + */ +public interface CamelComponentCatalog { + + /** + * Find all the component names from the Camel catalog + */ + List<String> findComponentNames(); + + /** + * Returns the component information as JSon format. + * + * @param name the component name + * @return component details in JSon + */ + String componentJSonSchema(String name); +} http://git-wip-us.apache.org/repos/asf/camel/blob/7e552e81/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 new file mode 100644 index 0000000..28e4f0c --- /dev/null +++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelComponentCatalog.java @@ -0,0 +1,118 @@ +/** + * 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.catalog; + +import java.io.BufferedReader; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.LineNumberReader; +import java.util.ArrayList; +import java.util.List; + +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"; + + @Override + public List<String> findComponentNames() { + List<String> names = new ArrayList<String>(); + + InputStream is = DefaultCamelComponentCatalog.class.getClassLoader().getResourceAsStream(COMPONENTS_CATALOG); + if (is != null) { + try { + loadLines(is, names); + } catch (IOException e) { + // ignore + } + } + return names; + } + + @Override + public String componentJSonSchema(String name) { + String file = COMPONENTS_JSON + "/" + name + ".json"; + + InputStream is = DefaultCamelComponentCatalog.class.getClassLoader().getResourceAsStream(file); + if (is != null) { + try { + return loadText(is); + } catch (IOException e) { + // ignore + } + } + + return null; + } + + /** + * Loads the entire stream into memory as a String and returns it. + * <p/> + * <b>Notice:</b> This implementation appends a <tt>\n</tt> as line + * terminator at the of the text. + * <p/> + * Warning, don't use for crazy big streams :) + */ + private static void loadLines(InputStream in, List<String> lines) throws IOException { + InputStreamReader isr = new InputStreamReader(in); + try { + BufferedReader reader = new LineNumberReader(isr); + while (true) { + String line = reader.readLine(); + if (line != null) { + lines.add(line); + } else { + break; + } + } + } finally { + isr.close(); + in.close(); + } + } + + /** + * Loads the entire stream into memory as a String and returns it. + * <p/> + * <b>Notice:</b> This implementation appends a <tt>\n</tt> as line + * terminator at the of the text. + * <p/> + * Warning, don't use for crazy big streams :) + */ + public static String loadText(InputStream in) throws IOException { + StringBuilder builder = new StringBuilder(); + InputStreamReader isr = new InputStreamReader(in); + try { + BufferedReader reader = new LineNumberReader(isr); + while (true) { + String line = reader.readLine(); + if (line != null) { + builder.append(line); + builder.append("\n"); + } else { + break; + } + } + return builder.toString(); + } finally { + isr.close(); + in.close(); + } + } + +} http://git-wip-us.apache.org/repos/asf/camel/blob/7e552e81/platforms/commands/commands-core/pom.xml ---------------------------------------------------------------------- diff --git a/platforms/commands/commands-core/pom.xml b/platforms/commands/commands-core/pom.xml index 03f9bdb..1650572 100644 --- a/platforms/commands/commands-core/pom.xml +++ b/platforms/commands/commands-core/pom.xml @@ -44,13 +44,7 @@ </dependency> <dependency> <groupId>org.apache.camel</groupId> - <artifactId>components</artifactId> - <version>${project.version}</version> - <type>pom</type> - </dependency> - <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-ftp</artifactId> + <artifactId>camel-catalog</artifactId> </dependency> <dependency> <groupId>org.slf4j</groupId> http://git-wip-us.apache.org/repos/asf/camel/blob/7e552e81/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java ---------------------------------------------------------------------- diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java index 23fde80..56e69e6 100644 --- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java +++ b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/AbstractCamelController.java @@ -28,8 +28,8 @@ import java.util.Properties; import org.apache.camel.CamelContext; import org.apache.camel.Endpoint; import org.apache.camel.Route; -import org.apache.camel.commands.catalog.CamelComponentCatalog; -import org.apache.camel.commands.catalog.CamelComponentCatalogService; +import org.apache.camel.catalog.CamelComponentCatalog; +import org.apache.camel.catalog.DefaultCamelComponentCatalog; import org.apache.camel.model.RouteDefinition; import org.apache.camel.model.rest.RestDefinition; import org.apache.camel.spi.RestRegistry; @@ -40,7 +40,7 @@ import org.apache.camel.util.JsonSchemaHelper; */ public abstract class AbstractCamelController implements CamelController { - private CamelComponentCatalog catalog = new CamelComponentCatalogService(); + private CamelComponentCatalog catalog = new DefaultCamelComponentCatalog(); public CamelContext getCamelContext(String name) { for (CamelContext camelContext : this.getCamelContexts()) { @@ -274,7 +274,6 @@ public abstract class AbstractCamelController implements CamelController { public List<Map<String, String>> listComponentsCatalog() throws Exception { List<Map<String, String>> answer = new ArrayList<Map<String, String>>(); - CamelComponentCatalogService catalog = new CamelComponentCatalogService(); List<String> names = catalog.findComponentNames(); for (String name : names) { // load component json data, and parse it to gather the component meta-data http://git-wip-us.apache.org/repos/asf/camel/blob/7e552e81/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 deleted file mode 100644 index 7bac695..0000000 --- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/catalog/CamelComponentCatalog.java +++ /dev/null @@ -1,38 +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.commands.catalog; - -import java.util.List; - -/** - * Catalog of all the Camel components from this Apache Camel release. - */ -public interface CamelComponentCatalog { - - /** - * Find all the component names from the Camel catalog - */ - List<String> findComponentNames(); - - /** - * Returns the component information as JSon format. - * - * @param name the component name - * @return component details in JSon - */ - String componentJSonSchema(String name); -} http://git-wip-us.apache.org/repos/asf/camel/blob/7e552e81/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/catalog/CamelComponentCatalogService.java ---------------------------------------------------------------------- diff --git a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/catalog/CamelComponentCatalogService.java b/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/catalog/CamelComponentCatalogService.java deleted file mode 100644 index a163a86..0000000 --- a/platforms/commands/commands-core/src/main/java/org/apache/camel/commands/catalog/CamelComponentCatalogService.java +++ /dev/null @@ -1,120 +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.commands.catalog; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.io.LineNumberReader; -import java.util.ArrayList; -import java.util.List; - -public class CamelComponentCatalogService implements CamelComponentCatalog { - - private static String COMPONENTS_CATALOG = "org/apache/camel/commands/catalog/components-catalog"; - private static String COMPONENTS_JSON = "org/apache/camel/commands/catalog/components"; - - @Override - public List<String> findComponentNames() { - List<String> names = new ArrayList<String>(); - - InputStream is = CamelComponentCatalogService.class.getClassLoader().getResourceAsStream(COMPONENTS_CATALOG); - if (is != null) { - try { - loadLines(is, names); - } catch (IOException e) { - // ignore - } - } - return names; - } - - @Override - public String componentJSonSchema(String name) { - String file = COMPONENTS_JSON + "/" + name + ".json"; - - InputStream is = CamelComponentCatalogService.class.getClassLoader().getResourceAsStream(file); - if (is != null) { - try { - return loadText(is); - } catch (IOException e) { - // ignore - } - } - - return null; - } - - /** - * Loads the entire stream into memory as a String and returns it. - * <p/> - * <b>Notice:</b> This implementation appends a <tt>\n</tt> as line - * terminator at the of the text. - * <p/> - * Warning, don't use for crazy big streams :) - */ - private static void loadLines(InputStream in, List<String> lines) throws IOException { - InputStreamReader isr = new InputStreamReader(in); - try { - BufferedReader reader = new LineNumberReader(isr); - while (true) { - String line = reader.readLine(); - if (line != null) { - lines.add(line); - } else { - break; - } - } - } finally { - isr.close(); - in.close(); - } - } - - /** - * Loads the entire stream into memory as a String and returns it. - * <p/> - * <b>Notice:</b> This implementation appends a <tt>\n</tt> as line - * terminator at the of the text. - * <p/> - * Warning, don't use for crazy big streams :) - */ - public static String loadText(InputStream in) throws IOException { - StringBuilder builder = new StringBuilder(); - InputStreamReader isr = new InputStreamReader(in); - try { - BufferedReader reader = new LineNumberReader(isr); - while (true) { - String line = reader.readLine(); - if (line != null) { - builder.append(line); - builder.append("\n"); - } else { - break; - } - } - return builder.toString(); - } finally { - isr.close(); - in.close(); - } - } - - - -} http://git-wip-us.apache.org/repos/asf/camel/blob/7e552e81/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/catalog/CamelComponentCatalogTest.java ---------------------------------------------------------------------- diff --git a/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/catalog/CamelComponentCatalogTest.java b/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/catalog/CamelComponentCatalogTest.java index 1090670..4f08b71 100644 --- a/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/catalog/CamelComponentCatalogTest.java +++ b/platforms/commands/commands-core/src/test/java/org/apache/camel/commands/catalog/CamelComponentCatalogTest.java @@ -19,6 +19,8 @@ package org.apache.camel.commands.catalog; import java.util.List; import junit.framework.TestCase; +import org.apache.camel.catalog.CamelComponentCatalog; +import org.apache.camel.catalog.DefaultCamelComponentCatalog; import org.junit.Test; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -29,7 +31,7 @@ public class CamelComponentCatalogTest extends TestCase { @Test public void testFindComponentNames() { - CamelComponentCatalog catalog = new CamelComponentCatalogService(); + CamelComponentCatalog catalog = new DefaultCamelComponentCatalog(); List<String> names = catalog.findComponentNames(); assertNotNull(names); @@ -40,7 +42,7 @@ public class CamelComponentCatalogTest extends TestCase { @Test public void testCoreComponentJson() { - CamelComponentCatalog catalog = new CamelComponentCatalogService(); + CamelComponentCatalog catalog = new DefaultCamelComponentCatalog(); String json = catalog.componentJSonSchema("bean"); assertNotNull(json); @@ -51,7 +53,7 @@ public class CamelComponentCatalogTest extends TestCase { @Test public void testFtpComponentJson() { - CamelComponentCatalog catalog = new CamelComponentCatalogService(); + CamelComponentCatalog catalog = new DefaultCamelComponentCatalog(); String json = catalog.componentJSonSchema("ftp"); assertNotNull(json); http://git-wip-us.apache.org/repos/asf/camel/blob/7e552e81/platforms/karaf/features/src/main/resources/features.xml ---------------------------------------------------------------------- diff --git a/platforms/karaf/features/src/main/resources/features.xml b/platforms/karaf/features/src/main/resources/features.xml index c00347f..d8a63f6 100644 --- a/platforms/karaf/features/src/main/resources/features.xml +++ b/platforms/karaf/features/src/main/resources/features.xml @@ -36,6 +36,7 @@ <feature name='camel-core' version='${project.version}' resolver='(obr)' start-level='50'> <feature version='${servicemix-specs-version}'>xml-specs-api</feature> <bundle>mvn:org.apache.camel/camel-core/${project.version}</bundle> + <bundle>mvn:org.apache.camel/camel-catalog/${project.version}</bundle> <bundle>mvn:org.apache.camel/camel-commands-core/${project.version}</bundle> <bundle>mvn:org.apache.camel.karaf/camel-karaf-commands/${project.version}</bundle> </feature> http://git-wip-us.apache.org/repos/asf/camel/blob/7e552e81/platforms/pom.xml ---------------------------------------------------------------------- diff --git a/platforms/pom.xml b/platforms/pom.xml index e699ca7..cdaf2af 100644 --- a/platforms/pom.xml +++ b/platforms/pom.xml @@ -32,6 +32,7 @@ <packaging>pom</packaging> <modules> + <module>catalog</module> <module>commands</module> <module>karaf</module> </modules> http://git-wip-us.apache.org/repos/asf/camel/blob/7e552e81/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 b807a54..54a779d 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 @@ -54,23 +54,23 @@ public class CommandsPrepareMojo extends AbstractMojo { protected MavenProject project; /** - * The output directory for generated components file + * The output directory for components catalog * - * @parameter default-value="${project.build.directory}/classes/org/apache/camel/commands/catalog/components" + * @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" + * @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; @@ -125,7 +125,7 @@ public class CommandsPrepareMojo extends AbstractMojo { } } - File all = new File(outDir, "../components-catalog"); + File all = new File(outDir, "../components.properties"); try { FileOutputStream fos = new FileOutputStream(all, false);