commons-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From joc...@apache.org
Subject svn commit: r518041 - in /jakarta/commons/proper/io/trunk: ./ src/changes/ src/java/org/apache/commons/io/ src/test/org/apache/commons/io/ xdocs/
Date Wed, 14 Mar 2007 06:50:04 GMT
Author: jochen
Date: Tue Mar 13 23:50:03 2007
New Revision: 518041

URL: http://svn.apache.org/viewvc?view=rev&rev=518041
Log:
Created the FileCleaningTracker, basically a non-static
version of the FileCleaner, which can be controlled by
the user.
PR: IO-116

Added:
    jakarta/commons/proper/io/trunk/src/changes/
    jakarta/commons/proper/io/trunk/src/changes/changes.xml
    jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileCleaningTracker.java
    jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleaningTrackerTestCase.java
    jakarta/commons/proper/io/trunk/xdocs/upgradeto1_4.xml
Modified:
    jakarta/commons/proper/io/trunk/   (props changed)
    jakarta/commons/proper/io/trunk/pom.xml
    jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileCleaner.java
    jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleanerTestCase.java

Propchange: jakarta/commons/proper/io/trunk/
------------------------------------------------------------------------------
--- svn:ignore (original)
+++ svn:ignore Tue Mar 13 23:50:03 2007
@@ -9,3 +9,4 @@
 .checkstyle
 bin
 *.log
+.settings

Modified: jakarta/commons/proper/io/trunk/pom.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/pom.xml?view=diff&rev=518041&r1=518040&r2=518041
==============================================================================
--- jakarta/commons/proper/io/trunk/pom.xml (original)
+++ jakarta/commons/proper/io/trunk/pom.xml Tue Mar 13 23:50:03 2007
@@ -131,7 +131,11 @@
         <role>Java Developer</role>
       </roles>
     </developer>
-
+    <developer>
+      <name>Jochen Wiedmann</name>
+      <id>jochen</id>
+      <email>jochen.wiedmann@gmail.com</email>
+    </developer>
   </developers>
 
   <contributors>
@@ -220,4 +224,23 @@
       </plugins>
     </build>
 
+  <reporting>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-changes-plugin</artifactId>
+        <configuration>
+          <issueLinkTemplate>%URL%/../%ISSUE%</issueLinkTemplate>
+        </configuration>
+        <reportSets>
+          <reportSet>
+            <reports>
+              <report>changes-report</report>
+              <report>jira-report</report>
+            </reports>
+          </reportSet>
+        </reportSets>
+      </plugin>
+    </plugins>
+  </reporting>
 </project>

Added: jakarta/commons/proper/io/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/changes/changes.xml?view=auto&rev=518041
==============================================================================
--- jakarta/commons/proper/io/trunk/src/changes/changes.xml (added)
+++ jakarta/commons/proper/io/trunk/src/changes/changes.xml Tue Mar 13 23:50:03 2007
@@ -0,0 +1,50 @@
+<?xml version="1.0"?>
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements.  See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You 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.
+-->
+
+<!--
+This file is used by the maven-changes-plugin to generate the release notes.
+Useful ways of finding items to add to this file are:
+
+1.  Add items when you fix a bug or add a feature (this makes the 
+release process easy :-).
+
+2.  Do a Jira search for tickets closed since the previous release.
+
+3.  Use the report generated by the maven-changelog-plugin to see all
+CVS commits.  Set the project.properties' maven.changelog.range 
+property to the number of days since the last release.
+
+
+The <action> type attribute can be add,update,fix,remove.
+-->
+
+<document>
+  <properties>
+    <title>Release Notes</title>
+  </properties>
+
+  <body>
+    <release version="1.4" date="Not yet released">
+      <action dev="jochen" type="fix" issue="IO-116">
+        Created the FileCleaningTracker, basically a non-static
+        version of the FileCleaner, which can be controlled by
+        the user.
+      </action>
+    </release>
+  </body>
+</document>

Modified: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileCleaner.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileCleaner.java?view=diff&rev=518041&r1=518040&r2=518041
==============================================================================
--- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileCleaner.java (original)
+++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileCleaner.java Tue Mar
13 23:50:03 2007
@@ -17,10 +17,6 @@
 package org.apache.commons.io;
 
 import java.io.File;
