-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #4971 from aloubyansky/4959
Platform Descriptor: load resources from a classloader instead of FileSystem
- Loading branch information
Showing
5 changed files
with
88 additions
and
34 deletions.
There are no files selected for viewing
22 changes: 22 additions & 0 deletions
22
...rc/main/java/io/quarkus/platform/descriptor/loader/json/impl/ClassPathResourceLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package io.quarkus.platform.descriptor.loader.json.impl; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public class ClassPathResourceLoader implements ResourceLoader { | ||
|
||
private final ClassLoader cl; | ||
|
||
public ClassPathResourceLoader(ClassLoader cl) { | ||
this.cl = cl; | ||
} | ||
|
||
@Override | ||
public InputStream getResourceAsStream(String name) throws IOException { | ||
final InputStream stream = cl.getResourceAsStream(name); | ||
if (stream == null) { | ||
throw new IOException("Failed to locate " + name + " on the classpath"); | ||
} | ||
return stream; | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
...rc/main/java/io/quarkus/platform/descriptor/loader/json/impl/DirectoryResourceLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package io.quarkus.platform.descriptor.loader.json.impl; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.file.Files; | ||
import java.nio.file.Path; | ||
|
||
public class DirectoryResourceLoader implements ResourceLoader { | ||
|
||
private final Path dir; | ||
|
||
public DirectoryResourceLoader(Path dir) { | ||
if (!Files.isDirectory(dir)) { | ||
throw new IllegalStateException("Failed to locate directory " + dir); | ||
} | ||
this.dir = dir; | ||
} | ||
|
||
@Override | ||
public InputStream getResourceAsStream(String name) throws IOException { | ||
Path resource = dir.resolve(name); | ||
if (!Files.exists(resource)) { | ||
throw new IOException("Failed to locate " + resource); | ||
} | ||
if (Files.isDirectory(resource)) { | ||
throw new IOException("Can't open a stream for path pointing to directory " + resource); | ||
} | ||
return Files.newInputStream(resource); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 9 additions & 0 deletions
9
...or-json/src/main/java/io/quarkus/platform/descriptor/loader/json/impl/ResourceLoader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.quarkus.platform.descriptor.loader.json.impl; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
public interface ResourceLoader { | ||
|
||
InputStream getResourceAsStream(String name) throws IOException; | ||
} |