This is an automated email from the ASF dual-hosted git repository.
nfilotto 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 425293d0291 CAMEL-18864: java-joor-dsl - Drop support of class files
(#9016)
425293d0291 is described below
commit 425293d0291328f50304f51029a8e60422bb52df
Author: Nicolas Filotto <[email protected]>
AuthorDate: Mon Jan 9 13:26:53 2023 +0100
CAMEL-18864: java-joor-dsl - Drop support of class files (#9016)
## Motivation
I think we can remove the .class also in camel core for `java-joor` dsl as
it is not really needed anymore. I think (I am getting older so it is maybe no
longer there) there is an option in camel-main to configure a "compile
directory" so removing would also need to remove that.
## Modifications
* Remove the `ClassRoutesBuilderLoader`
* Remove "compile directory" and "compile load first" everywhere it is
defined and used
* Remove all related unit tests
* Add a note in the upgrade guide
---
.../camel/spi/ExtendedRoutesBuilderLoader.java | 21 ----
.../MainConfigurationPropertiesConfigurer.java | 12 ---
.../camel-main-configuration-metadata.json | 2 -
core/camel-main/src/main/docs/main.adoc | 4 +-
.../org/apache/camel/main/BaseMainSupport.java | 15 +--
.../camel/main/MainConfigurationProperties.java | 54 ----------
.../org/apache/camel/main/MainRoutesLoader.java | 46 ---------
.../ROOT/pages/camel-3x-upgrade-guide-3_21.adoc | 3 +
.../support/ExtendedRouteBuilderLoaderSupport.java | 26 +----
.../dsl/java/joor/ClassRoutesBuilderLoader.java | 103 -------------------
.../dsl/java/joor/JavaRoutesBuilderLoader.java | 68 ------------
.../java/joor/ClassRoutesBuilderLoaderTest.java | 69 -------------
.../dsl/java/joor/JavaJoorCaptureByteCodeTest.java | 114 ---------------------
.../dsl/java/joor/JavaJoorSaveToDiskTest.java | 71 -------------
.../java/org/apache/camel/main/KameletMain.java | 2 +-
.../download/DependencyDownloaderRoutesLoader.java | 8 +-
16 files changed, 11 insertions(+), 607 deletions(-)
diff --git
a/core/camel-api/src/main/java/org/apache/camel/spi/ExtendedRoutesBuilderLoader.java
b/core/camel-api/src/main/java/org/apache/camel/spi/ExtendedRoutesBuilderLoader.java
index 5e3551eb2b4..8528775e58e 100644
---
a/core/camel-api/src/main/java/org/apache/camel/spi/ExtendedRoutesBuilderLoader.java
+++
b/core/camel-api/src/main/java/org/apache/camel/spi/ExtendedRoutesBuilderLoader.java
@@ -34,25 +34,4 @@ public interface ExtendedRoutesBuilderLoader extends
RoutesBuilderLoader {
*/
Collection<RoutesBuilder> loadRoutesBuilders(Collection<Resource>
resources) throws Exception;
- String getCompileDirectory();
-
- /**
- * Directory to use for saving runtime compiled Camel routes to class
files, when using camel-java-joor-dsl as Java
- * DSL (such as when using Camel K with Java source routes). Camel will
compile to in-memory only by default.
- * Specifying this option, allows Camel to persist the compiled class to
disk. And when starting the application
- * again the routes are loaded from the pre-compiled class files instead
of re-compiling again.
- */
- void setCompileDirectory(String compileDirectory);
-
- boolean isCompileLoadFirst();
-
- /**
- * Whether to load preexisting compiled Camel routes class files, when
using camel-java-joor-dsl as Java DSL (such
- * as when using Camel K with Java source routes).
- *
- * If enabled then Camel will look in the routes compile directory if a
compiled Java route already exists and load
- * its bytecode instead of runtime compiling from its java source file.
- */
- void setCompileLoadFirst(boolean compileLoadFirst);
-
}
diff --git
a/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
b/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
index f55f7da8e7c..6c80c9ec9df 100644
---
a/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
+++
b/core/camel-main/src/generated/java/org/apache/camel/main/MainConfigurationPropertiesConfigurer.java
@@ -169,10 +169,6 @@ public class MainConfigurationPropertiesConfigurer extends
org.apache.camel.supp
case "RoutesBuilders": target.setRoutesBuilders(property(camelContext,
java.util.List.class, value)); return true;
case "routescollectorenabled":
case "RoutesCollectorEnabled":
target.setRoutesCollectorEnabled(property(camelContext, boolean.class, value));
return true;
- case "routescompiledirectory":
- case "RoutesCompileDirectory":
target.setRoutesCompileDirectory(property(camelContext, java.lang.String.class,
value)); return true;
- case "routescompileloadfirst":
- case "RoutesCompileLoadFirst":
target.setRoutesCompileLoadFirst(property(camelContext, boolean.class, value));
return true;
case "routesexcludepattern":
case "RoutesExcludePattern":
target.setRoutesExcludePattern(property(camelContext, java.lang.String.class,
value)); return true;
case "routesincludepattern":
@@ -412,10 +408,6 @@ public class MainConfigurationPropertiesConfigurer extends
org.apache.camel.supp
case "RoutesBuilders": return java.util.List.class;
case "routescollectorenabled":
case "RoutesCollectorEnabled": return boolean.class;
- case "routescompiledirectory":
- case "RoutesCompileDirectory": return java.lang.String.class;
- case "routescompileloadfirst":
- case "RoutesCompileLoadFirst": return boolean.class;
case "routesexcludepattern":
case "RoutesExcludePattern": return java.lang.String.class;
case "routesincludepattern":
@@ -656,10 +648,6 @@ public class MainConfigurationPropertiesConfigurer extends
org.apache.camel.supp
case "RoutesBuilders": return target.getRoutesBuilders();
case "routescollectorenabled":
case "RoutesCollectorEnabled": return
target.isRoutesCollectorEnabled();
- case "routescompiledirectory":
- case "RoutesCompileDirectory": return
target.getRoutesCompileDirectory();
- case "routescompileloadfirst":
- case "RoutesCompileLoadFirst": return
target.isRoutesCompileLoadFirst();
case "routesexcludepattern":
case "RoutesExcludePattern": return target.getRoutesExcludePattern();
case "routesincludepattern":
diff --git
a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
index d2d09c2a980..c614a5232d4 100644
---
a/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
+++
b/core/camel-main/src/generated/resources/META-INF/camel-main-configuration-metadata.json
@@ -86,8 +86,6 @@
{ "name": "camel.main.routesBuilderClasses", "description": "Sets classes
names that implement RoutesBuilder .", "sourceType":
"org.apache.camel.main.MainConfigurationProperties", "type": "string",
"javaType": "java.lang.String" },
{ "name": "camel.main.routesBuilders", "description": "Sets the
RoutesBuilder instances.", "sourceType":
"org.apache.camel.main.MainConfigurationProperties", "type": "object",
"javaType": "java.util.List" },
{ "name": "camel.main.routesCollectorEnabled", "description": "Whether the
routes collector is enabled or not. When enabled Camel will auto-discover
routes (RouteBuilder instances from the registry and also load additional
routes from the file system). The routes collector is default enabled.",
"sourceType": "org.apache.camel.main.DefaultConfigurationProperties", "type":
"boolean", "javaType": "boolean", "defaultValue": true },
- { "name": "camel.main.routesCompileDirectory", "description": "Directory
to use for saving runtime compiled Camel routes to class files, when using
camel-java-joor-dsl as Java DSL (such as when using Camel K with Java source
routes). Camel will compile to in-memory only by default. Specifying this
option, allows Camel to persist the compiled class to disk. And when starting
the application again the routes are loaded from the pre-compiled class files
instead of re-compiling again.", [...]
- { "name": "camel.main.routesCompileLoadFirst", "description": "Whether to
load preexisting compiled Camel routes class files, when using
camel-java-joor-dsl as Java DSL (such as when using Camel K with Java source
routes). If enabled then Camel will look in the routes compile directory if a
compiled Java route already exists and load its bytecode instead of runtime
compiling from its java source file.", "sourceType":
"org.apache.camel.main.MainConfigurationProperties", "type": "boole [...]
{ "name": "camel.main.routesExcludePattern", "description": "Used for
exclusive filtering of routes from directories. The exclusive filtering takes
precedence over inclusive filtering. The pattern is using Ant-path style
pattern. Multiple patterns can be specified separated by comma, as example, to
exclude all the routes from a directory whose name contains foo use:
**\/foo.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "string",
"javaType": [...]
{ "name": "camel.main.routesIncludePattern", "description": "Used for
inclusive filtering of routes from directories. The exclusive filtering takes
precedence over inclusive filtering. The pattern is using Ant-path style
pattern. Multiple patterns can be specified separated by comma, as example, to
include all the routes from a directory whose name contains foo use:
**\/foo.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "string",
"javaType": [...]
{ "name": "camel.main.routesReloadDirectory", "description": "Directory to
scan for route changes. Camel cannot scan the classpath, so this must be
configured to a file directory. Development with Maven as build tool, you can
configure the directory to be src\/main\/resources to scan for Camel routes in
XML or YAML files.", "sourceType":
"org.apache.camel.main.DefaultConfigurationProperties", "type": "string",
"javaType": "java.lang.String", "defaultValue": "src\/main\/resources\/camel" },
diff --git a/core/camel-main/src/main/docs/main.adoc
b/core/camel-main/src/main/docs/main.adoc
index d441f5b8a35..73438fb59a9 100644
--- a/core/camel-main/src/main/docs/main.adoc
+++ b/core/camel-main/src/main/docs/main.adoc
@@ -18,7 +18,7 @@ The following tables lists all the options:
// main options: START
=== Camel Main configurations
-The camel.main supports 118 options, which are listed below.
+The camel.main supports 116 options, which are listed below.
[width="100%",cols="2,5,^1,2",options="header"]
|===
@@ -97,8 +97,6 @@ The camel.main supports 118 options, which are listed below.
| *camel.main.routesBuilder{zwsp}Classes* | Sets classes names that implement
RoutesBuilder . | | String
| *camel.main.routesBuilders* | Sets the RoutesBuilder instances. | | List
| *camel.main.routesCollector{zwsp}Enabled* | Whether the routes collector is
enabled or not. When enabled Camel will auto-discover routes (RouteBuilder
instances from the registry and also load additional routes from the file
system). The routes collector is default enabled. | true | boolean
-| *camel.main.routesCompile{zwsp}Directory* | Directory to use for saving
runtime compiled Camel routes to class files, when using camel-java-joor-dsl as
Java DSL (such as when using Camel K with Java source routes). Camel will
compile to in-memory only by default. Specifying this option, allows Camel to
persist the compiled class to disk. And when starting the application again the
routes are loaded from the pre-compiled class files instead of re-compiling
again. | | String
-| *camel.main.routesCompileLoad{zwsp}First* | Whether to load preexisting
compiled Camel routes class files, when using camel-java-joor-dsl as Java DSL
(such as when using Camel K with Java source routes). If enabled then Camel
will look in the routes compile directory if a compiled Java route already
exists and load its bytecode instead of runtime compiling from its java source
file. | false | boolean
| *camel.main.routesExclude{zwsp}Pattern* | Used for exclusive filtering of
routes from directories. The exclusive filtering takes precedence over
inclusive filtering. The pattern is using Ant-path style pattern. Multiple
patterns can be specified separated by comma, as example, to exclude all the
routes from a directory whose name contains foo use: **/foo. | | String
| *camel.main.routesInclude{zwsp}Pattern* | Used for inclusive filtering of
routes from directories. The exclusive filtering takes precedence over
inclusive filtering. The pattern is using Ant-path style pattern. Multiple
patterns can be specified separated by comma, as example, to include all the
routes from a directory whose name contains foo use: **/foo. |
classpath:camel/*,classpath:camel-template/*,classpath:camel-rest/* | String
| *camel.main.routesReload{zwsp}Directory* | Directory to scan for route
changes. Camel cannot scan the classpath, so this must be configured to a file
directory. Development with Maven as build tool, you can configure the
directory to be src/main/resources to scan for Camel routes in XML or YAML
files. | src/main/resources/camel | String
diff --git
a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
index 78f6f55ab6e..850eb8a7614 100644
--- a/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
+++ b/core/camel-main/src/main/java/org/apache/camel/main/BaseMainSupport.java
@@ -48,6 +48,7 @@ import org.apache.camel.console.DevConsoleRegistry;
import org.apache.camel.health.HealthCheck;
import org.apache.camel.health.HealthCheckRegistry;
import org.apache.camel.health.HealthCheckRepository;
+import org.apache.camel.impl.engine.DefaultRoutesLoader;
import org.apache.camel.saga.CamelSagaService;
import org.apache.camel.spi.AutowiredLifecycleStrategy;
import org.apache.camel.spi.CamelBeanPostProcessor;
@@ -468,18 +469,6 @@ public abstract class BaseMainSupport extends BaseService {
mainConfigurationProperties.setRoutesIncludePattern(value);
return null;
});
- autoConfigurationSingleOption(camelContext,
autoConfiguredProperties, "camel.main.routesCompileDirectory",
- value -> {
-
mainConfigurationProperties.setRoutesCompileDirectory(value);
- return null;
- });
- autoConfigurationSingleOption(camelContext,
autoConfiguredProperties, "camel.main.routesCompileLoadFirst",
- value -> {
- boolean bool =
CamelContextHelper.parseBoolean(camelContext, value);
-
mainConfigurationProperties.setRoutesCompileLoadFirst(bool);
- return null;
- });
-
// eager load properties from modeline by scanning DSL sources and
gather properties for auto configuration
if (camelContext.isModeline() ||
mainConfigurationProperties.isModeline()) {
modelineRoutes(camelContext);
@@ -607,7 +596,7 @@ public abstract class BaseMainSupport extends BaseService {
protected void configureRoutesLoader(CamelContext camelContext) {
// use main based routes loader
- camelContext.adapt(ExtendedCamelContext.class).setRoutesLoader(new
MainRoutesLoader(mainConfigurationProperties));
+ camelContext.adapt(ExtendedCamelContext.class).setRoutesLoader(new
DefaultRoutesLoader());
}
protected void modelineRoutes(CamelContext camelContext) throws Exception {
diff --git
a/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java
b/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java
index a3bab9c95e7..7475119eb57 100644
---
a/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java
+++
b/core/camel-main/src/main/java/org/apache/camel/main/MainConfigurationProperties.java
@@ -42,8 +42,6 @@ public class MainConfigurationProperties extends
DefaultConfigurationProperties<
private int extraShutdownTimeout = 15;
private String basePackageScan;
private boolean basePackageScanEnabled = true;
- private String routesCompileDirectory;
- private boolean routesCompileLoadFirst;
private String routesBuilderClasses;
private String configurationClasses;
@@ -333,35 +331,6 @@ public class MainConfigurationProperties extends
DefaultConfigurationProperties<
this.basePackageScanEnabled = basePackageScanEnabled;
}
- public String getRoutesCompileDirectory() {
- return routesCompileDirectory;
- }
-
- /**
- * Directory to use for saving runtime compiled Camel routes to class
files, when using camel-java-joor-dsl as Java
- * DSL (such as when using Camel K with Java source routes). Camel will
compile to in-memory only by default.
- * Specifying this option, allows Camel to persist the compiled class to
disk. And when starting the application
- * again the routes are loaded from the pre-compiled class files instead
of re-compiling again.
- */
- public void setRoutesCompileDirectory(String routesCompileDirectory) {
- this.routesCompileDirectory = routesCompileDirectory;
- }
-
- public boolean isRoutesCompileLoadFirst() {
- return routesCompileLoadFirst;
- }
-
- /**
- * Whether to load preexisting compiled Camel routes class files, when
using camel-java-joor-dsl as Java DSL (such
- * as when using Camel K with Java source routes).
- *
- * If enabled then Camel will look in the routes compile directory if a
compiled Java route already exists and load
- * its bytecode instead of runtime compiling from its java source file.
- */
- public void setRoutesCompileLoadFirst(boolean routesCompileLoadFirst) {
- this.routesCompileLoadFirst = routesCompileLoadFirst;
- }
-
public int getDurationHitExitCode() {
return durationHitExitCode;
}
@@ -621,29 +590,6 @@ public class MainConfigurationProperties extends
DefaultConfigurationProperties<
return this;
}
- /**
- * Directory to use for saving runtime compiled Camel routes to class
files, when using camel-java-joor-dsl as Java
- * DSL (such as when using Camel K with Java source routes). Camel will
compile to in-memory only by default.
- * Specifying this option, allows Camel to persist the compiled class to
disk. And when starting the application
- * again the routes are loaded from the pre-compiled class files instead
of re-compiling again.
- */
- public MainConfigurationProperties withRoutesCompileDirectory(String
routeCompileDirectory) {
- this.routesCompileDirectory = routeCompileDirectory;
- return this;
- }
-
- /**
- * Whether to load preexisting compiled Camel routes class files, when
using camel-java-joor-dsl as Java DSL (such
- * as when using Camel K with Java source routes).
- *
- * If enabled then Camel will look in the routes compile directory if a
compiled Java route already exists and load
- * its bytecode instead of runtime compiling from its java source file.
- */
- public MainConfigurationProperties withRoutesCompileLoadFirst(boolean
routesCompileLoadFirst) {
- this.routesCompileLoadFirst = routesCompileLoadFirst;
- return this;
- }
-
// fluent builders - configurations
// --------------------------------------------------------------
diff --git
a/core/camel-main/src/main/java/org/apache/camel/main/MainRoutesLoader.java
b/core/camel-main/src/main/java/org/apache/camel/main/MainRoutesLoader.java
deleted file mode 100644
index af43eacd6c6..00000000000
--- a/core/camel-main/src/main/java/org/apache/camel/main/MainRoutesLoader.java
+++ /dev/null
@@ -1,46 +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.main;
-
-import org.apache.camel.impl.engine.DefaultRoutesLoader;
-import org.apache.camel.spi.ExtendedRoutesBuilderLoader;
-import org.apache.camel.spi.RoutesBuilderLoader;
-
-/**
- * Main {@link org.apache.camel.spi.RoutesLoader}.
- */
-public class MainRoutesLoader extends DefaultRoutesLoader {
-
- private final MainConfigurationProperties configuration;
-
- public MainRoutesLoader(MainConfigurationProperties configuration) {
- this.configuration = configuration;
- }
-
- @Override
- public void initRoutesBuilderLoader(RoutesBuilderLoader loader) {
- // configure extended routes loader options
- if (loader instanceof ExtendedRoutesBuilderLoader) {
- ExtendedRoutesBuilderLoader ext = (ExtendedRoutesBuilderLoader)
loader;
- if (configuration.getRoutesCompileDirectory() != null) {
-
ext.setCompileDirectory(configuration.getRoutesCompileDirectory());
- }
- ext.setCompileLoadFirst(configuration.isRoutesCompileLoadFirst());
- }
- }
-
-}
diff --git
a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_21.adoc
b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_21.adoc
index 3daccc7622a..664392b68b2 100644
--- a/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_21.adoc
+++ b/docs/user-manual/modules/ROOT/pages/camel-3x-upgrade-guide-3_21.adoc
@@ -87,6 +87,9 @@ For example as shown below for the context health check:
}
----
+=== camel-java-joor-dsl
+
+The `camel-java-joor-dsl` cannot anymore load routes defined in class files as
we consider it no more needed, consequently the ability to configure the
compile directory and the compile load first flag using the corresponding
`camel-main` properties is no longer possible.
=== Deprecated Components
diff --git
a/dsl/camel-dsl-support/src/main/java/org/apache/camel/dsl/support/ExtendedRouteBuilderLoaderSupport.java
b/dsl/camel-dsl-support/src/main/java/org/apache/camel/dsl/support/ExtendedRouteBuilderLoaderSupport.java
index f32d5630ba1..08ce226ea0d 100644
---
a/dsl/camel-dsl-support/src/main/java/org/apache/camel/dsl/support/ExtendedRouteBuilderLoaderSupport.java
+++
b/dsl/camel-dsl-support/src/main/java/org/apache/camel/dsl/support/ExtendedRouteBuilderLoaderSupport.java
@@ -30,9 +30,6 @@ import org.apache.camel.spi.RoutesBuilderLoader;
public abstract class ExtendedRouteBuilderLoaderSupport extends
RouteBuilderLoaderSupport
implements ExtendedRoutesBuilderLoader {
- boolean compileLoadFirst;
- private String compileDirectory;
-
protected ExtendedRouteBuilderLoaderSupport(String extension) {
super(extension);
}
@@ -45,28 +42,7 @@ public abstract class ExtendedRouteBuilderLoaderSupport
extends RouteBuilderLoad
@Override
public Collection<RoutesBuilder> loadRoutesBuilders(Collection<Resource>
resources) throws Exception {
- Collection<RoutesBuilder> answer = doLoadRoutesBuilders(resources);
- return answer;
- }
-
- @Override
- public String getCompileDirectory() {
- return compileDirectory;
- }
-
- @Override
- public void setCompileDirectory(String compileDirectory) {
- this.compileDirectory = compileDirectory;
- }
-
- @Override
- public boolean isCompileLoadFirst() {
- return compileLoadFirst;
- }
-
- @Override
- public void setCompileLoadFirst(boolean compileLoadFirst) {
- this.compileLoadFirst = compileLoadFirst;
+ return doLoadRoutesBuilders(resources);
}
protected abstract Collection<RoutesBuilder>
doLoadRoutesBuilders(Collection<Resource> resources) throws Exception;
diff --git
a/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/ClassRoutesBuilderLoader.java
b/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/ClassRoutesBuilderLoader.java
deleted file mode 100644
index eb8b17a0423..00000000000
---
a/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/ClassRoutesBuilderLoader.java
+++ /dev/null
@@ -1,103 +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.java.joor;
-
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.LinkedHashMap;
-import java.util.Map;
-
-import org.apache.camel.CamelContextAware;
-import org.apache.camel.RoutesBuilder;
-import org.apache.camel.api.management.ManagedResource;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.dsl.support.ExtendedRouteBuilderLoaderSupport;
-import org.apache.camel.spi.CompilePostProcessor;
-import org.apache.camel.spi.Resource;
-import org.apache.camel.spi.ResourceAware;
-import org.apache.camel.spi.annotations.RoutesLoader;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static org.apache.camel.dsl.java.joor.Helper.asClassName;
-
-@ManagedResource(description = "Managed ClassRoutesBuilderLoader")
-@RoutesLoader(ClassRoutesBuilderLoader.EXTENSION)
-public class ClassRoutesBuilderLoader extends
ExtendedRouteBuilderLoaderSupport {
-
- public static final String EXTENSION = "class";
-
- private static final Logger LOG =
LoggerFactory.getLogger(ClassRoutesBuilderLoader.class);
-
- public ClassRoutesBuilderLoader() {
- super(EXTENSION);
- }
-
- @Override
- protected Collection<RoutesBuilder>
doLoadRoutesBuilders(Collection<Resource> resources) throws Exception {
- Collection<RoutesBuilder> answer = new ArrayList<>();
-
- LOG.debug("Loading .class resources from: {}", resources);
-
- // load all the byte code first from the resources
- Map<String, byte[]> byteCodes = new LinkedHashMap<>();
- for (Resource res : resources) {
- String className = asClassName(res);
- InputStream is = res.getInputStream(); // load resource as-is
- if (is != null) {
- byte[] code = is.readAllBytes();
- byteCodes.put(className, code);
- }
- }
-
- ByteArrayClassLoader cl = new ByteArrayClassLoader(byteCodes);
-
- // instantiate classes from the byte codes
- for (Resource res : resources) {
- String className = asClassName(res);
- Class<?> clazz = cl.findClass(className);
-
- Object obj;
- try {
- // requires a default no-arg constructor otherwise we skip the
class
- obj = getCamelContext().getInjector().newInstance(clazz);
- } catch (Exception e) {
- LOG.debug("Loaded class {} must have a default no-arg
constructor. Skipping.", className);
- continue;
- }
-
- // inject context and resource
- CamelContextAware.trySetCamelContext(obj, getCamelContext());
- ResourceAware.trySetResource(obj, res);
-
- // support custom annotation scanning post compilation
- // such as to register custom beans, type converters, etc.
- for (CompilePostProcessor pre : getCompilePostProcessors()) {
- // do not pass in byte code as we do not need to write to disk
again
- pre.postCompile(getCamelContext(), className, clazz, null,
obj);
- }
-
- if (obj instanceof RouteBuilder) {
- RouteBuilder builder = (RouteBuilder) obj;
- answer.add(builder);
- }
- }
-
- return answer;
- }
-}
diff --git
a/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/JavaRoutesBuilderLoader.java
b/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/JavaRoutesBuilderLoader.java
index bcd686b5f9a..a0c9e1e8abb 100644
---
a/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/JavaRoutesBuilderLoader.java
+++
b/dsl/camel-java-joor-dsl/src/main/java/org/apache/camel/dsl/java/joor/JavaRoutesBuilderLoader.java
@@ -16,12 +16,9 @@
*/
package org.apache.camel.dsl.java.joor;
-import java.io.File;
import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
import java.io.InputStream;
import java.lang.reflect.Modifier;
-import java.nio.file.Files;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashMap;
@@ -30,18 +27,15 @@ import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
-import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.RoutesBuilder;
import org.apache.camel.RuntimeCamelException;
import org.apache.camel.api.management.ManagedResource;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.dsl.support.ExtendedRouteBuilderLoaderSupport;
import org.apache.camel.spi.CompilePostProcessor;
-import org.apache.camel.spi.ExtendedRoutesBuilderLoader;
import org.apache.camel.spi.Resource;
import org.apache.camel.spi.ResourceAware;
import org.apache.camel.spi.annotations.RoutesLoader;
-import org.apache.camel.support.ResourceHelper;
import org.apache.camel.support.RouteWatcherReloadStrategy;
import org.apache.camel.util.IOHelper;
import org.apache.camel.util.ObjectHelper;
@@ -107,14 +101,6 @@ public class JavaRoutesBuilderLoader extends
ExtendedRouteBuilderLoaderSupport {
}
}
- if (getCompileDirectory() != null && isCompileLoadFirst()) {
- resources = doLoadCompiledFirst(nameToResource, answer);
- if (resources.isEmpty()) {
- // all resources are loaded from pre-compiled
- return answer;
- }
- }
-
LOG.debug("Compiling unit: {}", unit);
CompilationUnit.Result result = MultiCompile.compileUnit(unit);
@@ -149,13 +135,6 @@ public class JavaRoutesBuilderLoader extends
ExtendedRouteBuilderLoaderSupport {
}
}
- if (getCompileDirectory() != null) {
- byte[] byteCode = result.getByteCode(className);
- if (byteCode != null) {
- saveByteCodeToDisk(getCompileDirectory(), className,
byteCode);
- }
- }
-
// support custom annotation scanning post compilation
// such as to register custom beans, type converters, etc.
for (CompilePostProcessor pre : getCompilePostProcessors()) {
@@ -172,51 +151,4 @@ public class JavaRoutesBuilderLoader extends
ExtendedRouteBuilderLoaderSupport {
return answer;
}
- private Collection<Resource> doLoadCompiledFirst(Map<String, Resource>
nameToResource, Collection<RoutesBuilder> answer)
- throws Exception {
- // look for existing compiled and load them first, and any that are
missing is to be compiled
- Collection<Resource> toBeCompiled = new ArrayList<>();
-
- Collection<Resource> byteCodes = new ArrayList<>();
- for (var entry : nameToResource.entrySet()) {
- final String className = entry.getKey();
-
- File source = new File(getCompileDirectory(), className +
".class");
- if (source.exists()) {
- byte[] code = Files.readAllBytes(source.toPath());
- byteCodes.add(ResourceHelper.fromBytes("class:" + className +
".class", code));
- } else {
- final Resource resource = entry.getValue();
- toBeCompiled.add(resource);
- }
- }
- if (!byteCodes.isEmpty()) {
- // use the loader that can load from class byte codes
- ExtendedRoutesBuilderLoader loader
- = (ExtendedRoutesBuilderLoader)
getCamelContext().adapt(ExtendedCamelContext.class)
- .getRoutesLoader().getRoutesLoader("class");
- Collection<RoutesBuilder> loaded =
loader.loadRoutesBuilders(byteCodes);
- answer.addAll(loaded);
- }
-
- return toBeCompiled;
- }
-
- private static void saveByteCodeToDisk(String outputDirectory, String
name, byte[] byteCode) {
- // write to disk (can be triggered multiple times so only write once)
- File target = new File(outputDirectory, name + ".class");
- if (!target.exists()) {
- // create work-dir if needed
- new File(outputDirectory).mkdirs();
- try {
- try (FileOutputStream fos = new FileOutputStream(target)) {
- LOG.debug("Writing compiled class: {} as bytecode to file:
{}", name, target);
- fos.write(byteCode);
- }
- } catch (Exception e) {
- LOG.warn("Error saving compiled class: {} as bytecode to file:
{} due to {}", name, target, e.getMessage());
- }
- }
- }
-
}
diff --git
a/dsl/camel-java-joor-dsl/src/test/java/org/apache/camel/dsl/java/joor/ClassRoutesBuilderLoaderTest.java
b/dsl/camel-java-joor-dsl/src/test/java/org/apache/camel/dsl/java/joor/ClassRoutesBuilderLoaderTest.java
deleted file mode 100644
index c0d9cfbbe4a..00000000000
---
a/dsl/camel-java-joor-dsl/src/test/java/org/apache/camel/dsl/java/joor/ClassRoutesBuilderLoaderTest.java
+++ /dev/null
@@ -1,69 +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.java.joor;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collection;
-
-import org.apache.camel.RoutesBuilder;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.model.ToDefinition;
-import org.apache.camel.spi.Resource;
-import org.apache.camel.support.ResourceSupport;
-import org.assertj.core.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-
-public class ClassRoutesBuilderLoaderTest {
-
- @Test
- void testLoadRoutes() throws Exception {
- try (DefaultCamelContext context = new DefaultCamelContext()) {
- Resource resource = new ResourceSupport("class",
"org/apache/camel/dsl/java/joor/DummyRoute.class") {
- @Override
- public boolean exists() {
- return true;
- }
-
- @Override
- public InputStream getInputStream() throws IOException {
- return ClassRoutesBuilderLoaderTest.class
-
.getResourceAsStream("/org/apache/camel/dsl/java/joor/DummyRoute.class");
- }
- };
- Collection<RoutesBuilder> builders =
context.getRoutesLoader().findRoutesBuilders(resource);
-
- assertThat(builders).hasSize(1);
-
- RouteBuilder builder = (RouteBuilder) builders.iterator().next();
- builder.setCamelContext(context);
- builder.configure();
-
- Assertions.assertThat(builder.getRouteCollection().getRoutes())
- .hasSize(1)
- .first()
- .satisfies(rd -> {
-
Assertions.assertThat(rd.getInput().getEndpointUri()).matches("direct:dummy");
-
Assertions.assertThat(rd.getOutputs().get(0)).isInstanceOf(ToDefinition.class);
- });
- }
- }
-
-}
diff --git
a/dsl/camel-java-joor-dsl/src/test/java/org/apache/camel/dsl/java/joor/JavaJoorCaptureByteCodeTest.java
b/dsl/camel-java-joor-dsl/src/test/java/org/apache/camel/dsl/java/joor/JavaJoorCaptureByteCodeTest.java
deleted file mode 100644
index f7ed873a806..00000000000
---
a/dsl/camel-java-joor-dsl/src/test/java/org/apache/camel/dsl/java/joor/JavaJoorCaptureByteCodeTest.java
+++ /dev/null
@@ -1,114 +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.java.joor;
-
-import java.io.ByteArrayInputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Collection;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.ProducerTemplate;
-import org.apache.camel.RoutesBuilder;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.spi.CompilePostProcessor;
-import org.apache.camel.spi.Resource;
-import org.apache.camel.support.ResourceSupport;
-import org.junit.jupiter.api.Test;
-
-import static org.assertj.core.api.Assertions.assertThat;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
-public class JavaJoorCaptureByteCodeTest {
-
- private final MyPostCompiler postCompiler = new MyPostCompiler();
-
- @Test
- public void testCaptureByteCode() throws Exception {
- try (DefaultCamelContext context = new DefaultCamelContext()) {
- context.getRegistry().bind("MyPostCompiler", postCompiler);
- context.start();
-
- Resource resource =
context.getResourceLoader().resolveResource("/routes/MyMockRoute.java");
- Collection<RoutesBuilder> builders =
context.getRoutesLoader().findRoutesBuilders(resource);
-
- assertThat(builders).hasSize(1);
-
- RouteBuilder builder = (RouteBuilder) builders.iterator().next();
- builder.setCamelContext(context);
- builder.configure();
-
- assertEquals("MyMockRoute", postCompiler.getName());
- assertNotNull(postCompiler.getCode());
- }
-
- // load the route (its byte code) from another context
-
- try (DefaultCamelContext context = new DefaultCamelContext()) {
- context.start();
-
- Resource res = new ResourceSupport("class", "MyMockRoute.class") {
- @Override
- public boolean exists() {
- return true;
- }
-
- @Override
- public InputStream getInputStream() throws IOException {
- return new ByteArrayInputStream(postCompiler.getCode());
- }
- };
-
- Collection<RoutesBuilder> builders =
context.getRoutesLoader().findRoutesBuilders(res);
- assertThat(builders).hasSize(1);
-
- RouteBuilder builder = (RouteBuilder) builders.iterator().next();
- builder.setCamelContext(context);
- context.addRoutes(builder);
-
- MockEndpoint mock = context.getEndpoint("mock:result",
MockEndpoint.class);
- mock.expectedBodiesReceived("Hello ByteCode");
- ProducerTemplate template = context.createProducerTemplate();
- template.sendBody("direct:start", "Hello ByteCode");
- mock.assertIsSatisfied();
- }
- }
-
- private static final class MyPostCompiler implements CompilePostProcessor {
-
- private String name;
- private byte[] code;
-
- @Override
- public void postCompile(CamelContext camelContext, String name,
Class<?> clazz, byte[] byteCode, Object instance)
- throws Exception {
- this.name = name;
- this.code = byteCode;
- }
-
- public String getName() {
- return name;
- }
-
- public byte[] getCode() {
- return code;
- }
- }
-}
diff --git
a/dsl/camel-java-joor-dsl/src/test/java/org/apache/camel/dsl/java/joor/JavaJoorSaveToDiskTest.java
b/dsl/camel-java-joor-dsl/src/test/java/org/apache/camel/dsl/java/joor/JavaJoorSaveToDiskTest.java
deleted file mode 100644
index d2e95513ec9..00000000000
---
a/dsl/camel-java-joor-dsl/src/test/java/org/apache/camel/dsl/java/joor/JavaJoorSaveToDiskTest.java
+++ /dev/null
@@ -1,71 +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.java.joor;
-
-import java.io.File;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.impl.DefaultCamelContext;
-import org.apache.camel.spi.Resource;
-import org.apache.camel.util.FileUtil;
-import org.junit.jupiter.api.Assertions;
-import org.junit.jupiter.api.Test;
-
-public class JavaJoorSaveToDiskTest {
-
- @Test
- public void testSaveToDisk() throws Exception {
- FileUtil.removeDir(new File("target/compiled"));
-
- try (DefaultCamelContext context = new DefaultCamelContext()) {
- context.start();
-
- JavaRoutesBuilderLoader loader = new JavaRoutesBuilderLoader();
- loader.setCamelContext(context);
- loader.setCompileDirectory("target/compiled");
- loader.start();
-
- Resource resource =
context.getResourceLoader().resolveResource("/routes/MyMockRoute.java");
- RouteBuilder builder = (RouteBuilder)
loader.loadRoutesBuilder(resource);
-
- builder.setCamelContext(context);
- builder.configure();
- }
-
- // should have saved to disk
- Assertions.assertTrue(new
File("target/compiled/MyMockRoute.class").exists());
-
- // should be able to load from disk
- try (DefaultCamelContext context = new DefaultCamelContext()) {
- context.start();
-
- JavaRoutesBuilderLoader loader = new JavaRoutesBuilderLoader();
- loader.setCamelContext(context);
- loader.setCompileDirectory("target/compiled");
- loader.setCompileLoadFirst(true);
- loader.start();
-
- Resource resource =
context.getResourceLoader().resolveResource("/routes/MyMockRoute.java");
- RouteBuilder builder = (RouteBuilder)
loader.loadRoutesBuilder(resource);
-
- builder.setCamelContext(context);
- builder.configure();
- }
-
- }
-
-}
diff --git
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
index df29d50d8fb..d28a5bc67ff 100644
---
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
+++
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/KameletMain.java
@@ -488,7 +488,7 @@ public class KameletMain extends MainCommandLineSupport {
if (download) {
// use resolvers that can auto downloaded
camelContext.adapt(ExtendedCamelContext.class)
- .setRoutesLoader(new
DependencyDownloaderRoutesLoader(camelContext, configure()));
+ .setRoutesLoader(new
DependencyDownloaderRoutesLoader(camelContext));
} else {
super.configureRoutesLoader(camelContext);
}
diff --git
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderRoutesLoader.java
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderRoutesLoader.java
index f2173a3e5bb..fe0272d829a 100644
---
a/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderRoutesLoader.java
+++
b/dsl/camel-kamelet-main/src/main/java/org/apache/camel/main/download/DependencyDownloaderRoutesLoader.java
@@ -20,8 +20,7 @@ import org.apache.camel.CamelContext;
import org.apache.camel.CamelContextAware;
import org.apache.camel.ExtendedCamelContext;
import org.apache.camel.dsl.yaml.KameletRoutesBuilderLoader;
-import org.apache.camel.main.MainConfigurationProperties;
-import org.apache.camel.main.MainRoutesLoader;
+import org.apache.camel.impl.engine.DefaultRoutesLoader;
import org.apache.camel.spi.FactoryFinder;
import org.apache.camel.spi.RoutesBuilderLoader;
import org.apache.camel.support.ResolverHelper;
@@ -30,12 +29,11 @@ import org.apache.camel.support.service.ServiceHelper;
/**
* Auto downloaded needed DSL JARs.
*/
-public class DependencyDownloaderRoutesLoader extends MainRoutesLoader {
+public class DependencyDownloaderRoutesLoader extends DefaultRoutesLoader {
private final DependencyDownloader downloader;
- public DependencyDownloaderRoutesLoader(CamelContext camelContext,
MainConfigurationProperties configuration) {
- super(configuration);
+ public DependencyDownloaderRoutesLoader(CamelContext camelContext) {
setCamelContext(camelContext);
this.downloader = camelContext.hasService(DependencyDownloader.class);
}