This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new 2ba3d4aa5f7 CAMEL-22079: camel-dsl-modeline: Remove deprecated camel-k specific modelines 2ba3d4aa5f7 is described below commit 2ba3d4aa5f7c222e793abfabfc90ae491f0e0fa9 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Sun May 18 09:46:53 2025 +0200 CAMEL-22079: camel-dsl-modeline: Remove deprecated camel-k specific modelines --- .../ROOT/pages/camel-4x-upgrade-guide-4_12.adoc | 4 + .../src/main/docs/dsl-modeline.adoc | 16 +- .../camel/dsl/modeline/CamelKModelineParser.java | 136 --------------- .../camel/dsl/modeline/DefaultModelineFactory.java | 16 +- .../apache/camel/dsl/modeline/DependencyTrait.java | 44 ----- .../org/apache/camel/dsl/modeline/EnvTrait.java | 44 ----- .../camel/dsl/modeline/JBangModelineParser.java | 10 -- .../apache/camel/dsl/modeline/ModelineParser.java | 18 -- .../org/apache/camel/dsl/modeline/NameTrait.java | 41 ----- .../apache/camel/dsl/modeline/PropertyTrait.java | 130 --------------- .../java/org/apache/camel/dsl/modeline/Trait.java | 42 ----- .../dsl/modeline/CamelKModelineParserTest.java | 185 --------------------- .../src/test/resources/myapp.properties | 19 --- 13 files changed, 7 insertions(+), 698 deletions(-) diff --git a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_12.adoc b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_12.adoc index 8824a5e159c..b2baf4d9228 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_12.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-4x-upgrade-guide-4_12.adoc @@ -158,6 +158,10 @@ It is also recommended to migrate your XML-IO XML files to use the new namespace Add options allowing the addition of an `Authorization` header for Basic or Bearer authentication to client and asynchronous MDN requests. +=== camel-dsl-modeline + +Removed deprecated `camel-k:` specific modelines. + === camel-jackson / camel-jacksonxml The default unmarshalType has been changed from `HashMap` to `LinkedHashMap` that keeps ordering of the elements diff --git a/dsl/camel-dsl-modeline/src/main/docs/dsl-modeline.adoc b/dsl/camel-dsl-modeline/src/main/docs/dsl-modeline.adoc index 93622555a50..e405ebc52ee 100644 --- a/dsl/camel-dsl-modeline/src/main/docs/dsl-modeline.adoc +++ b/dsl/camel-dsl-modeline/src/main/docs/dsl-modeline.adoc @@ -13,17 +13,5 @@ == Camel JBang -There is support for https://www.jbang.dev/documentation/guide/latest/dependencies.html[JBang dependencies] using the `//DEPS` comments style. - -== Camel K - -*Deprecated* - -Support for Camel K style modeline when running Camel standalone such as with Camel JBang. - -The following traits is supported: - -- dependency -- env -- name -- property +There is support for https://www.jbang.dev/documentation/guide/latest/dependencies.html[JBang dependencies] using the `//DEPS` comments style, +when using Camel JBang. diff --git a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/CamelKModelineParser.java b/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/CamelKModelineParser.java deleted file mode 100644 index 551d37086d8..00000000000 --- a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/CamelKModelineParser.java +++ /dev/null @@ -1,136 +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.dsl.modeline; - -import java.io.LineNumberReader; -import java.util.ArrayList; -import java.util.Collections; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -import org.apache.camel.spi.CamelContextCustomizer; -import org.apache.camel.spi.Resource; -import org.apache.camel.util.StringHelper; -import org.apache.camel.util.StringQuoteHelper; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -@Deprecated(since = "4.10") -public class CamelKModelineParser implements ModelineParser { - - private static final Logger LOG = LoggerFactory.getLogger(CamelKModelineParser.class); - - public static final String MODELINE_START = "camel-k:"; - - private final Map<String, Trait> traits = new HashMap<>(); - - public CamelKModelineParser() { - // add known traits - Trait trait = new DependencyTrait(); - this.traits.put(trait.getName(), trait); - // property trait is added from the default mode line factory - trait = new NameTrait(); - this.traits.put(trait.getName(), trait); - trait = new EnvTrait(); - this.traits.put(trait.getName(), trait); - } - - @Override - public void addTrait(Trait trait) { - this.traits.put(trait.getName(), trait); - } - - @Override - public List<CamelContextCustomizer> parse(Resource resource) throws Exception { - List<CamelContextCustomizer> answer = new ArrayList<>(); - - if (resource.exists()) { - try (LineNumberReader reader = new LineNumberReader(resource.getReader())) { - String line = reader.readLine(); - while (line != null) { - List<CamelContextCustomizer> list = parse(resource, line); - answer.addAll(list); - line = reader.readLine(); - } - } - } - - return answer; - } - - protected List<CamelContextCustomizer> parse(Resource resource, String line) { - if (!isModeline(line)) { - return Collections.emptyList(); - } - line = removeLeadingComments(line); - - List<CamelContextCustomizer> answer = new ArrayList<>(); - - if (line.startsWith(MODELINE_START)) { - LOG.warn("Using modeline is deprecated. {}: {}", resource.getLocation(), line); - - line = line.substring(MODELINE_START.length()).trim(); - // split into key value pairs - String[] parts = StringQuoteHelper.splitSafeQuote(line, ' ', false); - for (String part : parts) { - part = part.trim(); - String key = StringHelper.before(part, "="); - String value = StringHelper.after(part, "="); - Trait trait = parseModeline(resource, key, value); - if (trait != null) { - CamelContextCustomizer customizer = trait.parseTrait(resource, value); - if (customizer != null) { - answer.add(customizer); - } - } - } - } - - return answer; - } - - @Override - public Trait parseModeline(Resource resource, String key, String value) { - return traits.get(key); - } - - @Override - public boolean isModeline(String line) { - // the line must be a comment and start with camel-k - if (line == null) { - return false; - } - line = removeLeadingComments(line); - return line.startsWith(MODELINE_START); - } - - private static String removeLeadingComments(String line) { - if (line == null) { - return null; - } - - line = line.trim(); - while (line.startsWith("/") || line.startsWith("#")) { - line = line.substring(1); - } - - line = line.trim(); - return line; - } - -} diff --git a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/DefaultModelineFactory.java b/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/DefaultModelineFactory.java index da617f8152e..3fc3ca025fa 100644 --- a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/DefaultModelineFactory.java +++ b/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/DefaultModelineFactory.java @@ -25,8 +25,6 @@ import org.apache.camel.NonManagedService; import org.apache.camel.StaticService; import org.apache.camel.spi.CamelContextCustomizer; import org.apache.camel.spi.ModelineFactory; -import org.apache.camel.spi.PropertiesComponent; -import org.apache.camel.spi.PropertiesSource; import org.apache.camel.spi.Resource; import org.apache.camel.spi.annotations.JdkService; import org.apache.camel.support.CamelContextHelper; @@ -37,7 +35,6 @@ public class DefaultModelineFactory extends ServiceSupport implements ModelineFactory, CamelContextAware, NonManagedService, StaticService { private CamelContext camelContext; - private final ModelineParser camelk = new CamelKModelineParser(); private final ModelineParser jbang = new JBangModelineParser(); private ModelineParser parser; @@ -53,9 +50,7 @@ public class DefaultModelineFactory extends ServiceSupport @Override public void parseModeline(Resource resource) throws Exception { - List<CamelContextCustomizer> customizers = new ArrayList<>(); - customizers.addAll(camelk.parse(resource)); - customizers.addAll(jbang.parse(resource)); + List<CamelContextCustomizer> customizers = new ArrayList<>(jbang.parse(resource)); // custom parser which may return null if (parser != null) { var list = parser.parse(resource); @@ -79,15 +74,6 @@ public class DefaultModelineFactory extends ServiceSupport protected void doInit() throws Exception { // is there any custom modeline parser parser = CamelContextHelper.findSingleByType(camelContext, ModelineParser.class); - - // the property is both a trait and a source, but we must use the same instance - // so we need to get the existing instance from the properties component to - // add to the parser as its trait - PropertiesComponent pc = camelContext.getPropertiesComponent(); - PropertiesSource ps = pc.getPropertiesSource("property"); - if (ps instanceof Trait trait) { - camelk.addTrait(trait); - } } @Override diff --git a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/DependencyTrait.java b/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/DependencyTrait.java deleted file mode 100644 index e60dcd66ce5..00000000000 --- a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/DependencyTrait.java +++ /dev/null @@ -1,44 +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.dsl.modeline; - -import org.apache.camel.CamelContext; -import org.apache.camel.spi.CamelContextCustomizer; -import org.apache.camel.spi.DependencyStrategy; -import org.apache.camel.spi.Resource; - -@Deprecated(since = "4.10") -public class DependencyTrait implements Trait { - - @Override - public String getName() { - return "dependency"; - } - - @Override - public CamelContextCustomizer parseTrait(Resource resource, String trait) { - return new CamelContextCustomizer() { - @Override - public void configure(CamelContext camelContext) { - for (DependencyStrategy ds : camelContext.getRegistry().findByType(DependencyStrategy.class)) { - ds.onDependency(trait); - } - } - }; - } - -} diff --git a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/EnvTrait.java b/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/EnvTrait.java deleted file mode 100644 index 3506da70daa..00000000000 --- a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/EnvTrait.java +++ /dev/null @@ -1,44 +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.dsl.modeline; - -import org.apache.camel.CamelContext; -import org.apache.camel.spi.CamelContextCustomizer; -import org.apache.camel.spi.Resource; -import org.apache.camel.util.StringHelper; - -@Deprecated(since = "4.10") -public class EnvTrait implements Trait { - - @Override - public String getName() { - return "env"; - } - - @Override - public CamelContextCustomizer parseTrait(Resource resource, String trait) { - String key = StringHelper.before(trait, "=").trim(); - String value = StringHelper.after(trait, "=").trim(); - return new CamelContextCustomizer() { - @Override - public void configure(CamelContext camelContext) { - System.getenv().put(key, value); - } - }; - } - -} diff --git a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/JBangModelineParser.java b/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/JBangModelineParser.java index f55fd40b894..1deb2f586b0 100644 --- a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/JBangModelineParser.java +++ b/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/JBangModelineParser.java @@ -31,16 +31,6 @@ public class JBangModelineParser implements ModelineParser { public static final String JBANG_DEPS_START = "//DEPS"; - @Override - public void addTrait(Trait trait) { - throw new UnsupportedOperationException("Cannot add traits"); - } - - @Override - public Trait parseModeline(Resource resource, String key, String value) { - return null; - } - @Override public List<CamelContextCustomizer> parse(Resource resource) throws Exception { List<CamelContextCustomizer> answer = new ArrayList<>(); diff --git a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/ModelineParser.java b/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/ModelineParser.java index 5d49361f952..0b3e7e98374 100644 --- a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/ModelineParser.java +++ b/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/ModelineParser.java @@ -26,14 +26,6 @@ import org.apache.camel.spi.Resource; */ public interface ModelineParser { - /** - * Adds the {@link Trait} to the parser - * - * @param trait the trait - */ - @Deprecated - void addTrait(Trait trait); - /** * Is the given source code line a modeline? * @@ -51,14 +43,4 @@ public interface ModelineParser { */ List<CamelContextCustomizer> parse(Resource resource) throws Exception; - /** - * A modeline was detected while parsing - * - * @param resource the resource - * @param key the mode line key - * @param value the mode line value - * @return the trait that handles the detected modeline - */ - @Deprecated - Trait parseModeline(Resource resource, String key, String value); } diff --git a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/NameTrait.java b/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/NameTrait.java deleted file mode 100644 index 281f2641578..00000000000 --- a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/NameTrait.java +++ /dev/null @@ -1,41 +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.dsl.modeline; - -import org.apache.camel.CamelContext; -import org.apache.camel.spi.CamelContextCustomizer; -import org.apache.camel.spi.Resource; - -@Deprecated(since = "4.10") -public class NameTrait implements Trait { - - @Override - public String getName() { - return "name"; - } - - @Override - public CamelContextCustomizer parseTrait(Resource resource, String trait) { - return new CamelContextCustomizer() { - @Override - public void configure(CamelContext camelContext) { - camelContext.getCamelContextExtension().setName(trait); - } - }; - } - -} diff --git a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/PropertyTrait.java b/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/PropertyTrait.java deleted file mode 100644 index f5db6314991..00000000000 --- a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/PropertyTrait.java +++ /dev/null @@ -1,130 +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.dsl.modeline; - -import java.io.InputStream; -import java.util.Properties; -import java.util.function.Predicate; - -import org.apache.camel.CamelContext; -import org.apache.camel.CamelContextAware; -import org.apache.camel.Ordered; -import org.apache.camel.spi.CamelContextCustomizer; -import org.apache.camel.spi.LoadablePropertiesSource; -import org.apache.camel.spi.PropertiesSource; -import org.apache.camel.spi.Resource; -import org.apache.camel.spi.annotations.JdkService; -import org.apache.camel.support.ResourceHelper; -import org.apache.camel.util.OrderedLocationProperties; -import org.apache.camel.util.StringHelper; - -/** - * This trait is a {@link PropertiesSource} so Camel properties component will use this directly when looking for - * property values. - */ -@Deprecated(since = "4.10") -@JdkService("properties-source-factory") -public class PropertyTrait implements Trait, LoadablePropertiesSource, CamelContextAware, Ordered { - - private final OrderedLocationProperties properties = new OrderedLocationProperties(); - private CamelContext camelContext; - - @Override - public int getOrder() { - return 900; - } - - @Override - public CamelContext getCamelContext() { - return camelContext; - } - - @Override - public void setCamelContext(CamelContext camelContext) { - this.camelContext = camelContext; - } - - @Override - public String getName() { - return "property"; - } - - @Override - public String getProperty(String name) { - return properties.getProperty(name); - } - - @Override - public CamelContextCustomizer parseTrait(Resource resource, String trait) { - if (trait.contains("=")) { - String key = StringHelper.before(trait, "=").trim(); - String value = StringHelper.after(trait, "=").trim(); - setProperty(resource, key, value); - } else { - if (ResourceHelper.hasScheme(trait)) { - // it is a properties file so load resource - try (InputStream is = ResourceHelper.resolveResourceAsInputStream(camelContext, trait)) { - Properties prop = new Properties(); - prop.load(is); - for (String k : prop.stringPropertyNames()) { - String v = prop.getProperty(k); - String key = k.trim(); - String value = v.trim(); - setProperty(resource, key, value); - } - } catch (Exception e) { - // ignore - } - } - } - return null; - } - - protected void setProperty(Resource resource, String key, String value) { - String loc = resource.getLocation(); - properties.put(loc, key, value); - } - - @Override - public Properties loadProperties() { - return properties; - } - - @Override - public Properties loadProperties(Predicate<String> filter) { - OrderedLocationProperties answer = new OrderedLocationProperties(); - - for (String name : properties.stringPropertyNames()) { - if (filter.test(name)) { - answer.put(properties.getLocation(name), name, properties.get(name)); - } - } - - return answer; - } - - @Override - public void reloadProperties(String location) { - // noop - } - - @Override - public String toString() { - return "camel-dsl-modeline"; - } - -} diff --git a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/Trait.java b/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/Trait.java deleted file mode 100644 index ac8050fc92e..00000000000 --- a/dsl/camel-dsl-modeline/src/main/java/org/apache/camel/dsl/modeline/Trait.java +++ /dev/null @@ -1,42 +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.dsl.modeline; - -import org.apache.camel.spi.CamelContextCustomizer; -import org.apache.camel.spi.Resource; - -/** - * Modeline trait - */ -@Deprecated(since = "4.10") -public interface Trait { - - /** - * Name of trait - */ - String getName(); - - /** - * Parses the trait - * - * @param resource the source - * @param trait the trait - * @return a customizer if the trait is accepted, otherwise null is returned - */ - CamelContextCustomizer parseTrait(Resource resource, String trait); - -} diff --git a/dsl/camel-dsl-modeline/src/test/java/org/apache/camel/dsl/modeline/CamelKModelineParserTest.java b/dsl/camel-dsl-modeline/src/test/java/org/apache/camel/dsl/modeline/CamelKModelineParserTest.java deleted file mode 100644 index 5e398bf8ca5..00000000000 --- a/dsl/camel-dsl-modeline/src/test/java/org/apache/camel/dsl/modeline/CamelKModelineParserTest.java +++ /dev/null @@ -1,185 +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.dsl.modeline; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.camel.CamelContext; -import org.apache.camel.spi.DependencyStrategy; -import org.apache.camel.spi.ModelineFactory; -import org.apache.camel.support.PluginHelper; -import org.apache.camel.support.ResourceHelper; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -@Deprecated -public class CamelKModelineParserTest extends CamelTestSupport { - - private final List<String> deps = new ArrayList<>(); - - private ModelineFactory resolveModelineFactory(CamelContext camelContext) { - return PluginHelper.getModelineFactory(camelContext); - } - - @Override - protected CamelContext createCamelContext() throws Exception { - CamelContext context = super.createCamelContext(); - context.getRegistry().bind("myDep", new DependencyStrategy() { - @Override - public void onDependency(String dependency) { - deps.add(dependency); - } - }); - return context; - } - - @Override - public boolean isUseRouteBuilder() { - return false; - } - - @Test - public void testModelineSingleDependency() throws Exception { - context.start(); - - Assertions.assertEquals(0, deps.size()); - - String line = "// camel-k: dependency=mvn:org.my:application:1.0"; - ModelineFactory factory = resolveModelineFactory(context); - factory.parseModeline(ResourceHelper.fromString(null, line)); - - Assertions.assertEquals(1, deps.size()); - Assertions.assertEquals("mvn:org.my:application:1.0", deps.get(0)); - } - - @Test - public void testModelineSingleDependencyCommentHash() throws Exception { - context.start(); - - Assertions.assertEquals(0, deps.size()); - - String line = "### camel-k: dependency=mvn:org.my:application:1.0"; - ModelineFactory factory = resolveModelineFactory(context); - factory.parseModeline(ResourceHelper.fromString(null, line)); - - Assertions.assertEquals(1, deps.size()); - Assertions.assertEquals("mvn:org.my:application:1.0", deps.get(0)); - } - - @Test - public void testModelineMultiDependency() throws Exception { - context.start(); - deps.clear(); - - Assertions.assertEquals(0, deps.size()); - - String line = "// camel-k: dependency=mvn:org.my:application:1.0 dependency=mvn:com.foo:myapp:2.1"; - ModelineFactory factory = resolveModelineFactory(context); - factory.parseModeline(ResourceHelper.fromString(null, line)); - - Assertions.assertEquals(2, deps.size()); - Assertions.assertEquals("mvn:org.my:application:1.0", deps.get(0)); - Assertions.assertEquals("mvn:com.foo:myapp:2.1", deps.get(1)); - } - - @Test - public void testModelineSingleProperty() throws Exception { - context.start(); - - String line = "// camel-k: property=hi=Hello"; - ModelineFactory factory = resolveModelineFactory(context); - factory.parseModeline(ResourceHelper.fromString(null, line)); - - Assertions.assertEquals("Hello", context.getPropertiesComponent().parseUri("{{hi}}")); - } - - @Test - public void testModelineMultiProperty() throws Exception { - context.start(); - - String line = "// camel-k: property=hi=Hello property=bye=Farvel"; - ModelineFactory factory = resolveModelineFactory(context); - factory.parseModeline(ResourceHelper.fromString(null, line)); - - Assertions.assertEquals("Hello", context.getPropertiesComponent().parseUri("{{hi}}")); - Assertions.assertEquals("Farvel", context.getPropertiesComponent().parseUri("{{bye}}")); - } - - @Test - public void testModelineQuoteProperty() throws Exception { - context.start(); - - String line = "// camel-k: property=hi='Hello World' property=bye='Farvel Verden'"; - ModelineFactory factory = resolveModelineFactory(context); - factory.parseModeline(ResourceHelper.fromString(null, line)); - - Assertions.assertEquals("Hello World", context.getPropertiesComponent().parseUri("{{hi}}")); - Assertions.assertEquals("Farvel Verden", context.getPropertiesComponent().parseUri("{{bye}}")); - } - - @Test - public void testModelineMixed() throws Exception { - context.start(); - deps.clear(); - - Assertions.assertEquals(0, deps.size()); - - String line = "// camel-k: dependency=mvn:org.my:application:1.0 property=hi=Hello dependency=mvn:com.foo:myapp:2.1"; - ModelineFactory factory = resolveModelineFactory(context); - factory.parseModeline(ResourceHelper.fromString(null, line)); - - Assertions.assertEquals(2, deps.size()); - Assertions.assertEquals("mvn:org.my:application:1.0", deps.get(0)); - Assertions.assertEquals("mvn:com.foo:myapp:2.1", deps.get(1)); - - Assertions.assertEquals("Hello", context.getPropertiesComponent().parseUri("{{hi}}")); - } - - @Test - public void testModelineMixedWithSpaces() throws Exception { - context.start(); - deps.clear(); - - Assertions.assertEquals(0, deps.size()); - - String line - = "// camel-k: dependency=mvn:org.my:application:1.0 property=hi=Hello dependency=mvn:com.foo:myapp:2.1"; - ModelineFactory factory = resolveModelineFactory(context); - factory.parseModeline(ResourceHelper.fromString(null, line)); - - Assertions.assertEquals(2, deps.size()); - Assertions.assertEquals("mvn:org.my:application:1.0", deps.get(0)); - Assertions.assertEquals("mvn:com.foo:myapp:2.1", deps.get(1)); - - Assertions.assertEquals("Hello", context.getPropertiesComponent().parseUri("{{hi}}")); - } - - @Test - public void testModelinePropertiesFile() throws Exception { - context.start(); - - String line = "// camel-k: property=classpath:myapp.properties"; - ModelineFactory factory = resolveModelineFactory(context); - factory.parseModeline(ResourceHelper.fromString(null, line)); - - Assertions.assertEquals("Hej", context.getPropertiesComponent().parseUri("{{hi}}")); - Assertions.assertEquals("bar", context.getPropertiesComponent().parseUri("{{foo}}")); - } - -} diff --git a/dsl/camel-dsl-modeline/src/test/resources/myapp.properties b/dsl/camel-dsl-modeline/src/test/resources/myapp.properties deleted file mode 100644 index f37f1bd70d6..00000000000 --- a/dsl/camel-dsl-modeline/src/test/resources/myapp.properties +++ /dev/null @@ -1,19 +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. -## --------------------------------------------------------------------------- - -foo=bar -hi=Hej \ No newline at end of file