Skip to content

Commit c285db8

Browse files
committed
[Fix #3569] Refining for windows
1 parent 6ece5f8 commit c285db8

File tree

8 files changed

+46
-46
lines changed

8 files changed

+46
-46
lines changed

kogito-serverless-workflow/kogito-serverless-workflow-builder/pom.xml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,6 @@
106106
<groupId>org.kie.kogito</groupId>
107107
<artifactId>kogito-jq-expression</artifactId>
108108
</dependency>
109-
<dependency>
110-
<groupId>org.apache.kie.sonataflow</groupId>
111-
<artifactId>
112-
sonataflow-addons-quarkus-camel-deployment
113-
</artifactId>
114-
<version>999-SNAPSHOT</version>
115-
</dependency>
116109
</dependencies>
117110

118111
</project>

kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/io/FileContentLoader.java

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,24 +20,41 @@
2020

2121
import java.io.IOException;
2222
import java.io.UncheckedIOException;
23+
import java.net.URI;
2324
import java.nio.file.Files;
2425
import java.nio.file.Path;
2526
import java.util.Optional;
2627

28+
import org.slf4j.Logger;
29+
import org.slf4j.LoggerFactory;
30+
2731
public class FileContentLoader extends CachedContentLoader {
2832

2933
private final Path path;
3034

35+
private static final Logger logger = LoggerFactory.getLogger(FileContentLoader.class);
36+
3137
FileContentLoader(String uri, URIContentLoader... fallbackContentLoaders) {
3238
super(uri, fallbackContentLoaders);
33-
this.path = Path.of(uriToPath(uri));
39+
this.path = obtainPath(uri);
3440
}
3541

3642
@Override
3743
public URIContentLoaderType type() {
3844
return URIContentLoaderType.FILE;
3945
}
4046

47+
private static Path obtainPath(String uri) {
48+
if (uri.startsWith(URIContentLoaderType.FILE.scheme())) {
49+
try {
50+
return Path.of(URI.create(uri));
51+
} catch (Exception ex) {
52+
logger.info("URI {} is not valid one according to Java, trying alternative approach", uri, ex);
53+
}
54+
}
55+
return Path.of(uriToPath(uri));
56+
}
57+
4158
@Override
4259
protected Optional<Path> internalGetPath() {
4360
return Files.exists(path) ? Optional.of(path) : Optional.empty();

kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/io/URIContentLoaderFactory.java

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,11 @@ public static byte[] readBytes(String uriStr, Workflow workflow, Optional<Parser
7474
}
7575

7676
public static Builder builder(URI uri) {
77-
return new Builder(uri);
77+
return new Builder(uri.toString());
7878
}
7979

8080
public static Builder builder(String uri) {
81-
return new Builder(URI.create(uri));
81+
return new Builder(uri);
8282
}
8383

8484
public static class Builder {
@@ -134,11 +134,7 @@ public URIContentLoader build() {
134134
}
135135

136136
public static String compoundURI(String baseURI, String uri) {
137-
if (URIContentLoaderType.scheme(uri).isPresent()) {
138-
return uri;
139-
}
140-
final URIContentLoaderType baseType = URIContentLoaderType.from(baseURI);
141-
return baseType.addScheme(baseType.isAbsolutePath(uri) ? uri : baseType.concat(baseType.trimLast(baseType.uriToPath(baseURI)), uri));
137+
return URIContentLoaderType.scheme(uri).isPresent() ? uri : URIContentLoaderType.from(baseURI).concat(baseURI, uri);
142138
}
143139

144140
private URIContentLoaderFactory() {

kogito-serverless-workflow/kogito-serverless-workflow-builder/src/main/java/org/kie/kogito/serverless/workflow/io/URIContentLoaderType.java

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ public static Optional<String> scheme(String uri) {
4646
public static URIContentLoaderType from(String uri) {
4747
return scheme(uri).map(scheme -> {
4848
switch (scheme) {
49+
default:
4950
case "file":
5051
return FILE;
5152
case "classpath":
@@ -54,17 +55,10 @@ public static URIContentLoaderType from(String uri) {
5455
return HTTP;
5556
case "https":
5657
return HTTPS;
57-
default:
58-
throw new IllegalArgumentException("Unrecognized protocol " + scheme + "for uri " + uri);
5958
}
6059
}).orElse(FILE);
6160
}
6261

63-
public String addScheme(String path) {
64-
String lowerCasePath = path.toLowerCase();
65-
return lowerCasePath.startsWith(scheme) ? path : scheme + path;
66-
}
67-
6862
public boolean isAbsolutePath(String path) {
6963
if (!path.isBlank()) {
7064
char firstChar = path.trim().charAt(0);
@@ -78,16 +72,19 @@ public boolean isAbsolutePath(String path) {
7872
}
7973

8074
public String concat(String basePath, String additionalPath) {
81-
char separator = separator();
82-
if (!basePath.isBlank() && !isAbsolutePath(basePath)) {
83-
basePath = separator + basePath;
75+
if (isAbsolutePath(additionalPath)) {
76+
return keepSchemaIfPresent(basePath, additionalPath);
77+
}
78+
int indexOf = lastIndexOf(basePath);
79+
if (indexOf != -1) {
80+
return keepSchemaIfPresent(basePath, basePath.substring(0, indexOf + 1) + additionalPath);
81+
} else {
82+
return keepSchemaIfPresent(basePath, additionalPath);
8483
}
85-
return basePath + separator + additionalPath;
8684
}
8785

88-
public String trimLast(String path) {
89-
int indexOf = lastIndexOf(path);
90-
return indexOf != -1 ? path.substring(0, indexOf) : "";
86+
private String keepSchemaIfPresent(String basePath, String resultPath) {
87+
return basePath.startsWith(scheme) && !resultPath.startsWith(scheme) ? scheme + resultPath : resultPath;
9188
}
9289

9390
public String lastPart(String path) {
@@ -112,8 +109,4 @@ private int lastIndexOf(String path) {
112109
return indexOf;
113110
}
114111

115-
private char separator() {
116-
return additionalSeparators.length > 0 ? additionalSeparators[0] : '/';
117-
}
118-
119112
}

kogito-serverless-workflow/kogito-serverless-workflow-builder/src/test/java/org/kie/kogito/serverless/workflow/io/URIContentLoaderTest.java

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,12 @@ class URIContentLoaderTest {
3434

3535
@Test
3636
void testExistingFile() throws URISyntaxException {
37-
assertThat(readString(builder(Thread.currentThread().getContextClassLoader().getResource("pepe.txt").toURI()))).isEqualTo("my name is javierito");
37+
assertThat(readString(builder(Thread.currentThread().getContextClassLoader().getResource("pepe a pepa.txt").toURI()))).isEqualTo("my name is javierito");
3838
}
3939

4040
@Test
4141
void testExistingClasspath() {
42-
assertThat(readString(builder("classpath:pepe.txt"))).isEqualTo("my name is javierito");
42+
assertThat(readString(builder("classpath:pepe a pepa.txt"))).isEqualTo("my name is javierito");
4343
}
4444

4545
@Test
@@ -56,13 +56,14 @@ void testNotExistingClasspath() {
5656

5757
@Test
5858
void testCompoundURI() {
59-
assertThat(compoundURI("classpath:pepe.json", "pepa.json")).isEqualTo("classpath:/pepa.json");
60-
assertThat(compoundURI("classpath:pepe.json", "file:///pepa.json")).isEqualTo("file:///pepa.json");
59+
assertThat(compoundURI("classpath:pepe.json", "pepa.json")).isEqualTo("classpath:pepa.json");
60+
assertThat(compoundURI("classpath:pepe.json", "file:/pepa.json")).isEqualTo("file:/pepa.json");
6161
assertThat(compoundURI("classpath:schema/pepe.json", "/pepa.json")).isEqualTo("classpath:/pepa.json");
62-
assertThat(compoundURI("classpath:schema/pepe.json", "pepa.json")).isEqualTo("classpath:/schema/pepa.json");
63-
assertThat(compoundURI("pepe.json", "pepa.json")).isEqualTo("file:/pepa.json");
64-
assertThat(compoundURI("schema/pepe.json", "pepa.json")).isEqualTo("file:/schema/pepa.json");
65-
assertThat(compoundURI("schema/pepe.json", "/pepa.json")).isEqualTo("file:/pepa.json");
62+
assertThat(compoundURI("classpath:schema/pepe.json", "pepa.json")).isEqualTo("classpath:schema/pepa.json");
63+
assertThat(compoundURI("pepe.json", "pepa.json")).isEqualTo("pepa.json");
64+
assertThat(compoundURI("schema/pepe.json", "pepa.json")).isEqualTo("schema/pepa.json");
65+
assertThat(compoundURI("schema/pepe.json", "/pepa.json")).isEqualTo("/pepa.json");
6666
assertThat(compoundURI("pepe.json", "classpath:pepa.json")).isEqualTo("classpath:pepa.json");
6767
}
68+
6869
}

quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/quarkus/serverless/workflow/rpc/WorkflowRPCCodeGenProvider.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,8 @@ public boolean trigger(CodeGenContext context) throws CodeGenException {
7272
}
7373
ProtocUtils.generateDescriptor(protoFiles, context);
7474
return true;
75-
} catch (IOException io) {
75+
} catch (Exception io) {
76+
logger.error("Exception generating RPC code", io);
7677
throw new CodeGenException(io);
7778
}
7879
}

quarkus/extensions/kogito-quarkus-serverless-workflow-extension/kogito-quarkus-serverless-workflow-deployment/src/main/java/org/kie/kogito/serverless/workflow/io/QuarkusResourceCache.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,7 @@
1818
*/
1919
package org.kie.kogito.serverless.workflow.io;
2020

21-
import java.net.URI;
22-
import java.util.function.Function;
21+
import java.util.function.Supplier;
2322

2423
import io.quarkus.cache.Cache;
2524
import io.quarkus.cache.CacheName;
@@ -40,7 +39,7 @@ void init() {
4039
ResourceCacheFactory.setResourceCache(this::get);
4140
}
4241

43-
private byte[] get(URI uri, Function<URI, byte[]> retrieveCall) {
44-
return cache.get(uri, retrieveCall).await().indefinitely();
42+
private byte[] get(String uri, Supplier<byte[]> retrieveCall) {
43+
return cache.get(uri, u -> retrieveCall.get()).await().indefinitely();
4544
}
4645
}

0 commit comments

Comments
 (0)