From: Vladimir Kulev Date: Mon, 16 Nov 2015 22:40:27 +0000 (+0200) Subject: Support on-the-fly compiled CSS hot reload from classpath (#16949) X-Git-Tag: 7.6.0.beta2~35 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=66f297fe1ad372c2e8904710cce5e069ac61897f;p=vaadin-framework.git Support on-the-fly compiled CSS hot reload from classpath (#16949) Change-Id: Iadb9b23697c162705d99a7b9b7fd992766d39b19 --- diff --git a/server/src/com/vaadin/server/VaadinServlet.java b/server/src/com/vaadin/server/VaadinServlet.java index 61df02feaa..e7799dac67 100644 --- a/server/src/com/vaadin/server/VaadinServlet.java +++ b/server/src/com/vaadin/server/VaadinServlet.java @@ -29,6 +29,7 @@ import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; import java.net.URLDecoder; +import java.net.URISyntaxException; import java.util.ArrayList; import java.util.Arrays; import java.util.Collection; @@ -65,7 +66,7 @@ import elemental.json.JsonObject; @SuppressWarnings("serial") public class VaadinServlet extends HttpServlet implements Constants { - private static class ScssCacheEntry implements Serializable { + private class ScssCacheEntry implements Serializable { private final String css; private final List sourceUris; @@ -119,13 +120,24 @@ public class VaadinServlet extends HttpServlet implements Constants { long newest = 0; for (String uri : sourceUris) { File file = new File(uri); + URL resource = getService().getClassLoader().getResource(uri); + long lastModified = -1L; if (file.exists()) { - newest = Math.max(newest, file.lastModified()); - } else if (!uri.startsWith("VAADIN/")) { + lastModified = file.lastModified(); + } else if (resource != null && resource.getProtocol().equals("file")) { + try { + file = new File(resource.toURI()); + if (file.exists()) { + lastModified = file.lastModified(); + } + } catch (URISyntaxException e) { + getLogger().log(Level.WARNING, "Could not resolve timestamp for " + resource, e); + } + } + if (lastModified == -1L && resource == null) { /* - * Ignore missing files starting with VAADIN/ since those - * are fetched from the classpath, report problem and abort - * for other files. + * Ignore missing files found in the classpath, + * report problem and abort for other files. */ getLogger() .log(Level.WARNING, @@ -134,6 +146,7 @@ public class VaadinServlet extends HttpServlet implements Constants { // -1 means this cache entry will never be valid return -1; } + newest = Math.max(newest, lastModified); } return newest;