Skip to content

Commit

Permalink
runtime: simplify loader development
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Jan 25, 2019
1 parent e7427c7 commit 3290846
Show file tree
Hide file tree
Showing 15 changed files with 94 additions and 137 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public interface RoutesLoader {
*
* @return the supported languages.
*/
List<Language> getSupportedLanguages();
List<String> getSupportedLanguages();

/**
* Creates a camel {@link RouteBuilder} from the given resource.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -37,7 +37,7 @@ public String getLocation() {
return location;
}

public Language getLanguage() {
public String getLanguage() {
return language;
}

Expand Down Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<Language> getSupportedLanguages() {
return Collections.singletonList(Language.Groovy)
List<String> getSupportedLanguages() {
return Collections.singletonList("groovy")
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
/**
* 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;
import java.util.List;

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;
import org.apache.commons.lang3.StringUtils;

public class JavaClassLoader implements RoutesLoader {
@Override
public List<Language> getSupportedLanguages() {
return Collections.singletonList(Language.JavaClass);
public List<String> getSupportedLanguages() {
return Collections.singletonList("class");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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<Language> getSupportedLanguages() {
return Collections.singletonList(Language.JavaScript);
public List<String> getSupportedLanguages() {
return Collections.singletonList("js");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -17,8 +32,8 @@

public class JavaSourceLoader implements RoutesLoader {
@Override
public List<Language> getSupportedLanguages() {
return Collections.singletonList(Language.JavaSource);
public List<String> getSupportedLanguages() {
return Collections.singletonList("java");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand All @@ -20,8 +35,8 @@ public class XmlLoader implements RoutesLoader {
private static final Logger LOGGER = LoggerFactory.getLogger(XmlLoader.class);

@Override
public List<Language> getSupportedLanguages() {
return Collections.singletonList(Language.Xml);
public List<String> getSupportedLanguages() {
return Collections.singletonList("xml");
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -41,8 +40,8 @@ class KotlinRoutesLoader : RoutesLoader {
val LOGGER : Logger = LoggerFactory.getLogger(KotlinRoutesLoader::class.java)
}

override fun getSupportedLanguages(): List<Language> {
return listOf(Language.Kotlin)
override fun getSupportedLanguages(): List<String> {
return listOf("kts")
}

@Throws(Exception::class)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -56,8 +55,8 @@ public YamlFlowLoader() {
}

@Override
public List<Language> getSupportedLanguages() {
return Collections.singletonList(Language.YamlFlow);
public List<String> getSupportedLanguages() {
return Collections.singletonList("flow");
}

@SuppressWarnings("uncheked")
Expand Down

0 comments on commit 3290846

Please sign in to comment.