From: Henri Sara Date: Wed, 28 Oct 2009 13:50:35 +0000 (+0000) Subject: Create widgetset in first suitable classpath directory - should be a source directory X-Git-Tag: 6.7.0.beta1~2368 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=4103157e7e88d6ea41839ddb5c20ca9176a662be;p=vaadin-framework.git Create widgetset in first suitable classpath directory - should be a source directory svn changeset:9430/svn branch:6.2 --- diff --git a/src/com/vaadin/terminal/gwt/widgetsetutils/ClassPathExplorer.java b/src/com/vaadin/terminal/gwt/widgetsetutils/ClassPathExplorer.java index 6a45860803..269d911ad1 100644 --- a/src/com/vaadin/terminal/gwt/widgetsetutils/ClassPathExplorer.java +++ b/src/com/vaadin/terminal/gwt/widgetsetutils/ClassPathExplorer.java @@ -7,10 +7,14 @@ import java.net.JarURLConnection; import java.net.MalformedURLException; import java.net.URL; import java.net.URLConnection; +import java.util.ArrayList; import java.util.Collection; import java.util.Enumeration; import java.util.HashMap; import java.util.HashSet; +import java.util.Iterator; +import java.util.LinkedHashMap; +import java.util.List; import java.util.Map; import java.util.Set; import java.util.jar.Attributes; @@ -50,7 +54,8 @@ public class ClassPathExplorer { } }; - private static Map classpathLocations = getClasspathLocations(); + private static List rawClasspathEntries = getRawClasspathEntries(); + private static Map classpathLocations = getClasspathLocations(rawClasspathEntries); private ClassPathExplorer() { } @@ -150,8 +155,9 @@ public class ClassPathExplorer { * Determine every URL location defined by the current classpath, and it's * associated package name. */ - private final static Map getClasspathLocations() { - Map locations = new HashMap(); + private final static List getRawClasspathEntries() { + // try to keep the order of the classpath + List locations = new ArrayList(); String pathSep = System.getProperty("path.separator"); String classpath = System.getProperty("java.class.path"); @@ -169,14 +175,28 @@ public class ClassPathExplorer { for (int i = 0; i < split.length; i++) { String classpathEntry = split[i]; if (acceptClassPathEntry(classpathEntry)) { - File file = new File(classpathEntry); - include(null, file, locations); + locations.add(classpathEntry); } } return locations; } + /** + * Determine every URL location defined by the current classpath, and it's + * associated package name. + */ + private final static Map getClasspathLocations( + List rawClasspathEntries) { + // try to keep the order of the classpath + Map locations = new LinkedHashMap(); + for (String classpathEntry : rawClasspathEntries) { + File file = new File(classpathEntry); + include(null, file, locations); + } + return locations; + } + private static boolean acceptClassPathEntry(String classpathEntry) { if (!classpathEntry.endsWith(".jar")) { // accept all non jars (practically directories) @@ -351,6 +371,41 @@ public class ClassPathExplorer { } } + /** + * Find and return the default source directory where to create new + * widgetsets. + * + * Return the first directory (not a JAR file etc.) on the classpath by + * default. + * + * TODO this could be done better... + * + * @return URL + */ + public static URL getDefaultSourceDirectory() { + System.err.println("classpathLocations keys: " + + classpathLocations.keySet()); + Iterator it = rawClasspathEntries.iterator(); + while (it.hasNext()) { + String entry = it.next(); + + File directory = new File(entry); + if (directory.exists() && !directory.isHidden() + && directory.isDirectory()) { + try { + return new URL("file://" + directory.getCanonicalPath()); + } catch (MalformedURLException e) { + e.printStackTrace(); + // ignore: continue to the next classpath entry + } catch (IOException e) { + e.printStackTrace(); + // ignore: continue to the next classpath entry + } + } + } + return null; + } + /** * Test method for helper tool */ diff --git a/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetSetBuilder.java b/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetSetBuilder.java index 6ce6097269..c6e9dd2275 100644 --- a/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetSetBuilder.java +++ b/src/com/vaadin/terminal/gwt/widgetsetutils/WidgetSetBuilder.java @@ -41,9 +41,14 @@ public class WidgetSetBuilder { .getAvailableWidgetSets(); URL sourceUrl = availableWidgetSets.get(widgetset); + if (sourceUrl == null) { + // find first/default source directory + sourceUrl = ClassPathExplorer.getDefaultSourceDirectory(); + } String widgetsetfilename = sourceUrl.getFile() + "/" + widgetset.replace(".", "/") + ".gwt.xml"; + File widgetsetFile = new File(widgetsetfilename); if (!widgetsetFile.exists()) { // create empty gwt module file