Skip to content

Instantly share code, notes, and snippets.

@joschi
Created February 20, 2013 10:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joschi/4994511 to your computer and use it in GitHub Desktop.
Save joschi/4994511 to your computer and use it in GitHub Desktop.
Source diff between OneJAR 0.97 and 0.97.1.
diff -ru 0.97/src/com/simontuffs/onejar/Boot.java 0.97.1/src/com/simontuffs/onejar/Boot.java
--- 0.97/src/com/simontuffs/onejar/Boot.java 2011-05-04 12:57:38.000000000 +0200
+++ 0.97.1/src/com/simontuffs/onejar/Boot.java 2012-08-14 21:46:30.000000000 +0200
@@ -12,6 +12,7 @@
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
+import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
@@ -50,6 +51,8 @@
* @author simon@simontuffs.com (<a href="http://www.simontuffs.com">http://www.simontuffs.com</a>)
*/
public class Boot {
+
+ private final static Logger LOGGER = Logger.getLogger("Boot");
/**
* The name of the manifest attribute which controls which class
@@ -80,6 +83,7 @@
public final static String P_VERBOSE = PROPERTY_PREFIX + "verbose";
public final static String P_INFO = PROPERTY_PREFIX + "info";
public final static String P_WARNING = PROPERTY_PREFIX + "warning";
+ public final static String P_SILENT = PROPERTY_PREFIX + "silent";
public final static String P_STATISTICS = PROPERTY_PREFIX + "statistics";
public final static String P_SHOW_PROPERTIES = PROPERTY_PREFIX + "show.properties";
public final static String P_JARPATH = PROPERTY_PREFIX + "jar.path";
@@ -100,7 +104,8 @@
"false: Recorded classes are flattened into a single directory. \nDuplicates are ignored (first wins)",
P_VERBOSE, "true: Print verbose classloading information",
P_INFO, "true: Print informative classloading information",
- P_WARNING, "true: Print serious classloading warnings",
+ P_WARNING, "true: Print serious classloading warnings",
+ P_SILENT, "true: Don't print any output",
P_STATISTICS, "true: Shows statistics about the One-Jar Classloader",
P_JARPATH, "Full path of the one-jar file being executed. \nOnly needed if java.class.path does not contain the path to the jar, e.g. on Max OS/X.",
P_ONE_JAR_CLASS_PATH, "Extra classpaths to be added to the execution environment. \nUse platform independent path separator '" + P_PATH_SEPARATOR + "'",
@@ -115,7 +120,7 @@
protected static String mainJar;
- protected static boolean warning = true, info, verbose, statistics;
+ protected static boolean statistics;
protected static String myJarPath;
protected static long startTime = System.currentTimeMillis();
@@ -148,18 +153,6 @@
loader = $loader;
}
- protected static void VERBOSE(String message) {
- if (verbose) System.out.println("Boot: " + message);
- }
-
- protected static void WARNING(String message) {
- System.err.println("Boot: Warning: " + message);
- }
-
- protected static void INFO(String message) {
- if (info) System.out.println("Boot: Info: " + message);
- }
-
protected static void PRINTLN(String message) {
System.out.println("Boot: " + message);
}
@@ -172,38 +165,16 @@
args = processArgs(args);
+ initializeLogging();
+
// Is the main class specified on the command line? If so, boot it.
// Otherwise, read the main class out of the manifest.
String mainClass = null;
- {
- // Default properties are in resource 'one-jar.properties'.
- Properties properties = new Properties();
- String props = "one-jar.properties";
- InputStream is = Boot.class.getResourceAsStream("/" + props);
- if (is != null) {
- INFO("loading properties from " + props);
- properties.load(is);
- }
-
- // Merge in anything in a local file with the same name.
- if (new File(props).exists()) {
- is = new FileInputStream(props);
- if (is != null) {
- INFO("merging properties from " + props);
- properties.load(is);
- }
- }
-
- // Set system properties only if not already specified.
- Enumeration _enum = properties.propertyNames();
- while (_enum.hasMoreElements()) {
- String name = (String)_enum.nextElement();
- if (System.getProperty(name) == null) {
- System.setProperty(name, properties.getProperty(name));
- }
- }
- }
+ initializeProperties();
+ // Reinitialze Logging (property file could have other loglevel set)
+ initializeLogging();
+
if (Boolean.valueOf(System.getProperty(P_SHOW_PROPERTIES, "false")).booleanValue()) {
// What are the system properties.
Properties props = System.getProperties();
@@ -257,7 +228,7 @@
if (mainClass == null) {
mainClass = attributes.getValue(BOOT_CLASS);
if (mainClass != null) {
- WARNING("The manifest attribute " + BOOT_CLASS + " is deprecated in favor of the attribute " + ONE_JAR_MAIN_CLASS);
+ LOGGER.warning("The manifest attribute " + BOOT_CLASS + " is deprecated in favor of the attribute " + ONE_JAR_MAIN_CLASS);
}
}
}
@@ -277,7 +248,7 @@
// There is no main jar. Info unless mainJar is empty string.
// The load(mainClass) will scan for main jars anyway.
if (!"".equals(mainJar)){
- INFO("Unable to locate main jar '" + mainJar + "' in the JAR file " + getMyJarPath());
+ LOGGER.info("Unable to locate main jar '" + mainJar + "' in the JAR file " + getMyJarPath());
}
}
}
@@ -299,12 +270,12 @@
final String wrapLoader = jis.getManifest().getMainAttributes().getValue(WRAP_CLASS_LOADER);
jis.close();
if (wrapLoader == null) {
- WARNING(url + " did not contain a " + WRAP_CLASS_LOADER + " attribute, unable to load wrapping classloader");
+ LOGGER.warning(url + " did not contain a " + WRAP_CLASS_LOADER + " attribute, unable to load wrapping classloader");
} else {
- INFO("using " + wrapLoader);
+ LOGGER.info("using " + wrapLoader);
JarClassLoader wrapped = getWrapLoader(bootLoader, wrapLoader);
if (wrapped == null) {
- WARNING("Unable to instantiate " + wrapLoader + " from " + WRAP_DIR + ": using default JarClassLoader");
+ LOGGER.warning("Unable to instantiate " + wrapLoader + " from " + WRAP_DIR + ": using default JarClassLoader");
wrapped = getBootLoader(null);
}
setClassLoader(wrapped);
@@ -312,7 +283,7 @@
}
} else {
setClassLoader(getBootLoader(bootLoaderName, Boot.class.getClassLoader()));
- INFO("using JarClassLoader: " + getClassLoader().getClass().getName());
+ LOGGER.info("using JarClassLoader: " + getClassLoader().getClass().getName());
}
// Allow injection of the URL factory.
@@ -343,6 +314,48 @@
}
}
+ private static void initializeProperties() throws IOException,
+ FileNotFoundException {
+ {
+ // Default properties are in resource 'one-jar.properties'.
+ Properties properties = new Properties();
+ String props = "one-jar.properties";
+ InputStream is = Boot.class.getResourceAsStream("/" + props);
+ if (is != null) {
+ LOGGER.info("loading properties from " + props);
+ properties.load(is);
+ }
+
+ // Merge in anything in a local file with the same name.
+ if (new File(props).exists()) {
+ is = new FileInputStream(props);
+ if (is != null) {
+ LOGGER.info("merging properties from " + props);
+ properties.load(is);
+ }
+ }
+
+ // Set system properties only if not already specified.
+ Enumeration _enum = properties.propertyNames();
+ while (_enum.hasMoreElements()) {
+ String name = (String)_enum.nextElement();
+ if (System.getProperty(name) == null) {
+ System.setProperty(name, properties.getProperty(name));
+ }
+ }
+ }
+ }
+
+ private static void initializeLogging() {
+ if (Boolean.valueOf(System.getProperty(P_VERBOSE, "false")).booleanValue()) {
+ Logger.setLevel(Logger.LOGLEVEL_VERBOSE);
+ } else if (Boolean.valueOf(System.getProperty(P_INFO, "false")).booleanValue()) {
+ Logger.setLevel(Logger.LOGLEVEL_INFO);
+ } else if (Boolean.valueOf(System.getProperty(P_SILENT, "false")).booleanValue()) {
+ Logger.setLevel(Logger.LOGLEVEL_NONE);
+ }
+ }
+
public static void showTime() {
long endtime = System.currentTimeMillis();
if (statistics) {
@@ -351,7 +364,7 @@
}
public static void setProperties(IProperties jarloader) {
- INFO("setProperties(" + jarloader + ")");
+ LOGGER.info("setProperties(" + jarloader + ")");
if (getProperty(P_RECORD, "false")) {
jarloader.setRecord(true);
jarloader.setRecording(System.getProperty(P_RECORD));
@@ -360,14 +373,6 @@
jarloader.setRecord(true);
jarloader.setFlatten(false);
}
- // TODO: clean up the use of one-jar.{verbose,info,warning} properties.
- if (verbose = getProperty(P_VERBOSE, "false")) {
- jarloader.setVerbose(true);
- jarloader.setInfo(true);
- }
- jarloader.setInfo(info=getProperty(P_INFO, "false"));
- jarloader.setWarning(warning=getProperty(P_WARNING, "true"));
-
statistics = getProperty(P_STATISTICS, "false");
}
@@ -398,7 +403,7 @@
String jars[] =jarname.split(System.getProperty("path.separator"));
for (int i=0; i<jars.length; i++) {
jarname = jars[i];
- VERBOSE("Checking " + jarname + " as One-Jar file");
+ LOGGER.fine("Checking " + jarname + " as One-Jar file");
// Allow for URL based paths, as well as file-based paths. File
InputStream is = null;
try {
@@ -427,7 +432,7 @@
}
} catch (Exception x) {
x.printStackTrace();
- WARNING("jar=" + myJarPath + " loaded from " + P_JAVA_CLASS_PATH + " (" + System.getProperty(P_JAVA_CLASS_PATH) + ")");
+ LOGGER.warning("jar=" + myJarPath + " loaded from " + P_JAVA_CLASS_PATH + " (" + System.getProperty(P_JAVA_CLASS_PATH) + ")");
}
}
if (myJarPath == null) {
@@ -452,7 +457,7 @@
Enumeration entries = zip.entries();
while (entries.hasMoreElements()) {
ZipEntry entry = (ZipEntry) entries.nextElement();
- VERBOSE(("findZipEntry(): entry=" + entry.getName()));
+ LOGGER.fine(("findZipEntry(): entry=" + entry.getName()));
if (entry.getName().equals(name))
return entry;
}
@@ -485,7 +490,7 @@
public static String[] processArgs(String args[]) throws Exception {
// Check for arguments which matter to us, and strip them.
- VERBOSE("processArgs(" + Arrays.asList(args) + ")");
+ LOGGER.fine("processArgs(" + Arrays.asList(args) + ")");
ArrayList list = new ArrayList();
for (int a=0; a<args.length; a++) {
String argument = args[a];
@@ -536,7 +541,7 @@
Constructor ctor = cls.getConstructor(new Class[]{String.class});
return ctor.newInstance(new Object[]{WRAP_DIR});
} catch (Exception x) {
- WARNING("Unable to instantiate " + loader + ": " + x + " continuing using default " + JarClassLoader.class.getName());
+ LOGGER.warning("Unable to instantiate " + loader + ": " + x + " continuing using default " + JarClassLoader.class.getName());
}
}
return new JarClassLoader(WRAP_DIR);
@@ -556,7 +561,7 @@
Constructor ctor = cls.getConstructor(new Class[]{ClassLoader.class});
return ctor.newInstance(new Object[]{Boot.class.getClassLoader()});
} catch (Exception x) {
- WARNING("Unable to instantiate " + loader + ": " + x + " continuing using default " + JarClassLoader.class.getName());
+ LOGGER.warning("Unable to instantiate " + loader + ": " + x + " continuing using default " + JarClassLoader.class.getName());
}
}
return new JarClassLoader(Boot.class.getClassLoader());
@@ -574,7 +579,7 @@
Constructor ctor = jarLoaderClass.getConstructor(new Class[]{ClassLoader.class});
return ctor.newInstance(new Object[]{bootLoader});
} catch (Throwable t) {
- WARNING(t.toString());
+ LOGGER.warning(t.toString());
}
return null;
}
diff -ru 0.97/src/com/simontuffs/onejar/IProperties.java 0.97.1/src/com/simontuffs/onejar/IProperties.java
--- 0.97/src/com/simontuffs/onejar/IProperties.java 2011-05-04 12:15:56.000000000 +0200
+++ 0.97.1/src/com/simontuffs/onejar/IProperties.java 2012-08-14 21:46:30.000000000 +0200
@@ -10,6 +10,7 @@
public void setVerbose(boolean verbose);
public void setInfo(boolean info);
public void setWarning(boolean warn);
+ public void setSilent(boolean silent);
public void setRecord(boolean record);
public void setFlatten(boolean flatten);
public void setRecording(String recording);
diff -ru 0.97/src/com/simontuffs/onejar/JarClassLoader.java 0.97.1/src/com/simontuffs/onejar/JarClassLoader.java
--- 0.97/src/com/simontuffs/onejar/JarClassLoader.java 2011-05-04 12:17:48.000000000 +0200
+++ 0.97.1/src/com/simontuffs/onejar/JarClassLoader.java 2012-08-14 21:46:30.000000000 +0200
@@ -71,6 +71,8 @@
* @author simon@simontuffs.com (<a href="http://www.simontuffs.com">http://www.simontuffs.com</a>)
*/
public class JarClassLoader extends ClassLoader implements IProperties {
+
+ private final static Logger LOGGER = Logger.getLogger("JarClassLoader");
public final static String LIB_PREFIX = "lib/";
public final static String BINLIB_PREFIX = "binlib/";
@@ -104,31 +106,11 @@
}
- protected String PREFIX() {
- return "JarClassLoader: ";
- }
-
- protected String NAME() {
- return (name != null? "'" + name + "' ": "");
- }
-
- protected void VERBOSE(String message) {
- if (verbose) System.out.println(PREFIX() + NAME() + message);
- }
-
- protected void WARNING(String message) {
- if (warning) System.err.println(PREFIX() + "Warning: " + NAME() + message);
- }
-
- protected void INFO(String message) {
- if (info) System.out.println(PREFIX() + "Info: " + NAME() + message);
- }
-
- protected void PRINTLN(String message) {
+ protected static void PRINTLN(String message) {
System.out.println(message);
}
- protected void PRINT(String message) {
+ protected static void PRINT(String message) {
System.out.print(message);
}
@@ -140,7 +122,6 @@
protected Set jarNames = Collections.synchronizedSet(new HashSet());
protected boolean record = false, flatten = false, unpackFindResource = false;
- protected boolean verbose = false, info = false, warning = true;
protected String recording = RECORDING;
protected String jarName, mainJar, wrapDir;
@@ -265,17 +246,17 @@
// toURI() takes care of adding the trailing slash in this case so everything's ok
list.add(new File(_path).toURI().toURL());
} catch (MalformedURLException ignore) {
- Boot.WARNING("Unable to parse external path: " + path);
+ LOGGER.warning("Unable to parse external path: " + path);
} catch (IOException ignore) {
- Boot.WARNING("Unable to parse external path: " + path);
+ LOGGER.warning("Unable to parse external path: " + path);
} catch (IllegalArgumentException ignore) {
// won't happen File.toURI() returns an absolute URI
- Boot.WARNING("Unable to parse external path: " + path);
+ LOGGER.warning("Unable to parse external path: " + path);
}
}
}
URL urls[] = (URL[])list.toArray(new URL[0]);
- Boot.INFO("external URLs=" + Arrays.asList(urls));
+ LOGGER.info("external URLs=" + Arrays.asList(urls));
// BUG-2833948
// Delegate back into this classloader, use ThreadLocal to avoid recursion.
externalClassLoader = new URLClassLoader(urls, this) {
@@ -289,7 +270,7 @@
if (reentered(LOAD_CLASS + name)) {
throw new ClassNotFoundException(name);
}
- VERBOSE("externalClassLoader.loadClass(" + name + ")");
+ LOGGER.fine("externalClassLoader.loadClass(" + name + ")");
Object old = current.get();
current.set(LOAD_CLASS + name);
try {
@@ -301,7 +282,7 @@
public URL getResource(String name) {
if (reentered(GET_RESOURCE + name))
return null;
- VERBOSE("externalClassLoader.getResource(" + name + ")");
+ LOGGER.fine("externalClassLoader.getResource(" + name + ")");
Object old = current.get();
current.set(GET_RESOURCE + name);
try {
@@ -313,7 +294,7 @@
public URL findResource(String name) {
if (reentered(FIND_RESOURCE + name))
return null;
- VERBOSE("externalClassLoader.findResource(" + name + ")");
+ LOGGER.fine("externalClassLoader.findResource(" + name + ")");
Object old = current.get();
current.set(name);
try {
@@ -339,7 +320,7 @@
}
public String load(String mainClass, String jarName) {
- VERBOSE("load("+mainClass+","+jarName+")");
+ LOGGER.fine("load("+mainClass+","+jarName+")");
if (record) {
new File(recording).mkdirs();
}
@@ -375,7 +356,7 @@
File tmpdir = new File(expanddir);
if (noExpand == false && expand != null) {
expanded = true;
- VERBOSE(EXPAND + "=" + expand);
+ LOGGER.fine(EXPAND + "=" + expand);
expandPaths = expand.split(",");
boolean getconfirm = Boolean.TRUE.toString().equals(manifest.getMainAttributes().getValue(CONFIRM_EXPAND));
if (getconfirm) {
@@ -414,14 +395,14 @@
if (showexpand) {
PRINTLN(msg);
} else {
- INFO(msg);
+ LOGGER.info(msg);
}
- if (dest.exists()) INFO("Update because lastModified=" + new Date(dest.lastModified()) + ", entry=" + new Date(entry.getTime()));
+ if (dest.exists()) LOGGER.info("Update because lastModified=" + new Date(dest.lastModified()) + ", entry=" + new Date(entry.getTime()));
File parent = dest.getParentFile();
if (parent != null) {
parent.mkdirs();
}
- VERBOSE("using jarFile.getInputStream(" + entry + ")");
+ LOGGER.fine("using jarFile.getInputStream(" + entry + ")");
InputStream is = jarFile.getInputStream(entry);
FileOutputStream os = new FileOutputStream(dest);
copy(is, os);
@@ -432,7 +413,7 @@
if (showexpand) {
PRINTLN(msg);
} else {
- VERBOSE(msg);
+ LOGGER.fine(msg);
}
}
}
@@ -441,8 +422,8 @@
if (wrapDir != null && $entry.startsWith(wrapDir) || $entry.startsWith(LIB_PREFIX) || $entry.startsWith(MAIN_PREFIX)) {
if (wrapDir != null && !entry.getName().startsWith(wrapDir)) continue;
// Load it!
- VERBOSE("caching " + $entry);
- VERBOSE("using jarFile.getInputStream(" + entry + ")");
+ LOGGER.fine("caching " + $entry);
+ LOGGER.fine("using jarFile.getInputStream(" + entry + ")");
{
// Note: loadByteCode consumes the input stream, so make sure its scope
// does not extend beyond here.
@@ -464,8 +445,8 @@
mainJar = $entry;
}
} else if (mainJar != null) {
- WARNING("A main class is defined in multiple jar files inside " + MAIN_PREFIX + mainJar + " and " + $entry);
- WARNING("The main class " + mainClass + " from " + mainJar + " will be used");
+ LOGGER.warning("A main class is defined in multiple jar files inside " + MAIN_PREFIX + mainJar + " and " + $entry);
+ LOGGER.warning("The main class " + mainClass + " from " + mainJar + " will be used");
}
}
} else if (wrapDir == null && $entry.startsWith(UNPACK)) {
@@ -478,7 +459,7 @@
File dir = new File(TMP);
File sentinel = new File(dir, $entry.replace('/', '.'));
if (!sentinel.exists()) {
- INFO("unpacking " + $entry + " into " + dir.getCanonicalPath());
+ LOGGER.info("unpacking " + $entry + " into " + dir.getCanonicalPath());
loadByteCode(is, $entry, TMP);
sentinel.getParentFile().mkdirs();
sentinel.createNewFile();
@@ -486,11 +467,11 @@
} else if ($entry.endsWith(CLASS)) {
// A plain vanilla class file rooted at the top of the jar file.
loadBytes(entry, jarFile.getInputStream(entry), "/", null, manifest);
- VERBOSE("One-Jar class: " + jarFile.getName() + "!/" + entry.getName());
+ LOGGER.fine("One-Jar class: " + jarFile.getName() + "!/" + entry.getName());
} else {
// A resource?
loadBytes(entry, jarFile.getInputStream(entry), "/", null, manifest);
- VERBOSE("One-Jar resource: " + jarFile.getName() + "!/" + entry.getName());
+ LOGGER.fine("One-Jar resource: " + jarFile.getName() + "!/" + entry.getName());
}
}
// If mainClass is still not defined, return null. The caller is then responsible
@@ -535,7 +516,7 @@
// TODO: implement lazy loading of bytecode.
Manifest manifest = jis.getManifest();
if (manifest == null) {
- WARNING("Null manifest from input stream associated with: " + jar);
+ LOGGER.warning("Null manifest from input stream associated with: " + jar);
}
while ((entry = jis.getNextJarEntry()) != null) {
// if (entry.isDirectory()) continue;
@@ -594,7 +575,7 @@
if (type.equals("class")) {
if (alreadyCached(entryName, jar, baos)) return;
byteCode.put(entryName, new ByteCode(entryName, entry.getName(), baos, jar, man));
- VERBOSE("cached bytes for class " + entryName);
+ LOGGER.fine("cached bytes for class " + entryName);
} else {
// Another kind of resource. Cache this by name, and also prefixed
// by the jar name. Don't duplicate the bytes. This allows us
@@ -604,13 +585,13 @@
// Keep a set of jar names so we can do multiple-resource lookup by name
// as in findResources().
jarNames.add(jar);
- VERBOSE("cached bytes for local name " + localname);
+ LOGGER.fine("cached bytes for local name " + localname);
// Only keep the first non-local entry: this is like classpath where the first
// to define wins.
if (alreadyCached(entryName, jar, baos)) return;
byteCode.put(entryName, new ByteCode(entryName, entry.getName(), baos, jar, man));
- VERBOSE("cached bytes for entry name " + entryName);
+ LOGGER.fine("cached bytes for entry name " + entryName);
}
}
@@ -651,11 +632,11 @@
// Look up the class in the byte codes.
// Translate path?
- VERBOSE("findClass(" + name + ")");
+ LOGGER.fine("findClass(" + name + ")");
String cache = name.replace('.', '/') + CLASS;
ByteCode bytecode = (ByteCode)byteCode.get(cache);
if (bytecode != null) {
- VERBOSE("found " + name + " in codebase '" + bytecode.codebase + "'");
+ LOGGER.fine("found " + name + " in codebase '" + bytecode.codebase + "'");
if (record) {
record(bytecode);
}
@@ -709,7 +690,7 @@
return defineClass(name, bytes, pd);
}
- VERBOSE(name + " not found");
+ LOGGER.fine(name + " not found");
throw new ClassNotFoundException(name);
}
@@ -799,7 +780,7 @@
protected Class defineClass(String name, byte[] bytes, ProtectionDomain pd) throws ClassFormatError {
// Simple, non wrapped class definition.
- VERBOSE("defineClass("+name+")");
+ LOGGER.fine("defineClass("+name+")");
return defineClass(name, bytes, 0, bytes.length, pd);
}
@@ -810,14 +791,14 @@
File file = new File(dir, fileName);
if (!file.exists()) {
file.getParentFile().mkdirs();
- VERBOSE("" + file);
+ LOGGER.fine("" + file);
try {
FileOutputStream fos = new FileOutputStream(file);
fos.write(bytecode.bytes);
fos.close();
} catch (IOException iox) {
- System.err.println(PREFIX() + "unable to record " + file + ": " + iox);
+ LOGGER.severe("unable to record " + file + ": " + iox);
}
}
@@ -859,7 +840,7 @@
*/
public InputStream getByteStream(String resource) {
- VERBOSE("getByteStream(" + resource + ")");
+ LOGGER.fine("getByteStream(" + resource + ")");
InputStream result = null;
if (externalClassLoader != null) {
@@ -893,7 +874,7 @@
if (result == null) {
if (jarNames.contains(resource)) {
// resource wanted is an actual jar
- INFO("loading resource file directly" + resource);
+ LOGGER.info("loading resource file directly" + resource);
result = super.getResourceAsStream(resource);
}
}
@@ -914,7 +895,7 @@
result = parentClassLoader.getResourceAsStream(resource);
}
}
- VERBOSE("getByteStream(" + resource + ") -> " + result);
+ LOGGER.fine("getByteStream(" + resource + ") -> " + result);
return result;
}
@@ -946,7 +927,7 @@
resource = $resource;
}
}
- VERBOSE("resource " + $resource + " resolved to " + resource + (callerCode != null? " in codebase " + callerCode.codebase: " (unknown codebase)"));
+ LOGGER.fine("resource " + $resource + " resolved to " + resource + (callerCode != null? " in codebase " + callerCode.codebase: " (unknown codebase)"));
return resource;
}
@@ -967,12 +948,12 @@
String message = existing.name + " in " + jar + " is hidden by " + existing.codebase + " (with different bytecode)";
if (name.endsWith(".class")) {
// This is probably trouble.
- WARNING(existing.name + " in " + jar + " is hidden by " + existing.codebase + " (with different bytecode)");
+ LOGGER.warning(existing.name + " in " + jar + " is hidden by " + existing.codebase + " (with different bytecode)");
} else {
- INFO(existing.name + " in " + jar + " is hidden by " + existing.codebase + " (with different bytes)");
+ LOGGER.info(existing.name + " in " + jar + " is hidden by " + existing.codebase + " (with different bytes)");
}
} else {
- VERBOSE(existing.name + " in " + jar + " is hidden by " + existing.codebase + " (with same bytecode)");
+ LOGGER.fine(existing.name + " in " + jar + " is hidden by " + existing.codebase + " (with same bytecode)");
}
// Speedup GC.
bytes = null;
@@ -992,7 +973,7 @@
// classloader classes.
for (int i=0; i<stack.length; i++) {
String cls = stack[i].getClassName().replace(".","/") + ".class";
- INFO("getCaller(): cls=" + cls);
+ LOGGER.info("getCaller(): cls=" + cls);
if (byteCode.get(cls) != null) {
String caller = stack[i].getClassName();
if (!caller.startsWith("com.simontuffs.onejar")) {
@@ -1034,28 +1015,34 @@
return flatten;
}
- public void setVerbose(boolean $verbose) {
- verbose = $verbose;
- if (verbose) info = true;
+ public void setVerbose(boolean verbose) {
+ if (verbose) {
+ Logger.setLevel(Logger.LOGLEVEL_VERBOSE);
+ } else {
+ setInfo(true);
+ }
}
- public boolean getVerbose() {
- return verbose;
+ public void setWarning(boolean warning) {
+ if (warning) {
+ Logger.setLevel(Logger.LOGLEVEL_WARN);
+ } else {
+ setInfo(true);
+ }
}
-
- public void setInfo(boolean $info) {
- info = $info;
+
+ public void setInfo(boolean info) {
+ Logger.setLevel(Logger.LOGLEVEL_INFO);
}
- public boolean getInfo() {
- return info;
+
+ public void setSilent(boolean silent) {
+ if (silent) {
+ Logger.setLevel(Logger.LOGLEVEL_NONE);
+ } else {
+ setInfo(true);
+ }
}
- public void setWarning(boolean $warning) {
- warning = $warning;
- }
- public boolean getWarning() {
- return warning;
- }
protected URLStreamHandler oneJarHandler = new Handler();
// Injectable URL factory.
@@ -1146,12 +1133,12 @@
// and findResources();
protected URL findResource(String $resource) {
try {
- VERBOSE("findResource(\"" + $resource + "\")");
+ LOGGER.fine("findResource(\"" + $resource + "\")");
URL url = externalClassLoader!=null ? externalClassLoader.getResource($resource) : null;
if (url != null)
{
- INFO("findResource() found in external: \"" + $resource + "\"");
- //VERBOSE("findResource(): " + $resource + "=" + url);
+ LOGGER.info("findResource() found in external: \"" + $resource + "\"");
+ //LOGGER.fine("findResource(): " + $resource + "=" + url);
return url;
}
// Delegate to parent.
@@ -1169,22 +1156,22 @@
if (resource != null) {
// We know how to handle it.
ByteCode entry = ((ByteCode) byteCode.get(resource));
- INFO("findResource() found: \"" + $resource + "\" for caller " + getCaller() + " in codebase " + entry.codebase);
+ LOGGER.info("findResource() found: \"" + $resource + "\" for caller " + getCaller() + " in codebase " + entry.codebase);
return urlFactory.getURL(entry.codebase, $resource);
}
- INFO("findResource(): unable to locate \"" + $resource + "\"");
+ LOGGER.info("findResource(): unable to locate \"" + $resource + "\"");
// If all else fails, return null.
return null;
} catch (MalformedURLException mux) {
- WARNING("unable to locate " + $resource + " due to " + mux);
+ LOGGER.warning("unable to locate " + $resource + " due to " + mux);
}
return null;
}
protected Enumeration findResources(String name) throws IOException {
- INFO("findResources(" + name + ")");
- INFO("findResources: looking in " + jarNames);
+ LOGGER.info("findResources(" + name + ")");
+ LOGGER.info("findResources: looking in " + jarNames);
Iterator iter = jarNames.iterator();
final List resources = new ArrayList();
while (iter.hasNext()) {
@@ -1192,7 +1179,7 @@
ByteCode entry = ((ByteCode) byteCode.get(resource));
if (byteCode.containsKey(resource)) {
URL url = urlFactory.getURL(entry.codebase, name);
- INFO("findResources(): Adding " + url + " to resources list.");
+ LOGGER.info("findResources(): Adding " + url + " to resources list.");
resources.add(url);
}
}
@@ -1289,14 +1276,14 @@
}
}//TODO Need some work for solaris
- VERBOSE("Using arch-specific native library path: " + binlib);
+ LOGGER.fine("Using arch-specific native library path: " + binlib);
String retValue = findTheLibrary(binlib, name);
if (retValue != null) {
- VERBOSE("Found in arch-specific directory!");
+ LOGGER.fine("Found in arch-specific directory!");
return retValue;
} else {
- VERBOSE("Search in standard native directory!");
+ LOGGER.fine("Search in standard native directory!");
return findTheLibrary(BINLIB_PREFIX, name);
}
}
@@ -1344,19 +1331,19 @@
os = new FileOutputStream(tempNativeLib);
copy(is, os);
os.close();
- VERBOSE("Stored native library " + name + " at " + tempNativeLib);
+ LOGGER.fine("Stored native library " + name + " at " + tempNativeLib);
result = tempNativeLib.getPath();
binLibPath.put(resourcePath, result);
} else {
// Library is not in the jar
// Return null by default to search the java.library.path
- VERBOSE("No native library at " + resourcePath +
+ LOGGER.fine("No native library at " + resourcePath +
"java.library.path will be searched instead.");
}
} catch(Throwable e) {
// Couldn't load the library
// Return null by default to search the java.library.path
- WARNING("Unable to load native library: " + e);
+ LOGGER.warning("Unable to load native library: " + e);
}
}
Nur in 0.97.1/src/com/simontuffs/onejar: Logger.java.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment