]> source.dussan.org Git - vaadin-framework.git/commitdiff
Support on-the-fly compiled CSS hot reload from classpath (#16949)
authorVladimir Kulev <me@lightoze.net>
Mon, 16 Nov 2015 22:40:27 +0000 (00:40 +0200)
committerVladimir Kulev <me@lightoze.net>
Tue, 17 Nov 2015 09:14:35 +0000 (11:14 +0200)
Change-Id: Iadb9b23697c162705d99a7b9b7fd992766d39b19

server/src/com/vaadin/server/VaadinServlet.java

index 61df02feaae7a1f9fd55e4c2c1cc57982de8406b..e7799dac672e1a603214df1743f68e7bdc52b9b3 100644 (file)
@@ -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<String> 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;