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 d8af2269ed21 CAMEL-26930: camel-jbang - the profile properties are
read next to application.properties, and the clipboard is written to the work
directory (#29981)
d8af2269ed21 is described below
commit d8af2269ed21b2490f407cd415cfac63dba4db31
Author: Claus Ibsen <[email protected]>
AuthorDate: Sun Nov 15 10:00:23 2026 +0100
CAMEL-26930: camel-jbang - the profile properties are read next to
application.properties, and the clipboard is written to the work directory
(#29981)
Two points of item 7 of
[CAMEL-26930](https://issues.apache.org/jira/browse/CAMEL-26930) that were
found by reading the code: where camel run reads and writes files.
## The profile properties
`RunProfileProperties.load` read `application.properties` from the folder
of the files (or the source directory), but `application-<profile>.properties`
from the current directory. So `camel run other/route.camel.yaml
--profile=dev`, or a run of an example, took `application.properties` from
there and the profile from here (and a profile file of the current directory
into another project). It is now read next to `application.properties`, as
`RunPipeline` already adds it to the files o [...]
The golden case `profile` (`--profile=dev`, with `camel.jbang.dependencies`
in both files) shows it: the test runs from the module folder, so the profile
file was not found, and the export had the dependencies of both files. Run from
inside the folder, the profile was read and its
`camel.jbang.dependencies=camel:kafka` overrode `camel:http`, as it does now
from anywhere:
```
-camel.jbang.dependencies=camel\:http,camel\:kafka
-dependency=mvn\:org.apache.camel\:camel-http\:${camel.version}
+camel.jbang.dependencies=camel\:kafka
```
## The clipboard
`camel run clipboard.java` with a Java class in the clipboard wrote
`<Class>.java` into the current directory, over a file of that name; the other
clipboard files go to the work directory (`.camel-jbang/work`). The class now
goes there too, still under its class name, so it compiles.
## Tests
- `RunProfilePropertiesTest` (new): the profile is read next to
`application.properties` (it fails without the fix), and the profile of a
source directory.
- `RunClipboardFileTest` (new): a Java class is `<work>/<Class>.java`,
without its package; other files are `<work>/generated-clipboard.<ext>`.
- The golden `profile.export.txt`, as above.
- camel-jbang-run: 321 pass. camel-jbang-core: 3071 + 264 pass.
Co-Authored-By: Claude Opus 5.5 <[email protected]>
---
.../apache/camel/dsl/jbang/core/commands/Run.java | 26 +++++----
.../jbang/core/commands/RunClipboardFileTest.java | 43 +++++++++++++++
.../resources/golden/expected/profile.export.txt | 3 +-
.../camel/dsl/jbang/run/RunProfileProperties.java | 4 +-
.../dsl/jbang/run/RunProfilePropertiesTest.java | 63 ++++++++++++++++++++++
5 files changed, 127 insertions(+), 12 deletions(-)
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 f1c31a7eaffe..e5642261c684 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
@@ -1740,26 +1740,34 @@ public class Run extends CamelCommand implements
CommandLifecycle {
Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard();
Object t = c.getData(DataFlavor.stringFlavor);
if (t != null) {
- String fn = workDir + "/" + CLIPBOARD_GENERATED_FILE + "." + ext;
+ String fqn = null;
if ("java".equals(ext)) {
- String fqn = determineClassName(t.toString());
+ fqn = determineClassName(t.toString());
if (fqn == null) {
// wrap code in wrapper
return loadFromCode(t.toString(), "ClipboardRoute", true);
}
- // drop package in file name
- String cn = fqn;
- if (fqn.contains(".")) {
- cn = cn.substring(cn.lastIndexOf('.') + 1);
- }
- fn = cn + ".java";
}
- Files.writeString(Paths.get(fn), t.toString());
+ Path fn = clipboardFile(workDir, ext, fqn);
+ Files.createDirectories(fn.getParent());
+ Files.writeString(fn, t.toString());
file = "file:" + fn;
}
return file;
}
+ /**
+ * The file the clipboard is written to, in the work directory: a Java
class in a file of its class name (without
+ * the package). The class was written into the current directory, over a
file of that name (CAMEL-26930).
+ */
+ static Path clipboardFile(Path workDir, String ext, String className) {
+ if (className != null) {
+ String simple = className.contains(".") ?
className.substring(className.lastIndexOf('.') + 1) : className;
+ return workDir.resolve(simple + ".java");
+ }
+ return workDir.resolve(CLIPBOARD_GENERATED_FILE + "." + ext);
+ }
+
private boolean isLoggingLevelFromCommandLine() {
try {
return isOptionGiven("--logging-level");
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunClipboardFileTest.java
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunClipboardFileTest.java
new file mode 100644
index 000000000000..8006f38d323f
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/RunClipboardFileTest.java
@@ -0,0 +1,43 @@
+/*
+ * 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.jbang.core.commands;
+
+import java.nio.file.Path;
+
+import org.junit.jupiter.api.Test;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * camel run clipboard.java writes the clipboard into the work directory: a
Java class was written into the current
+ * directory, over a file of that name (CAMEL-26930).
+ */
+class RunClipboardFileTest {
+
+ private final Path work = Path.of(".camel-jbang", "work");
+
+ @Test
+ void aJavaClassIsInTheWorkDirectoryUnderItsClassName() {
+ assertThat(Run.clipboardFile(work, "java",
"com.acme.OrderRoute")).isEqualTo(work.resolve("OrderRoute.java"));
+ assertThat(Run.clipboardFile(work, "java",
"OrderRoute")).isEqualTo(work.resolve("OrderRoute.java"));
+ }
+
+ @Test
+ void otherFilesAreInTheWorkDirectory() {
+ assertThat(Run.clipboardFile(work, "yaml",
null)).isEqualTo(work.resolve("generated-clipboard.yaml"));
+ }
+}
diff --git
a/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/expected/profile.export.txt
b/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/expected/profile.export.txt
index a5459397ff5c..9568ad206bc6 100644
---
a/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/expected/profile.export.txt
+++
b/dsl/camel-jbang/camel-jbang-core/src/test/resources/golden/expected/profile.export.txt
@@ -16,8 +16,7 @@ camel.jbang.javaVersion=21
camel.jbang.kameletsVersion=${kamelets.version}
camel.main.routesIncludePattern=file\:src/test/resources/golden/profile/route.camel.yaml
camel.component.properties.location=file\:src/test/resources/golden/profile/application-dev.properties,file\:src/test/resources/golden/profile/application.properties
-camel.jbang.dependencies=camel\:http,camel\:kafka
-dependency=mvn\:org.apache.camel\:camel-http\:${camel.version}
+camel.jbang.dependencies=camel\:kafka
dependency=mvn\:org.apache.camel\:camel-kafka\:${camel.version}
dependency=mvn\:org.apache.camel\:camel-kamelet\:${camel.version}
dependency=mvn\:org.apache.camel.kamelets\:camel-kamelets\:${kamelets.version}
diff --git
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/RunProfileProperties.java
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/RunProfileProperties.java
index 8ca91446a342..6a7b40ac8bb2 100644
---
a/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/RunProfileProperties.java
+++
b/dsl/camel-jbang/camel-jbang-run/src/main/java/org/apache/camel/dsl/jbang/run/RunProfileProperties.java
@@ -85,7 +85,9 @@ public final class RunProfileProperties {
if (sourceDir != null) {
profilePropertiesPath =
Paths.get(sourceDir).resolve("application-" + profile + ".properties");
} else {
- profilePropertiesPath = Paths.get("application-" + profile +
".properties");
+ // next to application.properties: the current directory was
read, so a run of the files of another
+ // folder took application.properties from there and the
profile from here (CAMEL-26930)
+ profilePropertiesPath = baseDir.resolve("application-" +
profile + ".properties");
}
// application-profile.properties should override standard
application.properties
Properties override = loadExisting(profilePropertiesPath,
loadedFiles, eachFile);
diff --git
a/dsl/camel-jbang/camel-jbang-run/src/test/java/org/apache/camel/dsl/jbang/run/RunProfilePropertiesTest.java
b/dsl/camel-jbang/camel-jbang-run/src/test/java/org/apache/camel/dsl/jbang/run/RunProfilePropertiesTest.java
new file mode 100644
index 000000000000..bfa63425f045
--- /dev/null
+++
b/dsl/camel-jbang/camel-jbang-run/src/test/java/org/apache/camel/dsl/jbang/run/RunProfilePropertiesTest.java
@@ -0,0 +1,63 @@
+/*
+ * 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.jbang.run;
+
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.util.LinkedHashSet;
+import java.util.Properties;
+import java.util.Set;
+
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+/**
+ * The application properties of a run, and the ones of its profile.
+ */
+class RunProfilePropertiesTest {
+
+ @TempDir
+ Path dir;
+
+ @Test
+ void theProfileIsReadNextToApplicationProperties() throws Exception {
+ // the profile was read from the current directory, not from the
folder of the files (CAMEL-26930)
+ Files.writeString(dir.resolve("application.properties"),
"greeting=hello\nport=8080\n");
+ Files.writeString(dir.resolve("application-dev.properties"),
"greeting=dev\n");
+ Set<Path> loaded = new LinkedHashSet<>();
+
+ Properties properties = RunProfileProperties.load(dir, null, "dev",
loaded, p -> {
+ });
+
+ assertThat(properties).containsEntry("greeting",
"dev").containsEntry("port", "8080");
+
assertThat(loaded).containsExactly(dir.resolve("application.properties"),
+ dir.resolve("application-dev.properties"));
+ }
+
+ @Test
+ void theProfileOfASourceDirectory() throws Exception {
+ Files.writeString(dir.resolve("application-dev.properties"),
"greeting=dev\n");
+
+ Properties properties = RunProfileProperties.load(Path.of("."),
dir.toString(), "dev", new LinkedHashSet<>(),
+ p -> {
+ });
+
+ assertThat(properties).containsEntry("greeting", "dev");
+ }
+}