ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anto...@apache.org
Subject cvs commit: ant/src/testcases/org/apache/tools/ant/util FileUtilsTest.java
Date Tue, 24 Jun 2003 16:07:28 GMT
antoine     2003/06/24 09:07:27

  Modified:    .        WHATSNEW
               src/main/org/apache/tools/ant/util FileUtils.java
               src/testcases/org/apache/tools/ant/util FileUtilsTest.java
  Log:
  Use java.io.tmpdir as location for temporary files
  in FileUtils#createTempFile (when the directory parameter is null)
  
  Revision  Changes    Path
  1.447     +3 -0      ant/WHATSNEW
  
  Index: WHATSNEW
  ===================================================================
  RCS file: /home/cvs/ant/WHATSNEW,v
  retrieving revision 1.446
  retrieving revision 1.447
  diff -u -r1.446 -r1.447
  --- WHATSNEW	24 Jun 2003 15:08:53 -0000	1.446
  +++ WHATSNEW	24 Jun 2003 16:07:24 -0000	1.447
  @@ -445,6 +445,9 @@
   
   * <checksum> has two new properties: totalproperty and todir.
   
  +* FileUtils#createTempFile will now create temporary files in the 
  +  directory pointed to by the property java.io.tmpdir
  +
   Changes from Ant 1.5.2 to Ant 1.5.3
   ===================================
   
  
  
  
  1.43      +6 -5      ant/src/main/org/apache/tools/ant/util/FileUtils.java
  
  Index: FileUtils.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/util/FileUtils.java,v
  retrieving revision 1.42
  retrieving revision 1.43
  diff -u -r1.42 -r1.43
  --- FileUtils.java	19 May 2003 15:55:22 -0000	1.42
  +++ FileUtils.java	24 Jun 2003 16:07:24 -0000	1.43
  @@ -783,20 +783,21 @@
        * of this method will yield a different file name.</p>
        *
        * <p>This method is different to File.createTempFile of JDK 1.2
  -     * as it doesn't create the file itself and doesn't use platform
  -     * specific temporary directory when the parentDir attribute is
  +     * as it doesn't create the file itself.
  +     * It uses the location pointed to by java.io.tmpdir
  +     * when the parentDir attribute is
        * null.</p>
        *
        * @param parentDir Directory to create the temporary file in -
        * current working directory will be assumed if this parameter is
        * null.
        *
  -     * @since 1.8
  +     * @since ant 1.5
        */
       public File createTempFile(String prefix, String suffix, File parentDir) {
   
           File result = null;
  -        String parent = null;
  +        String parent = System.getProperty("java.io.tmpdir");
           if (parentDir != null) {
               parent = parentDir.getPath();
           }
  
  
  
  1.18      +61 -60    ant/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java
  
  Index: FileUtilsTest.java
  ===================================================================
  RCS file: /home/cvs/ant/src/testcases/org/apache/tools/ant/util/FileUtilsTest.java,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- FileUtilsTest.java	23 Jun 2003 16:18:00 -0000	1.17
  +++ FileUtilsTest.java	24 Jun 2003 16:07:26 -0000	1.18
  @@ -64,8 +64,8 @@
   /**
    * Tests for org.apache.tools.ant.util.FileUtils.
    *
  - * @author Stefan Bodewig 
  - * @author <a href="mailto:jtulley@novell.com">Jeff Tulley</a> 
  + * @author Stefan Bodewig
  + * @author <a href="mailto:jtulley@novell.com">Jeff Tulley</a>
    */
   public class FileUtilsTest extends TestCase {
   
  @@ -117,7 +117,7 @@
               // JDK 1.1
               assertEquals(modTime, secondModTime);
           }
  -        
  +
   
           // number of milliseconds in a day
           final int millisperday=24 * 3600 * 1000;
  @@ -145,30 +145,30 @@
           /*
            * Start with simple absolute file names.
            */
  -        assertEquals(File.separator, 
  +        assertEquals(File.separator,
                        fu.resolveFile(null, "/").getPath());
  -        assertEquals(File.separator, 
  +        assertEquals(File.separator,
                        fu.resolveFile(null, "\\").getPath());
   
           /*
            * throw in drive letters
            */
           String driveSpec = "C:";
  -        assertEquals(driveSpec + "\\", 
  +        assertEquals(driveSpec + "\\",
                        fu.resolveFile(null, driveSpec + "/").getPath());
  -        assertEquals(driveSpec + "\\", 
  +        assertEquals(driveSpec + "\\",
                        fu.resolveFile(null, driveSpec + "\\").getPath());
           String driveSpecLower = "c:";
  -        assertEquals(driveSpec + "\\", 
  +        assertEquals(driveSpec + "\\",
                        fu.resolveFile(null, driveSpecLower + "/").getPath());
  -        assertEquals(driveSpec + "\\", 
  +        assertEquals(driveSpec + "\\",
                        fu.resolveFile(null, driveSpecLower + "\\").getPath());
           /*
            * promised to eliminate consecutive slashes after drive letter.
            */
  -        assertEquals(driveSpec + "\\", 
  +        assertEquals(driveSpec + "\\",
                        fu.resolveFile(null, driveSpec + "/////").getPath());
  -        assertEquals(driveSpec + "\\", 
  +        assertEquals(driveSpec + "\\",
                        fu.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath());
   
           if (Os.isFamily("netware")) {
  @@ -176,21 +176,21 @@
                * throw in NetWare volume names
                */
               driveSpec = "SYS:";
  -            assertEquals(driveSpec, 
  +            assertEquals(driveSpec,
                            fu.resolveFile(null, driveSpec + "/").getPath());
  -            assertEquals(driveSpec, 
  +            assertEquals(driveSpec,
                            fu.resolveFile(null, driveSpec + "\\").getPath());
               driveSpecLower = "sys:";
  -            assertEquals(driveSpec, 
  +            assertEquals(driveSpec,
                            fu.resolveFile(null, driveSpecLower + "/").getPath());
  -            assertEquals(driveSpec, 
  +            assertEquals(driveSpec,
                            fu.resolveFile(null, driveSpecLower + "\\").getPath());
               /*
                * promised to eliminate consecutive slashes after drive letter.
                */
  -            assertEquals(driveSpec, 
  +            assertEquals(driveSpec,
                            fu.resolveFile(null, driveSpec + "/////").getPath());
  -            assertEquals(driveSpec, 
  +            assertEquals(driveSpec,
                            fu.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath());
           }
   
  @@ -227,60 +227,60 @@
           /*
            * Start with simple absolute file names.
            */
  -        assertEquals(File.separator, 
  +        assertEquals(File.separator,
                        fu.normalize("/").getPath());
  -        assertEquals(File.separator, 
  +        assertEquals(File.separator,
                        fu.normalize("\\").getPath());
   
           /*
            * throw in drive letters
            */
           String driveSpec = "C:";
  -        assertEquals(driveSpec, 
  +        assertEquals(driveSpec,
                        fu.normalize(driveSpec).getPath());
  -        assertEquals(driveSpec + "\\", 
  +        assertEquals(driveSpec + "\\",
                        fu.normalize(driveSpec + "/").getPath());
  -        assertEquals(driveSpec + "\\", 
  +        assertEquals(driveSpec + "\\",
                        fu.normalize(driveSpec + "\\").getPath());
           String driveSpecLower = "c:";
  -        assertEquals(driveSpec + "\\", 
  +        assertEquals(driveSpec + "\\",
                        fu.normalize(driveSpecLower + "/").getPath());
  -        assertEquals(driveSpec + "\\", 
  +        assertEquals(driveSpec + "\\",
                        fu.normalize(driveSpecLower + "\\").getPath());
           /*
            * promised to eliminate consecutive slashes after drive letter.
            */
  -        assertEquals(driveSpec + "\\", 
  +        assertEquals(driveSpec + "\\",
                        fu.normalize(driveSpec + "/////").getPath());
  -        assertEquals(driveSpec + "\\", 
  +        assertEquals(driveSpec + "\\",
                        fu.normalize(driveSpec + "\\\\\\\\\\\\").getPath());
   
           if (Os.isFamily("netware")) {
               /*
  -             * throw in NetWare volume names 
  +             * throw in NetWare volume names
                */
               driveSpec = "SYS:";
  -            assertEquals(driveSpec, 
  +            assertEquals(driveSpec,
                            fu.normalize(driveSpec).getPath());
  -            assertEquals(driveSpec, 
  +            assertEquals(driveSpec,
                            fu.normalize(driveSpec + "/").getPath());
  -            assertEquals(driveSpec, 
  +            assertEquals(driveSpec,
                            fu.normalize(driveSpec + "\\").getPath());
               driveSpecLower = "sys:";
  -            assertEquals(driveSpec, 
  +            assertEquals(driveSpec,
                            fu.normalize(driveSpecLower).getPath());
  -            assertEquals(driveSpec, 
  +            assertEquals(driveSpec,
                            fu.normalize(driveSpecLower + "/").getPath());
  -            assertEquals(driveSpec, 
  +            assertEquals(driveSpec,
                            fu.normalize(driveSpecLower + "\\").getPath());
  -            assertEquals(driveSpec + "\\junk", 
  +            assertEquals(driveSpec + "\\junk",
                            fu.normalize(driveSpecLower + "\\junk").getPath());
               /*
                * promised to eliminate consecutive slashes after drive letter.
                */
  -            assertEquals(driveSpec, 
  +            assertEquals(driveSpec,
                            fu.normalize(driveSpec + "/////").getPath());
  -            assertEquals(driveSpec, 
  +            assertEquals(driveSpec,
                            fu.normalize(driveSpec + "\\\\\\\\\\\\").getPath());
           }
   
  @@ -310,7 +310,7 @@
           } catch (BuildException e) {
               // Expected exception caught
           }
  -        
  +
           try {
               fu.normalize(localize("/1/../../b"));
               fail("successfully crawled beyond the filesystem root");
  @@ -329,7 +329,7 @@
           } catch (NullPointerException npe) {
               // Expected exception caught
           }
  -        
  +
           File f = fu.resolveFile(null, "a");
           assertEquals(f, new File("a"));
       }
  @@ -345,17 +345,18 @@
           String name = tmp1.getName();
           assertTrue("starts with pre", name.startsWith("pre"));
           assertTrue("ends with .suf", name.endsWith(".suf"));
  -        assertEquals("is inside parent dir", 
  +        assertEquals("is inside parent dir",
                        parent.getAbsolutePath(),
                        tmp1.getParent());
   
           File tmp2 = fu.createTempFile("pre", ".suf", parent);
  -        assertTrue("files are different", 
  +        assertTrue("files are different",
                      !tmp1.getAbsolutePath().equals(tmp2.getAbsolutePath()));
   
           // null parent dir
           File tmp3 = fu.createTempFile("pre", ".suf", null);
  -        assertEquals((new File(tmp3.getName())).getAbsolutePath(),
  +        String  tmploc = System.getProperty("java.io.tmpdir");
  +        assertEquals((new File(tmploc, tmp3.getName())).getAbsolutePath(),
                        tmp3.getAbsolutePath());
       }
   
  @@ -363,17 +364,17 @@
        * Test contentEquals
        */
       public void testContentEquals() throws IOException {
  -        assertTrue("Non existing files", fu.contentEquals(new File("foo"), 
  +        assertTrue("Non existing files", fu.contentEquals(new File("foo"),
                                                             new File("bar")));
  -        assertTrue("One exists, the other one doesn\'t", 
  +        assertTrue("One exists, the other one doesn\'t",
                      !fu.contentEquals(new File("foo"), new File("build.xml")));
           assertTrue("Don\'t compare directories",
                      !fu.contentEquals(new File("src"), new File("src")));
           assertTrue("File equals itself",
  -                   fu.contentEquals(new File("build.xml"), 
  +                   fu.contentEquals(new File("build.xml"),
                                       new File("build.xml")));
           assertTrue("Files are different",
  -                   !fu.contentEquals(new File("build.xml"), 
  +                   !fu.contentEquals(new File("build.xml"),
                                        new File("docs.xml")));
       }
   
  @@ -391,34 +392,34 @@
        * Test removeLeadingPath.
        */
       public void testRemoveLeadingPath() {
  -        assertEquals("bar", fu.removeLeadingPath(new File("/foo"), 
  +        assertEquals("bar", fu.removeLeadingPath(new File("/foo"),
                                                    new File("/foo/bar")));
  -        assertEquals("bar", fu.removeLeadingPath(new File("/foo/"), 
  +        assertEquals("bar", fu.removeLeadingPath(new File("/foo/"),
                                                    new File("/foo/bar")));
  -        assertEquals("bar", fu.removeLeadingPath(new File("\\foo"), 
  +        assertEquals("bar", fu.removeLeadingPath(new File("\\foo"),
                                                    new File("\\foo\\bar")));
  -        assertEquals("bar", fu.removeLeadingPath(new File("\\foo\\"), 
  +        assertEquals("bar", fu.removeLeadingPath(new File("\\foo\\"),
                                                    new File("\\foo\\bar")));
  -        assertEquals("bar", fu.removeLeadingPath(new File("c:/foo"), 
  +        assertEquals("bar", fu.removeLeadingPath(new File("c:/foo"),
                                                    new File("c:/foo/bar")));
  -        assertEquals("bar", fu.removeLeadingPath(new File("c:/foo/"), 
  +        assertEquals("bar", fu.removeLeadingPath(new File("c:/foo/"),
                                                    new File("c:/foo/bar")));
  -        assertEquals("bar", fu.removeLeadingPath(new File("c:\\foo"), 
  +        assertEquals("bar", fu.removeLeadingPath(new File("c:\\foo"),
                                                    new File("c:\\foo\\bar")));
  -        assertEquals("bar", fu.removeLeadingPath(new File("c:\\foo\\"), 
  +        assertEquals("bar", fu.removeLeadingPath(new File("c:\\foo\\"),
                                                    new File("c:\\foo\\bar")));
  -        assertEquals(fu.normalize("/bar").getAbsolutePath(), 
  +        assertEquals(fu.normalize("/bar").getAbsolutePath(),
                        fu.removeLeadingPath(new File("/foo"), new File("/bar")));
  -        assertEquals(fu.normalize("/foobar").getAbsolutePath(), 
  +        assertEquals(fu.normalize("/foobar").getAbsolutePath(),
                        fu.removeLeadingPath(new File("/foo"), new File("/foobar")));
           // bugzilla report 19979
  -        assertEquals("", fu.removeLeadingPath(new File("/foo/bar"), 
  +        assertEquals("", fu.removeLeadingPath(new File("/foo/bar"),
                                                 new File("/foo/bar")));
  -        assertEquals("", fu.removeLeadingPath(new File("/foo/bar"), 
  +        assertEquals("", fu.removeLeadingPath(new File("/foo/bar"),
                                                 new File("/foo/bar/")));
  -        assertEquals("", fu.removeLeadingPath(new File("/foo/bar/"), 
  +        assertEquals("", fu.removeLeadingPath(new File("/foo/bar/"),
                                                 new File("/foo/bar/")));
  -        assertEquals("", fu.removeLeadingPath(new File("/foo/bar/"), 
  +        assertEquals("", fu.removeLeadingPath(new File("/foo/bar/"),
                                                 new File("/foo/bar")));
       }
   
  @@ -455,7 +456,7 @@
               assertEquals("C:\\foo", fu.fromURI("file:///c:/foo"));
           }
           assertEquals(localize("/foo"), fu.fromURI("file:///foo"));
  -        assertEquals("." + File.separator + "foo", 
  +        assertEquals("." + File.separator + "foo",
                        fu.fromURI("file:./foo"));
           assertEquals(localize("/foo bar"), fu.fromURI("file:///foo%20bar"));
           assertEquals(localize("/foo#bar"), fu.fromURI("file:///foo%23bar"));
  
  
  

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


Mime
View raw message