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 2022/04/11 17:52:41 UTC
[camel] branch main updated: CAMEL-17927: camel-jbang - Run from github does not work
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 913a5f1837b CAMEL-17927: camel-jbang - Run from github does not work
913a5f1837b is described below
commit 913a5f1837b70aaa9f7341bb32a8543234847d97
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Mon Apr 11 19:52:20 2022 +0200
CAMEL-17927: camel-jbang - Run from github does not work
---
.../org/apache/camel/main/BaseMainSupport.java | 40 +++++++++++-----------
.../apache/camel/dsl/modeline/ModelineParser.java | 14 ++++----
.../apache/camel/dsl/jbang/core/commands/Run.java | 15 ++++++--
3 files changed, 40 insertions(+), 29 deletions(-)
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 c18caaf037f..0cf744ed4da 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
@@ -433,25 +433,25 @@ public abstract class BaseMainSupport extends BaseService {
MainHelper::optionKey);
Object value = prop.remove("camel.main.startupRecorder");
- if (value != null) {
+ if (ObjectHelper.isNotEmpty(value)) {
mainConfigurationProperties.setStartupRecorder(value.toString());
}
value = prop.remove("camel.main.startupRecorderRecording");
- if (value != null) {
+ if (ObjectHelper.isNotEmpty(value)) {
mainConfigurationProperties.setStartupRecorderRecording("true".equalsIgnoreCase(value.toString()));
}
value = prop.remove("camel.main.startupRecorderProfile");
- if (value != null) {
+ if (ObjectHelper.isNotEmpty(value)) {
mainConfigurationProperties.setStartupRecorderProfile(
CamelContextHelper.parseText(camelContext, value.toString()));
}
value = prop.remove("camel.main.startupRecorderDuration");
- if (value != null) {
+ if (ObjectHelper.isNotEmpty(value)) {
mainConfigurationProperties.setStartupRecorderDuration(Long.parseLong(value.toString()));
}
value = prop.remove("camel.main.startupRecorderMaxDepth");
- if (value != null) {
+ if (ObjectHelper.isNotEmpty(value)) {
mainConfigurationProperties.setStartupRecorderMaxDepth(Integer.parseInt(value.toString()));
}
@@ -600,7 +600,7 @@ public abstract class BaseMainSupport extends BaseService {
// special for environment-variable-enabled as we need to know this early before we set all the other options
Object envEnabled = prop.remove("camel.main.autoConfigurationEnvironmentVariablesEnabled");
- if (envEnabled != null) {
+ if (ObjectHelper.isNotEmpty(envEnabled)) {
mainConfigurationProperties.setAutoConfigurationEnvironmentVariablesEnabled(
CamelContextHelper.parseBoolean(camelContext, envEnabled.toString()));
String loc = prop.getLocation("camel.main.autoConfigurationEnvironmentVariablesEnabled");
@@ -609,7 +609,7 @@ public abstract class BaseMainSupport extends BaseService {
}
// special for system-properties-enabled as we need to know this early before we set all the other options
Object jvmEnabled = prop.remove("camel.main.autoConfigurationSystemPropertiesEnabled");
- if (jvmEnabled != null) {
+ if (ObjectHelper.isNotEmpty(jvmEnabled)) {
mainConfigurationProperties.setAutoConfigurationSystemPropertiesEnabled(
CamelContextHelper.parseBoolean(camelContext, jvmEnabled.toString()));
String loc = prop.getLocation("camel.main.autoConfigurationSystemPropertiesEnabled");
@@ -645,21 +645,21 @@ public abstract class BaseMainSupport extends BaseService {
// special for fail-fast as we need to know this early before we set all the other options
String loc = "ENV";
Object failFast = propENV != null ? propENV.remove("camel.main.autoconfigurationfailfast") : null;
- if (propJVM != null) {
+ if (ObjectHelper.isNotEmpty(propJVM)) {
Object val = propJVM.remove("camel.main.autoconfigurationfailfast");
- if (val != null) {
+ if (ObjectHelper.isNotEmpty(val)) {
loc = "SYS";
failFast = val;
}
}
- if (failFast != null) {
+ if (ObjectHelper.isNotEmpty(failFast)) {
mainConfigurationProperties
.setAutoConfigurationFailFast(CamelContextHelper.parseBoolean(camelContext, failFast.toString()));
autoConfiguredProperties.put(loc, "camel.main.autoConfigurationFailFast", failFast.toString());
} else {
loc = prop.getLocation("camel.main.autoConfigurationFailFast");
failFast = prop.remove("camel.main.autoConfigurationFailFast");
- if (failFast != null) {
+ if (ObjectHelper.isNotEmpty(failFast)) {
mainConfigurationProperties
.setAutoConfigurationFailFast(CamelContextHelper.parseBoolean(camelContext, failFast.toString()));
autoConfiguredProperties.put(loc, "camel.main.autoConfigurationFailFast", failFast.toString());
@@ -671,7 +671,7 @@ public abstract class BaseMainSupport extends BaseService {
CamelContext camelContext, OrderedLocationProperties autoConfiguredProperties) {
Object pattern = getInitialProperties().getProperty("camel.main.routesIncludePattern");
- if (pattern != null) {
+ if (ObjectHelper.isNotEmpty(pattern)) {
mainConfigurationProperties
.setRoutesIncludePattern(CamelContextHelper.parseText(camelContext, pattern.toString()));
autoConfiguredProperties.put("initial", "camel.main.routesIncludePattern", pattern.toString());
@@ -688,7 +688,7 @@ public abstract class BaseMainSupport extends BaseService {
// special for environment-variable-enabled as we need to know this early before we set all the other options
String loc = prop.getLocation("camel.main.routesIncludePattern");
pattern = prop.remove("camel.main.routesIncludePattern");
- if (pattern != null) {
+ if (ObjectHelper.isNotEmpty(pattern)) {
mainConfigurationProperties.setRoutesIncludePattern(
CamelContextHelper.parseText(camelContext, pattern.toString()));
autoConfiguredProperties.put(loc, "camel.main.routesIncludePattern",
@@ -697,7 +697,7 @@ public abstract class BaseMainSupport extends BaseService {
// special for system-properties-enabled as we need to know this early before we set all the other options
loc = prop.getLocation("camel.main.routesIncludePattern");
Object jvmEnabled = prop.remove("camel.main.routesIncludePattern");
- if (jvmEnabled != null) {
+ if (ObjectHelper.isNotEmpty(jvmEnabled)) {
mainConfigurationProperties.setRoutesIncludePattern(
CamelContextHelper.parseText(camelContext, jvmEnabled.toString()));
autoConfiguredProperties.put(loc, "camel.main.routesIncludePattern",
@@ -732,21 +732,21 @@ public abstract class BaseMainSupport extends BaseService {
// special for fail-fast as we need to know this early before we set all the other options
loc = "ENV";
pattern = propENV != null ? propENV.remove("camel.main.routesincludepattern") : null;
- if (propJVM != null) {
+ if (ObjectHelper.isNotEmpty(propJVM)) {
Object val = propJVM.remove("camel.main.routesincludepattern");
- if (val != null) {
+ if (ObjectHelper.isNotEmpty(val)) {
loc = "SYS";
pattern = val;
}
}
- if (pattern != null) {
+ if (ObjectHelper.isNotEmpty(pattern)) {
mainConfigurationProperties
.setRoutesIncludePattern(CamelContextHelper.parseText(camelContext, pattern.toString()));
autoConfiguredProperties.put(loc, "camel.main.routesIncludePattern", pattern.toString());
} else {
loc = prop.getLocation("camel.main.routesIncludePattern");
pattern = prop.remove("camel.main.routesIncludePattern");
- if (pattern != null) {
+ if (ObjectHelper.isNotEmpty(pattern)) {
mainConfigurationProperties
.setRoutesIncludePattern(CamelContextHelper.parseText(camelContext, pattern.toString()));
autoConfiguredProperties.put(loc, "camel.main.routesIncludePattern", pattern.toString());
@@ -762,7 +762,7 @@ public abstract class BaseMainSupport extends BaseService {
OrderedLocationProperties autoConfiguredProperties)
throws Exception {
- if (config.getFileConfigurations() != null) {
+ if (ObjectHelper.isNotEmpty(config.getFileConfigurations())) {
String[] locs = config.getFileConfigurations().split(",");
for (String loc : locs) {
String path = FileUtil.onlyPath(loc);
@@ -1143,7 +1143,7 @@ public abstract class BaseMainSupport extends BaseService {
throws Exception {
Object obj = lraProperties.remove("enabled");
- if (obj != null) {
+ if (ObjectHelper.isNotEmpty(obj)) {
String loc = lraProperties.getLocation("enabled");
autoConfiguredProperties.put(loc, "camel.lra.enabled", obj.toString());
}
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 3345400cc01..24a8b9065c0 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
@@ -56,12 +56,14 @@ public class ModelineParser {
public List<CamelContextCustomizer> parse(Resource resource) throws Exception {
List<CamelContextCustomizer> answer = new ArrayList<>();
- 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();
+ 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();
+ }
}
}
diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
index 9e2e0ce2e74..c68bdae82e0 100644
--- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
+++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java
@@ -308,7 +308,9 @@ class Run implements Callable<Integer> {
sjReload.add(file.substring(5));
}
}
- main.addInitialProperty("camel.main.routesIncludePattern", js.toString());
+ if (js.length() > 0) {
+ main.addInitialProperty("camel.main.routesIncludePattern", js.toString());
+ }
if (sjClasspathFiles.length() > 0) {
main.addInitialProperty("camel.jbang.classpathFiles", sjClasspathFiles.toString());
}
@@ -371,9 +373,11 @@ class Run implements Callable<Integer> {
// strip https://github.com/
url = url.substring(19);
// https://github.com/apache/camel-k/blob/main/examples/languages/routes.kts
- // https://github.com/apache/camel-k/blob/v1.7.0/examples/languages/routes.kts
+ // https://raw.githubusercontent.com/apache/camel-kamelets-examples/main/jbang/hello-java/Hey.java
+ // https://github.com/apache/camel-kamelets-examples/blob/main/jbang/hello-java/Hey.java
url = url.replaceFirst("/", ":");
url = url.replaceFirst("/", ":");
+ url = url.replaceFirst("tree/", "");
url = url.replaceFirst("blob/", "");
url = url.replaceFirst("/", ":");
return "github:" + url;
@@ -465,7 +469,12 @@ class Run implements Callable<Integer> {
private boolean knownFile(String file) {
String ext = FileUtil.onlyExt(file, true);
- return Arrays.stream(ACCEPTED_FILE_EXT).anyMatch(e -> e.equalsIgnoreCase(ext));
+ if (ext != null) {
+ return Arrays.stream(ACCEPTED_FILE_EXT).anyMatch(e -> e.equalsIgnoreCase(ext));
+ } else {
+ // assume match as it can be wildcard or dir
+ return true;
+ }
}
}