This is an automated email from the ASF dual-hosted git repository.
liujun pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/dubbo-initializer.git
The following commit(s) were added to refs/heads/main by this push:
new 692d8b1 fix FileSystemException when loading dockerfile
new 54c6740 Merge pull request #31 from chickenlj/fix-file-load
692d8b1 is described below
commit 692d8b1e84c38c5f4e0e595cae94941226ca32a8
Author: chickenlj <[email protected]>
AuthorDate: Thu Dec 28 14:42:16 2023 +0800
fix FileSystemException when loading dockerfile
---
.../generation/extension/DockerfileCodeContributor.java | 15 +++++----------
1 file changed, 5 insertions(+), 10 deletions(-)
diff --git
a/initializer-generator/src/main/java/com/alibaba/initializer/generation/extension/DockerfileCodeContributor.java
b/initializer-generator/src/main/java/com/alibaba/initializer/generation/extension/DockerfileCodeContributor.java
index c11c70a..134d287 100644
---
a/initializer-generator/src/main/java/com/alibaba/initializer/generation/extension/DockerfileCodeContributor.java
+++
b/initializer-generator/src/main/java/com/alibaba/initializer/generation/extension/DockerfileCodeContributor.java
@@ -34,7 +34,7 @@ import java.nio.file.StandardOpenOption;
import java.util.Map;
public class DockerfileCodeContributor implements ProjectContributor {
- private static final String DOCKERFILE_PATH = "/docker/Dockerfile";
+ private static final String DOCKERFILE_PATH = "/docker/";
public static final String PLACEHOLDER = "${JDK_IMAGE}";
private static final Map<String, String> JDK_IMAGE_VERSIONS = Map.of(
@@ -62,15 +62,10 @@ public class DockerfileCodeContributor implements
ProjectContributor {
}
private void writeDockerfile(Path projectRoot, String dockerFileName) {
- URL url = getClass().getResource(DOCKERFILE_PATH);
- if (url == null) {
- throw new IllegalArgumentException("Resource not found on
classpath: " + DOCKERFILE_PATH);
- }
-
- try {
- URI uri = url.toURI();
+ try (InputStream in = getClass().getResourceAsStream(DOCKERFILE_PATH +
dockerFileName)) {
// Read the file content
- String dockerFileTemplate = Files.readString(Paths.get(uri));
+ assert in != null;
+ String dockerFileTemplate = new String(in.readAllBytes());
// Replace the placeholders
String dockerFileContent = dockerFileTemplate.replace(PLACEHOLDER,
JDK_IMAGE_VERSIONS.get(description.getLanguage().jvmVersion()));
@@ -81,7 +76,7 @@ public class DockerfileCodeContributor implements
ProjectContributor {
writer.write(dockerFileContent);
}
} catch (Exception e) {
- throw new FileSystemNotFoundException("Resource is not located in
the file system: " + e.getMessage());
+ throw new RuntimeException("Resource is not located in the file
system: " + e.getMessage(), e);
}
}