|
|
@@ -30,13 +30,15 @@ import java.util.Optional; |
|
|
|
import org.apache.tools.ant.BuildException; |
|
|
|
import org.apache.tools.ant.MagicTestNames; |
|
|
|
import org.apache.tools.ant.taskdefs.condition.Os; |
|
|
|
import org.junit.After; |
|
|
|
import org.junit.Assert; |
|
|
|
import org.junit.Before; |
|
|
|
import org.junit.Rule; |
|
|
|
import org.junit.Test; |
|
|
|
import org.junit.rules.ExpectedException; |
|
|
|
import org.junit.rules.TemporaryFolder; |
|
|
|
|
|
|
|
import static org.apache.tools.ant.util.FileUtils.getFileUtils; |
|
|
|
import static org.apache.tools.ant.util.FileUtils.isCaseSensitiveFileSystem; |
|
|
|
import static org.apache.tools.ant.util.FileUtils.isContextRelativePath; |
|
|
|
import static org.hamcrest.Matchers.endsWith; |
|
|
|
import static org.hamcrest.Matchers.startsWith; |
|
|
|
import static org.junit.Assert.assertEquals; |
|
|
@@ -56,9 +58,10 @@ public class FileUtilsTest { |
|
|
|
@Rule |
|
|
|
public ExpectedException thrown = ExpectedException.none(); |
|
|
|
|
|
|
|
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); |
|
|
|
@Rule |
|
|
|
public TemporaryFolder folder = new TemporaryFolder(); |
|
|
|
|
|
|
|
private static final String ROOT = System.getProperty(MagicTestNames.TEST_ROOT_DIRECTORY); |
|
|
|
private File removeThis; |
|
|
|
private String root; |
|
|
|
|
|
|
|
@Before |
|
|
@@ -67,13 +70,6 @@ public class FileUtilsTest { |
|
|
|
root = new File(File.separator).getAbsolutePath().toUpperCase(); |
|
|
|
} |
|
|
|
|
|
|
|
@After |
|
|
|
public void tearDown() { |
|
|
|
if (removeThis != null && removeThis.exists() && !removeThis.delete()) { |
|
|
|
removeThis.deleteOnExit(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* test modification. |
|
|
|
* Since Ant1.7, the method being tested no longer uses |
|
|
@@ -86,17 +82,16 @@ public class FileUtilsTest { |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
public void testSetLastModified() throws IOException { |
|
|
|
removeThis = new File("dummy"); |
|
|
|
FileOutputStream fos = new FileOutputStream(removeThis); |
|
|
|
fos.write(new byte[0]); |
|
|
|
fos.close(); |
|
|
|
File removeThis = folder.newFile("dummy"); |
|
|
|
try (FileOutputStream fos = new FileOutputStream(removeThis)) { |
|
|
|
fos.write(new byte[0]); |
|
|
|
} |
|
|
|
assumeTrue("Could not change file modified time", |
|
|
|
removeThis.setLastModified(removeThis.lastModified() - 2000)); |
|
|
|
long modTime = removeThis.lastModified(); |
|
|
|
assertNotEquals(0, modTime); |
|
|
|
|
|
|
|
|
|
|
|
FILE_UTILS.setFileLastModified(removeThis, -1); |
|
|
|
getFileUtils().setFileLastModified(removeThis, -1); |
|
|
|
long secondModTime = removeThis.lastModified(); |
|
|
|
assertTrue(secondModTime > modTime); |
|
|
|
|
|
|
@@ -105,7 +100,7 @@ public class FileUtilsTest { |
|
|
|
// in a previous version, the date of the file was set to 123456 |
|
|
|
// milliseconds since 01.01.1970 |
|
|
|
// it did not work on a computer running JDK 1.4.1_02 + Windows 2000 |
|
|
|
FILE_UTILS.setFileLastModified(removeThis, secondModTime + millisperday); |
|
|
|
getFileUtils().setFileLastModified(removeThis, secondModTime + millisperday); |
|
|
|
long thirdModTime = removeThis.lastModified(); |
|
|
|
/* |
|
|
|
* I would love to compare this with 123456, but depending on |
|
|
@@ -122,37 +117,37 @@ public class FileUtilsTest { |
|
|
|
/* |
|
|
|
* Start with simple absolute file names. |
|
|
|
*/ |
|
|
|
assertEquals(File.separator, FILE_UTILS.resolveFile(null, "/").getPath()); |
|
|
|
assertEquals(File.separator, FILE_UTILS.resolveFile(null, "\\").getPath()); |
|
|
|
assertEquals(File.separator, getFileUtils().resolveFile(null, "/").getPath()); |
|
|
|
assertEquals(File.separator, getFileUtils().resolveFile(null, "\\").getPath()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testResolveFileDosOrNetware() { |
|
|
|
assumeTrue("Not DOS or Netware", Os.isFamily("dos") || Os.isFamily("netware")); |
|
|
|
assertEqualsIgnoreDriveCase(localize(File.separator), |
|
|
|
FILE_UTILS.resolveFile(null, "/").getPath()); |
|
|
|
getFileUtils().resolveFile(null, "/").getPath()); |
|
|
|
assertEqualsIgnoreDriveCase(localize(File.separator), |
|
|
|
FILE_UTILS.resolveFile(null, "\\").getPath()); |
|
|
|
getFileUtils().resolveFile(null, "\\").getPath()); |
|
|
|
/* |
|
|
|
* throw in drive letters |
|
|
|
*/ |
|
|
|
String driveSpec = "C:"; |
|
|
|
assertEquals(driveSpec + "\\", |
|
|
|
FILE_UTILS.resolveFile(null, driveSpec + "/").getPath()); |
|
|
|
getFileUtils().resolveFile(null, driveSpec + "/").getPath()); |
|
|
|
assertEquals(driveSpec + "\\", |
|
|
|
FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath()); |
|
|
|
getFileUtils().resolveFile(null, driveSpec + "\\").getPath()); |
|
|
|
String driveSpecLower = "c:"; |
|
|
|
assertEquals(driveSpecLower + "\\", |
|
|
|
FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath()); |
|
|
|
getFileUtils().resolveFile(null, driveSpecLower + "/").getPath()); |
|
|
|
assertEquals(driveSpecLower + "\\", |
|
|
|
FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath()); |
|
|
|
getFileUtils().resolveFile(null, driveSpecLower + "\\").getPath()); |
|
|
|
/* |
|
|
|
* promised to eliminate consecutive slashes after drive letter. |
|
|
|
*/ |
|
|
|
assertEquals(driveSpec + "\\", |
|
|
|
FILE_UTILS.resolveFile(null, driveSpec + "/////").getPath()); |
|
|
|
getFileUtils().resolveFile(null, driveSpec + "/////").getPath()); |
|
|
|
assertEquals(driveSpec + "\\", |
|
|
|
FILE_UTILS.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath()); |
|
|
|
getFileUtils().resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath()); |
|
|
|
|
|
|
|
if (Os.isFamily("netware")) { |
|
|
|
/* |
|
|
@@ -160,21 +155,21 @@ public class FileUtilsTest { |
|
|
|
*/ |
|
|
|
driveSpec = "SYS:"; |
|
|
|
assertEquals(driveSpec, |
|
|
|
FILE_UTILS.resolveFile(null, driveSpec + "/").getPath()); |
|
|
|
getFileUtils().resolveFile(null, driveSpec + "/").getPath()); |
|
|
|
assertEquals(driveSpec, |
|
|
|
FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath()); |
|
|
|
getFileUtils().resolveFile(null, driveSpec + "\\").getPath()); |
|
|
|
driveSpecLower = "sys:"; |
|
|
|
assertEquals(driveSpec, |
|
|
|
FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath()); |
|
|
|
getFileUtils().resolveFile(null, driveSpecLower + "/").getPath()); |
|
|
|
assertEquals(driveSpec, |
|
|
|
FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath()); |
|
|
|
getFileUtils().resolveFile(null, driveSpecLower + "\\").getPath()); |
|
|
|
/* |
|
|
|
* promised to eliminate consecutive slashes after drive letter. |
|
|
|
*/ |
|
|
|
assertEquals(driveSpec, |
|
|
|
FILE_UTILS.resolveFile(null, driveSpec + "/////").getPath()); |
|
|
|
getFileUtils().resolveFile(null, driveSpec + "/////").getPath()); |
|
|
|
assertEquals(driveSpec, |
|
|
|
FILE_UTILS.resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath()); |
|
|
|
getFileUtils().resolveFile(null, driveSpec + "\\\\\\\\\\\\").getPath()); |
|
|
|
} |
|
|
|
} |
|
|
|
@Test |
|
|
@@ -186,14 +181,14 @@ public class FileUtilsTest { |
|
|
|
String driveSpec = "C:"; |
|
|
|
String udir = System.getProperty("user.dir"); |
|
|
|
assertEquals(udir + File.separator + driveSpec, |
|
|
|
FILE_UTILS.resolveFile(null, driveSpec + "/").getPath()); |
|
|
|
getFileUtils().resolveFile(null, driveSpec + "/").getPath()); |
|
|
|
assertEquals(udir + File.separator + driveSpec, |
|
|
|
FILE_UTILS.resolveFile(null, driveSpec + "\\").getPath()); |
|
|
|
getFileUtils().resolveFile(null, driveSpec + "\\").getPath()); |
|
|
|
String driveSpecLower = "c:"; |
|
|
|
assertEquals(udir + File.separator + driveSpecLower, |
|
|
|
FILE_UTILS.resolveFile(null, driveSpecLower + "/").getPath()); |
|
|
|
getFileUtils().resolveFile(null, driveSpecLower + "/").getPath()); |
|
|
|
assertEquals(udir + File.separator + driveSpecLower, |
|
|
|
FILE_UTILS.resolveFile(null, driveSpecLower + "\\").getPath()); |
|
|
|
getFileUtils().resolveFile(null, driveSpecLower + "\\").getPath()); |
|
|
|
} |
|
|
|
|
|
|
|
/* |
|
|
@@ -202,25 +197,25 @@ public class FileUtilsTest { |
|
|
|
@Test |
|
|
|
public void testResolveRelativeFile() { |
|
|
|
assertEquals(localize("/1/2/3/4"), |
|
|
|
FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "4").getPath()); |
|
|
|
getFileUtils().resolveFile(new File(localize("/1/2/3")), "4").getPath()); |
|
|
|
assertEquals(localize("/1/2/3/4"), |
|
|
|
FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "./4").getPath()); |
|
|
|
getFileUtils().resolveFile(new File(localize("/1/2/3")), "./4").getPath()); |
|
|
|
assertEquals(localize("/1/2/3/4"), |
|
|
|
FILE_UTILS.resolveFile(new File(localize("/1/2/3")), ".\\4").getPath()); |
|
|
|
getFileUtils().resolveFile(new File(localize("/1/2/3")), ".\\4").getPath()); |
|
|
|
assertEquals(localize("/1/2/3/4"), |
|
|
|
FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "./.\\4").getPath()); |
|
|
|
getFileUtils().resolveFile(new File(localize("/1/2/3")), "./.\\4").getPath()); |
|
|
|
assertEquals(localize("/1/2/3/4"), |
|
|
|
FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "../3/4").getPath()); |
|
|
|
getFileUtils().resolveFile(new File(localize("/1/2/3")), "../3/4").getPath()); |
|
|
|
assertEquals(localize("/1/2/3/4"), |
|
|
|
FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "..\\3\\4").getPath()); |
|
|
|
getFileUtils().resolveFile(new File(localize("/1/2/3")), "..\\3\\4").getPath()); |
|
|
|
assertEquals(localize("/1/2/3/4"), |
|
|
|
FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "../../5/.././2/./3/6/../4").getPath()); |
|
|
|
getFileUtils().resolveFile(new File(localize("/1/2/3")), "../../5/.././2/./3/6/../4").getPath()); |
|
|
|
assertEquals(localize("/1/2/3/4"), |
|
|
|
FILE_UTILS.resolveFile(new File(localize("/1/2/3")), "..\\../5/..\\./2/./3/6\\../4").getPath()); |
|
|
|
getFileUtils().resolveFile(new File(localize("/1/2/3")), "..\\../5/..\\./2/./3/6\\../4").getPath()); |
|
|
|
|
|
|
|
assertEquals("meaningless result but no exception", |
|
|
|
new File(localize("/1/../../b")), |
|
|
|
FILE_UTILS.resolveFile(new File(localize("/1")), "../../b")); |
|
|
|
getFileUtils().resolveFile(new File(localize("/1")), "../../b")); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
@@ -230,27 +225,27 @@ public class FileUtilsTest { |
|
|
|
/* |
|
|
|
* Start with simple absolute file names. |
|
|
|
*/ |
|
|
|
assertEquals(File.separator, FILE_UTILS.normalize("/").getPath()); |
|
|
|
assertEquals(File.separator, FILE_UTILS.normalize("\\").getPath()); |
|
|
|
assertEquals(File.separator, getFileUtils().normalize("/").getPath()); |
|
|
|
assertEquals(File.separator, getFileUtils().normalize("\\").getPath()); |
|
|
|
|
|
|
|
// Expected exception caught |
|
|
|
thrown.expect(BuildException.class); |
|
|
|
String driveSpec = "C:"; |
|
|
|
assertEquals(driveSpec, FILE_UTILS.normalize(driveSpec).getPath()); |
|
|
|
assertEquals(driveSpec, getFileUtils().normalize(driveSpec).getPath()); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testNormalizeSlashDosOrNetware() { |
|
|
|
assumeTrue("Not DOS or Netware", Os.isFamily("dos") || Os.isFamily("netware")); |
|
|
|
thrown.expect(BuildException.class); |
|
|
|
FILE_UTILS.normalize("/").getPath(); |
|
|
|
getFileUtils().normalize("/").getPath(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testNormalizeBackSlashDosOrNetware() { |
|
|
|
assumeTrue("Not DOS or Netware", Os.isFamily("dos") || Os.isFamily("netware")); |
|
|
|
thrown.expect(BuildException.class); |
|
|
|
FILE_UTILS.normalize("\\").getPath(); |
|
|
|
getFileUtils().normalize("\\").getPath(); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
@@ -262,52 +257,52 @@ public class FileUtilsTest { |
|
|
|
*/ |
|
|
|
String driveSpec = "C:"; |
|
|
|
assertEquals(driveSpec + "\\", |
|
|
|
FILE_UTILS.normalize(driveSpec + "/").getPath()); |
|
|
|
getFileUtils().normalize(driveSpec + "/").getPath()); |
|
|
|
assertEquals(driveSpec + "\\", |
|
|
|
FILE_UTILS.normalize(driveSpec + "\\").getPath()); |
|
|
|
getFileUtils().normalize(driveSpec + "\\").getPath()); |
|
|
|
String driveSpecLower = "c:"; |
|
|
|
assertEquals(driveSpecLower + "\\", |
|
|
|
FILE_UTILS.normalize(driveSpecLower + "/").getPath()); |
|
|
|
getFileUtils().normalize(driveSpecLower + "/").getPath()); |
|
|
|
assertEquals(driveSpecLower + "\\", |
|
|
|
FILE_UTILS.normalize(driveSpecLower + "\\").getPath()); |
|
|
|
getFileUtils().normalize(driveSpecLower + "\\").getPath()); |
|
|
|
/* |
|
|
|
* promised to eliminate consecutive slashes after drive letter. |
|
|
|
*/ |
|
|
|
assertEquals(driveSpec + "\\", |
|
|
|
FILE_UTILS.normalize(driveSpec + "/////").getPath()); |
|
|
|
getFileUtils().normalize(driveSpec + "/////").getPath()); |
|
|
|
assertEquals(driveSpec + "\\", |
|
|
|
FILE_UTILS.normalize(driveSpec + "\\\\\\\\\\\\").getPath()); |
|
|
|
getFileUtils().normalize(driveSpec + "\\\\\\\\\\\\").getPath()); |
|
|
|
|
|
|
|
// Expected exception caught |
|
|
|
thrown.expect(BuildException.class); |
|
|
|
FILE_UTILS.normalize(driveSpec).getPath(); |
|
|
|
getFileUtils().normalize(driveSpec).getPath(); |
|
|
|
} else if (Os.isFamily("netware")) { |
|
|
|
/* |
|
|
|
* throw in NetWare volume names |
|
|
|
*/ |
|
|
|
String driveSpec = "SYS:"; |
|
|
|
assertEquals(driveSpec, |
|
|
|
FILE_UTILS.normalize(driveSpec).getPath()); |
|
|
|
getFileUtils().normalize(driveSpec).getPath()); |
|
|
|
assertEquals(driveSpec, |
|
|
|
FILE_UTILS.normalize(driveSpec + "/").getPath()); |
|
|
|
getFileUtils().normalize(driveSpec + "/").getPath()); |
|
|
|
assertEquals(driveSpec, |
|
|
|
FILE_UTILS.normalize(driveSpec + "\\").getPath()); |
|
|
|
getFileUtils().normalize(driveSpec + "\\").getPath()); |
|
|
|
String driveSpecLower = "sys:"; |
|
|
|
assertEquals(driveSpec, |
|
|
|
FILE_UTILS.normalize(driveSpecLower).getPath()); |
|
|
|
getFileUtils().normalize(driveSpecLower).getPath()); |
|
|
|
assertEquals(driveSpec, |
|
|
|
FILE_UTILS.normalize(driveSpecLower + "/").getPath()); |
|
|
|
getFileUtils().normalize(driveSpecLower + "/").getPath()); |
|
|
|
assertEquals(driveSpec, |
|
|
|
FILE_UTILS.normalize(driveSpecLower + "\\").getPath()); |
|
|
|
getFileUtils().normalize(driveSpecLower + "\\").getPath()); |
|
|
|
assertEquals(driveSpec + "\\junk", |
|
|
|
FILE_UTILS.normalize(driveSpecLower + "\\junk").getPath()); |
|
|
|
getFileUtils().normalize(driveSpecLower + "\\junk").getPath()); |
|
|
|
/* |
|
|
|
* promised to eliminate consecutive slashes after drive letter. |
|
|
|
*/ |
|
|
|
assertEquals(driveSpec, |
|
|
|
FILE_UTILS.normalize(driveSpec + "/////").getPath()); |
|
|
|
getFileUtils().normalize(driveSpec + "/////").getPath()); |
|
|
|
assertEquals(driveSpec, |
|
|
|
FILE_UTILS.normalize(driveSpec + "\\\\\\\\\\\\").getPath()); |
|
|
|
getFileUtils().normalize(driveSpec + "\\\\\\\\\\\\").getPath()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
@@ -317,29 +312,29 @@ public class FileUtilsTest { |
|
|
|
@Test |
|
|
|
public void testNormalizeRelativeFile() { |
|
|
|
assertEquals(localize("/1/2/3/4"), |
|
|
|
FILE_UTILS.normalize(localize("/1/2/3/4")).getPath()); |
|
|
|
getFileUtils().normalize(localize("/1/2/3/4")).getPath()); |
|
|
|
assertEquals(localize("/1/2/3/4"), |
|
|
|
FILE_UTILS.normalize(localize("/1/2/3/./4")).getPath()); |
|
|
|
getFileUtils().normalize(localize("/1/2/3/./4")).getPath()); |
|
|
|
assertEquals(localize("/1/2/3/4"), |
|
|
|
FILE_UTILS.normalize(localize("/1/2/3/.\\4")).getPath()); |
|
|
|
getFileUtils().normalize(localize("/1/2/3/.\\4")).getPath()); |
|
|
|
assertEquals(localize("/1/2/3/4"), |
|
|
|
FILE_UTILS.normalize(localize("/1/2/3/./.\\4")).getPath()); |
|
|
|
getFileUtils().normalize(localize("/1/2/3/./.\\4")).getPath()); |
|
|
|
assertEquals(localize("/1/2/3/4"), |
|
|
|
FILE_UTILS.normalize(localize("/1/2/3/../3/4")).getPath()); |
|
|
|
getFileUtils().normalize(localize("/1/2/3/../3/4")).getPath()); |
|
|
|
assertEquals(localize("/1/2/3/4"), |
|
|
|
FILE_UTILS.normalize(localize("/1/2/3/..\\3\\4")).getPath()); |
|
|
|
getFileUtils().normalize(localize("/1/2/3/..\\3\\4")).getPath()); |
|
|
|
assertEquals(localize("/1/2/3/4"), |
|
|
|
FILE_UTILS.normalize(localize("/1/2/3/../../5/.././2/./3/6/../4")).getPath()); |
|
|
|
getFileUtils().normalize(localize("/1/2/3/../../5/.././2/./3/6/../4")).getPath()); |
|
|
|
assertEquals(localize("/1/2/3/4"), |
|
|
|
FILE_UTILS.normalize(localize("/1/2/3/..\\../5/..\\./2/./3/6\\../4")).getPath()); |
|
|
|
getFileUtils().normalize(localize("/1/2/3/..\\../5/..\\./2/./3/6\\../4")).getPath()); |
|
|
|
|
|
|
|
assertEquals("will not go outside FS root (but will not throw an exception either)", |
|
|
|
new File(localize("/1/../../b")), |
|
|
|
FILE_UTILS.normalize(localize("/1/../../b"))); |
|
|
|
getFileUtils().normalize(localize("/1/../../b"))); |
|
|
|
|
|
|
|
// Expected exception caught |
|
|
|
thrown.expect(BuildException.class); |
|
|
|
FILE_UTILS.normalize("foo"); |
|
|
|
getFileUtils().normalize("foo"); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -347,22 +342,21 @@ public class FileUtilsTest { |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
public void testNullArgs() { |
|
|
|
File f = FILE_UTILS.resolveFile(null, "a"); |
|
|
|
File f = getFileUtils().resolveFile(null, "a"); |
|
|
|
assertEquals(f, new File("a").getAbsoluteFile()); |
|
|
|
|
|
|
|
// Expected exception caught |
|
|
|
thrown.expect(NullPointerException.class); |
|
|
|
FILE_UTILS.normalize(null); |
|
|
|
getFileUtils().normalize(null); |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
* Test createTempFile |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
public void testCreateTempFile() { |
|
|
|
public void testCreateTempFile() throws IOException { |
|
|
|
// null parent dir |
|
|
|
File tmp1 = FILE_UTILS.createTempFile("pre", ".suf", null, false, true); |
|
|
|
File tmp1 = getFileUtils().createTempFile("pre", ".suf", null, false, true); |
|
|
|
String tmploc = System.getProperty("java.io.tmpdir"); |
|
|
|
String name = tmp1.getName(); |
|
|
|
assertThat("starts with pre", name, startsWith("pre")); |
|
|
@@ -372,11 +366,9 @@ public class FileUtilsTest { |
|
|
|
tmp1.getAbsolutePath()); |
|
|
|
tmp1.delete(); |
|
|
|
|
|
|
|
File dir2 = new File(tmploc + "/ant-test"); |
|
|
|
dir2.mkdir(); |
|
|
|
removeThis = dir2; |
|
|
|
File dir2 = folder.newFolder("ant-test"); |
|
|
|
|
|
|
|
File tmp2 = FILE_UTILS.createTempFile("pre", ".suf", dir2, true, true); |
|
|
|
File tmp2 = getFileUtils().createTempFile("pre", ".suf", dir2, true, true); |
|
|
|
String name2 = tmp2.getName(); |
|
|
|
assertThat("starts with pre", name2, startsWith("pre")); |
|
|
|
assertThat("ends with .suf", name2, endsWith(".suf")); |
|
|
@@ -384,10 +376,9 @@ public class FileUtilsTest { |
|
|
|
assertEquals((new File(dir2, tmp2.getName())).getAbsolutePath(), |
|
|
|
tmp2.getAbsolutePath()); |
|
|
|
tmp2.delete(); |
|
|
|
dir2.delete(); |
|
|
|
|
|
|
|
File parent = new File((new File("/tmp")).getAbsolutePath()); |
|
|
|
tmp1 = FILE_UTILS.createTempFile("pre", ".suf", parent, false); |
|
|
|
tmp1 = getFileUtils().createTempFile("pre", ".suf", parent, false); |
|
|
|
assertFalse("new file", tmp1.exists()); |
|
|
|
|
|
|
|
name = tmp1.getName(); |
|
|
@@ -396,11 +387,11 @@ public class FileUtilsTest { |
|
|
|
assertEquals("is inside parent dir", parent.getAbsolutePath(), tmp1 |
|
|
|
.getParent()); |
|
|
|
|
|
|
|
tmp2 = FILE_UTILS.createTempFile("pre", ".suf", parent, false); |
|
|
|
tmp2 = getFileUtils().createTempFile("pre", ".suf", parent, false); |
|
|
|
assertNotEquals("files are different", tmp1.getAbsolutePath(), tmp2.getAbsolutePath()); |
|
|
|
|
|
|
|
// null parent dir |
|
|
|
File tmp3 = FILE_UTILS.createTempFile("pre", ".suf", null, false); |
|
|
|
File tmp3 = getFileUtils().createTempFile("pre", ".suf", null, false); |
|
|
|
tmploc = System.getProperty("java.io.tmpdir"); |
|
|
|
assertEquals((new File(tmploc, tmp3.getName())).getAbsolutePath(), |
|
|
|
tmp3.getAbsolutePath()); |
|
|
@@ -412,19 +403,19 @@ public class FileUtilsTest { |
|
|
|
@Test |
|
|
|
public void testContentEquals() throws IOException { |
|
|
|
assertTrue("Non existing files", |
|
|
|
FILE_UTILS.contentEquals(new File(ROOT, "foo"), |
|
|
|
getFileUtils().contentEquals(new File(ROOT, "foo"), |
|
|
|
new File(ROOT, "bar"))); |
|
|
|
assertFalse("One exists, the other one doesn\'t", |
|
|
|
FILE_UTILS.contentEquals(new File(ROOT, "foo"), |
|
|
|
getFileUtils().contentEquals(new File(ROOT, "foo"), |
|
|
|
new File(ROOT, "build.xml"))); |
|
|
|
assertFalse("Don\'t compare directories", |
|
|
|
FILE_UTILS.contentEquals(new File(ROOT, "src"), |
|
|
|
getFileUtils().contentEquals(new File(ROOT, "src"), |
|
|
|
new File(ROOT, "src"))); |
|
|
|
assertTrue("File equals itself", |
|
|
|
FILE_UTILS.contentEquals(new File(ROOT, "build.xml"), |
|
|
|
getFileUtils().contentEquals(new File(ROOT, "build.xml"), |
|
|
|
new File(ROOT, "build.xml"))); |
|
|
|
assertFalse("Files are different", |
|
|
|
FILE_UTILS.contentEquals(new File(ROOT, "build.xml"), |
|
|
|
getFileUtils().contentEquals(new File(ROOT, "build.xml"), |
|
|
|
new File(ROOT, "docs.xml"))); |
|
|
|
} |
|
|
|
|
|
|
@@ -433,9 +424,10 @@ public class FileUtilsTest { |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
public void testCreateNewFile() throws IOException { |
|
|
|
removeThis = new File("dummy"); |
|
|
|
File removeThis = new File("dummy"); |
|
|
|
removeThis.deleteOnExit(); |
|
|
|
assertFalse(removeThis.exists()); |
|
|
|
FILE_UTILS.createNewFile(removeThis); |
|
|
|
getFileUtils().createNewFile(removeThis); |
|
|
|
assertTrue(removeThis.exists()); |
|
|
|
} |
|
|
|
|
|
|
@@ -444,45 +436,45 @@ public class FileUtilsTest { |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
public void testRemoveLeadingPath() { |
|
|
|
assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("/foo"), |
|
|
|
assertEquals("bar", getFileUtils().removeLeadingPath(new File("/foo"), |
|
|
|
new File("/foo/bar"))); |
|
|
|
assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("/foo/"), |
|
|
|
assertEquals("bar", getFileUtils().removeLeadingPath(new File("/foo/"), |
|
|
|
new File("/foo/bar"))); |
|
|
|
assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("\\foo"), |
|
|
|
assertEquals("bar", getFileUtils().removeLeadingPath(new File("\\foo"), |
|
|
|
new File("\\foo\\bar"))); |
|
|
|
assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("\\foo\\"), |
|
|
|
assertEquals("bar", getFileUtils().removeLeadingPath(new File("\\foo\\"), |
|
|
|
new File("\\foo\\bar"))); |
|
|
|
assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:/foo"), |
|
|
|
assertEquals("bar", getFileUtils().removeLeadingPath(new File("c:/foo"), |
|
|
|
new File("c:/foo/bar"))); |
|
|
|
assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:/foo/"), |
|
|
|
assertEquals("bar", getFileUtils().removeLeadingPath(new File("c:/foo/"), |
|
|
|
new File("c:/foo/bar"))); |
|
|
|
assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:\\foo"), |
|
|
|
assertEquals("bar", getFileUtils().removeLeadingPath(new File("c:\\foo"), |
|
|
|
new File("c:\\foo\\bar"))); |
|
|
|
assertEquals("bar", FILE_UTILS.removeLeadingPath(new File("c:\\foo\\"), |
|
|
|
assertEquals("bar", getFileUtils().removeLeadingPath(new File("c:\\foo\\"), |
|
|
|
new File("c:\\foo\\bar"))); |
|
|
|
if (!Os.isFamily("dos") && !Os.isFamily("netware")) { |
|
|
|
assertEquals(FILE_UTILS.normalize("/bar").getAbsolutePath(), |
|
|
|
FILE_UTILS.removeLeadingPath(new File("/foo"), new File("/bar"))); |
|
|
|
assertEquals(FILE_UTILS.normalize("/foobar").getAbsolutePath(), |
|
|
|
FILE_UTILS.removeLeadingPath(new File("/foo"), new File("/foobar"))); |
|
|
|
assertEquals(getFileUtils().normalize("/bar").getAbsolutePath(), |
|
|
|
getFileUtils().removeLeadingPath(new File("/foo"), new File("/bar"))); |
|
|
|
assertEquals(getFileUtils().normalize("/foobar").getAbsolutePath(), |
|
|
|
getFileUtils().removeLeadingPath(new File("/foo"), new File("/foobar"))); |
|
|
|
} |
|
|
|
// bugzilla report 19979 |
|
|
|
assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar"), |
|
|
|
assertEquals("", getFileUtils().removeLeadingPath(new File("/foo/bar"), |
|
|
|
new File("/foo/bar"))); |
|
|
|
assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar"), |
|
|
|
assertEquals("", getFileUtils().removeLeadingPath(new File("/foo/bar"), |
|
|
|
new File("/foo/bar/"))); |
|
|
|
assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar/"), |
|
|
|
assertEquals("", getFileUtils().removeLeadingPath(new File("/foo/bar/"), |
|
|
|
new File("/foo/bar/"))); |
|
|
|
assertEquals("", FILE_UTILS.removeLeadingPath(new File("/foo/bar/"), |
|
|
|
assertEquals("", getFileUtils().removeLeadingPath(new File("/foo/bar/"), |
|
|
|
new File("/foo/bar"))); |
|
|
|
|
|
|
|
String expected = "foo/bar".replace('\\', File.separatorChar) |
|
|
|
.replace('/', File.separatorChar); |
|
|
|
assertEquals(expected, FILE_UTILS.removeLeadingPath(new File("/"), |
|
|
|
assertEquals(expected, getFileUtils().removeLeadingPath(new File("/"), |
|
|
|
new File("/foo/bar"))); |
|
|
|
assertEquals(expected, FILE_UTILS.removeLeadingPath(new File("c:/"), |
|
|
|
assertEquals(expected, getFileUtils().removeLeadingPath(new File("c:/"), |
|
|
|
new File("c:/foo/bar"))); |
|
|
|
assertEquals(expected, FILE_UTILS.removeLeadingPath(new File("c:\\"), |
|
|
|
assertEquals(expected, getFileUtils().removeLeadingPath(new File("c:\\"), |
|
|
|
new File("c:\\foo\\bar"))); |
|
|
|
} |
|
|
|
|
|
|
@@ -499,28 +491,28 @@ public class FileUtilsTest { |
|
|
|
dosRoot = ""; |
|
|
|
} |
|
|
|
if (Os.isFamily("dos")) { |
|
|
|
assertEquals("file:/c:/foo", removeExtraneousAuthority(FILE_UTILS.toURI("c:\\foo"))); |
|
|
|
assertEquals("file:/c:/foo", removeExtraneousAuthority(getFileUtils().toURI("c:\\foo"))); |
|
|
|
} |
|
|
|
if (Os.isFamily("netware")) { |
|
|
|
assertEquals("file:/SYS:/foo", removeExtraneousAuthority(FILE_UTILS.toURI("sys:\\foo"))); |
|
|
|
assertEquals("file:/SYS:/foo", removeExtraneousAuthority(getFileUtils().toURI("sys:\\foo"))); |
|
|
|
} |
|
|
|
if (File.pathSeparatorChar == '/') { |
|
|
|
assertEquals("file:/foo", removeExtraneousAuthority(FILE_UTILS.toURI("/foo"))); |
|
|
|
assertThat("file: URIs must name absolute paths", FILE_UTILS.toURI("./foo"), startsWith("file:/")); |
|
|
|
assertThat(FILE_UTILS.toURI("./foo"), endsWith("/foo")); |
|
|
|
assertEquals("file:/" + dosRoot + "foo%20bar", removeExtraneousAuthority(FILE_UTILS.toURI("/foo bar"))); |
|
|
|
assertEquals("file:/" + dosRoot + "foo%23bar", removeExtraneousAuthority(FILE_UTILS.toURI("/foo#bar"))); |
|
|
|
assertEquals("file:/foo", removeExtraneousAuthority(getFileUtils().toURI("/foo"))); |
|
|
|
assertThat("file: URIs must name absolute paths", getFileUtils().toURI("./foo"), startsWith("file:/")); |
|
|
|
assertThat(getFileUtils().toURI("./foo"), endsWith("/foo")); |
|
|
|
assertEquals("file:/" + dosRoot + "foo%20bar", removeExtraneousAuthority(getFileUtils().toURI("/foo bar"))); |
|
|
|
assertEquals("file:/" + dosRoot + "foo%23bar", removeExtraneousAuthority(getFileUtils().toURI("/foo#bar"))); |
|
|
|
} else if (File.pathSeparatorChar == '\\') { |
|
|
|
assertEquals("file:/" + dosRoot + "foo", removeExtraneousAuthority(FILE_UTILS.toURI("\\foo"))); |
|
|
|
assertThat("file: URIs must name absolute paths", FILE_UTILS.toURI(".\\foo"), startsWith("file:/")); |
|
|
|
assertThat(FILE_UTILS.toURI(".\\foo"), endsWith("/foo")); |
|
|
|
assertEquals("file:/" + dosRoot + "foo%20bar", removeExtraneousAuthority(FILE_UTILS.toURI("\\foo bar"))); |
|
|
|
assertEquals("file:/" + dosRoot + "foo%23bar", removeExtraneousAuthority(FILE_UTILS.toURI("\\foo#bar"))); |
|
|
|
assertEquals("file:/" + dosRoot + "foo", removeExtraneousAuthority(getFileUtils().toURI("\\foo"))); |
|
|
|
assertThat("file: URIs must name absolute paths", getFileUtils().toURI(".\\foo"), startsWith("file:/")); |
|
|
|
assertThat(getFileUtils().toURI(".\\foo"), endsWith("/foo")); |
|
|
|
assertEquals("file:/" + dosRoot + "foo%20bar", removeExtraneousAuthority(getFileUtils().toURI("\\foo bar"))); |
|
|
|
assertEquals("file:/" + dosRoot + "foo%23bar", removeExtraneousAuthority(getFileUtils().toURI("\\foo#bar"))); |
|
|
|
} |
|
|
|
// a test with ant for germans |
|
|
|
// the escaped character used for the test is the "a umlaut" |
|
|
|
// this is the fix for the bug 37348 |
|
|
|
assertEquals("file:/" + dosRoot + "%C3%A4nt", removeExtraneousAuthority(FILE_UTILS.toURI("/\u00E4nt"))); |
|
|
|
assertEquals("file:/" + dosRoot + "%C3%A4nt", removeExtraneousAuthority(getFileUtils().toURI("/\u00E4nt"))); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -539,8 +531,8 @@ public class FileUtilsTest { |
|
|
|
@Test |
|
|
|
public void testIsContextRelativePath() { |
|
|
|
assumeTrue("Test only runs on DOS", Os.isFamily("dos")); |
|
|
|
assertTrue(FileUtils.isContextRelativePath("/\u00E4nt")); |
|
|
|
assertTrue(FileUtils.isContextRelativePath("\\foo")); |
|
|
|
assertTrue(isContextRelativePath("/\u00E4nt")); |
|
|
|
assertTrue(isContextRelativePath("\\foo")); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -555,16 +547,16 @@ public class FileUtilsTest { |
|
|
|
dosRoot = ""; |
|
|
|
} |
|
|
|
if (Os.isFamily("netware")) { |
|
|
|
assertEqualsIgnoreDriveCase("SYS:\\foo", FILE_UTILS.fromURI("file:///sys:/foo")); |
|
|
|
assertEqualsIgnoreDriveCase("SYS:\\foo", getFileUtils().fromURI("file:///sys:/foo")); |
|
|
|
} |
|
|
|
if (Os.isFamily("dos")) { |
|
|
|
assertEqualsIgnoreDriveCase("C:\\foo", FILE_UTILS.fromURI("file:///c:/foo")); |
|
|
|
assertEqualsIgnoreDriveCase("C:\\foo", getFileUtils().fromURI("file:///c:/foo")); |
|
|
|
} |
|
|
|
assertEqualsIgnoreDriveCase(dosRoot + File.separator + "foo", FILE_UTILS.fromURI("file:///foo")); |
|
|
|
assertEqualsIgnoreDriveCase(dosRoot + File.separator + "foo", getFileUtils().fromURI("file:///foo")); |
|
|
|
assertEquals("." + File.separator + "foo", |
|
|
|
FILE_UTILS.fromURI("file:./foo")); |
|
|
|
assertEquals(dosRoot + File.separator + "foo bar", FILE_UTILS.fromURI("file:///foo%20bar")); |
|
|
|
assertEquals(dosRoot + File.separator + "foo#bar", FILE_UTILS.fromURI("file:///foo%23bar")); |
|
|
|
getFileUtils().fromURI("file:./foo")); |
|
|
|
assertEquals(dosRoot + File.separator + "foo bar", getFileUtils().fromURI("file:///foo%20bar")); |
|
|
|
assertEquals(dosRoot + File.separator + "foo#bar", getFileUtils().fromURI("file:///foo%23bar")); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
@@ -581,30 +573,30 @@ public class FileUtilsTest { |
|
|
|
|
|
|
|
//check that older is up to date with a newer dest |
|
|
|
assertTrue("older source files are up to date", |
|
|
|
FILE_UTILS.isUpToDate(firstTime,secondTime)); |
|
|
|
getFileUtils().isUpToDate(firstTime,secondTime)); |
|
|
|
//check that older is up to date with a newer dest |
|
|
|
assertFalse("newer source files are no up to date", |
|
|
|
FILE_UTILS.isUpToDate(secondTime, firstTime)); |
|
|
|
getFileUtils().isUpToDate(secondTime, firstTime)); |
|
|
|
|
|
|
|
assertFalse("-1 dest timestamp implies nonexistence", |
|
|
|
FILE_UTILS.isUpToDate(firstTime, -1L)); |
|
|
|
getFileUtils().isUpToDate(firstTime, -1L)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void testHasErrorInCase() { |
|
|
|
File tempFolder = new File(System.getProperty("java.io.tmpdir")); |
|
|
|
File wellcased = FILE_UTILS.createTempFile("alpha", "beta", tempFolder, |
|
|
|
File wellcased = getFileUtils().createTempFile("alpha", "beta", tempFolder, |
|
|
|
true, true); |
|
|
|
String s = wellcased.getName().toUpperCase(); |
|
|
|
File wrongcased = new File(tempFolder, s); |
|
|
|
if (Os.isFamily("mac") && Os.isFamily("unix")) { |
|
|
|
//no guarantees on filesystem case-sensitivity |
|
|
|
} else if (Os.isFamily("dos")) { |
|
|
|
assertTrue(FILE_UTILS.hasErrorInCase(wrongcased)); |
|
|
|
assertFalse(FILE_UTILS.hasErrorInCase(wellcased)); |
|
|
|
assertTrue(getFileUtils().hasErrorInCase(wrongcased)); |
|
|
|
assertFalse(getFileUtils().hasErrorInCase(wellcased)); |
|
|
|
} else { |
|
|
|
assertFalse(FILE_UTILS.hasErrorInCase(wrongcased)); |
|
|
|
assertFalse(FILE_UTILS.hasErrorInCase(wellcased)); |
|
|
|
assertFalse(getFileUtils().hasErrorInCase(wrongcased)); |
|
|
|
assertFalse(getFileUtils().hasErrorInCase(wellcased)); |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
@@ -612,7 +604,7 @@ public class FileUtilsTest { |
|
|
|
@Test |
|
|
|
public void testGetDefaultEncoding() { |
|
|
|
// This just tests that the function does not blow up |
|
|
|
FILE_UTILS.getDefaultEncoding(); |
|
|
|
getFileUtils().getDefaultEncoding(); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -620,9 +612,9 @@ public class FileUtilsTest { |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
public void isLeadingPathCannotBeFooledByTooManyDoubleDots() { |
|
|
|
assertFalse(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/../../bar"))); |
|
|
|
assertFalse(FILE_UTILS.isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\..\\..\\bar"))); |
|
|
|
assertFalse(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/../.."))); |
|
|
|
assertFalse(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/../../bar"))); |
|
|
|
assertFalse(getFileUtils().isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\..\\..\\bar"))); |
|
|
|
assertFalse(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/../.."))); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -630,61 +622,61 @@ public class FileUtilsTest { |
|
|
|
*/ |
|
|
|
@Test |
|
|
|
public void isLeadingPathCanonicalVersionCannotBeFooledByTooManyDoubleDots() throws IOException { |
|
|
|
assertFalse(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/../../bar"), true)); |
|
|
|
assertFalse(FILE_UTILS.isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\..\\..\\bar"), true)); |
|
|
|
assertFalse(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/../.."), true)); |
|
|
|
assertFalse(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/../../bar"), true)); |
|
|
|
assertFalse(getFileUtils().isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\..\\..\\bar"), true)); |
|
|
|
assertFalse(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/../.."), true)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void isLeadingPathCanonicalVersionWorksAsExpectedOnUnix() throws IOException { |
|
|
|
assumeFalse("Test doesn't run on DOS", Os.isFamily("dos")); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/bar"), true)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/baz/../bar"), true)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/../foo/bar"), true)); |
|
|
|
assertFalse(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foobar"), true)); |
|
|
|
assertFalse(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/bar"), true)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/bar"), true)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/baz/../bar"), true)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/../foo/bar"), true)); |
|
|
|
assertFalse(getFileUtils().isLeadingPath(new File("/foo"), new File("/foobar"), true)); |
|
|
|
assertFalse(getFileUtils().isLeadingPath(new File("/foo"), new File("/bar"), true)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void isLeadingPathAndTrailingSlashesOnUnix() throws IOException { |
|
|
|
assumeFalse("Test doesn't run on DOS", Os.isFamily("dos")); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/bar"), true)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/bar/"), true)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/"), true)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo"), true)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/"), true)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("/foo/"), new File("/foo/bar"), true)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("/foo/"), new File("/foo/bar/"), true)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("/foo/"), new File("/foo/"), true)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("/foo/"), new File("/foo"), true)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/"), true)); |
|
|
|
|
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/bar"), false)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/bar/"), false)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo/"), false)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo/"), new File("/foo"), false)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("/foo"), new File("/foo/"), false)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("/foo/"), new File("/foo/bar"), false)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("/foo/"), new File("/foo/bar/"), false)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("/foo/"), new File("/foo/"), false)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("/foo/"), new File("/foo"), false)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("/foo"), new File("/foo/"), false)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void isLeadingPathCanonicalVersionWorksAsExpectedOnDos() throws IOException { |
|
|
|
assumeTrue("Test only runs on DOS", Os.isFamily("dos")); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("C:\\foo"), new File("C:\\foo\\bar"), true)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("C:\\foo"), new File("C:\\foo\\baz\\..\\bar"), true)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("C:\\foo"), new File("C:\\foo\\..\\foo\\bar"), true)); |
|
|
|
assertFalse(FILE_UTILS.isLeadingPath(new File("C:\\foo"), new File("C:\\foobar"), true)); |
|
|
|
assertFalse(FILE_UTILS.isLeadingPath(new File("C:\\foo"), new File("C:\\bar"), true)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("C:\\foo"), new File("C:\\foo\\bar"), true)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("C:\\foo"), new File("C:\\foo\\baz\\..\\bar"), true)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("C:\\foo"), new File("C:\\foo\\..\\foo\\bar"), true)); |
|
|
|
assertFalse(getFileUtils().isLeadingPath(new File("C:\\foo"), new File("C:\\foobar"), true)); |
|
|
|
assertFalse(getFileUtils().isLeadingPath(new File("C:\\foo"), new File("C:\\bar"), true)); |
|
|
|
} |
|
|
|
|
|
|
|
@Test |
|
|
|
public void isLeadingPathAndTrailingSlashesOnDos() throws IOException { |
|
|
|
assumeTrue("Test only runs on DOS", Os.isFamily("dos")); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar"), true)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar\\"), true)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\"), true)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo"), true)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\"), true)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar"), true)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar\\"), true)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\"), true)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo"), true)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\"), true)); |
|
|
|
|
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar"), false)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar\\"), false)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\"), false)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo"), false)); |
|
|
|
assertTrue(FILE_UTILS.isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\"), false)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar"), false)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\bar\\"), false)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo\\"), false)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo\\"), new File("c:\\foo"), false)); |
|
|
|
assertTrue(getFileUtils().isLeadingPath(new File("c:\\foo"), new File("c:\\foo\\"), false)); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
@@ -707,17 +699,18 @@ public class FileUtilsTest { |
|
|
|
final Boolean expectedCaseSensitivity = !existsAsLowerCase || !existsAsUpperCase; |
|
|
|
|
|
|
|
// call the method and pass it a directory |
|
|
|
Optional<Boolean> actualCaseSensitivity = FileUtils.isCaseSensitiveFileSystem(tmpDir); |
|
|
|
Assert.assertTrue("Filesystem case sensitivity was expected to be determined", actualCaseSensitivity.isPresent()); |
|
|
|
Assert.assertEquals("Filesystem was expected to be case " + (expectedCaseSensitivity |
|
|
|
Optional<Boolean> actualCaseSensitivity = isCaseSensitiveFileSystem(tmpDir); |
|
|
|
assertTrue("Filesystem case sensitivity was expected to be determined", actualCaseSensitivity.isPresent()); |
|
|
|
assertEquals("Filesystem was expected to be case " + (expectedCaseSensitivity |
|
|
|
? "sensitive" : "insensitive"), expectedCaseSensitivity, actualCaseSensitivity.get()); |
|
|
|
|
|
|
|
// now test it out by passing it a file |
|
|
|
actualCaseSensitivity = FileUtils.isCaseSensitiveFileSystem(tmpFile); |
|
|
|
Assert.assertTrue("Filesystem case sensitivity was expected to be determined", actualCaseSensitivity.isPresent()); |
|
|
|
Assert.assertEquals("Filesystem was expected to be case " + (expectedCaseSensitivity |
|
|
|
actualCaseSensitivity = isCaseSensitiveFileSystem(tmpFile); |
|
|
|
assertTrue("Filesystem case sensitivity was expected to be determined", actualCaseSensitivity.isPresent()); |
|
|
|
assertEquals("Filesystem was expected to be case " + (expectedCaseSensitivity |
|
|
|
? "sensitive" : "insensitive"), expectedCaseSensitivity, actualCaseSensitivity.get()); |
|
|
|
} |
|
|
|
|
|
|
|
/** |
|
|
|
* adapt file separators to local conventions |
|
|
|
*/ |
|
|
|