diff --git a/build.xml b/build.xml
index c7f5cd3..1fa6ec7 100644
--- a/build.xml
+++ b/build.xml
@@ -108,7 +108,6 @@
Implementation of Log that maps directly to a Log4J
- * Category. Initial configuration of the corresponding
- * Category instances should be done in the usual manner, as outlined in
- * the Log4J documentation.
Log4JLogger instead.
- *
- * @author Scott Sanders
- * @author Rod Waldhoff
- * @author Robert Burrell Donkin
- * @version $Id$
- */
-public final class Log4JCategoryLog implements Log {
-
-
- // ------------------------------------------------------------- Attributes
-
- /** The fully qualified name of the Log4JCategoryLog class. */
- private static final String FQCN = Log4JCategoryLog.class.getName();
-
- /** Log to this category */
- private Category category = null;
-
-
- // ------------------------------------------------------------ Constructor
-
- public Log4JCategoryLog() {
- }
-
-
- /**
- * Base constructor.
- */
- public Log4JCategoryLog(String name) {
- this.category=Category.getInstance(name);
- }
-
- /** For use with a log4j factory.
- */
- public Log4JCategoryLog(Category category ) {
- this.category=category;
- }
-
-
- // ---------------------------------------------------------- Implmentation
-
-
- /**
- * Log a message to the Log4j Category with TRACE priority.
- * Currently logs to DEBUG level in Log4J.
- */
- public void trace(Object message) {
- category.log(FQCN, Priority.DEBUG, message, null);
- }
-
-
- /**
- * Log an error to the Log4j Category with TRACE priority.
- * Currently logs to DEBUG level in Log4J.
- */
- public void trace(Object message, Throwable t) {
- category.log(FQCN, Priority.DEBUG, message, t );
- }
-
-
- /**
- * Log a message to the Log4j Category with DEBUG priority.
- */
- public void debug(Object message) {
- category.log(FQCN, Priority.DEBUG, message, null);
- }
-
- /**
- * Log an error to the Log4j Category with DEBUG priority.
- */
- public void debug(Object message, Throwable t) {
- category.log(FQCN, Priority.DEBUG, message, t );
- }
-
-
- /**
- * Log a message to the Log4j Category with INFO priority.
- */
- public void info(Object message) {
- category.log(FQCN, Priority.INFO, message, null );
- }
-
-
- /**
- * Log an error to the Log4j Category with INFO priority.
- */
- public void info(Object message, Throwable t) {
- category.log(FQCN, Priority.INFO, message, t );
- }
-
-
- /**
- * Log a message to the Log4j Category with WARN priority.
- */
- public void warn(Object message) {
- category.log(FQCN, Priority.WARN, message, null );
- }
-
-
- /**
- * Log an error to the Log4j Category with WARN priority.
- */
- public void warn(Object message, Throwable t) {
- category.log(FQCN, Priority.WARN, message, t );
- }
-
-
- /**
- * Log a message to the Log4j Category with ERROR priority.
- */
- public void error(Object message) {
- category.log(FQCN, Priority.ERROR, message, null );
- }
-
-
- /**
- * Log an error to the Log4j Category with ERROR priority.
- */
- public void error(Object message, Throwable t) {
- category.log(FQCN, Priority.ERROR, message, t );
- }
-
-
- /**
- * Log a message to the Log4j Category with FATAL priority.
- */
- public void fatal(Object message) {
- category.log(FQCN, Priority.FATAL, message, null );
- }
-
-
- /**
- * Log an error to the Log4j Category with FATAL priority.
- */
- public void fatal(Object message, Throwable t) {
- category.log(FQCN, Priority.FATAL, message, t );
- }
-
-
- /**
- * Return the native Category instance we are using.
- */
- public Category getCategory() {
- return (this.category);
- }
-
-
- /**
- * Check whether the Log4j Category used is enabled for DEBUG priority.
- */
- public boolean isDebugEnabled() {
- return category.isDebugEnabled();
- }
-
-
- /**
- * Check whether the Log4j Category used is enabled for ERROR priority.
- */
- public boolean isErrorEnabled() {
- return category.isEnabledFor(Priority.ERROR);
- }
-
-
- /**
- * Check whether the Log4j Category used is enabled for FATAL priority.
- */
- public boolean isFatalEnabled() {
- return category.isEnabledFor(Priority.FATAL);
- }
-
-
- /**
- * Check whether the Log4j Category used is enabled for INFO priority.
- */
- public boolean isInfoEnabled() {
- return category.isInfoEnabled();
- }
-
-
- /**
- * Check whether the Log4j Category used is enabled for TRACE priority.
- * For Log4J, this returns the value of isDebugEnabled()
- */
- public boolean isTraceEnabled() {
- return category.isDebugEnabled();
- }
-
- /**
- * Check whether the Log4j Category used is enabled for WARN priority.
- */
- public boolean isWarnEnabled() {
- return category.isEnabledFor(Priority.WARN);
- }
-}
diff --git a/optional/src/java/org/apache/commons/logging/impl/MemoryLog.java b/optional/src/java/org/apache/commons/logging/impl/MemoryLog.java
deleted file mode 100644
index c24ff3b..0000000
--- a/optional/src/java/org/apache/commons/logging/impl/MemoryLog.java
+++ /dev/null
@@ -1,432 +0,0 @@
-/*
- * Copyright 2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package org.apache.commons.logging.impl;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Date;
-import java.util.List;
-
-import org.apache.commons.logging.Log;
-
-/**
- * Memory implementation of Log that keeps all log message as - * entries in memory. The class is designed to be used in unit tests. - * The default log level is TRACE.
- *The code borrows heavily from the SimpleLog class.
- * @author Jörg Schaible - * @version $Id$ - */ -public class MemoryLog implements Log { - - // ------------------------------------------------------- Class Attributes - - /** - * A class for a log entry. - */ - public static class Entry { - - private final Date date; - private final String name; - private final int level; - private final Object message; - private final Throwable throwable; - - /** - * Construct a log entry. - * @param name the logger's name - * @param level the log level - * @param message the message to log - * @param t the throwable attending the log - */ - private Entry(String name, int level, Object message, Throwable t) { - this.date = new Date(); - this.name = name; - this.level = level; - this.message = message; - this.throwable = t; - } - - /** - * @return Returns the logging date. - */ - public Date getDate() { - return date; - } - - /** - * @return Returns the logger's name. - */ - public String getLogName() { - return name; - } - - /** - * @return Returns the log message. - */ - public Object getMessage() { - return message; - } - /** - * @return Returns the attendent {@link java.lang.Throwable} of the log or null. - */ - public Throwable getThrowable() { - return throwable; - } - - /** - * @return Returns the log level. - */ - public int getLevel() { - return level; - } - } - - /** The list with all log entries. */ - private static final List logEntries = Collections.synchronizedList(new ArrayList()); - - - // ---------------------------------------------------- Log Level Constants - - /** "Trace" level logging. */ - public static final int LOG_LEVEL_TRACE = 1; - /** "Debug" level logging. */ - public static final int LOG_LEVEL_DEBUG = 2; - /** "Info" level logging. */ - public static final int LOG_LEVEL_INFO = 3; - /** "Warn" level logging. */ - public static final int LOG_LEVEL_WARN = 4; - /** "Error" level logging. */ - public static final int LOG_LEVEL_ERROR = 5; - /** "Fatal" level logging. */ - public static final int LOG_LEVEL_FATAL = 6; - - /** Enable all logging levels */ - public static final int LOG_LEVEL_ALL = (LOG_LEVEL_TRACE - 1); - - /** Enable no logging levels */ - public static final int LOG_LEVEL_OFF = (LOG_LEVEL_FATAL + 1); - - - // ------------------------------------------------------------- Attributes - - /** The name of this simple log instance */ - protected String logName = null; - /** The current log level */ - protected int currentLogLevel; - - - // ------------------------------------------------------------ Constructor - - /** - * Construct a simple log with given name. - * - * @param name log name - */ - public MemoryLog(String name) { - - logName = name; - - // Set initial log level - setLevel(MemoryLog.LOG_LEVEL_TRACE); - } - - - // -------------------------------------------------------- Properties - - /** - *Set logging level.
- * - * @param currentLogLevel new logging level - */ - public void setLevel(int currentLogLevel) { - - this.currentLogLevel = currentLogLevel; - - } - - - /** - * @return Returns the logging level. - */ - public int getLevel() { - - return currentLogLevel; - } - - - // -------------------------------------------------------- Logging Methods - - - /** - * Do the actual logging.
- * This method assembles the message
- * and then calls write() to cause it to be written.
Log a message with debug log level.
- */ - public final void debug(Object message) { - - if (isLevelEnabled(MemoryLog.LOG_LEVEL_DEBUG)) { - log(MemoryLog.LOG_LEVEL_DEBUG, message, null); - } - } - - - /** - *Log an error with debug log level.
- */ - public final void debug(Object message, Throwable t) { - - if (isLevelEnabled(MemoryLog.LOG_LEVEL_DEBUG)) { - log(MemoryLog.LOG_LEVEL_DEBUG, message, t); - } - } - - - /** - *Log a message with trace log level.
- */ - public final void trace(Object message) { - - if (isLevelEnabled(MemoryLog.LOG_LEVEL_TRACE)) { - log(MemoryLog.LOG_LEVEL_TRACE, message, null); - } - } - - - /** - *Log an error with trace log level.
- */ - public final void trace(Object message, Throwable t) { - - if (isLevelEnabled(MemoryLog.LOG_LEVEL_TRACE)) { - log(MemoryLog.LOG_LEVEL_TRACE, message, t); - } - } - - - /** - *Log a message with info log level.
- */ - public final void info(Object message) { - - if (isLevelEnabled(MemoryLog.LOG_LEVEL_INFO)) { - log(MemoryLog.LOG_LEVEL_INFO,message,null); - } - } - - - /** - *Log an error with info log level.
- */ - public final void info(Object message, Throwable t) { - - if (isLevelEnabled(MemoryLog.LOG_LEVEL_INFO)) { - log(MemoryLog.LOG_LEVEL_INFO, message, t); - } - } - - - /** - *Log a message with warn log level.
- */ - public final void warn(Object message) { - - if (isLevelEnabled(MemoryLog.LOG_LEVEL_WARN)) { - log(MemoryLog.LOG_LEVEL_WARN, message, null); - } - } - - - /** - *Log an error with warn log level.
- */ - public final void warn(Object message, Throwable t) { - - if (isLevelEnabled(MemoryLog.LOG_LEVEL_WARN)) { - log(MemoryLog.LOG_LEVEL_WARN, message, t); - } - } - - - /** - *Log a message with error log level.
- */ - public final void error(Object message) { - - if (isLevelEnabled(MemoryLog.LOG_LEVEL_ERROR)) { - log(MemoryLog.LOG_LEVEL_ERROR, message, null); - } - } - - - /** - *Log an error with error log level.
- */ - public final void error(Object message, Throwable t) { - - if (isLevelEnabled(MemoryLog.LOG_LEVEL_ERROR)) { - log(MemoryLog.LOG_LEVEL_ERROR, message, t); - } - } - - - /** - *Log a message with fatal log level.
- */ - public final void fatal(Object message) { - - if (isLevelEnabled(MemoryLog.LOG_LEVEL_FATAL)) { - log(MemoryLog.LOG_LEVEL_FATAL, message, null); - } - } - - - /** - *Log an error with fatal log level.
- */ - public final void fatal(Object message, Throwable t) { - - if (isLevelEnabled(MemoryLog.LOG_LEVEL_FATAL)) { - log(MemoryLog.LOG_LEVEL_FATAL, message, t); - } - } - - - /** - *Are debug messages currently enabled?
- * - * This allows expensive operations such as String
- * concatenation to be avoided when the message will be ignored by the
- * logger.
Are error messages currently enabled?
- * - * This allows expensive operations such as String
- * concatenation to be avoided when the message will be ignored by the
- * logger.
Are fatal messages currently enabled?
- * - * This allows expensive operations such as String
- * concatenation to be avoided when the message will be ignored by the
- * logger.
Are info messages currently enabled?
- * - * This allows expensive operations such as String
- * concatenation to be avoided when the message will be ignored by the
- * logger.
Are trace messages currently enabled?
- * - * This allows expensive operations such as String
- * concatenation to be avoided when the message will be ignored by the
- * logger.
Are warn messages currently enabled?
- * - * This allows expensive operations such as String
- * concatenation to be avoided when the message will be ignored by the
- * logger.
Implementation of Hashtable that uses WeakReference's
- * to hold its keys thus allowing them to be reclaimed by the garbage collector.
- * The associated values are retained using strong references.
This class follows the symantics of Hashtable as closely as
- * possible. It therefore does not accept null values or keys.
Note:
- * This is not intended to be a general purpose hash table replacement.
- * This implementation is also tuned towards a particular purpose: for use as a replacement
- * for Hashtable in LogFactory. This application requires
- * good liveliness for get and put. Various tradeoffs
- * have been made with this in mind.
- *
- * Usage: typical use case is as a drop-in replacement
- * for the Hashtable used in LogFactory for J2EE enviroments
- * running 1.3+ JVMs. Use of this class in most cases (see below) will
- * allow classloaders to be collected by the garbage collector without the need
- * to call {@link org.apache.commons.logging.LogFactory#release(ClassLoader) LogFactory.release(ClassLoader)}.
- *
org.apache.commons.logging.LogFactory looks to see whether this
- * class is present in the classpath, and if so then uses it to store
- * references to the LogFactory implementationd it loads
- * (rather than using a standard Hashtable instance).
- * Having this class used instead of Hashtable solves
- * certain issues related to dynamic reloading of applications in J2EE-style
- * environments. However this class requires java 1.3 or later (due to its use
- * of java.lang.ref.WeakReference and associates) and therefore cannot be
- * included in the main logging distribution which supports JVMs prior to 1.3.
- * And by the way, this extends Hashtable rather than HashMap
- * for backwards compatibility reasons. See the documentation
- * for method LogFactory.createFactoryStore for more details.
The reason all this is necessary is due to a issue which
- * arises during hot deploy in a J2EE-like containers.
- * Each component running in the container owns one or more classloaders; when
- * the component loads a LogFactory instance via the component classloader
- * a reference to it gets stored in the static LogFactory.factories member,
- * keyed by the component's classloader so different components don't
- * stomp on each other. When the component is later unloaded, the container
- * sets the component's classloader to null with the intent that all the
- * component's classes get garbage-collected. However there's still a
- * reference to the component's classloader from the "global" LogFactory's
- * factories member! If LogFactory.release() is called whenever component
- * is unloaded (as happens in some famous containers), the classloaders will be correctly
- * garbage collected.
- * However, holding the classloader references weakly ensures that the classloader
- * will be garbage collected without programmatic intervention.
- * Unfortunately, weak references are
- * only available in java 1.3+, so this code only uses WeakHashtable if the
- * class has explicitly been made available on the classpath.
- * Because the presence of this class in the classpath ensures proper - * unload of components without the need to call method - * {@link org.apache.commons.logging.LogFactory#release(ClassLoader) LogFactory.release ClassLoader)}, - * it is recommended that this class be deployed along with the standard - * commons-logging.jar file when using commons-logging in J2EE - * environments (which will presumably be running on Java 1.3 or later). - * There are no know ill effects from using this class.
- * - *- * Limitations: - * There is still one (unusual) scenario in which a component will not - * be correctly unloaded without an explicit release. Though weak references - * are used for its keys, it is necessary to use - * strong references for its values.
- * - * If the abstract class LogFactory is
- * loaded by the container classloader but a subclass of
- * LogFactory [LogFactory1] is loaded by the component's
- * classloader and an instance stored in the static map associated with the
- * base LogFactory class, then there is a strong reference from the LogFactory
- * class to the LogFactory1 instance (as normal) and a strong reference from
- * the LogFactory1 instance to the component classloader via
- * getClass().getClassLoader(). This chain of references will prevent
- * collection of the child classloader.
- * Such a situation occurs when the commons-logging.jar is
- * loaded by a parent classloader (e.g. a server level classloader in a
- * servlet container) and a custom LogFactory implementation is
- * loaded by a child classloader (e.g. a web app classloader).
To avoid this scenario, ensure
- * that any custom LogFactory subclass is loaded by the same classloader as
- * the base LogFactory. Creating custom LogFactory subclasses is,
- * however, rare. The standard LogFactoryImpl class should be sufficient
- * for most or all users.
null
- */
- private Referenced(Object referant) {
- reference = new WeakReference(referant);
- // Calc a permanent hashCode so calls to Hashtable.remove()
- // work if the WeakReference has been cleared
- hashCode = referant.hashCode();
- }
-
- /**
- *
- * @throws NullPointerException if key is null
- */
- private Referenced(Object key, ReferenceQueue queue) {
- reference = new WeakKey(key, queue, this);
- // Calc a permanent hashCode so calls to Hashtable.remove()
- // work if the WeakReference has been cleared
- hashCode = key.hashCode();
-
- }
-
- public int hashCode() {
- return hashCode;
- }
-
- private Object getValue() {
- return reference.get();
- }
-
- public boolean equals(Object o) {
- boolean result = false;
- if (o instanceof Referenced) {
- Referenced otherKey = (Referenced) o;
- Object thisKeyValue = getValue();
- Object otherKeyValue = otherKey.getValue();
- if (thisKeyValue == null) {
- result = (otherKeyValue == null);
-
- // Since our hashcode was calculated from the original
- // non-null referant, the above check breaks the
- // hashcode/equals contract, as two cleared Referenced
- // objects could test equal but have different hashcodes.
- // We can reduce (not eliminate) the chance of this
- // happening by comparing hashcodes.
- if (result == true) {
- result = (this.hashCode() == otherKey.hashCode());
- }
- // In any case, as our c'tor does not allow null referants
- // and Hashtable does not do equality checks between
- // existing keys, normal hashtable operations should never
- // result in an equals comparison between null referants
- }
- else
- {
- result = thisKeyValue.equals(otherKeyValue);
- }
- }
- return result;
- }
- }
-
- /**
- * WeakReference subclass that holds a hard reference to an
- * associated value and also makes accessible
- * the Referenced object holding it.
- */
- private final static class WeakKey extends WeakReference {
-
- private final Referenced referenced;
-
- private WeakKey(Object key,
- ReferenceQueue queue,
- Referenced referenced) {
- super(key, queue);
- this.referenced = referenced;
- }
-
- private Referenced getReferenced() {
- return referenced;
- }
- }
-}
diff --git a/optional/src/java/overview.html b/optional/src/java/overview.html
deleted file mode 100644
index 484f8ee..0000000
--- a/optional/src/java/overview.html
+++ /dev/null
@@ -1,33 +0,0 @@
-
-
-
-
-Contains optional additions to JCL.
- -Contained are classes which are not considered appropriate -to distribute as part of JCL main distribution. -Some classes are JVM dependent. -Others are targetted at uncommon use cases. -Utility code is also appropriate. -
- - diff --git a/optional/src/test/org/apache/commons/logging/IFactoryCreator.java b/optional/src/test/org/apache/commons/logging/IFactoryCreator.java deleted file mode 100644 index 5ed3ae8..0000000 --- a/optional/src/test/org/apache/commons/logging/IFactoryCreator.java +++ /dev/null @@ -1,36 +0,0 @@ -/* - * Copyright 2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.commons.logging; - -import java.lang.ref.WeakReference; - - - -/** - * Interface implemented by SubDeploymentClass. The LogFactoryTest's - * IsolatedClassLoader will delegate loading of this interface to the - * test runner's classloader, so the test can interact with - * SubDeploymentClass via this interface. - * - * @author bstansberry - * - * @see LogFactoryTest - */ -public interface IFactoryCreator { - - WeakReference getWeakFactory(); - -} diff --git a/optional/src/test/org/apache/commons/logging/LogFactoryTest.java b/optional/src/test/org/apache/commons/logging/LogFactoryTest.java deleted file mode 100644 index 67c9e85..0000000 --- a/optional/src/test/org/apache/commons/logging/LogFactoryTest.java +++ /dev/null @@ -1,260 +0,0 @@ -/* - * Copyright 2004 The Apache Software Foundation. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - - -package org.apache.commons.logging; - -import java.io.ByteArrayOutputStream; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; -import java.lang.ref.WeakReference; - -import junit.framework.TestCase; - -import org.apache.commons.logging.impl.LogFactoryImpl; -import org.apache.commons.logging.impl.WeakHashtable; - -public class LogFactoryTest extends TestCase { - - - /** Maximum number of iterations before our test fails */ - private static final int MAX_GC_ITERATIONS = 50; - - private ClassLoader origLoader = null; - private String origFactoryProperty = null; - - public LogFactoryTest(String testName) { - super(testName); - } - - public void testLogFactoryType() { - assertTrue(LogFactory.factories instanceof WeakHashtable); - } - - /** - * Tests that LogFactories are not removed from the map - * if their creating ClassLoader is still alive. - */ - public void testHoldFactories() throws Exception - { - // 1) Basic test - - // Get a weak reference to the factory using the classloader. - // When this reference is cleared we know the factory has been - // cleared from LogFactory.factories as well - WeakReference weakFactory = loadFactoryFromContextClassLoader(); - // Run the gc, confirming that the factory - // is not dropped from the map even though there are - // no other references to it - checkRelease(weakFactory, true); - - // 2) Test using an isolated classloader a la a web app - - // Create a classloader that isolates commons-logging - ClassLoader childLoader = new IsolatedClassLoader(origLoader); - Thread.currentThread().setContextClassLoader(childLoader); - weakFactory = loadFactoryFromContextClassLoader(); - Thread.currentThread().setContextClassLoader(origLoader); - // At this point we still have a reference to childLoader, - // so the factory should not be cleared - - checkRelease(weakFactory, true); - } - - /** - * Tests that a ClassLoader is eventually removed from the map - * after all hard references to it are removed. - */ - public void testReleaseClassLoader() throws Exception - { - // 1) Test of a child classloader that follows the Java2 - // delegation model (e.g. an EJB module classloader) - - // Create a classloader that delegates to its parent - ClassLoader childLoader = new ClassLoader() {}; - // Get a weak reference to the factory using the classloader. - // When this reference is cleared we know the factory has been - // cleared from LogFactory.factories as well - Thread.currentThread().setContextClassLoader(childLoader); - loadFactoryFromContextClassLoader(); - Thread.currentThread().setContextClassLoader(origLoader); - - // Get a WeakReference to the child loader so we know when it - // has been gc'ed - WeakReference weakLoader = new WeakReference(childLoader); - // Remove any hard reference to the childLoader or the factory creator - childLoader = null; - - // Run the gc, confirming that childLoader is dropped from the map - checkRelease(weakLoader, false); - - // 2) Test using an isolated classloader a la a web app - - childLoader = new IsolatedClassLoader(origLoader); - Thread.currentThread().setContextClassLoader(childLoader); - loadFactoryFromContextClassLoader(); - Thread.currentThread().setContextClassLoader(origLoader); - weakLoader = new WeakReference(childLoader); - childLoader = null; // somewhat equivalent to undeploying a webapp - - checkRelease(weakLoader, false); - - } - - /** - * Repeatedly run the gc, checking whether the given WeakReference - * is not cleared and failing or succeeding based on - * parameterfailOnRelease.
- */
- private void checkRelease(WeakReference reference, boolean failOnRelease) {
-
- int iterations = 0;
- int bytz = 2;
- while(true) {
- System.gc();
- if(iterations++ > MAX_GC_ITERATIONS){
- if (failOnRelease) {
- break;
- }
- fail("Max iterations reached before reference released.");
- }
-
- if(reference.get() == null) {
- if (failOnRelease) {
- fail("reference released");
- }
- else {
- break;
- }
- } else {
- // create garbage:
- byte[] b;
- try {
- b = new byte[bytz];
- bytz = bytz * 2;
- }
- catch (OutOfMemoryError oom) {
- // Doing this is probably a no-no, but it seems to work ;-)
- b = null;
- System.gc();
- if (failOnRelease) {
- break;
- }
- fail("OutOfMemory before reference released.");
- }
- }
- }
- }
-
- protected void setUp() throws Exception {
- // Preserve the original classloader and factory implementation
- // class so we can restore them when we are done
- origLoader = Thread.currentThread().getContextClassLoader();
- origFactoryProperty = System.getProperty(LogFactory.FACTORY_PROPERTY);
-
- // Ensure we use LogFactoryImpl as our factory
- System.setProperty(LogFactory.FACTORY_PROPERTY,
- LogFactoryImpl.class.getName());
-
- super.setUp();
- }
-
- protected void tearDown() throws Exception {
- // Set the classloader back to whatever it originally was
- Thread.currentThread().setContextClassLoader(origLoader);
-
- // Set the factory implementation class back to
- // whatever it originally was
- if (origFactoryProperty != null) {
- System.setProperty(LogFactory.FACTORY_PROPERTY,
- origFactoryProperty);
- }
- else {
- System.getProperties().remove(LogFactory.FACTORY_PROPERTY);
- }
-
- super.tearDown();
- }
-
- private static WeakReference loadFactoryFromContextClassLoader()
- throws Exception {
- ClassLoader loader = Thread.currentThread().getContextClassLoader();
- Class clazz = loader.loadClass(SubDeploymentClass.class.getName());
- IFactoryCreator creator = (IFactoryCreator) clazz.newInstance();
- return creator.getWeakFactory();
- }
-
- /**
- * A ClassLoader that mimics the operation of a web app classloader
- * by not delegating some calls to its parent.
- *
- * In this case it does not delegate loading commons-logging classes,
- * acting as if commons-logging were in WEB-INF/lib. However, it does
- * delegate loading of IFactoryCreator, thus allowing this class to
- * interact with SubDeploymentClass via IFactoryCreator.
- */
- private static final class IsolatedClassLoader extends ClassLoader {
-
- private IsolatedClassLoader(ClassLoader parent) {
- super(parent);
- }
-
- protected synchronized Class loadClass(String name, boolean resolve)
- throws ClassNotFoundException
- {
- if (name != null && name.startsWith("org.apache.commons.logging")
- && "org.apache.commons.logging.IFactoryCreator".equals(name) == false) {
- // First, check if the class has already been loaded
- Class c = findClass(name);
-
- if (resolve) {
- resolveClass(c);
- }
- return c;
- }
- else {
- return super.loadClass(name, resolve);
- }
- }
-
- protected Class findClass(String name) throws ClassNotFoundException {
- if (name != null && name.startsWith("org.apache.commons.logging")
- && "org.apache.commons.logging.IFactoryCreator".equals(name) == false) {
- try {
- InputStream is = getResourceAsStream( name.replace('.','/').concat(".class"));
- byte[] bytes = new byte[1024];
- ByteArrayOutputStream baos = new ByteArrayOutputStream(1024);
- int read;
- while ((read = is.read(bytes)) > -1) {
- baos.write(bytes, 0, read);
- }
- bytes = baos.toByteArray();
- return this.defineClass(name, bytes, 0, bytes.length);
- } catch (FileNotFoundException e) {
- throw new ClassNotFoundException("cannot find " + name, e);
- } catch (IOException e) {
- throw new ClassNotFoundException("cannot read " + name, e);
- }
- }
- else {
- return super.findClass(name);
- }
- }
-
- }
-
-}
diff --git a/optional/src/test/org/apache/commons/logging/SubDeploymentClass.java b/optional/src/test/org/apache/commons/logging/SubDeploymentClass.java
deleted file mode 100644
index ac6bb73..0000000
--- a/optional/src/test/org/apache/commons/logging/SubDeploymentClass.java
+++ /dev/null
@@ -1,41 +0,0 @@
-/*
- * Copyright 2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.commons.logging;
-
-import java.lang.ref.WeakReference;
-
-/**
- * Class that mocks a user class deployed in a sub-deployment that
- * interacts with LogFactory.
- *
- * @author bstansberry
- *
- * @see LogFactoryTest
- */
-public class SubDeploymentClass implements IFactoryCreator {
-
- private WeakReference weakFactory = null;
-
- public SubDeploymentClass() {
- LogFactory factory = LogFactory.getFactory();
- weakFactory = new WeakReference(factory);
- }
-
- public WeakReference getWeakFactory() {
- return weakFactory;
- }
-
-}
diff --git a/optional/src/test/org/apache/commons/logging/TestAll.java b/optional/src/test/org/apache/commons/logging/TestAll.java
deleted file mode 100644
index 9119c9d..0000000
--- a/optional/src/test/org/apache/commons/logging/TestAll.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/*
- * Copyright 2004 The Apache Software Foundation.
- *
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-
-
-package org.apache.commons.logging;
-
-import junit.framework.*;
-import org.apache.commons.logging.impl.MemoryLogTest;
-import org.apache.commons.logging.impl.WeakHashtableTest;
-
-/**
- * The build script calls just one TestSuite - this one!
- * All tests should be written into separate TestSuite's
- * and added to this. Don't clutter this class with implementations.