]> source.dussan.org Git - vaadin-framework.git/commitdiff
Ensure widgetset compile messages go to stdout (#7516)
authorArtur Signell <artur@vaadin.com>
Fri, 20 Dec 2013 09:31:04 +0000 (11:31 +0200)
committerVaadin Code Review <review@vaadin.com>
Tue, 21 Jan 2014 06:43:46 +0000 (06:43 +0000)
Change-Id: Ibd6efa1db419e2dcf1d5f5d97c2a5c988d99a230

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

index cc04e50b3cf2dcede36dc0d9ba6bf1e3096c5f78..3ad76794de50c7f35d909dbba2e94c8b67034e4a 100644 (file)
@@ -32,8 +32,6 @@ import java.util.Set;
 import java.util.jar.Attributes;
 import java.util.jar.JarFile;
 import java.util.jar.Manifest;
-import java.util.logging.Level;
-import java.util.logging.Logger;
 
 /**
  * Utility class to collect widgetset related information from classpath.
@@ -111,6 +109,15 @@ public class ClassPathExplorer {
      */
     private static Map<String, URL> classpathLocations = getClasspathLocations(rawClasspathEntries);
 
+    private static boolean debug = false;
+
+    static {
+        String debugProperty = System.getProperty("debug");
+        if (debugProperty != null && !debugProperty.equals("")) {
+            debug = true;
+        }
+    }
+
     /**
      * No instantiation from outside, callable methods are static.
      */
@@ -163,9 +170,8 @@ public class ClassPathExplorer {
             sb.append("\n");
         }
 
-        final Logger logger = getLogger();
-        logger.info(sb.toString());
-        logger.info("Search took " + (end - start) + "ms");
+        log(sb.toString());
+        log("Search took " + (end - start) + "ms");
         return new LocationInfo(widgetsets, themes);
     }
 
@@ -226,8 +232,7 @@ public class ClassPathExplorer {
                     } catch (MalformedURLException e) {
                         // should never happen as based on an existing URL,
                         // only changing end of file name/path part
-                        getLogger().log(Level.SEVERE,
-                                "Error locating the widgetset " + classname, e);
+                        error("Error locating the widgetset " + classname, e);
                     }
                 }
             }
@@ -276,7 +281,7 @@ public class ClassPathExplorer {
                     }
                 }
             } catch (IOException e) {
-                getLogger().log(Level.WARNING, "Error parsing jar file", e);
+                error("Error parsing jar file", e);
             }
 
         }
@@ -304,7 +309,7 @@ public class ClassPathExplorer {
             classpath = classpath.substring(0, classpath.length() - 1);
         }
 
-        getLogger().log(Level.FINE, "Classpath: {0}", classpath);
+        debug("Classpath: " + classpath);
 
         String[] split = classpath.split(pathSep);
         for (int i = 0; i < split.length; i++) {
@@ -338,9 +343,8 @@ public class ClassPathExplorer {
             include(null, file, locations);
         }
         long end = System.currentTimeMillis();
-        Logger logger = getLogger();
-        if (logger.isLoggable(Level.FINE)) {
-            logger.fine("getClassPathLocations took " + (end - start) + "ms");
+        if (debug) {
+            debug("getClassPathLocations took " + (end - start) + "ms");
         }
         return locations;
     }
@@ -379,7 +383,8 @@ public class ClassPathExplorer {
                     url = new URL("jar:" + url.toExternalForm() + "!/");
                     JarURLConnection conn = (JarURLConnection) url
                             .openConnection();
-                    getLogger().fine(url.toString());
+                    debug(url.toString());
+
                     JarFile jarFile = conn.getJarFile();
                     Manifest manifest = jarFile.getManifest();
                     if (manifest != null) {
@@ -393,11 +398,13 @@ public class ClassPathExplorer {
                         }
                     }
                 } catch (MalformedURLException e) {
-                    getLogger().log(Level.FINEST, "Failed to inspect JAR file",
-                            e);
+                    if (debug) {
+                        error("Failed to inspect JAR file", e);
+                    }
                 } catch (IOException e) {
-                    getLogger().log(Level.FINEST, "Failed to inspect JAR file",
-                            e);
+                    if (debug) {
+                        error("Failed to inspect JAR file", e);
+                    }
                 }
 
                 return false;
@@ -489,14 +496,12 @@ public class ClassPathExplorer {
      */
     public static URL getDefaultSourceDirectory() {
 
-        final Logger logger = getLogger();
-
-        if (logger.isLoggable(Level.FINE)) {
-            logger.fine("classpathLocations values:");
+        if (debug) {
+            debug("classpathLocations values:");
             ArrayList<String> locations = new ArrayList<String>(
                     classpathLocations.keySet());
             for (String location : locations) {
-                logger.fine(String.valueOf(classpathLocations.get(location)));
+                debug(String.valueOf(classpathLocations.get(location)));
             }
         }
 
@@ -510,11 +515,15 @@ public class ClassPathExplorer {
                 try {
                     return new URL("file://" + directory.getCanonicalPath());
                 } catch (MalformedURLException e) {
-                    logger.log(Level.FINEST, "Ignoring exception", e);
                     // ignore: continue to the next classpath entry
+                    if (debug) {
+                        e.printStackTrace();
+                    }
                 } catch (IOException e) {
-                    logger.log(Level.FINEST, "Ignoring exception", e);
                     // ignore: continue to the next classpath entry
+                    if (debug) {
+                        e.printStackTrace();
+                    }
                 }
             }
         }
@@ -525,14 +534,24 @@ public class ClassPathExplorer {
      * Test method for helper tool
      */
     public static void main(String[] args) {
-        getLogger().info(
-                "Searching for available widgetsets and stylesheets...");
+        log("Searching for available widgetsets and stylesheets...");
 
         ClassPathExplorer.getAvailableWidgetSetsAndStylesheets();
     }
 
-    private static final Logger getLogger() {
-        return Logger.getLogger(ClassPathExplorer.class.getName());
+    private static void log(String message) {
+        System.out.println(message);
+    }
+
+    private static void error(String message, Exception e) {
+        System.err.println(message);
+        e.printStackTrace();
+    }
+
+    private static void debug(String message) {
+        if (debug) {
+            System.out.println(message);
+        }
     }
 
 }