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.
*/
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.
*/
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);
}
} 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);
}
}
}
}
}
} catch (IOException e) {
- getLogger().log(Level.WARNING, "Error parsing jar file", e);
+ error("Error parsing jar file", e);
}
}
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++) {
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;
}
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) {
}
}
} 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;
*/
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)));
}
}
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();
+ }
}
}
}
* 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);
+ }
}
}