Use final.
This commit is contained in:
@@ -40,7 +40,7 @@ public class LogConfigurationException extends RuntimeException {
|
|||||||
*
|
*
|
||||||
* @param message The detail message
|
* @param message The detail message
|
||||||
*/
|
*/
|
||||||
public LogConfigurationException(String message) {
|
public LogConfigurationException(final String message) {
|
||||||
super(message);
|
super(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -50,7 +50,7 @@ public class LogConfigurationException extends RuntimeException {
|
|||||||
*
|
*
|
||||||
* @param cause The underlying cause
|
* @param cause The underlying cause
|
||||||
*/
|
*/
|
||||||
public LogConfigurationException(Throwable cause) {
|
public LogConfigurationException(final Throwable cause) {
|
||||||
this(cause == null ? null : cause.toString(), cause);
|
this(cause == null ? null : cause.toString(), cause);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -60,7 +60,7 @@ public class LogConfigurationException extends RuntimeException {
|
|||||||
* @param message The detail message
|
* @param message The detail message
|
||||||
* @param cause The underlying cause
|
* @param cause The underlying cause
|
||||||
*/
|
*/
|
||||||
public LogConfigurationException(String message, Throwable cause) {
|
public LogConfigurationException(final String message, final Throwable cause) {
|
||||||
super(message + " (Caused by " + cause + ")");
|
super(message + " (Caused by " + cause + ")");
|
||||||
this.cause = cause; // Two-argument version requires JDK 1.4 or later
|
this.cause = cause; // Two-argument version requires JDK 1.4 or later
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -318,7 +318,7 @@ public abstract class LogFactory {
|
|||||||
String storeImplementationClass;
|
String storeImplementationClass;
|
||||||
try {
|
try {
|
||||||
storeImplementationClass = getSystemProperty(HASHTABLE_IMPLEMENTATION_PROPERTY, null);
|
storeImplementationClass = getSystemProperty(HASHTABLE_IMPLEMENTATION_PROPERTY, null);
|
||||||
} catch (SecurityException ex) {
|
} catch (final SecurityException ex) {
|
||||||
// Permissions don't allow this to be accessed. Default to the "modern"
|
// Permissions don't allow this to be accessed. Default to the "modern"
|
||||||
// weak hashtable implementation if it is available.
|
// weak hashtable implementation if it is available.
|
||||||
storeImplementationClass = null;
|
storeImplementationClass = null;
|
||||||
@@ -328,9 +328,9 @@ public abstract class LogFactory {
|
|||||||
storeImplementationClass = WEAK_HASHTABLE_CLASSNAME;
|
storeImplementationClass = WEAK_HASHTABLE_CLASSNAME;
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Class implementationClass = Class.forName(storeImplementationClass);
|
final Class implementationClass = Class.forName(storeImplementationClass);
|
||||||
result = (Hashtable) implementationClass.newInstance();
|
result = (Hashtable) implementationClass.newInstance();
|
||||||
} catch (Throwable t) {
|
} catch (final Throwable t) {
|
||||||
handleThrowable(t); // may re-throw t
|
handleThrowable(t); // may re-throw t
|
||||||
|
|
||||||
// ignore
|
// ignore
|
||||||
@@ -355,7 +355,7 @@ public abstract class LogFactory {
|
|||||||
// --------------------------------------------------------- Static Methods
|
// --------------------------------------------------------- Static Methods
|
||||||
|
|
||||||
/** Utility method to safely trim a string. */
|
/** Utility method to safely trim a string. */
|
||||||
private static String trim(String src) {
|
private static String trim(final String src) {
|
||||||
if (src == null) {
|
if (src == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -374,7 +374,7 @@ public abstract class LogFactory {
|
|||||||
*
|
*
|
||||||
* @param t the Throwable to check
|
* @param t the Throwable to check
|
||||||
*/
|
*/
|
||||||
protected static void handleThrowable(Throwable t) {
|
protected static void handleThrowable(final Throwable t) {
|
||||||
if (t instanceof ThreadDeath) {
|
if (t instanceof ThreadDeath) {
|
||||||
throw (ThreadDeath) t;
|
throw (ThreadDeath) t;
|
||||||
}
|
}
|
||||||
@@ -416,7 +416,7 @@ public abstract class LogFactory {
|
|||||||
*/
|
*/
|
||||||
public static LogFactory getFactory() throws LogConfigurationException {
|
public static LogFactory getFactory() throws LogConfigurationException {
|
||||||
// Identify the class loader we will be using
|
// Identify the class loader we will be using
|
||||||
ClassLoader contextClassLoader = getContextClassLoaderInternal();
|
final ClassLoader contextClassLoader = getContextClassLoaderInternal();
|
||||||
|
|
||||||
if (contextClassLoader == null) {
|
if (contextClassLoader == null) {
|
||||||
// This is an odd enough situation to report about. This
|
// This is an odd enough situation to report about. This
|
||||||
@@ -450,13 +450,13 @@ public abstract class LogFactory {
|
|||||||
// As the properties file (if it exists) will be used one way or
|
// As the properties file (if it exists) will be used one way or
|
||||||
// another in the end we may as well look for it first.
|
// another in the end we may as well look for it first.
|
||||||
|
|
||||||
Properties props = getConfigurationFile(contextClassLoader, FACTORY_PROPERTIES);
|
final Properties props = getConfigurationFile(contextClassLoader, FACTORY_PROPERTIES);
|
||||||
|
|
||||||
// Determine whether we will be using the thread context class loader to
|
// Determine whether we will be using the thread context class loader to
|
||||||
// load logging classes or not by checking the loaded properties file (if any).
|
// load logging classes or not by checking the loaded properties file (if any).
|
||||||
ClassLoader baseClassLoader = contextClassLoader;
|
ClassLoader baseClassLoader = contextClassLoader;
|
||||||
if (props != null) {
|
if (props != null) {
|
||||||
String useTCCLStr = props.getProperty(TCCL_KEY);
|
final String useTCCLStr = props.getProperty(TCCL_KEY);
|
||||||
if (useTCCLStr != null) {
|
if (useTCCLStr != null) {
|
||||||
// The Boolean.valueOf(useTCCLStr).booleanValue() formulation
|
// The Boolean.valueOf(useTCCLStr).booleanValue() formulation
|
||||||
// is required for Java 1.2 compatibility.
|
// is required for Java 1.2 compatibility.
|
||||||
@@ -481,7 +481,7 @@ public abstract class LogFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
String factoryClass = getSystemProperty(FACTORY_PROPERTY, null);
|
final String factoryClass = getSystemProperty(FACTORY_PROPERTY, null);
|
||||||
if (factoryClass != null) {
|
if (factoryClass != null) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("[LOOKUP] Creating an instance of LogFactory class '" + factoryClass +
|
logDiagnostic("[LOOKUP] Creating an instance of LogFactory class '" + factoryClass +
|
||||||
@@ -493,14 +493,14 @@ public abstract class LogFactory {
|
|||||||
logDiagnostic("[LOOKUP] No system property [" + FACTORY_PROPERTY + "] defined.");
|
logDiagnostic("[LOOKUP] No system property [" + FACTORY_PROPERTY + "] defined.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SecurityException e) {
|
} catch (final SecurityException e) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("[LOOKUP] A security exception occurred while trying to create an" +
|
logDiagnostic("[LOOKUP] A security exception occurred while trying to create an" +
|
||||||
" instance of the custom factory class" + ": [" + trim(e.getMessage()) +
|
" instance of the custom factory class" + ": [" + trim(e.getMessage()) +
|
||||||
"]. Trying alternative implementations...");
|
"]. Trying alternative implementations...");
|
||||||
}
|
}
|
||||||
// ignore
|
// ignore
|
||||||
} catch (RuntimeException e) {
|
} catch (final RuntimeException e) {
|
||||||
// This is not consistent with the behavior when a bad LogFactory class is
|
// This is not consistent with the behavior when a bad LogFactory class is
|
||||||
// specified in a services file.
|
// specified in a services file.
|
||||||
//
|
//
|
||||||
@@ -535,7 +535,7 @@ public abstract class LogFactory {
|
|||||||
BufferedReader rd;
|
BufferedReader rd;
|
||||||
try {
|
try {
|
||||||
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
rd = new BufferedReader(new InputStreamReader(is, "UTF-8"));
|
||||||
} catch (java.io.UnsupportedEncodingException e) {
|
} catch (final java.io.UnsupportedEncodingException e) {
|
||||||
rd = new BufferedReader(new InputStreamReader(is));
|
rd = new BufferedReader(new InputStreamReader(is));
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -561,7 +561,7 @@ public abstract class LogFactory {
|
|||||||
logDiagnostic("[LOOKUP] No resource file with name '" + SERVICE_ID + "' found.");
|
logDiagnostic("[LOOKUP] No resource file with name '" + SERVICE_ID + "' found.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (Exception ex) {
|
} catch (final Exception ex) {
|
||||||
// note: if the specified LogFactory class wasn't compatible with LogFactory
|
// note: if the specified LogFactory class wasn't compatible with LogFactory
|
||||||
// for some reason, a ClassCastException will be caught here, and attempts will
|
// for some reason, a ClassCastException will be caught here, and attempts will
|
||||||
// continue to find a compatible class.
|
// continue to find a compatible class.
|
||||||
@@ -585,7 +585,7 @@ public abstract class LogFactory {
|
|||||||
"[LOOKUP] Looking in properties file for entry with key '" + FACTORY_PROPERTY +
|
"[LOOKUP] Looking in properties file for entry with key '" + FACTORY_PROPERTY +
|
||||||
"' to define the LogFactory subclass to use...");
|
"' to define the LogFactory subclass to use...");
|
||||||
}
|
}
|
||||||
String factoryClass = props.getProperty(FACTORY_PROPERTY);
|
final String factoryClass = props.getProperty(FACTORY_PROPERTY);
|
||||||
if (factoryClass != null) {
|
if (factoryClass != null) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic(
|
logDiagnostic(
|
||||||
@@ -635,10 +635,10 @@ public abstract class LogFactory {
|
|||||||
cacheFactory(contextClassLoader, factory);
|
cacheFactory(contextClassLoader, factory);
|
||||||
|
|
||||||
if (props != null) {
|
if (props != null) {
|
||||||
Enumeration names = props.propertyNames();
|
final Enumeration names = props.propertyNames();
|
||||||
while (names.hasMoreElements()) {
|
while (names.hasMoreElements()) {
|
||||||
String name = (String) names.nextElement();
|
final String name = (String) names.nextElement();
|
||||||
String value = props.getProperty(name);
|
final String value = props.getProperty(name);
|
||||||
factory.setAttribute(name, value);
|
factory.setAttribute(name, value);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -655,7 +655,7 @@ public abstract class LogFactory {
|
|||||||
* @throws LogConfigurationException if a suitable <code>Log</code>
|
* @throws LogConfigurationException if a suitable <code>Log</code>
|
||||||
* instance cannot be returned
|
* instance cannot be returned
|
||||||
*/
|
*/
|
||||||
public static Log getLog(Class clazz) throws LogConfigurationException {
|
public static Log getLog(final Class clazz) throws LogConfigurationException {
|
||||||
return getFactory().getInstance(clazz);
|
return getFactory().getInstance(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -669,7 +669,7 @@ public abstract class LogFactory {
|
|||||||
* @throws LogConfigurationException if a suitable <code>Log</code>
|
* @throws LogConfigurationException if a suitable <code>Log</code>
|
||||||
* instance cannot be returned
|
* instance cannot be returned
|
||||||
*/
|
*/
|
||||||
public static Log getLog(String name) throws LogConfigurationException {
|
public static Log getLog(final String name) throws LogConfigurationException {
|
||||||
return getFactory().getInstance(name);
|
return getFactory().getInstance(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -681,7 +681,7 @@ public abstract class LogFactory {
|
|||||||
*
|
*
|
||||||
* @param classLoader ClassLoader for which to release the LogFactory
|
* @param classLoader ClassLoader for which to release the LogFactory
|
||||||
*/
|
*/
|
||||||
public static void release(ClassLoader classLoader) {
|
public static void release(final ClassLoader classLoader) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("Releasing factory for classloader " + objectId(classLoader));
|
logDiagnostic("Releasing factory for classloader " + objectId(classLoader));
|
||||||
}
|
}
|
||||||
@@ -720,7 +720,7 @@ public abstract class LogFactory {
|
|||||||
synchronized (factories) {
|
synchronized (factories) {
|
||||||
final Enumeration elements = factories.elements();
|
final Enumeration elements = factories.elements();
|
||||||
while (elements.hasMoreElements()) {
|
while (elements.hasMoreElements()) {
|
||||||
LogFactory element = (LogFactory) elements.nextElement();
|
final LogFactory element = (LogFactory) elements.nextElement();
|
||||||
element.release();
|
element.release();
|
||||||
}
|
}
|
||||||
factories.clear();
|
factories.clear();
|
||||||
@@ -761,10 +761,10 @@ public abstract class LogFactory {
|
|||||||
*
|
*
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
protected static ClassLoader getClassLoader(Class clazz) {
|
protected static ClassLoader getClassLoader(final Class clazz) {
|
||||||
try {
|
try {
|
||||||
return clazz.getClassLoader();
|
return clazz.getClassLoader();
|
||||||
} catch (SecurityException ex) {
|
} catch (final SecurityException ex) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("Unable to get classloader for class '" + clazz +
|
logDiagnostic("Unable to get classloader for class '" + clazz +
|
||||||
"' due to security restrictions - " + ex.getMessage());
|
"' due to security restrictions - " + ex.getMessage());
|
||||||
@@ -842,7 +842,7 @@ public abstract class LogFactory {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
classLoader = Thread.currentThread().getContextClassLoader();
|
classLoader = Thread.currentThread().getContextClassLoader();
|
||||||
} catch (SecurityException ex) {
|
} catch (final SecurityException ex) {
|
||||||
/**
|
/**
|
||||||
* getContextClassLoader() throws SecurityException when
|
* getContextClassLoader() throws SecurityException when
|
||||||
* the context class loader isn't an ancestor of the
|
* the context class loader isn't an ancestor of the
|
||||||
@@ -873,7 +873,7 @@ public abstract class LogFactory {
|
|||||||
* one has previously been created, or null if this is the first time
|
* one has previously been created, or null if this is the first time
|
||||||
* we have seen this particular classloader.
|
* we have seen this particular classloader.
|
||||||
*/
|
*/
|
||||||
private static LogFactory getCachedFactory(ClassLoader contextClassLoader) {
|
private static LogFactory getCachedFactory(final ClassLoader contextClassLoader) {
|
||||||
if (contextClassLoader == null) {
|
if (contextClassLoader == null) {
|
||||||
// We have to handle this specially, as factories is a Hashtable
|
// We have to handle this specially, as factories is a Hashtable
|
||||||
// and those don't accept null as a key value.
|
// and those don't accept null as a key value.
|
||||||
@@ -894,7 +894,7 @@ public abstract class LogFactory {
|
|||||||
* this can be null under some circumstances; this is ok.
|
* this can be null under some circumstances; this is ok.
|
||||||
* @param factory should be the factory to cache. This should never be null.
|
* @param factory should be the factory to cache. This should never be null.
|
||||||
*/
|
*/
|
||||||
private static void cacheFactory(ClassLoader classLoader, LogFactory factory) {
|
private static void cacheFactory(final ClassLoader classLoader, final LogFactory factory) {
|
||||||
// Ideally we would assert(factory != null) here. However reporting
|
// Ideally we would assert(factory != null) here. However reporting
|
||||||
// errors from within a logging implementation is a little tricky!
|
// errors from within a logging implementation is a little tricky!
|
||||||
|
|
||||||
@@ -958,7 +958,7 @@ public abstract class LogFactory {
|
|||||||
// Note that any unchecked exceptions thrown by the createFactory
|
// Note that any unchecked exceptions thrown by the createFactory
|
||||||
// method will propagate out of this method; in particular a
|
// method will propagate out of this method; in particular a
|
||||||
// ClassCastException can be thrown.
|
// ClassCastException can be thrown.
|
||||||
Object result = AccessController.doPrivileged(
|
final Object result = AccessController.doPrivileged(
|
||||||
new PrivilegedAction() {
|
new PrivilegedAction() {
|
||||||
public Object run() {
|
public Object run() {
|
||||||
return createFactory(factoryClass, classLoader);
|
return createFactory(factoryClass, classLoader);
|
||||||
@@ -966,7 +966,7 @@ public abstract class LogFactory {
|
|||||||
});
|
});
|
||||||
|
|
||||||
if (result instanceof LogConfigurationException) {
|
if (result instanceof LogConfigurationException) {
|
||||||
LogConfigurationException ex = (LogConfigurationException) result;
|
final LogConfigurationException ex = (LogConfigurationException) result;
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("An error occurred while loading the factory class:" + ex.getMessage());
|
logDiagnostic("An error occurred while loading the factory class:" + ex.getMessage());
|
||||||
}
|
}
|
||||||
@@ -1010,7 +1010,7 @@ public abstract class LogFactory {
|
|||||||
* @return either a LogFactory object or a LogConfigurationException object.
|
* @return either a LogFactory object or a LogConfigurationException object.
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
protected static Object createFactory(String factoryClass, ClassLoader classLoader) {
|
protected static Object createFactory(final String factoryClass, final ClassLoader classLoader) {
|
||||||
// This will be used to diagnose bad configurations
|
// This will be used to diagnose bad configurations
|
||||||
// and allow a useful message to be sent to the user
|
// and allow a useful message to be sent to the user
|
||||||
Class logFactoryClass = null;
|
Class logFactoryClass = null;
|
||||||
@@ -1050,7 +1050,7 @@ public abstract class LogFactory {
|
|||||||
|
|
||||||
return (LogFactory) logFactoryClass.newInstance();
|
return (LogFactory) logFactoryClass.newInstance();
|
||||||
|
|
||||||
} catch (ClassNotFoundException ex) {
|
} catch (final ClassNotFoundException ex) {
|
||||||
if (classLoader == thisClassLoader) {
|
if (classLoader == thisClassLoader) {
|
||||||
// Nothing more to try, onwards.
|
// Nothing more to try, onwards.
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
@@ -1060,7 +1060,7 @@ public abstract class LogFactory {
|
|||||||
throw ex;
|
throw ex;
|
||||||
}
|
}
|
||||||
// ignore exception, continue
|
// ignore exception, continue
|
||||||
} catch (NoClassDefFoundError e) {
|
} catch (final NoClassDefFoundError e) {
|
||||||
if (classLoader == thisClassLoader) {
|
if (classLoader == thisClassLoader) {
|
||||||
// Nothing more to try, onwards.
|
// Nothing more to try, onwards.
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
@@ -1071,7 +1071,7 @@ public abstract class LogFactory {
|
|||||||
throw e;
|
throw e;
|
||||||
}
|
}
|
||||||
// ignore exception, continue
|
// ignore exception, continue
|
||||||
} catch (ClassCastException e) {
|
} catch (final ClassCastException e) {
|
||||||
if (classLoader == thisClassLoader) {
|
if (classLoader == thisClassLoader) {
|
||||||
// There's no point in falling through to the code below that
|
// There's no point in falling through to the code below that
|
||||||
// tries again with thisClassLoader, because we've just tried
|
// tries again with thisClassLoader, because we've just tried
|
||||||
@@ -1149,7 +1149,7 @@ public abstract class LogFactory {
|
|||||||
}
|
}
|
||||||
logFactoryClass = Class.forName(factoryClass);
|
logFactoryClass = Class.forName(factoryClass);
|
||||||
return (LogFactory) logFactoryClass.newInstance();
|
return (LogFactory) logFactoryClass.newInstance();
|
||||||
} catch (Exception e) {
|
} catch (final Exception e) {
|
||||||
// Check to see if we've got a bad configuration
|
// Check to see if we've got a bad configuration
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("Unable to create LogFactory instance.");
|
logDiagnostic("Unable to create LogFactory instance.");
|
||||||
@@ -1175,16 +1175,16 @@ public abstract class LogFactory {
|
|||||||
* <code>LogFactory</code> when that class is loaded via the same
|
* <code>LogFactory</code> when that class is loaded via the same
|
||||||
* classloader that loaded the <code>logFactoryClass</code>.
|
* classloader that loaded the <code>logFactoryClass</code>.
|
||||||
*/
|
*/
|
||||||
private static boolean implementsLogFactory(Class logFactoryClass) {
|
private static boolean implementsLogFactory(final Class logFactoryClass) {
|
||||||
boolean implementsLogFactory = false;
|
boolean implementsLogFactory = false;
|
||||||
if (logFactoryClass != null) {
|
if (logFactoryClass != null) {
|
||||||
try {
|
try {
|
||||||
ClassLoader logFactoryClassLoader = logFactoryClass.getClassLoader();
|
final ClassLoader logFactoryClassLoader = logFactoryClass.getClassLoader();
|
||||||
if (logFactoryClassLoader == null) {
|
if (logFactoryClassLoader == null) {
|
||||||
logDiagnostic("[CUSTOM LOG FACTORY] was loaded by the boot classloader");
|
logDiagnostic("[CUSTOM LOG FACTORY] was loaded by the boot classloader");
|
||||||
} else {
|
} else {
|
||||||
logHierarchy("[CUSTOM LOG FACTORY] ", logFactoryClassLoader);
|
logHierarchy("[CUSTOM LOG FACTORY] ", logFactoryClassLoader);
|
||||||
Class factoryFromCustomLoader
|
final Class factoryFromCustomLoader
|
||||||
= Class.forName("org.apache.commons.logging.LogFactory", false, logFactoryClassLoader);
|
= Class.forName("org.apache.commons.logging.LogFactory", false, logFactoryClassLoader);
|
||||||
implementsLogFactory = factoryFromCustomLoader.isAssignableFrom(logFactoryClass);
|
implementsLogFactory = factoryFromCustomLoader.isAssignableFrom(logFactoryClass);
|
||||||
if (implementsLogFactory) {
|
if (implementsLogFactory) {
|
||||||
@@ -1195,7 +1195,7 @@ public abstract class LogFactory {
|
|||||||
" does not implement LogFactory.");
|
" does not implement LogFactory.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SecurityException e) {
|
} catch (final SecurityException e) {
|
||||||
//
|
//
|
||||||
// The application is running within a hostile security environment.
|
// The application is running within a hostile security environment.
|
||||||
// This will make it very hard to diagnose issues with JCL.
|
// This will make it very hard to diagnose issues with JCL.
|
||||||
@@ -1203,7 +1203,7 @@ public abstract class LogFactory {
|
|||||||
//
|
//
|
||||||
logDiagnostic("[CUSTOM LOG FACTORY] SecurityException thrown whilst trying to determine whether " +
|
logDiagnostic("[CUSTOM LOG FACTORY] SecurityException thrown whilst trying to determine whether " +
|
||||||
"the compatibility was caused by a classloader conflict: " + e.getMessage());
|
"the compatibility was caused by a classloader conflict: " + e.getMessage());
|
||||||
} catch (LinkageError e) {
|
} catch (final LinkageError e) {
|
||||||
//
|
//
|
||||||
// This should be an unusual circumstance.
|
// This should be an unusual circumstance.
|
||||||
// LinkageError's usually indicate that a dependent class has incompatibly changed.
|
// LinkageError's usually indicate that a dependent class has incompatibly changed.
|
||||||
@@ -1212,7 +1212,7 @@ public abstract class LogFactory {
|
|||||||
//
|
//
|
||||||
logDiagnostic("[CUSTOM LOG FACTORY] LinkageError thrown whilst trying to determine whether " +
|
logDiagnostic("[CUSTOM LOG FACTORY] LinkageError thrown whilst trying to determine whether " +
|
||||||
"the compatibility was caused by a classloader conflict: " + e.getMessage());
|
"the compatibility was caused by a classloader conflict: " + e.getMessage());
|
||||||
} catch (ClassNotFoundException e) {
|
} catch (final ClassNotFoundException e) {
|
||||||
//
|
//
|
||||||
// LogFactory cannot be loaded by the classloader which loaded the custom factory implementation.
|
// LogFactory cannot be loaded by the classloader which loaded the custom factory implementation.
|
||||||
// The custom implementation is not viable until this is corrected.
|
// The custom implementation is not viable until this is corrected.
|
||||||
@@ -1260,7 +1260,7 @@ public abstract class LogFactory {
|
|||||||
* If resources could not be listed for some reason, null is returned.
|
* If resources could not be listed for some reason, null is returned.
|
||||||
*/
|
*/
|
||||||
private static Enumeration getResources(final ClassLoader loader, final String name) {
|
private static Enumeration getResources(final ClassLoader loader, final String name) {
|
||||||
PrivilegedAction action =
|
final PrivilegedAction action =
|
||||||
new PrivilegedAction() {
|
new PrivilegedAction() {
|
||||||
public Object run() {
|
public Object run() {
|
||||||
try {
|
try {
|
||||||
@@ -1269,13 +1269,13 @@ public abstract class LogFactory {
|
|||||||
} else {
|
} else {
|
||||||
return ClassLoader.getSystemResources(name);
|
return ClassLoader.getSystemResources(name);
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("Exception while trying to find configuration file " +
|
logDiagnostic("Exception while trying to find configuration file " +
|
||||||
name + ":" + e.getMessage());
|
name + ":" + e.getMessage());
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
} catch (NoSuchMethodError e) {
|
} catch (final NoSuchMethodError e) {
|
||||||
// we must be running on a 1.1 JVM which doesn't support
|
// we must be running on a 1.1 JVM which doesn't support
|
||||||
// ClassLoader.getSystemResources; just return null in
|
// ClassLoader.getSystemResources; just return null in
|
||||||
// this case.
|
// this case.
|
||||||
@@ -1283,7 +1283,7 @@ public abstract class LogFactory {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
Object result = AccessController.doPrivileged(action);
|
final Object result = AccessController.doPrivileged(action);
|
||||||
return (Enumeration) result;
|
return (Enumeration) result;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1296,7 +1296,7 @@ public abstract class LogFactory {
|
|||||||
* {@code Null} is returned if the URL cannot be opened.
|
* {@code Null} is returned if the URL cannot be opened.
|
||||||
*/
|
*/
|
||||||
private static Properties getProperties(final URL url) {
|
private static Properties getProperties(final URL url) {
|
||||||
PrivilegedAction action =
|
final PrivilegedAction action =
|
||||||
new PrivilegedAction() {
|
new PrivilegedAction() {
|
||||||
public Object run() {
|
public Object run() {
|
||||||
InputStream stream = null;
|
InputStream stream = null;
|
||||||
@@ -1304,17 +1304,17 @@ public abstract class LogFactory {
|
|||||||
// We must ensure that useCaches is set to false, as the
|
// We must ensure that useCaches is set to false, as the
|
||||||
// default behavior of java is to cache file handles, and
|
// default behavior of java is to cache file handles, and
|
||||||
// this "locks" files, preventing hot-redeploy on windows.
|
// this "locks" files, preventing hot-redeploy on windows.
|
||||||
URLConnection connection = url.openConnection();
|
final URLConnection connection = url.openConnection();
|
||||||
connection.setUseCaches(false);
|
connection.setUseCaches(false);
|
||||||
stream = connection.getInputStream();
|
stream = connection.getInputStream();
|
||||||
if (stream != null) {
|
if (stream != null) {
|
||||||
Properties props = new Properties();
|
final Properties props = new Properties();
|
||||||
props.load(stream);
|
props.load(stream);
|
||||||
stream.close();
|
stream.close();
|
||||||
stream = null;
|
stream = null;
|
||||||
return props;
|
return props;
|
||||||
}
|
}
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("Unable to read URL " + url);
|
logDiagnostic("Unable to read URL " + url);
|
||||||
}
|
}
|
||||||
@@ -1322,7 +1322,7 @@ public abstract class LogFactory {
|
|||||||
if (stream != null) {
|
if (stream != null) {
|
||||||
try {
|
try {
|
||||||
stream.close();
|
stream.close();
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
// ignore exception; this should not happen
|
// ignore exception; this should not happen
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("Unable to close stream for URL " + url);
|
logDiagnostic("Unable to close stream for URL " + url);
|
||||||
@@ -1356,26 +1356,26 @@ public abstract class LogFactory {
|
|||||||
* webapps. Webapps can also use explicit priorities to override a configuration
|
* webapps. Webapps can also use explicit priorities to override a configuration
|
||||||
* file in the shared classpath if needed.
|
* file in the shared classpath if needed.
|
||||||
*/
|
*/
|
||||||
private static final Properties getConfigurationFile(ClassLoader classLoader, String fileName) {
|
private static final Properties getConfigurationFile(final ClassLoader classLoader, final String fileName) {
|
||||||
Properties props = null;
|
Properties props = null;
|
||||||
double priority = 0.0;
|
double priority = 0.0;
|
||||||
URL propsUrl = null;
|
URL propsUrl = null;
|
||||||
try {
|
try {
|
||||||
Enumeration urls = getResources(classLoader, fileName);
|
final Enumeration urls = getResources(classLoader, fileName);
|
||||||
|
|
||||||
if (urls == null) {
|
if (urls == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
while (urls.hasMoreElements()) {
|
while (urls.hasMoreElements()) {
|
||||||
URL url = (URL) urls.nextElement();
|
final URL url = (URL) urls.nextElement();
|
||||||
|
|
||||||
Properties newProps = getProperties(url);
|
final Properties newProps = getProperties(url);
|
||||||
if (newProps != null) {
|
if (newProps != null) {
|
||||||
if (props == null) {
|
if (props == null) {
|
||||||
propsUrl = url;
|
propsUrl = url;
|
||||||
props = newProps;
|
props = newProps;
|
||||||
String priorityStr = props.getProperty(PRIORITY_KEY);
|
final String priorityStr = props.getProperty(PRIORITY_KEY);
|
||||||
priority = 0.0;
|
priority = 0.0;
|
||||||
if (priorityStr != null) {
|
if (priorityStr != null) {
|
||||||
priority = Double.parseDouble(priorityStr);
|
priority = Double.parseDouble(priorityStr);
|
||||||
@@ -1386,7 +1386,7 @@ public abstract class LogFactory {
|
|||||||
" with priority " + priority);
|
" with priority " + priority);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
String newPriorityStr = newProps.getProperty(PRIORITY_KEY);
|
final String newPriorityStr = newProps.getProperty(PRIORITY_KEY);
|
||||||
double newPriority = 0.0;
|
double newPriority = 0.0;
|
||||||
if (newPriorityStr != null) {
|
if (newPriorityStr != null) {
|
||||||
newPriority = Double.parseDouble(newPriorityStr);
|
newPriority = Double.parseDouble(newPriorityStr);
|
||||||
@@ -1415,7 +1415,7 @@ public abstract class LogFactory {
|
|||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (SecurityException e) {
|
} catch (final SecurityException e) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("SecurityException thrown while trying to find/read config files.");
|
logDiagnostic("SecurityException thrown while trying to find/read config files.");
|
||||||
}
|
}
|
||||||
@@ -1464,7 +1464,7 @@ public abstract class LogFactory {
|
|||||||
if (dest == null) {
|
if (dest == null) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
} catch (SecurityException ex) {
|
} catch (final SecurityException ex) {
|
||||||
// We must be running in some very secure environment.
|
// We must be running in some very secure environment.
|
||||||
// We just have to assume output is not wanted..
|
// We just have to assume output is not wanted..
|
||||||
return null;
|
return null;
|
||||||
@@ -1477,9 +1477,9 @@ public abstract class LogFactory {
|
|||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
// open the file in append mode
|
// open the file in append mode
|
||||||
FileOutputStream fos = new FileOutputStream(dest, true);
|
final FileOutputStream fos = new FileOutputStream(dest, true);
|
||||||
return new PrintStream(fos);
|
return new PrintStream(fos);
|
||||||
} catch (IOException ex) {
|
} catch (final IOException ex) {
|
||||||
// We should report this to the user - but how?
|
// We should report this to the user - but how?
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -1517,7 +1517,7 @@ public abstract class LogFactory {
|
|||||||
*
|
*
|
||||||
* @param msg is the diagnostic message to be output.
|
* @param msg is the diagnostic message to be output.
|
||||||
*/
|
*/
|
||||||
private static final void logDiagnostic(String msg) {
|
private static final void logDiagnostic(final String msg) {
|
||||||
if (diagnosticsStream != null) {
|
if (diagnosticsStream != null) {
|
||||||
diagnosticsStream.print(diagnosticPrefix);
|
diagnosticsStream.print(diagnosticPrefix);
|
||||||
diagnosticsStream.println(msg);
|
diagnosticsStream.println(msg);
|
||||||
@@ -1531,7 +1531,7 @@ public abstract class LogFactory {
|
|||||||
* @param msg is the diagnostic message to be output.
|
* @param msg is the diagnostic message to be output.
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
protected static final void logRawDiagnostic(String msg) {
|
protected static final void logRawDiagnostic(final String msg) {
|
||||||
if (diagnosticsStream != null) {
|
if (diagnosticsStream != null) {
|
||||||
diagnosticsStream.println(msg);
|
diagnosticsStream.println(msg);
|
||||||
diagnosticsStream.flush();
|
diagnosticsStream.flush();
|
||||||
@@ -1555,7 +1555,7 @@ public abstract class LogFactory {
|
|||||||
* @param clazz is the class whose classloader + tree are to be
|
* @param clazz is the class whose classloader + tree are to be
|
||||||
* output.
|
* output.
|
||||||
*/
|
*/
|
||||||
private static void logClassLoaderEnvironment(Class clazz) {
|
private static void logClassLoaderEnvironment(final Class clazz) {
|
||||||
if (!isDiagnosticsEnabled()) {
|
if (!isDiagnosticsEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1566,16 +1566,16 @@ public abstract class LogFactory {
|
|||||||
// these variables then we do not want to output them to the diagnostic stream.
|
// these variables then we do not want to output them to the diagnostic stream.
|
||||||
logDiagnostic("[ENV] Extension directories (java.ext.dir): " + System.getProperty("java.ext.dir"));
|
logDiagnostic("[ENV] Extension directories (java.ext.dir): " + System.getProperty("java.ext.dir"));
|
||||||
logDiagnostic("[ENV] Application classpath (java.class.path): " + System.getProperty("java.class.path"));
|
logDiagnostic("[ENV] Application classpath (java.class.path): " + System.getProperty("java.class.path"));
|
||||||
} catch (SecurityException ex) {
|
} catch (final SecurityException ex) {
|
||||||
logDiagnostic("[ENV] Security setting prevent interrogation of system classpaths.");
|
logDiagnostic("[ENV] Security setting prevent interrogation of system classpaths.");
|
||||||
}
|
}
|
||||||
|
|
||||||
String className = clazz.getName();
|
final String className = clazz.getName();
|
||||||
ClassLoader classLoader;
|
ClassLoader classLoader;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
classLoader = getClassLoader(clazz);
|
classLoader = getClassLoader(clazz);
|
||||||
} catch (SecurityException ex) {
|
} catch (final SecurityException ex) {
|
||||||
// not much useful diagnostics we can print here!
|
// not much useful diagnostics we can print here!
|
||||||
logDiagnostic("[ENV] Security forbids determining the classloader for " + className);
|
logDiagnostic("[ENV] Security forbids determining the classloader for " + className);
|
||||||
return;
|
return;
|
||||||
@@ -1592,7 +1592,7 @@ public abstract class LogFactory {
|
|||||||
* @param prefix
|
* @param prefix
|
||||||
* @param classLoader
|
* @param classLoader
|
||||||
*/
|
*/
|
||||||
private static void logHierarchy(String prefix, ClassLoader classLoader) {
|
private static void logHierarchy(final String prefix, ClassLoader classLoader) {
|
||||||
if (!isDiagnosticsEnabled()) {
|
if (!isDiagnosticsEnabled()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1604,7 +1604,7 @@ public abstract class LogFactory {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
systemClassLoader = ClassLoader.getSystemClassLoader();
|
systemClassLoader = ClassLoader.getSystemClassLoader();
|
||||||
} catch (SecurityException ex) {
|
} catch (final SecurityException ex) {
|
||||||
logDiagnostic(prefix + "Security forbids determining the system classloader.");
|
logDiagnostic(prefix + "Security forbids determining the system classloader.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@@ -1618,7 +1618,7 @@ public abstract class LogFactory {
|
|||||||
|
|
||||||
try {
|
try {
|
||||||
classLoader = classLoader.getParent();
|
classLoader = classLoader.getParent();
|
||||||
} catch (SecurityException ex) {
|
} catch (final SecurityException ex) {
|
||||||
buf.append(" --> SECRET");
|
buf.append(" --> SECRET");
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -1645,7 +1645,7 @@ public abstract class LogFactory {
|
|||||||
* @return a string of form classname@hashcode, or "null" if param o is null.
|
* @return a string of form classname@hashcode, or "null" if param o is null.
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
public static String objectId(Object o) {
|
public static String objectId(final Object o) {
|
||||||
if (o == null) {
|
if (o == null) {
|
||||||
return "null";
|
return "null";
|
||||||
} else {
|
} else {
|
||||||
@@ -1687,13 +1687,13 @@ public abstract class LogFactory {
|
|||||||
// output diagnostics from this class are static.
|
// output diagnostics from this class are static.
|
||||||
String classLoaderName;
|
String classLoaderName;
|
||||||
try {
|
try {
|
||||||
ClassLoader classLoader = thisClassLoader;
|
final ClassLoader classLoader = thisClassLoader;
|
||||||
if (thisClassLoader == null) {
|
if (thisClassLoader == null) {
|
||||||
classLoaderName = "BOOTLOADER";
|
classLoaderName = "BOOTLOADER";
|
||||||
} else {
|
} else {
|
||||||
classLoaderName = objectId(classLoader);
|
classLoaderName = objectId(classLoader);
|
||||||
}
|
}
|
||||||
} catch (SecurityException e) {
|
} catch (final SecurityException e) {
|
||||||
classLoaderName = "UNKNOWN";
|
classLoaderName = "UNKNOWN";
|
||||||
}
|
}
|
||||||
diagnosticPrefix = "[LogFactory from " + classLoaderName + "] ";
|
diagnosticPrefix = "[LogFactory from " + classLoaderName + "] ";
|
||||||
|
|||||||
@@ -74,7 +74,7 @@ public class LogSource {
|
|||||||
// Is Log4J Available?
|
// Is Log4J Available?
|
||||||
try {
|
try {
|
||||||
log4jIsAvailable = null != Class.forName("org.apache.log4j.Logger");
|
log4jIsAvailable = null != Class.forName("org.apache.log4j.Logger");
|
||||||
} catch (Throwable t) {
|
} catch (final Throwable t) {
|
||||||
log4jIsAvailable = false;
|
log4jIsAvailable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -82,7 +82,7 @@ public class LogSource {
|
|||||||
try {
|
try {
|
||||||
jdk14IsAvailable = null != Class.forName("java.util.logging.Logger") &&
|
jdk14IsAvailable = null != Class.forName("java.util.logging.Logger") &&
|
||||||
null != Class.forName("org.apache.commons.logging.impl.Jdk14Logger");
|
null != Class.forName("org.apache.commons.logging.impl.Jdk14Logger");
|
||||||
} catch (Throwable t) {
|
} catch (final Throwable t) {
|
||||||
jdk14IsAvailable = false;
|
jdk14IsAvailable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -93,15 +93,15 @@ public class LogSource {
|
|||||||
if (name == null) {
|
if (name == null) {
|
||||||
name = System.getProperty("org.apache.commons.logging.Log");
|
name = System.getProperty("org.apache.commons.logging.Log");
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (final Throwable t) {
|
||||||
}
|
}
|
||||||
if (name != null) {
|
if (name != null) {
|
||||||
try {
|
try {
|
||||||
setLogImplementation(name);
|
setLogImplementation(name);
|
||||||
} catch (Throwable t) {
|
} catch (final Throwable t) {
|
||||||
try {
|
try {
|
||||||
setLogImplementation("org.apache.commons.logging.impl.NoOpLog");
|
setLogImplementation("org.apache.commons.logging.impl.NoOpLog");
|
||||||
} catch (Throwable u) {
|
} catch (final Throwable u) {
|
||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -114,10 +114,10 @@ public class LogSource {
|
|||||||
} else {
|
} else {
|
||||||
setLogImplementation("org.apache.commons.logging.impl.NoOpLog");
|
setLogImplementation("org.apache.commons.logging.impl.NoOpLog");
|
||||||
}
|
}
|
||||||
} catch (Throwable t) {
|
} catch (final Throwable t) {
|
||||||
try {
|
try {
|
||||||
setLogImplementation("org.apache.commons.logging.impl.NoOpLog");
|
setLogImplementation("org.apache.commons.logging.impl.NoOpLog");
|
||||||
} catch (Throwable u) {
|
} catch (final Throwable u) {
|
||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,14 +139,14 @@ public class LogSource {
|
|||||||
* and provide a constructor that takes a single {@link String} argument
|
* and provide a constructor that takes a single {@link String} argument
|
||||||
* (containing the name of the log).
|
* (containing the name of the log).
|
||||||
*/
|
*/
|
||||||
static public void setLogImplementation(String classname)
|
static public void setLogImplementation(final String classname)
|
||||||
throws LinkageError, NoSuchMethodException, SecurityException, ClassNotFoundException {
|
throws LinkageError, NoSuchMethodException, SecurityException, ClassNotFoundException {
|
||||||
try {
|
try {
|
||||||
Class logclass = Class.forName(classname);
|
final Class logclass = Class.forName(classname);
|
||||||
Class[] argtypes = new Class[1];
|
final Class[] argtypes = new Class[1];
|
||||||
argtypes[0] = "".getClass();
|
argtypes[0] = "".getClass();
|
||||||
logImplctor = logclass.getConstructor(argtypes);
|
logImplctor = logclass.getConstructor(argtypes);
|
||||||
} catch (Throwable t) {
|
} catch (final Throwable t) {
|
||||||
logImplctor = null;
|
logImplctor = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -156,15 +156,15 @@ public class LogSource {
|
|||||||
* The given class must implement {@link Log}, and provide a constructor
|
* The given class must implement {@link Log}, and provide a constructor
|
||||||
* that takes a single {@link String} argument (containing the name of the log).
|
* that takes a single {@link String} argument (containing the name of the log).
|
||||||
*/
|
*/
|
||||||
static public void setLogImplementation(Class logclass)
|
static public void setLogImplementation(final Class logclass)
|
||||||
throws LinkageError, ExceptionInInitializerError, NoSuchMethodException, SecurityException {
|
throws LinkageError, ExceptionInInitializerError, NoSuchMethodException, SecurityException {
|
||||||
Class[] argtypes = new Class[1];
|
final Class[] argtypes = new Class[1];
|
||||||
argtypes[0] = "".getClass();
|
argtypes[0] = "".getClass();
|
||||||
logImplctor = logclass.getConstructor(argtypes);
|
logImplctor = logclass.getConstructor(argtypes);
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Get a <code>Log</code> instance by class name. */
|
/** Get a <code>Log</code> instance by class name. */
|
||||||
static public Log getInstance(String name) {
|
static public Log getInstance(final String name) {
|
||||||
Log log = (Log) logs.get(name);
|
Log log = (Log) logs.get(name);
|
||||||
if (null == log) {
|
if (null == log) {
|
||||||
log = makeNewLogInstance(name);
|
log = makeNewLogInstance(name);
|
||||||
@@ -174,7 +174,7 @@ public class LogSource {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/** Get a <code>Log</code> instance by class. */
|
/** Get a <code>Log</code> instance by class. */
|
||||||
static public Log getInstance(Class clazz) {
|
static public Log getInstance(final Class clazz) {
|
||||||
return getInstance(clazz.getName());
|
return getInstance(clazz.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -195,12 +195,12 @@ public class LogSource {
|
|||||||
*
|
*
|
||||||
* @param name the log name (or category)
|
* @param name the log name (or category)
|
||||||
*/
|
*/
|
||||||
static public Log makeNewLogInstance(String name) {
|
static public Log makeNewLogInstance(final String name) {
|
||||||
Log log;
|
Log log;
|
||||||
try {
|
try {
|
||||||
Object[] args = { name };
|
final Object[] args = { name };
|
||||||
log = (Log) logImplctor.newInstance(args);
|
log = (Log) logImplctor.newInstance(args);
|
||||||
} catch (Throwable t) {
|
} catch (final Throwable t) {
|
||||||
log = null;
|
log = null;
|
||||||
}
|
}
|
||||||
if (null == log) {
|
if (null == log) {
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ public class AvalonLogger implements Log {
|
|||||||
*
|
*
|
||||||
* @param logger the Avalon logger implementation to delegate to
|
* @param logger the Avalon logger implementation to delegate to
|
||||||
*/
|
*/
|
||||||
public AvalonLogger(Logger logger) {
|
public AvalonLogger(final Logger logger) {
|
||||||
this.logger = logger;
|
this.logger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -73,7 +73,7 @@ public class AvalonLogger implements Log {
|
|||||||
*
|
*
|
||||||
* @param name the name of the avalon logger implementation to delegate to
|
* @param name the name of the avalon logger implementation to delegate to
|
||||||
*/
|
*/
|
||||||
public AvalonLogger(String name) {
|
public AvalonLogger(final String name) {
|
||||||
if (defaultLogger == null) {
|
if (defaultLogger == null) {
|
||||||
throw new NullPointerException("default logger has to be specified if this constructor is used!");
|
throw new NullPointerException("default logger has to be specified if this constructor is used!");
|
||||||
}
|
}
|
||||||
@@ -95,7 +95,7 @@ public class AvalonLogger implements Log {
|
|||||||
* @param logger the default avalon logger,
|
* @param logger the default avalon logger,
|
||||||
* in case there is no logger instance supplied in constructor
|
* in case there is no logger instance supplied in constructor
|
||||||
*/
|
*/
|
||||||
public static void setDefaultLogger(Logger logger) {
|
public static void setDefaultLogger(final Logger logger) {
|
||||||
defaultLogger = logger;
|
defaultLogger = logger;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ public class AvalonLogger implements Log {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
|
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void debug(Object message, Throwable t) {
|
public void debug(final Object message, final Throwable t) {
|
||||||
if (getLogger().isDebugEnabled()) {
|
if (getLogger().isDebugEnabled()) {
|
||||||
getLogger().debug(String.valueOf(message), t);
|
getLogger().debug(String.valueOf(message), t);
|
||||||
}
|
}
|
||||||
@@ -118,7 +118,7 @@ public class AvalonLogger implements Log {
|
|||||||
* @param message to log.
|
* @param message to log.
|
||||||
* @see org.apache.commons.logging.Log#debug(Object)
|
* @see org.apache.commons.logging.Log#debug(Object)
|
||||||
*/
|
*/
|
||||||
public void debug(Object message) {
|
public void debug(final Object message) {
|
||||||
if (getLogger().isDebugEnabled()) {
|
if (getLogger().isDebugEnabled()) {
|
||||||
getLogger().debug(String.valueOf(message));
|
getLogger().debug(String.valueOf(message));
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ public class AvalonLogger implements Log {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#error(Object, Throwable)
|
* @see org.apache.commons.logging.Log#error(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void error(Object message, Throwable t) {
|
public void error(final Object message, final Throwable t) {
|
||||||
if (getLogger().isErrorEnabled()) {
|
if (getLogger().isErrorEnabled()) {
|
||||||
getLogger().error(String.valueOf(message), t);
|
getLogger().error(String.valueOf(message), t);
|
||||||
}
|
}
|
||||||
@@ -143,7 +143,7 @@ public class AvalonLogger implements Log {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#error(Object)
|
* @see org.apache.commons.logging.Log#error(Object)
|
||||||
*/
|
*/
|
||||||
public void error(Object message) {
|
public void error(final Object message) {
|
||||||
if (getLogger().isErrorEnabled()) {
|
if (getLogger().isErrorEnabled()) {
|
||||||
getLogger().error(String.valueOf(message));
|
getLogger().error(String.valueOf(message));
|
||||||
}
|
}
|
||||||
@@ -156,7 +156,7 @@ public class AvalonLogger implements Log {
|
|||||||
* @param t log this cause.
|
* @param t log this cause.
|
||||||
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
|
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void fatal(Object message, Throwable t) {
|
public void fatal(final Object message, final Throwable t) {
|
||||||
if (getLogger().isFatalErrorEnabled()) {
|
if (getLogger().isFatalErrorEnabled()) {
|
||||||
getLogger().fatalError(String.valueOf(message), t);
|
getLogger().fatalError(String.valueOf(message), t);
|
||||||
}
|
}
|
||||||
@@ -168,7 +168,7 @@ public class AvalonLogger implements Log {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#fatal(Object)
|
* @see org.apache.commons.logging.Log#fatal(Object)
|
||||||
*/
|
*/
|
||||||
public void fatal(Object message) {
|
public void fatal(final Object message) {
|
||||||
if (getLogger().isFatalErrorEnabled()) {
|
if (getLogger().isFatalErrorEnabled()) {
|
||||||
getLogger().fatalError(String.valueOf(message));
|
getLogger().fatalError(String.valueOf(message));
|
||||||
}
|
}
|
||||||
@@ -181,7 +181,7 @@ public class AvalonLogger implements Log {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#info(Object, Throwable)
|
* @see org.apache.commons.logging.Log#info(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void info(Object message, Throwable t) {
|
public void info(final Object message, final Throwable t) {
|
||||||
if (getLogger().isInfoEnabled()) {
|
if (getLogger().isInfoEnabled()) {
|
||||||
getLogger().info(String.valueOf(message), t);
|
getLogger().info(String.valueOf(message), t);
|
||||||
}
|
}
|
||||||
@@ -193,7 +193,7 @@ public class AvalonLogger implements Log {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#info(Object)
|
* @see org.apache.commons.logging.Log#info(Object)
|
||||||
*/
|
*/
|
||||||
public void info(Object message) {
|
public void info(final Object message) {
|
||||||
if (getLogger().isInfoEnabled()) {
|
if (getLogger().isInfoEnabled()) {
|
||||||
getLogger().info(String.valueOf(message));
|
getLogger().info(String.valueOf(message));
|
||||||
}
|
}
|
||||||
@@ -254,7 +254,7 @@ public class AvalonLogger implements Log {
|
|||||||
* @param t log this cause.
|
* @param t log this cause.
|
||||||
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
|
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void trace(Object message, Throwable t) {
|
public void trace(final Object message, final Throwable t) {
|
||||||
if (getLogger().isDebugEnabled()) {
|
if (getLogger().isDebugEnabled()) {
|
||||||
getLogger().debug(String.valueOf(message), t);
|
getLogger().debug(String.valueOf(message), t);
|
||||||
}
|
}
|
||||||
@@ -266,7 +266,7 @@ public class AvalonLogger implements Log {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#trace(Object)
|
* @see org.apache.commons.logging.Log#trace(Object)
|
||||||
*/
|
*/
|
||||||
public void trace(Object message) {
|
public void trace(final Object message) {
|
||||||
if (getLogger().isDebugEnabled()) {
|
if (getLogger().isDebugEnabled()) {
|
||||||
getLogger().debug(String.valueOf(message));
|
getLogger().debug(String.valueOf(message));
|
||||||
}
|
}
|
||||||
@@ -279,7 +279,7 @@ public class AvalonLogger implements Log {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
|
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void warn(Object message, Throwable t) {
|
public void warn(final Object message, final Throwable t) {
|
||||||
if (getLogger().isWarnEnabled()) {
|
if (getLogger().isWarnEnabled()) {
|
||||||
getLogger().warn(String.valueOf(message), t);
|
getLogger().warn(String.valueOf(message), t);
|
||||||
}
|
}
|
||||||
@@ -291,7 +291,7 @@ public class AvalonLogger implements Log {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#warn(Object)
|
* @see org.apache.commons.logging.Log#warn(Object)
|
||||||
*/
|
*/
|
||||||
public void warn(Object message) {
|
public void warn(final Object message) {
|
||||||
if (getLogger().isWarnEnabled()) {
|
if (getLogger().isWarnEnabled()) {
|
||||||
getLogger().warn(String.valueOf(message));
|
getLogger().warn(String.valueOf(message));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -66,16 +66,16 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
|
|||||||
*
|
*
|
||||||
* @param name Name of the logger to be constructed
|
* @param name Name of the logger to be constructed
|
||||||
*/
|
*/
|
||||||
public Jdk13LumberjackLogger(String name) {
|
public Jdk13LumberjackLogger(final String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
logger = getLogger();
|
logger = getLogger();
|
||||||
}
|
}
|
||||||
|
|
||||||
// --------------------------------------------------------- Public Methods
|
// --------------------------------------------------------- Public Methods
|
||||||
|
|
||||||
private void log( Level level, String msg, Throwable ex ) {
|
private void log( final Level level, final String msg, final Throwable ex ) {
|
||||||
if( getLogger().isLoggable(level) ) {
|
if( getLogger().isLoggable(level) ) {
|
||||||
LogRecord record = new LogRecord(level, msg);
|
final LogRecord record = new LogRecord(level, msg);
|
||||||
if( !classAndMethodFound ) {
|
if( !classAndMethodFound ) {
|
||||||
getClassAndMethod();
|
getClassAndMethod();
|
||||||
}
|
}
|
||||||
@@ -94,13 +94,13 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
|
|||||||
*/
|
*/
|
||||||
private void getClassAndMethod() {
|
private void getClassAndMethod() {
|
||||||
try {
|
try {
|
||||||
Throwable throwable = new Throwable();
|
final Throwable throwable = new Throwable();
|
||||||
throwable.fillInStackTrace();
|
throwable.fillInStackTrace();
|
||||||
StringWriter stringWriter = new StringWriter();
|
final StringWriter stringWriter = new StringWriter();
|
||||||
PrintWriter printWriter = new PrintWriter( stringWriter );
|
final PrintWriter printWriter = new PrintWriter( stringWriter );
|
||||||
throwable.printStackTrace( printWriter );
|
throwable.printStackTrace( printWriter );
|
||||||
String traceString = stringWriter.getBuffer().toString();
|
final String traceString = stringWriter.getBuffer().toString();
|
||||||
StringTokenizer tokenizer =
|
final StringTokenizer tokenizer =
|
||||||
new StringTokenizer( traceString, "\n" );
|
new StringTokenizer( traceString, "\n" );
|
||||||
tokenizer.nextToken();
|
tokenizer.nextToken();
|
||||||
String line = tokenizer.nextToken();
|
String line = tokenizer.nextToken();
|
||||||
@@ -110,13 +110,13 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
|
|||||||
while ( line.indexOf( this.getClass().getName() ) >= 0 ) {
|
while ( line.indexOf( this.getClass().getName() ) >= 0 ) {
|
||||||
line = tokenizer.nextToken();
|
line = tokenizer.nextToken();
|
||||||
}
|
}
|
||||||
int start = line.indexOf( "at " ) + 3;
|
final int start = line.indexOf( "at " ) + 3;
|
||||||
int end = line.indexOf( '(' );
|
final int end = line.indexOf( '(' );
|
||||||
String temp = line.substring( start, end );
|
final String temp = line.substring( start, end );
|
||||||
int lastPeriod = temp.lastIndexOf( '.' );
|
final int lastPeriod = temp.lastIndexOf( '.' );
|
||||||
sourceClassName = temp.substring( 0, lastPeriod );
|
sourceClassName = temp.substring( 0, lastPeriod );
|
||||||
sourceMethodName = temp.substring( lastPeriod + 1 );
|
sourceMethodName = temp.substring( lastPeriod + 1 );
|
||||||
} catch ( Exception ex ) {
|
} catch ( final Exception ex ) {
|
||||||
// ignore - leave class and methodname unknown
|
// ignore - leave class and methodname unknown
|
||||||
}
|
}
|
||||||
classAndMethodFound = true;
|
classAndMethodFound = true;
|
||||||
@@ -128,7 +128,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#debug(Object)
|
* @see org.apache.commons.logging.Log#debug(Object)
|
||||||
*/
|
*/
|
||||||
public void debug(Object message) {
|
public void debug(final Object message) {
|
||||||
log(Level.FINE, String.valueOf(message), null);
|
log(Level.FINE, String.valueOf(message), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -139,7 +139,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
|
|||||||
* @param exception log this cause
|
* @param exception log this cause
|
||||||
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
|
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void debug(Object message, Throwable exception) {
|
public void debug(final Object message, final Throwable exception) {
|
||||||
log(Level.FINE, String.valueOf(message), exception);
|
log(Level.FINE, String.valueOf(message), exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -149,7 +149,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#error(Object)
|
* @see org.apache.commons.logging.Log#error(Object)
|
||||||
*/
|
*/
|
||||||
public void error(Object message) {
|
public void error(final Object message) {
|
||||||
log(Level.SEVERE, String.valueOf(message), null);
|
log(Level.SEVERE, String.valueOf(message), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -160,7 +160,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
|
|||||||
* @param exception log this cause
|
* @param exception log this cause
|
||||||
* @see org.apache.commons.logging.Log#error(Object, Throwable)
|
* @see org.apache.commons.logging.Log#error(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void error(Object message, Throwable exception) {
|
public void error(final Object message, final Throwable exception) {
|
||||||
log(Level.SEVERE, String.valueOf(message), exception);
|
log(Level.SEVERE, String.valueOf(message), exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#fatal(Object)
|
* @see org.apache.commons.logging.Log#fatal(Object)
|
||||||
*/
|
*/
|
||||||
public void fatal(Object message) {
|
public void fatal(final Object message) {
|
||||||
log(Level.SEVERE, String.valueOf(message), null);
|
log(Level.SEVERE, String.valueOf(message), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -181,7 +181,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
|
|||||||
* @param exception log this cause
|
* @param exception log this cause
|
||||||
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
|
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void fatal(Object message, Throwable exception) {
|
public void fatal(final Object message, final Throwable exception) {
|
||||||
log(Level.SEVERE, String.valueOf(message), exception);
|
log(Level.SEVERE, String.valueOf(message), exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -201,7 +201,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#info(Object)
|
* @see org.apache.commons.logging.Log#info(Object)
|
||||||
*/
|
*/
|
||||||
public void info(Object message) {
|
public void info(final Object message) {
|
||||||
log(Level.INFO, String.valueOf(message), null);
|
log(Level.INFO, String.valueOf(message), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -212,7 +212,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
|
|||||||
* @param exception log this cause
|
* @param exception log this cause
|
||||||
* @see org.apache.commons.logging.Log#info(Object, Throwable)
|
* @see org.apache.commons.logging.Log#info(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void info(Object message, Throwable exception) {
|
public void info(final Object message, final Throwable exception) {
|
||||||
log(Level.INFO, String.valueOf(message), exception);
|
log(Level.INFO, String.valueOf(message), exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,7 +264,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#trace(Object)
|
* @see org.apache.commons.logging.Log#trace(Object)
|
||||||
*/
|
*/
|
||||||
public void trace(Object message) {
|
public void trace(final Object message) {
|
||||||
log(Level.FINEST, String.valueOf(message), null);
|
log(Level.FINEST, String.valueOf(message), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -275,7 +275,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
|
|||||||
* @param exception log this cause
|
* @param exception log this cause
|
||||||
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
|
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void trace(Object message, Throwable exception) {
|
public void trace(final Object message, final Throwable exception) {
|
||||||
log(Level.FINEST, String.valueOf(message), exception);
|
log(Level.FINEST, String.valueOf(message), exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,7 +285,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#warn(Object)
|
* @see org.apache.commons.logging.Log#warn(Object)
|
||||||
*/
|
*/
|
||||||
public void warn(Object message) {
|
public void warn(final Object message) {
|
||||||
log(Level.WARNING, String.valueOf(message), null);
|
log(Level.WARNING, String.valueOf(message), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -296,7 +296,7 @@ public class Jdk13LumberjackLogger implements Log, Serializable {
|
|||||||
* @param exception log this cause
|
* @param exception log this cause
|
||||||
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
|
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void warn(Object message, Throwable exception) {
|
public void warn(final Object message, final Throwable exception) {
|
||||||
log(Level.WARNING, String.valueOf(message), exception);
|
log(Level.WARNING, String.valueOf(message), exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class Jdk14Logger implements Log, Serializable {
|
|||||||
*
|
*
|
||||||
* @param name Name of the logger to be constructed
|
* @param name Name of the logger to be constructed
|
||||||
*/
|
*/
|
||||||
public Jdk14Logger(String name) {
|
public Jdk14Logger(final String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
logger = getLogger();
|
logger = getLogger();
|
||||||
}
|
}
|
||||||
@@ -69,18 +69,18 @@ public class Jdk14Logger implements Log, Serializable {
|
|||||||
|
|
||||||
// --------------------------------------------------------- Protected Methods
|
// --------------------------------------------------------- Protected Methods
|
||||||
|
|
||||||
protected void log( Level level, String msg, Throwable ex ) {
|
protected void log( final Level level, final String msg, final Throwable ex ) {
|
||||||
Logger logger = getLogger();
|
final Logger logger = getLogger();
|
||||||
if (logger.isLoggable(level)) {
|
if (logger.isLoggable(level)) {
|
||||||
// Hack (?) to get the stack trace.
|
// Hack (?) to get the stack trace.
|
||||||
Throwable dummyException = new Throwable();
|
final Throwable dummyException = new Throwable();
|
||||||
StackTraceElement locations[] = dummyException.getStackTrace();
|
final StackTraceElement locations[] = dummyException.getStackTrace();
|
||||||
// LOGGING-132: use the provided logger name instead of the class name
|
// LOGGING-132: use the provided logger name instead of the class name
|
||||||
String cname = name;
|
final String cname = name;
|
||||||
String method = "unknown";
|
String method = "unknown";
|
||||||
// Caller will be the third element
|
// Caller will be the third element
|
||||||
if( locations != null && locations.length > 2 ) {
|
if( locations != null && locations.length > 2 ) {
|
||||||
StackTraceElement caller = locations[2];
|
final StackTraceElement caller = locations[2];
|
||||||
method = caller.getMethodName();
|
method = caller.getMethodName();
|
||||||
}
|
}
|
||||||
if( ex == null ) {
|
if( ex == null ) {
|
||||||
@@ -99,7 +99,7 @@ public class Jdk14Logger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#debug(Object)
|
* @see org.apache.commons.logging.Log#debug(Object)
|
||||||
*/
|
*/
|
||||||
public void debug(Object message) {
|
public void debug(final Object message) {
|
||||||
log(Level.FINE, String.valueOf(message), null);
|
log(Level.FINE, String.valueOf(message), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -110,7 +110,7 @@ public class Jdk14Logger implements Log, Serializable {
|
|||||||
* @param exception log this cause
|
* @param exception log this cause
|
||||||
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
|
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void debug(Object message, Throwable exception) {
|
public void debug(final Object message, final Throwable exception) {
|
||||||
log(Level.FINE, String.valueOf(message), exception);
|
log(Level.FINE, String.valueOf(message), exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -120,7 +120,7 @@ public class Jdk14Logger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#error(Object)
|
* @see org.apache.commons.logging.Log#error(Object)
|
||||||
*/
|
*/
|
||||||
public void error(Object message) {
|
public void error(final Object message) {
|
||||||
log(Level.SEVERE, String.valueOf(message), null);
|
log(Level.SEVERE, String.valueOf(message), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -131,7 +131,7 @@ public class Jdk14Logger implements Log, Serializable {
|
|||||||
* @param exception log this cause
|
* @param exception log this cause
|
||||||
* @see org.apache.commons.logging.Log#error(Object, Throwable)
|
* @see org.apache.commons.logging.Log#error(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void error(Object message, Throwable exception) {
|
public void error(final Object message, final Throwable exception) {
|
||||||
log(Level.SEVERE, String.valueOf(message), exception);
|
log(Level.SEVERE, String.valueOf(message), exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ public class Jdk14Logger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#fatal(Object)
|
* @see org.apache.commons.logging.Log#fatal(Object)
|
||||||
*/
|
*/
|
||||||
public void fatal(Object message) {
|
public void fatal(final Object message) {
|
||||||
log(Level.SEVERE, String.valueOf(message), null);
|
log(Level.SEVERE, String.valueOf(message), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -152,7 +152,7 @@ public class Jdk14Logger implements Log, Serializable {
|
|||||||
* @param exception log this cause
|
* @param exception log this cause
|
||||||
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
|
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void fatal(Object message, Throwable exception) {
|
public void fatal(final Object message, final Throwable exception) {
|
||||||
log(Level.SEVERE, String.valueOf(message), exception);
|
log(Level.SEVERE, String.valueOf(message), exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ public class Jdk14Logger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#info(Object)
|
* @see org.apache.commons.logging.Log#info(Object)
|
||||||
*/
|
*/
|
||||||
public void info(Object message) {
|
public void info(final Object message) {
|
||||||
log(Level.INFO, String.valueOf(message), null);
|
log(Level.INFO, String.valueOf(message), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ public class Jdk14Logger implements Log, Serializable {
|
|||||||
* @param exception log this cause
|
* @param exception log this cause
|
||||||
* @see org.apache.commons.logging.Log#info(Object, Throwable)
|
* @see org.apache.commons.logging.Log#info(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void info(Object message, Throwable exception) {
|
public void info(final Object message, final Throwable exception) {
|
||||||
log(Level.INFO, String.valueOf(message), exception);
|
log(Level.INFO, String.valueOf(message), exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,7 +235,7 @@ public class Jdk14Logger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#trace(Object)
|
* @see org.apache.commons.logging.Log#trace(Object)
|
||||||
*/
|
*/
|
||||||
public void trace(Object message) {
|
public void trace(final Object message) {
|
||||||
log(Level.FINEST, String.valueOf(message), null);
|
log(Level.FINEST, String.valueOf(message), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,7 +246,7 @@ public class Jdk14Logger implements Log, Serializable {
|
|||||||
* @param exception log this cause
|
* @param exception log this cause
|
||||||
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
|
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void trace(Object message, Throwable exception) {
|
public void trace(final Object message, final Throwable exception) {
|
||||||
log(Level.FINEST, String.valueOf(message), exception);
|
log(Level.FINEST, String.valueOf(message), exception);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -256,7 +256,7 @@ public class Jdk14Logger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#warn(Object)
|
* @see org.apache.commons.logging.Log#warn(Object)
|
||||||
*/
|
*/
|
||||||
public void warn(Object message) {
|
public void warn(final Object message) {
|
||||||
log(Level.WARNING, String.valueOf(message), null);
|
log(Level.WARNING, String.valueOf(message), null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -267,7 +267,7 @@ public class Jdk14Logger implements Log, Serializable {
|
|||||||
* @param exception log this cause
|
* @param exception log this cause
|
||||||
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
|
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void warn(Object message, Throwable exception) {
|
public void warn(final Object message, final Throwable exception) {
|
||||||
log(Level.WARNING, String.valueOf(message), exception);
|
log(Level.WARNING, String.valueOf(message), exception);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -87,7 +87,7 @@ public class Log4JLogger implements Log, Serializable {
|
|||||||
Priority _traceLevel;
|
Priority _traceLevel;
|
||||||
try {
|
try {
|
||||||
_traceLevel = (Priority) Level.class.getDeclaredField("TRACE").get(null);
|
_traceLevel = (Priority) Level.class.getDeclaredField("TRACE").get(null);
|
||||||
} catch(Exception ex) {
|
} catch(final Exception ex) {
|
||||||
// ok, trace not available
|
// ok, trace not available
|
||||||
_traceLevel = Level.DEBUG;
|
_traceLevel = Level.DEBUG;
|
||||||
}
|
}
|
||||||
@@ -103,7 +103,7 @@ public class Log4JLogger implements Log, Serializable {
|
|||||||
/**
|
/**
|
||||||
* Base constructor.
|
* Base constructor.
|
||||||
*/
|
*/
|
||||||
public Log4JLogger(String name) {
|
public Log4JLogger(final String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.logger = getLogger();
|
this.logger = getLogger();
|
||||||
}
|
}
|
||||||
@@ -111,7 +111,7 @@ public class Log4JLogger implements Log, Serializable {
|
|||||||
/**
|
/**
|
||||||
* For use with a log4j factory.
|
* For use with a log4j factory.
|
||||||
*/
|
*/
|
||||||
public Log4JLogger(Logger logger) {
|
public Log4JLogger(final Logger logger) {
|
||||||
if (logger == null) {
|
if (logger == null) {
|
||||||
throw new IllegalArgumentException(
|
throw new IllegalArgumentException(
|
||||||
"Warning - null logger in constructor; possible log4j misconfiguration.");
|
"Warning - null logger in constructor; possible log4j misconfiguration.");
|
||||||
@@ -128,7 +128,7 @@ public class Log4JLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#trace(Object)
|
* @see org.apache.commons.logging.Log#trace(Object)
|
||||||
*/
|
*/
|
||||||
public void trace(Object message) {
|
public void trace(final Object message) {
|
||||||
getLogger().log(FQCN, traceLevel, message, null);
|
getLogger().log(FQCN, traceLevel, message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -141,7 +141,7 @@ public class Log4JLogger implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
|
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void trace(Object message, Throwable t) {
|
public void trace(final Object message, final Throwable t) {
|
||||||
getLogger().log(FQCN, traceLevel, message, t);
|
getLogger().log(FQCN, traceLevel, message, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -151,7 +151,7 @@ public class Log4JLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#debug(Object)
|
* @see org.apache.commons.logging.Log#debug(Object)
|
||||||
*/
|
*/
|
||||||
public void debug(Object message) {
|
public void debug(final Object message) {
|
||||||
getLogger().log(FQCN, Level.DEBUG, message, null);
|
getLogger().log(FQCN, Level.DEBUG, message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -162,7 +162,7 @@ public class Log4JLogger implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
|
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void debug(Object message, Throwable t) {
|
public void debug(final Object message, final Throwable t) {
|
||||||
getLogger().log(FQCN, Level.DEBUG, message, t);
|
getLogger().log(FQCN, Level.DEBUG, message, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -172,7 +172,7 @@ public class Log4JLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#info(Object)
|
* @see org.apache.commons.logging.Log#info(Object)
|
||||||
*/
|
*/
|
||||||
public void info(Object message) {
|
public void info(final Object message) {
|
||||||
getLogger().log(FQCN, Level.INFO, message, null);
|
getLogger().log(FQCN, Level.INFO, message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ public class Log4JLogger implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#info(Object, Throwable)
|
* @see org.apache.commons.logging.Log#info(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void info(Object message, Throwable t) {
|
public void info(final Object message, final Throwable t) {
|
||||||
getLogger().log(FQCN, Level.INFO, message, t);
|
getLogger().log(FQCN, Level.INFO, message, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +193,7 @@ public class Log4JLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#warn(Object)
|
* @see org.apache.commons.logging.Log#warn(Object)
|
||||||
*/
|
*/
|
||||||
public void warn(Object message) {
|
public void warn(final Object message) {
|
||||||
getLogger().log(FQCN, Level.WARN, message, null);
|
getLogger().log(FQCN, Level.WARN, message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -204,7 +204,7 @@ public class Log4JLogger implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
|
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void warn(Object message, Throwable t) {
|
public void warn(final Object message, final Throwable t) {
|
||||||
getLogger().log(FQCN, Level.WARN, message, t);
|
getLogger().log(FQCN, Level.WARN, message, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -214,7 +214,7 @@ public class Log4JLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#error(Object)
|
* @see org.apache.commons.logging.Log#error(Object)
|
||||||
*/
|
*/
|
||||||
public void error(Object message) {
|
public void error(final Object message) {
|
||||||
getLogger().log(FQCN, Level.ERROR, message, null);
|
getLogger().log(FQCN, Level.ERROR, message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -225,7 +225,7 @@ public class Log4JLogger implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#error(Object, Throwable)
|
* @see org.apache.commons.logging.Log#error(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void error(Object message, Throwable t) {
|
public void error(final Object message, final Throwable t) {
|
||||||
getLogger().log(FQCN, Level.ERROR, message, t);
|
getLogger().log(FQCN, Level.ERROR, message, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -235,7 +235,7 @@ public class Log4JLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#fatal(Object)
|
* @see org.apache.commons.logging.Log#fatal(Object)
|
||||||
*/
|
*/
|
||||||
public void fatal(Object message) {
|
public void fatal(final Object message) {
|
||||||
getLogger().log(FQCN, Level.FATAL, message, null);
|
getLogger().log(FQCN, Level.FATAL, message, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -246,7 +246,7 @@ public class Log4JLogger implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
|
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void fatal(Object message, Throwable t) {
|
public void fatal(final Object message, final Throwable t) {
|
||||||
getLogger().log(FQCN, Level.FATAL, message, t);
|
getLogger().log(FQCN, Level.FATAL, message, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -242,7 +242,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
*
|
*
|
||||||
* @param name Name of the attribute to return
|
* @param name Name of the attribute to return
|
||||||
*/
|
*/
|
||||||
public Object getAttribute(String name) {
|
public Object getAttribute(final String name) {
|
||||||
return attributes.get(name);
|
return attributes.get(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -264,7 +264,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
* @throws LogConfigurationException if a suitable <code>Log</code>
|
* @throws LogConfigurationException if a suitable <code>Log</code>
|
||||||
* instance cannot be returned
|
* instance cannot be returned
|
||||||
*/
|
*/
|
||||||
public Log getInstance(Class clazz) throws LogConfigurationException {
|
public Log getInstance(final Class clazz) throws LogConfigurationException {
|
||||||
return getInstance(clazz.getName());
|
return getInstance(clazz.getName());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,7 +285,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
* @throws LogConfigurationException if a suitable <code>Log</code>
|
* @throws LogConfigurationException if a suitable <code>Log</code>
|
||||||
* instance cannot be returned
|
* instance cannot be returned
|
||||||
*/
|
*/
|
||||||
public Log getInstance(String name) throws LogConfigurationException {
|
public Log getInstance(final String name) throws LogConfigurationException {
|
||||||
Log instance = (Log) instances.get(name);
|
Log instance = (Log) instances.get(name);
|
||||||
if (instance == null) {
|
if (instance == null) {
|
||||||
instance = newInstance(name);
|
instance = newInstance(name);
|
||||||
@@ -314,7 +314,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
*
|
*
|
||||||
* @param name Name of the attribute to remove
|
* @param name Name of the attribute to remove
|
||||||
*/
|
*/
|
||||||
public void removeAttribute(String name) {
|
public void removeAttribute(final String name) {
|
||||||
attributes.remove(name);
|
attributes.remove(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -342,7 +342,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
* @param value Value of the attribute to set, or <code>null</code>
|
* @param value Value of the attribute to set, or <code>null</code>
|
||||||
* to remove any setting for this attribute
|
* to remove any setting for this attribute
|
||||||
*/
|
*/
|
||||||
public void setAttribute(String name, Object value) {
|
public void setAttribute(final String name, final Object value) {
|
||||||
if (logConstructor != null) {
|
if (logConstructor != null) {
|
||||||
logDiagnostic("setAttribute: call too late; configuration already performed.");
|
logDiagnostic("setAttribute: call too late; configuration already performed.");
|
||||||
}
|
}
|
||||||
@@ -387,7 +387,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
* See LogFactory.getClassLoader.
|
* See LogFactory.getClassLoader.
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
protected static ClassLoader getClassLoader(Class clazz) {
|
protected static ClassLoader getClassLoader(final Class clazz) {
|
||||||
return LogFactory.getClassLoader(clazz);
|
return LogFactory.getClassLoader(clazz);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -415,8 +415,8 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
// the context it is intended to manage.
|
// the context it is intended to manage.
|
||||||
// Note that this prefix should be kept consistent with that
|
// Note that this prefix should be kept consistent with that
|
||||||
// in LogFactory.
|
// in LogFactory.
|
||||||
Class clazz = this.getClass();
|
final Class clazz = this.getClass();
|
||||||
ClassLoader classLoader = getClassLoader(clazz);
|
final ClassLoader classLoader = getClassLoader(clazz);
|
||||||
String classLoaderName;
|
String classLoaderName;
|
||||||
try {
|
try {
|
||||||
if (classLoader == null) {
|
if (classLoader == null) {
|
||||||
@@ -424,7 +424,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
} else {
|
} else {
|
||||||
classLoaderName = objectId(classLoader);
|
classLoaderName = objectId(classLoader);
|
||||||
}
|
}
|
||||||
} catch (SecurityException e) {
|
} catch (final SecurityException e) {
|
||||||
classLoaderName = "UNKNOWN";
|
classLoaderName = "UNKNOWN";
|
||||||
}
|
}
|
||||||
diagnosticPrefix = "[LogFactoryImpl@" + System.identityHashCode(this) + " from " + classLoaderName + "] ";
|
diagnosticPrefix = "[LogFactoryImpl@" + System.identityHashCode(this) + " from " + classLoaderName + "] ";
|
||||||
@@ -437,7 +437,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
* @param msg diagnostic message
|
* @param msg diagnostic message
|
||||||
* @since 1.1
|
* @since 1.1
|
||||||
*/
|
*/
|
||||||
protected void logDiagnostic(String msg) {
|
protected void logDiagnostic(final String msg) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logRawDiagnostic(diagnosticPrefix + msg);
|
logRawDiagnostic(diagnosticPrefix + msg);
|
||||||
}
|
}
|
||||||
@@ -533,37 +533,37 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
* @throws LogConfigurationException if a new instance cannot
|
* @throws LogConfigurationException if a new instance cannot
|
||||||
* be created
|
* be created
|
||||||
*/
|
*/
|
||||||
protected Log newInstance(String name) throws LogConfigurationException {
|
protected Log newInstance(final String name) throws LogConfigurationException {
|
||||||
Log instance;
|
Log instance;
|
||||||
try {
|
try {
|
||||||
if (logConstructor == null) {
|
if (logConstructor == null) {
|
||||||
instance = discoverLogImplementation(name);
|
instance = discoverLogImplementation(name);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
Object params[] = { name };
|
final Object params[] = { name };
|
||||||
instance = (Log) logConstructor.newInstance(params);
|
instance = (Log) logConstructor.newInstance(params);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (logMethod != null) {
|
if (logMethod != null) {
|
||||||
Object params[] = { this };
|
final Object params[] = { this };
|
||||||
logMethod.invoke(instance, params);
|
logMethod.invoke(instance, params);
|
||||||
}
|
}
|
||||||
|
|
||||||
return instance;
|
return instance;
|
||||||
|
|
||||||
} catch (LogConfigurationException lce) {
|
} catch (final LogConfigurationException lce) {
|
||||||
|
|
||||||
// this type of exception means there was a problem in discovery
|
// this type of exception means there was a problem in discovery
|
||||||
// and we've already output diagnostics about the issue, etc.;
|
// and we've already output diagnostics about the issue, etc.;
|
||||||
// just pass it on
|
// just pass it on
|
||||||
throw lce;
|
throw lce;
|
||||||
|
|
||||||
} catch (InvocationTargetException e) {
|
} catch (final InvocationTargetException e) {
|
||||||
// A problem occurred invoking the Constructor or Method
|
// A problem occurred invoking the Constructor or Method
|
||||||
// previously discovered
|
// previously discovered
|
||||||
Throwable c = e.getTargetException();
|
final Throwable c = e.getTargetException();
|
||||||
throw new LogConfigurationException(c == null ? e : c);
|
throw new LogConfigurationException(c == null ? e : c);
|
||||||
} catch (Throwable t) {
|
} catch (final Throwable t) {
|
||||||
handleThrowable(t); // may re-throw t
|
handleThrowable(t); // may re-throw t
|
||||||
// A problem occurred invoking the Constructor or Method
|
// A problem occurred invoking the Constructor or Method
|
||||||
// previously discovered
|
// previously discovered
|
||||||
@@ -635,7 +635,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
return cl.getParent();
|
return cl.getParent();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} catch (SecurityException ex) {
|
} catch (final SecurityException ex) {
|
||||||
logDiagnostic("[SECURITY] Unable to obtain parent classloader");
|
logDiagnostic("[SECURITY] Unable to obtain parent classloader");
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -647,12 +647,12 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
* present and available for use. Note that this does <i>not</i>
|
* present and available for use. Note that this does <i>not</i>
|
||||||
* affect the future behavior of this class.
|
* affect the future behavior of this class.
|
||||||
*/
|
*/
|
||||||
private boolean isLogLibraryAvailable(String name, String classname) {
|
private boolean isLogLibraryAvailable(final String name, final String classname) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("Checking for '" + name + "'.");
|
logDiagnostic("Checking for '" + name + "'.");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
Log log = createLogFromClass(
|
final Log log = createLogFromClass(
|
||||||
classname,
|
classname,
|
||||||
this.getClass().getName(), // dummy category
|
this.getClass().getName(), // dummy category
|
||||||
false);
|
false);
|
||||||
@@ -668,7 +668,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
} catch (LogConfigurationException e) {
|
} catch (final LogConfigurationException e) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("Logging system '" + name + "' is available but not useable.");
|
logDiagnostic("Logging system '" + name + "' is available but not useable.");
|
||||||
}
|
}
|
||||||
@@ -687,12 +687,12 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
*
|
*
|
||||||
* @return the value associated with the property, or null.
|
* @return the value associated with the property, or null.
|
||||||
*/
|
*/
|
||||||
private String getConfigurationValue(String property) {
|
private String getConfigurationValue(final String property) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("[ENV] Trying to get configuration for item " + property);
|
logDiagnostic("[ENV] Trying to get configuration for item " + property);
|
||||||
}
|
}
|
||||||
|
|
||||||
Object valueObj = getAttribute(property);
|
final Object valueObj = getAttribute(property);
|
||||||
if (valueObj != null) {
|
if (valueObj != null) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("[ENV] Found LogFactory attribute [" + valueObj + "] for " + property);
|
logDiagnostic("[ENV] Found LogFactory attribute [" + valueObj + "] for " + property);
|
||||||
@@ -709,7 +709,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
// property that the caller cannot, then output it in readable form as a
|
// property that the caller cannot, then output it in readable form as a
|
||||||
// diagnostic message. However it's only ever JCL-specific properties
|
// diagnostic message. However it's only ever JCL-specific properties
|
||||||
// involved here, so the harm is truly trivial.
|
// involved here, so the harm is truly trivial.
|
||||||
String value = getSystemProperty(property, null);
|
final String value = getSystemProperty(property, null);
|
||||||
if (value != null) {
|
if (value != null) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("[ENV] Found system property [" + value + "] for " + property);
|
logDiagnostic("[ENV] Found system property [" + value + "] for " + property);
|
||||||
@@ -720,7 +720,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("[ENV] No system property found for property " + property);
|
logDiagnostic("[ENV] No system property found for property " + property);
|
||||||
}
|
}
|
||||||
} catch (SecurityException e) {
|
} catch (final SecurityException e) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("[ENV] Security prevented reading system property " + property);
|
logDiagnostic("[ENV] Security prevented reading system property " + property);
|
||||||
}
|
}
|
||||||
@@ -737,8 +737,8 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
* Get the setting for the user-configurable behavior specified by key.
|
* Get the setting for the user-configurable behavior specified by key.
|
||||||
* If nothing has explicitly been set, then return dflt.
|
* If nothing has explicitly been set, then return dflt.
|
||||||
*/
|
*/
|
||||||
private boolean getBooleanConfiguration(String key, boolean dflt) {
|
private boolean getBooleanConfiguration(final String key, final boolean dflt) {
|
||||||
String val = getConfigurationValue(key);
|
final String val = getConfigurationValue(key);
|
||||||
if (val == null) {
|
if (val == null) {
|
||||||
return dflt;
|
return dflt;
|
||||||
}
|
}
|
||||||
@@ -767,7 +767,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
* @throws LogConfigurationException if an error in discovery occurs,
|
* @throws LogConfigurationException if an error in discovery occurs,
|
||||||
* or if no adapter at all can be instantiated
|
* or if no adapter at all can be instantiated
|
||||||
*/
|
*/
|
||||||
private Log discoverLogImplementation(String logCategory)
|
private Log discoverLogImplementation(final String logCategory)
|
||||||
throws LogConfigurationException {
|
throws LogConfigurationException {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("Discovering a Log implementation...");
|
logDiagnostic("Discovering a Log implementation...");
|
||||||
@@ -778,7 +778,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
Log result = null;
|
Log result = null;
|
||||||
|
|
||||||
// See if the user specified the Log implementation to use
|
// See if the user specified the Log implementation to use
|
||||||
String specifiedLogClassName = findUserSpecifiedLogClassName();
|
final String specifiedLogClassName = findUserSpecifiedLogClassName();
|
||||||
|
|
||||||
if (specifiedLogClassName != null) {
|
if (specifiedLogClassName != null) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
@@ -790,7 +790,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
logCategory,
|
logCategory,
|
||||||
true);
|
true);
|
||||||
if (result == null) {
|
if (result == null) {
|
||||||
StringBuffer messageBuffer = new StringBuffer("User-specified log class '");
|
final StringBuffer messageBuffer = new StringBuffer("User-specified log class '");
|
||||||
messageBuffer.append(specifiedLogClassName);
|
messageBuffer.append(specifiedLogClassName);
|
||||||
messageBuffer.append("' cannot be found or is not useable.");
|
messageBuffer.append("' cannot be found or is not useable.");
|
||||||
|
|
||||||
@@ -904,7 +904,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
specifiedClass = getSystemProperty(LOG_PROPERTY, null);
|
specifiedClass = getSystemProperty(LOG_PROPERTY, null);
|
||||||
} catch (SecurityException e) {
|
} catch (final SecurityException e) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("No access allowed to system property '" +
|
logDiagnostic("No access allowed to system property '" +
|
||||||
LOG_PROPERTY + "' - " + e.getMessage());
|
LOG_PROPERTY + "' - " + e.getMessage());
|
||||||
@@ -919,7 +919,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
specifiedClass = getSystemProperty(LOG_PROPERTY_OLD, null);
|
specifiedClass = getSystemProperty(LOG_PROPERTY_OLD, null);
|
||||||
} catch (SecurityException e) {
|
} catch (final SecurityException e) {
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("No access allowed to system property '" +
|
logDiagnostic("No access allowed to system property '" +
|
||||||
LOG_PROPERTY_OLD + "' - " + e.getMessage());
|
LOG_PROPERTY_OLD + "' - " + e.getMessage());
|
||||||
@@ -951,16 +951,16 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
* configuration and the handleFlawedDiscovery method decided this
|
* configuration and the handleFlawedDiscovery method decided this
|
||||||
* problem was fatal.
|
* problem was fatal.
|
||||||
*/
|
*/
|
||||||
private Log createLogFromClass(String logAdapterClassName,
|
private Log createLogFromClass(final String logAdapterClassName,
|
||||||
String logCategory,
|
final String logCategory,
|
||||||
boolean affectState)
|
final boolean affectState)
|
||||||
throws LogConfigurationException {
|
throws LogConfigurationException {
|
||||||
|
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("Attempting to instantiate '" + logAdapterClassName + "'");
|
logDiagnostic("Attempting to instantiate '" + logAdapterClassName + "'");
|
||||||
}
|
}
|
||||||
|
|
||||||
Object[] params = { logCategory };
|
final Object[] params = { logCategory };
|
||||||
Log logAdapter = null;
|
Log logAdapter = null;
|
||||||
Constructor constructor = null;
|
Constructor constructor = null;
|
||||||
|
|
||||||
@@ -978,7 +978,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
// will load the class from -- unless the classloader is doing
|
// will load the class from -- unless the classloader is doing
|
||||||
// something weird.
|
// something weird.
|
||||||
URL url;
|
URL url;
|
||||||
String resourceName = logAdapterClassName.replace('.', '/') + ".class";
|
final String resourceName = logAdapterClassName.replace('.', '/') + ".class";
|
||||||
if (currentCL != null) {
|
if (currentCL != null) {
|
||||||
url = currentCL.getResource(resourceName );
|
url = currentCL.getResource(resourceName );
|
||||||
} else {
|
} else {
|
||||||
@@ -995,7 +995,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
Class c;
|
Class c;
|
||||||
try {
|
try {
|
||||||
c = Class.forName(logAdapterClassName, true, currentCL);
|
c = Class.forName(logAdapterClassName, true, currentCL);
|
||||||
} catch (ClassNotFoundException originalClassNotFoundException) {
|
} catch (final ClassNotFoundException originalClassNotFoundException) {
|
||||||
// The current classloader was unable to find the log adapter
|
// The current classloader was unable to find the log adapter
|
||||||
// in this or any ancestor classloader. There's no point in
|
// in this or any ancestor classloader. There's no point in
|
||||||
// trying higher up in the hierarchy in this case..
|
// trying higher up in the hierarchy in this case..
|
||||||
@@ -1011,7 +1011,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
// Java 1.2 classloading guidelines but JCL can
|
// Java 1.2 classloading guidelines but JCL can
|
||||||
// and so should handle this case.
|
// and so should handle this case.
|
||||||
c = Class.forName(logAdapterClassName);
|
c = Class.forName(logAdapterClassName);
|
||||||
} catch (ClassNotFoundException secondaryClassNotFoundException) {
|
} catch (final ClassNotFoundException secondaryClassNotFoundException) {
|
||||||
// no point continuing: this adapter isn't available
|
// no point continuing: this adapter isn't available
|
||||||
msg = secondaryClassNotFoundException.getMessage();
|
msg = secondaryClassNotFoundException.getMessage();
|
||||||
logDiagnostic("The log adapter '" + logAdapterClassName +
|
logDiagnostic("The log adapter '" + logAdapterClassName +
|
||||||
@@ -1021,7 +1021,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
constructor = c.getConstructor(logConstructorSignature);
|
constructor = c.getConstructor(logConstructorSignature);
|
||||||
Object o = constructor.newInstance(params);
|
final Object o = constructor.newInstance(params);
|
||||||
|
|
||||||
// Note that we do this test after trying to create an instance
|
// Note that we do this test after trying to create an instance
|
||||||
// [rather than testing Log.class.isAssignableFrom(c)] so that
|
// [rather than testing Log.class.isAssignableFrom(c)] so that
|
||||||
@@ -1044,34 +1044,34 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
// LogConfigurationException if it regards this problem as
|
// LogConfigurationException if it regards this problem as
|
||||||
// fatal, and just return if not.
|
// fatal, and just return if not.
|
||||||
handleFlawedHierarchy(currentCL, c);
|
handleFlawedHierarchy(currentCL, c);
|
||||||
} catch (NoClassDefFoundError e) {
|
} catch (final NoClassDefFoundError e) {
|
||||||
// We were able to load the adapter but it had references to
|
// We were able to load the adapter but it had references to
|
||||||
// other classes that could not be found. This simply means that
|
// other classes that could not be found. This simply means that
|
||||||
// the underlying logger library is not present in this or any
|
// the underlying logger library is not present in this or any
|
||||||
// ancestor classloader. There's no point in trying higher up
|
// ancestor classloader. There's no point in trying higher up
|
||||||
// in the hierarchy in this case..
|
// in the hierarchy in this case..
|
||||||
String msg = e.getMessage();
|
final String msg = e.getMessage();
|
||||||
logDiagnostic("The log adapter '" + logAdapterClassName +
|
logDiagnostic("The log adapter '" + logAdapterClassName +
|
||||||
"' is missing dependencies when loaded via classloader " + objectId(currentCL) +
|
"' is missing dependencies when loaded via classloader " + objectId(currentCL) +
|
||||||
": " + msg.trim());
|
": " + msg.trim());
|
||||||
break;
|
break;
|
||||||
} catch (ExceptionInInitializerError e) {
|
} catch (final ExceptionInInitializerError e) {
|
||||||
// A static initializer block or the initializer code associated
|
// A static initializer block or the initializer code associated
|
||||||
// with a static variable on the log adapter class has thrown
|
// with a static variable on the log adapter class has thrown
|
||||||
// an exception.
|
// an exception.
|
||||||
//
|
//
|
||||||
// We treat this as meaning the adapter's underlying logging
|
// We treat this as meaning the adapter's underlying logging
|
||||||
// library could not be found.
|
// library could not be found.
|
||||||
String msg = e.getMessage();
|
final String msg = e.getMessage();
|
||||||
logDiagnostic("The log adapter '" + logAdapterClassName +
|
logDiagnostic("The log adapter '" + logAdapterClassName +
|
||||||
"' is unable to initialize itself when loaded via classloader " + objectId(currentCL) +
|
"' is unable to initialize itself when loaded via classloader " + objectId(currentCL) +
|
||||||
": " + msg.trim());
|
": " + msg.trim());
|
||||||
break;
|
break;
|
||||||
} catch (LogConfigurationException e) {
|
} catch (final LogConfigurationException e) {
|
||||||
// call to handleFlawedHierarchy above must have thrown
|
// call to handleFlawedHierarchy above must have thrown
|
||||||
// a LogConfigurationException, so just throw it on
|
// a LogConfigurationException, so just throw it on
|
||||||
throw e;
|
throw e;
|
||||||
} catch (Throwable t) {
|
} catch (final Throwable t) {
|
||||||
handleThrowable(t); // may re-throw t
|
handleThrowable(t); // may re-throw t
|
||||||
// handleFlawedDiscovery will determine whether this is a fatal
|
// handleFlawedDiscovery will determine whether this is a fatal
|
||||||
// problem or not. If it is fatal, then a LogConfigurationException
|
// problem or not. If it is fatal, then a LogConfigurationException
|
||||||
@@ -1097,7 +1097,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
try {
|
try {
|
||||||
this.logMethod = logAdapterClass.getMethod("setLogFactory", logMethodSignature);
|
this.logMethod = logAdapterClass.getMethod("setLogFactory", logMethodSignature);
|
||||||
logDiagnostic("Found method setLogFactory(LogFactory) in '" + logAdapterClassName + "'");
|
logDiagnostic("Found method setLogFactory(LogFactory) in '" + logAdapterClassName + "'");
|
||||||
} catch (Throwable t) {
|
} catch (final Throwable t) {
|
||||||
handleThrowable(t); // may re-throw t
|
handleThrowable(t); // may re-throw t
|
||||||
this.logMethod = null;
|
this.logMethod = null;
|
||||||
logDiagnostic("[INFO] '" + logAdapterClassName + "' from classloader " + objectId(currentCL) +
|
logDiagnostic("[INFO] '" + logAdapterClassName + "' from classloader " + objectId(currentCL) +
|
||||||
@@ -1130,15 +1130,15 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private ClassLoader getBaseClassLoader() throws LogConfigurationException {
|
private ClassLoader getBaseClassLoader() throws LogConfigurationException {
|
||||||
ClassLoader thisClassLoader = getClassLoader(LogFactoryImpl.class);
|
final ClassLoader thisClassLoader = getClassLoader(LogFactoryImpl.class);
|
||||||
|
|
||||||
if (!useTCCL) {
|
if (!useTCCL) {
|
||||||
return thisClassLoader;
|
return thisClassLoader;
|
||||||
}
|
}
|
||||||
|
|
||||||
ClassLoader contextClassLoader = getContextClassLoaderInternal();
|
final ClassLoader contextClassLoader = getContextClassLoaderInternal();
|
||||||
|
|
||||||
ClassLoader baseClassLoader = getLowestClassLoader(
|
final ClassLoader baseClassLoader = getLowestClassLoader(
|
||||||
contextClassLoader, thisClassLoader);
|
contextClassLoader, thisClassLoader);
|
||||||
|
|
||||||
if (baseClassLoader == null) {
|
if (baseClassLoader == null) {
|
||||||
@@ -1200,7 +1200,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
* @return c1 if it has c2 as an ancestor, c2 if it has c1 as an ancestor,
|
* @return c1 if it has c2 as an ancestor, c2 if it has c1 as an ancestor,
|
||||||
* and null if neither is an ancestor of the other.
|
* and null if neither is an ancestor of the other.
|
||||||
*/
|
*/
|
||||||
private ClassLoader getLowestClassLoader(ClassLoader c1, ClassLoader c2) {
|
private ClassLoader getLowestClassLoader(final ClassLoader c1, final ClassLoader c2) {
|
||||||
// TODO: use AccessController when dealing with classloaders here
|
// TODO: use AccessController when dealing with classloaders here
|
||||||
|
|
||||||
if (c1 == null) {
|
if (c1 == null) {
|
||||||
@@ -1251,9 +1251,9 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
*
|
*
|
||||||
* @throws LogConfigurationException ALWAYS
|
* @throws LogConfigurationException ALWAYS
|
||||||
*/
|
*/
|
||||||
private void handleFlawedDiscovery(String logAdapterClassName,
|
private void handleFlawedDiscovery(final String logAdapterClassName,
|
||||||
ClassLoader classLoader, // USED?
|
final ClassLoader classLoader, // USED?
|
||||||
Throwable discoveryFlaw) {
|
final Throwable discoveryFlaw) {
|
||||||
|
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
logDiagnostic("Could not instantiate Log '" +
|
logDiagnostic("Could not instantiate Log '" +
|
||||||
@@ -1265,16 +1265,16 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
// Ok, the lib is there but while trying to create a real underlying
|
// Ok, the lib is there but while trying to create a real underlying
|
||||||
// logger something failed in the underlying lib; display info about
|
// logger something failed in the underlying lib; display info about
|
||||||
// that if possible.
|
// that if possible.
|
||||||
InvocationTargetException ite = (InvocationTargetException)discoveryFlaw;
|
final InvocationTargetException ite = (InvocationTargetException)discoveryFlaw;
|
||||||
Throwable cause = ite.getTargetException();
|
final Throwable cause = ite.getTargetException();
|
||||||
if (cause != null) {
|
if (cause != null) {
|
||||||
logDiagnostic("... InvocationTargetException: " +
|
logDiagnostic("... InvocationTargetException: " +
|
||||||
cause.getClass().getName() + ": " +
|
cause.getClass().getName() + ": " +
|
||||||
cause.getLocalizedMessage());
|
cause.getLocalizedMessage());
|
||||||
|
|
||||||
if (cause instanceof ExceptionInInitializerError) {
|
if (cause instanceof ExceptionInInitializerError) {
|
||||||
ExceptionInInitializerError eiie = (ExceptionInInitializerError)cause;
|
final ExceptionInInitializerError eiie = (ExceptionInInitializerError)cause;
|
||||||
Throwable cause2 = eiie.getException();
|
final Throwable cause2 = eiie.getException();
|
||||||
if (cause2 != null) {
|
if (cause2 != null) {
|
||||||
final StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
cause2.printStackTrace(new PrintWriter(sw, true));
|
cause2.printStackTrace(new PrintWriter(sw, true));
|
||||||
@@ -1316,12 +1316,12 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
* @throws LogConfigurationException when the situation
|
* @throws LogConfigurationException when the situation
|
||||||
* should not be recovered from.
|
* should not be recovered from.
|
||||||
*/
|
*/
|
||||||
private void handleFlawedHierarchy(ClassLoader badClassLoader, Class badClass)
|
private void handleFlawedHierarchy(final ClassLoader badClassLoader, final Class badClass)
|
||||||
throws LogConfigurationException {
|
throws LogConfigurationException {
|
||||||
|
|
||||||
boolean implementsLog = false;
|
boolean implementsLog = false;
|
||||||
String logInterfaceName = Log.class.getName();
|
final String logInterfaceName = Log.class.getName();
|
||||||
Class interfaces[] = badClass.getInterfaces();
|
final Class interfaces[] = badClass.getInterfaces();
|
||||||
for (int i = 0; i < interfaces.length; i++) {
|
for (int i = 0; i < interfaces.length; i++) {
|
||||||
if (logInterfaceName.equals(interfaces[i].getName())) {
|
if (logInterfaceName.equals(interfaces[i].getName())) {
|
||||||
implementsLog = true;
|
implementsLog = true;
|
||||||
@@ -1334,18 +1334,18 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
// it is in the wrong classloader
|
// it is in the wrong classloader
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
try {
|
try {
|
||||||
ClassLoader logInterfaceClassLoader = getClassLoader(Log.class);
|
final ClassLoader logInterfaceClassLoader = getClassLoader(Log.class);
|
||||||
logDiagnostic("Class '" + badClass.getName() + "' was found in classloader " +
|
logDiagnostic("Class '" + badClass.getName() + "' was found in classloader " +
|
||||||
objectId(badClassLoader) + ". It is bound to a Log interface which is not" +
|
objectId(badClassLoader) + ". It is bound to a Log interface which is not" +
|
||||||
" the one loaded from classloader " + objectId(logInterfaceClassLoader));
|
" the one loaded from classloader " + objectId(logInterfaceClassLoader));
|
||||||
} catch (Throwable t) {
|
} catch (final Throwable t) {
|
||||||
handleThrowable(t); // may re-throw t
|
handleThrowable(t); // may re-throw t
|
||||||
logDiagnostic("Error while trying to output diagnostics about" + " bad class '" + badClass + "'");
|
logDiagnostic("Error while trying to output diagnostics about" + " bad class '" + badClass + "'");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!allowFlawedHierarchy) {
|
if (!allowFlawedHierarchy) {
|
||||||
StringBuffer msg = new StringBuffer();
|
final StringBuffer msg = new StringBuffer();
|
||||||
msg.append("Terminating logging for this context ");
|
msg.append("Terminating logging for this context ");
|
||||||
msg.append("due to bad log hierarchy. ");
|
msg.append("due to bad log hierarchy. ");
|
||||||
msg.append("You have more than one version of '");
|
msg.append("You have more than one version of '");
|
||||||
@@ -1358,7 +1358,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
StringBuffer msg = new StringBuffer();
|
final StringBuffer msg = new StringBuffer();
|
||||||
msg.append("Warning: bad log hierarchy. ");
|
msg.append("Warning: bad log hierarchy. ");
|
||||||
msg.append("You have more than one version of '");
|
msg.append("You have more than one version of '");
|
||||||
msg.append(Log.class.getName());
|
msg.append(Log.class.getName());
|
||||||
@@ -1368,7 +1368,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
} else {
|
} else {
|
||||||
// this is just a bad adapter class
|
// this is just a bad adapter class
|
||||||
if (!allowFlawedDiscovery) {
|
if (!allowFlawedDiscovery) {
|
||||||
StringBuffer msg = new StringBuffer();
|
final StringBuffer msg = new StringBuffer();
|
||||||
msg.append("Terminating logging for this context. ");
|
msg.append("Terminating logging for this context. ");
|
||||||
msg.append("Log class '");
|
msg.append("Log class '");
|
||||||
msg.append(badClass.getName());
|
msg.append(badClass.getName());
|
||||||
@@ -1381,7 +1381,7 @@ public class LogFactoryImpl extends LogFactory {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (isDiagnosticsEnabled()) {
|
if (isDiagnosticsEnabled()) {
|
||||||
StringBuffer msg = new StringBuffer();
|
final StringBuffer msg = new StringBuffer();
|
||||||
msg.append("[WARNING] Log class '");
|
msg.append("[WARNING] Log class '");
|
||||||
msg.append(badClass.getName());
|
msg.append(badClass.getName());
|
||||||
msg.append("' does not implement the Log interface.");
|
msg.append("' does not implement the Log interface.");
|
||||||
|
|||||||
@@ -54,7 +54,7 @@ public class LogKitLogger implements Log, Serializable {
|
|||||||
*
|
*
|
||||||
* @param name log name
|
* @param name log name
|
||||||
*/
|
*/
|
||||||
public LogKitLogger(String name) {
|
public LogKitLogger(final String name) {
|
||||||
this.name = name;
|
this.name = name;
|
||||||
this.logger = getLogger();
|
this.logger = getLogger();
|
||||||
}
|
}
|
||||||
@@ -85,7 +85,7 @@ public class LogKitLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#trace(Object)
|
* @see org.apache.commons.logging.Log#trace(Object)
|
||||||
*/
|
*/
|
||||||
public void trace(Object message) {
|
public void trace(final Object message) {
|
||||||
debug(message);
|
debug(message);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -96,7 +96,7 @@ public class LogKitLogger implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
|
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void trace(Object message, Throwable t) {
|
public void trace(final Object message, final Throwable t) {
|
||||||
debug(message, t);
|
debug(message, t);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -106,7 +106,7 @@ public class LogKitLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#debug(Object)
|
* @see org.apache.commons.logging.Log#debug(Object)
|
||||||
*/
|
*/
|
||||||
public void debug(Object message) {
|
public void debug(final Object message) {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
getLogger().debug(String.valueOf(message));
|
getLogger().debug(String.valueOf(message));
|
||||||
}
|
}
|
||||||
@@ -119,7 +119,7 @@ public class LogKitLogger implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
|
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void debug(Object message, Throwable t) {
|
public void debug(final Object message, final Throwable t) {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
getLogger().debug(String.valueOf(message), t);
|
getLogger().debug(String.valueOf(message), t);
|
||||||
}
|
}
|
||||||
@@ -131,7 +131,7 @@ public class LogKitLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#info(Object)
|
* @see org.apache.commons.logging.Log#info(Object)
|
||||||
*/
|
*/
|
||||||
public void info(Object message) {
|
public void info(final Object message) {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
getLogger().info(String.valueOf(message));
|
getLogger().info(String.valueOf(message));
|
||||||
}
|
}
|
||||||
@@ -144,7 +144,7 @@ public class LogKitLogger implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#info(Object, Throwable)
|
* @see org.apache.commons.logging.Log#info(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void info(Object message, Throwable t) {
|
public void info(final Object message, final Throwable t) {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
getLogger().info(String.valueOf(message), t);
|
getLogger().info(String.valueOf(message), t);
|
||||||
}
|
}
|
||||||
@@ -156,7 +156,7 @@ public class LogKitLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#warn(Object)
|
* @see org.apache.commons.logging.Log#warn(Object)
|
||||||
*/
|
*/
|
||||||
public void warn(Object message) {
|
public void warn(final Object message) {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
getLogger().warn(String.valueOf(message));
|
getLogger().warn(String.valueOf(message));
|
||||||
}
|
}
|
||||||
@@ -169,7 +169,7 @@ public class LogKitLogger implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
|
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void warn(Object message, Throwable t) {
|
public void warn(final Object message, final Throwable t) {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
getLogger().warn(String.valueOf(message), t);
|
getLogger().warn(String.valueOf(message), t);
|
||||||
}
|
}
|
||||||
@@ -181,7 +181,7 @@ public class LogKitLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#error(Object)
|
* @see org.apache.commons.logging.Log#error(Object)
|
||||||
*/
|
*/
|
||||||
public void error(Object message) {
|
public void error(final Object message) {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
getLogger().error(String.valueOf(message));
|
getLogger().error(String.valueOf(message));
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ public class LogKitLogger implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#error(Object, Throwable)
|
* @see org.apache.commons.logging.Log#error(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void error(Object message, Throwable t) {
|
public void error(final Object message, final Throwable t) {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
getLogger().error(String.valueOf(message), t);
|
getLogger().error(String.valueOf(message), t);
|
||||||
}
|
}
|
||||||
@@ -206,7 +206,7 @@ public class LogKitLogger implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#fatal(Object)
|
* @see org.apache.commons.logging.Log#fatal(Object)
|
||||||
*/
|
*/
|
||||||
public void fatal(Object message) {
|
public void fatal(final Object message) {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
getLogger().fatalError(String.valueOf(message));
|
getLogger().fatalError(String.valueOf(message));
|
||||||
}
|
}
|
||||||
@@ -219,7 +219,7 @@ public class LogKitLogger implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
|
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public void fatal(Object message, Throwable t) {
|
public void fatal(final Object message, final Throwable t) {
|
||||||
if (message != null) {
|
if (message != null) {
|
||||||
getLogger().fatalError(String.valueOf(message), t);
|
getLogger().fatalError(String.valueOf(message), t);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,31 +34,31 @@ public class NoOpLog implements Log, Serializable {
|
|||||||
/** Convenience constructor */
|
/** Convenience constructor */
|
||||||
public NoOpLog() { }
|
public NoOpLog() { }
|
||||||
/** Base constructor */
|
/** Base constructor */
|
||||||
public NoOpLog(String name) { }
|
public NoOpLog(final String name) { }
|
||||||
/** Do nothing */
|
/** Do nothing */
|
||||||
public void trace(Object message) { }
|
public void trace(final Object message) { }
|
||||||
/** Do nothing */
|
/** Do nothing */
|
||||||
public void trace(Object message, Throwable t) { }
|
public void trace(final Object message, final Throwable t) { }
|
||||||
/** Do nothing */
|
/** Do nothing */
|
||||||
public void debug(Object message) { }
|
public void debug(final Object message) { }
|
||||||
/** Do nothing */
|
/** Do nothing */
|
||||||
public void debug(Object message, Throwable t) { }
|
public void debug(final Object message, final Throwable t) { }
|
||||||
/** Do nothing */
|
/** Do nothing */
|
||||||
public void info(Object message) { }
|
public void info(final Object message) { }
|
||||||
/** Do nothing */
|
/** Do nothing */
|
||||||
public void info(Object message, Throwable t) { }
|
public void info(final Object message, final Throwable t) { }
|
||||||
/** Do nothing */
|
/** Do nothing */
|
||||||
public void warn(Object message) { }
|
public void warn(final Object message) { }
|
||||||
/** Do nothing */
|
/** Do nothing */
|
||||||
public void warn(Object message, Throwable t) { }
|
public void warn(final Object message, final Throwable t) { }
|
||||||
/** Do nothing */
|
/** Do nothing */
|
||||||
public void error(Object message) { }
|
public void error(final Object message) { }
|
||||||
/** Do nothing */
|
/** Do nothing */
|
||||||
public void error(Object message, Throwable t) { }
|
public void error(final Object message, final Throwable t) { }
|
||||||
/** Do nothing */
|
/** Do nothing */
|
||||||
public void fatal(Object message) { }
|
public void fatal(final Object message) { }
|
||||||
/** Do nothing */
|
/** Do nothing */
|
||||||
public void fatal(Object message, Throwable t) { }
|
public void fatal(final Object message, final Throwable t) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Debug is never enabled.
|
* Debug is never enabled.
|
||||||
|
|||||||
@@ -56,10 +56,10 @@ public class ServletContextCleaner implements ServletContextListener {
|
|||||||
* class to release any logging information related to the current
|
* class to release any logging information related to the current
|
||||||
* contextClassloader.
|
* contextClassloader.
|
||||||
*/
|
*/
|
||||||
public void contextDestroyed(ServletContextEvent sce) {
|
public void contextDestroyed(final ServletContextEvent sce) {
|
||||||
ClassLoader tccl = Thread.currentThread().getContextClassLoader();
|
final ClassLoader tccl = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
Object[] params = new Object[1];
|
final Object[] params = new Object[1];
|
||||||
params[0] = tccl;
|
params[0] = tccl;
|
||||||
|
|
||||||
// Walk up the tree of classloaders, finding all the available
|
// Walk up the tree of classloaders, finding all the available
|
||||||
@@ -98,23 +98,23 @@ public class ServletContextCleaner implements ServletContextListener {
|
|||||||
// via this loader, but is accessible via some ancestor then that class
|
// via this loader, but is accessible via some ancestor then that class
|
||||||
// will be returned.
|
// will be returned.
|
||||||
try {
|
try {
|
||||||
Class logFactoryClass = loader.loadClass("org.apache.commons.logging.LogFactory");
|
final Class logFactoryClass = loader.loadClass("org.apache.commons.logging.LogFactory");
|
||||||
Method releaseMethod = logFactoryClass.getMethod("release", RELEASE_SIGNATURE);
|
final Method releaseMethod = logFactoryClass.getMethod("release", RELEASE_SIGNATURE);
|
||||||
releaseMethod.invoke(null, params);
|
releaseMethod.invoke(null, params);
|
||||||
loader = logFactoryClass.getClassLoader().getParent();
|
loader = logFactoryClass.getClassLoader().getParent();
|
||||||
} catch(ClassNotFoundException ex) {
|
} catch(final ClassNotFoundException ex) {
|
||||||
// Neither the current classloader nor any of its ancestors could find
|
// Neither the current classloader nor any of its ancestors could find
|
||||||
// the LogFactory class, so we can stop now.
|
// the LogFactory class, so we can stop now.
|
||||||
loader = null;
|
loader = null;
|
||||||
} catch(NoSuchMethodException ex) {
|
} catch(final NoSuchMethodException ex) {
|
||||||
// This is not expected; every version of JCL has this method
|
// This is not expected; every version of JCL has this method
|
||||||
System.err.println("LogFactory instance found which does not support release method!");
|
System.err.println("LogFactory instance found which does not support release method!");
|
||||||
loader = null;
|
loader = null;
|
||||||
} catch(IllegalAccessException ex) {
|
} catch(final IllegalAccessException ex) {
|
||||||
// This is not expected; every ancestor class should be accessible
|
// This is not expected; every ancestor class should be accessible
|
||||||
System.err.println("LogFactory instance found which is not accessable!");
|
System.err.println("LogFactory instance found which is not accessable!");
|
||||||
loader = null;
|
loader = null;
|
||||||
} catch(InvocationTargetException ex) {
|
} catch(final InvocationTargetException ex) {
|
||||||
// This is not expected
|
// This is not expected
|
||||||
System.err.println("LogFactory instance release method failed!");
|
System.err.println("LogFactory instance release method failed!");
|
||||||
loader = null;
|
loader = null;
|
||||||
@@ -130,7 +130,7 @@ public class ServletContextCleaner implements ServletContextListener {
|
|||||||
/**
|
/**
|
||||||
* Invoked when a webapp is deployed. Nothing needs to be done here.
|
* Invoked when a webapp is deployed. Nothing needs to be done here.
|
||||||
*/
|
*/
|
||||||
public void contextInitialized(ServletContextEvent sce) {
|
public void contextInitialized(final ServletContextEvent sce) {
|
||||||
// do nothing
|
// do nothing
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -133,23 +133,23 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
|
|
||||||
// ------------------------------------------------------------ Initializer
|
// ------------------------------------------------------------ Initializer
|
||||||
|
|
||||||
private static String getStringProperty(String name) {
|
private static String getStringProperty(final String name) {
|
||||||
String prop = null;
|
String prop = null;
|
||||||
try {
|
try {
|
||||||
prop = System.getProperty(name);
|
prop = System.getProperty(name);
|
||||||
} catch (SecurityException e) {
|
} catch (final SecurityException e) {
|
||||||
// Ignore
|
// Ignore
|
||||||
}
|
}
|
||||||
return prop == null ? simpleLogProps.getProperty(name) : prop;
|
return prop == null ? simpleLogProps.getProperty(name) : prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String getStringProperty(String name, String dephault) {
|
private static String getStringProperty(final String name, final String dephault) {
|
||||||
String prop = getStringProperty(name);
|
final String prop = getStringProperty(name);
|
||||||
return prop == null ? dephault : prop;
|
return prop == null ? dephault : prop;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean getBooleanProperty(String name, boolean dephault) {
|
private static boolean getBooleanProperty(final String name, final boolean dephault) {
|
||||||
String prop = getStringProperty(name);
|
final String prop = getStringProperty(name);
|
||||||
return prop == null ? dephault : "true".equalsIgnoreCase(prop);
|
return prop == null ? dephault : "true".equalsIgnoreCase(prop);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,16 +158,16 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
// Override with system properties.
|
// Override with system properties.
|
||||||
static {
|
static {
|
||||||
// Add props from the resource simplelog.properties
|
// Add props from the resource simplelog.properties
|
||||||
InputStream in = getResourceAsStream("simplelog.properties");
|
final InputStream in = getResourceAsStream("simplelog.properties");
|
||||||
if (null != in) {
|
if (null != in) {
|
||||||
try {
|
try {
|
||||||
simpleLogProps.load(in);
|
simpleLogProps.load(in);
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
// ignored
|
// ignored
|
||||||
} finally {
|
} finally {
|
||||||
try {
|
try {
|
||||||
in.close();
|
in.close();
|
||||||
} catch (IOException e) {
|
} catch (final IOException e) {
|
||||||
// ignored
|
// ignored
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -182,7 +182,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
dateTimeFormat);
|
dateTimeFormat);
|
||||||
try {
|
try {
|
||||||
dateFormatter = new SimpleDateFormat(dateTimeFormat);
|
dateFormatter = new SimpleDateFormat(dateTimeFormat);
|
||||||
} catch(IllegalArgumentException e) {
|
} catch(final IllegalArgumentException e) {
|
||||||
// If the format pattern is invalid - use the default format
|
// If the format pattern is invalid - use the default format
|
||||||
dateTimeFormat = DEFAULT_DATE_TIME_FORMAT;
|
dateTimeFormat = DEFAULT_DATE_TIME_FORMAT;
|
||||||
dateFormatter = new SimpleDateFormat(dateTimeFormat);
|
dateFormatter = new SimpleDateFormat(dateTimeFormat);
|
||||||
@@ -253,7 +253,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
*
|
*
|
||||||
* @param currentLogLevel new logging level
|
* @param currentLogLevel new logging level
|
||||||
*/
|
*/
|
||||||
public void setLevel(int currentLogLevel) {
|
public void setLevel(final int currentLogLevel) {
|
||||||
this.currentLogLevel = currentLogLevel;
|
this.currentLogLevel = currentLogLevel;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -276,7 +276,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
* @param message The message itself (typically a String)
|
* @param message The message itself (typically a String)
|
||||||
* @param t The exception whose stack trace should be logged
|
* @param t The exception whose stack trace should be logged
|
||||||
*/
|
*/
|
||||||
protected void log(int type, Object message, Throwable t) {
|
protected void log(final int type, final Object message, final Throwable t) {
|
||||||
// Use a string buffer for better performance
|
// Use a string buffer for better performance
|
||||||
final StringBuffer buf = new StringBuffer();
|
final StringBuffer buf = new StringBuffer();
|
||||||
|
|
||||||
@@ -341,7 +341,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
* @param buffer A <code>StringBuffer</code> containing the accumulated
|
* @param buffer A <code>StringBuffer</code> containing the accumulated
|
||||||
* text to be logged
|
* text to be logged
|
||||||
*/
|
*/
|
||||||
protected void write(StringBuffer buffer) {
|
protected void write(final StringBuffer buffer) {
|
||||||
System.err.println(buffer.toString());
|
System.err.println(buffer.toString());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -350,7 +350,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
*
|
*
|
||||||
* @param logLevel is this level enabled?
|
* @param logLevel is this level enabled?
|
||||||
*/
|
*/
|
||||||
protected boolean isLevelEnabled(int logLevel) {
|
protected boolean isLevelEnabled(final int logLevel) {
|
||||||
// log level are numerically ordered so can use simple numeric
|
// log level are numerically ordered so can use simple numeric
|
||||||
// comparison
|
// comparison
|
||||||
return logLevel >= currentLogLevel;
|
return logLevel >= currentLogLevel;
|
||||||
@@ -365,7 +365,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#debug(Object)
|
* @see org.apache.commons.logging.Log#debug(Object)
|
||||||
*/
|
*/
|
||||||
public final void debug(Object message) {
|
public final void debug(final Object message) {
|
||||||
if (isLevelEnabled(SimpleLog.LOG_LEVEL_DEBUG)) {
|
if (isLevelEnabled(SimpleLog.LOG_LEVEL_DEBUG)) {
|
||||||
log(SimpleLog.LOG_LEVEL_DEBUG, message, null);
|
log(SimpleLog.LOG_LEVEL_DEBUG, message, null);
|
||||||
}
|
}
|
||||||
@@ -379,7 +379,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
|
* @see org.apache.commons.logging.Log#debug(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public final void debug(Object message, Throwable t) {
|
public final void debug(final Object message, final Throwable t) {
|
||||||
if (isLevelEnabled(SimpleLog.LOG_LEVEL_DEBUG)) {
|
if (isLevelEnabled(SimpleLog.LOG_LEVEL_DEBUG)) {
|
||||||
log(SimpleLog.LOG_LEVEL_DEBUG, message, t);
|
log(SimpleLog.LOG_LEVEL_DEBUG, message, t);
|
||||||
}
|
}
|
||||||
@@ -391,7 +391,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#trace(Object)
|
* @see org.apache.commons.logging.Log#trace(Object)
|
||||||
*/
|
*/
|
||||||
public final void trace(Object message) {
|
public final void trace(final Object message) {
|
||||||
if (isLevelEnabled(SimpleLog.LOG_LEVEL_TRACE)) {
|
if (isLevelEnabled(SimpleLog.LOG_LEVEL_TRACE)) {
|
||||||
log(SimpleLog.LOG_LEVEL_TRACE, message, null);
|
log(SimpleLog.LOG_LEVEL_TRACE, message, null);
|
||||||
}
|
}
|
||||||
@@ -404,7 +404,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
|
* @see org.apache.commons.logging.Log#trace(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public final void trace(Object message, Throwable t) {
|
public final void trace(final Object message, final Throwable t) {
|
||||||
if (isLevelEnabled(SimpleLog.LOG_LEVEL_TRACE)) {
|
if (isLevelEnabled(SimpleLog.LOG_LEVEL_TRACE)) {
|
||||||
log(SimpleLog.LOG_LEVEL_TRACE, message, t);
|
log(SimpleLog.LOG_LEVEL_TRACE, message, t);
|
||||||
}
|
}
|
||||||
@@ -416,7 +416,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#info(Object)
|
* @see org.apache.commons.logging.Log#info(Object)
|
||||||
*/
|
*/
|
||||||
public final void info(Object message) {
|
public final void info(final Object message) {
|
||||||
if (isLevelEnabled(SimpleLog.LOG_LEVEL_INFO)) {
|
if (isLevelEnabled(SimpleLog.LOG_LEVEL_INFO)) {
|
||||||
log(SimpleLog.LOG_LEVEL_INFO,message,null);
|
log(SimpleLog.LOG_LEVEL_INFO,message,null);
|
||||||
}
|
}
|
||||||
@@ -429,7 +429,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#info(Object, Throwable)
|
* @see org.apache.commons.logging.Log#info(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public final void info(Object message, Throwable t) {
|
public final void info(final Object message, final Throwable t) {
|
||||||
if (isLevelEnabled(SimpleLog.LOG_LEVEL_INFO)) {
|
if (isLevelEnabled(SimpleLog.LOG_LEVEL_INFO)) {
|
||||||
log(SimpleLog.LOG_LEVEL_INFO, message, t);
|
log(SimpleLog.LOG_LEVEL_INFO, message, t);
|
||||||
}
|
}
|
||||||
@@ -441,7 +441,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#warn(Object)
|
* @see org.apache.commons.logging.Log#warn(Object)
|
||||||
*/
|
*/
|
||||||
public final void warn(Object message) {
|
public final void warn(final Object message) {
|
||||||
if (isLevelEnabled(SimpleLog.LOG_LEVEL_WARN)) {
|
if (isLevelEnabled(SimpleLog.LOG_LEVEL_WARN)) {
|
||||||
log(SimpleLog.LOG_LEVEL_WARN, message, null);
|
log(SimpleLog.LOG_LEVEL_WARN, message, null);
|
||||||
}
|
}
|
||||||
@@ -454,7 +454,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
|
* @see org.apache.commons.logging.Log#warn(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public final void warn(Object message, Throwable t) {
|
public final void warn(final Object message, final Throwable t) {
|
||||||
if (isLevelEnabled(SimpleLog.LOG_LEVEL_WARN)) {
|
if (isLevelEnabled(SimpleLog.LOG_LEVEL_WARN)) {
|
||||||
log(SimpleLog.LOG_LEVEL_WARN, message, t);
|
log(SimpleLog.LOG_LEVEL_WARN, message, t);
|
||||||
}
|
}
|
||||||
@@ -466,7 +466,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#error(Object)
|
* @see org.apache.commons.logging.Log#error(Object)
|
||||||
*/
|
*/
|
||||||
public final void error(Object message) {
|
public final void error(final Object message) {
|
||||||
if (isLevelEnabled(SimpleLog.LOG_LEVEL_ERROR)) {
|
if (isLevelEnabled(SimpleLog.LOG_LEVEL_ERROR)) {
|
||||||
log(SimpleLog.LOG_LEVEL_ERROR, message, null);
|
log(SimpleLog.LOG_LEVEL_ERROR, message, null);
|
||||||
}
|
}
|
||||||
@@ -479,7 +479,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#error(Object, Throwable)
|
* @see org.apache.commons.logging.Log#error(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public final void error(Object message, Throwable t) {
|
public final void error(final Object message, final Throwable t) {
|
||||||
if (isLevelEnabled(SimpleLog.LOG_LEVEL_ERROR)) {
|
if (isLevelEnabled(SimpleLog.LOG_LEVEL_ERROR)) {
|
||||||
log(SimpleLog.LOG_LEVEL_ERROR, message, t);
|
log(SimpleLog.LOG_LEVEL_ERROR, message, t);
|
||||||
}
|
}
|
||||||
@@ -491,7 +491,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
* @param message to log
|
* @param message to log
|
||||||
* @see org.apache.commons.logging.Log#fatal(Object)
|
* @see org.apache.commons.logging.Log#fatal(Object)
|
||||||
*/
|
*/
|
||||||
public final void fatal(Object message) {
|
public final void fatal(final Object message) {
|
||||||
if (isLevelEnabled(SimpleLog.LOG_LEVEL_FATAL)) {
|
if (isLevelEnabled(SimpleLog.LOG_LEVEL_FATAL)) {
|
||||||
log(SimpleLog.LOG_LEVEL_FATAL, message, null);
|
log(SimpleLog.LOG_LEVEL_FATAL, message, null);
|
||||||
}
|
}
|
||||||
@@ -504,7 +504,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
* @param t log this cause
|
* @param t log this cause
|
||||||
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
|
* @see org.apache.commons.logging.Log#fatal(Object, Throwable)
|
||||||
*/
|
*/
|
||||||
public final void fatal(Object message, Throwable t) {
|
public final void fatal(final Object message, final Throwable t) {
|
||||||
if (isLevelEnabled(SimpleLog.LOG_LEVEL_FATAL)) {
|
if (isLevelEnabled(SimpleLog.LOG_LEVEL_FATAL)) {
|
||||||
log(SimpleLog.LOG_LEVEL_FATAL, message, t);
|
log(SimpleLog.LOG_LEVEL_FATAL, message, t);
|
||||||
}
|
}
|
||||||
@@ -596,9 +596,9 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
// Get the thread context class loader (if there is one)
|
// Get the thread context class loader (if there is one)
|
||||||
try {
|
try {
|
||||||
classLoader = (ClassLoader)method.invoke(Thread.currentThread(), (Class[]) null);
|
classLoader = (ClassLoader)method.invoke(Thread.currentThread(), (Class[]) null);
|
||||||
} catch (IllegalAccessException e) {
|
} catch (final IllegalAccessException e) {
|
||||||
// ignore
|
// ignore
|
||||||
} catch (InvocationTargetException e) {
|
} catch (final InvocationTargetException e) {
|
||||||
/**
|
/**
|
||||||
* InvocationTargetException is thrown by 'invoke' when
|
* InvocationTargetException is thrown by 'invoke' when
|
||||||
* the method being invoked (getContextClassLoader) throws
|
* the method being invoked (getContextClassLoader) throws
|
||||||
@@ -624,7 +624,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
("Unexpected InvocationTargetException", e.getTargetException());
|
("Unexpected InvocationTargetException", e.getTargetException());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (NoSuchMethodException e) {
|
} catch (final NoSuchMethodException e) {
|
||||||
// Assume we are running on JDK 1.1
|
// Assume we are running on JDK 1.1
|
||||||
// ignore
|
// ignore
|
||||||
}
|
}
|
||||||
@@ -641,7 +641,7 @@ public class SimpleLog implements Log, Serializable {
|
|||||||
return (InputStream)AccessController.doPrivileged(
|
return (InputStream)AccessController.doPrivileged(
|
||||||
new PrivilegedAction() {
|
new PrivilegedAction() {
|
||||||
public Object run() {
|
public Object run() {
|
||||||
ClassLoader threadCL = getContextClassLoader();
|
final ClassLoader threadCL = getContextClassLoader();
|
||||||
|
|
||||||
if (threadCL != null) {
|
if (threadCL != null) {
|
||||||
return threadCL.getResourceAsStream(name);
|
return threadCL.getResourceAsStream(name);
|
||||||
|
|||||||
@@ -139,9 +139,9 @@ public final class WeakHashtable extends Hashtable {
|
|||||||
/**
|
/**
|
||||||
*@see Hashtable
|
*@see Hashtable
|
||||||
*/
|
*/
|
||||||
public boolean containsKey(Object key) {
|
public boolean containsKey(final Object key) {
|
||||||
// purge should not be required
|
// purge should not be required
|
||||||
Referenced referenced = new Referenced(key);
|
final Referenced referenced = new Referenced(key);
|
||||||
return super.containsKey(referenced);
|
return super.containsKey(referenced);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -158,15 +158,15 @@ public final class WeakHashtable extends Hashtable {
|
|||||||
*/
|
*/
|
||||||
public Set entrySet() {
|
public Set entrySet() {
|
||||||
purge();
|
purge();
|
||||||
Set referencedEntries = super.entrySet();
|
final Set referencedEntries = super.entrySet();
|
||||||
Set unreferencedEntries = new HashSet();
|
final Set unreferencedEntries = new HashSet();
|
||||||
for (Iterator it=referencedEntries.iterator(); it.hasNext();) {
|
for (final Iterator it=referencedEntries.iterator(); it.hasNext();) {
|
||||||
Map.Entry entry = (Map.Entry) it.next();
|
final Map.Entry entry = (Map.Entry) it.next();
|
||||||
Referenced referencedKey = (Referenced) entry.getKey();
|
final Referenced referencedKey = (Referenced) entry.getKey();
|
||||||
Object key = referencedKey.getValue();
|
final Object key = referencedKey.getValue();
|
||||||
Object value = entry.getValue();
|
final Object value = entry.getValue();
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
Entry dereferencedEntry = new Entry(key, value);
|
final Entry dereferencedEntry = new Entry(key, value);
|
||||||
unreferencedEntries.add(dereferencedEntry);
|
unreferencedEntries.add(dereferencedEntry);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -176,9 +176,9 @@ public final class WeakHashtable extends Hashtable {
|
|||||||
/**
|
/**
|
||||||
*@see Hashtable
|
*@see Hashtable
|
||||||
*/
|
*/
|
||||||
public Object get(Object key) {
|
public Object get(final Object key) {
|
||||||
// for performance reasons, no purge
|
// for performance reasons, no purge
|
||||||
Referenced referenceKey = new Referenced(key);
|
final Referenced referenceKey = new Referenced(key);
|
||||||
return super.get(referenceKey);
|
return super.get(referenceKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -193,7 +193,7 @@ public final class WeakHashtable extends Hashtable {
|
|||||||
return enumer.hasMoreElements();
|
return enumer.hasMoreElements();
|
||||||
}
|
}
|
||||||
public Object nextElement() {
|
public Object nextElement() {
|
||||||
Referenced nextReference = (Referenced) enumer.nextElement();
|
final Referenced nextReference = (Referenced) enumer.nextElement();
|
||||||
return nextReference.getValue();
|
return nextReference.getValue();
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@@ -204,11 +204,11 @@ public final class WeakHashtable extends Hashtable {
|
|||||||
*/
|
*/
|
||||||
public Set keySet() {
|
public Set keySet() {
|
||||||
purge();
|
purge();
|
||||||
Set referencedKeys = super.keySet();
|
final Set referencedKeys = super.keySet();
|
||||||
Set unreferencedKeys = new HashSet();
|
final Set unreferencedKeys = new HashSet();
|
||||||
for (Iterator it=referencedKeys.iterator(); it.hasNext();) {
|
for (final Iterator it=referencedKeys.iterator(); it.hasNext();) {
|
||||||
Referenced referenceKey = (Referenced) it.next();
|
final Referenced referenceKey = (Referenced) it.next();
|
||||||
Object keyValue = referenceKey.getValue();
|
final Object keyValue = referenceKey.getValue();
|
||||||
if (keyValue != null) {
|
if (keyValue != null) {
|
||||||
unreferencedKeys.add(keyValue);
|
unreferencedKeys.add(keyValue);
|
||||||
}
|
}
|
||||||
@@ -219,7 +219,7 @@ public final class WeakHashtable extends Hashtable {
|
|||||||
/**
|
/**
|
||||||
*@see Hashtable
|
*@see Hashtable
|
||||||
*/
|
*/
|
||||||
public synchronized Object put(Object key, Object value) {
|
public synchronized Object put(final Object key, final Object value) {
|
||||||
// check for nulls, ensuring semantics match superclass
|
// check for nulls, ensuring semantics match superclass
|
||||||
if (key == null) {
|
if (key == null) {
|
||||||
throw new NullPointerException("Null keys are not allowed");
|
throw new NullPointerException("Null keys are not allowed");
|
||||||
@@ -239,18 +239,18 @@ public final class WeakHashtable extends Hashtable {
|
|||||||
purgeOne();
|
purgeOne();
|
||||||
}
|
}
|
||||||
|
|
||||||
Referenced keyRef = new Referenced(key, queue);
|
final Referenced keyRef = new Referenced(key, queue);
|
||||||
return super.put(keyRef, value);
|
return super.put(keyRef, value);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*@see Hashtable
|
*@see Hashtable
|
||||||
*/
|
*/
|
||||||
public void putAll(Map t) {
|
public void putAll(final Map t) {
|
||||||
if (t != null) {
|
if (t != null) {
|
||||||
Set entrySet = t.entrySet();
|
final Set entrySet = t.entrySet();
|
||||||
for (Iterator it=entrySet.iterator(); it.hasNext();) {
|
for (final Iterator it=entrySet.iterator(); it.hasNext();) {
|
||||||
Map.Entry entry = (Map.Entry) it.next();
|
final Map.Entry entry = (Map.Entry) it.next();
|
||||||
put(entry.getKey(), entry.getValue());
|
put(entry.getKey(), entry.getValue());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -267,7 +267,7 @@ public final class WeakHashtable extends Hashtable {
|
|||||||
/**
|
/**
|
||||||
*@see Hashtable
|
*@see Hashtable
|
||||||
*/
|
*/
|
||||||
public synchronized Object remove(Object key) {
|
public synchronized Object remove(final Object key) {
|
||||||
// for performance reasons, only purge every
|
// for performance reasons, only purge every
|
||||||
// MAX_CHANGES_BEFORE_PURGE times
|
// MAX_CHANGES_BEFORE_PURGE times
|
||||||
if (changeCount++ > MAX_CHANGES_BEFORE_PURGE) {
|
if (changeCount++ > MAX_CHANGES_BEFORE_PURGE) {
|
||||||
@@ -342,7 +342,7 @@ public final class WeakHashtable extends Hashtable {
|
|||||||
*/
|
*/
|
||||||
private void purgeOne() {
|
private void purgeOne() {
|
||||||
synchronized (queue) {
|
synchronized (queue) {
|
||||||
WeakKey key = (WeakKey) queue.poll();
|
final WeakKey key = (WeakKey) queue.poll();
|
||||||
if (key != null) {
|
if (key != null) {
|
||||||
super.remove(key.getReferenced());
|
super.remove(key.getReferenced());
|
||||||
}
|
}
|
||||||
@@ -355,15 +355,15 @@ public final class WeakHashtable extends Hashtable {
|
|||||||
private final Object key;
|
private final Object key;
|
||||||
private final Object value;
|
private final Object value;
|
||||||
|
|
||||||
private Entry(Object key, Object value) {
|
private Entry(final Object key, final Object value) {
|
||||||
this.key = key;
|
this.key = key;
|
||||||
this.value = value;
|
this.value = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
public boolean equals(final Object o) {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
if (o instanceof Map.Entry) {
|
if (o instanceof Map.Entry) {
|
||||||
Map.Entry entry = (Map.Entry) o;
|
final Map.Entry entry = (Map.Entry) o;
|
||||||
result = (getKey()==null ?
|
result = (getKey()==null ?
|
||||||
entry.getKey() == null :
|
entry.getKey() == null :
|
||||||
getKey().equals(entry.getKey())) &&
|
getKey().equals(entry.getKey())) &&
|
||||||
@@ -379,7 +379,7 @@ public final class WeakHashtable extends Hashtable {
|
|||||||
(getValue()==null ? 0 : getValue().hashCode());
|
(getValue()==null ? 0 : getValue().hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
public Object setValue(Object value) {
|
public Object setValue(final Object value) {
|
||||||
throw new UnsupportedOperationException("Entry.setValue is not supported.");
|
throw new UnsupportedOperationException("Entry.setValue is not supported.");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -402,7 +402,7 @@ public final class WeakHashtable extends Hashtable {
|
|||||||
*
|
*
|
||||||
* @throws NullPointerException if referant is <code>null</code>
|
* @throws NullPointerException if referant is <code>null</code>
|
||||||
*/
|
*/
|
||||||
private Referenced(Object referant) {
|
private Referenced(final Object referant) {
|
||||||
reference = new WeakReference(referant);
|
reference = new WeakReference(referant);
|
||||||
// Calc a permanent hashCode so calls to Hashtable.remove()
|
// Calc a permanent hashCode so calls to Hashtable.remove()
|
||||||
// work if the WeakReference has been cleared
|
// work if the WeakReference has been cleared
|
||||||
@@ -413,7 +413,7 @@ public final class WeakHashtable extends Hashtable {
|
|||||||
*
|
*
|
||||||
* @throws NullPointerException if key is <code>null</code>
|
* @throws NullPointerException if key is <code>null</code>
|
||||||
*/
|
*/
|
||||||
private Referenced(Object key, ReferenceQueue queue) {
|
private Referenced(final Object key, final ReferenceQueue queue) {
|
||||||
reference = new WeakKey(key, queue, this);
|
reference = new WeakKey(key, queue, this);
|
||||||
// Calc a permanent hashCode so calls to Hashtable.remove()
|
// Calc a permanent hashCode so calls to Hashtable.remove()
|
||||||
// work if the WeakReference has been cleared
|
// work if the WeakReference has been cleared
|
||||||
@@ -429,12 +429,12 @@ public final class WeakHashtable extends Hashtable {
|
|||||||
return reference.get();
|
return reference.get();
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean equals(Object o) {
|
public boolean equals(final Object o) {
|
||||||
boolean result = false;
|
boolean result = false;
|
||||||
if (o instanceof Referenced) {
|
if (o instanceof Referenced) {
|
||||||
Referenced otherKey = (Referenced) o;
|
final Referenced otherKey = (Referenced) o;
|
||||||
Object thisKeyValue = getValue();
|
final Object thisKeyValue = getValue();
|
||||||
Object otherKeyValue = otherKey.getValue();
|
final Object otherKeyValue = otherKey.getValue();
|
||||||
if (thisKeyValue == null) {
|
if (thisKeyValue == null) {
|
||||||
result = otherKeyValue == null;
|
result = otherKeyValue == null;
|
||||||
|
|
||||||
@@ -468,9 +468,9 @@ public final class WeakHashtable extends Hashtable {
|
|||||||
|
|
||||||
private final Referenced referenced;
|
private final Referenced referenced;
|
||||||
|
|
||||||
private WeakKey(Object key,
|
private WeakKey(final Object key,
|
||||||
ReferenceQueue queue,
|
final ReferenceQueue queue,
|
||||||
Referenced referenced) {
|
final Referenced referenced) {
|
||||||
super(key, queue);
|
super(key, queue);
|
||||||
this.referenced = referenced;
|
this.referenced = referenced;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ public abstract class AbstractLogTest extends TestCase {
|
|||||||
|
|
||||||
public void testLoggingWithNullParameters()
|
public void testLoggingWithNullParameters()
|
||||||
{
|
{
|
||||||
Log log = this.getLogObject();
|
final Log log = this.getLogObject();
|
||||||
|
|
||||||
assertNotNull(log);
|
assertNotNull(log);
|
||||||
|
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ public class AltHashtable extends Hashtable {
|
|||||||
public static Object lastKey;
|
public static Object lastKey;
|
||||||
public static Object lastValue;
|
public static Object lastValue;
|
||||||
|
|
||||||
public Object put(Object key, Object value) {
|
public Object put(final Object key, final Object value) {
|
||||||
lastKey = key;
|
lastKey = key;
|
||||||
lastValue = value;
|
lastValue = value;
|
||||||
return super.put(key, value);
|
return super.put(key, value);
|
||||||
|
|||||||
@@ -28,15 +28,15 @@ import junit.framework.TestCase;
|
|||||||
public class AltHashtableTestCase extends TestCase {
|
public class AltHashtableTestCase extends TestCase {
|
||||||
|
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
Class thisClass = AltHashtableTestCase.class;
|
final Class thisClass = AltHashtableTestCase.class;
|
||||||
ClassLoader thisClassLoader = thisClass.getClassLoader();
|
final ClassLoader thisClassLoader = thisClass.getClassLoader();
|
||||||
|
|
||||||
PathableClassLoader loader = new PathableClassLoader(null);
|
final PathableClassLoader loader = new PathableClassLoader(null);
|
||||||
loader.useExplicitLoader("junit.", thisClassLoader);
|
loader.useExplicitLoader("junit.", thisClassLoader);
|
||||||
loader.addLogicalLib("testclasses");
|
loader.addLogicalLib("testclasses");
|
||||||
loader.addLogicalLib("commons-logging");
|
loader.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
Class testClass = loader.loadClass(thisClass.getName());
|
final Class testClass = loader.loadClass(thisClass.getName());
|
||||||
return new PathableTestSuite(testClass, loader);
|
return new PathableTestSuite(testClass, loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -86,7 +86,7 @@ public class AltHashtableTestCase extends TestCase {
|
|||||||
AltHashtable.lastValue = null;
|
AltHashtable.lastValue = null;
|
||||||
|
|
||||||
LogFactory.getLog(AltHashtableTestCase.class);
|
LogFactory.getLog(AltHashtableTestCase.class);
|
||||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||||
assertEquals(contextLoader, AltHashtable.lastKey);
|
assertEquals(contextLoader, AltHashtable.lastKey);
|
||||||
assertNotNull(AltHashtable.lastValue);
|
assertNotNull(AltHashtable.lastValue);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,17 +29,17 @@ public class BasicOperationsTestCase extends TestCase
|
|||||||
{
|
{
|
||||||
public void testIsEnabledClassLog()
|
public void testIsEnabledClassLog()
|
||||||
{
|
{
|
||||||
Log log = LogFactory.getLog(BasicOperationsTestCase.class);
|
final Log log = LogFactory.getLog(BasicOperationsTestCase.class);
|
||||||
executeIsEnabledTest(log);
|
executeIsEnabledTest(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testIsEnabledNamedLog()
|
public void testIsEnabledNamedLog()
|
||||||
{
|
{
|
||||||
Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
|
final Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
|
||||||
executeIsEnabledTest(log);
|
executeIsEnabledTest(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeIsEnabledTest(Log log)
|
public void executeIsEnabledTest(final Log log)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -50,7 +50,7 @@ public class BasicOperationsTestCase extends TestCase
|
|||||||
log.isErrorEnabled();
|
log.isErrorEnabled();
|
||||||
log.isFatalEnabled();
|
log.isFatalEnabled();
|
||||||
}
|
}
|
||||||
catch (Throwable t)
|
catch (final Throwable t)
|
||||||
{
|
{
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
fail("Exception thrown: " + t);
|
fail("Exception thrown: " + t);
|
||||||
@@ -59,17 +59,17 @@ public class BasicOperationsTestCase extends TestCase
|
|||||||
|
|
||||||
public void testMessageWithoutExceptionClassLog()
|
public void testMessageWithoutExceptionClassLog()
|
||||||
{
|
{
|
||||||
Log log = LogFactory.getLog(BasicOperationsTestCase.class);
|
final Log log = LogFactory.getLog(BasicOperationsTestCase.class);
|
||||||
executeMessageWithoutExceptionTest(log);
|
executeMessageWithoutExceptionTest(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMessageWithoutExceptionNamedLog()
|
public void testMessageWithoutExceptionNamedLog()
|
||||||
{
|
{
|
||||||
Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
|
final Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
|
||||||
executeMessageWithoutExceptionTest(log);
|
executeMessageWithoutExceptionTest(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeMessageWithoutExceptionTest(Log log)
|
public void executeMessageWithoutExceptionTest(final Log log)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -80,7 +80,7 @@ public class BasicOperationsTestCase extends TestCase
|
|||||||
log.error("Hello, Mum");
|
log.error("Hello, Mum");
|
||||||
log.fatal("Hello, Mum");
|
log.fatal("Hello, Mum");
|
||||||
}
|
}
|
||||||
catch (Throwable t)
|
catch (final Throwable t)
|
||||||
{
|
{
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
fail("Exception thrown: " + t);
|
fail("Exception thrown: " + t);
|
||||||
@@ -89,17 +89,17 @@ public class BasicOperationsTestCase extends TestCase
|
|||||||
|
|
||||||
public void testMessageWithExceptionClassLog()
|
public void testMessageWithExceptionClassLog()
|
||||||
{
|
{
|
||||||
Log log = LogFactory.getLog(BasicOperationsTestCase.class);
|
final Log log = LogFactory.getLog(BasicOperationsTestCase.class);
|
||||||
executeMessageWithExceptionTest(log);
|
executeMessageWithExceptionTest(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void testMessageWithExceptionNamedLog()
|
public void testMessageWithExceptionNamedLog()
|
||||||
{
|
{
|
||||||
Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
|
final Log log = LogFactory.getLog(BasicOperationsTestCase.class.getName());
|
||||||
executeMessageWithExceptionTest(log);
|
executeMessageWithExceptionTest(log);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void executeMessageWithExceptionTest(Log log)
|
public void executeMessageWithExceptionTest(final Log log)
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
@@ -110,7 +110,7 @@ public class BasicOperationsTestCase extends TestCase
|
|||||||
log.error("Hello, Mum", new ArithmeticException());
|
log.error("Hello, Mum", new ArithmeticException());
|
||||||
log.fatal("Hello, Mum", new ArithmeticException());
|
log.fatal("Hello, Mum", new ArithmeticException());
|
||||||
}
|
}
|
||||||
catch (Throwable t)
|
catch (final Throwable t)
|
||||||
{
|
{
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
fail("Exception thrown: " + t);
|
fail("Exception thrown: " + t);
|
||||||
|
|||||||
@@ -41,11 +41,11 @@ public class LoadTestCase extends TestCase{
|
|||||||
|
|
||||||
java.util.Map classes = new java.util.HashMap();
|
java.util.Map classes = new java.util.HashMap();
|
||||||
|
|
||||||
AppClassLoader(ClassLoader parent){
|
AppClassLoader(final ClassLoader parent){
|
||||||
super(parent);
|
super(parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Class def(String name)throws ClassNotFoundException{
|
private Class def(final String name)throws ClassNotFoundException{
|
||||||
|
|
||||||
Class result = (Class)classes.get(name);
|
Class result = (Class)classes.get(name);
|
||||||
if(result != null){
|
if(result != null){
|
||||||
@@ -54,23 +54,23 @@ public class LoadTestCase extends TestCase{
|
|||||||
|
|
||||||
try{
|
try{
|
||||||
|
|
||||||
ClassLoader cl = this.getClass().getClassLoader();
|
final ClassLoader cl = this.getClass().getClassLoader();
|
||||||
String classFileName = name.replace('.','/') + ".class";
|
final String classFileName = name.replace('.','/') + ".class";
|
||||||
java.io.InputStream is = cl.getResourceAsStream(classFileName);
|
final java.io.InputStream is = cl.getResourceAsStream(classFileName);
|
||||||
java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
|
final java.io.ByteArrayOutputStream out = new java.io.ByteArrayOutputStream();
|
||||||
|
|
||||||
while(is.available() > 0){
|
while(is.available() > 0){
|
||||||
out.write(is.read());
|
out.write(is.read());
|
||||||
}
|
}
|
||||||
|
|
||||||
byte data [] = out.toByteArray();
|
final byte data [] = out.toByteArray();
|
||||||
|
|
||||||
result = super.defineClass(name, data, 0, data.length );
|
result = super.defineClass(name, data, 0, data.length );
|
||||||
classes.put(name,result);
|
classes.put(name,result);
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
||||||
}catch(java.io.IOException ioe){
|
}catch(final java.io.IOException ioe){
|
||||||
|
|
||||||
throw new ClassNotFoundException( name + " caused by "
|
throw new ClassNotFoundException( name + " caused by "
|
||||||
+ ioe.getMessage() );
|
+ ioe.getMessage() );
|
||||||
@@ -81,7 +81,7 @@ public class LoadTestCase extends TestCase{
|
|||||||
|
|
||||||
// not very trivial to emulate we must implement "findClass",
|
// not very trivial to emulate we must implement "findClass",
|
||||||
// but it will delegete to junit class loder first
|
// but it will delegete to junit class loder first
|
||||||
public Class loadClass(String name)throws ClassNotFoundException{
|
public Class loadClass(final String name)throws ClassNotFoundException{
|
||||||
|
|
||||||
//isolates all logging classes, application in the same classloader too.
|
//isolates all logging classes, application in the same classloader too.
|
||||||
//filters exeptions to simlify handling in test
|
//filters exeptions to simlify handling in test
|
||||||
@@ -102,9 +102,9 @@ public class LoadTestCase extends TestCase{
|
|||||||
* (expected to be a UserClass loaded via a custom classloader), passing
|
* (expected to be a UserClass loaded via a custom classloader), passing
|
||||||
* it the specified state parameter.
|
* it the specified state parameter.
|
||||||
*/
|
*/
|
||||||
private void setAllowFlawedContext(Class c, String state) throws Exception {
|
private void setAllowFlawedContext(final Class c, final String state) throws Exception {
|
||||||
Class[] params = {String.class};
|
final Class[] params = {String.class};
|
||||||
java.lang.reflect.Method m = c.getDeclaredMethod("setAllowFlawedContext", params);
|
final java.lang.reflect.Method m = c.getDeclaredMethod("setAllowFlawedContext", params);
|
||||||
m.invoke(null, new Object[] {state});
|
m.invoke(null, new Object[] {state});
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +145,7 @@ public class LoadTestCase extends TestCase{
|
|||||||
setAllowFlawedContext(cls, "false");
|
setAllowFlawedContext(cls, "false");
|
||||||
execute(cls);
|
execute(cls);
|
||||||
fail("Logging config succeeded when context classloader was null!");
|
fail("Logging config succeeded when context classloader was null!");
|
||||||
} catch(LogConfigurationException ex) {
|
} catch(final LogConfigurationException ex) {
|
||||||
// expected; the boot classloader doesn't *have* JCL available
|
// expected; the boot classloader doesn't *have* JCL available
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -170,7 +170,7 @@ public class LoadTestCase extends TestCase{
|
|||||||
execute(cls);
|
execute(cls);
|
||||||
fail("Error: somehow downcast a Logger loaded via system classloader"
|
fail("Error: somehow downcast a Logger loaded via system classloader"
|
||||||
+ " to the Log interface loaded via a custom classloader");
|
+ " to the Log interface loaded via a custom classloader");
|
||||||
} catch(LogConfigurationException ex) {
|
} catch(final LogConfigurationException ex) {
|
||||||
// expected
|
// expected
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -183,15 +183,15 @@ public class LoadTestCase extends TestCase{
|
|||||||
|
|
||||||
Class testObjCls = null;
|
Class testObjCls = null;
|
||||||
|
|
||||||
AppClassLoader appLoader = new AppClassLoader(
|
final AppClassLoader appLoader = new AppClassLoader(
|
||||||
this.getClass().getClassLoader());
|
this.getClass().getClassLoader());
|
||||||
try{
|
try{
|
||||||
|
|
||||||
testObjCls = appLoader.loadClass(UserClass.class.getName());
|
testObjCls = appLoader.loadClass(UserClass.class.getName());
|
||||||
|
|
||||||
}catch(ClassNotFoundException cnfe){
|
}catch(final ClassNotFoundException cnfe){
|
||||||
throw cnfe;
|
throw cnfe;
|
||||||
}catch(Throwable t){
|
}catch(final Throwable t){
|
||||||
t.printStackTrace();
|
t.printStackTrace();
|
||||||
fail("AppClassLoader failed ");
|
fail("AppClassLoader failed ");
|
||||||
}
|
}
|
||||||
@@ -205,7 +205,7 @@ public class LoadTestCase extends TestCase{
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void execute(Class cls)throws Exception{
|
private void execute(final Class cls)throws Exception{
|
||||||
|
|
||||||
cls.newInstance();
|
cls.newInstance();
|
||||||
|
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
* creates its own classloader to run unit tests in (eg maven2's
|
* creates its own classloader to run unit tests in (eg maven2's
|
||||||
* Surefire plugin).
|
* Surefire plugin).
|
||||||
*/
|
*/
|
||||||
public PathableClassLoader(ClassLoader parent) {
|
public PathableClassLoader(final ClassLoader parent) {
|
||||||
super(NO_URLS, parent);
|
super(NO_URLS, parent);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -102,7 +102,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
* use addLogicalLib instead, then define the location for that logical
|
* use addLogicalLib instead, then define the location for that logical
|
||||||
* library in the build.xml file.
|
* library in the build.xml file.
|
||||||
*/
|
*/
|
||||||
public void addURL(URL url) {
|
public void addURL(final URL url) {
|
||||||
super.addURL(url);
|
super.addURL(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -122,7 +122,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
* <p>
|
* <p>
|
||||||
* This value defaults to true.
|
* This value defaults to true.
|
||||||
*/
|
*/
|
||||||
public void setParentFirst(boolean state) {
|
public void setParentFirst(final boolean state) {
|
||||||
parentFirst = state;
|
parentFirst = state;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -138,7 +138,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
* Of course, this assumes that the classes of interest are already
|
* Of course, this assumes that the classes of interest are already
|
||||||
* in the classpath of the system classloader.
|
* in the classpath of the system classloader.
|
||||||
*/
|
*/
|
||||||
public void useSystemLoader(String prefix) {
|
public void useSystemLoader(final String prefix) {
|
||||||
useExplicitLoader(prefix, ClassLoader.getSystemClassLoader());
|
useExplicitLoader(prefix, ClassLoader.getSystemClassLoader());
|
||||||
|
|
||||||
}
|
}
|
||||||
@@ -168,7 +168,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
* then a prefix used to map from here to one of those classloaders.
|
* then a prefix used to map from here to one of those classloaders.
|
||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public void useExplicitLoader(String prefix, ClassLoader loader) {
|
public void useExplicitLoader(final String prefix, final ClassLoader loader) {
|
||||||
if (lookasides == null) {
|
if (lookasides == null) {
|
||||||
lookasides = new HashMap();
|
lookasides = new HashMap();
|
||||||
}
|
}
|
||||||
@@ -178,7 +178,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
/**
|
/**
|
||||||
* Specify a collection of logical libraries. See addLogicalLib.
|
* Specify a collection of logical libraries. See addLogicalLib.
|
||||||
*/
|
*/
|
||||||
public void addLogicalLib(String[] logicalLibs) {
|
public void addLogicalLib(final String[] logicalLibs) {
|
||||||
for(int i=0; i<logicalLibs.length; ++i) {
|
for(int i=0; i<logicalLibs.length; ++i) {
|
||||||
addLogicalLib(logicalLibs[i]);
|
addLogicalLib(logicalLibs[i]);
|
||||||
}
|
}
|
||||||
@@ -204,22 +204,22 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
* desired classpath without knowing the exact location of the necessary
|
* desired classpath without knowing the exact location of the necessary
|
||||||
* classes.
|
* classes.
|
||||||
*/
|
*/
|
||||||
public void addLogicalLib(String logicalLib) {
|
public void addLogicalLib(final String logicalLib) {
|
||||||
// first, check the system properties
|
// first, check the system properties
|
||||||
String filename = System.getProperty(logicalLib);
|
final String filename = System.getProperty(logicalLib);
|
||||||
if (filename != null) {
|
if (filename != null) {
|
||||||
try {
|
try {
|
||||||
URL libUrl = new File(filename).toURL();
|
final URL libUrl = new File(filename).toURL();
|
||||||
addURL(libUrl);
|
addURL(libUrl);
|
||||||
return;
|
return;
|
||||||
} catch(java.net.MalformedURLException e) {
|
} catch(final java.net.MalformedURLException e) {
|
||||||
throw new UnknownError(
|
throw new UnknownError(
|
||||||
"Invalid file [" + filename + "] for logical lib [" + logicalLib + "]");
|
"Invalid file [" + filename + "] for logical lib [" + logicalLib + "]");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// now check the classpath for a similar-named lib
|
// now check the classpath for a similar-named lib
|
||||||
URL libUrl = libFromClasspath(logicalLib);
|
final URL libUrl = libFromClasspath(logicalLib);
|
||||||
if (libUrl != null) {
|
if (libUrl != null) {
|
||||||
addURL(libUrl);
|
addURL(libUrl);
|
||||||
return;
|
return;
|
||||||
@@ -250,18 +250,18 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
* if "foo-1.1.jar" and "foobar-1.1.jar" are in the path, then a logicalLib
|
* if "foo-1.1.jar" and "foobar-1.1.jar" are in the path, then a logicalLib
|
||||||
* name of "foo" will match the first entry above.
|
* name of "foo" will match the first entry above.
|
||||||
*/
|
*/
|
||||||
private URL libFromClasspath(String logicalLib) {
|
private URL libFromClasspath(final String logicalLib) {
|
||||||
ClassLoader cl = this.getClass().getClassLoader();
|
final ClassLoader cl = this.getClass().getClassLoader();
|
||||||
if (cl instanceof URLClassLoader == false) {
|
if (cl instanceof URLClassLoader == false) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
URLClassLoader ucl = (URLClassLoader) cl;
|
final URLClassLoader ucl = (URLClassLoader) cl;
|
||||||
URL[] path = ucl.getURLs();
|
final URL[] path = ucl.getURLs();
|
||||||
URL shortestMatch = null;
|
URL shortestMatch = null;
|
||||||
int shortestMatchLen = Integer.MAX_VALUE;
|
int shortestMatchLen = Integer.MAX_VALUE;
|
||||||
for(int i=0; i<path.length; ++i) {
|
for(int i=0; i<path.length; ++i) {
|
||||||
URL u = path[i];
|
final URL u = path[i];
|
||||||
|
|
||||||
// extract the filename bit on the end of the url
|
// extract the filename bit on the end of the url
|
||||||
String filename = u.toString();
|
String filename = u.toString();
|
||||||
@@ -270,7 +270,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
int lastSlash = filename.lastIndexOf('/');
|
final int lastSlash = filename.lastIndexOf('/');
|
||||||
if (lastSlash >= 0) {
|
if (lastSlash >= 0) {
|
||||||
filename = filename.substring(lastSlash+1);
|
filename = filename.substring(lastSlash+1);
|
||||||
}
|
}
|
||||||
@@ -294,7 +294,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
* prefix associated with that entry then attempt to load the class via
|
* prefix associated with that entry then attempt to load the class via
|
||||||
* that entries' classloader.
|
* that entries' classloader.
|
||||||
*/
|
*/
|
||||||
protected Class loadClass(String name, boolean resolve)
|
protected Class loadClass(final String name, final boolean resolve)
|
||||||
throws ClassNotFoundException {
|
throws ClassNotFoundException {
|
||||||
// just for performance, check java and javax
|
// just for performance, check java and javax
|
||||||
if (name.startsWith("java.") || name.startsWith("javax.")) {
|
if (name.startsWith("java.") || name.startsWith("javax.")) {
|
||||||
@@ -302,12 +302,12 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (lookasides != null) {
|
if (lookasides != null) {
|
||||||
for(Iterator i = lookasides.entrySet().iterator(); i.hasNext(); ) {
|
for(final Iterator i = lookasides.entrySet().iterator(); i.hasNext(); ) {
|
||||||
Map.Entry entry = (Map.Entry) i.next();
|
final Map.Entry entry = (Map.Entry) i.next();
|
||||||
String prefix = (String) entry.getKey();
|
final String prefix = (String) entry.getKey();
|
||||||
if (name.startsWith(prefix) == true) {
|
if (name.startsWith(prefix) == true) {
|
||||||
ClassLoader loader = (ClassLoader) entry.getValue();
|
final ClassLoader loader = (ClassLoader) entry.getValue();
|
||||||
Class clazz = Class.forName(name, resolve, loader);
|
final Class clazz = Class.forName(name, resolve, loader);
|
||||||
return clazz;
|
return clazz;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -332,7 +332,7 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
resolveClass(clazz);
|
resolveClass(clazz);
|
||||||
}
|
}
|
||||||
return clazz;
|
return clazz;
|
||||||
} catch(ClassNotFoundException e) {
|
} catch(final ClassNotFoundException e) {
|
||||||
return super.loadClass(name, resolve);
|
return super.loadClass(name, resolve);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -343,11 +343,11 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
* the resource is looked for in the local classpath before the parent
|
* the resource is looked for in the local classpath before the parent
|
||||||
* loader is consulted.
|
* loader is consulted.
|
||||||
*/
|
*/
|
||||||
public URL getResource(String name) {
|
public URL getResource(final String name) {
|
||||||
if (parentFirst) {
|
if (parentFirst) {
|
||||||
return super.getResource(name);
|
return super.getResource(name);
|
||||||
} else {
|
} else {
|
||||||
URL local = super.findResource(name);
|
final URL local = super.findResource(name);
|
||||||
if (local != null) {
|
if (local != null) {
|
||||||
return local;
|
return local;
|
||||||
}
|
}
|
||||||
@@ -363,13 +363,13 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
* it's declared final in java1.4 (thought that's been removed for 1.5).
|
* it's declared final in java1.4 (thought that's been removed for 1.5).
|
||||||
* The inherited implementation always behaves as if parentFirst=true.
|
* The inherited implementation always behaves as if parentFirst=true.
|
||||||
*/
|
*/
|
||||||
public Enumeration getResourcesInOrder(String name) throws IOException {
|
public Enumeration getResourcesInOrder(final String name) throws IOException {
|
||||||
if (parentFirst) {
|
if (parentFirst) {
|
||||||
return super.getResources(name);
|
return super.getResources(name);
|
||||||
} else {
|
} else {
|
||||||
Enumeration localUrls = super.findResources(name);
|
final Enumeration localUrls = super.findResources(name);
|
||||||
|
|
||||||
ClassLoader parent = getParent();
|
final ClassLoader parent = getParent();
|
||||||
if (parent == null) {
|
if (parent == null) {
|
||||||
// Alas, there is no method to get matching resources
|
// Alas, there is no method to get matching resources
|
||||||
// from a null (BOOT) parent classloader. Calling
|
// from a null (BOOT) parent classloader. Calling
|
||||||
@@ -383,10 +383,10 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
// path!
|
// path!
|
||||||
return localUrls;
|
return localUrls;
|
||||||
}
|
}
|
||||||
Enumeration parentUrls = parent.getResources(name);
|
final Enumeration parentUrls = parent.getResources(name);
|
||||||
|
|
||||||
ArrayList localItems = toList(localUrls);
|
final ArrayList localItems = toList(localUrls);
|
||||||
ArrayList parentItems = toList(parentUrls);
|
final ArrayList parentItems = toList(parentUrls);
|
||||||
localItems.addAll(parentItems);
|
localItems.addAll(parentItems);
|
||||||
return Collections.enumeration(localItems);
|
return Collections.enumeration(localItems);
|
||||||
}
|
}
|
||||||
@@ -400,11 +400,11 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
* @return <code>ArrayList</code> containing the enumerated
|
* @return <code>ArrayList</code> containing the enumerated
|
||||||
* elements in the enumerated order, not null
|
* elements in the enumerated order, not null
|
||||||
*/
|
*/
|
||||||
private ArrayList toList(Enumeration en) {
|
private ArrayList toList(final Enumeration en) {
|
||||||
ArrayList results = new ArrayList();
|
final ArrayList results = new ArrayList();
|
||||||
if (en != null) {
|
if (en != null) {
|
||||||
while (en.hasMoreElements()){
|
while (en.hasMoreElements()){
|
||||||
Object element = en.nextElement();
|
final Object element = en.nextElement();
|
||||||
results.add(element);
|
results.add(element);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -416,15 +416,15 @@ public class PathableClassLoader extends URLClassLoader {
|
|||||||
* the resource is looked for in the local classpath before the parent
|
* the resource is looked for in the local classpath before the parent
|
||||||
* loader is consulted.
|
* loader is consulted.
|
||||||
*/
|
*/
|
||||||
public InputStream getResourceAsStream(String name) {
|
public InputStream getResourceAsStream(final String name) {
|
||||||
if (parentFirst) {
|
if (parentFirst) {
|
||||||
return super.getResourceAsStream(name);
|
return super.getResourceAsStream(name);
|
||||||
} else {
|
} else {
|
||||||
URL local = super.findResource(name);
|
final URL local = super.findResource(name);
|
||||||
if (local != null) {
|
if (local != null) {
|
||||||
try {
|
try {
|
||||||
return local.openStream();
|
return local.openStream();
|
||||||
} catch(IOException e) {
|
} catch(final IOException e) {
|
||||||
// TODO: check if this is right or whether we should
|
// TODO: check if this is right or whether we should
|
||||||
// fall back to trying parent. The javadoc doesn't say...
|
// fall back to trying parent. The javadoc doesn't say...
|
||||||
return null;
|
return null;
|
||||||
|
|||||||
@@ -120,7 +120,7 @@ public class PathableTestSuite extends TestSuite {
|
|||||||
* calls to Thread.currentThread.getContextClassLoader from test methods
|
* calls to Thread.currentThread.getContextClassLoader from test methods
|
||||||
* (or any method called by test methods).
|
* (or any method called by test methods).
|
||||||
*/
|
*/
|
||||||
public PathableTestSuite(Class testClass, ClassLoader contextClassLoader) {
|
public PathableTestSuite(final Class testClass, final ClassLoader contextClassLoader) {
|
||||||
super(testClass);
|
super(testClass);
|
||||||
contextLoader = contextClassLoader;
|
contextLoader = contextClassLoader;
|
||||||
}
|
}
|
||||||
@@ -133,9 +133,9 @@ public class PathableTestSuite extends TestSuite {
|
|||||||
* The context classloader and system properties are saved before each
|
* The context classloader and system properties are saved before each
|
||||||
* test, and restored after the test completes to better isolate tests.
|
* test, and restored after the test completes to better isolate tests.
|
||||||
*/
|
*/
|
||||||
public void runTest(Test test, TestResult result) {
|
public void runTest(final Test test, final TestResult result) {
|
||||||
ClassLoader origContext = Thread.currentThread().getContextClassLoader();
|
final ClassLoader origContext = Thread.currentThread().getContextClassLoader();
|
||||||
Properties oldSysProps = (Properties) System.getProperties().clone();
|
final Properties oldSysProps = (Properties) System.getProperties().clone();
|
||||||
try {
|
try {
|
||||||
Thread.currentThread().setContextClassLoader(contextLoader);
|
Thread.currentThread().setContextClassLoader(contextLoader);
|
||||||
test.run(result);
|
test.run(result);
|
||||||
|
|||||||
@@ -29,13 +29,13 @@ public class UserClass {
|
|||||||
* when an instance of this class is actually created <i>before</i> calling
|
* when an instance of this class is actually created <i>before</i> calling
|
||||||
* this method!
|
* this method!
|
||||||
*/
|
*/
|
||||||
public static void setAllowFlawedContext(String state) {
|
public static void setAllowFlawedContext(final String state) {
|
||||||
LogFactory f = LogFactory.getFactory();
|
final LogFactory f = LogFactory.getFactory();
|
||||||
f.setAttribute(LogFactoryImpl.ALLOW_FLAWED_CONTEXT_PROPERTY, state);
|
f.setAttribute(LogFactoryImpl.ALLOW_FLAWED_CONTEXT_PROPERTY, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
public UserClass() {
|
public UserClass() {
|
||||||
Log log = LogFactory.getLog(LoadTestCase.class);
|
final Log log = LogFactory.getLog(LoadTestCase.class);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -31,14 +31,14 @@ import junit.framework.TestSuite;
|
|||||||
public class AvalonLoggerTestCase extends AbstractLogTest {
|
public class AvalonLoggerTestCase extends AbstractLogTest {
|
||||||
|
|
||||||
public static Test suite() {
|
public static Test suite() {
|
||||||
TestSuite suite = new TestSuite();
|
final TestSuite suite = new TestSuite();
|
||||||
suite.addTestSuite(AvalonLoggerTestCase.class);
|
suite.addTestSuite(AvalonLoggerTestCase.class);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Log getLogObject() {
|
public Log getLogObject() {
|
||||||
// Output does not seem to be used, so don't display it.
|
// Output does not seem to be used, so don't display it.
|
||||||
Log log = new AvalonLogger(new NullLogger());
|
final Log log = new AvalonLogger(new NullLogger());
|
||||||
return log;
|
return log;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,39 +48,39 @@ public class FirstPriorityConfigTestCase extends TestCase {
|
|||||||
* Return the tests included in this test suite.
|
* Return the tests included in this test suite.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
Class thisClass = FirstPriorityConfigTestCase.class;
|
final Class thisClass = FirstPriorityConfigTestCase.class;
|
||||||
|
|
||||||
// Determine the URL to this .class file, so that we can then
|
// Determine the URL to this .class file, so that we can then
|
||||||
// append the priority dirs to it. For tidiness, load this
|
// append the priority dirs to it. For tidiness, load this
|
||||||
// class through a dummy loader though this is not absolutely
|
// class through a dummy loader though this is not absolutely
|
||||||
// necessary...
|
// necessary...
|
||||||
PathableClassLoader dummy = new PathableClassLoader(null);
|
final PathableClassLoader dummy = new PathableClassLoader(null);
|
||||||
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
dummy.addLogicalLib("testclasses");
|
dummy.addLogicalLib("testclasses");
|
||||||
dummy.addLogicalLib("commons-logging");
|
dummy.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||||
URL baseUrl = dummy.findResource(thisClassPath);
|
final URL baseUrl = dummy.findResource(thisClassPath);
|
||||||
|
|
||||||
// Now set up the desired classloader hierarchy. We'll put JCL
|
// Now set up the desired classloader hierarchy. We'll put JCL
|
||||||
// in the container path, the testcase in a webapp path, and
|
// in the container path, the testcase in a webapp path, and
|
||||||
// both config files into the webapp path too.
|
// both config files into the webapp path too.
|
||||||
PathableClassLoader containerLoader = new PathableClassLoader(null);
|
final PathableClassLoader containerLoader = new PathableClassLoader(null);
|
||||||
containerLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
containerLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
containerLoader.addLogicalLib("commons-logging");
|
containerLoader.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
PathableClassLoader webappLoader = new PathableClassLoader(containerLoader);
|
final PathableClassLoader webappLoader = new PathableClassLoader(containerLoader);
|
||||||
webappLoader.addLogicalLib("testclasses");
|
webappLoader.addLogicalLib("testclasses");
|
||||||
|
|
||||||
URL pri20URL = new URL(baseUrl, "priority20/");
|
final URL pri20URL = new URL(baseUrl, "priority20/");
|
||||||
webappLoader.addURL(pri20URL);
|
webappLoader.addURL(pri20URL);
|
||||||
|
|
||||||
URL pri10URL = new URL(baseUrl, "priority10/");
|
final URL pri10URL = new URL(baseUrl, "priority10/");
|
||||||
webappLoader.addURL(pri10URL);
|
webappLoader.addURL(pri10URL);
|
||||||
|
|
||||||
// load the test class via webapp loader, and use the webapp loader
|
// load the test class via webapp loader, and use the webapp loader
|
||||||
// as the tccl loader too.
|
// as the tccl loader too.
|
||||||
Class testClass = webappLoader.loadClass(thisClass.getName());
|
final Class testClass = webappLoader.loadClass(thisClass.getName());
|
||||||
return new PathableTestSuite(testClass, webappLoader);
|
return new PathableTestSuite(testClass, webappLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,11 +105,11 @@ public class FirstPriorityConfigTestCase extends TestCase {
|
|||||||
* the desired configId value.
|
* the desired configId value.
|
||||||
*/
|
*/
|
||||||
public void testPriority() throws Exception {
|
public void testPriority() throws Exception {
|
||||||
LogFactory instance = LogFactory.getFactory();
|
final LogFactory instance = LogFactory.getFactory();
|
||||||
|
|
||||||
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
final ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||||
ClassLoader lfClassLoader = instance.getClass().getClassLoader();
|
final ClassLoader lfClassLoader = instance.getClass().getClassLoader();
|
||||||
ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
|
final ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
// context classloader should be thisClassLoader
|
// context classloader should be thisClassLoader
|
||||||
assertEquals(thisClassLoader, contextClassLoader);
|
assertEquals(thisClassLoader, contextClassLoader);
|
||||||
@@ -119,7 +119,7 @@ public class FirstPriorityConfigTestCase extends TestCase {
|
|||||||
assertEquals(PathableClassLoader.class.getName(),
|
assertEquals(PathableClassLoader.class.getName(),
|
||||||
lfClassLoader.getClass().getName());
|
lfClassLoader.getClass().getName());
|
||||||
|
|
||||||
String id = (String) instance.getAttribute("configId");
|
final String id = (String) instance.getAttribute("configId");
|
||||||
assertEquals("Correct config file loaded", "priority20", id );
|
assertEquals("Correct config file loaded", "priority20", id );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -55,19 +55,19 @@ public class PriorityConfigTestCase extends TestCase {
|
|||||||
* Return the tests included in this test suite.
|
* Return the tests included in this test suite.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
Class thisClass = PriorityConfigTestCase.class;
|
final Class thisClass = PriorityConfigTestCase.class;
|
||||||
|
|
||||||
// Determine the URL to this .class file, so that we can then
|
// Determine the URL to this .class file, so that we can then
|
||||||
// append the priority dirs to it. For tidiness, load this
|
// append the priority dirs to it. For tidiness, load this
|
||||||
// class through a dummy loader though this is not absolutely
|
// class through a dummy loader though this is not absolutely
|
||||||
// necessary...
|
// necessary...
|
||||||
PathableClassLoader dummy = new PathableClassLoader(null);
|
final PathableClassLoader dummy = new PathableClassLoader(null);
|
||||||
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
dummy.addLogicalLib("testclasses");
|
dummy.addLogicalLib("testclasses");
|
||||||
dummy.addLogicalLib("commons-logging");
|
dummy.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||||
URL baseUrl = dummy.findResource(thisClassPath);
|
final URL baseUrl = dummy.findResource(thisClassPath);
|
||||||
|
|
||||||
// Now set up the desired classloader hierarchy. We'll put a config
|
// Now set up the desired classloader hierarchy. We'll put a config
|
||||||
// file of priority=10 in the container path, and ones of both
|
// file of priority=10 in the container path, and ones of both
|
||||||
@@ -76,29 +76,29 @@ public class PriorityConfigTestCase extends TestCase {
|
|||||||
// A second properties file with priority=20 is also added,
|
// A second properties file with priority=20 is also added,
|
||||||
// so we can check that the first one in the classpath is
|
// so we can check that the first one in the classpath is
|
||||||
// used.
|
// used.
|
||||||
PathableClassLoader containerLoader = new PathableClassLoader(null);
|
final PathableClassLoader containerLoader = new PathableClassLoader(null);
|
||||||
containerLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
containerLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
containerLoader.addLogicalLib("commons-logging");
|
containerLoader.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
URL pri10URL = new URL(baseUrl, "priority10/");
|
final URL pri10URL = new URL(baseUrl, "priority10/");
|
||||||
containerLoader.addURL(pri10URL);
|
containerLoader.addURL(pri10URL);
|
||||||
|
|
||||||
PathableClassLoader webappLoader = new PathableClassLoader(containerLoader);
|
final PathableClassLoader webappLoader = new PathableClassLoader(containerLoader);
|
||||||
webappLoader.setParentFirst(true);
|
webappLoader.setParentFirst(true);
|
||||||
webappLoader.addLogicalLib("testclasses");
|
webappLoader.addLogicalLib("testclasses");
|
||||||
|
|
||||||
URL noPriorityURL = new URL(baseUrl, "nopriority/");
|
final URL noPriorityURL = new URL(baseUrl, "nopriority/");
|
||||||
webappLoader.addURL(noPriorityURL);
|
webappLoader.addURL(noPriorityURL);
|
||||||
|
|
||||||
URL pri20URL = new URL(baseUrl, "priority20/");
|
final URL pri20URL = new URL(baseUrl, "priority20/");
|
||||||
webappLoader.addURL(pri20URL);
|
webappLoader.addURL(pri20URL);
|
||||||
|
|
||||||
URL pri20aURL = new URL(baseUrl, "priority20a/");
|
final URL pri20aURL = new URL(baseUrl, "priority20a/");
|
||||||
webappLoader.addURL(pri20aURL);
|
webappLoader.addURL(pri20aURL);
|
||||||
|
|
||||||
// load the test class via webapp loader, and use the webapp loader
|
// load the test class via webapp loader, and use the webapp loader
|
||||||
// as the tccl loader too.
|
// as the tccl loader too.
|
||||||
Class testClass = webappLoader.loadClass(thisClass.getName());
|
final Class testClass = webappLoader.loadClass(thisClass.getName());
|
||||||
return new PathableTestSuite(testClass, webappLoader);
|
return new PathableTestSuite(testClass, webappLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -123,8 +123,8 @@ public class PriorityConfigTestCase extends TestCase {
|
|||||||
* the desired configId value.
|
* the desired configId value.
|
||||||
*/
|
*/
|
||||||
public void testPriority() throws Exception {
|
public void testPriority() throws Exception {
|
||||||
LogFactory instance = LogFactory.getFactory();
|
final LogFactory instance = LogFactory.getFactory();
|
||||||
String id = (String) instance.getAttribute("configId");
|
final String id = (String) instance.getAttribute("configId");
|
||||||
assertEquals("Correct config file loaded", "priority20", id );
|
assertEquals("Correct config file loaded", "priority20", id );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -50,7 +50,7 @@ public class WeakHashtableTestCase extends TestCase {
|
|||||||
private Long valueTwo;
|
private Long valueTwo;
|
||||||
private Long valueThree;
|
private Long valueThree;
|
||||||
|
|
||||||
public WeakHashtableTestCase(String testName) {
|
public WeakHashtableTestCase(final String testName) {
|
||||||
super(testName);
|
super(testName);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,8 +105,8 @@ public class WeakHashtableTestCase extends TestCase {
|
|||||||
|
|
||||||
/** Tests public Enumeration elements() */
|
/** Tests public Enumeration elements() */
|
||||||
public void testElements() throws Exception {
|
public void testElements() throws Exception {
|
||||||
ArrayList elements = new ArrayList();
|
final ArrayList elements = new ArrayList();
|
||||||
for (Enumeration e = weakHashtable.elements(); e.hasMoreElements();) {
|
for (final Enumeration e = weakHashtable.elements(); e.hasMoreElements();) {
|
||||||
elements.add(e.nextElement());
|
elements.add(e.nextElement());
|
||||||
}
|
}
|
||||||
assertEquals(3, elements.size());
|
assertEquals(3, elements.size());
|
||||||
@@ -117,10 +117,10 @@ public class WeakHashtableTestCase extends TestCase {
|
|||||||
|
|
||||||
/** Tests public Set entrySet() */
|
/** Tests public Set entrySet() */
|
||||||
public void testEntrySet() throws Exception {
|
public void testEntrySet() throws Exception {
|
||||||
Set entrySet = weakHashtable.entrySet();
|
final Set entrySet = weakHashtable.entrySet();
|
||||||
for (Iterator it = entrySet.iterator(); it.hasNext();) {
|
for (final Iterator it = entrySet.iterator(); it.hasNext();) {
|
||||||
Map.Entry entry = (Map.Entry) it.next();
|
final Map.Entry entry = (Map.Entry) it.next();
|
||||||
Object key = entry.getKey();
|
final Object key = entry.getKey();
|
||||||
if (keyOne.equals(key)) {
|
if (keyOne.equals(key)) {
|
||||||
assertEquals(valueOne, entry.getValue());
|
assertEquals(valueOne, entry.getValue());
|
||||||
} else if (keyTwo.equals(key)) {
|
} else if (keyTwo.equals(key)) {
|
||||||
@@ -143,8 +143,8 @@ public class WeakHashtableTestCase extends TestCase {
|
|||||||
|
|
||||||
/** Tests public Enumeration keys() */
|
/** Tests public Enumeration keys() */
|
||||||
public void testKeys() throws Exception {
|
public void testKeys() throws Exception {
|
||||||
ArrayList keys = new ArrayList();
|
final ArrayList keys = new ArrayList();
|
||||||
for (Enumeration e = weakHashtable.keys(); e.hasMoreElements();) {
|
for (final Enumeration e = weakHashtable.keys(); e.hasMoreElements();) {
|
||||||
keys.add(e.nextElement());
|
keys.add(e.nextElement());
|
||||||
}
|
}
|
||||||
assertEquals(3, keys.size());
|
assertEquals(3, keys.size());
|
||||||
@@ -155,7 +155,7 @@ public class WeakHashtableTestCase extends TestCase {
|
|||||||
|
|
||||||
/** Tests public Set keySet() */
|
/** Tests public Set keySet() */
|
||||||
public void testKeySet() throws Exception {
|
public void testKeySet() throws Exception {
|
||||||
Set keySet = weakHashtable.keySet();
|
final Set keySet = weakHashtable.keySet();
|
||||||
assertEquals(3, keySet.size());
|
assertEquals(3, keySet.size());
|
||||||
assertTrue(keySet.contains(keyOne));
|
assertTrue(keySet.contains(keyOne));
|
||||||
assertTrue(keySet.contains(keyTwo));
|
assertTrue(keySet.contains(keyTwo));
|
||||||
@@ -164,7 +164,7 @@ public class WeakHashtableTestCase extends TestCase {
|
|||||||
|
|
||||||
/** Tests public Object put(Object key, Object value) */
|
/** Tests public Object put(Object key, Object value) */
|
||||||
public void testPut() throws Exception {
|
public void testPut() throws Exception {
|
||||||
Long anotherKey = new Long(2004);
|
final Long anotherKey = new Long(2004);
|
||||||
weakHashtable.put(anotherKey, new Long(1066));
|
weakHashtable.put(anotherKey, new Long(1066));
|
||||||
|
|
||||||
assertEquals(new Long(1066), weakHashtable.get(anotherKey));
|
assertEquals(new Long(1066), weakHashtable.get(anotherKey));
|
||||||
@@ -174,7 +174,7 @@ public class WeakHashtableTestCase extends TestCase {
|
|||||||
try {
|
try {
|
||||||
weakHashtable.put(null, new Object());
|
weakHashtable.put(null, new Object());
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (final Exception e) {
|
||||||
caught = e;
|
caught = e;
|
||||||
}
|
}
|
||||||
assertNotNull("did not throw an exception adding a null key", caught);
|
assertNotNull("did not throw an exception adding a null key", caught);
|
||||||
@@ -182,7 +182,7 @@ public class WeakHashtableTestCase extends TestCase {
|
|||||||
try {
|
try {
|
||||||
weakHashtable.put(new Object(), null);
|
weakHashtable.put(new Object(), null);
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (final Exception e) {
|
||||||
caught = e;
|
caught = e;
|
||||||
}
|
}
|
||||||
assertNotNull("did not throw an exception adding a null value", caught);
|
assertNotNull("did not throw an exception adding a null value", caught);
|
||||||
@@ -190,12 +190,12 @@ public class WeakHashtableTestCase extends TestCase {
|
|||||||
|
|
||||||
/** Tests public void putAll(Map t) */
|
/** Tests public void putAll(Map t) */
|
||||||
public void testPutAll() throws Exception {
|
public void testPutAll() throws Exception {
|
||||||
Map newValues = new HashMap();
|
final Map newValues = new HashMap();
|
||||||
Long newKey = new Long(1066);
|
final Long newKey = new Long(1066);
|
||||||
Long newValue = new Long(1415);
|
final Long newValue = new Long(1415);
|
||||||
newValues.put(newKey, newValue);
|
newValues.put(newKey, newValue);
|
||||||
Long anotherNewKey = new Long(1645);
|
final Long anotherNewKey = new Long(1645);
|
||||||
Long anotherNewValue = new Long(1815);
|
final Long anotherNewValue = new Long(1815);
|
||||||
newValues.put(anotherNewKey, anotherNewValue);
|
newValues.put(anotherNewKey, anotherNewValue);
|
||||||
weakHashtable.putAll(newValues);
|
weakHashtable.putAll(newValues);
|
||||||
|
|
||||||
@@ -213,7 +213,7 @@ public class WeakHashtableTestCase extends TestCase {
|
|||||||
|
|
||||||
/** Tests public Collection values() */
|
/** Tests public Collection values() */
|
||||||
public void testValues() throws Exception {
|
public void testValues() throws Exception {
|
||||||
Collection values = weakHashtable.values();
|
final Collection values = weakHashtable.values();
|
||||||
assertEquals(3, values.size());
|
assertEquals(3, values.size());
|
||||||
assertTrue(values.contains(valueOne));
|
assertTrue(values.contains(valueOne));
|
||||||
assertTrue(values.contains(valueTwo));
|
assertTrue(values.contains(valueTwo));
|
||||||
@@ -229,8 +229,8 @@ public class WeakHashtableTestCase extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void xxxIgnoretestRelease() throws Exception {
|
public void xxxIgnoretestRelease() throws Exception {
|
||||||
assertNotNull(weakHashtable.get(new Long(1)));
|
assertNotNull(weakHashtable.get(new Long(1)));
|
||||||
ReferenceQueue testQueue = new ReferenceQueue();
|
final ReferenceQueue testQueue = new ReferenceQueue();
|
||||||
WeakReference weakKeyOne = new WeakReference(keyOne, testQueue);
|
final WeakReference weakKeyOne = new WeakReference(keyOne, testQueue);
|
||||||
|
|
||||||
// lose our references
|
// lose our references
|
||||||
keyOne = null;
|
keyOne = null;
|
||||||
@@ -253,7 +253,7 @@ public class WeakHashtableTestCase extends TestCase {
|
|||||||
|
|
||||||
} else {
|
} else {
|
||||||
// create garbage:
|
// create garbage:
|
||||||
byte[] b = new byte[bytz];
|
final byte[] b = new byte[bytz];
|
||||||
bytz = bytz * 2;
|
bytz = bytz * 2;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -270,7 +270,7 @@ public class WeakHashtableTestCase extends TestCase {
|
|||||||
|
|
||||||
public static class StupidThread extends Thread {
|
public static class StupidThread extends Thread {
|
||||||
|
|
||||||
public StupidThread(String name) {
|
public StupidThread(final String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,7 +285,7 @@ public class WeakHashtableTestCase extends TestCase {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void testLOGGING_119() throws Exception {
|
public void testLOGGING_119() throws Exception {
|
||||||
Thread [] t = new Thread[THREAD_COUNT];
|
final Thread [] t = new Thread[THREAD_COUNT];
|
||||||
for (int j=1; j <= OUTER_LOOP; j++) {
|
for (int j=1; j <= OUTER_LOOP; j++) {
|
||||||
hashtable = new WeakHashtable();
|
hashtable = new WeakHashtable();
|
||||||
for (int i = 0; i < t.length; i++) {
|
for (int i = 0; i < t.length; i++) {
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ import org.apache.commons.logging.PathableTestSuite;
|
|||||||
|
|
||||||
public class CustomConfigAPITestCase extends CustomConfigTestCase {
|
public class CustomConfigAPITestCase extends CustomConfigTestCase {
|
||||||
|
|
||||||
public CustomConfigAPITestCase(String name) {
|
public CustomConfigAPITestCase(final String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -38,7 +38,7 @@ public class CustomConfigAPITestCase extends CustomConfigTestCase {
|
|||||||
* Return the tests included in this test suite.
|
* Return the tests included in this test suite.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
PathableClassLoader parent = new PathableClassLoader(null);
|
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
|
|
||||||
// the TestHandler class must be accessable from the System classloader
|
// the TestHandler class must be accessable from the System classloader
|
||||||
@@ -46,16 +46,16 @@ public class CustomConfigAPITestCase extends CustomConfigTestCase {
|
|||||||
// be able to instantiate it. And this test case must see the same
|
// be able to instantiate it. And this test case must see the same
|
||||||
// class in order to be able to access its data. Yes this is ugly
|
// class in order to be able to access its data. Yes this is ugly
|
||||||
// but the whole jdk14 API is a ******* mess anyway.
|
// but the whole jdk14 API is a ******* mess anyway.
|
||||||
ClassLoader scl = ClassLoader.getSystemClassLoader();
|
final ClassLoader scl = ClassLoader.getSystemClassLoader();
|
||||||
loadTestHandler(HANDLER_NAME, scl);
|
loadTestHandler(HANDLER_NAME, scl);
|
||||||
parent.useExplicitLoader(HANDLER_NAME, scl);
|
parent.useExplicitLoader(HANDLER_NAME, scl);
|
||||||
parent.addLogicalLib("commons-logging-api");
|
parent.addLogicalLib("commons-logging-api");
|
||||||
|
|
||||||
PathableClassLoader child = new PathableClassLoader(parent);
|
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||||
child.addLogicalLib("testclasses");
|
child.addLogicalLib("testclasses");
|
||||||
child.addLogicalLib("commons-logging");
|
child.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
Class testClass = child.loadClass(CustomConfigAPITestCase.class.getName());
|
final Class testClass = child.loadClass(CustomConfigAPITestCase.class.getName());
|
||||||
return new PathableTestSuite(testClass, child);
|
return new PathableTestSuite(testClass, child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ import org.apache.commons.logging.PathableClassLoader;
|
|||||||
public class CustomConfigFullTestCase extends CustomConfigTestCase {
|
public class CustomConfigFullTestCase extends CustomConfigTestCase {
|
||||||
|
|
||||||
|
|
||||||
public CustomConfigFullTestCase(String name) {
|
public CustomConfigFullTestCase(final String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -41,7 +41,7 @@ public class CustomConfigFullTestCase extends CustomConfigTestCase {
|
|||||||
* Return the tests included in this test suite.
|
* Return the tests included in this test suite.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
PathableClassLoader parent = new PathableClassLoader(null);
|
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
|
|
||||||
// the TestHandler class must be accessable from the System classloader
|
// the TestHandler class must be accessable from the System classloader
|
||||||
@@ -49,15 +49,15 @@ public class CustomConfigFullTestCase extends CustomConfigTestCase {
|
|||||||
// be able to instantiate it. And this test case must see the same
|
// be able to instantiate it. And this test case must see the same
|
||||||
// class in order to be able to access its data. Yes this is ugly
|
// class in order to be able to access its data. Yes this is ugly
|
||||||
// but the whole jdk14 API is a ******* mess anyway.
|
// but the whole jdk14 API is a ******* mess anyway.
|
||||||
ClassLoader scl = ClassLoader.getSystemClassLoader();
|
final ClassLoader scl = ClassLoader.getSystemClassLoader();
|
||||||
loadTestHandler(HANDLER_NAME, scl);
|
loadTestHandler(HANDLER_NAME, scl);
|
||||||
parent.useExplicitLoader(HANDLER_NAME, scl);
|
parent.useExplicitLoader(HANDLER_NAME, scl);
|
||||||
parent.addLogicalLib("commons-logging");
|
parent.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
PathableClassLoader child = new PathableClassLoader(parent);
|
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||||
child.addLogicalLib("testclasses");
|
child.addLogicalLib("testclasses");
|
||||||
|
|
||||||
Class testClass = child.loadClass(CustomConfigFullTestCase.class.getName());
|
final Class testClass = child.loadClass(CustomConfigFullTestCase.class.getName());
|
||||||
return new PathableTestSuite(testClass, child);
|
return new PathableTestSuite(testClass, child);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -56,7 +56,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
|||||||
*
|
*
|
||||||
* @param name Name of the test case
|
* @param name Name of the test case
|
||||||
*/
|
*/
|
||||||
public CustomConfigTestCase(String name) {
|
public CustomConfigTestCase(final String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,15 +109,15 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
|||||||
* Given the name of a class that is somewhere in the classpath of the provided
|
* Given the name of a class that is somewhere in the classpath of the provided
|
||||||
* classloader, return the contents of the corresponding .class file.
|
* classloader, return the contents of the corresponding .class file.
|
||||||
*/
|
*/
|
||||||
protected static byte[] readClass(String name, ClassLoader srcCL) throws Exception {
|
protected static byte[] readClass(final String name, final ClassLoader srcCL) throws Exception {
|
||||||
String resName = name.replace('.', '/') + ".class";
|
final String resName = name.replace('.', '/') + ".class";
|
||||||
System.err.println("Trying to load resource [" + resName + "]");
|
System.err.println("Trying to load resource [" + resName + "]");
|
||||||
InputStream is = srcCL.getResourceAsStream(resName);
|
final InputStream is = srcCL.getResourceAsStream(resName);
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
System.err.println("Reading resource [" + resName + "]");
|
System.err.println("Reading resource [" + resName + "]");
|
||||||
byte[] buf = new byte[1000];
|
final byte[] buf = new byte[1000];
|
||||||
for(;;) {
|
for(;;) {
|
||||||
int read = is.read(buf);
|
final int read = is.read(buf);
|
||||||
if (read <= 0) {
|
if (read <= 0) {
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
@@ -133,30 +133,30 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
|||||||
* works for classes for which all dependencies are already loaded in
|
* works for classes for which all dependencies are already loaded in
|
||||||
* that classloader.
|
* that classloader.
|
||||||
*/
|
*/
|
||||||
protected static void loadTestHandler(String className, ClassLoader targetCL) {
|
protected static void loadTestHandler(final String className, final ClassLoader targetCL) {
|
||||||
try {
|
try {
|
||||||
targetCL.loadClass(className);
|
targetCL.loadClass(className);
|
||||||
// fail("Class already in target classloader");
|
// fail("Class already in target classloader");
|
||||||
return;
|
return;
|
||||||
} catch(ClassNotFoundException ex) {
|
} catch(final ClassNotFoundException ex) {
|
||||||
// ok, go ahead and load it
|
// ok, go ahead and load it
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ClassLoader srcCL = CustomConfigAPITestCase.class.getClassLoader();
|
final ClassLoader srcCL = CustomConfigAPITestCase.class.getClassLoader();
|
||||||
byte[] classData = readClass(className, srcCL);
|
final byte[] classData = readClass(className, srcCL);
|
||||||
|
|
||||||
Class[] params = new Class[] { String.class, classData.getClass(), Integer.TYPE, Integer.TYPE };
|
final Class[] params = new Class[] { String.class, classData.getClass(), Integer.TYPE, Integer.TYPE };
|
||||||
Method m = ClassLoader.class.getDeclaredMethod("defineClass", params);
|
final Method m = ClassLoader.class.getDeclaredMethod("defineClass", params);
|
||||||
|
|
||||||
Object[] args = new Object[4];
|
final Object[] args = new Object[4];
|
||||||
args[0] = className;
|
args[0] = className;
|
||||||
args[1] = classData;
|
args[1] = classData;
|
||||||
args[2] = new Integer(0);
|
args[2] = new Integer(0);
|
||||||
args[3] = new Integer(classData.length);
|
args[3] = new Integer(classData.length);
|
||||||
m.setAccessible(true);
|
m.setAccessible(true);
|
||||||
m.invoke(targetCL, args);
|
m.invoke(targetCL, args);
|
||||||
} catch(Exception e) {
|
} catch(final Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
fail("Unable to load class " + className);
|
fail("Unable to load class " + className);
|
||||||
}
|
}
|
||||||
@@ -179,7 +179,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
|||||||
* Return the tests included in this test suite.
|
* Return the tests included in this test suite.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
PathableClassLoader cl = new PathableClassLoader(null);
|
final PathableClassLoader cl = new PathableClassLoader(null);
|
||||||
cl.useExplicitLoader("junit.", Test.class.getClassLoader());
|
cl.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
|
|
||||||
// the TestHandler class must be accessable from the System classloader
|
// the TestHandler class must be accessable from the System classloader
|
||||||
@@ -187,13 +187,13 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
|||||||
// be able to instantiate it. And this test case must see the same
|
// be able to instantiate it. And this test case must see the same
|
||||||
// class in order to be able to access its data. Yes this is ugly
|
// class in order to be able to access its data. Yes this is ugly
|
||||||
// but the whole jdk14 API is a ******* mess anyway.
|
// but the whole jdk14 API is a ******* mess anyway.
|
||||||
ClassLoader scl = ClassLoader.getSystemClassLoader();
|
final ClassLoader scl = ClassLoader.getSystemClassLoader();
|
||||||
loadTestHandler(HANDLER_NAME, scl);
|
loadTestHandler(HANDLER_NAME, scl);
|
||||||
cl.useExplicitLoader(HANDLER_NAME, scl);
|
cl.useExplicitLoader(HANDLER_NAME, scl);
|
||||||
cl.addLogicalLib("commons-logging");
|
cl.addLogicalLib("commons-logging");
|
||||||
cl.addLogicalLib("testclasses");
|
cl.addLogicalLib("testclasses");
|
||||||
|
|
||||||
Class testClass = cl.loadClass(CustomConfigTestCase.class.getName());
|
final Class testClass = cl.loadClass(CustomConfigTestCase.class.getName());
|
||||||
return new PathableTestSuite(testClass, cl);
|
return new PathableTestSuite(testClass, cl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -290,11 +290,11 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
|||||||
|
|
||||||
|
|
||||||
// Check the recorded messages
|
// Check the recorded messages
|
||||||
protected void checkLogRecords(boolean thrown) {
|
protected void checkLogRecords(final boolean thrown) {
|
||||||
Iterator records = handler.records();
|
final Iterator records = handler.records();
|
||||||
for (int i = 0; i < testMessages.length; i++) {
|
for (int i = 0; i < testMessages.length; i++) {
|
||||||
assertTrue(records.hasNext());
|
assertTrue(records.hasNext());
|
||||||
LogRecord record = (LogRecord) records.next();
|
final LogRecord record = (LogRecord) records.next();
|
||||||
assertEquals("LogRecord level",
|
assertEquals("LogRecord level",
|
||||||
testLevels[i], record.getLevel());
|
testLevels[i], record.getLevel());
|
||||||
assertEquals("LogRecord message",
|
assertEquals("LogRecord message",
|
||||||
@@ -327,7 +327,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
|||||||
|
|
||||||
// Log the messages with exceptions
|
// Log the messages with exceptions
|
||||||
protected void logExceptionMessages() {
|
protected void logExceptionMessages() {
|
||||||
Throwable t = new DummyException();
|
final Throwable t = new DummyException();
|
||||||
log.trace("trace", t); // Should not actually get logged
|
log.trace("trace", t); // Should not actually get logged
|
||||||
log.debug("debug", t);
|
log.debug("debug", t);
|
||||||
log.info("info", t);
|
log.info("info", t);
|
||||||
@@ -377,15 +377,15 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
|||||||
|
|
||||||
|
|
||||||
// Set up logger instance
|
// Set up logger instance
|
||||||
protected void setUpLogger(String name) throws Exception {
|
protected void setUpLogger(final String name) throws Exception {
|
||||||
logger = Logger.getLogger(name);
|
logger = Logger.getLogger(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// Set up LogManager instance
|
// Set up LogManager instance
|
||||||
protected void setUpManager(String config) throws Exception {
|
protected void setUpManager(final String config) throws Exception {
|
||||||
manager = LogManager.getLogManager();
|
manager = LogManager.getLogManager();
|
||||||
InputStream is =
|
final InputStream is =
|
||||||
this.getClass().getClassLoader().getResourceAsStream(config);
|
this.getClass().getClassLoader().getResourceAsStream(config);
|
||||||
manager.readConfiguration(is);
|
manager.readConfiguration(is);
|
||||||
is.close();
|
is.close();
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ public class DefaultConfigTestCase extends TestCase {
|
|||||||
*
|
*
|
||||||
* @param name Name of the test case
|
* @param name Name of the test case
|
||||||
*/
|
*/
|
||||||
public DefaultConfigTestCase(String name) {
|
public DefaultConfigTestCase(final String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -88,12 +88,12 @@ public class DefaultConfigTestCase extends TestCase {
|
|||||||
* Return the tests included in this test suite.
|
* Return the tests included in this test suite.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
PathableClassLoader loader = new PathableClassLoader(null);
|
final PathableClassLoader loader = new PathableClassLoader(null);
|
||||||
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
loader.addLogicalLib("testclasses");
|
loader.addLogicalLib("testclasses");
|
||||||
loader.addLogicalLib("commons-logging");
|
loader.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
Class testClass = loader.loadClass(DefaultConfigTestCase.class.getName());
|
final Class testClass = loader.loadClass(DefaultConfigTestCase.class.getName());
|
||||||
return new PathableTestSuite(testClass, loader);
|
return new PathableTestSuite(testClass, loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -126,7 +126,7 @@ public class DefaultConfigTestCase extends TestCase {
|
|||||||
"org.apache.commons.logging.impl.LogFactoryImpl",
|
"org.apache.commons.logging.impl.LogFactoryImpl",
|
||||||
factory.getClass().getName());
|
factory.getClass().getName());
|
||||||
|
|
||||||
String names[] = factory.getAttributeNames();
|
final String names[] = factory.getAttributeNames();
|
||||||
assertNotNull("Names exists", names);
|
assertNotNull("Names exists", names);
|
||||||
assertEquals("Names empty", 0, names.length);
|
assertEquals("Names empty", 0, names.length);
|
||||||
|
|
||||||
@@ -137,13 +137,13 @@ public class DefaultConfigTestCase extends TestCase {
|
|||||||
public void testSerializable() throws Exception {
|
public void testSerializable() throws Exception {
|
||||||
|
|
||||||
// Serialize and deserialize the instance
|
// Serialize and deserialize the instance
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
final ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||||
oos.writeObject(log);
|
oos.writeObject(log);
|
||||||
oos.close();
|
oos.close();
|
||||||
ByteArrayInputStream bais =
|
final ByteArrayInputStream bais =
|
||||||
new ByteArrayInputStream(baos.toByteArray());
|
new ByteArrayInputStream(baos.toByteArray());
|
||||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
final ObjectInputStream ois = new ObjectInputStream(bais);
|
||||||
log = (Log) ois.readObject();
|
log = (Log) ois.readObject();
|
||||||
ois.close();
|
ois.close();
|
||||||
|
|
||||||
@@ -183,7 +183,7 @@ public class DefaultConfigTestCase extends TestCase {
|
|||||||
|
|
||||||
|
|
||||||
// Set up log instance
|
// Set up log instance
|
||||||
protected void setUpLog(String name) throws Exception {
|
protected void setUpLog(final String name) throws Exception {
|
||||||
log = LogFactory.getLog(name);
|
log = LogFactory.getLog(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ public class TestHandler extends Handler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
public void publish(LogRecord record) {
|
public void publish(final LogRecord record) {
|
||||||
records.add(record);
|
records.add(record);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -88,13 +88,13 @@ public abstract class StandardTests extends TestCase {
|
|||||||
* Test that a LogFactory gets created as expected.
|
* Test that a LogFactory gets created as expected.
|
||||||
*/
|
*/
|
||||||
public void testCreateFactory() {
|
public void testCreateFactory() {
|
||||||
LogFactory factory = LogFactory.getFactory();
|
final LogFactory factory = LogFactory.getFactory();
|
||||||
assertNotNull("LogFactory exists", factory);
|
assertNotNull("LogFactory exists", factory);
|
||||||
assertEquals("LogFactory class",
|
assertEquals("LogFactory class",
|
||||||
"org.apache.commons.logging.impl.LogFactoryImpl",
|
"org.apache.commons.logging.impl.LogFactoryImpl",
|
||||||
factory.getClass().getName());
|
factory.getClass().getName());
|
||||||
|
|
||||||
String names[] = factory.getAttributeNames();
|
final String names[] = factory.getAttributeNames();
|
||||||
assertNotNull("Names exists", names);
|
assertNotNull("Names exists", names);
|
||||||
assertEquals("Names empty", 0, names.length);
|
assertEquals("Names empty", 0, names.length);
|
||||||
}
|
}
|
||||||
@@ -103,9 +103,9 @@ public abstract class StandardTests extends TestCase {
|
|||||||
* Verify that we can log messages without exceptions.
|
* Verify that we can log messages without exceptions.
|
||||||
*/
|
*/
|
||||||
public void testPlainMessages() throws Exception {
|
public void testPlainMessages() throws Exception {
|
||||||
List logEvents = new ArrayList();
|
final List logEvents = new ArrayList();
|
||||||
setUpTestAppender(logEvents);
|
setUpTestAppender(logEvents);
|
||||||
Log log = LogFactory.getLog("test-category");
|
final Log log = LogFactory.getLog("test-category");
|
||||||
logPlainMessages(log);
|
logPlainMessages(log);
|
||||||
checkLoggingEvents(logEvents, false);
|
checkLoggingEvents(logEvents, false);
|
||||||
}
|
}
|
||||||
@@ -114,9 +114,9 @@ public abstract class StandardTests extends TestCase {
|
|||||||
* Verify that we can log exception messages.
|
* Verify that we can log exception messages.
|
||||||
*/
|
*/
|
||||||
public void testExceptionMessages() throws Exception {
|
public void testExceptionMessages() throws Exception {
|
||||||
List logEvents = new ArrayList();
|
final List logEvents = new ArrayList();
|
||||||
setUpTestAppender(logEvents);
|
setUpTestAppender(logEvents);
|
||||||
Log log = LogFactory.getLog("test-category");
|
final Log log = LogFactory.getLog("test-category");
|
||||||
logExceptionMessages(log);
|
logExceptionMessages(log);
|
||||||
checkLoggingEvents(logEvents, true);
|
checkLoggingEvents(logEvents, true);
|
||||||
}
|
}
|
||||||
@@ -125,18 +125,18 @@ public abstract class StandardTests extends TestCase {
|
|||||||
* Test Serializability of Log instance
|
* Test Serializability of Log instance
|
||||||
*/
|
*/
|
||||||
public void testSerializable() throws Exception {
|
public void testSerializable() throws Exception {
|
||||||
List logEvents = new ArrayList();
|
final List logEvents = new ArrayList();
|
||||||
setUpTestAppender(logEvents);
|
setUpTestAppender(logEvents);
|
||||||
Log log = LogFactory.getLog("test-category");
|
final Log log = LogFactory.getLog("test-category");
|
||||||
|
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
final ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||||
oos.writeObject(log);
|
oos.writeObject(log);
|
||||||
oos.close();
|
oos.close();
|
||||||
ByteArrayInputStream bais =
|
final ByteArrayInputStream bais =
|
||||||
new ByteArrayInputStream(baos.toByteArray());
|
new ByteArrayInputStream(baos.toByteArray());
|
||||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
final ObjectInputStream ois = new ObjectInputStream(bais);
|
||||||
Log newLog = (Log) ois.readObject();
|
final Log newLog = (Log) ois.readObject();
|
||||||
ois.close();
|
ois.close();
|
||||||
|
|
||||||
// Check the characteristics of the resulting object
|
// Check the characteristics of the resulting object
|
||||||
@@ -162,7 +162,7 @@ public abstract class StandardTests extends TestCase {
|
|||||||
* logevents with no associated exception info). True if
|
* logevents with no associated exception info). True if
|
||||||
* logExceptionMessages was called.
|
* logExceptionMessages was called.
|
||||||
*/
|
*/
|
||||||
private void checkLoggingEvents(List logEvents, boolean thrown) {
|
private void checkLoggingEvents(final List logEvents, final boolean thrown) {
|
||||||
LogEvent ev;
|
LogEvent ev;
|
||||||
|
|
||||||
assertEquals("Unexpected number of log events", 4, logEvents.size());
|
assertEquals("Unexpected number of log events", 4, logEvents.size());
|
||||||
@@ -192,7 +192,7 @@ public abstract class StandardTests extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* Log plain messages.
|
* Log plain messages.
|
||||||
*/
|
*/
|
||||||
private void logPlainMessages(Log log) {
|
private void logPlainMessages(final Log log) {
|
||||||
log.trace("trace"); // Should not actually get logged
|
log.trace("trace"); // Should not actually get logged
|
||||||
log.debug("debug"); // Should not actually get logged
|
log.debug("debug"); // Should not actually get logged
|
||||||
log.info("info");
|
log.info("info");
|
||||||
@@ -204,8 +204,8 @@ public abstract class StandardTests extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* Log messages with exceptions
|
* Log messages with exceptions
|
||||||
*/
|
*/
|
||||||
private void logExceptionMessages(Log log) {
|
private void logExceptionMessages(final Log log) {
|
||||||
Throwable t = new DummyException();
|
final Throwable t = new DummyException();
|
||||||
log.trace("trace", t); // Should not actually get logged
|
log.trace("trace", t); // Should not actually get logged
|
||||||
log.debug("debug", t); // Should not actually get logged
|
log.debug("debug", t); // Should not actually get logged
|
||||||
log.info("info", t);
|
log.info("info", t);
|
||||||
|
|||||||
@@ -36,16 +36,16 @@ public class ApiClasspathStandardTestCase extends TestCase {
|
|||||||
* Return the tests included in this test suite.
|
* Return the tests included in this test suite.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
PathableClassLoader parent = new PathableClassLoader(null);
|
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
parent.addLogicalLib("commons-logging-api");
|
parent.addLogicalLib("commons-logging-api");
|
||||||
|
|
||||||
PathableClassLoader child = new PathableClassLoader(parent);
|
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||||
child.addLogicalLib("log4j12");
|
child.addLogicalLib("log4j12");
|
||||||
child.addLogicalLib("commons-logging");
|
child.addLogicalLib("commons-logging");
|
||||||
child.addLogicalLib("testclasses");
|
child.addLogicalLib("testclasses");
|
||||||
|
|
||||||
Class testClass = child.loadClass(
|
final Class testClass = child.loadClass(
|
||||||
"org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
|
"org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
|
||||||
return new PathableTestSuite(testClass, child);
|
return new PathableTestSuite(testClass, child);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -34,13 +34,13 @@ public class AppClasspathStandardTestCase extends TestCase {
|
|||||||
* Return the tests included in this test suite.
|
* Return the tests included in this test suite.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
PathableClassLoader loader = new PathableClassLoader(null);
|
final PathableClassLoader loader = new PathableClassLoader(null);
|
||||||
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
loader.addLogicalLib("testclasses");
|
loader.addLogicalLib("testclasses");
|
||||||
loader.addLogicalLib("log4j12");
|
loader.addLogicalLib("log4j12");
|
||||||
loader.addLogicalLib("commons-logging");
|
loader.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
Class testClass = loader.loadClass(
|
final Class testClass = loader.loadClass(
|
||||||
"org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
|
"org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
|
||||||
return new PathableTestSuite(testClass, loader);
|
return new PathableTestSuite(testClass, loader);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,15 +35,15 @@ public class ChildClasspathStandardTestCase extends TestCase {
|
|||||||
* Return the tests included in this test suite.
|
* Return the tests included in this test suite.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
PathableClassLoader parent = new PathableClassLoader(null);
|
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
|
|
||||||
PathableClassLoader child = new PathableClassLoader(parent);
|
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||||
child.addLogicalLib("testclasses");
|
child.addLogicalLib("testclasses");
|
||||||
child.addLogicalLib("log4j12");
|
child.addLogicalLib("log4j12");
|
||||||
child.addLogicalLib("commons-logging");
|
child.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
Class testClass = child.loadClass(
|
final Class testClass = child.loadClass(
|
||||||
"org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
|
"org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
|
||||||
return new PathableTestSuite(testClass, child);
|
return new PathableTestSuite(testClass, child);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ import org.apache.log4j.Logger;
|
|||||||
|
|
||||||
public class Log4j12StandardTests extends StandardTests {
|
public class Log4j12StandardTests extends StandardTests {
|
||||||
|
|
||||||
public void setUpTestAppender(List logEvents) {
|
public void setUpTestAppender(final List logEvents) {
|
||||||
TestAppender appender = new TestAppender(logEvents);
|
final TestAppender appender = new TestAppender(logEvents);
|
||||||
Logger rootLogger = Logger.getRootLogger();
|
final Logger rootLogger = Logger.getRootLogger();
|
||||||
rootLogger.removeAllAppenders();
|
rootLogger.removeAllAppenders();
|
||||||
rootLogger.addAppender(appender);
|
rootLogger.addAppender(appender);
|
||||||
rootLogger.setLevel(Level.INFO);
|
rootLogger.setLevel(Level.INFO);
|
||||||
|
|||||||
@@ -34,15 +34,15 @@ public class ParentClasspathStandardTestCase extends TestCase {
|
|||||||
* Return the tests included in this test suite.
|
* Return the tests included in this test suite.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
PathableClassLoader parent = new PathableClassLoader(null);
|
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
parent.addLogicalLib("commons-logging");
|
parent.addLogicalLib("commons-logging");
|
||||||
parent.addLogicalLib("log4j12");
|
parent.addLogicalLib("log4j12");
|
||||||
|
|
||||||
PathableClassLoader child = new PathableClassLoader(parent);
|
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||||
child.addLogicalLib("testclasses");
|
child.addLogicalLib("testclasses");
|
||||||
|
|
||||||
Class testClass = child.loadClass(
|
final Class testClass = child.loadClass(
|
||||||
"org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
|
"org.apache.commons.logging.log4j.log4j12.Log4j12StandardTests");
|
||||||
return new PathableTestSuite(testClass, child);
|
return new PathableTestSuite(testClass, child);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -36,7 +36,7 @@ public class TestAppender extends AppenderSkeleton {
|
|||||||
/**
|
/**
|
||||||
* Constructor.
|
* Constructor.
|
||||||
*/
|
*/
|
||||||
public TestAppender(List logEvents) {
|
public TestAppender(final List logEvents) {
|
||||||
events = logEvents;
|
events = logEvents;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -49,8 +49,8 @@ public class TestAppender extends AppenderSkeleton {
|
|||||||
|
|
||||||
// ------------------------------------------------------- Appender Methods
|
// ------------------------------------------------------- Appender Methods
|
||||||
|
|
||||||
protected void append(LoggingEvent event) {
|
protected void append(final LoggingEvent event) {
|
||||||
StandardTests.LogEvent lev = new StandardTests.LogEvent();
|
final StandardTests.LogEvent lev = new StandardTests.LogEvent();
|
||||||
|
|
||||||
lev.level = event.getLevel().toString();
|
lev.level = event.getLevel().toString();
|
||||||
|
|
||||||
|
|||||||
@@ -61,15 +61,15 @@ public class StandardTestCase extends AbstractLogTest {
|
|||||||
* Return the tests included in this test suite.
|
* Return the tests included in this test suite.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
Class thisClass = StandardTestCase.class;
|
final Class thisClass = StandardTestCase.class;
|
||||||
|
|
||||||
PathableClassLoader loader = new PathableClassLoader(null);
|
final PathableClassLoader loader = new PathableClassLoader(null);
|
||||||
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
loader.addLogicalLib("testclasses");
|
loader.addLogicalLib("testclasses");
|
||||||
loader.addLogicalLib("commons-logging");
|
loader.addLogicalLib("commons-logging");
|
||||||
loader.addLogicalLib("logkit");
|
loader.addLogicalLib("logkit");
|
||||||
|
|
||||||
Class testClass = loader.loadClass(thisClass.getName());
|
final Class testClass = loader.loadClass(thisClass.getName());
|
||||||
return new PathableTestSuite(testClass, loader);
|
return new PathableTestSuite(testClass, loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -115,7 +115,7 @@ public class StandardTestCase extends AbstractLogTest {
|
|||||||
"org.apache.commons.logging.impl.LogFactoryImpl",
|
"org.apache.commons.logging.impl.LogFactoryImpl",
|
||||||
factory.getClass().getName());
|
factory.getClass().getName());
|
||||||
|
|
||||||
String names[] = factory.getAttributeNames();
|
final String names[] = factory.getAttributeNames();
|
||||||
assertNotNull("Names exists", names);
|
assertNotNull("Names exists", names);
|
||||||
assertEquals("Names empty", 0, names.length);
|
assertEquals("Names empty", 0, names.length);
|
||||||
}
|
}
|
||||||
@@ -130,13 +130,13 @@ public class StandardTestCase extends AbstractLogTest {
|
|||||||
checkStandard();
|
checkStandard();
|
||||||
|
|
||||||
// Serialize and deserialize the instance
|
// Serialize and deserialize the instance
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
final ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||||
oos.writeObject(log);
|
oos.writeObject(log);
|
||||||
oos.close();
|
oos.close();
|
||||||
ByteArrayInputStream bais =
|
final ByteArrayInputStream bais =
|
||||||
new ByteArrayInputStream(baos.toByteArray());
|
new ByteArrayInputStream(baos.toByteArray());
|
||||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
final ObjectInputStream ois = new ObjectInputStream(bais);
|
||||||
log = (Log) ois.readObject();
|
log = (Log) ois.readObject();
|
||||||
ois.close();
|
ois.close();
|
||||||
|
|
||||||
|
|||||||
@@ -68,13 +68,13 @@ public class NoOpLogTestCase extends AbstractLogTest
|
|||||||
checkLog(log);
|
checkLog(log);
|
||||||
|
|
||||||
// Serialize and deserialize the instance
|
// Serialize and deserialize the instance
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
final ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||||
oos.writeObject(log);
|
oos.writeObject(log);
|
||||||
oos.close();
|
oos.close();
|
||||||
ByteArrayInputStream bais =
|
final ByteArrayInputStream bais =
|
||||||
new ByteArrayInputStream(baos.toByteArray());
|
new ByteArrayInputStream(baos.toByteArray());
|
||||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
final ObjectInputStream ois = new ObjectInputStream(bais);
|
||||||
log = (Log) ois.readObject();
|
log = (Log) ois.readObject();
|
||||||
ois.close();
|
ois.close();
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ public class NoOpLogTestCase extends AbstractLogTest
|
|||||||
|
|
||||||
// -------------------------------------------------------- Support Methods
|
// -------------------------------------------------------- Support Methods
|
||||||
|
|
||||||
private void checkLog(Log log) {
|
private void checkLog(final Log log) {
|
||||||
|
|
||||||
assertNotNull("Log exists", log);
|
assertNotNull("Log exists", log);
|
||||||
assertEquals("Log class",
|
assertEquals("Log class",
|
||||||
|
|||||||
@@ -52,12 +52,12 @@ public class ChildFirstTestCase extends TestCase {
|
|||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
Class thisClass = ChildFirstTestCase.class;
|
final Class thisClass = ChildFirstTestCase.class;
|
||||||
ClassLoader thisClassLoader = thisClass.getClassLoader();
|
final ClassLoader thisClassLoader = thisClass.getClassLoader();
|
||||||
|
|
||||||
// Make the parent a direct child of the bootloader to hide all
|
// Make the parent a direct child of the bootloader to hide all
|
||||||
// other classes in the system classpath
|
// other classes in the system classpath
|
||||||
PathableClassLoader parent = new PathableClassLoader(null);
|
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||||
parent.setParentFirst(false);
|
parent.setParentFirst(false);
|
||||||
|
|
||||||
// Make the junit classes visible as a special case, as junit
|
// Make the junit classes visible as a special case, as junit
|
||||||
@@ -71,7 +71,7 @@ public class ChildFirstTestCase extends TestCase {
|
|||||||
parent.addLogicalLib("commons-logging");
|
parent.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
// Create a child classloader to load the test case through
|
// Create a child classloader to load the test case through
|
||||||
PathableClassLoader child = new PathableClassLoader(parent);
|
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||||
child.setParentFirst(false);
|
child.setParentFirst(false);
|
||||||
|
|
||||||
// Obviously, the child classloader needs to have the test classes
|
// Obviously, the child classloader needs to have the test classes
|
||||||
@@ -80,11 +80,11 @@ public class ChildFirstTestCase extends TestCase {
|
|||||||
child.addLogicalLib("commons-logging-adapters");
|
child.addLogicalLib("commons-logging-adapters");
|
||||||
|
|
||||||
// Create a third classloader to be the context classloader.
|
// Create a third classloader to be the context classloader.
|
||||||
PathableClassLoader context = new PathableClassLoader(child);
|
final PathableClassLoader context = new PathableClassLoader(child);
|
||||||
context.setParentFirst(false);
|
context.setParentFirst(false);
|
||||||
|
|
||||||
// reload this class via the child classloader
|
// reload this class via the child classloader
|
||||||
Class testClass = child.loadClass(thisClass.getName());
|
final Class testClass = child.loadClass(thisClass.getName());
|
||||||
|
|
||||||
// and return our custom TestSuite class
|
// and return our custom TestSuite class
|
||||||
return new PathableTestSuite(testClass, context);
|
return new PathableTestSuite(testClass, context);
|
||||||
@@ -96,7 +96,7 @@ public class ChildFirstTestCase extends TestCase {
|
|||||||
* this object instance.
|
* this object instance.
|
||||||
*/
|
*/
|
||||||
private Set getAncestorCLs() {
|
private Set getAncestorCLs() {
|
||||||
Set s = new HashSet();
|
final Set s = new HashSet();
|
||||||
ClassLoader cl = this.getClass().getClassLoader();
|
ClassLoader cl = this.getClass().getClassLoader();
|
||||||
while (cl != null) {
|
while (cl != null) {
|
||||||
s.add(cl);
|
s.add(cl);
|
||||||
@@ -113,14 +113,14 @@ public class ChildFirstTestCase extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testPaths() throws Exception {
|
public void testPaths() throws Exception {
|
||||||
// the context classloader is not expected to be null
|
// the context classloader is not expected to be null
|
||||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||||
assertNotNull("Context classloader is null", contextLoader);
|
assertNotNull("Context classloader is null", contextLoader);
|
||||||
assertEquals("Context classloader has unexpected type",
|
assertEquals("Context classloader has unexpected type",
|
||||||
PathableClassLoader.class.getName(),
|
PathableClassLoader.class.getName(),
|
||||||
contextLoader.getClass().getName());
|
contextLoader.getClass().getName());
|
||||||
|
|
||||||
// the classloader that loaded this class is obviously not null
|
// the classloader that loaded this class is obviously not null
|
||||||
ClassLoader thisLoader = this.getClass().getClassLoader();
|
final ClassLoader thisLoader = this.getClass().getClassLoader();
|
||||||
assertNotNull("thisLoader is null", thisLoader);
|
assertNotNull("thisLoader is null", thisLoader);
|
||||||
assertEquals("thisLoader has unexpected type",
|
assertEquals("thisLoader has unexpected type",
|
||||||
PathableClassLoader.class.getName(),
|
PathableClassLoader.class.getName(),
|
||||||
@@ -132,7 +132,7 @@ public class ChildFirstTestCase extends TestCase {
|
|||||||
thisLoader, contextLoader.getParent());
|
thisLoader, contextLoader.getParent());
|
||||||
|
|
||||||
// thisLoader's parent should be available
|
// thisLoader's parent should be available
|
||||||
ClassLoader parentLoader = thisLoader.getParent();
|
final ClassLoader parentLoader = thisLoader.getParent();
|
||||||
assertNotNull("Parent classloader is null", parentLoader);
|
assertNotNull("Parent classloader is null", parentLoader);
|
||||||
assertEquals("Parent classloader has unexpected type",
|
assertEquals("Parent classloader has unexpected type",
|
||||||
PathableClassLoader.class.getName(),
|
PathableClassLoader.class.getName(),
|
||||||
@@ -144,7 +144,7 @@ public class ChildFirstTestCase extends TestCase {
|
|||||||
// getSystemClassloader is not a PathableClassLoader; it's of a
|
// getSystemClassloader is not a PathableClassLoader; it's of a
|
||||||
// built-in type. This also verifies that system classloader is none of
|
// built-in type. This also verifies that system classloader is none of
|
||||||
// (context, child, parent).
|
// (context, child, parent).
|
||||||
ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
|
final ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
|
||||||
assertNotNull("System classloader is null", systemLoader);
|
assertNotNull("System classloader is null", systemLoader);
|
||||||
assertFalse("System classloader has unexpected type",
|
assertFalse("System classloader has unexpected type",
|
||||||
PathableClassLoader.class.getName().equals(
|
PathableClassLoader.class.getName().equals(
|
||||||
@@ -153,38 +153,38 @@ public class ChildFirstTestCase extends TestCase {
|
|||||||
// junit classes should be visible; their classloader is not
|
// junit classes should be visible; their classloader is not
|
||||||
// in the hierarchy of parent classloaders for this class,
|
// in the hierarchy of parent classloaders for this class,
|
||||||
// though it is accessable due to trickery in the PathableClassLoader.
|
// though it is accessable due to trickery in the PathableClassLoader.
|
||||||
Class junitTest = contextLoader.loadClass("junit.framework.Test");
|
final Class junitTest = contextLoader.loadClass("junit.framework.Test");
|
||||||
Set ancestorCLs = getAncestorCLs();
|
final Set ancestorCLs = getAncestorCLs();
|
||||||
assertFalse("Junit not loaded by ancestor classloader",
|
assertFalse("Junit not loaded by ancestor classloader",
|
||||||
ancestorCLs.contains(junitTest.getClassLoader()));
|
ancestorCLs.contains(junitTest.getClassLoader()));
|
||||||
|
|
||||||
// jcl api classes should be visible only via the parent
|
// jcl api classes should be visible only via the parent
|
||||||
Class logClass = contextLoader.loadClass("org.apache.commons.logging.Log");
|
final Class logClass = contextLoader.loadClass("org.apache.commons.logging.Log");
|
||||||
assertSame("Log class not loaded via parent",
|
assertSame("Log class not loaded via parent",
|
||||||
logClass.getClassLoader(), parentLoader);
|
logClass.getClassLoader(), parentLoader);
|
||||||
|
|
||||||
// jcl adapter classes should be visible via both parent and child. However
|
// jcl adapter classes should be visible via both parent and child. However
|
||||||
// as the classloaders are child-first we should see the child one.
|
// as the classloaders are child-first we should see the child one.
|
||||||
Class log4jClass = contextLoader.loadClass("org.apache.commons.logging.impl.Log4JLogger");
|
final Class log4jClass = contextLoader.loadClass("org.apache.commons.logging.impl.Log4JLogger");
|
||||||
assertSame("Log4JLogger not loaded via child",
|
assertSame("Log4JLogger not loaded via child",
|
||||||
log4jClass.getClassLoader(), thisLoader);
|
log4jClass.getClassLoader(), thisLoader);
|
||||||
|
|
||||||
// test classes should be visible via the child only
|
// test classes should be visible via the child only
|
||||||
Class testClass = contextLoader.loadClass("org.apache.commons.logging.PathableTestSuite");
|
final Class testClass = contextLoader.loadClass("org.apache.commons.logging.PathableTestSuite");
|
||||||
assertSame("PathableTestSuite not loaded via child",
|
assertSame("PathableTestSuite not loaded via child",
|
||||||
testClass.getClassLoader(), thisLoader);
|
testClass.getClassLoader(), thisLoader);
|
||||||
|
|
||||||
// test loading of class that is not available
|
// test loading of class that is not available
|
||||||
try {
|
try {
|
||||||
Class noSuchClass = contextLoader.loadClass("no.such.class");
|
final Class noSuchClass = contextLoader.loadClass("no.such.class");
|
||||||
fail("Class no.such.class is unexpectedly available");
|
fail("Class no.such.class is unexpectedly available");
|
||||||
assertNotNull(noSuchClass); // silence warning about unused var
|
assertNotNull(noSuchClass); // silence warning about unused var
|
||||||
} catch(ClassNotFoundException ex) {
|
} catch(final ClassNotFoundException ex) {
|
||||||
// ok
|
// ok
|
||||||
}
|
}
|
||||||
|
|
||||||
// String class classloader is null
|
// String class classloader is null
|
||||||
Class stringClass = contextLoader.loadClass("java.lang.String");
|
final Class stringClass = contextLoader.loadClass("java.lang.String");
|
||||||
assertNull("String class classloader is not null!",
|
assertNull("String class classloader is not null!",
|
||||||
stringClass.getClassLoader());
|
stringClass.getClassLoader());
|
||||||
}
|
}
|
||||||
@@ -195,8 +195,8 @@ public class ChildFirstTestCase extends TestCase {
|
|||||||
public void testResource() {
|
public void testResource() {
|
||||||
URL resource;
|
URL resource;
|
||||||
|
|
||||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||||
ClassLoader childLoader = contextLoader.getParent();
|
final ClassLoader childLoader = contextLoader.getParent();
|
||||||
|
|
||||||
// getResource where it doesn't exist
|
// getResource where it doesn't exist
|
||||||
resource = childLoader.getResource("nosuchfile");
|
resource = childLoader.getResource("nosuchfile");
|
||||||
@@ -228,10 +228,10 @@ public class ChildFirstTestCase extends TestCase {
|
|||||||
URL[] urls;
|
URL[] urls;
|
||||||
|
|
||||||
// verify the classloader hierarchy
|
// verify the classloader hierarchy
|
||||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||||
ClassLoader childLoader = contextLoader.getParent();
|
final ClassLoader childLoader = contextLoader.getParent();
|
||||||
ClassLoader parentLoader = childLoader.getParent();
|
final ClassLoader parentLoader = childLoader.getParent();
|
||||||
ClassLoader bootLoader = parentLoader.getParent();
|
final ClassLoader bootLoader = parentLoader.getParent();
|
||||||
assertNull("Unexpected classloader hierarchy", bootLoader);
|
assertNull("Unexpected classloader hierarchy", bootLoader);
|
||||||
|
|
||||||
// getResources where no instances exist
|
// getResources where no instances exist
|
||||||
@@ -264,7 +264,7 @@ public class ChildFirstTestCase extends TestCase {
|
|||||||
|
|
||||||
// There is no guarantee about the ordering of results returned from getResources
|
// There is no guarantee about the ordering of results returned from getResources
|
||||||
// To make this test portable across JVMs, sort the string to give them a known order
|
// To make this test portable across JVMs, sort the string to give them a known order
|
||||||
String[] urlsToStrings = new String[2];
|
final String[] urlsToStrings = new String[2];
|
||||||
urlsToStrings[0] = urls[0].toString();
|
urlsToStrings[0] = urls[0].toString();
|
||||||
urlsToStrings[1] = urls[1].toString();
|
urlsToStrings[1] = urls[1].toString();
|
||||||
Arrays.sort(urlsToStrings);
|
Arrays.sort(urlsToStrings);
|
||||||
@@ -277,13 +277,13 @@ public class ChildFirstTestCase extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* Utility method to convert an enumeration-of-URLs into an array of URLs.
|
* Utility method to convert an enumeration-of-URLs into an array of URLs.
|
||||||
*/
|
*/
|
||||||
private static URL[] toURLArray(Enumeration e) {
|
private static URL[] toURLArray(final Enumeration e) {
|
||||||
ArrayList l = new ArrayList();
|
final ArrayList l = new ArrayList();
|
||||||
while (e.hasMoreElements()) {
|
while (e.hasMoreElements()) {
|
||||||
URL u = (URL) e.nextElement();
|
final URL u = (URL) e.nextElement();
|
||||||
l.add(u);
|
l.add(u);
|
||||||
}
|
}
|
||||||
URL[] tmp = new URL[l.size()];
|
final URL[] tmp = new URL[l.size()];
|
||||||
return (URL[]) l.toArray(tmp);
|
return (URL[]) l.toArray(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -294,10 +294,10 @@ public class ChildFirstTestCase extends TestCase {
|
|||||||
java.io.InputStream is;
|
java.io.InputStream is;
|
||||||
|
|
||||||
// verify the classloader hierarchy
|
// verify the classloader hierarchy
|
||||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||||
ClassLoader childLoader = contextLoader.getParent();
|
final ClassLoader childLoader = contextLoader.getParent();
|
||||||
ClassLoader parentLoader = childLoader.getParent();
|
final ClassLoader parentLoader = childLoader.getParent();
|
||||||
ClassLoader bootLoader = parentLoader.getParent();
|
final ClassLoader bootLoader = parentLoader.getParent();
|
||||||
assertNull("Unexpected classloader hierarchy", bootLoader);
|
assertNull("Unexpected classloader hierarchy", bootLoader);
|
||||||
|
|
||||||
// getResourceAsStream where no instances exist
|
// getResourceAsStream where no instances exist
|
||||||
|
|||||||
@@ -35,15 +35,15 @@ public class GeneralTestCase extends TestCase {
|
|||||||
* Set up a custom classloader hierarchy for this test case.
|
* Set up a custom classloader hierarchy for this test case.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
Class thisClass = GeneralTestCase.class;
|
final Class thisClass = GeneralTestCase.class;
|
||||||
ClassLoader thisClassLoader = thisClass.getClassLoader();
|
final ClassLoader thisClassLoader = thisClass.getClassLoader();
|
||||||
|
|
||||||
PathableClassLoader loader = new PathableClassLoader(null);
|
final PathableClassLoader loader = new PathableClassLoader(null);
|
||||||
loader.useExplicitLoader("junit.", thisClassLoader);
|
loader.useExplicitLoader("junit.", thisClassLoader);
|
||||||
loader.addLogicalLib("testclasses");
|
loader.addLogicalLib("testclasses");
|
||||||
|
|
||||||
// reload this class via the child classloader
|
// reload this class via the child classloader
|
||||||
Class testClass = loader.loadClass(thisClass.getName());
|
final Class testClass = loader.loadClass(thisClass.getName());
|
||||||
|
|
||||||
// and return our custom TestSuite class
|
// and return our custom TestSuite class
|
||||||
return new PathableTestSuite(testClass, loader);
|
return new PathableTestSuite(testClass, loader);
|
||||||
@@ -87,12 +87,12 @@ public class GeneralTestCase extends TestCase {
|
|||||||
* a non-custom one.
|
* a non-custom one.
|
||||||
*/
|
*/
|
||||||
private static void checkAndSetContext() {
|
private static void checkAndSetContext() {
|
||||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||||
assertEquals("ContextLoader is of unexpected type",
|
assertEquals("ContextLoader is of unexpected type",
|
||||||
contextLoader.getClass().getName(),
|
contextLoader.getClass().getName(),
|
||||||
PathableClassLoader.class.getName());
|
PathableClassLoader.class.getName());
|
||||||
|
|
||||||
URL[] noUrls = new URL[0];
|
final URL[] noUrls = new URL[0];
|
||||||
Thread.currentThread().setContextClassLoader(new URLClassLoader(noUrls));
|
Thread.currentThread().setContextClassLoader(new URLClassLoader(noUrls));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -52,12 +52,12 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
* </ul>
|
* </ul>
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
Class thisClass = ParentFirstTestCase.class;
|
final Class thisClass = ParentFirstTestCase.class;
|
||||||
ClassLoader thisClassLoader = thisClass.getClassLoader();
|
final ClassLoader thisClassLoader = thisClass.getClassLoader();
|
||||||
|
|
||||||
// Make the parent a direct child of the bootloader to hide all
|
// Make the parent a direct child of the bootloader to hide all
|
||||||
// other classes in the system classpath
|
// other classes in the system classpath
|
||||||
PathableClassLoader parent = new PathableClassLoader(null);
|
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||||
|
|
||||||
// Make the junit classes visible as a special case, as junit
|
// Make the junit classes visible as a special case, as junit
|
||||||
// won't be able to call this class at all without this. The
|
// won't be able to call this class at all without this. The
|
||||||
@@ -70,7 +70,7 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
parent.addLogicalLib("commons-logging");
|
parent.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
// create a child classloader to load the test case through
|
// create a child classloader to load the test case through
|
||||||
PathableClassLoader child = new PathableClassLoader(parent);
|
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||||
|
|
||||||
// obviously, the child classloader needs to have the test classes
|
// obviously, the child classloader needs to have the test classes
|
||||||
// in its path!
|
// in its path!
|
||||||
@@ -78,10 +78,10 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
child.addLogicalLib("commons-logging-adapters");
|
child.addLogicalLib("commons-logging-adapters");
|
||||||
|
|
||||||
// create a third classloader to be the context classloader.
|
// create a third classloader to be the context classloader.
|
||||||
PathableClassLoader context = new PathableClassLoader(child);
|
final PathableClassLoader context = new PathableClassLoader(child);
|
||||||
|
|
||||||
// reload this class via the child classloader
|
// reload this class via the child classloader
|
||||||
Class testClass = child.loadClass(thisClass.getName());
|
final Class testClass = child.loadClass(thisClass.getName());
|
||||||
|
|
||||||
// and return our custom TestSuite class
|
// and return our custom TestSuite class
|
||||||
return new PathableTestSuite(testClass, context);
|
return new PathableTestSuite(testClass, context);
|
||||||
@@ -93,7 +93,7 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
* this object instance.
|
* this object instance.
|
||||||
*/
|
*/
|
||||||
private Set getAncestorCLs() {
|
private Set getAncestorCLs() {
|
||||||
Set s = new HashSet();
|
final Set s = new HashSet();
|
||||||
ClassLoader cl = this.getClass().getClassLoader();
|
ClassLoader cl = this.getClass().getClassLoader();
|
||||||
while (cl != null) {
|
while (cl != null) {
|
||||||
s.add(cl);
|
s.add(cl);
|
||||||
@@ -110,14 +110,14 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testPaths() throws Exception {
|
public void testPaths() throws Exception {
|
||||||
// the context classloader is not expected to be null
|
// the context classloader is not expected to be null
|
||||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||||
assertNotNull("Context classloader is null", contextLoader);
|
assertNotNull("Context classloader is null", contextLoader);
|
||||||
assertEquals("Context classloader has unexpected type",
|
assertEquals("Context classloader has unexpected type",
|
||||||
PathableClassLoader.class.getName(),
|
PathableClassLoader.class.getName(),
|
||||||
contextLoader.getClass().getName());
|
contextLoader.getClass().getName());
|
||||||
|
|
||||||
// the classloader that loaded this class is obviously not null
|
// the classloader that loaded this class is obviously not null
|
||||||
ClassLoader thisLoader = this.getClass().getClassLoader();
|
final ClassLoader thisLoader = this.getClass().getClassLoader();
|
||||||
assertNotNull("thisLoader is null", thisLoader);
|
assertNotNull("thisLoader is null", thisLoader);
|
||||||
assertEquals("thisLoader has unexpected type",
|
assertEquals("thisLoader has unexpected type",
|
||||||
PathableClassLoader.class.getName(),
|
PathableClassLoader.class.getName(),
|
||||||
@@ -129,7 +129,7 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
thisLoader, contextLoader.getParent());
|
thisLoader, contextLoader.getParent());
|
||||||
|
|
||||||
// thisLoader's parent should be available
|
// thisLoader's parent should be available
|
||||||
ClassLoader parentLoader = thisLoader.getParent();
|
final ClassLoader parentLoader = thisLoader.getParent();
|
||||||
assertNotNull("Parent classloader is null", parentLoader);
|
assertNotNull("Parent classloader is null", parentLoader);
|
||||||
assertEquals("Parent classloader has unexpected type",
|
assertEquals("Parent classloader has unexpected type",
|
||||||
PathableClassLoader.class.getName(),
|
PathableClassLoader.class.getName(),
|
||||||
@@ -141,7 +141,7 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
// getSystemClassloader is not a PathableClassLoader; it's of a
|
// getSystemClassloader is not a PathableClassLoader; it's of a
|
||||||
// built-in type. This also verifies that system classloader is none of
|
// built-in type. This also verifies that system classloader is none of
|
||||||
// (context, child, parent).
|
// (context, child, parent).
|
||||||
ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
|
final ClassLoader systemLoader = ClassLoader.getSystemClassLoader();
|
||||||
assertNotNull("System classloader is null", systemLoader);
|
assertNotNull("System classloader is null", systemLoader);
|
||||||
assertFalse("System classloader has unexpected type",
|
assertFalse("System classloader has unexpected type",
|
||||||
PathableClassLoader.class.getName().equals(
|
PathableClassLoader.class.getName().equals(
|
||||||
@@ -150,38 +150,38 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
// junit classes should be visible; their classloader is not
|
// junit classes should be visible; their classloader is not
|
||||||
// in the hierarchy of parent classloaders for this class,
|
// in the hierarchy of parent classloaders for this class,
|
||||||
// though it is accessable due to trickery in the PathableClassLoader.
|
// though it is accessable due to trickery in the PathableClassLoader.
|
||||||
Class junitTest = contextLoader.loadClass("junit.framework.Test");
|
final Class junitTest = contextLoader.loadClass("junit.framework.Test");
|
||||||
Set ancestorCLs = getAncestorCLs();
|
final Set ancestorCLs = getAncestorCLs();
|
||||||
assertFalse("Junit not loaded by ancestor classloader",
|
assertFalse("Junit not loaded by ancestor classloader",
|
||||||
ancestorCLs.contains(junitTest.getClassLoader()));
|
ancestorCLs.contains(junitTest.getClassLoader()));
|
||||||
|
|
||||||
// jcl api classes should be visible only via the parent
|
// jcl api classes should be visible only via the parent
|
||||||
Class logClass = contextLoader.loadClass("org.apache.commons.logging.Log");
|
final Class logClass = contextLoader.loadClass("org.apache.commons.logging.Log");
|
||||||
assertSame("Log class not loaded via parent",
|
assertSame("Log class not loaded via parent",
|
||||||
logClass.getClassLoader(), parentLoader);
|
logClass.getClassLoader(), parentLoader);
|
||||||
|
|
||||||
// jcl adapter classes should be visible via both parent and child. However
|
// jcl adapter classes should be visible via both parent and child. However
|
||||||
// as the classloaders are parent-first we should see the parent one.
|
// as the classloaders are parent-first we should see the parent one.
|
||||||
Class log4jClass = contextLoader.loadClass("org.apache.commons.logging.impl.Log4JLogger");
|
final Class log4jClass = contextLoader.loadClass("org.apache.commons.logging.impl.Log4JLogger");
|
||||||
assertSame("Log4JLogger not loaded via parent",
|
assertSame("Log4JLogger not loaded via parent",
|
||||||
log4jClass.getClassLoader(), parentLoader);
|
log4jClass.getClassLoader(), parentLoader);
|
||||||
|
|
||||||
// test classes should be visible via the child only
|
// test classes should be visible via the child only
|
||||||
Class testClass = contextLoader.loadClass("org.apache.commons.logging.PathableTestSuite");
|
final Class testClass = contextLoader.loadClass("org.apache.commons.logging.PathableTestSuite");
|
||||||
assertSame("PathableTestSuite not loaded via child",
|
assertSame("PathableTestSuite not loaded via child",
|
||||||
testClass.getClassLoader(), thisLoader);
|
testClass.getClassLoader(), thisLoader);
|
||||||
|
|
||||||
// test loading of class that is not available
|
// test loading of class that is not available
|
||||||
try {
|
try {
|
||||||
Class noSuchClass = contextLoader.loadClass("no.such.class");
|
final Class noSuchClass = contextLoader.loadClass("no.such.class");
|
||||||
fail("Class no.such.class is unexpectedly available");
|
fail("Class no.such.class is unexpectedly available");
|
||||||
assertNotNull(noSuchClass); // silence warning about unused var
|
assertNotNull(noSuchClass); // silence warning about unused var
|
||||||
} catch(ClassNotFoundException ex) {
|
} catch(final ClassNotFoundException ex) {
|
||||||
// ok
|
// ok
|
||||||
}
|
}
|
||||||
|
|
||||||
// String class classloader is null
|
// String class classloader is null
|
||||||
Class stringClass = contextLoader.loadClass("java.lang.String");
|
final Class stringClass = contextLoader.loadClass("java.lang.String");
|
||||||
assertNull("String class classloader is not null!",
|
assertNull("String class classloader is not null!",
|
||||||
stringClass.getClassLoader());
|
stringClass.getClassLoader());
|
||||||
}
|
}
|
||||||
@@ -192,8 +192,8 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
public void testResource() {
|
public void testResource() {
|
||||||
URL resource;
|
URL resource;
|
||||||
|
|
||||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||||
ClassLoader childLoader = contextLoader.getParent();
|
final ClassLoader childLoader = contextLoader.getParent();
|
||||||
|
|
||||||
// getResource where it doesn't exist
|
// getResource where it doesn't exist
|
||||||
resource = childLoader.getResource("nosuchfile");
|
resource = childLoader.getResource("nosuchfile");
|
||||||
@@ -225,10 +225,10 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
URL[] urls;
|
URL[] urls;
|
||||||
|
|
||||||
// verify the classloader hierarchy
|
// verify the classloader hierarchy
|
||||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||||
ClassLoader childLoader = contextLoader.getParent();
|
final ClassLoader childLoader = contextLoader.getParent();
|
||||||
ClassLoader parentLoader = childLoader.getParent();
|
final ClassLoader parentLoader = childLoader.getParent();
|
||||||
ClassLoader bootLoader = parentLoader.getParent();
|
final ClassLoader bootLoader = parentLoader.getParent();
|
||||||
assertNull("Unexpected classloader hierarchy", bootLoader);
|
assertNull("Unexpected classloader hierarchy", bootLoader);
|
||||||
|
|
||||||
// getResources where no instances exist
|
// getResources where no instances exist
|
||||||
@@ -254,7 +254,7 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
|
|
||||||
// There is no gaurantee about the ordering of results returned from getResources
|
// There is no gaurantee about the ordering of results returned from getResources
|
||||||
// To make this test portable across JVMs, sort the string to give them a known order
|
// To make this test portable across JVMs, sort the string to give them a known order
|
||||||
String[] urlsToStrings = new String[2];
|
final String[] urlsToStrings = new String[2];
|
||||||
urlsToStrings[0] = urls[0].toString();
|
urlsToStrings[0] = urls[0].toString();
|
||||||
urlsToStrings[1] = urls[1].toString();
|
urlsToStrings[1] = urls[1].toString();
|
||||||
Arrays.sort(urlsToStrings);
|
Arrays.sort(urlsToStrings);
|
||||||
@@ -268,13 +268,13 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
/**
|
/**
|
||||||
* Utility method to convert an enumeration-of-URLs into an array of URLs.
|
* Utility method to convert an enumeration-of-URLs into an array of URLs.
|
||||||
*/
|
*/
|
||||||
private static URL[] toURLArray(Enumeration e) {
|
private static URL[] toURLArray(final Enumeration e) {
|
||||||
ArrayList l = new ArrayList();
|
final ArrayList l = new ArrayList();
|
||||||
while (e.hasMoreElements()) {
|
while (e.hasMoreElements()) {
|
||||||
URL u = (URL) e.nextElement();
|
final URL u = (URL) e.nextElement();
|
||||||
l.add(u);
|
l.add(u);
|
||||||
}
|
}
|
||||||
URL[] tmp = new URL[l.size()];
|
final URL[] tmp = new URL[l.size()];
|
||||||
return (URL[]) l.toArray(tmp);
|
return (URL[]) l.toArray(tmp);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -285,10 +285,10 @@ public class ParentFirstTestCase extends TestCase {
|
|||||||
java.io.InputStream is;
|
java.io.InputStream is;
|
||||||
|
|
||||||
// verify the classloader hierarchy
|
// verify the classloader hierarchy
|
||||||
ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
final ClassLoader contextLoader = Thread.currentThread().getContextClassLoader();
|
||||||
ClassLoader childLoader = contextLoader.getParent();
|
final ClassLoader childLoader = contextLoader.getParent();
|
||||||
ClassLoader parentLoader = childLoader.getParent();
|
final ClassLoader parentLoader = childLoader.getParent();
|
||||||
ClassLoader bootLoader = parentLoader.getParent();
|
final ClassLoader bootLoader = parentLoader.getParent();
|
||||||
assertNull("Unexpected classloader hierarchy", bootLoader);
|
assertNull("Unexpected classloader hierarchy", bootLoader);
|
||||||
|
|
||||||
// getResourceAsStream where no instances exist
|
// getResourceAsStream where no instances exist
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import org.apache.commons.logging.LogFactory;
|
|||||||
public class DummyClass {
|
public class DummyClass {
|
||||||
|
|
||||||
public DummyClass() {
|
public DummyClass() {
|
||||||
Log log = LogFactory.getLog(DummyClass.class);
|
final Log log = LogFactory.getLog(DummyClass.class);
|
||||||
log.info("Some log message");
|
log.info("Some log message");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,7 +42,7 @@ public class MockSecurityManager extends SecurityManager {
|
|||||||
* Define the set of permissions to be granted to classes in the o.a.c.l package,
|
* Define the set of permissions to be granted to classes in the o.a.c.l package,
|
||||||
* but NOT to unit-test classes in o.a.c.l.security package.
|
* but NOT to unit-test classes in o.a.c.l.security package.
|
||||||
*/
|
*/
|
||||||
public void addPermission(Permission p) {
|
public void addPermission(final Permission p) {
|
||||||
permissions.add(p);
|
permissions.add(p);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,7 +58,7 @@ public class MockSecurityManager extends SecurityManager {
|
|||||||
return untrustedCodeCount;
|
return untrustedCodeCount;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void checkPermission(Permission p) throws SecurityException {
|
public void checkPermission(final Permission p) throws SecurityException {
|
||||||
if (setSecurityManagerPerm.implies(p)) {
|
if (setSecurityManagerPerm.implies(p)) {
|
||||||
// ok, allow this; we don't want to block any calls to setSecurityManager
|
// ok, allow this; we don't want to block any calls to setSecurityManager
|
||||||
// otherwise this custom security manager cannot be reset to the original.
|
// otherwise this custom security manager cannot be reset to the original.
|
||||||
@@ -69,7 +69,7 @@ public class MockSecurityManager extends SecurityManager {
|
|||||||
// Allow read-only access to files, as this is needed to load classes!
|
// Allow read-only access to files, as this is needed to load classes!
|
||||||
// Ideally, we would limit this to just .class and .jar files.
|
// Ideally, we would limit this to just .class and .jar files.
|
||||||
if (p instanceof FilePermission) {
|
if (p instanceof FilePermission) {
|
||||||
FilePermission fp = (FilePermission) p;
|
final FilePermission fp = (FilePermission) p;
|
||||||
if (fp.getActions().equals("read")) {
|
if (fp.getActions().equals("read")) {
|
||||||
// System.out.println("Permit read of files");
|
// System.out.println("Permit read of files");
|
||||||
return;
|
return;
|
||||||
@@ -78,14 +78,14 @@ public class MockSecurityManager extends SecurityManager {
|
|||||||
|
|
||||||
System.out.println("\n\ntesting permission:" + p.getClass() + ":"+ p);
|
System.out.println("\n\ntesting permission:" + p.getClass() + ":"+ p);
|
||||||
|
|
||||||
Exception e = new Exception();
|
final Exception e = new Exception();
|
||||||
e.fillInStackTrace();
|
e.fillInStackTrace();
|
||||||
StackTraceElement[] stack = e.getStackTrace();
|
final StackTraceElement[] stack = e.getStackTrace();
|
||||||
|
|
||||||
// scan the call stack from most recent to oldest.
|
// scan the call stack from most recent to oldest.
|
||||||
// start at 1 to skip the entry in the stack for this method
|
// start at 1 to skip the entry in the stack for this method
|
||||||
for(int i=1; i<stack.length; ++i) {
|
for(int i=1; i<stack.length; ++i) {
|
||||||
String cname = stack[i].getClassName();
|
final String cname = stack[i].getClassName();
|
||||||
System.out.println("" + i + ":" + stack[i].getClassName() +
|
System.out.println("" + i + ":" + stack[i].getClassName() +
|
||||||
"." + stack[i].getMethodName() + ":" + stack[i].getLineNumber());
|
"." + stack[i].getMethodName() + ":" + stack[i].getLineNumber());
|
||||||
|
|
||||||
|
|||||||
@@ -59,12 +59,12 @@ public class SecurityAllowedTestCase extends TestCase
|
|||||||
* Return the tests included in this test suite.
|
* Return the tests included in this test suite.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
PathableClassLoader parent = new PathableClassLoader(null);
|
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
parent.addLogicalLib("commons-logging");
|
parent.addLogicalLib("commons-logging");
|
||||||
parent.addLogicalLib("testclasses");
|
parent.addLogicalLib("testclasses");
|
||||||
|
|
||||||
Class testClass = parent.loadClass(
|
final Class testClass = parent.loadClass(
|
||||||
"org.apache.commons.logging.security.SecurityAllowedTestCase");
|
"org.apache.commons.logging.security.SecurityAllowedTestCase");
|
||||||
return new PathableTestSuite(testClass, parent);
|
return new PathableTestSuite(testClass, parent);
|
||||||
}
|
}
|
||||||
@@ -88,17 +88,17 @@ public class SecurityAllowedTestCase extends TestCase
|
|||||||
System.setProperty(
|
System.setProperty(
|
||||||
LogFactory.HASHTABLE_IMPLEMENTATION_PROPERTY,
|
LogFactory.HASHTABLE_IMPLEMENTATION_PROPERTY,
|
||||||
CustomHashtable.class.getName());
|
CustomHashtable.class.getName());
|
||||||
MockSecurityManager mySecurityManager = new MockSecurityManager();
|
final MockSecurityManager mySecurityManager = new MockSecurityManager();
|
||||||
mySecurityManager.addPermission(new AllPermission());
|
mySecurityManager.addPermission(new AllPermission());
|
||||||
System.setSecurityManager(mySecurityManager);
|
System.setSecurityManager(mySecurityManager);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Use reflection so that we can control exactly when the static
|
// Use reflection so that we can control exactly when the static
|
||||||
// initialiser for the LogFactory class is executed.
|
// initialiser for the LogFactory class is executed.
|
||||||
Class c = this.getClass().getClassLoader().loadClass(
|
final Class c = this.getClass().getClassLoader().loadClass(
|
||||||
"org.apache.commons.logging.LogFactory");
|
"org.apache.commons.logging.LogFactory");
|
||||||
Method m = c.getMethod("getLog", new Class[] {Class.class});
|
final Method m = c.getMethod("getLog", new Class[] {Class.class});
|
||||||
Log log = (Log) m.invoke(null, new Object[] {this.getClass()});
|
final Log log = (Log) m.invoke(null, new Object[] {this.getClass()});
|
||||||
|
|
||||||
// Check whether we had any security exceptions so far (which were
|
// Check whether we had any security exceptions so far (which were
|
||||||
// caught by the code). We should not, as every secure operation
|
// caught by the code). We should not, as every secure operation
|
||||||
@@ -111,28 +111,28 @@ public class SecurityAllowedTestCase extends TestCase
|
|||||||
// wrap calls to log methods in AccessControllers because writes to
|
// wrap calls to log methods in AccessControllers because writes to
|
||||||
// a log file *should* only be permitted if the original caller is
|
// a log file *should* only be permitted if the original caller is
|
||||||
// trusted to access that file.
|
// trusted to access that file.
|
||||||
int untrustedCodeCount = mySecurityManager.getUntrustedCodeCount();
|
final int untrustedCodeCount = mySecurityManager.getUntrustedCodeCount();
|
||||||
log.info("testing");
|
log.info("testing");
|
||||||
|
|
||||||
// check that the default map implementation was loaded, as JCL was
|
// check that the default map implementation was loaded, as JCL was
|
||||||
// forbidden from reading the HASHTABLE_IMPLEMENTATION_PROPERTY property.
|
// forbidden from reading the HASHTABLE_IMPLEMENTATION_PROPERTY property.
|
||||||
System.setSecurityManager(null);
|
System.setSecurityManager(null);
|
||||||
Field factoryField = c.getDeclaredField("factories");
|
final Field factoryField = c.getDeclaredField("factories");
|
||||||
factoryField.setAccessible(true);
|
factoryField.setAccessible(true);
|
||||||
Object factoryTable = factoryField.get(null);
|
final Object factoryTable = factoryField.get(null);
|
||||||
assertNotNull(factoryTable);
|
assertNotNull(factoryTable);
|
||||||
assertEquals(CustomHashtable.class.getName(), factoryTable.getClass().getName());
|
assertEquals(CustomHashtable.class.getName(), factoryTable.getClass().getName());
|
||||||
|
|
||||||
// we better compare that we have no security exception during the call to log
|
// we better compare that we have no security exception during the call to log
|
||||||
// IBM JVM tries to load bundles during the invoke call, which increase the count
|
// IBM JVM tries to load bundles during the invoke call, which increase the count
|
||||||
assertEquals("Untrusted code count", untrustedCodeCount, mySecurityManager.getUntrustedCodeCount());
|
assertEquals("Untrusted code count", untrustedCodeCount, mySecurityManager.getUntrustedCodeCount());
|
||||||
} catch(Throwable t) {
|
} catch(final Throwable t) {
|
||||||
// Restore original security manager so output can be generated; the
|
// Restore original security manager so output can be generated; the
|
||||||
// PrintWriter constructor tries to read the line.separator
|
// PrintWriter constructor tries to read the line.separator
|
||||||
// system property.
|
// system property.
|
||||||
System.setSecurityManager(oldSecMgr);
|
System.setSecurityManager(oldSecMgr);
|
||||||
StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
final PrintWriter pw = new PrintWriter(sw);
|
||||||
t.printStackTrace(pw);
|
t.printStackTrace(pw);
|
||||||
fail("Unexpected exception:" + t.getMessage() + ":" + sw.toString());
|
fail("Unexpected exception:" + t.getMessage() + ":" + sw.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -63,12 +63,12 @@ public class SecurityForbiddenTestCase extends TestCase
|
|||||||
* Return the tests included in this test suite.
|
* Return the tests included in this test suite.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
PathableClassLoader parent = new PathableClassLoader(null);
|
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
parent.addLogicalLib("commons-logging");
|
parent.addLogicalLib("commons-logging");
|
||||||
parent.addLogicalLib("testclasses");
|
parent.addLogicalLib("testclasses");
|
||||||
|
|
||||||
Class testClass = parent.loadClass(
|
final Class testClass = parent.loadClass(
|
||||||
"org.apache.commons.logging.security.SecurityForbiddenTestCase");
|
"org.apache.commons.logging.security.SecurityForbiddenTestCase");
|
||||||
return new PathableTestSuite(testClass, parent);
|
return new PathableTestSuite(testClass, parent);
|
||||||
}
|
}
|
||||||
@@ -77,7 +77,7 @@ public class SecurityForbiddenTestCase extends TestCase
|
|||||||
// save security manager so it can be restored in tearDown
|
// save security manager so it can be restored in tearDown
|
||||||
oldSecMgr = System.getSecurityManager();
|
oldSecMgr = System.getSecurityManager();
|
||||||
|
|
||||||
PathableClassLoader classLoader = new PathableClassLoader(null);
|
final PathableClassLoader classLoader = new PathableClassLoader(null);
|
||||||
classLoader.addLogicalLib("commons-logging");
|
classLoader.addLogicalLib("commons-logging");
|
||||||
classLoader.addLogicalLib("testclasses");
|
classLoader.addLogicalLib("testclasses");
|
||||||
|
|
||||||
@@ -99,17 +99,17 @@ public class SecurityForbiddenTestCase extends TestCase
|
|||||||
System.setProperty(
|
System.setProperty(
|
||||||
LogFactory.HASHTABLE_IMPLEMENTATION_PROPERTY,
|
LogFactory.HASHTABLE_IMPLEMENTATION_PROPERTY,
|
||||||
CustomHashtable.class.getName());
|
CustomHashtable.class.getName());
|
||||||
MockSecurityManager mySecurityManager = new MockSecurityManager();
|
final MockSecurityManager mySecurityManager = new MockSecurityManager();
|
||||||
|
|
||||||
System.setSecurityManager(mySecurityManager);
|
System.setSecurityManager(mySecurityManager);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Use reflection so that we can control exactly when the static
|
// Use reflection so that we can control exactly when the static
|
||||||
// initialiser for the LogFactory class is executed.
|
// initialiser for the LogFactory class is executed.
|
||||||
Class c = this.getClass().getClassLoader().loadClass(
|
final Class c = this.getClass().getClassLoader().loadClass(
|
||||||
"org.apache.commons.logging.LogFactory");
|
"org.apache.commons.logging.LogFactory");
|
||||||
Method m = c.getMethod("getLog", new Class[] {Class.class});
|
final Method m = c.getMethod("getLog", new Class[] {Class.class});
|
||||||
Log log = (Log) m.invoke(null, new Object[] {this.getClass()});
|
final Log log = (Log) m.invoke(null, new Object[] {this.getClass()});
|
||||||
log.info("testing");
|
log.info("testing");
|
||||||
|
|
||||||
// check that the default map implementation was loaded, as JCL was
|
// check that the default map implementation was loaded, as JCL was
|
||||||
@@ -118,22 +118,22 @@ public class SecurityForbiddenTestCase extends TestCase
|
|||||||
// The default is either the java Hashtable class (java < 1.2) or the
|
// The default is either the java Hashtable class (java < 1.2) or the
|
||||||
// JCL WeakHashtable (java >= 1.3).
|
// JCL WeakHashtable (java >= 1.3).
|
||||||
System.setSecurityManager(oldSecMgr);
|
System.setSecurityManager(oldSecMgr);
|
||||||
Field factoryField = c.getDeclaredField("factories");
|
final Field factoryField = c.getDeclaredField("factories");
|
||||||
factoryField.setAccessible(true);
|
factoryField.setAccessible(true);
|
||||||
Object factoryTable = factoryField.get(null);
|
final Object factoryTable = factoryField.get(null);
|
||||||
assertNotNull(factoryTable);
|
assertNotNull(factoryTable);
|
||||||
String ftClassName = factoryTable.getClass().getName();
|
final String ftClassName = factoryTable.getClass().getName();
|
||||||
assertTrue("Custom hashtable unexpectedly used",
|
assertTrue("Custom hashtable unexpectedly used",
|
||||||
!CustomHashtable.class.getName().equals(ftClassName));
|
!CustomHashtable.class.getName().equals(ftClassName));
|
||||||
|
|
||||||
assertEquals(0, mySecurityManager.getUntrustedCodeCount());
|
assertEquals(0, mySecurityManager.getUntrustedCodeCount());
|
||||||
} catch(Throwable t) {
|
} catch(final Throwable t) {
|
||||||
// Restore original security manager so output can be generated; the
|
// Restore original security manager so output can be generated; the
|
||||||
// PrintWriter constructor tries to read the line.separator
|
// PrintWriter constructor tries to read the line.separator
|
||||||
// system property.
|
// system property.
|
||||||
System.setSecurityManager(oldSecMgr);
|
System.setSecurityManager(oldSecMgr);
|
||||||
StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
final PrintWriter pw = new PrintWriter(sw);
|
||||||
t.printStackTrace(pw);
|
t.printStackTrace(pw);
|
||||||
fail("Unexpected exception:" + t.getMessage() + ":" + sw.toString());
|
fail("Unexpected exception:" + t.getMessage() + ":" + sw.toString());
|
||||||
}
|
}
|
||||||
@@ -148,7 +148,7 @@ public class SecurityForbiddenTestCase extends TestCase
|
|||||||
System.setProperty(
|
System.setProperty(
|
||||||
LogFactory.HASHTABLE_IMPLEMENTATION_PROPERTY,
|
LogFactory.HASHTABLE_IMPLEMENTATION_PROPERTY,
|
||||||
CustomHashtable.class.getName());
|
CustomHashtable.class.getName());
|
||||||
MockSecurityManager mySecurityManager = new MockSecurityManager();
|
final MockSecurityManager mySecurityManager = new MockSecurityManager();
|
||||||
|
|
||||||
System.setSecurityManager(mySecurityManager);
|
System.setSecurityManager(mySecurityManager);
|
||||||
|
|
||||||
@@ -160,13 +160,13 @@ public class SecurityForbiddenTestCase extends TestCase
|
|||||||
|
|
||||||
System.setSecurityManager(oldSecMgr);
|
System.setSecurityManager(oldSecMgr);
|
||||||
assertEquals(0, mySecurityManager.getUntrustedCodeCount());
|
assertEquals(0, mySecurityManager.getUntrustedCodeCount());
|
||||||
} catch(Throwable t) {
|
} catch(final Throwable t) {
|
||||||
// Restore original security manager so output can be generated; the
|
// Restore original security manager so output can be generated; the
|
||||||
// PrintWriter constructor tries to read the line.separator
|
// PrintWriter constructor tries to read the line.separator
|
||||||
// system property.
|
// system property.
|
||||||
System.setSecurityManager(oldSecMgr);
|
System.setSecurityManager(oldSecMgr);
|
||||||
StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
final PrintWriter pw = new PrintWriter(sw);
|
||||||
t.printStackTrace(pw);
|
t.printStackTrace(pw);
|
||||||
fail("Unexpected exception:" + t.getMessage() + ":" + sw.toString());
|
fail("Unexpected exception:" + t.getMessage() + ":" + sw.toString());
|
||||||
}
|
}
|
||||||
@@ -175,14 +175,14 @@ public class SecurityForbiddenTestCase extends TestCase
|
|||||||
/**
|
/**
|
||||||
* Loads a class with the given classloader.
|
* Loads a class with the given classloader.
|
||||||
*/
|
*/
|
||||||
private Object loadClass(String name, ClassLoader classLoader) {
|
private Object loadClass(final String name, final ClassLoader classLoader) {
|
||||||
try {
|
try {
|
||||||
Class clazz = classLoader.loadClass(name);
|
final Class clazz = classLoader.loadClass(name);
|
||||||
Object obj = clazz.newInstance();
|
final Object obj = clazz.newInstance();
|
||||||
return obj;
|
return obj;
|
||||||
} catch ( Exception e ) {
|
} catch ( final Exception e ) {
|
||||||
StringWriter sw = new StringWriter();
|
final StringWriter sw = new StringWriter();
|
||||||
PrintWriter pw = new PrintWriter(sw);
|
final PrintWriter pw = new PrintWriter(sw);
|
||||||
e.printStackTrace(pw);
|
e.printStackTrace(pw);
|
||||||
fail("Unexpected exception:" + e.getMessage() + ":" + sw.toString());
|
fail("Unexpected exception:" + e.getMessage() + ":" + sw.toString());
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -43,21 +43,21 @@ public class BasicServletTestCase extends TestCase {
|
|||||||
// where a web.xml file specifies ServletContextCleaner as a listener, and
|
// where a web.xml file specifies ServletContextCleaner as a listener, and
|
||||||
// that class is deployed via a shared classloader.
|
// that class is deployed via a shared classloader.
|
||||||
|
|
||||||
PathableClassLoader parent = new PathableClassLoader(null);
|
final PathableClassLoader parent = new PathableClassLoader(null);
|
||||||
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
parent.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
parent.addLogicalLib("commons-logging");
|
parent.addLogicalLib("commons-logging");
|
||||||
parent.addLogicalLib("servlet-api");
|
parent.addLogicalLib("servlet-api");
|
||||||
|
|
||||||
PathableClassLoader child = new PathableClassLoader(parent);
|
final PathableClassLoader child = new PathableClassLoader(parent);
|
||||||
child.setParentFirst(false);
|
child.setParentFirst(false);
|
||||||
child.addLogicalLib("commons-logging");
|
child.addLogicalLib("commons-logging");
|
||||||
child.addLogicalLib("testclasses");
|
child.addLogicalLib("testclasses");
|
||||||
|
|
||||||
PathableClassLoader tccl = new PathableClassLoader(child);
|
final PathableClassLoader tccl = new PathableClassLoader(child);
|
||||||
tccl.setParentFirst(false);
|
tccl.setParentFirst(false);
|
||||||
tccl.addLogicalLib("commons-logging");
|
tccl.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
Class testClass = child.loadClass(BasicServletTestCase.class.getName());
|
final Class testClass = child.loadClass(BasicServletTestCase.class.getName());
|
||||||
return new PathableTestSuite(testClass, tccl);
|
return new PathableTestSuite(testClass, tccl);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -66,7 +66,7 @@ public class BasicServletTestCase extends TestCase {
|
|||||||
* Testing anything else is rather difficult...
|
* Testing anything else is rather difficult...
|
||||||
*/
|
*/
|
||||||
public void testBasics() {
|
public void testBasics() {
|
||||||
ServletContextCleaner scc = new ServletContextCleaner();
|
final ServletContextCleaner scc = new ServletContextCleaner();
|
||||||
scc.contextDestroyed(null);
|
scc.contextDestroyed(null);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,14 +107,14 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
|||||||
* Or we could fix SimpleLog to be sane...
|
* Or we could fix SimpleLog to be sane...
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
Class thisClass = CustomConfigTestCase.class;
|
final Class thisClass = CustomConfigTestCase.class;
|
||||||
|
|
||||||
PathableClassLoader loader = new PathableClassLoader(null);
|
final PathableClassLoader loader = new PathableClassLoader(null);
|
||||||
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
loader.addLogicalLib("testclasses");
|
loader.addLogicalLib("testclasses");
|
||||||
loader.addLogicalLib("commons-logging");
|
loader.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
Class testClass = loader.loadClass(thisClass.getName());
|
final Class testClass = loader.loadClass(thisClass.getName());
|
||||||
return new PathableTestSuite(testClass, loader);
|
return new PathableTestSuite(testClass, loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -209,12 +209,12 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
|||||||
// Check the actual log records against the expected ones
|
// Check the actual log records against the expected ones
|
||||||
protected void checkExpected() {
|
protected void checkExpected() {
|
||||||
|
|
||||||
List acts = ((DecoratedSimpleLog) log).getCache();
|
final List acts = ((DecoratedSimpleLog) log).getCache();
|
||||||
Iterator exps = expected.iterator();
|
final Iterator exps = expected.iterator();
|
||||||
int n = 0;
|
int n = 0;
|
||||||
while (exps.hasNext()) {
|
while (exps.hasNext()) {
|
||||||
LogRecord exp = (LogRecord) exps.next();
|
final LogRecord exp = (LogRecord) exps.next();
|
||||||
LogRecord act = (LogRecord) acts.get(n++);
|
final LogRecord act = (LogRecord) acts.get(n++);
|
||||||
assertEquals("Row " + n + " type", exp.type, act.type);
|
assertEquals("Row " + n + " type", exp.type, act.type);
|
||||||
assertEquals("Row " + n + " message", exp.message, act.message);
|
assertEquals("Row " + n + " message", exp.message, act.message);
|
||||||
assertEquals("Row " + n + " throwable", exp.t, act.t);
|
assertEquals("Row " + n + " throwable", exp.t, act.t);
|
||||||
@@ -235,7 +235,7 @@ public class CustomConfigTestCase extends DefaultConfigTestCase {
|
|||||||
protected void logExceptionMessages() {
|
protected void logExceptionMessages() {
|
||||||
|
|
||||||
// Generate log records
|
// Generate log records
|
||||||
Throwable t = new DummyException();
|
final Throwable t = new DummyException();
|
||||||
log.trace("trace", t); // Should not actually get logged
|
log.trace("trace", t); // Should not actually get logged
|
||||||
log.debug("debug", t);
|
log.debug("debug", t);
|
||||||
log.info("info", t);
|
log.info("info", t);
|
||||||
|
|||||||
@@ -47,14 +47,14 @@ public class DateTimeCustomConfigTestCase extends CustomConfigTestCase {
|
|||||||
* Or we could fix SimpleLog to be sane...
|
* Or we could fix SimpleLog to be sane...
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
Class thisClass = DateTimeCustomConfigTestCase.class;
|
final Class thisClass = DateTimeCustomConfigTestCase.class;
|
||||||
|
|
||||||
PathableClassLoader loader = new PathableClassLoader(null);
|
final PathableClassLoader loader = new PathableClassLoader(null);
|
||||||
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
loader.addLogicalLib("testclasses");
|
loader.addLogicalLib("testclasses");
|
||||||
loader.addLogicalLib("commons-logging");
|
loader.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
Class testClass = loader.loadClass(thisClass.getName());
|
final Class testClass = loader.loadClass(thisClass.getName());
|
||||||
return new PathableTestSuite(testClass, loader);
|
return new PathableTestSuite(testClass, loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -90,9 +90,9 @@ public class DateTimeCustomConfigTestCase extends CustomConfigTestCase {
|
|||||||
assertEquals("Expected date format to be set", "dd.mm.yyyy",
|
assertEquals("Expected date format to be set", "dd.mm.yyyy",
|
||||||
((DecoratedSimpleLog) log).getDateTimeFormat());
|
((DecoratedSimpleLog) log).getDateTimeFormat());
|
||||||
// try the formatter
|
// try the formatter
|
||||||
Date now = new Date();
|
final Date now = new Date();
|
||||||
DateFormat formatter = ((DecoratedSimpleLog) log).getDateTimeFormatter();
|
final DateFormat formatter = ((DecoratedSimpleLog) log).getDateTimeFormatter();
|
||||||
SimpleDateFormat sampleFormatter = new SimpleDateFormat("dd.mm.yyyy");
|
final SimpleDateFormat sampleFormatter = new SimpleDateFormat("dd.mm.yyyy");
|
||||||
assertEquals("Date should be formatters to pattern dd.mm.yyyy",
|
assertEquals("Date should be formatters to pattern dd.mm.yyyy",
|
||||||
sampleFormatter.format(now), formatter.format(now));
|
sampleFormatter.format(now), formatter.format(now));
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -40,7 +40,7 @@ public class DecoratedSimpleLog extends SimpleLog {
|
|||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = 196544280770017153L;
|
private static final long serialVersionUID = 196544280770017153L;
|
||||||
|
|
||||||
public DecoratedSimpleLog(String name) {
|
public DecoratedSimpleLog(final String name) {
|
||||||
super(name);
|
super(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,7 +76,7 @@ public class DecoratedSimpleLog extends SimpleLog {
|
|||||||
|
|
||||||
|
|
||||||
// Cache logged messages
|
// Cache logged messages
|
||||||
protected void log(int type, Object message, Throwable t) {
|
protected void log(final int type, final Object message, final Throwable t) {
|
||||||
|
|
||||||
super.log(type, message, t);
|
super.log(type, message, t);
|
||||||
cache.add(new LogRecord(type, message, t));
|
cache.add(new LogRecord(type, message, t));
|
||||||
|
|||||||
@@ -75,14 +75,14 @@ public class DefaultConfigTestCase extends TestCase {
|
|||||||
* Or we could fix SimpleLog to be sane...
|
* Or we could fix SimpleLog to be sane...
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
Class thisClass = DefaultConfigTestCase.class;
|
final Class thisClass = DefaultConfigTestCase.class;
|
||||||
|
|
||||||
PathableClassLoader loader = new PathableClassLoader(null);
|
final PathableClassLoader loader = new PathableClassLoader(null);
|
||||||
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
loader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
loader.addLogicalLib("testclasses");
|
loader.addLogicalLib("testclasses");
|
||||||
loader.addLogicalLib("commons-logging");
|
loader.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
Class testClass = loader.loadClass(thisClass.getName());
|
final Class testClass = loader.loadClass(thisClass.getName());
|
||||||
return new PathableTestSuite(testClass, loader);
|
return new PathableTestSuite(testClass, loader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -145,7 +145,7 @@ public class DefaultConfigTestCase extends TestCase {
|
|||||||
"org.apache.commons.logging.impl.LogFactoryImpl",
|
"org.apache.commons.logging.impl.LogFactoryImpl",
|
||||||
factory.getClass().getName());
|
factory.getClass().getName());
|
||||||
|
|
||||||
String names[] = factory.getAttributeNames();
|
final String names[] = factory.getAttributeNames();
|
||||||
assertNotNull("Names exists", names);
|
assertNotNull("Names exists", names);
|
||||||
assertEquals("Names empty", 0, names.length);
|
assertEquals("Names empty", 0, names.length);
|
||||||
|
|
||||||
@@ -156,13 +156,13 @@ public class DefaultConfigTestCase extends TestCase {
|
|||||||
public void testSerializable() throws Exception {
|
public void testSerializable() throws Exception {
|
||||||
|
|
||||||
// Serialize and deserialize the instance
|
// Serialize and deserialize the instance
|
||||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
final ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||||
ObjectOutputStream oos = new ObjectOutputStream(baos);
|
final ObjectOutputStream oos = new ObjectOutputStream(baos);
|
||||||
oos.writeObject(log);
|
oos.writeObject(log);
|
||||||
oos.close();
|
oos.close();
|
||||||
ByteArrayInputStream bais =
|
final ByteArrayInputStream bais =
|
||||||
new ByteArrayInputStream(baos.toByteArray());
|
new ByteArrayInputStream(baos.toByteArray());
|
||||||
ObjectInputStream ois = new ObjectInputStream(bais);
|
final ObjectInputStream ois = new ObjectInputStream(bais);
|
||||||
log = (Log) ois.readObject();
|
log = (Log) ois.readObject();
|
||||||
ois.close();
|
ois.close();
|
||||||
|
|
||||||
@@ -229,7 +229,7 @@ public class DefaultConfigTestCase extends TestCase {
|
|||||||
|
|
||||||
|
|
||||||
// Set up decorated log instance
|
// Set up decorated log instance
|
||||||
protected void setUpDecorated(String name) {
|
protected void setUpDecorated(final String name) {
|
||||||
log = new DecoratedSimpleLog(name);
|
log = new DecoratedSimpleLog(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -241,7 +241,7 @@ public class DefaultConfigTestCase extends TestCase {
|
|||||||
|
|
||||||
|
|
||||||
// Set up log instance
|
// Set up log instance
|
||||||
protected void setUpLog(String name) throws Exception {
|
protected void setUpLog(final String name) throws Exception {
|
||||||
log = LogFactory.getLog(name);
|
log = LogFactory.getLog(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -30,7 +30,7 @@ public class LogRecord implements Serializable {
|
|||||||
*/
|
*/
|
||||||
private static final long serialVersionUID = -5254831759209770665L;
|
private static final long serialVersionUID = -5254831759209770665L;
|
||||||
|
|
||||||
public LogRecord(int type, Object message, Throwable t) {
|
public LogRecord(final int type, final Object message, final Throwable t) {
|
||||||
this.type = type;
|
this.type = type;
|
||||||
this.message = message;
|
this.message = message;
|
||||||
this.t = t;
|
this.t = t;
|
||||||
|
|||||||
@@ -30,9 +30,9 @@ import junit.framework.TestCase;
|
|||||||
public class BadTCCLTestCase extends TestCase {
|
public class BadTCCLTestCase extends TestCase {
|
||||||
|
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
PathableClassLoader contextClassLoader = new PathableClassLoader(null);
|
final PathableClassLoader contextClassLoader = new PathableClassLoader(null);
|
||||||
contextClassLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
contextClassLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
PathableTestSuite suite = new PathableTestSuite(BadTCCLTestCase.class, contextClassLoader);
|
final PathableTestSuite suite = new PathableTestSuite(BadTCCLTestCase.class, contextClassLoader);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,7 +43,7 @@ public class BadTCCLTestCase extends TestCase {
|
|||||||
* by the LogFactory.
|
* by the LogFactory.
|
||||||
*/
|
*/
|
||||||
public void testGetLog() {
|
public void testGetLog() {
|
||||||
Log log = LogFactory.getLog(BadTCCLTestCase.class);
|
final Log log = LogFactory.getLog(BadTCCLTestCase.class);
|
||||||
log.debug("Hello, Mum");
|
log.debug("Hello, Mum");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -29,7 +29,7 @@ import junit.framework.TestCase;
|
|||||||
public class NullTCCLTestCase extends TestCase {
|
public class NullTCCLTestCase extends TestCase {
|
||||||
|
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
PathableTestSuite suite = new PathableTestSuite(NullTCCLTestCase.class, null);
|
final PathableTestSuite suite = new PathableTestSuite(NullTCCLTestCase.class, null);
|
||||||
return suite;
|
return suite;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -40,7 +40,7 @@ public class NullTCCLTestCase extends TestCase {
|
|||||||
* by the LogFactory.
|
* by the LogFactory.
|
||||||
*/
|
*/
|
||||||
public void testGetLog() {
|
public void testGetLog() {
|
||||||
Log log = LogFactory.getLog(NullTCCLTestCase.class);
|
final Log log = LogFactory.getLog(NullTCCLTestCase.class);
|
||||||
log.debug("Hello, Mum");
|
log.debug("Hello, Mum");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -20,7 +20,7 @@ import org.apache.commons.logging.Log;
|
|||||||
|
|
||||||
public class MyLog implements Log {
|
public class MyLog implements Log {
|
||||||
|
|
||||||
public MyLog(String category) {}
|
public MyLog(final String category) {}
|
||||||
|
|
||||||
public boolean isDebugEnabled() { return false; }
|
public boolean isDebugEnabled() { return false; }
|
||||||
public boolean isErrorEnabled() { return false; }
|
public boolean isErrorEnabled() { return false; }
|
||||||
@@ -29,16 +29,16 @@ public class MyLog implements Log {
|
|||||||
public boolean isTraceEnabled() { return false; }
|
public boolean isTraceEnabled() { return false; }
|
||||||
public boolean isWarnEnabled() { return false; }
|
public boolean isWarnEnabled() { return false; }
|
||||||
|
|
||||||
public void trace(Object message) {}
|
public void trace(final Object message) {}
|
||||||
public void trace(Object message, Throwable t) {}
|
public void trace(final Object message, final Throwable t) {}
|
||||||
public void debug(Object message) {}
|
public void debug(final Object message) {}
|
||||||
public void debug(Object message, Throwable t) {}
|
public void debug(final Object message, final Throwable t) {}
|
||||||
public void info(Object message) {}
|
public void info(final Object message) {}
|
||||||
public void info(Object message, Throwable t) {}
|
public void info(final Object message, final Throwable t) {}
|
||||||
public void warn(Object message) {}
|
public void warn(final Object message) {}
|
||||||
public void warn(Object message, Throwable t) {}
|
public void warn(final Object message, final Throwable t) {}
|
||||||
public void error(Object message) {}
|
public void error(final Object message) {}
|
||||||
public void error(Object message, Throwable t) {}
|
public void error(final Object message, final Throwable t) {}
|
||||||
public void fatal(Object message) {}
|
public void fatal(final Object message) {}
|
||||||
public void fatal(Object message, Throwable t) {}
|
public void fatal(final Object message, final Throwable t) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -22,11 +22,11 @@ import org.apache.commons.logging.Log;
|
|||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
public class MyLogFactoryImpl extends LogFactory {
|
public class MyLogFactoryImpl extends LogFactory {
|
||||||
public Object getAttribute(String name) { return null; }
|
public Object getAttribute(final String name) { return null; }
|
||||||
public String[] getAttributeNames() { return null; }
|
public String[] getAttributeNames() { return null; }
|
||||||
public Log getInstance(Class clazz) { return null; }
|
public Log getInstance(final Class clazz) { return null; }
|
||||||
public Log getInstance(String name) { return null; }
|
public Log getInstance(final String name) { return null; }
|
||||||
public void release() {}
|
public void release() {}
|
||||||
public void removeAttribute(String name) {}
|
public void removeAttribute(final String name) {}
|
||||||
public void setAttribute(String name, Object value) {}
|
public void setAttribute(final String name, final Object value) {}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,19 +48,19 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
* Return the tests included in this test suite.
|
* Return the tests included in this test suite.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
Class thisClass = TcclDisabledTestCase.class;
|
final Class thisClass = TcclDisabledTestCase.class;
|
||||||
|
|
||||||
// Determine the URL to this .class file, so that we can then
|
// Determine the URL to this .class file, so that we can then
|
||||||
// append the priority dirs to it. For tidiness, load this
|
// append the priority dirs to it. For tidiness, load this
|
||||||
// class through a dummy loader though this is not absolutely
|
// class through a dummy loader though this is not absolutely
|
||||||
// necessary...
|
// necessary...
|
||||||
PathableClassLoader dummy = new PathableClassLoader(null);
|
final PathableClassLoader dummy = new PathableClassLoader(null);
|
||||||
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
dummy.addLogicalLib("testclasses");
|
dummy.addLogicalLib("testclasses");
|
||||||
dummy.addLogicalLib("commons-logging");
|
dummy.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||||
URL baseUrl = dummy.findResource(thisClassPath);
|
final URL baseUrl = dummy.findResource(thisClassPath);
|
||||||
|
|
||||||
// Now set up the desired classloader hierarchy. Everything goes into
|
// Now set up the desired classloader hierarchy. Everything goes into
|
||||||
// the parent classpath, but we exclude the custom Log class.
|
// the parent classpath, but we exclude the custom Log class.
|
||||||
@@ -68,9 +68,9 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
// We then create a tccl classloader that can see the custom
|
// We then create a tccl classloader that can see the custom
|
||||||
// Log class. Therefore if that class can be found, then the
|
// Log class. Therefore if that class can be found, then the
|
||||||
// TCCL must have been used to load it.
|
// TCCL must have been used to load it.
|
||||||
PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
final PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||||
|
|
||||||
PathableClassLoader parentLoader = new PathableClassLoader(null);
|
final PathableClassLoader parentLoader = new PathableClassLoader(null);
|
||||||
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
parentLoader.addLogicalLib("commons-logging");
|
parentLoader.addLogicalLib("commons-logging");
|
||||||
parentLoader.addLogicalLib("testclasses");
|
parentLoader.addLogicalLib("testclasses");
|
||||||
@@ -78,13 +78,13 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
// the custom MyLog
|
// the custom MyLog
|
||||||
parentLoader.useExplicitLoader(MY_LOG_PKG + ".", emptyLoader);
|
parentLoader.useExplicitLoader(MY_LOG_PKG + ".", emptyLoader);
|
||||||
|
|
||||||
URL propsEnableUrl = new URL(baseUrl, "props_disable_tccl/");
|
final URL propsEnableUrl = new URL(baseUrl, "props_disable_tccl/");
|
||||||
parentLoader.addURL(propsEnableUrl);
|
parentLoader.addURL(propsEnableUrl);
|
||||||
|
|
||||||
PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
|
final PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
|
||||||
tcclLoader.addLogicalLib("testclasses");
|
tcclLoader.addLogicalLib("testclasses");
|
||||||
|
|
||||||
Class testClass = parentLoader.loadClass(thisClass.getName());
|
final Class testClass = parentLoader.loadClass(thisClass.getName());
|
||||||
return new PathableTestSuite(testClass, tcclLoader);
|
return new PathableTestSuite(testClass, tcclLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,26 +109,26 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testLoader() throws Exception {
|
public void testLoader() throws Exception {
|
||||||
|
|
||||||
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
final ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||||
ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
final ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
// the tccl loader should NOT be the same as the loader that loaded this test class.
|
// the tccl loader should NOT be the same as the loader that loaded this test class.
|
||||||
assertNotSame("tccl not same as test classloader", thisClassLoader, tcclLoader);
|
assertNotSame("tccl not same as test classloader", thisClassLoader, tcclLoader);
|
||||||
|
|
||||||
// MyLog should not be loadable via parent loader
|
// MyLog should not be loadable via parent loader
|
||||||
try {
|
try {
|
||||||
Class clazz = thisClassLoader.loadClass(MY_LOG_IMPL);
|
final Class clazz = thisClassLoader.loadClass(MY_LOG_IMPL);
|
||||||
fail("Unexpectedly able to load MyLog via test class classloader");
|
fail("Unexpectedly able to load MyLog via test class classloader");
|
||||||
assertNotNull(clazz); // silence warnings about unused var
|
assertNotNull(clazz); // silence warnings about unused var
|
||||||
} catch(ClassNotFoundException ex) {
|
} catch(final ClassNotFoundException ex) {
|
||||||
// ok, expected
|
// ok, expected
|
||||||
}
|
}
|
||||||
|
|
||||||
// MyLog should be loadable via tccl loader
|
// MyLog should be loadable via tccl loader
|
||||||
try {
|
try {
|
||||||
Class clazz = tcclLoader.loadClass(MY_LOG_IMPL);
|
final Class clazz = tcclLoader.loadClass(MY_LOG_IMPL);
|
||||||
assertNotNull(clazz);
|
assertNotNull(clazz);
|
||||||
} catch(ClassNotFoundException ex) {
|
} catch(final ClassNotFoundException ex) {
|
||||||
fail("Unexpectedly unable to load MyLog via tccl classloader");
|
fail("Unexpectedly unable to load MyLog via tccl classloader");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -140,20 +140,20 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
* we should see the default Log rather than the custom one.
|
* we should see the default Log rather than the custom one.
|
||||||
*/
|
*/
|
||||||
public void testTcclLoading() throws Exception {
|
public void testTcclLoading() throws Exception {
|
||||||
LogFactory instance = LogFactory.getFactory();
|
final LogFactory instance = LogFactory.getFactory();
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Correct LogFactory loaded",
|
"Correct LogFactory loaded",
|
||||||
"org.apache.commons.logging.impl.LogFactoryImpl",
|
"org.apache.commons.logging.impl.LogFactoryImpl",
|
||||||
instance.getClass().getName());
|
instance.getClass().getName());
|
||||||
|
|
||||||
try {
|
try {
|
||||||
Log log = instance.getInstance("test");
|
final Log log = instance.getInstance("test");
|
||||||
fail("Unexpectedly succeeded in loading a custom Log class"
|
fail("Unexpectedly succeeded in loading a custom Log class"
|
||||||
+ " that is only accessable via the tccl.");
|
+ " that is only accessable via the tccl.");
|
||||||
assertNotNull(log); // silence compiler warning about unused var
|
assertNotNull(log); // silence compiler warning about unused var
|
||||||
} catch(LogConfigurationException ex) {
|
} catch(final LogConfigurationException ex) {
|
||||||
// ok, expected
|
// ok, expected
|
||||||
int index = ex.getMessage().indexOf(MY_LOG_IMPL);
|
final int index = ex.getMessage().indexOf(MY_LOG_IMPL);
|
||||||
assertTrue("MyLog not found", index >= 0);
|
assertTrue("MyLog not found", index >= 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,19 +48,19 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
* Return the tests included in this test suite.
|
* Return the tests included in this test suite.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
Class thisClass = TcclEnabledTestCase.class;
|
final Class thisClass = TcclEnabledTestCase.class;
|
||||||
|
|
||||||
// Determine the URL to this .class file, so that we can then
|
// Determine the URL to this .class file, so that we can then
|
||||||
// append the priority dirs to it. For tidiness, load this
|
// append the priority dirs to it. For tidiness, load this
|
||||||
// class through a dummy loader though this is not absolutely
|
// class through a dummy loader though this is not absolutely
|
||||||
// necessary...
|
// necessary...
|
||||||
PathableClassLoader dummy = new PathableClassLoader(null);
|
final PathableClassLoader dummy = new PathableClassLoader(null);
|
||||||
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
dummy.addLogicalLib("testclasses");
|
dummy.addLogicalLib("testclasses");
|
||||||
dummy.addLogicalLib("commons-logging");
|
dummy.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||||
URL baseUrl = dummy.findResource(thisClassPath);
|
final URL baseUrl = dummy.findResource(thisClassPath);
|
||||||
|
|
||||||
// Now set up the desired classloader hierarchy. Everything goes into
|
// Now set up the desired classloader hierarchy. Everything goes into
|
||||||
// the parent classpath, but we exclude the custom Log class.
|
// the parent classpath, but we exclude the custom Log class.
|
||||||
@@ -68,9 +68,9 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
// We then create a tccl classloader that can see the custom
|
// We then create a tccl classloader that can see the custom
|
||||||
// Log class. Therefore if that class can be found, then the
|
// Log class. Therefore if that class can be found, then the
|
||||||
// TCCL must have been used to load it.
|
// TCCL must have been used to load it.
|
||||||
PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
final PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||||
|
|
||||||
PathableClassLoader parentLoader = new PathableClassLoader(null);
|
final PathableClassLoader parentLoader = new PathableClassLoader(null);
|
||||||
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
parentLoader.addLogicalLib("commons-logging");
|
parentLoader.addLogicalLib("commons-logging");
|
||||||
parentLoader.addLogicalLib("testclasses");
|
parentLoader.addLogicalLib("testclasses");
|
||||||
@@ -78,13 +78,13 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
// the custom MyLogFactoryImpl
|
// the custom MyLogFactoryImpl
|
||||||
parentLoader.useExplicitLoader(MY_LOG_PKG + ".", emptyLoader);
|
parentLoader.useExplicitLoader(MY_LOG_PKG + ".", emptyLoader);
|
||||||
|
|
||||||
URL propsEnableUrl = new URL(baseUrl, "props_enable_tccl/");
|
final URL propsEnableUrl = new URL(baseUrl, "props_enable_tccl/");
|
||||||
parentLoader.addURL(propsEnableUrl);
|
parentLoader.addURL(propsEnableUrl);
|
||||||
|
|
||||||
PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
|
final PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
|
||||||
tcclLoader.addLogicalLib("testclasses");
|
tcclLoader.addLogicalLib("testclasses");
|
||||||
|
|
||||||
Class testClass = parentLoader.loadClass(thisClass.getName());
|
final Class testClass = parentLoader.loadClass(thisClass.getName());
|
||||||
return new PathableTestSuite(testClass, tcclLoader);
|
return new PathableTestSuite(testClass, tcclLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -109,26 +109,26 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testLoader() throws Exception {
|
public void testLoader() throws Exception {
|
||||||
|
|
||||||
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
final ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||||
ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
final ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
// the tccl loader should NOT be the same as the loader that loaded this test class.
|
// the tccl loader should NOT be the same as the loader that loaded this test class.
|
||||||
assertNotSame("tccl not same as test classloader", thisClassLoader, tcclLoader);
|
assertNotSame("tccl not same as test classloader", thisClassLoader, tcclLoader);
|
||||||
|
|
||||||
// MyLog should not be loadable via parent loader
|
// MyLog should not be loadable via parent loader
|
||||||
try {
|
try {
|
||||||
Class clazz = thisClassLoader.loadClass(MY_LOG_IMPL);
|
final Class clazz = thisClassLoader.loadClass(MY_LOG_IMPL);
|
||||||
fail("Unexpectedly able to load MyLog via test class classloader");
|
fail("Unexpectedly able to load MyLog via test class classloader");
|
||||||
assertNotNull(clazz); // silence warnings about unused var
|
assertNotNull(clazz); // silence warnings about unused var
|
||||||
} catch(ClassNotFoundException ex) {
|
} catch(final ClassNotFoundException ex) {
|
||||||
// ok, expected
|
// ok, expected
|
||||||
}
|
}
|
||||||
|
|
||||||
// MyLog should be loadable via tccl loader
|
// MyLog should be loadable via tccl loader
|
||||||
try {
|
try {
|
||||||
Class clazz = tcclLoader.loadClass(MY_LOG_IMPL);
|
final Class clazz = tcclLoader.loadClass(MY_LOG_IMPL);
|
||||||
assertNotNull(clazz);
|
assertNotNull(clazz);
|
||||||
} catch(ClassNotFoundException ex) {
|
} catch(final ClassNotFoundException ex) {
|
||||||
fail("Unexpectedly unable to load MyLog via tccl classloader");
|
fail("Unexpectedly unable to load MyLog via tccl classloader");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -139,14 +139,14 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
* This proves that the TCCL was used to load that class.
|
* This proves that the TCCL was used to load that class.
|
||||||
*/
|
*/
|
||||||
public void testTcclLoading() throws Exception {
|
public void testTcclLoading() throws Exception {
|
||||||
LogFactory instance = LogFactory.getFactory();
|
final LogFactory instance = LogFactory.getFactory();
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Correct LogFactory loaded",
|
"Correct LogFactory loaded",
|
||||||
"org.apache.commons.logging.impl.LogFactoryImpl",
|
"org.apache.commons.logging.impl.LogFactoryImpl",
|
||||||
instance.getClass().getName());
|
instance.getClass().getName());
|
||||||
|
|
||||||
Log log = instance.getInstance("test");
|
final Log log = instance.getInstance("test");
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Correct Log loaded",
|
"Correct Log loaded",
|
||||||
MY_LOG_IMPL,
|
MY_LOG_IMPL,
|
||||||
|
|||||||
@@ -48,19 +48,19 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
* Return the tests included in this test suite.
|
* Return the tests included in this test suite.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
Class thisClass = TcclDisabledTestCase.class;
|
final Class thisClass = TcclDisabledTestCase.class;
|
||||||
|
|
||||||
// Determine the URL to this .class file, so that we can then
|
// Determine the URL to this .class file, so that we can then
|
||||||
// append the priority dirs to it. For tidiness, load this
|
// append the priority dirs to it. For tidiness, load this
|
||||||
// class through a dummy loader though this is not absolutely
|
// class through a dummy loader though this is not absolutely
|
||||||
// necessary...
|
// necessary...
|
||||||
PathableClassLoader dummy = new PathableClassLoader(null);
|
final PathableClassLoader dummy = new PathableClassLoader(null);
|
||||||
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
dummy.addLogicalLib("testclasses");
|
dummy.addLogicalLib("testclasses");
|
||||||
dummy.addLogicalLib("commons-logging");
|
dummy.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||||
URL baseUrl = dummy.findResource(thisClassPath);
|
final URL baseUrl = dummy.findResource(thisClassPath);
|
||||||
|
|
||||||
// Now set up the desired classloader hierarchy. Everything goes into
|
// Now set up the desired classloader hierarchy. Everything goes into
|
||||||
// the parent classpath, but we exclude the custom LogFactoryImpl
|
// the parent classpath, but we exclude the custom LogFactoryImpl
|
||||||
@@ -69,9 +69,9 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
// We then create a tccl classloader that can see the custom
|
// We then create a tccl classloader that can see the custom
|
||||||
// LogFactory class. Therefore if that class can be found, then the
|
// LogFactory class. Therefore if that class can be found, then the
|
||||||
// TCCL must have been used to load it.
|
// TCCL must have been used to load it.
|
||||||
PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
final PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||||
|
|
||||||
PathableClassLoader parentLoader = new PathableClassLoader(null);
|
final PathableClassLoader parentLoader = new PathableClassLoader(null);
|
||||||
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
parentLoader.addLogicalLib("commons-logging");
|
parentLoader.addLogicalLib("commons-logging");
|
||||||
parentLoader.addLogicalLib("testclasses");
|
parentLoader.addLogicalLib("testclasses");
|
||||||
@@ -80,13 +80,13 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
parentLoader.useExplicitLoader(
|
parentLoader.useExplicitLoader(
|
||||||
MY_LOG_FACTORY_PKG + ".", emptyLoader);
|
MY_LOG_FACTORY_PKG + ".", emptyLoader);
|
||||||
|
|
||||||
URL propsEnableUrl = new URL(baseUrl, "props_disable_tccl/");
|
final URL propsEnableUrl = new URL(baseUrl, "props_disable_tccl/");
|
||||||
parentLoader.addURL(propsEnableUrl);
|
parentLoader.addURL(propsEnableUrl);
|
||||||
|
|
||||||
PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
|
final PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
|
||||||
tcclLoader.addLogicalLib("testclasses");
|
tcclLoader.addLogicalLib("testclasses");
|
||||||
|
|
||||||
Class testClass = parentLoader.loadClass(thisClass.getName());
|
final Class testClass = parentLoader.loadClass(thisClass.getName());
|
||||||
return new PathableTestSuite(testClass, tcclLoader);
|
return new PathableTestSuite(testClass, tcclLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -111,26 +111,26 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testLoader() throws Exception {
|
public void testLoader() throws Exception {
|
||||||
|
|
||||||
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
final ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||||
ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
final ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
// the tccl loader should NOT be the same as the loader that loaded this test class.
|
// the tccl loader should NOT be the same as the loader that loaded this test class.
|
||||||
assertNotSame("tccl not same as test classloader", thisClassLoader, tcclLoader);
|
assertNotSame("tccl not same as test classloader", thisClassLoader, tcclLoader);
|
||||||
|
|
||||||
// MyLogFactoryImpl should not be loadable via parent loader
|
// MyLogFactoryImpl should not be loadable via parent loader
|
||||||
try {
|
try {
|
||||||
Class clazz = thisClassLoader.loadClass(MY_LOG_FACTORY_IMPL);
|
final Class clazz = thisClassLoader.loadClass(MY_LOG_FACTORY_IMPL);
|
||||||
fail("Unexpectedly able to load MyLogFactoryImpl via test class classloader");
|
fail("Unexpectedly able to load MyLogFactoryImpl via test class classloader");
|
||||||
assertNotNull(clazz); // silence warning about unused var
|
assertNotNull(clazz); // silence warning about unused var
|
||||||
} catch(ClassNotFoundException ex) {
|
} catch(final ClassNotFoundException ex) {
|
||||||
// ok, expected
|
// ok, expected
|
||||||
}
|
}
|
||||||
|
|
||||||
// MyLogFactoryImpl should be loadable via tccl loader
|
// MyLogFactoryImpl should be loadable via tccl loader
|
||||||
try {
|
try {
|
||||||
Class clazz = tcclLoader.loadClass(MY_LOG_FACTORY_IMPL);
|
final Class clazz = tcclLoader.loadClass(MY_LOG_FACTORY_IMPL);
|
||||||
assertNotNull(clazz);
|
assertNotNull(clazz);
|
||||||
} catch(ClassNotFoundException ex) {
|
} catch(final ClassNotFoundException ex) {
|
||||||
fail("Unexpectedly unable to load MyLogFactoryImpl via tccl classloader");
|
fail("Unexpectedly unable to load MyLogFactoryImpl via tccl classloader");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -143,13 +143,13 @@ public class TcclDisabledTestCase extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testTcclLoading() throws Exception {
|
public void testTcclLoading() throws Exception {
|
||||||
try {
|
try {
|
||||||
LogFactory instance = LogFactory.getFactory();
|
final LogFactory instance = LogFactory.getFactory();
|
||||||
fail("Unexpectedly succeeded in loading custom factory, though TCCL disabled.");
|
fail("Unexpectedly succeeded in loading custom factory, though TCCL disabled.");
|
||||||
assertNotNull(instance); // silence warning about unused var
|
assertNotNull(instance); // silence warning about unused var
|
||||||
} catch(org.apache.commons.logging.LogConfigurationException ex) {
|
} catch(final org.apache.commons.logging.LogConfigurationException ex) {
|
||||||
// ok, custom MyLogFactoryImpl as specified in props_disable_tccl
|
// ok, custom MyLogFactoryImpl as specified in props_disable_tccl
|
||||||
// could not be found.
|
// could not be found.
|
||||||
int index = ex.getMessage().indexOf(MY_LOG_FACTORY_IMPL);
|
final int index = ex.getMessage().indexOf(MY_LOG_FACTORY_IMPL);
|
||||||
assertTrue("MylogFactoryImpl not found", index >= 0);
|
assertTrue("MylogFactoryImpl not found", index >= 0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -42,19 +42,19 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
* Return the tests included in this test suite.
|
* Return the tests included in this test suite.
|
||||||
*/
|
*/
|
||||||
public static Test suite() throws Exception {
|
public static Test suite() throws Exception {
|
||||||
Class thisClass = TcclEnabledTestCase.class;
|
final Class thisClass = TcclEnabledTestCase.class;
|
||||||
|
|
||||||
// Determine the URL to this .class file, so that we can then
|
// Determine the URL to this .class file, so that we can then
|
||||||
// append the priority dirs to it. For tidiness, load this
|
// append the priority dirs to it. For tidiness, load this
|
||||||
// class through a dummy loader though this is not absolutely
|
// class through a dummy loader though this is not absolutely
|
||||||
// necessary...
|
// necessary...
|
||||||
PathableClassLoader dummy = new PathableClassLoader(null);
|
final PathableClassLoader dummy = new PathableClassLoader(null);
|
||||||
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
dummy.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
dummy.addLogicalLib("testclasses");
|
dummy.addLogicalLib("testclasses");
|
||||||
dummy.addLogicalLib("commons-logging");
|
dummy.addLogicalLib("commons-logging");
|
||||||
|
|
||||||
String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
final String thisClassPath = thisClass.getName().replace('.', '/') + ".class";
|
||||||
URL baseUrl = dummy.findResource(thisClassPath);
|
final URL baseUrl = dummy.findResource(thisClassPath);
|
||||||
|
|
||||||
// Now set up the desired classloader hierarchy. Everything goes into
|
// Now set up the desired classloader hierarchy. Everything goes into
|
||||||
// the parent classpath, but we exclude the custom LogFactoryImpl
|
// the parent classpath, but we exclude the custom LogFactoryImpl
|
||||||
@@ -63,9 +63,9 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
// We then create a tccl classloader that can see the custom
|
// We then create a tccl classloader that can see the custom
|
||||||
// LogFactory class. Therefore if that class can be found, then the
|
// LogFactory class. Therefore if that class can be found, then the
|
||||||
// TCCL must have been used to load it.
|
// TCCL must have been used to load it.
|
||||||
PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
final PathableClassLoader emptyLoader = new PathableClassLoader(null);
|
||||||
|
|
||||||
PathableClassLoader parentLoader = new PathableClassLoader(null);
|
final PathableClassLoader parentLoader = new PathableClassLoader(null);
|
||||||
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
parentLoader.useExplicitLoader("junit.", Test.class.getClassLoader());
|
||||||
parentLoader.addLogicalLib("commons-logging");
|
parentLoader.addLogicalLib("commons-logging");
|
||||||
parentLoader.addLogicalLib("testclasses");
|
parentLoader.addLogicalLib("testclasses");
|
||||||
@@ -74,13 +74,13 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
parentLoader.useExplicitLoader(
|
parentLoader.useExplicitLoader(
|
||||||
"org.apache.commons.logging.tccl.custom.", emptyLoader);
|
"org.apache.commons.logging.tccl.custom.", emptyLoader);
|
||||||
|
|
||||||
URL propsEnableUrl = new URL(baseUrl, "props_enable_tccl/");
|
final URL propsEnableUrl = new URL(baseUrl, "props_enable_tccl/");
|
||||||
parentLoader.addURL(propsEnableUrl);
|
parentLoader.addURL(propsEnableUrl);
|
||||||
|
|
||||||
PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
|
final PathableClassLoader tcclLoader = new PathableClassLoader(parentLoader);
|
||||||
tcclLoader.addLogicalLib("testclasses");
|
tcclLoader.addLogicalLib("testclasses");
|
||||||
|
|
||||||
Class testClass = parentLoader.loadClass(thisClass.getName());
|
final Class testClass = parentLoader.loadClass(thisClass.getName());
|
||||||
return new PathableTestSuite(testClass, tcclLoader);
|
return new PathableTestSuite(testClass, tcclLoader);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -105,28 +105,28 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
*/
|
*/
|
||||||
public void testLoader() throws Exception {
|
public void testLoader() throws Exception {
|
||||||
|
|
||||||
ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
final ClassLoader thisClassLoader = this.getClass().getClassLoader();
|
||||||
ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
final ClassLoader tcclLoader = Thread.currentThread().getContextClassLoader();
|
||||||
|
|
||||||
// the tccl loader should NOT be the same as the loader that loaded this test class.
|
// the tccl loader should NOT be the same as the loader that loaded this test class.
|
||||||
assertNotSame("tccl not same as test classloader", thisClassLoader, tcclLoader);
|
assertNotSame("tccl not same as test classloader", thisClassLoader, tcclLoader);
|
||||||
|
|
||||||
// MyLogFactoryImpl should not be loadable via parent loader
|
// MyLogFactoryImpl should not be loadable via parent loader
|
||||||
try {
|
try {
|
||||||
Class clazz = thisClassLoader.loadClass(
|
final Class clazz = thisClassLoader.loadClass(
|
||||||
"org.apache.commons.logging.tccl.custom.MyLogFactoryImpl");
|
"org.apache.commons.logging.tccl.custom.MyLogFactoryImpl");
|
||||||
fail("Unexpectedly able to load MyLogFactoryImpl via test class classloader");
|
fail("Unexpectedly able to load MyLogFactoryImpl via test class classloader");
|
||||||
assertNotNull(clazz); // silence warning about unused var
|
assertNotNull(clazz); // silence warning about unused var
|
||||||
} catch(ClassNotFoundException ex) {
|
} catch(final ClassNotFoundException ex) {
|
||||||
// ok, expected
|
// ok, expected
|
||||||
}
|
}
|
||||||
|
|
||||||
// MyLogFactoryImpl should be loadable via tccl loader
|
// MyLogFactoryImpl should be loadable via tccl loader
|
||||||
try {
|
try {
|
||||||
Class clazz = tcclLoader.loadClass(
|
final Class clazz = tcclLoader.loadClass(
|
||||||
"org.apache.commons.logging.tccl.custom.MyLogFactoryImpl");
|
"org.apache.commons.logging.tccl.custom.MyLogFactoryImpl");
|
||||||
assertNotNull(clazz);
|
assertNotNull(clazz);
|
||||||
} catch(ClassNotFoundException ex) {
|
} catch(final ClassNotFoundException ex) {
|
||||||
fail("Unexpectedly unable to load MyLogFactoryImpl via tccl classloader");
|
fail("Unexpectedly unable to load MyLogFactoryImpl via tccl classloader");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -137,7 +137,7 @@ public class TcclEnabledTestCase extends TestCase {
|
|||||||
* This proves that the TCCL was used to load that class.
|
* This proves that the TCCL was used to load that class.
|
||||||
*/
|
*/
|
||||||
public void testTcclLoading() throws Exception {
|
public void testTcclLoading() throws Exception {
|
||||||
LogFactory instance = LogFactory.getFactory();
|
final LogFactory instance = LogFactory.getFactory();
|
||||||
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"Correct LogFactory loaded",
|
"Correct LogFactory loaded",
|
||||||
|
|||||||
Reference in New Issue
Block a user