@@ -373,6 +373,6 @@ public class AntTypeDefinition { | |||
} | |||
private String extractClassname(Class<?> c) { | |||
return (c == null) ? "<null>" : c.getClass().getName(); | |||
return (c == null) ? "<null>" : c.getName(); | |||
} | |||
} |
@@ -126,7 +126,7 @@ public class ArgumentProcessorRegistry { | |||
processor = processorClass.getConstructor().newInstance(); | |||
} catch (Exception e) { | |||
throw new BuildException("The argument processor class" | |||
+ processorClass.getClass().getName() | |||
+ processorClass.getName() | |||
+ " could not be instantiated with a default constructor", | |||
e); | |||
} | |||
@@ -18,7 +18,6 @@ | |||
package org.apache.tools.ant.taskdefs; | |||
import java.io.IOException; | |||
import java.io.File; | |||
import java.nio.file.Files; | |||
import java.nio.file.Path; | |||
@@ -227,10 +227,7 @@ public class Sync extends Task { | |||
// set the case sensitivity of the directory scanner based on the | |||
// directory we are scanning, if we are able to determine that detail. | |||
// Else let the directory scanner default it to whatever it does internally | |||
final Optional<Boolean> caseSensitive = FileUtils.isCaseSensitiveFileSystem(toDir.toPath()); | |||
if (caseSensitive.isPresent()) { | |||
ds.setCaseSensitive(caseSensitive.get()); | |||
} | |||
FileUtils.isCaseSensitiveFileSystem(toDir.toPath()).ifPresent(ds::setCaseSensitive); | |||
} | |||
ds.addExcludes(excls); | |||
@@ -183,10 +183,8 @@ public class LauncherSupport { | |||
final List<TestRequest> requests = new ArrayList<>(); | |||
for (final TestDefinition test : tests) { | |||
final List<TestRequest> testRequests; | |||
if (test instanceof SingleTestClass) { | |||
testRequests = createTestRequests((SingleTestClass) test); | |||
} else if (test instanceof TestClasses) { | |||
testRequests = createTestRequests((TestClasses) test); | |||
if (test instanceof SingleTestClass || test instanceof TestClasses) { | |||
testRequests = createTestRequests(test); | |||
} else { | |||
throw new BuildException("Unexpected test definition type " + test.getClass().getName()); | |||
} | |||
@@ -37,9 +37,6 @@ import org.apache.tools.ant.taskdefs.condition.Os; | |||
*/ | |||
public final class JavaEnvUtils { | |||
private JavaEnvUtils() { | |||
} | |||
/** Are we on a DOS-based system */ | |||
private static final boolean IS_DOS = Os.isFamily("dos"); | |||
/** Are we on Novell NetWare */ | |||
@@ -146,6 +143,8 @@ public final class JavaEnvUtils { | |||
/** array of packages in the runtime */ | |||
private static Vector<String> jrePackages; | |||
private JavaEnvUtils() { | |||
} | |||
static { | |||
@@ -22,43 +22,38 @@ import java.io.File; | |||
import java.io.FileReader; | |||
import java.io.FileWriter; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.TemporaryFolder; | |||
import static org.hamcrest.Matchers.containsString; | |||
import static org.junit.Assert.assertThat; | |||
public class PropertyFileCLITest { | |||
@Rule | |||
public TemporaryFolder testFolder = new TemporaryFolder(); | |||
@Test | |||
public void testPropertyResolution() throws Exception { | |||
FileUtils fu = FileUtils.getFileUtils(); | |||
File props = fu.createTempFile("propertyfilecli", ".properties", | |||
null, true, true); | |||
File build = fu.createTempFile("propertyfilecli", ".xml", null, true, | |||
true); | |||
File log = fu.createTempFile("propertyfilecli", ".log", null, true, | |||
true); | |||
FileWriter fw = null; | |||
FileReader fr = null; | |||
try { | |||
fw = new FileWriter(props); | |||
File props = testFolder.newFile("propertyfilecli.properties"); | |||
try (FileWriter fw = new FileWriter(props)) { | |||
fw.write("w=world\nmessage=Hello, ${w}\n"); | |||
fw.close(); | |||
fw = new FileWriter(build); | |||
} | |||
File build = testFolder.newFile("propertyfilecli.xml"); | |||
try (FileWriter fw = new FileWriter(build)) { | |||
fw.write("<project><echo>${message}</echo></project>"); | |||
fw.close(); | |||
fw = null; | |||
Main m = new NoExitMain(); | |||
m.startAnt(new String[] { | |||
"-propertyfile", props.getAbsolutePath(), | |||
"-f", build.getAbsolutePath(), | |||
"-l", log.getAbsolutePath() | |||
}, null, null); | |||
String l = FileUtils.safeReadFully(fr = new FileReader(log)); | |||
assertThat(l, containsString("Hello, world")); | |||
} finally { | |||
FileUtils.close(fw); | |||
FileUtils.close(fr); | |||
} | |||
Main m = new NoExitMain(); | |||
File log = testFolder.newFile("propertyfilecli.log"); | |||
m.startAnt(new String[] { | |||
"-propertyfile", props.getAbsolutePath(), | |||
"-f", build.getAbsolutePath(), | |||
"-l", log.getAbsolutePath() | |||
}, null, null); | |||
try (FileReader fr = new FileReader(log)) { | |||
assertThat(FileUtils.safeReadFully(fr), containsString("Hello, world")); | |||
} | |||
} | |||
@@ -43,9 +43,6 @@ public class PropertyTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
/** Utilities used for file operations */ | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
@Before | |||
public void setUp() { | |||
buildRule.configureProject("src/etc/testcases/taskdefs/property.xml"); | |||
@@ -85,7 +82,7 @@ public class PropertyTest { | |||
@Test | |||
public void test5() { | |||
String baseDir = buildRule.getProject().getProperty(MagicNames.PROJECT_BASEDIR); | |||
String uri = FILE_UTILS.toURI(baseDir + "/property3.properties"); | |||
String uri = FileUtils.getFileUtils().toURI(baseDir + "/property3.properties"); | |||
buildRule.getProject().setNewProperty("test5.url", uri); | |||
buildRule.executeTarget("test5"); | |||
@@ -20,13 +20,10 @@ package org.apache.tools.ant.taskdefs; | |||
import org.apache.tools.ant.BuildFileRule; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.junit.Assume; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import java.util.Optional; | |||
import static org.hamcrest.Matchers.containsString; | |||
import static org.hamcrest.Matchers.not; | |||
import static org.junit.Assert.assertFalse; | |||
@@ -187,8 +187,7 @@ public class TouchTest { | |||
* @param time long | |||
*/ | |||
public void assertTimesNearlyMatch(long timestamp, long time) { | |||
long granularity = FILE_UTILS.getFileTimestampGranularity(); | |||
assertTimesNearlyMatch(timestamp, time, granularity); | |||
assertTimesNearlyMatch(timestamp, time, FILE_UTILS.getFileTimestampGranularity()); | |||
} | |||
/** | |||
@@ -18,19 +18,19 @@ | |||
package org.apache.tools.ant.taskdefs.email; | |||
import java.io.File; | |||
import java.io.FileOutputStream; | |||
import java.io.IOException; | |||
import java.io.PrintStream; | |||
import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.junit.After; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.TemporaryFolder; | |||
public class MessageTest { | |||
private static final File f = new File(System.getProperty("java.io.tmpdir"), | |||
"message.txt"); | |||
@Rule | |||
public TemporaryFolder testFolder = new TemporaryFolder(); | |||
/** | |||
* test for bugzilla 48932 | |||
*/ | |||
@@ -40,23 +40,9 @@ public class MessageTest { | |||
Project p = new Project(); | |||
ms.setProject(p); | |||
ms.addText("hi, this is an email"); | |||
FileOutputStream fis = null; | |||
try { | |||
fis = new FileOutputStream(f); | |||
ms.print(new PrintStream(fis)); | |||
fis.write(120); | |||
} finally { | |||
FileUtils.close(fis); | |||
} | |||
} | |||
@After | |||
public void tearDown() { | |||
if (f.exists()) { | |||
FileUtils fu = FileUtils.getFileUtils(); | |||
fu.tryHardToDelete(f); | |||
try (FileOutputStream fos = new FileOutputStream(testFolder.newFile("message.txt"))) { | |||
ms.print(new PrintStream(fos)); | |||
fos.write(120); | |||
} | |||
} | |||
} |
@@ -20,18 +20,18 @@ package org.apache.tools.ant.types; | |||
import org.apache.tools.ant.BuildException; | |||
import org.apache.tools.ant.Project; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.junit.Before; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TemporaryFolder; | |||
import java.io.File; | |||
import java.io.FileOutputStream; | |||
import java.io.IOException; | |||
import java.io.OutputStream; | |||
import java.io.OutputStreamWriter; | |||
import java.io.Writer; | |||
import java.nio.charset.Charset; | |||
import java.nio.charset.StandardCharsets; | |||
import static org.junit.Assert.assertArrayEquals; | |||
@@ -45,6 +45,9 @@ import static org.junit.Assert.assertEquals; | |||
public class PatternSetTest { | |||
@Rule | |||
public TemporaryFolder testFolder = new TemporaryFolder(); | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
@@ -222,23 +225,15 @@ public class PatternSetTest { | |||
@Test | |||
public void testEncodingOfIncludesFile() throws IOException { | |||
File testFile = File.createTempFile("ant-", ".pattern"); | |||
testFile.deleteOnExit(); | |||
OutputStream o = null; | |||
Writer w = null; | |||
try { | |||
o = new FileOutputStream(testFile); | |||
w = new OutputStreamWriter(o, StandardCharsets.UTF_16LE); | |||
File testFile = testFolder.newFile("ant.pattern"); | |||
Charset cs = StandardCharsets.UTF_16LE; | |||
try (Writer w = new OutputStreamWriter(new FileOutputStream(testFile), cs)) { | |||
w.write("\u00e4\n"); | |||
} finally { | |||
FileUtils.close(w); | |||
FileUtils.close(o); | |||
} | |||
PatternSet p = new PatternSet(); | |||
PatternSet.PatternFileNameEntry ne = | |||
(PatternSet.PatternFileNameEntry) p.createIncludesFile(); | |||
(PatternSet.PatternFileNameEntry) p.createIncludesFile(); | |||
ne.setName(testFile.getAbsolutePath()); | |||
ne.setEncoding("UTF-16LE"); | |||
assertArrayEquals(new String[] { "\u00e4" }, p.getIncludePatterns(project)); | |||
ne.setEncoding(cs.name()); | |||
assertArrayEquals(new String[] {"\u00e4"}, p.getIncludePatterns(project)); | |||
} | |||
} |
@@ -48,8 +48,6 @@ public class ResourceOutputTest { | |||
@Rule | |||
public BuildFileRule buildRule = new BuildFileRule(); | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
private Project project; | |||
@Before | |||
@@ -121,7 +119,7 @@ public class ResourceOutputTest { | |||
// TODO assert exception message | |||
File f = project.resolveFile("testurloutput"); | |||
try { | |||
FILE_UTILS.createNewFile(f); | |||
FileUtils.getFileUtils().createNewFile(f); | |||
testoutput(new URLResource(f)); | |||
} finally { | |||
if (!f.delete()) { | |||
@@ -20,6 +20,7 @@ package org.apache.tools.ant.types.selectors; | |||
import java.io.File; | |||
import java.io.FileWriter; | |||
import java.io.IOException; | |||
import java.text.RuleBasedCollator; | |||
import java.util.Arrays; | |||
import java.util.Comparator; | |||
@@ -41,12 +42,12 @@ import org.apache.tools.ant.types.selectors.modifiedselector.EqualComparator; | |||
import org.apache.tools.ant.types.selectors.modifiedselector.HashvalueAlgorithm; | |||
import org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector; | |||
import org.apache.tools.ant.types.selectors.modifiedselector.PropertiesfileCache; | |||
import org.apache.tools.ant.util.FileUtils; | |||
import org.junit.Before; | |||
import org.junit.Ignore; | |||
import org.junit.Rule; | |||
import org.junit.Test; | |||
import org.junit.rules.ExpectedException; | |||
import org.junit.rules.TemporaryFolder; | |||
import static org.hamcrest.Matchers.containsString; | |||
import static org.hamcrest.Matchers.startsWith; | |||
@@ -70,8 +71,8 @@ public class ModifiedSelectorTest { | |||
@Rule | |||
public ExpectedException thrown = ExpectedException.none(); | |||
/** Utilities used for file operations */ | |||
private static final FileUtils FILE_UTILS = FileUtils.getFileUtils(); | |||
@Rule | |||
public TemporaryFolder testFolder = new TemporaryFolder(); | |||
// ===================== fixtures ===================== | |||
@@ -344,11 +345,10 @@ public class ModifiedSelectorTest { | |||
* configure() method of ModifiedSelector. This testcase tests that. | |||
*/ | |||
@Test | |||
public void testCreatePropertiesCacheViaCustomSelector() { | |||
File cachefile = FILE_UTILS.createTempFile("tmp-cache-", ".properties", null, false, false); | |||
public void testCreatePropertiesCacheViaCustomSelector() throws IOException { | |||
File cachefile = testFolder.newFile("tmp-cache.properties"); | |||
// Configure the selector | |||
ExtendSelector s = new ExtendSelector(); | |||
s.setClassname("org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector"); | |||
s.addParam(createParam("update", "true")); | |||
@@ -359,7 +359,6 @@ public class ModifiedSelectorTest { | |||
// evaluate correctness | |||
assertTrue("Cache file is not created.", cachefile.exists()); | |||
cachefile.delete(); | |||
} | |||
@Test | |||
@@ -21,7 +21,6 @@ package org.apache.tools.ant.util; | |||
import java.io.File; | |||
import java.io.FileOutputStream; | |||
import java.io.IOException; | |||
import java.nio.file.FileSystem; | |||
import java.nio.file.Files; | |||
import java.nio.file.Path; | |||
import java.nio.file.Paths; | |||
@@ -705,7 +704,7 @@ public class FileUtilsTest { | |||
final boolean existsAsUpperCase = Files.exists(Paths.get(tmpDir.toString(), tmpFile.getFileName().toString().toUpperCase(Locale.US))); | |||
// if the temp file that we created is found to not exist in a particular "case", then | |||
// the filesystem is case sensitive | |||
final Boolean expectedCaseSensitivity = existsAsLowerCase == false || existsAsUpperCase == false; | |||
final Boolean expectedCaseSensitivity = !existsAsLowerCase || !existsAsUpperCase; | |||
// call the method and pass it a directory | |||
Optional<Boolean> actualCaseSensitivity = FileUtils.isCaseSensitiveFileSystem(tmpDir); | |||