@@ -0,0 +1,3187 @@
+/*%0A *  This file is part of the Heritrix web crawler (crawler.archive.org).%0A *%0A *  Licensed to the Internet Archive (IA) by one or more individual %0A *  contributors. %0A *%0A *  The IA licenses this file to You under the Apache License, Version 2.0%0A *  (the %22License%22); you may not use this file except in compliance with%0A *  the License.  You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A *  Unless required by applicable law or agreed to in writing, software%0A *  distributed under the License is distributed on an %22AS IS%22 BASIS,%0A *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A *  See the License for the specific language governing permissions and%0A *  limitations under the License.%0A */%0A%0Apackage org.archive.util;%0A%0Aimport java.io.File;%0Aimport java.io.IOException;%0A%0Aimport junit.framework.TestCase;%0A%0A%0A/**%0A * Base class for TestCases that want access to a tmp dir for the writing%0A * of files.%0A *%0A * @author stack%0A */%0Apublic abstract class TmpDirTestCase extends TestCase%0A%7B%0A    /**%0A     * Name of the system property that holds pointer to tmp directory into%0A     * which we can safely write files.%0A     */%0A    public static final String TEST_TMP_SYSTEM_PROPERTY_NAME = %22testtmpdir%22;%0A%0A    /**%0A     * Default test tmp.%0A     */%0A    public static final String DEFAULT_TEST_TMP_DIR = File.separator + %22tmp%22 +%0A        File.separator + %22heritrix-junit-tests%22;%0A%0A    /**%0A     * Directory to write temporary files to.%0A     */%0A    private File tmpDir = null;%0A%0A%0A    public TmpDirTestCase()%0A    %7B%0A        super();%0A    %7D%0A%0A    public TmpDirTestCase(String testName)%0A    %7B%0A        super(testName);%0A    %7D%0A%0A    /*%0A     * @see TestCase#setUp()%0A     */%0A    protected void setUp() throws Exception %7B%0A        super.setUp();%0A        this.tmpDir = tmpDir();%0A    %7D%0A%0A    /**%0A     * @return Returns the tmpDir.%0A     */%0A    public File getTmpDir()%0A    %7B%0A        return this.tmpDir;%0A    %7D%0A%0A    /**%0A     * Delete any files left over from previous run.%0A     *%0A     * @param basename Base name of files we're to clean up.%0A     */%0A    public void cleanUpOldFiles(String basename) %7B%0A        cleanUpOldFiles(getTmpDir(), basename);%0A    %7D%0A%0A    /**%0A     * Delete any files left over from previous run.%0A     *%0A     * @param prefix Base name of files we're to clean up.%0A     * @param basedir Directory to start cleaning in.%0A     */%0A    public void cleanUpOldFiles(File basedir, String prefix) %7B%0A        File %5B%5D files = FileUtils.getFilesWithPrefix(basedir, prefix);%0A        if (files != null) %7B%0A            for (int i = 0; i %3C files.length; i++) %7B%0A                org.apache.commons.io.FileUtils.deleteQuietly(files%5Bi%5D);%0A            %7D%0A        %7D%0A    %7D%0A    %0A    %0A    public static File tmpDir() throws IOException %7B%0A        String tmpDirStr = System.getProperty(TEST_TMP_SYSTEM_PROPERTY_NAME);%0A        tmpDirStr = (tmpDirStr == null)? DEFAULT_TEST_TMP_DIR: tmpDirStr;%0A        File tmpDir = new File(tmpDirStr);%0A        FileUtils.ensureWriteableDirectory(tmpDir);%0A%0A        if (!tmpDir.canWrite())%0A        %7B%0A            throw new IOException(tmpDir.getAbsolutePath() +%0A                 %22 is unwriteable.%22);%0A        %7D%0A        %0A        return tmpDir;%0A    %7D%0A%7D%0A

move TmpDirTestCase.java from heritrix to webarchive-commons