diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelCommand.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelCommand.java index 95b70b0979df2..da95a5257e4e7 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelCommand.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelCommand.java @@ -94,6 +94,14 @@ private void replacePlaceholders() throws Exception { public abstract Integer doCall() throws Exception; + protected static String getScheme(String name) { + int pos = name.indexOf(":"); + if (pos != -1) { + return name.substring(0, pos); + } + return null; + } + public Path getStatusFile(String pid) { return CommandLineHelper.getCamelDir().resolve(pid + "-status.json"); } diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyList.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyList.java index 7e23967ef5794..7ff744342599d 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyList.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyList.java @@ -77,10 +77,12 @@ protected Integer export() throws Exception { // special if user type: camel run . or camel run dirName if (files != null && files.size() == 1) { String name = FileUtil.stripTrailingSeparator(files.get(0)); - Path first = Path.of(name); - if (Files.isDirectory(first)) { - exportBaseDir = first; - RunHelper.dirToFiles(name, files); + if (getScheme(name) == null) { + Path first = Path.of(name); + if (Files.isDirectory(first)) { + exportBaseDir = first; + RunHelper.dirToFiles(name, files); + } } } diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Export.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Export.java index 4e1c209edc763..3f0296a3a72da 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Export.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Export.java @@ -88,10 +88,12 @@ protected Integer doExport() throws Exception { // special if user type: camel run . or camel run dirName if (files != null && files.size() == 1) { String name = FileUtil.stripTrailingSeparator(files.get(0)); - Path first = Path.of(name); - if (Files.isDirectory(first)) { - baseDir = first; - RunHelper.dirToFiles(name, files); + if (getScheme(name) == null) { + Path first = Path.of(name); + if (Files.isDirectory(first)) { + baseDir = first; + RunHelper.dirToFiles(name, files); + } } } diff --git a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java index 8783e4e3a4a70..d8d0e5728c4e0 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java +++ b/dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java @@ -351,14 +351,6 @@ protected static String mavenRepositoriesAsPomXml(String repos) { protected abstract Integer export() throws Exception; - protected static String getScheme(String name) { - int pos = name.indexOf(":"); - if (pos != -1) { - return name.substring(0, pos); - } - return null; - } - protected Integer runSilently(boolean ignoreLoadingError, boolean lazyBean, boolean verbose) throws Exception { Run run = new Run(getMain()); // need to declare the profile to use for run 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 1dcb930e9f2c8..46bf8c9a5bd2b 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 @@ -479,10 +479,12 @@ private int run() throws Exception { // special if user type: camel run . or camel run dirName if (sourceDir == null && files != null && files.size() == 1) { String name = FileUtil.stripTrailingSeparator(files.get(0)); - Path first = Path.of(name); - if (Files.isDirectory(first)) { - baseDir = first; - RunHelper.dirToFiles(name, files); + if (getScheme(name) == null) { + Path first = Path.of(name); + if (Files.isDirectory(first)) { + baseDir = first; + RunHelper.dirToFiles(name, files); + } } } diff --git a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/DependencyRuntimeTest.java b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/DependencyRuntimeTest.java index 1b7770f0f6635..cdb0a7c6ef7f0 100644 --- a/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/DependencyRuntimeTest.java +++ b/dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/DependencyRuntimeTest.java @@ -108,27 +108,24 @@ void testJsonOutput(String testPomXmlFile, String jsonOutput) throws Exception { private static class TestArguments { static final String QUARKUS_POM = "pom-xml-files/quarkus-pom.xml"; - static final String QUARKUS_POM_OUTPUT = """ - Runtime: quarkus - Camel Version: 4.11.0 - Camel Quarkus Version: 3.23.0 - Quarkus Version: 3.23.0"""; + static final String QUARKUS_POM_OUTPUT = "Runtime: quarkus" + System.lineSeparator() + + "Camel Version: 4.11.0" + System.lineSeparator() + + "Camel Quarkus Version: 3.23.0" + System.lineSeparator() + + "Quarkus Version: 3.23.0"; static final String QUARKUS_POM_JSON_OUTPUT = "{\"runtime\":\"quarkus\",\"camelVersion\":\"4.11.0\",\"camelQuarkusVersion\":\"3.23.0\",\"quarkusVersion\":\"3.23.0\",\"quarkusBomGroupId\":\"io.quarkus.platform\",\"quarkusBomArtifactId\":\"quarkus-bom\",\"camelQuarkusBomGroupId\":\"io.quarkus.platform\",\"camelQuarkusBomArtifactId\":\"quarkus-camel-bom\"}"; static final String SPRING_BOOT_POM = "pom-xml-files/springboot-pom.xml"; - static final String SPRING_BOOT_POM_OUTPUT = """ - Runtime: spring-boot - Camel Version: 4.14.0 - Camel Spring Boot Version: 4.14.0 - Spring Boot Version: 3.5.3"""; + static final String SPRING_BOOT_POM_OUTPUT = "Runtime: spring-boot" + System.lineSeparator() + + "Camel Version: 4.14.0" + System.lineSeparator() + + "Camel Spring Boot Version: 4.14.0" + System.lineSeparator() + + "Spring Boot Version: 3.5.3"; static final String SPRING_BOOT_POM_JSON_OUTPUT = "{\"runtime\":\"spring-boot\",\"camelVersion\":\"4.14.0\",\"camelSpringBootVersion\":\"4.14.0\",\"springBootVersion\":\"3.5.3\",\"camelSpringBootBomGroupId\":\"org.apache.camel.springboot\",\"camelSpringBootBomArtifactId\":\"camel-spring-boot-bom\"}"; static final String MAIN_POM = "pom-xml-files/main-pom.xml"; - static final String MAIN_POM_OUTPUT = """ - Runtime: main - Camel Version: 4.14.0"""; + static final String MAIN_POM_OUTPUT = "Runtime: main" + System.lineSeparator() + + "Camel Version: 4.14.0"; static final String MAIN_POM_JSON_OUTPUT = "{\"runtime\":\"main\",\"camelVersion\":\"4.14.0\"}"; diff --git a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExport.java b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExport.java index 197b8743a6a0d..109c9a58bb454 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExport.java +++ b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExport.java @@ -197,10 +197,12 @@ public Integer export() throws Exception { // special if user type: camel run . or camel run dirName if (files != null && files.size() == 1) { String name = FileUtil.stripTrailingSeparator(files.get(0)); - Path first = Path.of(name); - if (Files.isDirectory(first)) { - exportBaseDir = first; - RunHelper.dirToFiles(name, files); + if (getScheme(name) == null) { + Path first = Path.of(name); + if (Files.isDirectory(first)) { + exportBaseDir = first; + RunHelper.dirToFiles(name, files); + } } } if (exportBaseDir == null) { diff --git a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesRun.java b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesRun.java index 3e46ad9dac38c..e02ce08f1dbe1 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesRun.java +++ b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesRun.java @@ -320,10 +320,12 @@ public Integer doCall() throws Exception { Path baseDir = Path.of("."); if (files.size() == 1) { String name = FileUtil.stripTrailingSeparator(files.get(0)); - Path first = Path.of(name); - if (Files.isDirectory(first)) { - baseDir = first; - RunHelper.dirToFiles(name, files); + if (getScheme(name) == null) { + Path first = Path.of(name); + if (Files.isDirectory(first)) { + baseDir = first; + RunHelper.dirToFiles(name, files); + } } } // merge the properties from files @@ -423,7 +425,7 @@ public Integer doCall() throws Exception { } private String getIndexedWorkingDir(String projectName) { - var workingDir = RUN_PLATFORM_DIR + "/" + projectName; + var workingDir = RUN_PLATFORM_DIR + File.separator + projectName; if (devModeReloadCount > 0) { workingDir += "-%03d".formatted(devModeReloadCount); } @@ -654,7 +656,7 @@ private Integer buildProjectOutput(String workingDir) throws IOException, Interr args.add("--quiet"); } args.add("--file"); - args.add(workingDir); + args.add(new File(workingDir, "pom.xml").getAbsolutePath()); if (!ObjectHelper.isEmpty(namespace)) { args.add("-Djkube.namespace=%s".formatted(namespace)); @@ -717,7 +719,7 @@ private Integer deployProject(String workingDir, boolean reload) throws Exceptio // suppress maven transfer progress args.add("-ntp"); args.add("--file"); - args.add(workingDir); + args.add(new File(workingDir, "pom.xml").getAbsolutePath()); if (!imageBuild) { args.add("-Djkube.skip.build=true"); diff --git a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportTest.java b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportTest.java index da36299595e42..a97849d05e041 100644 --- a/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportTest.java +++ b/dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportTest.java @@ -601,11 +601,13 @@ public void shouldAddVolumes(RuntimeType rt) throws Exception { Assertions.assertEquals("pvc-foo", deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(0).getName()); Assertions.assertEquals("/container/path/foo", - deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(0).getMountPath()); + deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(0).getMountPath() + .replace('\\', '/')); Assertions.assertEquals("pvc-bar", deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(1).getName()); Assertions.assertEquals("/container/path/bar", - deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(1).getMountPath()); + deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(1).getMountPath() + .replace('\\', '/')); Assertions.assertEquals(2, deployment.getSpec().getTemplate().getSpec().getVolumes().size()); Assertions.assertEquals("pvc-foo", deployment.getSpec().getTemplate().getSpec().getVolumes().get(0).getName()); Assertions.assertEquals("pvc-foo", @@ -691,27 +693,30 @@ public void shouldAddConfigs() throws Exception { Assertions.assertEquals(5, volumeMounts.size()); // secret:foo Assertions.assertEquals("foo", volumeMounts.get(0).getName()); - Assertions.assertEquals("/etc/camel/conf.d/_secrets/foo", volumeMounts.get(0).getMountPath()); + Assertions.assertEquals("/etc/camel/conf.d/_secrets/foo", volumeMounts.get(0).getMountPath().replace('\\', '/')); Assertions.assertTrue(volumeMounts.get(0).getReadOnly()); // secret:foo/key-foo Assertions.assertEquals("foo", volumeMounts.get(1).getName()); - Assertions.assertEquals("/etc/camel/conf.d/_secrets/foo/key-foo", volumeMounts.get(1).getMountPath()); + Assertions.assertEquals("/etc/camel/conf.d/_secrets/foo/key-foo", + volumeMounts.get(1).getMountPath().replace('\\', '/')); Assertions.assertTrue(volumeMounts.get(1).getReadOnly()); Assertions.assertEquals("key-foo", volumes.get(1).getSecret().getItems().get(0).getKey()); Assertions.assertEquals("key-foo", volumes.get(1).getSecret().getItems().get(0).getPath()); // configmap:bar Assertions.assertEquals("bar", volumeMounts.get(2).getName()); - Assertions.assertEquals("/etc/camel/conf.d/_configmaps/bar", volumeMounts.get(2).getMountPath()); + Assertions.assertEquals("/etc/camel/conf.d/_configmaps/bar", volumeMounts.get(2).getMountPath().replace('\\', '/')); Assertions.assertTrue(volumeMounts.get(2).getReadOnly()); // configmap:bar/key-bar Assertions.assertEquals("bar", volumeMounts.get(3).getName()); - Assertions.assertEquals("/etc/camel/conf.d/_configmaps/bar/key-bar", volumeMounts.get(3).getMountPath()); + Assertions.assertEquals("/etc/camel/conf.d/_configmaps/bar/key-bar", + volumeMounts.get(3).getMountPath().replace('\\', '/')); Assertions.assertTrue(volumeMounts.get(3).getReadOnly()); Assertions.assertEquals("key-bar", volumes.get(3).getConfigMap().getItems().get(0).getKey()); Assertions.assertEquals("key-bar", volumes.get(3).getConfigMap().getItems().get(0).getPath()); // configmap:bar2/my.properties Assertions.assertEquals("bar2", volumeMounts.get(4).getName()); - Assertions.assertEquals("/etc/camel/conf.d/_configmaps/bar2/my.properties", volumeMounts.get(4).getMountPath()); + Assertions.assertEquals("/etc/camel/conf.d/_configmaps/bar2/my.properties", + volumeMounts.get(4).getMountPath().replace('\\', '/')); Assertions.assertEquals("my.properties", volumes.get(4).getConfigMap().getItems().get(0).getKey()); Assertions.assertEquals("my.properties", volumes.get(4).getConfigMap().getItems().get(0).getPath()); } @@ -734,30 +739,33 @@ public void shouldAddResources() throws Exception { Assertions.assertEquals(6, volumeMounts.size()); // secret:foo Assertions.assertEquals("foo", volumeMounts.get(0).getName()); - Assertions.assertEquals("/etc/camel/resources.d/_secrets/foo", volumeMounts.get(0).getMountPath()); + Assertions.assertEquals("/etc/camel/resources.d/_secrets/foo", volumeMounts.get(0).getMountPath().replace('\\', '/')); Assertions.assertTrue(volumeMounts.get(0).getReadOnly()); // secret:foo/key-foo Assertions.assertEquals("foo", volumeMounts.get(1).getName()); - Assertions.assertEquals("/etc/camel/resources.d/_secrets/foo/key-foo", volumeMounts.get(1).getMountPath()); + Assertions.assertEquals("/etc/camel/resources.d/_secrets/foo/key-foo", + volumeMounts.get(1).getMountPath().replace('\\', '/')); Assertions.assertEquals("key-foo", volumes.get(1).getSecret().getItems().get(0).getKey()); Assertions.assertEquals("key-foo", volumes.get(1).getSecret().getItems().get(0).getPath()); // secret:foo/key-foo@/etc/foodir/my-file.txt Assertions.assertEquals("foo", volumeMounts.get(2).getName()); - Assertions.assertEquals("/etc/foodir/my-file.txt", volumeMounts.get(2).getMountPath()); + Assertions.assertEquals("/etc/foodir/my-file.txt", volumeMounts.get(2).getMountPath().replace('\\', '/')); Assertions.assertEquals("my-file.txt", volumeMounts.get(2).getSubPath()); Assertions.assertEquals("key-foo", volumes.get(2).getSecret().getItems().get(0).getKey()); Assertions.assertEquals("my-file.txt", volumes.get(2).getSecret().getItems().get(0).getPath()); // configmap:bar Assertions.assertEquals("bar", volumeMounts.get(3).getName()); - Assertions.assertEquals("/etc/camel/resources.d/_configmaps/bar", volumeMounts.get(3).getMountPath()); + Assertions.assertEquals("/etc/camel/resources.d/_configmaps/bar", + volumeMounts.get(3).getMountPath().replace('\\', '/')); // configmap:bar/key-bar Assertions.assertEquals("bar", volumeMounts.get(4).getName()); - Assertions.assertEquals("/etc/camel/resources.d/_configmaps/bar/key-bar", volumeMounts.get(4).getMountPath()); + Assertions.assertEquals("/etc/camel/resources.d/_configmaps/bar/key-bar", + volumeMounts.get(4).getMountPath().replace('\\', '/')); Assertions.assertEquals("key-bar", volumes.get(4).getConfigMap().getItems().get(0).getKey()); Assertions.assertEquals("key-bar", volumes.get(4).getConfigMap().getItems().get(0).getPath()); // configmap:bar2/my.properties@/var/dir1/bar.bin Assertions.assertEquals("bar2", volumeMounts.get(5).getName()); - Assertions.assertEquals("/var/dir1/bar.bin", volumeMounts.get(5).getMountPath()); + Assertions.assertEquals("/var/dir1/bar.bin", volumeMounts.get(5).getMountPath().replace('\\', '/')); Assertions.assertEquals("bar.bin", volumeMounts.get(5).getSubPath()); Assertions.assertEquals("my.properties", volumes.get(5).getConfigMap().getItems().get(0).getKey()); Assertions.assertEquals("bar.bin", volumes.get(5).getConfigMap().getItems().get(0).getPath()); @@ -777,19 +785,21 @@ public void shouldAddConfigAndResources() throws Exception { // config configmap:bar1a/my.key1 Assertions.assertEquals("bar1a", volumeMounts.get(0).getName()); - Assertions.assertEquals("/etc/camel/conf.d/_configmaps/bar1a/my.key1", volumeMounts.get(0).getMountPath()); + Assertions.assertEquals("/etc/camel/conf.d/_configmaps/bar1a/my.key1", + volumeMounts.get(0).getMountPath().replace('\\', '/')); Assertions.assertEquals("my.key1", volumeMounts.get(0).getSubPath()); Assertions.assertEquals("my.key1", volumes.get(0).getConfigMap().getItems().get(0).getKey()); Assertions.assertEquals("my.key1", volumes.get(0).getConfigMap().getItems().get(0).getPath()); // resources configmap:bar2/key-bar2 Assertions.assertEquals("bar2", volumeMounts.get(1).getName()); - Assertions.assertEquals("/etc/camel/resources.d/_configmaps/bar2/key-bar2", volumeMounts.get(1).getMountPath()); + Assertions.assertEquals("/etc/camel/resources.d/_configmaps/bar2/key-bar2", + volumeMounts.get(1).getMountPath().replace('\\', '/')); Assertions.assertEquals("key-bar2", volumeMounts.get(1).getSubPath()); Assertions.assertEquals("key-bar2", volumes.get(1).getConfigMap().getItems().get(0).getKey()); Assertions.assertEquals("key-bar2", volumes.get(1).getConfigMap().getItems().get(0).getPath()); // resources configmap:bar2a/my.key2@/var/dir2/bar.bin Assertions.assertEquals("bar2a", volumeMounts.get(2).getName()); - Assertions.assertEquals("/var/dir2/bar.bin", volumeMounts.get(2).getMountPath()); + Assertions.assertEquals("/var/dir2/bar.bin", volumeMounts.get(2).getMountPath().replace('\\', '/')); Assertions.assertEquals("bar.bin", volumeMounts.get(2).getSubPath()); Assertions.assertEquals("my.key2", volumes.get(2).getConfigMap().getItems().get(0).getKey()); Assertions.assertEquals("bar.bin", volumes.get(2).getConfigMap().getItems().get(0).getPath()); @@ -812,7 +822,8 @@ public void shouldAddOpenApis(RuntimeType rt) throws Exception { Assertions.assertEquals("openapi", deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(0).getName()); Assertions.assertEquals("/etc/camel/resources.d/_configmaps/openapi/spec.yaml", - deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(0).getMountPath()); + deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(0).getMountPath() + .replace('\\', '/')); Assertions.assertEquals("spec.yaml", deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(0).getSubPath()); }