From: Artur Signell Date: Fri, 23 Sep 2016 19:08:39 +0000 (+0300) Subject: Fix widget set builder to create widget set in correct location (#20320) X-Git-Tag: 7.7.3~3 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=977cec7e3107c2da306d46449dbf32f6544313be;p=vaadin-framework.git Fix widget set builder to create widget set in correct location (#20320) 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 --- diff --git a/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java b/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java index fefdf18e70..1f69de073e 100644 --- a/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java +++ b/server/src/main/java/com/vaadin/server/widgetsetutils/ClassPathExplorer.java @@ -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;