diff --git a/runtime/camel-k-runtime-core/src/main/java/org/apache/camel/k/Language.java b/runtime/camel-k-runtime-core/src/main/java/org/apache/camel/k/Language.java deleted file mode 100644 index 5fb0194025..0000000000 --- a/runtime/camel-k-runtime-core/src/main/java/org/apache/camel/k/Language.java +++ /dev/null @@ -1,105 +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.k; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import org.apache.camel.util.ObjectHelper; -import org.apache.commons.lang3.StringUtils; - -public enum Language { - Unknown( - "unknown", - Collections.emptyList(), - Collections.emptyList()), - JavaClass( - "java-class", - Collections.singletonList("class"), - Collections.singletonList("class")), - JavaSource( - "java-source", - Collections.singletonList("java"), - Collections.singletonList("java")), - JavaScript( - "js", - Arrays.asList("js", "javascript"), - Collections.singletonList("js")), - Groovy( - "groovy", - Collections.singletonList("groovy"), - Collections.singletonList("groovy")), - Xml( - "xml", - Collections.singletonList("xml"), - Collections.singletonList("xml")), - YamlFlow( - "yaml-flow", - Arrays.asList("yaml-flow", "flow"), - Collections.singletonList("flow")), - Kotlin( - "kotlin", - Arrays.asList("kotlin", "kts"), - Collections.singletonList("kts")); - - private final String id; - private final List names; - private final List extensions; - - Language(String id, List names, List extensions) { - this.id = ObjectHelper.notNull(id, "id"); - this.names = names; - this.extensions = extensions; - } - - public String getId() { - return id; - } - - public List getNames() { - return names; - } - - public List getExtensions() { - return extensions; - } - - public static Language fromLanguageName(String name) { - for (Language language: values()) { - if (language.getNames().contains(name)) { - return language; - } - } - - return Unknown; - } - - public static Language fromLocation(String resource) { - for (Language language: values()) { - String path = StringUtils.substringAfter(resource, ":"); - - for (String ext : language.getExtensions()) { - if (path.endsWith("." + ext)) { - return language; - } - } - } - - return Unknown; - } -} diff --git a/runtime/camel-k-runtime-core/src/main/java/org/apache/camel/k/RoutesLoader.java b/runtime/camel-k-runtime-core/src/main/java/org/apache/camel/k/RoutesLoader.java index 3026b92607..fe78a54b7b 100644 --- a/runtime/camel-k-runtime-core/src/main/java/org/apache/camel/k/RoutesLoader.java +++ b/runtime/camel-k-runtime-core/src/main/java/org/apache/camel/k/RoutesLoader.java @@ -26,7 +26,7 @@ public interface RoutesLoader { * * @return the supported languages. */ - List getSupportedLanguages(); + List getSupportedLanguages(); /** * Creates a camel {@link RouteBuilder} from the given resource. diff --git a/runtime/camel-k-runtime-core/src/main/java/org/apache/camel/k/Source.java b/runtime/camel-k-runtime-core/src/main/java/org/apache/camel/k/Source.java index 12b2d1bf23..b777109564 100644 --- a/runtime/camel-k-runtime-core/src/main/java/org/apache/camel/k/Source.java +++ b/runtime/camel-k-runtime-core/src/main/java/org/apache/camel/k/Source.java @@ -24,10 +24,10 @@ public class Source { private final String location; - private final Language language; + private final String language; private final boolean compressed; - private Source(String location, Language language, boolean compression) { + private Source(String location, String language, boolean compression) { this.location = location; this.language = language; this.compressed = compression; @@ -37,7 +37,7 @@ public String getLocation() { return location; } - public Language getLanguage() { + public String getLanguage() { return language; } @@ -68,9 +68,15 @@ public static Source create(String uri) throws Exception { final String languageName = (String) params.get("language"); final boolean compression = Boolean.valueOf((String) params.get("compression")); - Language language = ObjectHelper.isNotEmpty(languageName) - ? Language.fromLanguageName(languageName) - : Language.fromLocation(location); + String language = languageName; + if (ObjectHelper.isEmpty(language)) { + language = StringUtils.substringAfterLast(location, ":"); + language = StringUtils.substringAfterLast(language, "."); + } + if (ObjectHelper.isEmpty(language)) { + throw new IllegalArgumentException("Unknown language " + language); + } + return new Source(location, language, compression); } diff --git a/runtime/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/RuntimeSupport.java b/runtime/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/RuntimeSupport.java index 59c6bf6dfe..ec8d47e2fe 100644 --- a/runtime/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/RuntimeSupport.java +++ b/runtime/camel-k-runtime-core/src/main/java/org/apache/camel/k/support/RuntimeSupport.java @@ -126,7 +126,7 @@ public static RoutesLoader lookupLoaderFromResource(CamelContext context, Source try { finder = context.getFactoryFinder(Constants.ROUTES_LOADER_RESOURCE_PATH); - loader = (RoutesLoader)finder.newInstance(source.getLanguage().getId()); + loader = (RoutesLoader)finder.newInstance(source.getLanguage()); } catch (NoFactoryAvailableException e) { throw new IllegalArgumentException("Unable to find loader for: " + source, e); } diff --git a/runtime/camel-k-runtime-groovy/src/main/groovy/org/apache/camel/k/groovy/GroovyRoutesLoader.groovy b/runtime/camel-k-runtime-groovy/src/main/groovy/org/apache/camel/k/groovy/GroovyRoutesLoader.groovy index 8493c4839d..7bf787fc96 100644 --- a/runtime/camel-k-runtime-groovy/src/main/groovy/org/apache/camel/k/groovy/GroovyRoutesLoader.groovy +++ b/runtime/camel-k-runtime-groovy/src/main/groovy/org/apache/camel/k/groovy/GroovyRoutesLoader.groovy @@ -16,20 +16,18 @@ */ package org.apache.camel.k.groovy - import org.apache.camel.builder.RouteBuilder -import org.apache.camel.k.Language import org.apache.camel.k.RoutesLoader import org.apache.camel.k.RuntimeRegistry import org.apache.camel.k.Source -import org.apache.camel.k.support.URIResolver import org.apache.camel.k.groovy.dsl.IntegrationConfiguration +import org.apache.camel.k.support.URIResolver import org.codehaus.groovy.control.CompilerConfiguration class GroovyRoutesLoader implements RoutesLoader { @Override - List getSupportedLanguages() { - return Collections.singletonList(Language.Groovy) + List getSupportedLanguages() { + return Collections.singletonList("groovy") } @Override diff --git a/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/loader/JavaClassLoader.java b/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/loader/JavaClassLoader.java index bf73a82769..c13f2d1572 100644 --- a/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/loader/JavaClassLoader.java +++ b/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/loader/JavaClassLoader.java @@ -1,3 +1,19 @@ +/** + * 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.k.jvm.loader; import java.util.Collections; @@ -5,7 +21,6 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.k.Constants; -import org.apache.camel.k.Language; import org.apache.camel.k.RoutesLoader; import org.apache.camel.k.RuntimeRegistry; import org.apache.camel.k.Source; @@ -13,8 +28,8 @@ public class JavaClassLoader implements RoutesLoader { @Override - public List getSupportedLanguages() { - return Collections.singletonList(Language.JavaClass); + public List getSupportedLanguages() { + return Collections.singletonList("class"); } @Override diff --git a/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/loader/JavaScriptLoader.java b/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/loader/JavaScriptLoader.java index ca05c108f1..c251f44213 100644 --- a/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/loader/JavaScriptLoader.java +++ b/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/loader/JavaScriptLoader.java @@ -1,3 +1,19 @@ +/** + * 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.k.jvm.loader; import java.io.InputStream; @@ -13,20 +29,19 @@ import org.apache.camel.CamelContext; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.k.Language; import org.apache.camel.k.RoutesLoader; import org.apache.camel.k.RuntimeRegistry; import org.apache.camel.k.Source; -import org.apache.camel.k.support.URIResolver; import org.apache.camel.k.jvm.dsl.Components; +import org.apache.camel.k.support.URIResolver; import org.apache.camel.model.RouteDefinition; import org.apache.camel.model.rest.RestConfigurationDefinition; import org.apache.camel.model.rest.RestDefinition; public class JavaScriptLoader implements RoutesLoader { @Override - public List getSupportedLanguages() { - return Collections.singletonList(Language.JavaScript); + public List getSupportedLanguages() { + return Collections.singletonList("js"); } @Override diff --git a/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/loader/JavaSourceLoader.java b/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/loader/JavaSourceLoader.java index bdcb6e3085..757c16bd60 100644 --- a/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/loader/JavaSourceLoader.java +++ b/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/loader/JavaSourceLoader.java @@ -1,3 +1,19 @@ +/** + * 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.k.jvm.loader; import java.io.InputStream; @@ -6,7 +22,6 @@ import java.util.List; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.k.Language; import org.apache.camel.k.RoutesLoader; import org.apache.camel.k.RuntimeRegistry; import org.apache.camel.k.Source; @@ -17,8 +32,8 @@ public class JavaSourceLoader implements RoutesLoader { @Override - public List getSupportedLanguages() { - return Collections.singletonList(Language.JavaSource); + public List getSupportedLanguages() { + return Collections.singletonList("java"); } @Override diff --git a/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/loader/XmlLoader.java b/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/loader/XmlLoader.java index b16fc62567..cd6e9addf7 100644 --- a/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/loader/XmlLoader.java +++ b/runtime/camel-k-runtime-jvm/src/main/java/org/apache/camel/k/jvm/loader/XmlLoader.java @@ -1,3 +1,19 @@ +/** + * 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.k.jvm.loader; import java.io.InputStream; @@ -6,7 +22,6 @@ import javax.xml.bind.UnmarshalException; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.k.Language; import org.apache.camel.k.RoutesLoader; import org.apache.camel.k.RuntimeRegistry; import org.apache.camel.k.Source; @@ -20,8 +35,8 @@ public class XmlLoader implements RoutesLoader { private static final Logger LOGGER = LoggerFactory.getLogger(XmlLoader.class); @Override - public List getSupportedLanguages() { - return Collections.singletonList(Language.Xml); + public List getSupportedLanguages() { + return Collections.singletonList("xml"); } @Override diff --git a/runtime/camel-k-runtime-jvm/src/main/resources/META-INF/services/org/apache/camel/k/loader/java-class b/runtime/camel-k-runtime-jvm/src/main/resources/META-INF/services/org/apache/camel/k/loader/class similarity index 100% rename from runtime/camel-k-runtime-jvm/src/main/resources/META-INF/services/org/apache/camel/k/loader/java-class rename to runtime/camel-k-runtime-jvm/src/main/resources/META-INF/services/org/apache/camel/k/loader/class diff --git a/runtime/camel-k-runtime-jvm/src/main/resources/META-INF/services/org/apache/camel/k/loader/java-source b/runtime/camel-k-runtime-jvm/src/main/resources/META-INF/services/org/apache/camel/k/loader/java similarity index 100% rename from runtime/camel-k-runtime-jvm/src/main/resources/META-INF/services/org/apache/camel/k/loader/java-source rename to runtime/camel-k-runtime-jvm/src/main/resources/META-INF/services/org/apache/camel/k/loader/java diff --git a/runtime/camel-k-runtime-kotlin/src/main/kotlin/org/apache/camel/k/kotlin/KotlinRoutesLoader.kt b/runtime/camel-k-runtime-kotlin/src/main/kotlin/org/apache/camel/k/kotlin/KotlinRoutesLoader.kt index 55604adc20..8d5f0e96d3 100644 --- a/runtime/camel-k-runtime-kotlin/src/main/kotlin/org/apache/camel/k/kotlin/KotlinRoutesLoader.kt +++ b/runtime/camel-k-runtime-kotlin/src/main/kotlin/org/apache/camel/k/kotlin/KotlinRoutesLoader.kt @@ -17,7 +17,6 @@ package org.apache.camel.k.kotlin import org.apache.camel.builder.RouteBuilder -import org.apache.camel.k.Language import org.apache.camel.k.RoutesLoader import org.apache.camel.k.RuntimeRegistry import org.apache.camel.k.Source @@ -41,8 +40,8 @@ class KotlinRoutesLoader : RoutesLoader { val LOGGER : Logger = LoggerFactory.getLogger(KotlinRoutesLoader::class.java) } - override fun getSupportedLanguages(): List { - return listOf(Language.Kotlin) + override fun getSupportedLanguages(): List { + return listOf("kts") } @Throws(Exception::class) diff --git a/runtime/camel-k-runtime-kotlin/src/main/resources/META-INF/services/org/apache/camel/k/loader/kotlin b/runtime/camel-k-runtime-kotlin/src/main/resources/META-INF/services/org/apache/camel/k/loader/kts similarity index 100% rename from runtime/camel-k-runtime-kotlin/src/main/resources/META-INF/services/org/apache/camel/k/loader/kotlin rename to runtime/camel-k-runtime-kotlin/src/main/resources/META-INF/services/org/apache/camel/k/loader/kts diff --git a/runtime/camel-k-runtime-yaml/src/main/java/org/apache/camel/k/yaml/YamlFlowLoader.java b/runtime/camel-k-runtime-yaml/src/main/java/org/apache/camel/k/yaml/YamlFlowLoader.java index d5b5a37e6d..8b6b7849ff 100644 --- a/runtime/camel-k-runtime-yaml/src/main/java/org/apache/camel/k/yaml/YamlFlowLoader.java +++ b/runtime/camel-k-runtime-yaml/src/main/java/org/apache/camel/k/yaml/YamlFlowLoader.java @@ -27,7 +27,6 @@ import com.fasterxml.jackson.dataformat.yaml.YAMLFactory; import com.fasterxml.jackson.dataformat.yaml.YAMLGenerator; import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.k.Language; import org.apache.camel.k.RoutesLoader; import org.apache.camel.k.RuntimeRegistry; import org.apache.camel.k.Source; @@ -56,8 +55,8 @@ public YamlFlowLoader() { } @Override - public List getSupportedLanguages() { - return Collections.singletonList(Language.YamlFlow); + public List getSupportedLanguages() { + return Collections.singletonList("flow"); } @SuppressWarnings("uncheked") diff --git a/runtime/camel-k-runtime-yaml/src/main/resources/META-INF/services/org/apache/camel/k/loader/yaml-flow b/runtime/camel-k-runtime-yaml/src/main/resources/META-INF/services/org/apache/camel/k/loader/flow similarity index 100% rename from runtime/camel-k-runtime-yaml/src/main/resources/META-INF/services/org/apache/camel/k/loader/yaml-flow rename to runtime/camel-k-runtime-yaml/src/main/resources/META-INF/services/org/apache/camel/k/loader/flow