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 <davscl...@apache.org> Authored: Mon Nov 7 12:58:17 2016 +0100 Committer: Claus Ibsen <davscl...@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(); + +}