]> source.dussan.org Git - vaadin-framework.git/commitdiff
Fix widget set builder to create widget set in correct location (#20320)
authorArtur Signell <artur@vaadin.com>
Fri, 23 Sep 2016 19:08:39 +0000 (22:08 +0300)
committerArtur Signell <artur@vaadin.com>
Sun, 25 Sep 2016 12:30:57 +0000 (15:30 +0300)
The fix for #20285 generates URLs so that the end in a slash, where the old
version generated URLs without the trailing slash. The trailing slash was not
taken into account by the code which updates a widget set.

Change-Id: Iabe716ed1632da7b2a6b1f4ffdc987c745d9452d

server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java

index fefdf18e70b3c868121c1b63da45762b224ba149..1f69de073e87c02e4168c9e0e08cbe56112253ea 100644 (file)
@@ -223,8 +223,21 @@ public class ClassPathExplorer {
 
                 if (!widgetsets.containsKey(classname)) {
                     String packagePath = packageName.replaceAll("\\.", "/");
-                    String basePath = location.getFile()
-                            .replaceAll("/" + packagePath + "$", "");
+
+                    String basePath = location.getFile();
+                    if (basePath.endsWith("/" + packagePath)) {
+                        basePath = basePath.replaceAll("/" + packagePath + "$",
+                                "");
+                    } else if (basePath.endsWith("/" + packagePath + "/")) {
+                        basePath = basePath.replaceAll("/" + packagePath + "/$",
+                                "");
+                    } else {
+                        throw new IllegalStateException(
+                                "Error trying to find base path, location ("
+                                        + location.getFile()
+                                        + ") does not end in expected '/"
+                                        + packagePath + "'");
+                    }
                     try {
                         URL url = new URL(location.getProtocol(),
                                 location.getHost(), location.getPort(),
@@ -453,8 +466,8 @@ public class ClassPathExplorer {
                         && !dirs[i].getPath().contains(File.separator + ".")) {
                     String key = dirs[i].getCanonicalPath() + "/" + name
                             + dirs[i].getName();
-                    locations.put(key,
-                            dirs[i].getCanonicalFile().toURI().toURL());
+                    URL url = dirs[i].getCanonicalFile().toURI().toURL();
+                    locations.put(key, url);
                 }
             } catch (Exception ioe) {
                 return;