You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2021/12/14 06:45:01 UTC
[camel] branch camel-3.14.x updated: CAMEL-17310: Reload routes should match resources that are the same when loaded via classpath or file scheme. mvn camel:dev now works.
This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch camel-3.14.x
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-3.14.x by this push:
new 0694e50 CAMEL-17310: Reload routes should match resources that are the same when loaded via classpath or file scheme. mvn camel:dev now works.
0694e50 is described below
commit 0694e504967d17dbbb32c64688377b6f27ad0df7
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Tue Dec 14 07:42:17 2021 +0100
CAMEL-17310: Reload routes should match resources that are the same when loaded via classpath or file scheme. mvn camel:dev now works.
---
.../camel/support/RouteWatcherReloadStrategy.java | 26 +++++++++++++++++++++-
.../main/java/org/apache/camel/maven/DevMojo.java | 18 ++++++++++-----
2 files changed, 37 insertions(+), 7 deletions(-)
diff --git a/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java b/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
index f2d84be..0b1b204 100644
--- a/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
+++ b/core/camel-support/src/main/java/org/apache/camel/support/RouteWatcherReloadStrategy.java
@@ -17,6 +17,7 @@
package org.apache.camel.support;
import java.io.File;
+import java.net.URI;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
@@ -156,7 +157,7 @@ public class RouteWatcherReloadStrategy extends FileWatcherResourceReloadStrateg
// remember all the sources of the current routes (except the updated)
getCamelContext().getRoutes().forEach(r -> {
Resource rs = r.getSourceResource();
- if (rs != null && (resource == null || !rs.getLocation().equals(resource.getLocation()))) {
+ if (rs != null && !equalResourceLocation(resource, rs)) {
sources.add(rs);
}
});
@@ -230,4 +231,27 @@ public class RouteWatcherReloadStrategy extends FileWatcherResourceReloadStrateg
}
}
+ /**
+ * Whether the two resources are loading the same resource
+ */
+ private static boolean equalResourceLocation(Resource source, Resource target) {
+ if (source == null || target == null) {
+ return false;
+ }
+
+ // use URI to match as file/classpath resources may refer to the same uri
+ URI u1 = source.getURI();
+ URI u2 = target.getURI();
+ boolean answer = u1.equals(u2);
+ if (!answer) {
+ // file and classpath may refer to the same when they have src/main/resources && target/classes
+ String s1 = u1.toString().replace("src/main/resources/", "").replace("src/test/resources/", "")
+ .replace("target/classes/", "");
+ String s2 = u2.toString().replace("src/main/resources/", "").replace("src/test/resources/", "")
+ .replace("target/classes/", "");
+ answer = s1.equals(s2);
+ }
+ return answer;
+ }
+
}
diff --git a/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DevMojo.java b/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DevMojo.java
index e34613a..ffa8086 100644
--- a/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DevMojo.java
+++ b/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/DevMojo.java
@@ -16,6 +16,8 @@
*/
package org.apache.camel.maven;
+import java.io.File;
+
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
@@ -38,16 +40,20 @@ public class DevMojo extends RunMojo {
*/
@Override
protected void beforeBootstrapCamel() throws Exception {
- String routesReloadDirectory = "src/main/resources";
-
+ String dir;
if (routesDirectory != null) {
- routesReloadDirectory = routesDirectory;
- } else if (routesDirectory == null && project.getResources().size() == 1) {
- routesReloadDirectory = project.getResources().get(0).getDirectory();
+ dir = routesDirectory;
+ } else if (project.getResources().size() == 1) {
+ dir = project.getResources().get(0).getDirectory();
+ } else {
+ dir = "src/main/resources";
}
+ // use absolute path for dir
+ dir = new File(dir).getAbsolutePath();
+
System.setProperty("camel.main.routesReloadEnabled", "true");
- System.setProperty("camel.main.routesReloadDirectory", routesReloadDirectory);
+ System.setProperty("camel.main.routesReloadDirectory", dir);
System.setProperty("camel.main.routesReloadDirectoryRecursive", "true");
System.setProperty("camel.main.durationMaxAction", "stop");
System.setProperty("camel.main.routesReloadPattern",