summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTeemu Suo-Anttila <teemusa@vaadin.com>2016-03-22 16:11:25 +0200
committerelmot <elmot@vaadin.com>2016-04-14 13:36:26 +0300
commit578f77f4523c1ee838b0aa2a309f19c61cb90a8a (patch)
tree215526b842b18efd5ab06807be3ac762813b8861
parent27a02ad862436f8dbaf360397e6787853e3126c4 (diff)
downloadvaadin-framework-578f77f4523c1ee838b0aa2a309f19c61cb90a8a.tar.gz
vaadin-framework-578f77f4523c1ee838b0aa2a309f19c61cb90a8a.zip
Fix ClassPathExplorer widgetset source directory lookup (#19694)
Change-Id: I2daf32e0c49501ef3807fd694a641491b26d46bd
-rw-r--r--server/src/com/vaadin/server/widgetsetutils/ClassPathExplorer.java38
-rw-r--r--server/src/com/vaadin/server/widgetsetutils/WidgetSetBuilder.java11
2 files changed, 37 insertions, 12 deletions
diff --git a/server/src/com/vaadin/server/widgetsetutils/ClassPathExplorer.java b/server/src/com/vaadin/server/widgetsetutils/ClassPathExplorer.java
index 063f4f5346..255f34d936 100644
--- a/server/src/com/vaadin/server/widgetsetutils/ClassPathExplorer.java
+++ b/server/src/com/vaadin/server/widgetsetutils/ClassPathExplorer.java
@@ -495,7 +495,24 @@ public class ClassPathExplorer {
* @return URL
*/
public static URL getDefaultSourceDirectory() {
+ return getWidgetsetSourceDirectory(null);
+ }
+ /**
+ * Find and return the source directory which contains the given widgetset
+ * file.
+ *
+ * If not applicable or widgetsetFileName is null, return the first
+ * directory (not a JAR file etc.) on the classpath.
+ *
+ * TODO this could be done better...
+ *
+ * @param widgetsetFileName
+ * relative path for the widgetset
+ *
+ * @return URL
+ */
+ public static URL getWidgetsetSourceDirectory(String widgetsetFileName) {
if (debug) {
debug("classpathLocations values:");
ArrayList<String> locations = new ArrayList<String>(
@@ -505,6 +522,7 @@ public class ClassPathExplorer {
}
}
+ URL firstDirectory = null;
Iterator<String> it = rawClasspathEntries.iterator();
while (it.hasNext()) {
String entry = it.next();
@@ -513,13 +531,18 @@ public class ClassPathExplorer {
if (directory.exists() && !directory.isHidden()
&& directory.isDirectory()) {
try {
- return new URL("file://" + directory.getCanonicalPath());
- } catch (MalformedURLException e) {
- // ignore: continue to the next classpath entry
- if (debug) {
- e.printStackTrace();
+ URL directoryUrl = directory.toURI().toURL();
+
+ // Store the first directory encountered.
+ if (firstDirectory == null) {
+ firstDirectory = directoryUrl;
}
- } catch (IOException e) {
+
+ if (widgetsetFileName == null
+ || new File(directory, widgetsetFileName).exists()) {
+ return directoryUrl;
+ }
+ } catch (MalformedURLException e) {
// ignore: continue to the next classpath entry
if (debug) {
e.printStackTrace();
@@ -527,7 +550,8 @@ public class ClassPathExplorer {
}
}
}
- return null;
+
+ return firstDirectory;
}
/**
diff --git a/server/src/com/vaadin/server/widgetsetutils/WidgetSetBuilder.java b/server/src/com/vaadin/server/widgetsetutils/WidgetSetBuilder.java
index f810a63a38..b0d8cdd004 100644
--- a/server/src/com/vaadin/server/widgetsetutils/WidgetSetBuilder.java
+++ b/server/src/com/vaadin/server/widgetsetutils/WidgetSetBuilder.java
@@ -61,16 +61,17 @@ public class WidgetSetBuilder {
Map<String, URL> availableWidgetSets = ClassPathExplorer
.getAvailableWidgetSets();
+ String widgetsetFileName = widgetset.replace(".", "/") + ".gwt.xml";
URL sourceUrl = availableWidgetSets.get(widgetset);
if (sourceUrl == null) {
// find first/default source directory
- sourceUrl = ClassPathExplorer.getDefaultSourceDirectory();
+ sourceUrl = ClassPathExplorer
+ .getWidgetsetSourceDirectory(widgetsetFileName);
}
- String widgetsetfilename = sourceUrl.getFile() + "/"
- + widgetset.replace(".", "/") + ".gwt.xml";
+ String wsFullPath = sourceUrl.getFile() + "/" + widgetsetFileName;
- File widgetsetFile = new File(widgetsetfilename);
+ File widgetsetFile = new File(wsFullPath);
if (!widgetsetFile.exists()) {
// create empty gwt module file
File parent = widgetsetFile.getParentFile();
@@ -137,7 +138,7 @@ public class WidgetSetBuilder {
changed = changed || !content.equals(originalContent);
if (changed) {
- commitChanges(widgetsetfilename, content);
+ commitChanges(wsFullPath, content);
}
} else {
System.out