Skip to content

Commit a9725c6

Browse files
authored
CAMEL-22798: Fix Camel-JBang tests on Windows (#20576)
1 parent c59d93b commit a9725c6

File tree

9 files changed

+79
-61
lines changed

9 files changed

+79
-61
lines changed

dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/CamelCommand.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,14 @@ private void replacePlaceholders() throws Exception {
9494

9595
public abstract Integer doCall() throws Exception;
9696

97+
protected static String getScheme(String name) {
98+
int pos = name.indexOf(":");
99+
if (pos != -1) {
100+
return name.substring(0, pos);
101+
}
102+
return null;
103+
}
104+
97105
public Path getStatusFile(String pid) {
98106
return CommandLineHelper.getCamelDir().resolve(pid + "-status.json");
99107
}

dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/DependencyList.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,12 @@ protected Integer export() throws Exception {
7777
// special if user type: camel run . or camel run dirName
7878
if (files != null && files.size() == 1) {
7979
String name = FileUtil.stripTrailingSeparator(files.get(0));
80-
Path first = Path.of(name);
81-
if (Files.isDirectory(first)) {
82-
exportBaseDir = first;
83-
RunHelper.dirToFiles(name, files);
80+
if (getScheme(name) == null) {
81+
Path first = Path.of(name);
82+
if (Files.isDirectory(first)) {
83+
exportBaseDir = first;
84+
RunHelper.dirToFiles(name, files);
85+
}
8486
}
8587
}
8688

dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Export.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,12 @@ protected Integer doExport() throws Exception {
8888
// special if user type: camel run . or camel run dirName
8989
if (files != null && files.size() == 1) {
9090
String name = FileUtil.stripTrailingSeparator(files.get(0));
91-
Path first = Path.of(name);
92-
if (Files.isDirectory(first)) {
93-
baseDir = first;
94-
RunHelper.dirToFiles(name, files);
91+
if (getScheme(name) == null) {
92+
Path first = Path.of(name);
93+
if (Files.isDirectory(first)) {
94+
baseDir = first;
95+
RunHelper.dirToFiles(name, files);
96+
}
9597
}
9698
}
9799

dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ExportBaseCommand.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -351,14 +351,6 @@ protected static String mavenRepositoriesAsPomXml(String repos) {
351351

352352
protected abstract Integer export() throws Exception;
353353

354-
protected static String getScheme(String name) {
355-
int pos = name.indexOf(":");
356-
if (pos != -1) {
357-
return name.substring(0, pos);
358-
}
359-
return null;
360-
}
361-
362354
protected Integer runSilently(boolean ignoreLoadingError, boolean lazyBean, boolean verbose) throws Exception {
363355
Run run = new Run(getMain());
364356
// need to declare the profile to use for run

dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/Run.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -479,10 +479,12 @@ private int run() throws Exception {
479479
// special if user type: camel run . or camel run dirName
480480
if (sourceDir == null && files != null && files.size() == 1) {
481481
String name = FileUtil.stripTrailingSeparator(files.get(0));
482-
Path first = Path.of(name);
483-
if (Files.isDirectory(first)) {
484-
baseDir = first;
485-
RunHelper.dirToFiles(name, files);
482+
if (getScheme(name) == null) {
483+
Path first = Path.of(name);
484+
if (Files.isDirectory(first)) {
485+
baseDir = first;
486+
RunHelper.dirToFiles(name, files);
487+
}
486488
}
487489
}
488490

dsl/camel-jbang/camel-jbang-core/src/test/java/org/apache/camel/dsl/jbang/core/commands/DependencyRuntimeTest.java

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -108,27 +108,24 @@ void testJsonOutput(String testPomXmlFile, String jsonOutput) throws Exception {
108108

109109
private static class TestArguments {
110110
static final String QUARKUS_POM = "pom-xml-files/quarkus-pom.xml";
111-
static final String QUARKUS_POM_OUTPUT = """
112-
Runtime: quarkus
113-
Camel Version: 4.11.0
114-
Camel Quarkus Version: 3.23.0
115-
Quarkus Version: 3.23.0""";
111+
static final String QUARKUS_POM_OUTPUT = "Runtime: quarkus" + System.lineSeparator() +
112+
"Camel Version: 4.11.0" + System.lineSeparator() +
113+
"Camel Quarkus Version: 3.23.0" + System.lineSeparator() +
114+
"Quarkus Version: 3.23.0";
116115
static final String QUARKUS_POM_JSON_OUTPUT
117116
= "{\"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\"}";
118117

119118
static final String SPRING_BOOT_POM = "pom-xml-files/springboot-pom.xml";
120-
static final String SPRING_BOOT_POM_OUTPUT = """
121-
Runtime: spring-boot
122-
Camel Version: 4.14.0
123-
Camel Spring Boot Version: 4.14.0
124-
Spring Boot Version: 3.5.3""";
119+
static final String SPRING_BOOT_POM_OUTPUT = "Runtime: spring-boot" + System.lineSeparator() +
120+
"Camel Version: 4.14.0" + System.lineSeparator() +
121+
"Camel Spring Boot Version: 4.14.0" + System.lineSeparator() +
122+
"Spring Boot Version: 3.5.3";
125123
static final String SPRING_BOOT_POM_JSON_OUTPUT
126124
= "{\"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\"}";
127125

128126
static final String MAIN_POM = "pom-xml-files/main-pom.xml";
129-
static final String MAIN_POM_OUTPUT = """
130-
Runtime: main
131-
Camel Version: 4.14.0""";
127+
static final String MAIN_POM_OUTPUT = "Runtime: main" + System.lineSeparator() +
128+
"Camel Version: 4.14.0";
132129
static final String MAIN_POM_JSON_OUTPUT
133130
= "{\"runtime\":\"main\",\"camelVersion\":\"4.14.0\"}";
134131

dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExport.java

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -197,10 +197,12 @@ public Integer export() throws Exception {
197197
// special if user type: camel run . or camel run dirName
198198
if (files != null && files.size() == 1) {
199199
String name = FileUtil.stripTrailingSeparator(files.get(0));
200-
Path first = Path.of(name);
201-
if (Files.isDirectory(first)) {
202-
exportBaseDir = first;
203-
RunHelper.dirToFiles(name, files);
200+
if (getScheme(name) == null) {
201+
Path first = Path.of(name);
202+
if (Files.isDirectory(first)) {
203+
exportBaseDir = first;
204+
RunHelper.dirToFiles(name, files);
205+
}
204206
}
205207
}
206208
if (exportBaseDir == null) {

dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/main/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesRun.java

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -320,10 +320,12 @@ public Integer doCall() throws Exception {
320320
Path baseDir = Path.of(".");
321321
if (files.size() == 1) {
322322
String name = FileUtil.stripTrailingSeparator(files.get(0));
323-
Path first = Path.of(name);
324-
if (Files.isDirectory(first)) {
325-
baseDir = first;
326-
RunHelper.dirToFiles(name, files);
323+
if (getScheme(name) == null) {
324+
Path first = Path.of(name);
325+
if (Files.isDirectory(first)) {
326+
baseDir = first;
327+
RunHelper.dirToFiles(name, files);
328+
}
327329
}
328330
}
329331
// merge the properties from files
@@ -423,7 +425,7 @@ public Integer doCall() throws Exception {
423425
}
424426

425427
private String getIndexedWorkingDir(String projectName) {
426-
var workingDir = RUN_PLATFORM_DIR + "/" + projectName;
428+
var workingDir = RUN_PLATFORM_DIR + File.separator + projectName;
427429
if (devModeReloadCount > 0) {
428430
workingDir += "-%03d".formatted(devModeReloadCount);
429431
}
@@ -654,7 +656,7 @@ private Integer buildProjectOutput(String workingDir) throws IOException, Interr
654656
args.add("--quiet");
655657
}
656658
args.add("--file");
657-
args.add(workingDir);
659+
args.add(new File(workingDir, "pom.xml").getAbsolutePath());
658660

659661
if (!ObjectHelper.isEmpty(namespace)) {
660662
args.add("-Djkube.namespace=%s".formatted(namespace));
@@ -717,7 +719,7 @@ private Integer deployProject(String workingDir, boolean reload) throws Exceptio
717719
// suppress maven transfer progress
718720
args.add("-ntp");
719721
args.add("--file");
720-
args.add(workingDir);
722+
args.add(new File(workingDir, "pom.xml").getAbsolutePath());
721723

722724
if (!imageBuild) {
723725
args.add("-Djkube.skip.build=true");

dsl/camel-jbang/camel-jbang-plugin-kubernetes/src/test/java/org/apache/camel/dsl/jbang/core/commands/kubernetes/KubernetesExportTest.java

Lines changed: 28 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -601,11 +601,13 @@ public void shouldAddVolumes(RuntimeType rt) throws Exception {
601601
Assertions.assertEquals("pvc-foo",
602602
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(0).getName());
603603
Assertions.assertEquals("/container/path/foo",
604-
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(0).getMountPath());
604+
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(0).getMountPath()
605+
.replace('\\', '/'));
605606
Assertions.assertEquals("pvc-bar",
606607
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(1).getName());
607608
Assertions.assertEquals("/container/path/bar",
608-
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(1).getMountPath());
609+
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(1).getMountPath()
610+
.replace('\\', '/'));
609611
Assertions.assertEquals(2, deployment.getSpec().getTemplate().getSpec().getVolumes().size());
610612
Assertions.assertEquals("pvc-foo", deployment.getSpec().getTemplate().getSpec().getVolumes().get(0).getName());
611613
Assertions.assertEquals("pvc-foo",
@@ -691,27 +693,30 @@ public void shouldAddConfigs() throws Exception {
691693
Assertions.assertEquals(5, volumeMounts.size());
692694
// secret:foo
693695
Assertions.assertEquals("foo", volumeMounts.get(0).getName());
694-
Assertions.assertEquals("/etc/camel/conf.d/_secrets/foo", volumeMounts.get(0).getMountPath());
696+
Assertions.assertEquals("/etc/camel/conf.d/_secrets/foo", volumeMounts.get(0).getMountPath().replace('\\', '/'));
695697
Assertions.assertTrue(volumeMounts.get(0).getReadOnly());
696698
// secret:foo/key-foo
697699
Assertions.assertEquals("foo", volumeMounts.get(1).getName());
698-
Assertions.assertEquals("/etc/camel/conf.d/_secrets/foo/key-foo", volumeMounts.get(1).getMountPath());
700+
Assertions.assertEquals("/etc/camel/conf.d/_secrets/foo/key-foo",
701+
volumeMounts.get(1).getMountPath().replace('\\', '/'));
699702
Assertions.assertTrue(volumeMounts.get(1).getReadOnly());
700703
Assertions.assertEquals("key-foo", volumes.get(1).getSecret().getItems().get(0).getKey());
701704
Assertions.assertEquals("key-foo", volumes.get(1).getSecret().getItems().get(0).getPath());
702705
// configmap:bar
703706
Assertions.assertEquals("bar", volumeMounts.get(2).getName());
704-
Assertions.assertEquals("/etc/camel/conf.d/_configmaps/bar", volumeMounts.get(2).getMountPath());
707+
Assertions.assertEquals("/etc/camel/conf.d/_configmaps/bar", volumeMounts.get(2).getMountPath().replace('\\', '/'));
705708
Assertions.assertTrue(volumeMounts.get(2).getReadOnly());
706709
// configmap:bar/key-bar
707710
Assertions.assertEquals("bar", volumeMounts.get(3).getName());
708-
Assertions.assertEquals("/etc/camel/conf.d/_configmaps/bar/key-bar", volumeMounts.get(3).getMountPath());
711+
Assertions.assertEquals("/etc/camel/conf.d/_configmaps/bar/key-bar",
712+
volumeMounts.get(3).getMountPath().replace('\\', '/'));
709713
Assertions.assertTrue(volumeMounts.get(3).getReadOnly());
710714
Assertions.assertEquals("key-bar", volumes.get(3).getConfigMap().getItems().get(0).getKey());
711715
Assertions.assertEquals("key-bar", volumes.get(3).getConfigMap().getItems().get(0).getPath());
712716
// configmap:bar2/my.properties
713717
Assertions.assertEquals("bar2", volumeMounts.get(4).getName());
714-
Assertions.assertEquals("/etc/camel/conf.d/_configmaps/bar2/my.properties", volumeMounts.get(4).getMountPath());
718+
Assertions.assertEquals("/etc/camel/conf.d/_configmaps/bar2/my.properties",
719+
volumeMounts.get(4).getMountPath().replace('\\', '/'));
715720
Assertions.assertEquals("my.properties", volumes.get(4).getConfigMap().getItems().get(0).getKey());
716721
Assertions.assertEquals("my.properties", volumes.get(4).getConfigMap().getItems().get(0).getPath());
717722
}
@@ -734,30 +739,33 @@ public void shouldAddResources() throws Exception {
734739
Assertions.assertEquals(6, volumeMounts.size());
735740
// secret:foo
736741
Assertions.assertEquals("foo", volumeMounts.get(0).getName());
737-
Assertions.assertEquals("/etc/camel/resources.d/_secrets/foo", volumeMounts.get(0).getMountPath());
742+
Assertions.assertEquals("/etc/camel/resources.d/_secrets/foo", volumeMounts.get(0).getMountPath().replace('\\', '/'));
738743
Assertions.assertTrue(volumeMounts.get(0).getReadOnly());
739744
// secret:foo/key-foo
740745
Assertions.assertEquals("foo", volumeMounts.get(1).getName());
741-
Assertions.assertEquals("/etc/camel/resources.d/_secrets/foo/key-foo", volumeMounts.get(1).getMountPath());
746+
Assertions.assertEquals("/etc/camel/resources.d/_secrets/foo/key-foo",
747+
volumeMounts.get(1).getMountPath().replace('\\', '/'));
742748
Assertions.assertEquals("key-foo", volumes.get(1).getSecret().getItems().get(0).getKey());
743749
Assertions.assertEquals("key-foo", volumes.get(1).getSecret().getItems().get(0).getPath());
744750
// secret:foo/key-foo@/etc/foodir/my-file.txt
745751
Assertions.assertEquals("foo", volumeMounts.get(2).getName());
746-
Assertions.assertEquals("/etc/foodir/my-file.txt", volumeMounts.get(2).getMountPath());
752+
Assertions.assertEquals("/etc/foodir/my-file.txt", volumeMounts.get(2).getMountPath().replace('\\', '/'));
747753
Assertions.assertEquals("my-file.txt", volumeMounts.get(2).getSubPath());
748754
Assertions.assertEquals("key-foo", volumes.get(2).getSecret().getItems().get(0).getKey());
749755
Assertions.assertEquals("my-file.txt", volumes.get(2).getSecret().getItems().get(0).getPath());
750756
// configmap:bar
751757
Assertions.assertEquals("bar", volumeMounts.get(3).getName());
752-
Assertions.assertEquals("/etc/camel/resources.d/_configmaps/bar", volumeMounts.get(3).getMountPath());
758+
Assertions.assertEquals("/etc/camel/resources.d/_configmaps/bar",
759+
volumeMounts.get(3).getMountPath().replace('\\', '/'));
753760
// configmap:bar/key-bar
754761
Assertions.assertEquals("bar", volumeMounts.get(4).getName());
755-
Assertions.assertEquals("/etc/camel/resources.d/_configmaps/bar/key-bar", volumeMounts.get(4).getMountPath());
762+
Assertions.assertEquals("/etc/camel/resources.d/_configmaps/bar/key-bar",
763+
volumeMounts.get(4).getMountPath().replace('\\', '/'));
756764
Assertions.assertEquals("key-bar", volumes.get(4).getConfigMap().getItems().get(0).getKey());
757765
Assertions.assertEquals("key-bar", volumes.get(4).getConfigMap().getItems().get(0).getPath());
758766
// configmap:bar2/my.properties@/var/dir1/bar.bin
759767
Assertions.assertEquals("bar2", volumeMounts.get(5).getName());
760-
Assertions.assertEquals("/var/dir1/bar.bin", volumeMounts.get(5).getMountPath());
768+
Assertions.assertEquals("/var/dir1/bar.bin", volumeMounts.get(5).getMountPath().replace('\\', '/'));
761769
Assertions.assertEquals("bar.bin", volumeMounts.get(5).getSubPath());
762770
Assertions.assertEquals("my.properties", volumes.get(5).getConfigMap().getItems().get(0).getKey());
763771
Assertions.assertEquals("bar.bin", volumes.get(5).getConfigMap().getItems().get(0).getPath());
@@ -777,19 +785,21 @@ public void shouldAddConfigAndResources() throws Exception {
777785

778786
// config configmap:bar1a/my.key1
779787
Assertions.assertEquals("bar1a", volumeMounts.get(0).getName());
780-
Assertions.assertEquals("/etc/camel/conf.d/_configmaps/bar1a/my.key1", volumeMounts.get(0).getMountPath());
788+
Assertions.assertEquals("/etc/camel/conf.d/_configmaps/bar1a/my.key1",
789+
volumeMounts.get(0).getMountPath().replace('\\', '/'));
781790
Assertions.assertEquals("my.key1", volumeMounts.get(0).getSubPath());
782791
Assertions.assertEquals("my.key1", volumes.get(0).getConfigMap().getItems().get(0).getKey());
783792
Assertions.assertEquals("my.key1", volumes.get(0).getConfigMap().getItems().get(0).getPath());
784793
// resources configmap:bar2/key-bar2
785794
Assertions.assertEquals("bar2", volumeMounts.get(1).getName());
786-
Assertions.assertEquals("/etc/camel/resources.d/_configmaps/bar2/key-bar2", volumeMounts.get(1).getMountPath());
795+
Assertions.assertEquals("/etc/camel/resources.d/_configmaps/bar2/key-bar2",
796+
volumeMounts.get(1).getMountPath().replace('\\', '/'));
787797
Assertions.assertEquals("key-bar2", volumeMounts.get(1).getSubPath());
788798
Assertions.assertEquals("key-bar2", volumes.get(1).getConfigMap().getItems().get(0).getKey());
789799
Assertions.assertEquals("key-bar2", volumes.get(1).getConfigMap().getItems().get(0).getPath());
790800
// resources configmap:bar2a/my.key2@/var/dir2/bar.bin
791801
Assertions.assertEquals("bar2a", volumeMounts.get(2).getName());
792-
Assertions.assertEquals("/var/dir2/bar.bin", volumeMounts.get(2).getMountPath());
802+
Assertions.assertEquals("/var/dir2/bar.bin", volumeMounts.get(2).getMountPath().replace('\\', '/'));
793803
Assertions.assertEquals("bar.bin", volumeMounts.get(2).getSubPath());
794804
Assertions.assertEquals("my.key2", volumes.get(2).getConfigMap().getItems().get(0).getKey());
795805
Assertions.assertEquals("bar.bin", volumes.get(2).getConfigMap().getItems().get(0).getPath());
@@ -812,7 +822,8 @@ public void shouldAddOpenApis(RuntimeType rt) throws Exception {
812822
Assertions.assertEquals("openapi",
813823
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(0).getName());
814824
Assertions.assertEquals("/etc/camel/resources.d/_configmaps/openapi/spec.yaml",
815-
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(0).getMountPath());
825+
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(0).getMountPath()
826+
.replace('\\', '/'));
816827
Assertions.assertEquals("spec.yaml",
817828
deployment.getSpec().getTemplate().getSpec().getContainers().get(0).getVolumeMounts().get(0).getSubPath());
818829
}

0 commit comments

Comments
 (0)