]> source.dussan.org Git - aspectj.git/commitdiff
Make sandbox directories unique among workspaces e.g. c:\temp\ajcSandbox\org.aspectj...
authormwebster <mwebster>
Thu, 15 Jun 2006 10:44:04 +0000 (10:44 +0000)
committermwebster <mwebster>
Thu, 15 Jun 2006 10:44:04 +0000 (10:44 +0000)
ajdoc/testsrc/org/aspectj/tools/ajdoc/AjdocTestCase.java
org.aspectj.ajdt.core/testsrc/org/aspectj/tools/ajc/Ajc.java
tests/src/org/aspectj/systemtest/incremental/tools/AjdeInteractionTestbed.java
util/src/org/aspectj/util/FileUtil.java
util/testsrc/org/aspectj/util/FileUtilTest.java

index 3b79bdb1e89ed3c63edf11e066a6a15761b0a97c..5216046450ba5cc8746563073f079aef7e84078f 100644 (file)
@@ -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
index ea74c9c9472b95ce6165b082b3a9e33515270784..aa2e70861b08bac3d7605018aa0e930612ac5286 100644 (file)
@@ -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
index 83d73d28d97e033ae672e50e65308b8c1573c45b..673763fe2a61ef45fce5011ec6792022783aa449 100644 (file)
@@ -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);
        }
index d7892f6eba194a9ac5d2c87718ba4dd37a4dbd1b..3e5b9ee4cddb47f376b2054790cf845257f5ddc9 100644 (file)
 
 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;
+       }
+
 }
index 23ac0e31f435078b13932360230a4c978e28ed0c..1879abef728bb7a705e8b5a39f99a38f2b87a8d7 100644 (file)
@@ -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());
+    }
 
 }