-import java.lang.ref.PhantomReference;
-import java.lang.ref.ReferenceQueue;
-import java.util.Collection;
-import java.util.Vector;
 
 /**
  * Keeps track of files awaiting deletion, and deletes them when an associated
@@ -39,25 +35,13 @@
  * @author Noel Bergman
  * @author Martin Cooper
  * @version $Id$
+ * @deprecated Use {@link FileCleaningTracker}
  */
 public class FileCleaner {
-
-    /**
-     * Queue of <code>Tracker</code> instances being watched.
-     */
-    static ReferenceQueue /* Tracker */ q = new ReferenceQueue();
     /**
-     * Collection of <code>Tracker</code> instances in existence.
+     * The instance to use for the deprecated, static methods.
      */
-    static Collection /* Tracker */ trackers = new Vector();  // synchronized
-    /**
-     * Whether to terminate the thread when the tracking is complete.
-     */
-    static volatile boolean exitWhenFinished = false;
-    /**
-     * The thread that will clean up registered files.
-     */
-    static Thread reaper;
+    static final FileCleaningTracker theInstance = new FileCleaningTracker();
 
     //-----------------------------------------------------------------------
     /**
@@ -68,9 +52,10 @@
      * @param file  the file to be tracked, not null
      * @param marker  the marker object used to track the file, not null
      * @throws NullPointerException if the file is null
+     * @deprecated Use {@link FileCleaningTracker#track(File, Object)}.
      */
     public static void track(File file, Object marker) {
-        track(file, marker, (FileDeleteStrategy) null);
+        theInstance.track(file, marker);
     }
 
     /**
@@ -82,12 +67,10 @@
      * @param marker  the marker object used to track the file, not null
      * @param deleteStrategy  the strategy to delete the file, null means normal
      * @throws NullPointerException if the file is null
+     * @deprecated Use {@link FileCleaningTracker#track(File, Object, FileDeleteStrategy)}.
      */
     public static void track(File file, Object marker, FileDeleteStrategy deleteStrategy)
{
-        if (file == null) {
-            throw new NullPointerException("The file must not be null");
-        }
-        addTracker(file.getPath(), marker, deleteStrategy);
+        theInstance.track(file, marker, deleteStrategy);
     }
 
     /**
@@ -98,9 +81,10 @@
      * @param path  the full path to the file to be tracked, not null
      * @param marker  the marker object used to track the file, not null
      * @throws NullPointerException if the path is null
+     * @deprecated Use {@link FileCleaningTracker#track(String, Object)}.
      */
     public static void track(String path, Object marker) {
-        track(path, marker, (FileDeleteStrategy) null);
+        theInstance.track(path, marker);
     }
 
     /**
@@ -112,31 +96,10 @@
      * @param marker  the marker object used to track the file, not null
      * @param deleteStrategy  the strategy to delete the file, null means normal
      * @throws NullPointerException if the path is null
+     * @deprecated Use {@link FileCleaningTracker#track(String, Object, FileDeleteStrategy)}.
      */
     public static void track(String path, Object marker, FileDeleteStrategy deleteStrategy)
{
-        if (path == null) {
-            throw new NullPointerException("The path must not be null");
-        }
-        addTracker(path, marker, deleteStrategy);
-    }
-
-    /**
-     * Adds a tracker to the list of trackers.
-     * 
-     * @param path  the full path to the file to be tracked, not null
-     * @param marker  the marker object used to track the file, not null
-     * @param deleteStrategy  the strategy to delete the file, null means normal
-     */
-    private static synchronized void addTracker(String path, Object marker, FileDeleteStrategy
deleteStrategy) {
-        // synchronized block protects reaper
-        if (exitWhenFinished) {
-            throw new IllegalStateException("No new trackers can be added once exitWhenFinished()
is called");
-        }
-        if (reaper == null) {
-            reaper = new Reaper();
-            reaper.start();
-        }
-        trackers.add(new Tracker(path, deleteStrategy, marker, q));
+        theInstance.track(path, marker, deleteStrategy);
     }
 
     //-----------------------------------------------------------------------
@@ -145,9 +108,10 @@
      * awaiting deletion.
      *
      * @return the number of files being tracked
+     * @deprecated Use {@link FileCleaningTracker#getTrackCount()}.
      */
     public static int getTrackCount() {
-        return trackers.size();
+        return theInstance.getTrackCount();
     }
 
     /**
@@ -170,90 +134,19 @@
      * This method allows the thread to be terminated. Simply call this method
      * in the resource cleanup code, such as {@link javax.servlet.ServletContextListener#contextDestroyed}.
      * One called, no new objects can be tracked by the file cleaner.
+     * @deprecated Use {@link FileCleaningTracker#exitWhenFinished()}.
      */
     public static synchronized void exitWhenFinished() {
-        // synchronized block protects reaper
-        exitWhenFinished = true;
-        if (reaper != null) {
-            synchronized (reaper) {
-                reaper.interrupt();
-            }
-        }
+        theInstance.exitWhenFinished();
     }
 
-    //-----------------------------------------------------------------------
     /**
-     * The reaper thread.
+     * Returns the singleton instance, which is used by the deprecated, static methods.
+     * This is mainly useful for code, which wants to support the new
+     * {@link FileCleaningTracker} class while maintain compatibility with the
+     * deprecated {@link FileCleaner}.
      */
-    static final class Reaper extends Thread {
-        /** Construct a new Reaper */
-        Reaper() {
-            super("File Reaper");
-            setPriority(Thread.MAX_PRIORITY);
-            setDaemon(true);
-        }
-
-        /**
-         * Run the reaper thread that will delete files as their associated
-         * marker objects are reclaimed by the garbage collector.
-         */
-        public void run() {
-            // thread exits when exitWhenFinished is true and there are no more tracked objects
-            while (exitWhenFinished == false || trackers.size() > 0) {
-                Tracker tracker = null;
-                try {
-                    // Wait for a tracker to remove.
-                    tracker = (Tracker) q.remove();
-                } catch (Exception e) {
-                    continue;
-                }
-                if (tracker != null) {
-                    tracker.delete();
-                    tracker.clear();
-                    trackers.remove(tracker);
-                }
-            }
-        }
+    public static FileCleaningTracker getInstance() {
+        return theInstance;
     }
-
-    //-----------------------------------------------------------------------
-    /**
-     * Inner class which acts as the reference for a file pending deletion.
-     */
-    static final class Tracker extends PhantomReference {
-
-        /**
-         * The full path to the file being tracked.
-         */
-        private final String path;
-        /**
-         * The strategy for deleting files.
-         */
-        private final FileDeleteStrategy deleteStrategy;
-
-        /**
-         * Constructs an instance of this class from the supplied parameters.
-         *
-         * @param path  the full path to the file to be tracked, not null
-         * @param deleteStrategy  the strategy to delete the file, null means normal
-         * @param marker  the marker object used to track the file, not null
-         * @param queue  the queue on to which the tracker will be pushed, not null
-         */
-        Tracker(String path, FileDeleteStrategy deleteStrategy, Object marker, ReferenceQueue
queue) {
-            super(marker, queue);
-            this.path = path;
-            this.deleteStrategy = (deleteStrategy == null ? FileDeleteStrategy.NORMAL : deleteStrategy);
-        }
-
-        /**
-         * Deletes the file associated with this tracker instance.
-         *
-         * @return <code>true</code> if the file was deleted successfully;
-         *         <code>false</code> otherwise.
-         */
-        public boolean delete() {
-            return deleteStrategy.deleteQuietly(new File(path));
-        }
-    }
-
 }

Added: jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileCleaningTracker.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileCleaningTracker.java?view=auto&rev=518041
==============================================================================
--- jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileCleaningTracker.java
(added)
+++ jakarta/commons/proper/io/trunk/src/java/org/apache/commons/io/FileCleaningTracker.java
Tue Mar 13 23:50:03 2007
@@ -0,0 +1,258 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.io;
+
+import java.io.File;
+import java.lang.ref.PhantomReference;
+import java.lang.ref.ReferenceQueue;
+import java.util.Collection;
+import java.util.Vector;
+
+/**
+ * Keeps track of files awaiting deletion, and deletes them when an associated
+ * marker object is reclaimed by the garbage collector.
+ * <p>
+ * This utility creates a background thread to handle file deletion.
+ * Each file to be deleted is registered with a handler object.
+ * When the handler object is garbage collected, the file is deleted.
+ * <p>
+ * In an environment with multiple class loaders (a servlet container, for
+ * example), you should consider stopping the background thread if it is no
+ * longer needed. This is done by invoking the method
+ * {@link #exitWhenFinished}, typically in
+ * {@link javax.servlet.ServletContextListener#contextDestroyed} or similar.
+ *
+ * @author Noel Bergman
+ * @author Martin Cooper
+ * @version $Id: FileCleaner.java 490987 2006-12-29 12:11:48Z scolebourne $
+ */
+public class FileCleaningTracker {
+    /**
+     * Queue of <code>Tracker</code> instances being watched.
+     */
+    ReferenceQueue /* Tracker */ q = new ReferenceQueue();
+    /**
+     * Collection of <code>Tracker</code> instances in existence.
+     */
+    final Collection /* Tracker */ trackers = new Vector();  // synchronized
+    /**
+     * Whether to terminate the thread when the tracking is complete.
+     */
+    volatile boolean exitWhenFinished = false;
+    /**
+     * The thread that will clean up registered files.
+     */
+    Thread reaper;
+
+    //-----------------------------------------------------------------------
+    /**
+     * Track the specified file, using the provided marker, deleting the file
+     * when the marker instance is garbage collected.
+     * The {@link FileDeleteStrategy#NORMAL normal} deletion strategy will be used.
+     *
+     * @param file  the file to be tracked, not null
+     * @param marker  the marker object used to track the file, not null
+     * @throws NullPointerException if the file is null
+     */
+    public void track(File file, Object marker) {
+        track(file, marker, (FileDeleteStrategy) null);
+    }
+
+    /**
+     * Track the specified file, using the provided marker, deleting the file
+     * when the marker instance is garbage collected.
+     * The speified deletion strategy is used.
+     *
+     * @param file  the file to be tracked, not null
+     * @param marker  the marker object used to track the file, not null
+     * @param deleteStrategy  the strategy to delete the file, null means normal
+     * @throws NullPointerException if the file is null
+     */
+    public void track(File file, Object marker, FileDeleteStrategy deleteStrategy) {
+        if (file == null) {
+            throw new NullPointerException("The file must not be null");
+        }
+        addTracker(file.getPath(), marker, deleteStrategy);
+    }
+
+    /**
+     * Track the specified file, using the provided marker, deleting the file
+     * when the marker instance is garbage collected.
+     * The {@link FileDeleteStrategy#NORMAL normal} deletion strategy will be used.
+     *
+     * @param path  the full path to the file to be tracked, not null
+     * @param marker  the marker object used to track the file, not null
+     * @throws NullPointerException if the path is null
+     */
+    public void track(String path, Object marker) {
+        track(path, marker, (FileDeleteStrategy) null);
+    }
+
+    /**
+     * Track the specified file, using the provided marker, deleting the file
+     * when the marker instance is garbage collected.
+     * The speified deletion strategy is used.
+     *
+     * @param path  the full path to the file to be tracked, not null
+     * @param marker  the marker object used to track the file, not null
+     * @param deleteStrategy  the strategy to delete the file, null means normal
+     * @throws NullPointerException if the path is null
+     */
+    public void track(String path, Object marker, FileDeleteStrategy deleteStrategy) {
+        if (path == null) {
+            throw new NullPointerException("The path must not be null");
+        }
+        addTracker(path, marker, deleteStrategy);
+    }
+
+    /**
+     * Adds a tracker to the list of trackers.
+     * 
+     * @param path  the full path to the file to be tracked, not null
+     * @param marker  the marker object used to track the file, not null
+     * @param deleteStrategy  the strategy to delete the file, null means normal
+     */
+    private synchronized void addTracker(String path, Object marker, FileDeleteStrategy deleteStrategy)
{
+        // synchronized block protects reaper
+        if (exitWhenFinished) {
+            throw new IllegalStateException("No new trackers can be added once exitWhenFinished()
is called");
+        }
+        if (reaper == null) {
+            reaper = new Reaper();
+            reaper.start();
+        }
+        trackers.add(new Tracker(path, deleteStrategy, marker, q));
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * Retrieve the number of files currently being tracked, and therefore
+     * awaiting deletion.
+     *
+     * @return the number of files being tracked
+     */
+    public int getTrackCount() {
+        return trackers.size();
+    }
+
+    /**
+     * Call this method to cause the file cleaner thread to terminate when
+     * there are no more objects being tracked for deletion.
+     * <p>
+     * In a simple environment, you don't need this method as the file cleaner
+     * thread will simply exit when the JVM exits. In a more complex environment,
+     * with multiple class loaders (such as an application server), you should be
+     * aware that the file cleaner thread will continue running even if the class
+     * loader it was started from terminates. This can consitute a memory leak.
+     * <p>
+     * For example, suppose that you have developed a web application, which
+     * contains the commons-io jar file in your WEB-INF/lib directory. In other
+     * words, the FileCleaner class is loaded through the class loader of your
+     * web application. If the web application is terminated, but the servlet
+     * container is still running, then the file cleaner thread will still exist,
+     * posing a memory leak.
+     * <p>
+     * This method allows the thread to be terminated. Simply call this method
+     * in the resource cleanup code, such as {@link javax.servlet.ServletContextListener#contextDestroyed}.
+     * One called, no new objects can be tracked by the file cleaner.
+     */
+    public synchronized void exitWhenFinished() {
+        // synchronized block protects reaper
+        exitWhenFinished = true;
+        if (reaper != null) {
+            synchronized (reaper) {
+                reaper.interrupt();
+            }
+        }
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * The reaper thread.
+     */
+    private final class Reaper extends Thread {
+        /** Construct a new Reaper */
+        Reaper() {
+            super("File Reaper");
+            setPriority(Thread.MAX_PRIORITY);
+            setDaemon(true);
+        }
+
+        /**
+         * Run the reaper thread that will delete files as their associated
+         * marker objects are reclaimed by the garbage collector.
+         */
+        public void run() {
+            // thread exits when exitWhenFinished is true and there are no more tracked objects
+            while (exitWhenFinished == false || trackers.size() > 0) {
+                Tracker tracker = null;
+                try {
+                    // Wait for a tracker to remove.
+                    tracker = (Tracker) q.remove();
+                } catch (Exception e) {
+                    continue;
+                }
+                if (tracker != null) {
+                    tracker.delete();
+                    tracker.clear();
+                    trackers.remove(tracker);
+                }
+            }
+        }
+    }
+
+    //-----------------------------------------------------------------------
+    /**
+     * Inner class which acts as the reference for a file pending deletion.
+     */
+    private static final class Tracker extends PhantomReference {
+
+        /**
+         * The full path to the file being tracked.
+         */
+        private final String path;
+        /**
+         * The strategy for deleting files.
+         */
+        private final FileDeleteStrategy deleteStrategy;
+
+        /**
+         * Constructs an instance of this class from the supplied parameters.
+         *
+         * @param path  the full path to the file to be tracked, not null
+         * @param deleteStrategy  the strategy to delete the file, null means normal
+         * @param marker  the marker object used to track the file, not null
+         * @param queue  the queue on to which the tracker will be pushed, not null
+         */
+        Tracker(String path, FileDeleteStrategy deleteStrategy, Object marker, ReferenceQueue
queue) {
+            super(marker, queue);
+            this.path = path;
+            this.deleteStrategy = (deleteStrategy == null ? FileDeleteStrategy.NORMAL : deleteStrategy);
+        }
+
+        /**
+         * Deletes the file associated with this tracker instance.
+         *
+         * @return <code>true</code> if the file was deleted successfully;
+         *         <code>false</code> otherwise.
+         */
+        public boolean delete() {
+            return deleteStrategy.deleteQuietly(new File(path));
+        }
+    }
+
+}

Modified: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleanerTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleanerTestCase.java?view=diff&rev=518041&r1=518040&r2=518041
==============================================================================
--- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleanerTestCase.java
(original)
+++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleanerTestCase.java
Tue Mar 13 23:50:03 2007
@@ -16,18 +16,12 @@
  */
 package org.apache.commons.io;
 
-import java.io.File;
 import java.io.IOException;
-import java.io.RandomAccessFile;
-import java.lang.ref.ReferenceQueue;
-import java.util.Vector;
 
 import junit.framework.Test;
 import junit.framework.TestSuite;
 import junit.textui.TestRunner;
 
-import org.apache.commons.io.testtools.FileBasedTestCase;
-
 /**
  * This is used to test FileCleaner for correctness.
  *
@@ -38,9 +32,10 @@
 
  * @see FileCleaner
  */
-public class FileCleanerTestCase extends FileBasedTestCase {
-
-    private File testFile;
+public class FileCleanerTestCase extends FileCleaningTrackerTestCase {
+    protected FileCleaningTracker newInstance() {
+        return FileCleaner.getInstance();
+    }
 
     public static void main(String[] args) {
         TestRunner.run(suite());
@@ -52,236 +47,5 @@
 
     public FileCleanerTestCase(String name) throws IOException {
         super(name);
-
-        testFile = new File(getTestDirectory(), "file-test.txt");
-    }
-
-    /** @see junit.framework.TestCase#setUp() */
-    protected void setUp() throws Exception {
-        getTestDirectory().mkdirs();
-    }
-
-    /** @see junit.framework.TestCase#tearDown() */
-    protected void tearDown() throws Exception {
-        FileUtils.deleteDirectory(getTestDirectory());
-        
-        // reset file cleaner class, so as not to break other tests
-        FileCleaner.q = new ReferenceQueue();
-        FileCleaner.trackers = new Vector();
-        FileCleaner.exitWhenFinished = false;
-        FileCleaner.reaper = null;
-    }
-
-    //-----------------------------------------------------------------------
-    public void testFileCleanerFile() throws Exception {
-        String path = testFile.getPath();
-        
-        assertEquals(false, testFile.exists());
-        RandomAccessFile r = new RandomAccessFile(testFile, "rw");
-        assertEquals(true, testFile.exists());
-        
-        assertEquals(0, FileCleaner.getTrackCount());
-        FileCleaner.track(path, r);
-        assertEquals(1, FileCleaner.getTrackCount());
-        
-        r.close();
-        testFile = null;
-        r = null;
-
-        waitUntilTrackCount();
-        
-        assertEquals(0, FileCleaner.getTrackCount());
-        assertEquals(false, new File(path).exists());
-    }
-
-    public void testFileCleanerDirectory() throws Exception {
-        createFile(testFile, 100);
-        assertEquals(true, testFile.exists());
-        assertEquals(true, getTestDirectory().exists());
-        
-        Object obj = new Object();
-        assertEquals(0, FileCleaner.getTrackCount());
-        FileCleaner.track(getTestDirectory(), obj);
-        assertEquals(1, FileCleaner.getTrackCount());
-        
-        obj = null;
-
-        waitUntilTrackCount();
-
-        assertEquals(0, FileCleaner.getTrackCount());
-        assertEquals(true, testFile.exists());  // not deleted, as dir not empty
-        assertEquals(true, testFile.getParentFile().exists());  // not deleted, as dir not
empty
-    }
-
-    public void testFileCleanerDirectory_NullStrategy() throws Exception {
-        createFile(testFile, 100);
-        assertEquals(true, testFile.exists());
-        assertEquals(true, getTestDirectory().exists());
-        
-        Object obj = new Object();
-        assertEquals(0, FileCleaner.getTrackCount());
-        FileCleaner.track(getTestDirectory(), obj, (FileDeleteStrategy) null);
-        assertEquals(1, FileCleaner.getTrackCount());
-        
-        obj = null;
-
-        waitUntilTrackCount();
-        
-        assertEquals(0, FileCleaner.getTrackCount());
-        assertEquals(true, testFile.exists());  // not deleted, as dir not empty
-        assertEquals(true, testFile.getParentFile().exists());  // not deleted, as dir not
empty
-    }
-
-    public void testFileCleanerDirectory_ForceStrategy() throws Exception {
-        createFile(testFile, 100);
-        assertEquals(true, testFile.exists());
-        assertEquals(true, getTestDirectory().exists());
-        
-        Object obj = new Object();
-        assertEquals(0, FileCleaner.getTrackCount());
-        FileCleaner.track(getTestDirectory(), obj, FileDeleteStrategy.FORCE);
-        assertEquals(1, FileCleaner.getTrackCount());
-        
-        obj = null;
-
-        waitUntilTrackCount();
-        
-        assertEquals(0, FileCleaner.getTrackCount());
-        assertEquals(false, testFile.exists());
-        assertEquals(false, testFile.getParentFile().exists());
-    }
-
-    public void testFileCleanerNull() throws Exception {
-        try {
-            FileCleaner.track((File) null, new Object());
-            fail();
-        } catch (NullPointerException ex) {
-            // expected
-        }
-        try {
-            FileCleaner.track((File) null, new Object(), FileDeleteStrategy.NORMAL);
-            fail();
-        } catch (NullPointerException ex) {
-            // expected
-        }
-        try {
-            FileCleaner.track((String) null, new Object());
-            fail();
-        } catch (NullPointerException ex) {
-            // expected
-        }
-        try {
-            FileCleaner.track((String) null, new Object(), FileDeleteStrategy.NORMAL);
-            fail();
-        } catch (NullPointerException ex) {
-            // expected
-        }
-    }
-
-    public void testFileCleanerExitWhenFinishedFirst() throws Exception {
-        assertEquals(false, FileCleaner.exitWhenFinished);
-        FileCleaner.exitWhenFinished();
-        assertEquals(true, FileCleaner.exitWhenFinished);
-        assertEquals(null, FileCleaner.reaper);
-        
-        waitUntilTrackCount();
-        
-        assertEquals(0, FileCleaner.getTrackCount());
-        assertEquals(true, FileCleaner.exitWhenFinished);
-        assertEquals(null, FileCleaner.reaper);
-    }
-
-    public void testFileCleanerExitWhenFinished_NoTrackAfter() throws Exception {
-        assertEquals(false, FileCleaner.exitWhenFinished);
-        FileCleaner.exitWhenFinished();
-        assertEquals(true, FileCleaner.exitWhenFinished);
-        assertEquals(null, FileCleaner.reaper);
-        
-        String path = testFile.getPath();
-        Object marker = new Object();
-        try {
-            FileCleaner.track(path, marker);
-            fail();
-        } catch (IllegalStateException ex) {
-            // expected
-        }
-        assertEquals(true, FileCleaner.exitWhenFinished);
-        assertEquals(null, FileCleaner.reaper);
-    }
-
-    public void testFileCleanerExitWhenFinished1() throws Exception {
-        String path = testFile.getPath();
-        
-        assertEquals(false, testFile.exists());
-        RandomAccessFile r = new RandomAccessFile(testFile, "rw");
-        assertEquals(true, testFile.exists());
-        
-        assertEquals(0, FileCleaner.getTrackCount());
-        FileCleaner.track(path, r);
-        assertEquals(1, FileCleaner.getTrackCount());
-        assertEquals(false, FileCleaner.exitWhenFinished);
-        assertEquals(true, FileCleaner.reaper.isAlive());
-        
-        assertEquals(false, FileCleaner.exitWhenFinished);
-        FileCleaner.exitWhenFinished();
-        assertEquals(true, FileCleaner.exitWhenFinished);
-        assertEquals(true, FileCleaner.reaper.isAlive());
-        
-        r.close();
-        testFile = null;
-        r = null;
-
-        waitUntilTrackCount();
-        
-        assertEquals(0, FileCleaner.getTrackCount());
-        assertEquals(false, new File(path).exists());
-        assertEquals(true, FileCleaner.exitWhenFinished);
-        assertEquals(false, FileCleaner.reaper.isAlive());
-    }
-
-    public void testFileCleanerExitWhenFinished2() throws Exception {
-        String path = testFile.getPath();
-        
-        assertEquals(false, testFile.exists());
-        RandomAccessFile r = new RandomAccessFile(testFile, "rw");
-        assertEquals(true, testFile.exists());
-        
-        assertEquals(0, FileCleaner.getTrackCount());
-        FileCleaner.track(path, r);
-        assertEquals(1, FileCleaner.getTrackCount());
-        assertEquals(false, FileCleaner.exitWhenFinished);
-        assertEquals(true, FileCleaner.reaper.isAlive());
-        
-        r.close();
-        testFile = null;
-        r = null;
-
-        waitUntilTrackCount();
-        
-        assertEquals(0, FileCleaner.getTrackCount());
-        assertEquals(false, new File(path).exists());
-        assertEquals(false, FileCleaner.exitWhenFinished);
-        assertEquals(true, FileCleaner.reaper.isAlive());
-        
-        assertEquals(false, FileCleaner.exitWhenFinished);
-        FileCleaner.exitWhenFinished();
-        for (int i = 0; i < 20 && FileCleaner.reaper.isAlive(); i++) {
-            Thread.sleep(500L);  // allow reaper thread to die
-        }
-        assertEquals(true, FileCleaner.exitWhenFinished);
-        assertEquals(false, FileCleaner.reaper.isAlive());
-    }
-
-    //-----------------------------------------------------------------------
-    private void waitUntilTrackCount() {
-        while (FileCleaner.getTrackCount() != 0) {
-            int total = 0;
-            while (FileCleaner.getTrackCount() != 0) {
-                byte[] b = new byte[1024 * 1024];
-                b[0] = (byte) System.currentTimeMillis();
-                total = total + b[0];
-                System.gc();
-            }
-        }
     }
 }

Added: jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleaningTrackerTestCase.java
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleaningTrackerTestCase.java?view=auto&rev=518041
==============================================================================
--- jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleaningTrackerTestCase.java
(added)
+++ jakarta/commons/proper/io/trunk/src/test/org/apache/commons/io/FileCleaningTrackerTestCase.java
Tue Mar 13 23:50:03 2007
@@ -0,0 +1,302 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You 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.io;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.RandomAccessFile;
+import java.lang.ref.ReferenceQueue;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import junit.textui.TestRunner;
+
+import org.apache.commons.io.testtools.FileBasedTestCase;
+
+/**
+ * This is used to test {@link FileCleaningTracker} for correctness.
+ *
+ * @author Noel Bergman
+ * @author Martin Cooper
+ *
+ * @version $Id: FileCleanerTestCase.java 482437 2006-12-05 01:13:05Z scolebourne $
+
+ * @see FileCleaner
+ */
+public class FileCleaningTrackerTestCase extends FileBasedTestCase {
+    protected FileCleaningTracker newInstance() {
+        return new FileCleaningTracker();
+    }
+
+    private File testFile;
+    private FileCleaningTracker theInstance;
+
+    public static void main(String[] args) {
+        TestRunner.run(suite());
+    }
+
+    public static Test suite() {
+        return new TestSuite(FileCleaningTrackerTestCase.class);
+    }
+
+    public FileCleaningTrackerTestCase(String name) throws IOException {
+        super(name);
+
+        testFile = new File(getTestDirectory(), "file-test.txt");
+    }
+
+    /** @see junit.framework.TestCase#setUp() */
+    protected void setUp() throws Exception {
+        theInstance = newInstance();
+        getTestDirectory().mkdirs();
+    }
+
+    /** @see junit.framework.TestCase#tearDown() */
+    protected void tearDown() throws Exception {
+        FileUtils.deleteDirectory(getTestDirectory());
+        
+        // reset file cleaner class, so as not to break other tests
+
+        /**
+         * The following block of code can possibly be removed when the
+         * deprecated {@link FileCleaner} is gone. The question is, whether
+         * we want to support reuse of {@link FileCleaningTracker} instances,
+         * which we should, IMO, not.
+         */
+        {
+            theInstance.q = new ReferenceQueue();
+            theInstance.trackers.clear();
+            theInstance.exitWhenFinished = false;
+            theInstance.reaper = null;
+        }
+        
+        theInstance = null;
+    }
+
+    //-----------------------------------------------------------------------
+    public void testFileCleanerFile() throws Exception {
+        String path = testFile.getPath();
+        
+        assertEquals(false, testFile.exists());
+        RandomAccessFile r = new RandomAccessFile(testFile, "rw");
+        assertEquals(true, testFile.exists());
+        
+        assertEquals(0, theInstance.getTrackCount());
+        theInstance.track(path, r);
+        assertEquals(1, theInstance.getTrackCount());
+        
+        r.close();
+        testFile = null;
+        r = null;
+
+        waitUntilTrackCount();
+        
+        assertEquals(0, theInstance.getTrackCount());
+        assertEquals(false, new File(path).exists());
+    }
+
+    public void testFileCleanerDirectory() throws Exception {
+        createFile(testFile, 100);
+        assertEquals(true, testFile.exists());
+        assertEquals(true, getTestDirectory().exists());
+        
+        Object obj = new Object();
+        assertEquals(0, theInstance.getTrackCount());
+        theInstance.track(getTestDirectory(), obj);
+        assertEquals(1, theInstance.getTrackCount());
+        
+        obj = null;
+
+        waitUntilTrackCount();
+
+        assertEquals(0, theInstance.getTrackCount());
+        assertEquals(true, testFile.exists());  // not deleted, as dir not empty
+        assertEquals(true, testFile.getParentFile().exists());  // not deleted, as dir not
empty
+    }
+
+    public void testFileCleanerDirectory_NullStrategy() throws Exception {
+        createFile(testFile, 100);
+        assertEquals(true, testFile.exists());
+        assertEquals(true, getTestDirectory().exists());
+        
+        Object obj = new Object();
+        assertEquals(0, theInstance.getTrackCount());
+        theInstance.track(getTestDirectory(), obj, (FileDeleteStrategy) null);
+        assertEquals(1, theInstance.getTrackCount());
+        
+        obj = null;
+
+        waitUntilTrackCount();
+        
+        assertEquals(0, theInstance.getTrackCount());
+        assertEquals(true, testFile.exists());  // not deleted, as dir not empty
+        assertEquals(true, testFile.getParentFile().exists());  // not deleted, as dir not
empty
+    }
+
+    public void testFileCleanerDirectory_ForceStrategy() throws Exception {
+        createFile(testFile, 100);
+        assertEquals(true, testFile.exists());
+        assertEquals(true, getTestDirectory().exists());
+        
+        Object obj = new Object();
+        assertEquals(0, theInstance.getTrackCount());
+        theInstance.track(getTestDirectory(), obj, FileDeleteStrategy.FORCE);
+        assertEquals(1, theInstance.getTrackCount());
+        
+        obj = null;
+
+        waitUntilTrackCount();
+        
+        assertEquals(0, theInstance.getTrackCount());
+        assertEquals(false, testFile.exists());
+        assertEquals(false, testFile.getParentFile().exists());
+    }
+
+    public void testFileCleanerNull() throws Exception {
+        try {
+            theInstance.track((File) null, new Object());
+            fail();
+        } catch (NullPointerException ex) {
+            // expected
+        }
+        try {
+            theInstance.track((File) null, new Object(), FileDeleteStrategy.NORMAL);
+            fail();
+        } catch (NullPointerException ex) {
+            // expected
+        }
+        try {
+            theInstance.track((String) null, new Object());
+            fail();
+        } catch (NullPointerException ex) {
+            // expected
+        }
+        try {
+            theInstance.track((String) null, new Object(), FileDeleteStrategy.NORMAL);
+            fail();
+        } catch (NullPointerException ex) {
+            // expected
+        }
+    }
+
+    public void testFileCleanerExitWhenFinishedFirst() throws Exception {
+        assertEquals(false, theInstance.exitWhenFinished);
+        theInstance.exitWhenFinished();
+        assertEquals(true, theInstance.exitWhenFinished);
+        assertEquals(null, theInstance.reaper);
+        
+        waitUntilTrackCount();
+        
+        assertEquals(0, theInstance.getTrackCount());
+        assertEquals(true, theInstance.exitWhenFinished);
+        assertEquals(null, theInstance.reaper);
+    }
+
+    public void testFileCleanerExitWhenFinished_NoTrackAfter() throws Exception {
+        assertEquals(false, theInstance.exitWhenFinished);
+        theInstance.exitWhenFinished();
+        assertEquals(true, theInstance.exitWhenFinished);
+        assertEquals(null, theInstance.reaper);
+        
+        String path = testFile.getPath();
+        Object marker = new Object();
+        try {
+            theInstance.track(path, marker);
+            fail();
+        } catch (IllegalStateException ex) {
+            // expected
+        }
+        assertEquals(true, theInstance.exitWhenFinished);
+        assertEquals(null, theInstance.reaper);
+    }
+
+    public void testFileCleanerExitWhenFinished1() throws Exception {
+        String path = testFile.getPath();
+        
+        assertEquals(false, testFile.exists());
+        RandomAccessFile r = new RandomAccessFile(testFile, "rw");
+        assertEquals(true, testFile.exists());
+        
+        assertEquals(0, theInstance.getTrackCount());
+        theInstance.track(path, r);
+        assertEquals(1, theInstance.getTrackCount());
+        assertEquals(false, theInstance.exitWhenFinished);
+        assertEquals(true, theInstance.reaper.isAlive());
+        
+        assertEquals(false, theInstance.exitWhenFinished);
+        theInstance.exitWhenFinished();
+        assertEquals(true, theInstance.exitWhenFinished);
+        assertEquals(true, theInstance.reaper.isAlive());
+        
+        r.close();
+        testFile = null;
+        r = null;
+
+        waitUntilTrackCount();
+        
+        assertEquals(0, theInstance.getTrackCount());
+        assertEquals(false, new File(path).exists());
+        assertEquals(true, theInstance.exitWhenFinished);
+        assertEquals(false, theInstance.reaper.isAlive());
+    }
+
+    public void testFileCleanerExitWhenFinished2() throws Exception {
+        String path = testFile.getPath();
+        
+        assertEquals(false, testFile.exists());
+        RandomAccessFile r = new RandomAccessFile(testFile, "rw");
+        assertEquals(true, testFile.exists());
+        
+        assertEquals(0, theInstance.getTrackCount());
+        theInstance.track(path, r);
+        assertEquals(1, theInstance.getTrackCount());
+        assertEquals(false, theInstance.exitWhenFinished);
+        assertEquals(true, theInstance.reaper.isAlive());
+        
+        r.close();
+        testFile = null;
+        r = null;
+
+        waitUntilTrackCount();
+        
+        assertEquals(0, theInstance.getTrackCount());
+        assertEquals(false, new File(path).exists());
+        assertEquals(false, theInstance.exitWhenFinished);
+        assertEquals(true, theInstance.reaper.isAlive());
+        
+        assertEquals(false, theInstance.exitWhenFinished);
+        theInstance.exitWhenFinished();
+        for (int i = 0; i < 20 && theInstance.reaper.isAlive(); i++) {
+            Thread.sleep(500L);  // allow reaper thread to die
+        }
+        assertEquals(true, theInstance.exitWhenFinished);
+        assertEquals(false, theInstance.reaper.isAlive());
+    }
+
+    //-----------------------------------------------------------------------
+    private void waitUntilTrackCount() {
+        while (theInstance.getTrackCount() != 0) {
+            int total = 0;
+            while (theInstance.getTrackCount() != 0) {
+                byte[] b = new byte[1024 * 1024];
+                b[0] = (byte) System.currentTimeMillis();
+                total = total + b[0];
+                System.gc();
+            }
+        }
+    }
+}

Added: jakarta/commons/proper/io/trunk/xdocs/upgradeto1_4.xml
URL: http://svn.apache.org/viewvc/jakarta/commons/proper/io/trunk/xdocs/upgradeto1_4.xml?view=auto&rev=518041
==============================================================================
--- jakarta/commons/proper/io/trunk/xdocs/upgradeto1_4.xml (added)
+++ jakarta/commons/proper/io/trunk/xdocs/upgradeto1_4.xml Tue Mar 13 23:50:03 2007
@@ -0,0 +1,65 @@
+<?xml version="1.0"?>
+<!--
+Licensed to the Apache Software Foundation (ASF) under one or more
+contributor license agreements.  See the NOTICE file distributed with
+this work for additional information regarding copyright ownership.
+The ASF licenses this file to You 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.
+-->
+<document>
+ <properties>
+  <title>Upgrade from 1.3 to 1.4</title>
+  <author email="commons-dev@jakarta.apache.org">Commons Documentation Team</author>
+ </properties>
+<body>
+
+<section name="Upgrade">
+<p>
+These are the release notes and advice for upgrading Commons-IO from
+version 1.3 to version 1.4.
+<source>
+Commons IO is a package of Java utility classes for java.io's hierarchy.  
+Classes in this package are considered to be so standard and of such high 
+reuse as to justify existence in java.io.
+
+Commons IO contains utility classes, stream implementations, file filters, 
+and endian transformation classes.
+
+
+Compatibility with 1.3
+----------------------
+Binary compatible - Yes
+
+Source compatible - Yes
+
+Semantic compatible - Yes
+  Check the bug fixes section for semantic bug fixes
+
+
+Deprecations from 1.3
+---------------------
+- FileCleaner deprecated, replaced by FileCleaningTracker
+  - the old class allowed static use only.
+  - instances of the new class may be put into arbitrary scope.
+
+
+Bug fixes from 1.2
+------------------
+
+Enhancements from 1.2
+---------------------
+</source>
+</p>
+</section>
+
+</body>
+</document>



---------------------------------------------------------------------
To unsubscribe, e-mail: commons-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: commons-dev-help@jakarta.apache.org


Mime
View raw message