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 2016/11/07 14:17:22 UTC
[1/5] camel git commit: CAMEL-10434: Camel catalog support different
runtimes to provide their supported list of components etc.
Repository: camel
Updated Branches:
refs/heads/master 10c2e35f2 -> 1691c6237
CAMEL-10434: Camel catalog support different runtimes to provide their supported list of components etc.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3da8d1e4
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3da8d1e4
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3da8d1e4
Branch: refs/heads/master
Commit: 3da8d1e47cd016708b6d4b6580842389116fd5d8
Parents: 048b709
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Nov 7 14:21:05 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Nov 7 14:22:49 2016 +0100
----------------------------------------------------------------------
platforms/catalog-provider-karaf/pom.xml | 2 +-
.../catalog/karaf/KarafRuntimeProvider.java | 117 ++++++++++++++++++-
.../catalog/karaf/KarafRuntimeProviderTest.java | 93 +++++++++++++++
.../camel-spring-boot-dependencies/pom.xml | 2 +-
4 files changed, 209 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/3da8d1e4/platforms/catalog-provider-karaf/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/catalog-provider-karaf/pom.xml b/platforms/catalog-provider-karaf/pom.xml
index 9aafd73..6923faa 100644
--- a/platforms/catalog-provider-karaf/pom.xml
+++ b/platforms/catalog-provider-karaf/pom.xml
@@ -89,7 +89,7 @@
<goal>copy-resources</goal>
</goals>
<configuration>
- <outputDirectory>${basedir}/target/resources</outputDirectory>
+ <outputDirectory>${basedir}/target/classes/org/apache/camel/catalog/karaf</outputDirectory>
<resources>
<resource>
<directory>../karaf/features/target/classes</directory>
http://git-wip-us.apache.org/repos/asf/camel/blob/3da8d1e4/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java
----------------------------------------------------------------------
diff --git a/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java b/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java
index 071d6e9..9c8ac17 100644
--- a/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java
+++ b/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java
@@ -16,14 +16,30 @@
*/
package org.apache.camel.catalog.karaf;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.HashMap;
import java.util.List;
+import java.util.Map;
+import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.camel.catalog.CamelCatalog;
+import org.apache.camel.catalog.DefaultRuntimeProvider;
+import org.apache.camel.catalog.JSonSchemaHelper;
import org.apache.camel.catalog.RuntimeProvider;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+
+import static org.w3c.dom.Node.ELEMENT_NODE;
public class KarafRuntimeProvider implements RuntimeProvider {
+ private static final String FEATURES = "org/apache/camel/catalog/karaf/features.xml";
private CamelCatalog camelCatalog;
+ private DefaultRuntimeProvider defaultProvider = new DefaultRuntimeProvider();
+
+ private Map<String, List<Map<String, String>>> rowsCache = new HashMap<>();
@Override
public CamelCatalog getCamelCatalog() {
@@ -33,6 +49,7 @@ public class KarafRuntimeProvider implements RuntimeProvider {
@Override
public void setCamelCatalog(CamelCatalog camelCatalog) {
this.camelCatalog = camelCatalog;
+ this.defaultProvider.setCamelCatalog(camelCatalog);
}
@Override
@@ -42,17 +59,111 @@ public class KarafRuntimeProvider implements RuntimeProvider {
@Override
public List<String> findComponentNames() {
- // parse the karaf features xml file
- return null;
+ // find the component name from all the default components
+ List<String> allNames = defaultProvider.findComponentNames();
+
+ List<String> answer = new ArrayList<>();
+
+ // filter out to only include what's in the karaf features file
+ InputStream is = camelCatalog.getVersionManager().getResourceAsStream(FEATURES);
+ if (is != null) {
+ try {
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setIgnoringComments(true);
+ dbf.setIgnoringElementContentWhitespace(true);
+ dbf.setNamespaceAware(false);
+ dbf.setValidating(false);
+ dbf.setXIncludeAware(false);
+ Document dom = dbf.newDocumentBuilder().parse(is);
+ NodeList children = dom.getElementsByTagName("features");
+
+ for (int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ if (child.getNodeType() == ELEMENT_NODE) {
+ NodeList children2 = child.getChildNodes();
+ for (int j = 0; j < children2.getLength(); j++) {
+ Node child2 = children2.item(j);
+ if ("feature".equals(child2.getNodeName())) {
+ // the name attribute is the maven artifact id of the component
+ String artifactId = child2.getAttributes().getNamedItem("name").getTextContent();
+ if (artifactId != null && artifactId.startsWith("camel-")) {
+ // find the component name based on the artifact id
+ String componentName = componentNameFromArtifactId(artifactId, allNames);
+ if (componentName != null) {
+ answer.add(componentName);
+ }
+ }
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+
+ System.out.println("Total components " + allNames.size() + " karaf supports " + answer.size());
+
+ // clear temporary cache
+ rowsCache.clear();
+
+ return answer;
}
@Override
public List<String> findDataFormatNames() {
- return null;
+ // karaf support all data formats
+ return defaultProvider.findDataFormatNames();
}
@Override
public List<String> findLanguageNames() {
+ // karaf support all languages
+ return defaultProvider.findLanguageNames();
+ }
+
+ private String componentNameFromArtifactId(String artifactId, List<String> allNames) {
+ // try a quick shortcut that is faster
+ String quick = artifactId.startsWith("camel-") ? artifactId.substring(6) : null;
+ if (quick != null) {
+ String json = camelCatalog.componentJSonSchema(quick);
+ if (json != null) {
+ List<Map<String, String>> rows = rowsCache.get(quick);
+ if (rows == null) {
+ rows = JSonSchemaHelper.parseJsonSchema("component", json, false);
+ rowsCache.put(quick, rows);
+ }
+ String componentArtifactId = getArtifactId(rows);
+ if (artifactId.equals(componentArtifactId)) {
+ return quick;
+ }
+ }
+ }
+
+ for (String name : allNames) {
+ String json = camelCatalog.componentJSonSchema(name);
+ if (json != null) {
+ List<Map<String, String>> rows = rowsCache.get(quick);
+ if (rows == null) {
+ rows = JSonSchemaHelper.parseJsonSchema("component", json, false);
+ rowsCache.put(quick, rows);
+ }
+ String componentArtifactId = getArtifactId(rows);
+ if (artifactId.equals(componentArtifactId)) {
+ return name;
+ }
+ }
+ }
return null;
}
+
+ public static String getArtifactId(List<Map<String, String>> rows) {
+ for (Map<String, String> row : rows) {
+ if (row.get("artifactId") != null) {
+ return row.get("artifactId");
+ }
+ }
+ return null;
+ }
+
}
http://git-wip-us.apache.org/repos/asf/camel/blob/3da8d1e4/platforms/catalog-provider-karaf/src/test/java/org/apache/camel/catalog/karaf/KarafRuntimeProviderTest.java
----------------------------------------------------------------------
diff --git a/platforms/catalog-provider-karaf/src/test/java/org/apache/camel/catalog/karaf/KarafRuntimeProviderTest.java b/platforms/catalog-provider-karaf/src/test/java/org/apache/camel/catalog/karaf/KarafRuntimeProviderTest.java
new file mode 100644
index 0000000..9d83d52
--- /dev/null
+++ b/platforms/catalog-provider-karaf/src/test/java/org/apache/camel/catalog/karaf/KarafRuntimeProviderTest.java
@@ -0,0 +1,93 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.karaf;
+
+import java.util.List;
+
+import org.apache.camel.catalog.CamelCatalog;
+import org.apache.camel.catalog.DefaultCamelCatalog;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class KarafRuntimeProviderTest {
+
+ static CamelCatalog catalog;
+
+ @BeforeClass
+ public static void createCamelCatalog() {
+ catalog = new DefaultCamelCatalog();
+ catalog.setRuntimeProvider(new KarafRuntimeProvider());
+ }
+
+ @Test
+ public void testGetVersion() throws Exception {
+ String version = catalog.getCatalogVersion();
+ assertNotNull(version);
+
+ String loaded = catalog.getLoadedVersion();
+ assertNotNull(loaded);
+ assertEquals(version, loaded);
+ }
+
+ @Test
+ public void testProviderName() throws Exception {
+ assertEquals("karaf", catalog.getRuntimeProvider().getProviderName());
+ }
+
+ @Test
+ public void testFindComponentNames() throws Exception {
+ List<String> names = catalog.findComponentNames();
+
+ assertNotNull(names);
+ assertFalse(names.isEmpty());
+
+ assertTrue(names.contains("ftp"));
+ assertTrue(names.contains("paxlogging"));
+ // camel-docker does not work in Karaf
+ assertFalse(names.contains("docker"));
+ }
+
+ @Test
+ public void testFindDataFormatNames() throws Exception {
+ List<String> names = catalog.findDataFormatNames();
+
+ assertNotNull(names);
+ assertFalse(names.isEmpty());
+
+ assertTrue(names.contains("bindy-csv"));
+ assertTrue(names.contains("zip"));
+ assertTrue(names.contains("zipfile"));
+ }
+
+ @Test
+ public void testFindLanguageNames() throws Exception {
+ List<String> names = catalog.findLanguageNames();
+
+ assertNotNull(names);
+ assertFalse(names.isEmpty());
+
+ assertTrue(names.contains("simple"));
+ assertTrue(names.contains("spel"));
+ assertTrue(names.contains("xpath"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/3da8d1e4/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml b/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
index edc5462..e8bffa9 100644
--- a/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
+++ b/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
@@ -24,7 +24,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>camel-spring-boot-dependencies</artifactId>
<packaging>pom</packaging>
- <name>Camel :: Platforms :: Spring-Boot :: Dependency Management :: BOM</name>
+ <name>Camel :: Spring-Boot :: Dependency Management :: BOM</name>
<description>Camel Spring-Boot BOM</description>
<dependencyManagement>
<dependencies>
[4/5] camel git commit: CAMEL-10434: Camel catalog support different
runtimes to provide their supported list of components etc.
Posted by da...@apache.org.
CAMEL-10434: Camel catalog support different runtimes to provide their supported list of components etc.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8dc5a541
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8dc5a541
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8dc5a541
Branch: refs/heads/master
Commit: 8dc5a5416fd9a8bd9572e908216fd9fad36b57a0
Parents: 7581f9e
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Nov 7 13:11:55 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Nov 7 14:22:49 2016 +0100
----------------------------------------------------------------------
platforms/catalog-provider-karaf/pom.xml | 110 +++++++++++++++++++
.../catalog/karaf/KarafRuntimeProvider.java | 58 ++++++++++
.../camel/catalog/DefaultCamelCatalog.java | 2 +
.../camel/catalog/DefaultRuntimeProvider.java | 10 +-
.../apache/camel/catalog/RuntimeProvider.java | 10 ++
platforms/pom.xml | 8 +-
6 files changed, 194 insertions(+), 4 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/8dc5a541/platforms/catalog-provider-karaf/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/catalog-provider-karaf/pom.xml b/platforms/catalog-provider-karaf/pom.xml
new file mode 100644
index 0000000..9aafd73
--- /dev/null
+++ b/platforms/catalog-provider-karaf/pom.xml
@@ -0,0 +1,110 @@
+<?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.19.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-catalog-provider-karaf</artifactId>
+ <packaging>jar</packaging>
+ <name>Camel :: Platforms :: Catalog :: Provider Karaf</name>
+ <description>Camel Catalog Karaf</description>
+
+ <properties>
+ <camel.osgi.export.pkg>
+ org.apache.camel.catalog.karaf
+ </camel.osgi.export.pkg>
+ </properties>
+
+ <dependencies>
+
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-catalog</artifactId>
+ </dependency>
+
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ <!-- logging -->
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-api</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-core</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.logging.log4j</groupId>
+ <artifactId>log4j-slf4j-impl</artifactId>
+ <scope>test</scope>
+ </dependency>
+
+ </dependencies>
+
+ <build>
+ <plugins>
+
+ <plugin>
+ <groupId>org.apache.felix</groupId>
+ <artifactId>maven-bundle-plugin</artifactId>
+ <extensions>true</extensions>
+ </plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-resources-plugin</artifactId>
+ <version>${maven-resources-plugin-version}</version>
+ <executions>
+ <execution>
+ <id>copy-resources</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>copy-resources</goal>
+ </goals>
+ <configuration>
+ <outputDirectory>${basedir}/target/resources</outputDirectory>
+ <resources>
+ <resource>
+ <directory>../karaf/features/target/classes</directory>
+ <includes>
+ <include>features.xml</include>
+ </includes>
+ </resource>
+ </resources>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+
+ </plugins>
+
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/camel/blob/8dc5a541/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java
----------------------------------------------------------------------
diff --git a/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java b/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java
new file mode 100644
index 0000000..071d6e9
--- /dev/null
+++ b/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java
@@ -0,0 +1,58 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.karaf;
+
+import java.util.List;
+
+import org.apache.camel.catalog.CamelCatalog;
+import org.apache.camel.catalog.RuntimeProvider;
+
+public class KarafRuntimeProvider implements RuntimeProvider {
+
+ private CamelCatalog camelCatalog;
+
+ @Override
+ public CamelCatalog getCamelCatalog() {
+ return camelCatalog;
+ }
+
+ @Override
+ public void setCamelCatalog(CamelCatalog camelCatalog) {
+ this.camelCatalog = camelCatalog;
+ }
+
+ @Override
+ public String getProviderName() {
+ return "karaf";
+ }
+
+ @Override
+ public List<String> findComponentNames() {
+ // parse the karaf features xml file
+ return null;
+ }
+
+ @Override
+ public List<String> findDataFormatNames() {
+ return null;
+ }
+
+ @Override
+ public List<String> findLanguageNames() {
+ return null;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8dc5a541/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
index 33ffccf..e498a7b 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
@@ -122,6 +122,8 @@ public class DefaultCamelCatalog implements CamelCatalog {
@Override
public void setRuntimeProvider(RuntimeProvider runtimeProvider) {
this.runtimeProvider = runtimeProvider;
+ // inject CamelCatalog to the provider
+ this.runtimeProvider.setCamelCatalog(this);
}
@Override
http://git-wip-us.apache.org/repos/asf/camel/blob/8dc5a541/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java
index f3e97d7..a18d193 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java
@@ -27,7 +27,10 @@ public class DefaultRuntimeProvider implements RuntimeProvider {
private static final String DATA_FORMATS_CATALOG = "org/apache/camel/catalog/dataformats.properties";
private static final String LANGUAGE_CATALOG = "org/apache/camel/catalog/languages.properties";
- private final CamelCatalog camelCatalog;
+ private CamelCatalog camelCatalog;
+
+ public DefaultRuntimeProvider() {
+ }
public DefaultRuntimeProvider(CamelCatalog camelCatalog) {
this.camelCatalog = camelCatalog;
@@ -39,6 +42,11 @@ public class DefaultRuntimeProvider implements RuntimeProvider {
}
@Override
+ public void setCamelCatalog(CamelCatalog camelCatalog) {
+ this.camelCatalog = camelCatalog;
+ }
+
+ @Override
public String getProviderName() {
return "default";
}
http://git-wip-us.apache.org/repos/asf/camel/blob/8dc5a541/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java
index f3e8744..2ab844f 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java
@@ -25,12 +25,22 @@ import java.util.List;
*/
public interface RuntimeProvider {
+ // TODO: maven archetype GAV
+ // original GAV
+ // spring-boot GAV
+ // karaf feature name
+
/**
* Gets the {@link CamelCatalog}
*/
CamelCatalog getCamelCatalog();
/**
+ * Sets the {@link CamelCatalog} to use
+ */
+ void setCamelCatalog(CamelCatalog camelCatalog);
+
+ /**
* Name of provider such as <tt>default</tt>, <tt>karaf</tt>, <tt>spring-boot</tt>
*/
String getProviderName();
http://git-wip-us.apache.org/repos/asf/camel/blob/8dc5a541/platforms/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/pom.xml b/platforms/pom.xml
index 3ba8260..c325083 100644
--- a/platforms/pom.xml
+++ b/platforms/pom.xml
@@ -32,12 +32,14 @@
<packaging>pom</packaging>
<modules>
- <module>catalog</module>
- <module>catalog-lucene</module>
- <module>catalog-maven</module>
<module>commands</module>
<module>karaf</module>
<module>spring-boot</module>
+ <!-- run catalog last -->
+ <module>catalog</module>
+ <module>catalog-lucene</module>
+ <module>catalog-maven</module>
+ <module>catalog-provider-karaf</module>
</modules>
</project>
[3/5] camel git commit: CAMEL-10434: Camel catalog support different
runtimes to provide their supported list of components etc.
Posted by da...@apache.org.
CAMEL-10434: Camel catalog support different runtimes to provide their supported list of components etc.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/7581f9e8
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/7581f9e8
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/7581f9e8
Branch: refs/heads/master
Commit: 7581f9e89279aaf43e009215f8da161801985df0
Parents: 10c2e35
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Nov 7 12:58:17 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Nov 7 14:22:49 2016 +0100
----------------------------------------------------------------------
.../org/apache/camel/catalog/CamelCatalog.java | 11 +++
.../camel/catalog/DefaultCamelCatalog.java | 46 ++++-------
.../camel/catalog/DefaultRuntimeProvider.java | 87 ++++++++++++++++++++
.../apache/camel/catalog/RuntimeProvider.java | 53 ++++++++++++
4 files changed, 167 insertions(+), 30 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/7581f9e8/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
index 5ee8714..426cd02 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/CamelCatalog.java
@@ -29,6 +29,17 @@ import javax.management.MXBean;
public interface CamelCatalog {
/**
+ * To plugin a custom {@link RuntimeProvider} that amends the catalog to only include information that is supported on the runtime.
+ */
+ void setRuntimeProvider(RuntimeProvider provider);
+
+ /**
+ * Gets the {@link RuntimeProvider} in use.
+ * @return
+ */
+ RuntimeProvider getRuntimeProvider();
+
+ /**
* Enables caching of the resources which makes the catalog faster, but keeps data in memory during caching.
* <p/>
* The catalog does not cache by default.
http://git-wip-us.apache.org/repos/asf/camel/blob/7581f9e8/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
index 6f723b4..33ffccf 100644
--- a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultCamelCatalog.java
@@ -73,9 +73,6 @@ public class DefaultCamelCatalog implements CamelCatalog {
// CHECKSTYLE:OFF
private static final String MODELS_CATALOG = "org/apache/camel/catalog/models.properties";
- private static final String COMPONENTS_CATALOG = "org/apache/camel/catalog/components.properties";
- private static final String DATA_FORMATS_CATALOG = "org/apache/camel/catalog/dataformats.properties";
- private static final String LANGUAGE_CATALOG = "org/apache/camel/catalog/languages.properties";
private static final String MODEL_DIR = "org/apache/camel/catalog/models";
private static final String COMPONENT_DIR = "org/apache/camel/catalog/components";
private static final String DATAFORMAT_DIR = "org/apache/camel/catalog/dataformats";
@@ -100,6 +97,7 @@ public class DefaultCamelCatalog implements CamelCatalog {
private boolean caching;
private SuggestionStrategy suggestionStrategy;
private VersionManager versionManager = new DefaultVersionManager(this);
+ private RuntimeProvider runtimeProvider = new DefaultRuntimeProvider(this);
/**
* Creates the {@link CamelCatalog} without caching enabled.
@@ -117,10 +115,21 @@ public class DefaultCamelCatalog implements CamelCatalog {
}
@Override
+ public RuntimeProvider getRuntimeProvider() {
+ return runtimeProvider;
+ }
+
+ @Override
+ public void setRuntimeProvider(RuntimeProvider runtimeProvider) {
+ this.runtimeProvider = runtimeProvider;
+ }
+
+ @Override
public void enableCache() {
caching = true;
}
+ @Override
public boolean isCaching() {
return caching;
}
@@ -210,15 +219,7 @@ public class DefaultCamelCatalog implements CamelCatalog {
}
if (names == null) {
- names = new ArrayList<String>();
- InputStream is = versionManager.getResourceAsStream(COMPONENTS_CATALOG);
- if (is != null) {
- try {
- CatalogHelper.loadLines(is, names);
- } catch (IOException e) {
- // ignore
- }
- }
+ names = runtimeProvider.findComponentNames();
// include third party components
for (Map.Entry<String, String> entry : extraComponents.entrySet()) {
@@ -243,15 +244,7 @@ public class DefaultCamelCatalog implements CamelCatalog {
}
if (names == null) {
- names = new ArrayList<String>();
- InputStream is = versionManager.getResourceAsStream(DATA_FORMATS_CATALOG);
- if (is != null) {
- try {
- CatalogHelper.loadLines(is, names);
- } catch (IOException e) {
- // ignore
- }
- }
+ names = runtimeProvider.findDataFormatNames();
// include third party data formats
for (Map.Entry<String, String> entry : extraDataFormats.entrySet()) {
@@ -276,15 +269,8 @@ public class DefaultCamelCatalog implements CamelCatalog {
}
if (names == null) {
- names = new ArrayList<String>();
- InputStream is = versionManager.getResourceAsStream(LANGUAGE_CATALOG);
- if (is != null) {
- try {
- CatalogHelper.loadLines(is, names);
- } catch (IOException e) {
- // ignore
- }
- }
+ names = runtimeProvider.findLanguageNames();
+
if (caching) {
cache.put("findLanguageNames", names);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/7581f9e8/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java
new file mode 100644
index 0000000..f3e97d7
--- /dev/null
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/DefaultRuntimeProvider.java
@@ -0,0 +1,87 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+public class DefaultRuntimeProvider implements RuntimeProvider {
+
+ private static final String COMPONENTS_CATALOG = "org/apache/camel/catalog/components.properties";
+ private static final String DATA_FORMATS_CATALOG = "org/apache/camel/catalog/dataformats.properties";
+ private static final String LANGUAGE_CATALOG = "org/apache/camel/catalog/languages.properties";
+
+ private final CamelCatalog camelCatalog;
+
+ public DefaultRuntimeProvider(CamelCatalog camelCatalog) {
+ this.camelCatalog = camelCatalog;
+ }
+
+ @Override
+ public CamelCatalog getCamelCatalog() {
+ return camelCatalog;
+ }
+
+ @Override
+ public String getProviderName() {
+ return "default";
+ }
+
+ @Override
+ public List<String> findComponentNames() {
+ List<String> names = new ArrayList<String>();
+ InputStream is = camelCatalog.getVersionManager().getResourceAsStream(COMPONENTS_CATALOG);
+ if (is != null) {
+ try {
+ CatalogHelper.loadLines(is, names);
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ return names;
+ }
+
+ @Override
+ public List<String> findDataFormatNames() {
+ List<String> names = new ArrayList<String>();
+ InputStream is = camelCatalog.getVersionManager().getResourceAsStream(DATA_FORMATS_CATALOG);
+ if (is != null) {
+ try {
+ CatalogHelper.loadLines(is, names);
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ return names;
+ }
+
+ @Override
+ public List<String> findLanguageNames() {
+ List<String> names = new ArrayList<String>();
+ InputStream is = camelCatalog.getVersionManager().getResourceAsStream(LANGUAGE_CATALOG);
+ if (is != null) {
+ try {
+ CatalogHelper.loadLines(is, names);
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ return names;
+ }
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/7581f9e8/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java
----------------------------------------------------------------------
diff --git a/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java b/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java
new file mode 100644
index 0000000..f3e8744
--- /dev/null
+++ b/platforms/catalog/src/main/java/org/apache/camel/catalog/RuntimeProvider.java
@@ -0,0 +1,53 @@
+/**
+ * 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
+ * <p>
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * <p>
+ * 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;
+
+/**
+ * A pluggable strategy for chosen runtime to run Camel such as default, karaf, spring-boot, etc.
+ * This allows third party runtimes to provide their own provider, that can amend the catalog
+ * to match the runtime. For example spring-boot or karaf does not support all the default Camel components.
+ */
+public interface RuntimeProvider {
+
+ /**
+ * Gets the {@link CamelCatalog}
+ */
+ CamelCatalog getCamelCatalog();
+
+ /**
+ * Name of provider such as <tt>default</tt>, <tt>karaf</tt>, <tt>spring-boot</tt>
+ */
+ String getProviderName();
+
+ /**
+ * Find all the component names from the Camel catalog supported by the provider
+ */
+ List<String> findComponentNames();
+
+ /**
+ * Find all the data format names from the Camel catalog supported by the provider
+ */
+ List<String> findDataFormatNames();
+
+ /**
+ * Find all the language names from the Camel catalog supported by the provider
+ */
+ List<String> findLanguageNames();
+
+}
[5/5] camel git commit: CAMEL-10434: Camel catalog support different
runtimes to provide their supported list of components etc.
Posted by da...@apache.org.
CAMEL-10434: Camel catalog support different runtimes to provide their supported list of components etc.
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/1691c623
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1691c623
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1691c623
Branch: refs/heads/master
Commit: 1691c6237e4bf789793fb07ba628578fa8f456b6
Parents: 3da8d1e
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Nov 7 15:13:41 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Nov 7 15:17:00 2016 +0100
----------------------------------------------------------------------
platforms/catalog-provider-karaf/pom.xml | 24 +-
.../catalog/karaf/KarafRuntimeProvider.java | 144 ++---
.../catalog/karaf/KarafRuntimeProviderTest.java | 6 +-
.../packaging/PrepareCatalogKarafMojo.java | 551 +++++++++++++++++++
4 files changed, 597 insertions(+), 128 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/1691c623/platforms/catalog-provider-karaf/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/catalog-provider-karaf/pom.xml b/platforms/catalog-provider-karaf/pom.xml
index 6923faa..bc2853a 100644
--- a/platforms/catalog-provider-karaf/pom.xml
+++ b/platforms/catalog-provider-karaf/pom.xml
@@ -77,28 +77,18 @@
<extensions>true</extensions>
</plugin>
+ <!-- generate and include all components in the catalog -->
<plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-resources-plugin</artifactId>
- <version>${maven-resources-plugin-version}</version>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-package-maven-plugin</artifactId>
+ <version>${project.version}</version>
<executions>
<execution>
- <id>copy-resources</id>
- <phase>compile</phase>
+ <!-- prepare the catalog before the user guide / readme -->
<goals>
- <goal>copy-resources</goal>
+ <goal>prepare-catalog-karaf</goal>
</goals>
- <configuration>
- <outputDirectory>${basedir}/target/classes/org/apache/camel/catalog/karaf</outputDirectory>
- <resources>
- <resource>
- <directory>../karaf/features/target/classes</directory>
- <includes>
- <include>features.xml</include>
- </includes>
- </resource>
- </resources>
- </configuration>
+ <phase>process-resources</phase>
</execution>
</executions>
</plugin>
http://git-wip-us.apache.org/repos/asf/camel/blob/1691c623/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java
----------------------------------------------------------------------
diff --git a/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java b/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java
index 9c8ac17..67c80c3 100644
--- a/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java
+++ b/platforms/catalog-provider-karaf/src/main/java/org/apache/camel/catalog/karaf/KarafRuntimeProvider.java
@@ -5,9 +5,9 @@
* 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ * 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.
@@ -16,30 +16,26 @@
*/
package org.apache.camel.catalog.karaf;
+import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
-import java.util.HashMap;
import java.util.List;
-import java.util.Map;
-import javax.xml.parsers.DocumentBuilderFactory;
import org.apache.camel.catalog.CamelCatalog;
-import org.apache.camel.catalog.DefaultRuntimeProvider;
-import org.apache.camel.catalog.JSonSchemaHelper;
+import org.apache.camel.catalog.CatalogHelper;
import org.apache.camel.catalog.RuntimeProvider;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-import static org.w3c.dom.Node.ELEMENT_NODE;
+/**
+ * A karaf based {@link RuntimeProvider} which only includes the supported Camel components, data formats, and languages
+ * which can be installed in Karaf using the Camel Karaf features.xml descriptor.
+ */
public class KarafRuntimeProvider implements RuntimeProvider {
- private static final String FEATURES = "org/apache/camel/catalog/karaf/features.xml";
- private CamelCatalog camelCatalog;
- private DefaultRuntimeProvider defaultProvider = new DefaultRuntimeProvider();
+ private static final String COMPONENTS_CATALOG = "org/apache/camel/catalog/karaf/components.properties";
+ private static final String DATA_FORMATS_CATALOG = "org/apache/camel/catalog/karaf/dataformats.properties";
+ private static final String LANGUAGE_CATALOG = "org/apache/camel/catalog/karaf/languages.properties";
- private Map<String, List<Map<String, String>>> rowsCache = new HashMap<>();
+ private CamelCatalog camelCatalog;
@Override
public CamelCatalog getCamelCatalog() {
@@ -49,7 +45,6 @@ public class KarafRuntimeProvider implements RuntimeProvider {
@Override
public void setCamelCatalog(CamelCatalog camelCatalog) {
this.camelCatalog = camelCatalog;
- this.defaultProvider.setCamelCatalog(camelCatalog);
}
@Override
@@ -59,111 +54,44 @@ public class KarafRuntimeProvider implements RuntimeProvider {
@Override
public List<String> findComponentNames() {
- // find the component name from all the default components
- List<String> allNames = defaultProvider.findComponentNames();
-
- List<String> answer = new ArrayList<>();
-
- // filter out to only include what's in the karaf features file
- InputStream is = camelCatalog.getVersionManager().getResourceAsStream(FEATURES);
+ List<String> names = new ArrayList<String>();
+ InputStream is = camelCatalog.getVersionManager().getResourceAsStream(COMPONENTS_CATALOG);
if (is != null) {
try {
- DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
- dbf.setIgnoringComments(true);
- dbf.setIgnoringElementContentWhitespace(true);
- dbf.setNamespaceAware(false);
- dbf.setValidating(false);
- dbf.setXIncludeAware(false);
- Document dom = dbf.newDocumentBuilder().parse(is);
- NodeList children = dom.getElementsByTagName("features");
-
- for (int i = 0; i < children.getLength(); i++) {
- Node child = children.item(i);
- if (child.getNodeType() == ELEMENT_NODE) {
- NodeList children2 = child.getChildNodes();
- for (int j = 0; j < children2.getLength(); j++) {
- Node child2 = children2.item(j);
- if ("feature".equals(child2.getNodeName())) {
- // the name attribute is the maven artifact id of the component
- String artifactId = child2.getAttributes().getNamedItem("name").getTextContent();
- if (artifactId != null && artifactId.startsWith("camel-")) {
- // find the component name based on the artifact id
- String componentName = componentNameFromArtifactId(artifactId, allNames);
- if (componentName != null) {
- answer.add(componentName);
- }
- }
- }
- }
- }
- }
- } catch (Exception e) {
+ CatalogHelper.loadLines(is, names);
+ } catch (IOException e) {
// ignore
}
}
-
- System.out.println("Total components " + allNames.size() + " karaf supports " + answer.size());
-
- // clear temporary cache
- rowsCache.clear();
-
- return answer;
+ return names;
}
@Override
public List<String> findDataFormatNames() {
- // karaf support all data formats
- return defaultProvider.findDataFormatNames();
- }
-
- @Override
- public List<String> findLanguageNames() {
- // karaf support all languages
- return defaultProvider.findLanguageNames();
- }
-
- private String componentNameFromArtifactId(String artifactId, List<String> allNames) {
- // try a quick shortcut that is faster
- String quick = artifactId.startsWith("camel-") ? artifactId.substring(6) : null;
- if (quick != null) {
- String json = camelCatalog.componentJSonSchema(quick);
- if (json != null) {
- List<Map<String, String>> rows = rowsCache.get(quick);
- if (rows == null) {
- rows = JSonSchemaHelper.parseJsonSchema("component", json, false);
- rowsCache.put(quick, rows);
- }
- String componentArtifactId = getArtifactId(rows);
- if (artifactId.equals(componentArtifactId)) {
- return quick;
- }
- }
- }
-
- for (String name : allNames) {
- String json = camelCatalog.componentJSonSchema(name);
- if (json != null) {
- List<Map<String, String>> rows = rowsCache.get(quick);
- if (rows == null) {
- rows = JSonSchemaHelper.parseJsonSchema("component", json, false);
- rowsCache.put(quick, rows);
- }
- String componentArtifactId = getArtifactId(rows);
- if (artifactId.equals(componentArtifactId)) {
- return name;
- }
+ List<String> names = new ArrayList<String>();
+ InputStream is = camelCatalog.getVersionManager().getResourceAsStream(DATA_FORMATS_CATALOG);
+ if (is != null) {
+ try {
+ CatalogHelper.loadLines(is, names);
+ } catch (IOException e) {
+ // ignore
}
}
- return null;
+ return names;
}
- public static String getArtifactId(List<Map<String, String>> rows) {
- for (Map<String, String> row : rows) {
- if (row.get("artifactId") != null) {
- return row.get("artifactId");
+ @Override
+ public List<String> findLanguageNames() {
+ List<String> names = new ArrayList<String>();
+ InputStream is = camelCatalog.getVersionManager().getResourceAsStream(LANGUAGE_CATALOG);
+ if (is != null) {
+ try {
+ CatalogHelper.loadLines(is, names);
+ } catch (IOException e) {
+ // ignore
}
}
- return null;
+ return names;
}
}
http://git-wip-us.apache.org/repos/asf/camel/blob/1691c623/platforms/catalog-provider-karaf/src/test/java/org/apache/camel/catalog/karaf/KarafRuntimeProviderTest.java
----------------------------------------------------------------------
diff --git a/platforms/catalog-provider-karaf/src/test/java/org/apache/camel/catalog/karaf/KarafRuntimeProviderTest.java b/platforms/catalog-provider-karaf/src/test/java/org/apache/camel/catalog/karaf/KarafRuntimeProviderTest.java
index 9d83d52..c652b2f 100644
--- a/platforms/catalog-provider-karaf/src/test/java/org/apache/camel/catalog/karaf/KarafRuntimeProviderTest.java
+++ b/platforms/catalog-provider-karaf/src/test/java/org/apache/camel/catalog/karaf/KarafRuntimeProviderTest.java
@@ -5,9 +5,9 @@
* 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
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ * 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.
http://git-wip-us.apache.org/repos/asf/camel/blob/1691c623/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogKarafMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogKarafMojo.java b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogKarafMojo.java
new file mode 100644
index 0000000..fc53c54
--- /dev/null
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/PrepareCatalogKarafMojo.java
@@ -0,0 +1,551 @@
+/**
+ * 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.io.InputStream;
+import java.nio.channels.FileChannel;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Set;
+import java.util.TreeSet;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import static org.w3c.dom.Node.ELEMENT_NODE;
+
+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;
+
+import static org.apache.camel.maven.packaging.PackageHelper.loadText;
+
+/**
+ * Prepares the Karaf provider camel catalog to include component it supports
+ *
+ * @goal prepare-catalog-karaf
+ */
+public class PrepareCatalogKarafMojo 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/karaf/components"
+ */
+ protected File componentsOutDir;
+
+ /**
+ * The output directory for dataformats catalog
+ *
+ * @parameter default-value="${project.build.directory}/classes/org/apache/camel/catalog/karaf/dataformats"
+ */
+ protected File dataFormatsOutDir;
+
+ /**
+ * The output directory for languages catalog
+ *
+ * @parameter default-value="${project.build.directory}/classes/org/apache/camel/catalog/karaf/languages"
+ */
+ protected File languagesOutDir;
+
+ /**
+ * The karaf features directory
+ *
+ * @parameter default-value="${project.build.directory}/../../../platforms/karaf/features/src/main/resources/"
+ */
+ protected File featuresDir;
+
+ /**
+ * 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 MojoExecutionException execution of the main class or one of the
+ * threads it generated failed.
+ * @throws MojoFailureException something bad happened...
+ */
+ public void execute() throws MojoExecutionException, MojoFailureException {
+ Set<String> features = findKarafFeatures();
+ executeComponents(features);
+ executeDataFormats(features);
+ executeLanguages(features);
+ }
+
+ protected void executeComponents(Set<String> features) throws MojoExecutionException, MojoFailureException {
+ getLog().info("Copying all Camel component json descriptors");
+
+ // lets use sorted set/maps
+ Set<File> jsonFiles = new TreeSet<File>();
+ Set<File> componentFiles = new TreeSet<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) {
+ // skip camel-spring-dm
+ if (dir.isDirectory() && "camel-spring-dm".equals(dir.getName())) {
+ continue;
+ }
+
+
+ if (dir.isDirectory() && !"target".equals(dir.getName())) {
+ File target = new File(dir, "target/classes");
+
+ // the directory must be in the list of known features
+ if (!features.contains(dir.getName())) {
+ continue;
+ }
+
+ // special for camel-salesforce which is in a sub dir
+ if ("camel-salesforce".equals(dir.getName())) {
+ target = new File(dir, "camel-salesforce-component/target/classes");
+ } else if ("camel-linkedin".equals(dir.getName())) {
+ target = new File(dir, "camel-linkedin-component/target/classes");
+ }
+
+
+ findComponentFilesRecursive(target, jsonFiles, componentFiles, new CamelComponentsFileFilter());
+ }
+ }
+ }
+ }
+ if (coreDir != null && coreDir.isDirectory()) {
+ File target = new File(coreDir, "target/classes");
+ findComponentFilesRecursive(target, jsonFiles, componentFiles, new CamelComponentsFileFilter());
+ }
+
+ getLog().info("Found " + componentFiles.size() + " component.properties files");
+ getLog().info("Found " + jsonFiles.size() + " component json files");
+
+ // make sure to create out dir
+ componentsOutDir.mkdirs();
+
+ Set<String> alternativeSchemes = new HashSet<>();
+
+ for (File file : jsonFiles) {
+ File to = new File(componentsOutDir, file.getName());
+ try {
+ copyFile(file, to);
+ } catch (IOException e) {
+ throw new MojoFailureException("Cannot copy file from " + file + " -> " + to, e);
+ }
+ }
+
+ File all = new File(componentsOutDir, "../components.properties");
+ try {
+ FileOutputStream fos = new FileOutputStream(all, false);
+
+ String[] names = componentsOutDir.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();
+
+ } catch (IOException e) {
+ throw new MojoFailureException("Error writing to file " + all);
+ }
+ }
+
+ protected void executeDataFormats(Set<String> features) throws MojoExecutionException, MojoFailureException {
+ getLog().info("Copying all Camel dataformat json descriptors");
+
+ // lets use sorted set/maps
+ Set<File> jsonFiles = new TreeSet<File>();
+ Set<File> dataFormatFiles = new TreeSet<File>();
+
+ // find all data formats from the components directory
+ if (componentsDir != null && componentsDir.isDirectory()) {
+ File[] dataFormats = componentsDir.listFiles();
+ if (dataFormats != null) {
+ for (File dir : dataFormats) {
+ if (dir.isDirectory() && !"target".equals(dir.getName())) {
+ // skip camel-spring-dm
+ if (dir.isDirectory() && "camel-spring-dm".equals(dir.getName())) {
+ continue;
+ }
+ // the directory must be in the list of known features
+ if (!features.contains(dir.getName())) {
+ continue;
+ }
+ File target = new File(dir, "target/classes");
+ findDataFormatFilesRecursive(target, jsonFiles, dataFormatFiles, new CamelDataFormatsFileFilter());
+ }
+ }
+ }
+ }
+ if (coreDir != null && coreDir.isDirectory()) {
+ File target = new File(coreDir, "target/classes");
+ findDataFormatFilesRecursive(target, jsonFiles, dataFormatFiles, new CamelDataFormatsFileFilter());
+ }
+
+ getLog().info("Found " + dataFormatFiles.size() + " dataformat.properties files");
+ getLog().info("Found " + jsonFiles.size() + " dataformat json files");
+
+ // make sure to create out dir
+ dataFormatsOutDir.mkdirs();
+
+ for (File file : jsonFiles) {
+ File to = new File(dataFormatsOutDir, file.getName());
+ try {
+ copyFile(file, to);
+ } catch (IOException e) {
+ throw new MojoFailureException("Cannot copy file from " + file + " -> " + to, e);
+ }
+ }
+
+ File all = new File(dataFormatsOutDir, "../dataformats.properties");
+ try {
+ FileOutputStream fos = new FileOutputStream(all, false);
+
+ String[] names = dataFormatsOutDir.list();
+ List<String> dataFormats = new ArrayList<String>();
+ // sort the names
+ for (String name : names) {
+ if (name.endsWith(".json")) {
+ // strip out .json from the name
+ String dataFormatName = name.substring(0, name.length() - 5);
+ dataFormats.add(dataFormatName);
+ }
+ }
+
+ Collections.sort(dataFormats);
+ for (String name : dataFormats) {
+ fos.write(name.getBytes());
+ fos.write("\n".getBytes());
+ }
+
+ fos.close();
+
+ } catch (IOException e) {
+ throw new MojoFailureException("Error writing to file " + all);
+ }
+ }
+
+ protected void executeLanguages(Set<String> features) throws MojoExecutionException, MojoFailureException {
+ getLog().info("Copying all Camel language json descriptors");
+
+ // lets use sorted set/maps
+ Set<File> jsonFiles = new TreeSet<File>();
+ Set<File> languageFiles = new TreeSet<File>();
+
+ // find all languages from the components directory
+ if (componentsDir != null && componentsDir.isDirectory()) {
+ File[] languages = componentsDir.listFiles();
+ if (languages != null) {
+ for (File dir : languages) {
+ // skip camel-spring-dm
+ if (dir.isDirectory() && "camel-spring-dm".equals(dir.getName())) {
+ continue;
+ }
+ // the directory must be in the list of known features
+ if (!features.contains(dir.getName())) {
+ continue;
+ }
+ if (dir.isDirectory() && !"target".equals(dir.getName())) {
+ File target = new File(dir, "target/classes");
+ findLanguageFilesRecursive(target, jsonFiles, languageFiles, new CamelLanguagesFileFilter());
+ }
+ }
+ }
+ }
+ if (coreDir != null && coreDir.isDirectory()) {
+ File target = new File(coreDir, "target/classes");
+ findLanguageFilesRecursive(target, jsonFiles, languageFiles, new CamelLanguagesFileFilter());
+ }
+
+ getLog().info("Found " + languageFiles.size() + " language.properties files");
+ getLog().info("Found " + jsonFiles.size() + " language json files");
+
+ // make sure to create out dir
+ languagesOutDir.mkdirs();
+
+ for (File file : jsonFiles) {
+ File to = new File(languagesOutDir, file.getName());
+ try {
+ copyFile(file, to);
+ } catch (IOException e) {
+ throw new MojoFailureException("Cannot copy file from " + file + " -> " + to, e);
+ }
+ }
+
+ File all = new File(languagesOutDir, "../languages.properties");
+ try {
+ FileOutputStream fos = new FileOutputStream(all, false);
+
+ String[] names = languagesOutDir.list();
+ List<String> languages = new ArrayList<String>();
+ // sort the names
+ for (String name : names) {
+ if (name.endsWith(".json")) {
+ // strip out .json from the name
+ String languageName = name.substring(0, name.length() - 5);
+ languages.add(languageName);
+ }
+ }
+
+ Collections.sort(languages);
+ for (String name : languages) {
+ fos.write(name.getBytes());
+ fos.write("\n".getBytes());
+ }
+
+ fos.close();
+
+ } catch (IOException e) {
+ throw new MojoFailureException("Error writing to file " + all);
+ }
+ }
+
+ private void findComponentFilesRecursive(File dir, Set<File> found, Set<File> components, FileFilter filter) {
+ File[] files = dir.listFiles(filter);
+ if (files != null) {
+ for (File file : files) {
+ // skip files in root dirs as Camel does not store information there but others may do
+ boolean rootDir = "classes".equals(dir.getName()) || "META-INF".equals(dir.getName());
+ boolean jsonFile = !rootDir && file.isFile() && file.getName().endsWith(".json");
+ boolean componentFile = !rootDir && file.isFile() && file.getName().equals("component.properties");
+ if (jsonFile) {
+ found.add(file);
+ } else if (componentFile) {
+ components.add(file);
+ } else if (file.isDirectory()) {
+ findComponentFilesRecursive(file, found, components, filter);
+ }
+ }
+ }
+ }
+
+ private void findDataFormatFilesRecursive(File dir, Set<File> found, Set<File> dataFormats, FileFilter filter) {
+ File[] files = dir.listFiles(filter);
+ if (files != null) {
+ for (File file : files) {
+ // skip files in root dirs as Camel does not store information there but others may do
+ boolean rootDir = "classes".equals(dir.getName()) || "META-INF".equals(dir.getName());
+ boolean jsonFile = !rootDir && file.isFile() && file.getName().endsWith(".json");
+ boolean dataFormatFile = !rootDir && file.isFile() && file.getName().equals("dataformat.properties");
+ if (jsonFile) {
+ found.add(file);
+ } else if (dataFormatFile) {
+ dataFormats.add(file);
+ } else if (file.isDirectory()) {
+ findDataFormatFilesRecursive(file, found, dataFormats, filter);
+ }
+ }
+ }
+ }
+
+ private void findLanguageFilesRecursive(File dir, Set<File> found, Set<File> languages, FileFilter filter) {
+ File[] files = dir.listFiles(filter);
+ if (files != null) {
+ for (File file : files) {
+ // skip files in root dirs as Camel does not store information there but others may do
+ boolean rootDir = "classes".equals(dir.getName()) || "META-INF".equals(dir.getName());
+ boolean jsonFile = !rootDir && file.isFile() && file.getName().endsWith(".json");
+ boolean languageFile = !rootDir && file.isFile() && file.getName().equals("language.properties");
+ if (jsonFile) {
+ found.add(file);
+ } else if (languageFile) {
+ languages.add(file);
+ } else if (file.isDirectory()) {
+ findLanguageFilesRecursive(file, found, languages, filter);
+ }
+ }
+ }
+ }
+
+ private class CamelComponentsFileFilter implements FileFilter {
+
+ @Override
+ public boolean accept(File pathname) {
+ if (pathname.isDirectory() && pathname.getName().equals("model")) {
+ // do not check the camel-core model packages as there is no components there
+ return false;
+ }
+ if (pathname.isFile() && pathname.getName().endsWith(".json")) {
+ // must be a components json file
+ try {
+ String json = loadText(new FileInputStream(pathname));
+ return json != null && json.contains("\"kind\": \"component\"");
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ return pathname.isDirectory() || (pathname.isFile() && pathname.getName().equals("component.properties"));
+ }
+ }
+
+ private class CamelDataFormatsFileFilter implements FileFilter {
+
+ @Override
+ public boolean accept(File pathname) {
+ if (pathname.isDirectory() && pathname.getName().equals("model")) {
+ // do not check the camel-core model packages as there is no components there
+ return false;
+ }
+ if (pathname.isFile() && pathname.getName().endsWith(".json")) {
+ // must be a dataformat json file
+ try {
+ String json = loadText(new FileInputStream(pathname));
+ return json != null && json.contains("\"kind\": \"dataformat\"");
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ return pathname.isDirectory() || (pathname.isFile() && pathname.getName().equals("dataformat.properties"));
+ }
+ }
+
+ private class CamelLanguagesFileFilter implements FileFilter {
+
+ @Override
+ public boolean accept(File pathname) {
+ if (pathname.isDirectory() && pathname.getName().equals("model")) {
+ // do not check the camel-core model packages as there is no components there
+ return false;
+ }
+ if (pathname.isFile() && pathname.getName().endsWith(".json")) {
+ // must be a language json file
+ try {
+ String json = loadText(new FileInputStream(pathname));
+ return json != null && json.contains("\"kind\": \"language\"");
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ return pathname.isDirectory() || (pathname.isFile() && pathname.getName().equals("language.properties"));
+ }
+ }
+
+ 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();
+ }
+ }
+ }
+
+ private Set<String> findKarafFeatures() throws MojoExecutionException, MojoFailureException {
+ Set<String> answer = new LinkedHashSet<>();
+
+ try {
+ // load features.xml file
+ InputStream is = new FileInputStream(new File(featuresDir, "features.xml"));
+
+ DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
+ dbf.setIgnoringComments(true);
+ dbf.setIgnoringElementContentWhitespace(true);
+ dbf.setNamespaceAware(false);
+ dbf.setValidating(false);
+ dbf.setXIncludeAware(false);
+ Document dom = dbf.newDocumentBuilder().parse(is);
+ NodeList children = dom.getElementsByTagName("features");
+
+ for (int i = 0; i < children.getLength(); i++) {
+ Node child = children.item(i);
+ if (child.getNodeType() == ELEMENT_NODE) {
+ NodeList children2 = child.getChildNodes();
+ for (int j = 0; j < children2.getLength(); j++) {
+ Node child2 = children2.item(j);
+ if ("feature".equals(child2.getNodeName())) {
+ // the name attribute is the maven artifact id of the component
+ String artifactId = child2.getAttributes().getNamedItem("name").getTextContent();
+ if (artifactId != null && artifactId.startsWith("camel-")) {
+ // find the component name based on the artifact id
+ answer.add(artifactId);
+ }
+ }
+ }
+ }
+ }
+ } catch (Exception e) {
+ throw new MojoExecutionException("Error reading features.xml file", e);
+ }
+
+ return answer;
+ }
+
+}
\ No newline at end of file
[2/5] camel git commit: Polished
Posted by da...@apache.org.
Polished
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/048b7098
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/048b7098
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/048b7098
Branch: refs/heads/master
Commit: 048b70985daaed31a348ac12d86d11de2d8d6c59
Parents: 8dc5a54
Author: Claus Ibsen <da...@apache.org>
Authored: Mon Nov 7 13:12:00 2016 +0100
Committer: Claus Ibsen <da...@apache.org>
Committed: Mon Nov 7 14:22:49 2016 +0100
----------------------------------------------------------------------
.../spring-boot-dm/camel-spring-boot-dependencies/pom.xml | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/048b7098/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml b/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
index e8bffa9..edc5462 100644
--- a/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
+++ b/platforms/spring-boot/spring-boot-dm/camel-spring-boot-dependencies/pom.xml
@@ -24,7 +24,7 @@
<modelVersion>4.0.0</modelVersion>
<artifactId>camel-spring-boot-dependencies</artifactId>
<packaging>pom</packaging>
- <name>Camel :: Spring-Boot :: Dependency Management :: BOM</name>
+ <name>Camel :: Platforms :: Spring-Boot :: Dependency Management :: BOM</name>
<description>Camel Spring-Boot BOM</description>
<dependencyManagement>
<dependencies>