From: Artur Signell Date: Tue, 18 Jan 2011 09:27:54 +0000 (+0000) Subject: #5026 WidgetSetBuilder creates duplicate references to non-Vaadin GWT modules X-Git-Tag: 6.7.0.beta1~493 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=bfb4bd3ffe8136160ab3b277775c94d40ac5e62c;p=vaadin-framework.git #5026 WidgetSetBuilder creates duplicate references to non-Vaadin GWT modules svn changeset:16919/svn branch:6.5 --- diff --git a/src/com/vaadin/terminal/gwt/widgetsetutils/ClassPathExplorer.java b/src/com/vaadin/terminal/gwt/widgetsetutils/ClassPathExplorer.java index 0fa618ec4f..5bf6df1ea3 100644 --- a/src/com/vaadin/terminal/gwt/widgetsetutils/ClassPathExplorer.java +++ b/src/com/vaadin/terminal/gwt/widgetsetutils/ClassPathExplorer.java @@ -189,30 +189,36 @@ public class ClassPathExplorer { String[] files = directory.list(); for (int i = 0; i < files.length; i++) { // we are only interested in .gwt.xml files - if (files[i].endsWith(".gwt.xml")) { - // remove the extension - String classname = files[i].substring(0, - files[i].length() - 8); - String packageName = locationString - .substring(locationString.lastIndexOf("/") + 1); - classname = packageName + "." + classname; - if (!widgetsets.containsKey(classname)) { - String packagePath = packageName.replaceAll("\\.", "/"); - String basePath = location.getFile().replaceAll( - "/" + packagePath + "$", ""); - try { - URL url = new URL(location.getProtocol(), - location.getHost(), location.getPort(), - basePath); - widgetsets.put(classname, url); - } catch (MalformedURLException e) { - // should never happen as based on an existing URL, - // only changing end of file name/path part - logger.log( - Level.SEVERE, - "Error locating the widgetset " + classname, - e); - } + if (!files[i].endsWith(".gwt.xml")) { + continue; + } + + // remove the .gwt.xml extension + String classname = files[i].substring(0, files[i].length() - 8); + String packageName = locationString.substring(locationString + .lastIndexOf("/") + 1); + classname = packageName + "." + classname; + + if (!WidgetSetBuilder.isWidgetset(classname)) { + // Only return widgetsets and not GWT modules to avoid + // comparing modules and widgetsets + continue; + } + + if (!widgetsets.containsKey(classname)) { + String packagePath = packageName.replaceAll("\\.", "/"); + String basePath = location.getFile().replaceAll( + "/" + packagePath + "$", ""); + try { + URL url = new URL(location.getProtocol(), + location.getHost(), location.getPort(), + basePath); + widgetsets.put(classname, url); + } catch (MalformedURLException e) { + // should never happen as based on an existing URL, + // only changing end of file name/path part + logger.log(Level.SEVERE, + "Error locating the widgetset " + classname, e); } } } diff --git a/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetSetBuilder.java b/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetSetBuilder.java index 7eaee22073..9b9639d307 100644 --- a/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetSetBuilder.java +++ b/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetSetBuilder.java @@ -100,7 +100,7 @@ public class WidgetSetBuilder { if (isEditable(content)) { String originalContent = content; - Collection oldInheritedWidgetsets = getCurrentGwtModules(content); + Collection oldInheritedWidgetsets = getCurrentInheritedWidgetsets(content); // add widgetsets that do not exist Iterator i = availableWidgetSets.keySet().iterator(); @@ -153,21 +153,26 @@ public class WidgetSetBuilder { + "\" />" + "\n"); } - private static Collection getCurrentGwtModules(String content) { + private static Collection getCurrentInheritedWidgetsets( + String content) { HashSet hashSet = new HashSet(); Pattern inheritsPattern = Pattern.compile(" name=\"([^\"]*)\""); Matcher matcher = inheritsPattern.matcher(content); while (matcher.find()) { - String possibleWidgetSet = matcher.group(1); - if (possibleWidgetSet.toLowerCase().contains("widgetset")) { - hashSet.add(possibleWidgetSet); + String gwtModule = matcher.group(1); + if (isWidgetset(gwtModule)) { + hashSet.add(gwtModule); } } return hashSet; } + static boolean isWidgetset(String gwtModuleName) { + return gwtModuleName.toLowerCase().contains("widgetset"); + } + private static String readFile(File widgetsetFile) throws IOException { Reader fi = new FileReader(widgetsetFile); BufferedReader bufferedReader = new BufferedReader(fi);