diff options
Diffstat (limited to 'util')
-rw-r--r-- | util/src/org/aspectj/util/FileUtil.java | 83 | ||||
-rw-r--r-- | util/testsrc/org/aspectj/util/FileUtilTest.java | 5 |
2 files changed, 84 insertions, 4 deletions
diff --git a/util/src/org/aspectj/util/FileUtil.java b/util/src/org/aspectj/util/FileUtil.java index d7892f6eb..3e5b9ee4c 100644 --- a/util/src/org/aspectj/util/FileUtil.java +++ b/util/src/org/aspectj/util/FileUtil.java @@ -13,10 +13,40 @@ package org.aspectj.util; -import java.io.*; -import java.net.*; -import java.util.*; -import java.util.zip.*; +import java.io.BufferedOutputStream; +import java.io.BufferedReader; +import java.io.ByteArrayOutputStream; +import java.io.DataInputStream; +import java.io.DataOutputStream; +import java.io.File; +import java.io.FileFilter; +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.FileReader; +import java.io.FileWriter; +import java.io.FilenameFilter; +import java.io.IOException; +import java.io.InputStream; +import java.io.InputStreamReader; +import java.io.OutputStream; +import java.io.PrintStream; +import java.io.Reader; +import java.io.StringReader; +import java.io.Writer; +import java.net.MalformedURLException; +import java.net.URL; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collections; +import java.util.Iterator; +import java.util.LinkedList; +import java.util.List; +import java.util.zip.ZipEntry; +import java.util.zip.ZipFile; +import java.util.zip.ZipInputStream; + +import junit.framework.AssertionFailedError; /** @@ -1326,6 +1356,8 @@ public class FileUtil { } } + private static final String SANDBOX_NAME = "ajcSandbox"; + private FileUtil() { throw new Error("utility class"); } public static List makeClasspath(URL[] urls) { @@ -1509,4 +1541,47 @@ public class FileUtil { } } + public static File createEmptySandbox() { + File sandbox; + + String os = System.getProperty("os.name"); + File tempDir = null; + // AMC - I did this rather than use the JDK default as I hate having to go look + // in c:\documents and settings\......... for the results of a failed test. + if (os.startsWith("Windows")) { + tempDir = new File("C:\\temp"); + if (!tempDir.exists()) {tempDir.mkdir();} + } else { + tempDir = new File("/tmp"); + } + File sandboxRoot = new File(tempDir,SANDBOX_NAME); + if (!sandboxRoot.exists()) { + sandboxRoot.mkdir(); + } + + + try { + File workspace = new File(".." + File.separator); + String workspaceName = workspace.getCanonicalPath(); + int index = workspaceName.lastIndexOf(File.separator); + workspaceName = workspaceName.substring(index+1); + + File workspaceRoot = new File(sandboxRoot,workspaceName); + if (!workspaceRoot.exists()) { + workspaceRoot.mkdir(); + } + + deleteContents(workspaceRoot); + + sandbox = File.createTempFile("ajcTest",".tmp",workspaceRoot); + sandbox.delete(); + sandbox.mkdir(); + + } catch (IOException ioEx) { + throw new AssertionFailedError("Unable to create sandbox directory for test"); + } + + return sandbox; + } + } diff --git a/util/testsrc/org/aspectj/util/FileUtilTest.java b/util/testsrc/org/aspectj/util/FileUtilTest.java index 23ac0e31f..1879abef7 100644 --- a/util/testsrc/org/aspectj/util/FileUtilTest.java +++ b/util/testsrc/org/aspectj/util/FileUtilTest.java @@ -706,5 +706,10 @@ public class FileUtilTest extends TestCase { assertTrue("written: " + pipe.totalWritten(), false); } } + + public void testCreateEmptySandbox () { + File sandbox = FileUtil.createEmptySandbox(); + assertTrue("Sandbox does not exist",sandbox.exists()); + } } |