Skip to content

Commit

Permalink
#27 Env: implement Env.findResourcesJarOrFolder() to also support cla…
Browse files Browse the repository at this point in the history
…sspath URLs pointing into JAR files
  • Loading branch information
mvysny committed Sep 2, 2024
1 parent 73ae2ac commit 1c987b3
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 10 deletions.
26 changes: 17 additions & 9 deletions common/src/main/java/com/github/mvysny/vaadinboot/common/Env.java
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public static URL findWebRoot() throws MalformedURLException {
* @return the jar file or a directory from which the class files are being served.
*/
@NotNull
public static File findResourcesJarOrFolder(@NotNull URL webRoot) {
public static File findResourcesJarOrFolder(@NotNull URL webRoot) throws IOException {
final File file = FileUtils.toFile(webRoot);
if (file != null) {
// probably dev env: serving webroot from a directory
Expand All @@ -206,14 +206,22 @@ public static File findResourcesJarOrFolder(@NotNull URL webRoot) {
if (!"jar".equals(webRoot.getProtocol())) {
throw new IllegalArgumentException("Parameter webRoot: invalid value " + webRoot + ": unsupported URL type");
}
System.out.println("!!! " + webRoot.getPath());
try {
System.out.println("!!! " + webRoot.toURI().getPath());
System.out.println("!!! " + webRoot.toURI().resolve("..").getPath());
System.out.println("!!! " + webRoot.toURI().resolve(".."));
} catch (URISyntaxException e) {
throw new RuntimeException(e);
// path looks like: file:/mnt/disk1/mavi/work/my/vaadin-boot/testapp-tomcat/build/distributions/testapp-tomcat-12.4-SNAPSHOT/lib/testapp-tomcat-12.4-SNAPSHOT.jar!/webapp
final String path = webRoot.getPath();
if (!path.endsWith("!/webapp")) {
throw new IllegalStateException("Invalid state: unexpected path " + path);
}
final URL url = new URL(path.substring(0, path.length() - 8));
final File jarFile = FileUtils.toFile(url);
if (jarFile == null) {
throw new IllegalStateException("Invalid state: can't convert URL to file: " + url);
}
if (!jarFile.exists()) {
throw new IllegalStateException("Invalid state: doesn't exist: " + jarFile);
}
if (!jarFile.isFile()) {
throw new IllegalStateException("Invalid state: not a file: " + jarFile);
}
throw new UnsupportedOperationException();
return jarFile;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ protected Context createWebAppContext(@NotNull VaadinBootBase<?> configuration)
return ctx;
}

protected void addStaticWebapp(@NotNull WebResourceRoot root) throws MalformedURLException {
protected void addStaticWebapp(@NotNull WebResourceRoot root) throws IOException {
final URL webapp = Env.findWebRoot();
final File file = Env.findResourcesJarOrFolder(webapp);
if (file.isDirectory()) {
Expand Down

0 comments on commit 1c987b3

Please sign in to comment.