diff options
5 files changed, 91 insertions, 109 deletions
diff --git a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java index 3b79bdb1e..521604645 100644 --- a/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java +++ b/ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java @@ -13,6 +13,8 @@ package org.aspectj.tools.ajdoc; import java.io.File; import java.io.IOException; +import org.aspectj.util.FileUtil; + import junit.framework.AssertionFailedError; import junit.framework.TestCase; @@ -25,7 +27,6 @@ public class AjdocTestCase extends TestCase{ public final static String testdataSrcDir = "../ajdoc/testdata"; protected static File sandboxDir; - private static final String SANDBOX_NAME = "ajcSandbox"; private String docOutdir, projectDir; @@ -34,7 +35,7 @@ public class AjdocTestCase extends TestCase{ docOutdir = null; projectDir = null; // Create a sandbox in which to work - createEmptySandbox(); + sandboxDir = FileUtil.createEmptySandbox(); // create the ajdocworkdingdir in the sandbox Main.setOutputWorkingDir(getWorkingDir().getAbsolutePath()); } @@ -45,40 +46,6 @@ public class AjdocTestCase extends TestCase{ Main.resetOutputWorkingDir(); } - // Taken from AjdeInteractionTestbed - private void createEmptySandbox() { - 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")) { - //Alex: try D first since NTFS on mine while FAT leads to failure.. - tempDir = new File("D:\\temp"); - if (!tempDir.exists()) { - 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(); - } - - org.aspectj.util.FileUtil.deleteContents(sandboxRoot); - - try { - sandboxDir = File.createTempFile("ajcTest",".tmp",sandboxRoot); - sandboxDir.delete(); - sandboxDir.mkdir(); - } catch (IOException ioEx) { - throw new AssertionFailedError("Unable to create sandbox directory for test"); - } - } - /** * Fill in the working directory with the project files and * create a doc top level directory in which to generate diff --git a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/Ajc.java b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/Ajc.java index ea74c9c94..aa2e70861 100644 --- a/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/Ajc.java +++ b/org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/Ajc.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.List; import java.util.StringTokenizer; -import junit.framework.AssertionFailedError; import org.aspectj.bridge.AbortException; import org.aspectj.bridge.ICommand; @@ -45,8 +44,6 @@ import org.aspectj.util.FileUtil; */ public class Ajc { - private static final String SANDBOX_NAME = "ajcSandbox"; - private static final String TESTER_PATH = ".."+File.separator+"testing-client"+File.separator+"bin" + File.pathSeparator+".."+File.separator+"runtime" +File.separator+"bin" @@ -183,7 +180,7 @@ public class Ajc { try { if (!isIncremental && shouldEmptySandbox) { - createEmptySandbox(); + sandbox = FileUtil.createEmptySandbox(); } args = adjustToSandbox(args,!isIncremental); MessageHandler holder = new MessageHandler(); @@ -256,7 +253,7 @@ public class Ajc { * Get the sandbox directory used for the compilation. */ public File getSandboxDirectory() { - if (sandbox == null) {createEmptySandbox();} + if (sandbox == null) {sandbox = FileUtil.createEmptySandbox();} return sandbox; } @@ -282,33 +279,6 @@ public class Ajc { return false; } - private void createEmptySandbox() { - 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(); - } - - FileUtil.deleteContents(sandboxRoot); - - try { - sandbox = File.createTempFile("ajcTest",".tmp",sandboxRoot); - sandbox.delete(); - sandbox.mkdir(); - } catch (IOException ioEx) { - throw new AssertionFailedError("Unable to create sandbox directory for test"); - } - } - /** * Make every relative file name and dir be absolute under sandbox * Add TESTER_PATH to classpath diff --git a/tests/src/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java b/tests/src/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java index 83d73d28d..673763fe2 100644 --- a/tests/src/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java +++ b/tests/src/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java @@ -12,7 +12,6 @@ package org.aspectj.systemtest.incremental.tools; import java.io.File; -import java.io.IOException; import java.util.ArrayList; import java.util.Hashtable; import java.util.Iterator; @@ -20,7 +19,6 @@ import java.util.List; import java.util.Map; import java.util.Set; -import junit.framework.AssertionFailedError; import junit.framework.TestCase; import org.aspectj.ajde.Ajde; @@ -37,6 +35,7 @@ import org.aspectj.asm.AsmManager; import org.aspectj.bridge.IMessage; import org.aspectj.bridge.ISourceLocation; import org.aspectj.bridge.IMessage.Kind; +import org.aspectj.util.FileUtil; /** * This class uses Ajde in the same way that an IDE (e.g. AJDT) does. @@ -57,7 +56,6 @@ public class AjdeInteractionTestbed extends TestCase { public static String testdataSrcDir = "../tests/multiIncremental"; protected static File sandboxDir; - private static final String SANDBOX_NAME = "ajcSandbox"; private static boolean buildModel; // Methods for configuring the build @@ -96,7 +94,7 @@ public class AjdeInteractionTestbed extends TestCase { MyProjectPropertiesAdapter.reset(); // Create a sandbox in which to work - createEmptySandbox(); + sandboxDir = FileUtil.createEmptySandbox(); } protected void tearDown() throws Exception { @@ -292,39 +290,6 @@ public class AjdeInteractionTestbed extends TestCase { // Infrastructure below here - private void createEmptySandbox() { - 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")) { - //Alex: try D first since NTFS on mine while FAT leads to failure.. - tempDir = new File("D:\\temp"); - if (!tempDir.exists()) { - 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(); - } - - org.aspectj.util.FileUtil.deleteContents(sandboxRoot); - - try { - sandboxDir = File.createTempFile("ajcTest",".tmp",sandboxRoot); - sandboxDir.delete(); - sandboxDir.mkdir(); - } catch (IOException ioEx) { - throw new AssertionFailedError("Unable to create sandbox directory for test"); - } - } - private static void log(String msg) { if (VERBOSE) System.out.println(msg); } 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()); + } } |