diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/email/MessageTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/email/MessageTest.java
index df75067fd..505decd07 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/email/MessageTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/email/MessageTest.java
@@ -1,62 +1,62 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-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.Test;
-
-public class MessageTest {
- private static final File f = new File(System.getProperty("java.io.tmpdir"),
- "message.txt");
- /**
- * test for bugzilla 48932
- */
- @Test
- public void testPrintStreamDoesNotGetClosed() throws IOException {
- Message ms = new Message();
- 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);
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+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.Test;
+
+public class MessageTest {
+ private static final File f = new File(System.getProperty("java.io.tmpdir"),
+ "message.txt");
+ /**
+ * test for bugzilla 48932
+ */
+ @Test
+ public void testPrintStreamDoesNotGetClosed() throws IOException {
+ Message ms = new Message();
+ 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);
+ }
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java
index 925844830..47abcfe3f 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ANTLRTest.java
@@ -1,216 +1,216 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.FileUtilities;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import java.io.File;
-import java.io.FilenameFilter;
-
-import static org.apache.tools.ant.AntAssert.assertContains;
-import static org.apache.tools.ant.AntAssert.assertNotContains;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * If you want to run tests, it is highly recommended
- * to download ANTLR (www.antlr.org), build the 'antlrall.jar' jar
- * with make antlr-all.jar and drop the jar (about 300KB) into
- * Ant lib.
- * - Running w/ the default antlr.jar (70KB) does not work (missing class)
- *
- * Unless of course you specify the ANTLR classpath in your
- * system classpath. (see ANTLR install.html)
- *
- */
-public class ANTLRTest {
-
- private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/antlr/";
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject(TASKDEFS_DIR + "antlr.xml");
- }
-
- @Test
- public void test1() {
- try {
- buildRule.executeTarget("test1");
- fail("required argument, target, missing");
- } catch (BuildException ex) {
- //TODO should check exception message
- }
- }
-
- @Test
- public void test2() {
- try {
- buildRule.executeTarget("test2");
- fail("Invalid output directory");
- } catch (BuildException ex) {
- //TODO should check exception message
- }
- }
-
- @Test
- public void test3() {
- buildRule.executeTarget("test3");
- }
-
- @Test
- public void test4() {
- buildRule.executeTarget("test4");
- }
-
- @Test
- public void test5() {
- // should print "panic: Cannot find importVocab file 'JavaTokenTypes.txt'"
- // since it needs to run java.g first before java.tree.g
- try {
- buildRule.executeTarget("test5");
- fail("ANTLR returned: 1");
- } catch (BuildException ex) {
- //TODO should check exception message
- }
- }
-
- @Test
- public void test6() {
- buildRule.executeTarget("test6");
- }
-
- @Test
- public void test7() {
- try {
- buildRule.executeTarget("test7");
- fail("Unable to determine generated class");
- } catch (BuildException ex) {
- //TODO should check exception message
- }
- }
-
- /**
- * This is a negative test for the super grammar (glib) option.
- */
- @Test
- public void test8() {
- try {
- buildRule.executeTarget("test8");
- fail("Invalid super grammar file");
- } catch (BuildException ex) {
- //TODO should check exception message
- }
- }
-
- /**
- * This is a positive test for the super grammar (glib) option. ANTLR
- * will throw an error if everything is not correct.
- */
- @Test
- public void test9() {
- buildRule.executeTarget("test9");
- }
-
- /**
- * This test creates an html-ized version of the calculator grammar.
- * The sanity check is simply whether or not an html file was generated.
- */
- @Test
- public void test10() {
- buildRule.executeTarget("test10");
- File outputDirectory = new File(buildRule.getProject().getProperty("output"));
- String[] calcFiles = outputDirectory.list(new HTMLFilter());
- assertTrue(calcFiles.length > 0);
- }
-
- /**
- * This is just a quick sanity check to run the diagnostic option and
- * make sure that it doesn't throw any funny exceptions.
- */
- @Test
- public void test11() {
- buildRule.executeTarget("test11");
- }
-
- /**
- * This is just a quick sanity check to run the trace option and
- * make sure that it doesn't throw any funny exceptions.
- */
- @Test
- public void test12() {
- buildRule.executeTarget("test12");
- }
-
- /**
- * This is just a quick sanity check to run all the rest of the
- * trace options (traceLexer, traceParser, and traceTreeWalker) to
- * make sure that they don't throw any funny exceptions.
- */
- @Test
- public void test13() {
- buildRule.executeTarget("test13");
- }
-
- @Test
- public void testNoRecompile() {
- buildRule.executeTarget("test9");
- assertNotContains("Skipped grammar file.", buildRule.getFullLog());
- buildRule.executeTarget("noRecompile");
- assertContains("Skipped grammar file.", buildRule.getFullLog());
- }
-
- @Test
- public void testNormalRecompile() {
- buildRule.executeTarget("test9");
- assertNotContains("Skipped grammar file.", buildRule.getFullLog());
-
- FileUtilities.rollbackTimetamps(buildRule.getOutputDir(), 5);
-
- buildRule.executeTarget("normalRecompile");
- assertNotContains("Skipped grammar file.", buildRule.getFullLog());
- }
-
- @Test
- // Bugzilla Report 12961
- public void testSupergrammarChangeRecompile() {
- buildRule.executeTarget("test9");
- assertNotContains("Skipped grammar file.", buildRule.getFullLog());
-
- FileUtilities.rollbackTimetamps(buildRule.getOutputDir(), 5);
-
- buildRule.executeTarget("supergrammarChangeRecompile");
- assertNotContains("Skipped grammar file.", buildRule.getFullLog());
-
- }
-
-}
-
-class HTMLFilter implements FilenameFilter {
- public boolean accept(File dir, String name) {
- return name.endsWith("html");
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.FileUtilities;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FilenameFilter;
+
+import static org.apache.tools.ant.AntAssert.assertContains;
+import static org.apache.tools.ant.AntAssert.assertNotContains;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * If you want to run tests, it is highly recommended
+ * to download ANTLR (www.antlr.org), build the 'antlrall.jar' jar
+ * with make antlr-all.jar and drop the jar (about 300KB) into
+ * Ant lib.
+ * - Running w/ the default antlr.jar (70KB) does not work (missing class)
+ *
+ * Unless of course you specify the ANTLR classpath in your
+ * system classpath. (see ANTLR install.html)
+ *
+ */
+public class ANTLRTest {
+
+ private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/antlr/";
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject(TASKDEFS_DIR + "antlr.xml");
+ }
+
+ @Test
+ public void test1() {
+ try {
+ buildRule.executeTarget("test1");
+ fail("required argument, target, missing");
+ } catch (BuildException ex) {
+ //TODO should check exception message
+ }
+ }
+
+ @Test
+ public void test2() {
+ try {
+ buildRule.executeTarget("test2");
+ fail("Invalid output directory");
+ } catch (BuildException ex) {
+ //TODO should check exception message
+ }
+ }
+
+ @Test
+ public void test3() {
+ buildRule.executeTarget("test3");
+ }
+
+ @Test
+ public void test4() {
+ buildRule.executeTarget("test4");
+ }
+
+ @Test
+ public void test5() {
+ // should print "panic: Cannot find importVocab file 'JavaTokenTypes.txt'"
+ // since it needs to run java.g first before java.tree.g
+ try {
+ buildRule.executeTarget("test5");
+ fail("ANTLR returned: 1");
+ } catch (BuildException ex) {
+ //TODO should check exception message
+ }
+ }
+
+ @Test
+ public void test6() {
+ buildRule.executeTarget("test6");
+ }
+
+ @Test
+ public void test7() {
+ try {
+ buildRule.executeTarget("test7");
+ fail("Unable to determine generated class");
+ } catch (BuildException ex) {
+ //TODO should check exception message
+ }
+ }
+
+ /**
+ * This is a negative test for the super grammar (glib) option.
+ */
+ @Test
+ public void test8() {
+ try {
+ buildRule.executeTarget("test8");
+ fail("Invalid super grammar file");
+ } catch (BuildException ex) {
+ //TODO should check exception message
+ }
+ }
+
+ /**
+ * This is a positive test for the super grammar (glib) option. ANTLR
+ * will throw an error if everything is not correct.
+ */
+ @Test
+ public void test9() {
+ buildRule.executeTarget("test9");
+ }
+
+ /**
+ * This test creates an html-ized version of the calculator grammar.
+ * The sanity check is simply whether or not an html file was generated.
+ */
+ @Test
+ public void test10() {
+ buildRule.executeTarget("test10");
+ File outputDirectory = new File(buildRule.getProject().getProperty("output"));
+ String[] calcFiles = outputDirectory.list(new HTMLFilter());
+ assertTrue(calcFiles.length > 0);
+ }
+
+ /**
+ * This is just a quick sanity check to run the diagnostic option and
+ * make sure that it doesn't throw any funny exceptions.
+ */
+ @Test
+ public void test11() {
+ buildRule.executeTarget("test11");
+ }
+
+ /**
+ * This is just a quick sanity check to run the trace option and
+ * make sure that it doesn't throw any funny exceptions.
+ */
+ @Test
+ public void test12() {
+ buildRule.executeTarget("test12");
+ }
+
+ /**
+ * This is just a quick sanity check to run all the rest of the
+ * trace options (traceLexer, traceParser, and traceTreeWalker) to
+ * make sure that they don't throw any funny exceptions.
+ */
+ @Test
+ public void test13() {
+ buildRule.executeTarget("test13");
+ }
+
+ @Test
+ public void testNoRecompile() {
+ buildRule.executeTarget("test9");
+ assertNotContains("Skipped grammar file.", buildRule.getFullLog());
+ buildRule.executeTarget("noRecompile");
+ assertContains("Skipped grammar file.", buildRule.getFullLog());
+ }
+
+ @Test
+ public void testNormalRecompile() {
+ buildRule.executeTarget("test9");
+ assertNotContains("Skipped grammar file.", buildRule.getFullLog());
+
+ FileUtilities.rollbackTimetamps(buildRule.getOutputDir(), 5);
+
+ buildRule.executeTarget("normalRecompile");
+ assertNotContains("Skipped grammar file.", buildRule.getFullLog());
+ }
+
+ @Test
+ // Bugzilla Report 12961
+ public void testSupergrammarChangeRecompile() {
+ buildRule.executeTarget("test9");
+ assertNotContains("Skipped grammar file.", buildRule.getFullLog());
+
+ FileUtilities.rollbackTimetamps(buildRule.getOutputDir(), 5);
+
+ buildRule.executeTarget("supergrammarChangeRecompile");
+ assertNotContains("Skipped grammar file.", buildRule.getFullLog());
+
+ }
+
+}
+
+class HTMLFilter implements FilenameFilter {
+ public boolean accept(File dir, String name) {
+ return name.endsWith("html");
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java
index 434e81f51..8f2f494e3 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/AbstractXSLTLiaisonTest.java
@@ -1,104 +1,104 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.net.URL;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-
-import org.apache.tools.ant.taskdefs.XSLTLiaison;
-import org.apache.tools.ant.util.FileUtils;
-import org.junit.Before;
-import org.junit.Test;
-import org.w3c.dom.Document;
-
-/**
- * Abtract testcase for XSLTLiaison.
- * Override createLiaison for each XSLTLiaison.
- *
- * Stephane Bailliez
- */
-public abstract class AbstractXSLTLiaisonTest {
-
- private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
-
- protected XSLTLiaison liaison;
-
- @Before
- public void setUp() throws Exception {
- liaison = createLiaison();
- }
-
- // to override
- protected abstract XSLTLiaison createLiaison() throws Exception ;
-
- /** load the file from the caller classloader that loaded this class */
- protected File getFile(String name) throws FileNotFoundException {
- URL url = getClass().getResource(name);
- if (url == null){
- throw new FileNotFoundException("Unable to load '" + name + "' from classpath");
- }
- return new File(FILE_UTILS.fromURI(url.toExternalForm()));
- }
-
- /** keep it simple stupid */
- @Test
- public void testTransform() throws Exception {
- File xsl = getFile("/taskdefs/optional/xsltliaison-in.xsl");
- liaison.setStylesheet(xsl);
- liaison.addParam("param", "value");
- File in = getFile("/taskdefs/optional/xsltliaison-in.xml");
- File out = new File("xsltliaison.tmp");
- out.deleteOnExit(); // just to be sure
- try {
- liaison.transform(in, out);
- } finally {
- out.delete();
- }
- }
-
- @Test
- public void testEncoding() throws Exception {
- File xsl = getFile("/taskdefs/optional/xsltliaison-encoding-in.xsl");
- liaison.setStylesheet(xsl);
- File in = getFile("/taskdefs/optional/xsltliaison-encoding-in.xml");
- File out = new File("xsltliaison-encoding.tmp");
- out.deleteOnExit(); // just to be sure
- try {
- liaison.transform(in, out);
- Document doc = parseXML(out);
- assertEquals("root",doc.getDocumentElement().getNodeName());
- assertEquals("message",doc.getDocumentElement().getFirstChild().getNodeName());
- assertEquals("\u00E9\u00E0\u00E8\u00EF\u00F9",doc.getDocumentElement().getFirstChild().getFirstChild().getNodeValue());
- } finally {
- out.delete();
- }
- }
-
- public Document parseXML(File file) throws Exception {
- DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder dbuilder = dbfactory.newDocumentBuilder();
- return dbuilder.parse(file);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.net.URL;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+
+import org.apache.tools.ant.taskdefs.XSLTLiaison;
+import org.apache.tools.ant.util.FileUtils;
+import org.junit.Before;
+import org.junit.Test;
+import org.w3c.dom.Document;
+
+/**
+ * Abtract testcase for XSLTLiaison.
+ * Override createLiaison for each XSLTLiaison.
+ *
+ * Stephane Bailliez
+ */
+public abstract class AbstractXSLTLiaisonTest {
+
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
+ protected XSLTLiaison liaison;
+
+ @Before
+ public void setUp() throws Exception {
+ liaison = createLiaison();
+ }
+
+ // to override
+ protected abstract XSLTLiaison createLiaison() throws Exception ;
+
+ /** load the file from the caller classloader that loaded this class */
+ protected File getFile(String name) throws FileNotFoundException {
+ URL url = getClass().getResource(name);
+ if (url == null){
+ throw new FileNotFoundException("Unable to load '" + name + "' from classpath");
+ }
+ return new File(FILE_UTILS.fromURI(url.toExternalForm()));
+ }
+
+ /** keep it simple stupid */
+ @Test
+ public void testTransform() throws Exception {
+ File xsl = getFile("/taskdefs/optional/xsltliaison-in.xsl");
+ liaison.setStylesheet(xsl);
+ liaison.addParam("param", "value");
+ File in = getFile("/taskdefs/optional/xsltliaison-in.xml");
+ File out = new File("xsltliaison.tmp");
+ out.deleteOnExit(); // just to be sure
+ try {
+ liaison.transform(in, out);
+ } finally {
+ out.delete();
+ }
+ }
+
+ @Test
+ public void testEncoding() throws Exception {
+ File xsl = getFile("/taskdefs/optional/xsltliaison-encoding-in.xsl");
+ liaison.setStylesheet(xsl);
+ File in = getFile("/taskdefs/optional/xsltliaison-encoding-in.xml");
+ File out = new File("xsltliaison-encoding.tmp");
+ out.deleteOnExit(); // just to be sure
+ try {
+ liaison.transform(in, out);
+ Document doc = parseXML(out);
+ assertEquals("root",doc.getDocumentElement().getNodeName());
+ assertEquals("message",doc.getDocumentElement().getFirstChild().getNodeName());
+ assertEquals("\u00E9\u00E0\u00E8\u00EF\u00F9",doc.getDocumentElement().getFirstChild().getFirstChild().getNodeValue());
+ } finally {
+ out.delete();
+ }
+ }
+
+ public Document parseXML(File file) throws Exception {
+ DocumentBuilderFactory dbfactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder dbuilder = dbfactory.newDocumentBuilder();
+ return dbuilder.parse(file);
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/BeanShellScriptTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/BeanShellScriptTest.java
index 880202293..834f17355 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/BeanShellScriptTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/BeanShellScriptTest.java
@@ -1,48 +1,48 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * Tests the examples of the <script> task docs.
- *
- * @since Ant 1.5.2
- */
-public class BeanShellScriptTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/script.xml");
- }
-
- @Test
- public void testCanLoad() {
- buildRule.executeTarget("useBeanshell");
- assertEquals("I'm here", buildRule.getLog());
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Tests the examples of the <script> task docs.
+ *
+ * @since Ant 1.5.2
+ */
+public class BeanShellScriptTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/script.xml");
+ }
+
+ @Test
+ public void testCanLoad() {
+ buildRule.executeTarget("useBeanshell");
+ assertEquals("I'm here", buildRule.getLog());
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java
index 925777c5d..2f351d460 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/EchoPropertiesTest.java
@@ -1,266 +1,266 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional;
-
-import static org.apache.tools.ant.AntAssert.assertContains;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assume.assumeTrue;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileReader;
-import java.io.IOException;
-import java.io.InputStream;
-import java.util.Properties;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-/**
- * Tests the EchoProperties task.
- *
- * @created 17-Jan-2002
- * @since Ant 1.5
- */
-public class EchoPropertiesTest {
-
- private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/";
- private static final String GOOD_OUTFILE = "test.properties";
- private static final String GOOD_OUTFILE_XML = "test.xml";
- private static final String PREFIX_OUTFILE = "test-prefix.properties";
- private static final String TEST_VALUE = "isSet";
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
-
- @Before
- public void setUp() {
- buildRule.configureProject(TASKDEFS_DIR + "echoproperties.xml");
- buildRule.getProject().setProperty("test.property", TEST_VALUE);
- }
-
-
- @After
- public void tearDown() {
- buildRule.executeTarget("cleanup");
- }
-
-
- @Test
- public void testEchoToLog() {
- buildRule.executeTarget("testEchoToLog");
- assertContains("test.property=" + TEST_VALUE, buildRule.getLog());
- }
-
- @Test
- public void testEchoWithEmptyPrefixToLog() {
- buildRule.executeTarget("testEchoWithEmptyPrefixToLog");
- assertContains("test.property="+TEST_VALUE, buildRule.getLog());
- }
-
-
- @Test
- public void testReadBadFile() {
- try {
- buildRule.executeTarget("testReadBadFile");
- fail("BuildException should have been thrown on bad file");
- }
- catch(BuildException ex) {
- assertContains("srcfile is a directory","srcfile is a directory!", ex.getMessage());
- }
- }
-
- @Test
- public void testReadBadFileNoFail() {
- buildRule.executeTarget("testReadBadFileNoFail");
- assertContains("srcfile is a directory!", buildRule.getLog());
- }
-
-
- @Test
- public void testEchoToBadFile() {
- try {
- buildRule.executeTarget("testEchoToBadFile");
- fail("BuildException should have been thrown on destination file being a directory");
- } catch(BuildException ex) {
- assertContains("destfile is a directory", "destfile is a directory!", ex.getMessage());
- }
- }
-
-
- @Test
- public void testEchoToBadFileNoFail() {
- buildRule.executeTarget("testEchoToBadFileNoFail");
- assertContains("destfile is a directory!", buildRule.getLog());
- }
-
-
- @Test
- public void testEchoToGoodFile() throws Exception {
- buildRule.executeTarget("testEchoToGoodFile");
- assertGoodFile();
- }
-
-
- @Test
- public void testEchoToGoodFileXml() throws Exception {
- buildRule.executeTarget("testEchoToGoodFileXml");
-
- // read in the file
- File f = createRelativeFile(GOOD_OUTFILE_XML);
- FileReader fr = new FileReader(f);
- BufferedReader br = new BufferedReader(fr);
- try {
- String read = null;
- while ((read = br.readLine()) != null) {
- if (read.indexOf("") >= 0) {
- // found the property we set - it's good.
- return;
- }
- }
- fail("did not encounter set property in generated file.");
- } finally {
- try {
- fr.close();
- } catch(IOException e) {}
- try {
- br.close();
- } catch(IOException e) {}
- }
- }
-
-
- @Test
- public void testEchoToGoodFileFail() throws Exception {
- buildRule.executeTarget("testEchoToGoodFileFail");
- assertGoodFile();
- }
-
-
- @Test
- public void testEchoToGoodFileNoFail() throws Exception {
- buildRule.executeTarget("testEchoToGoodFileNoFail");
- assertGoodFile();
- }
-
- @Test
- public void testEchoPrefix() throws Exception {
- testEchoPrefixVarious("testEchoPrefix");
- }
-
- @Test
- public void testEchoPrefixAsPropertyset() throws Exception {
- testEchoPrefixVarious("testEchoPrefixAsPropertyset");
- }
-
- @Test
- public void testEchoPrefixAsNegatedPropertyset() throws Exception {
- testEchoPrefixVarious("testEchoPrefixAsNegatedPropertyset");
- }
-
- @Test
- public void testEchoPrefixAsDoublyNegatedPropertyset() throws Exception {
- testEchoPrefixVarious("testEchoPrefixAsDoublyNegatedPropertyset");
- }
-
- @Test
- public void testWithPrefixAndRegex() throws Exception {
- try {
- buildRule.executeTarget("testWithPrefixAndRegex");
- fail("BuildException should have been thrown on Prefix and RegEx beng set");
- } catch (BuildException ex) {
- assertEquals("The target must fail with prefix and regex attributes set", "Please specify either prefix or regex, but not both", ex.getMessage());
- }
- }
-
- @Test
- public void testWithEmptyPrefixAndRegex() throws Exception {
- buildRule.executeTarget("testEchoWithEmptyPrefixToLog");
- assertContains("test.property="+TEST_VALUE, buildRule.getLog());
- }
-
- @Test
- public void testWithRegex() throws Exception {
- assumeTrue("Test skipped because no regexp matcher is present.", RegexpMatcherFactory.regexpMatcherPresent(buildRule.getProject()));
- buildRule.executeTarget("testWithRegex");
- // the following line has been changed from checking ant.home to ant.version so the test will still work when run outside of an ant script
- assertContains("ant.version=", buildRule.getFullLog());
- }
-
- private void testEchoPrefixVarious(String target) throws Exception {
- buildRule.executeTarget(target);
- Properties props = loadPropFile(PREFIX_OUTFILE);
- assertEquals("prefix didn't include 'a.set' property",
- "true", props.getProperty("a.set"));
- assertNull("prefix failed to filter out property 'b.set'",
- props.getProperty("b.set"));
- }
-
- protected Properties loadPropFile(String relativeFilename)
- throws IOException {
- File f = createRelativeFile(relativeFilename);
- Properties props=new Properties();
- InputStream in=null;
- try {
- in=new BufferedInputStream(new FileInputStream(f));
- props.load(in);
- } finally {
- if(in!=null) {
- try { in.close(); } catch(IOException e) {}
- }
- }
- return props;
- }
-
- protected void assertGoodFile() throws Exception {
- File f = createRelativeFile(GOOD_OUTFILE);
- assertTrue("Did not create "+f.getAbsolutePath(),
- f.exists());
- Properties props=loadPropFile(GOOD_OUTFILE);
- props.list(System.out);
- assertEquals("test property not found ",
- TEST_VALUE, props.getProperty("test.property"));
- }
-
-
- protected String toAbsolute(String filename) {
- return createRelativeFile(filename).getAbsolutePath();
- }
-
-
- protected File createRelativeFile(String filename) {
- if (filename.equals(".")) {
- return buildRule.getProject().getBaseDir();
- }
- // else
- return new File(buildRule.getProject().getBaseDir(), filename);
- }
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional;
+
+import static org.apache.tools.ant.AntAssert.assertContains;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
+
+import java.io.BufferedInputStream;
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.Properties;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Tests the EchoProperties task.
+ *
+ * @created 17-Jan-2002
+ * @since Ant 1.5
+ */
+public class EchoPropertiesTest {
+
+ private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/";
+ private static final String GOOD_OUTFILE = "test.properties";
+ private static final String GOOD_OUTFILE_XML = "test.xml";
+ private static final String PREFIX_OUTFILE = "test-prefix.properties";
+ private static final String TEST_VALUE = "isSet";
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject(TASKDEFS_DIR + "echoproperties.xml");
+ buildRule.getProject().setProperty("test.property", TEST_VALUE);
+ }
+
+
+ @After
+ public void tearDown() {
+ buildRule.executeTarget("cleanup");
+ }
+
+
+ @Test
+ public void testEchoToLog() {
+ buildRule.executeTarget("testEchoToLog");
+ assertContains("test.property=" + TEST_VALUE, buildRule.getLog());
+ }
+
+ @Test
+ public void testEchoWithEmptyPrefixToLog() {
+ buildRule.executeTarget("testEchoWithEmptyPrefixToLog");
+ assertContains("test.property="+TEST_VALUE, buildRule.getLog());
+ }
+
+
+ @Test
+ public void testReadBadFile() {
+ try {
+ buildRule.executeTarget("testReadBadFile");
+ fail("BuildException should have been thrown on bad file");
+ }
+ catch(BuildException ex) {
+ assertContains("srcfile is a directory","srcfile is a directory!", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testReadBadFileNoFail() {
+ buildRule.executeTarget("testReadBadFileNoFail");
+ assertContains("srcfile is a directory!", buildRule.getLog());
+ }
+
+
+ @Test
+ public void testEchoToBadFile() {
+ try {
+ buildRule.executeTarget("testEchoToBadFile");
+ fail("BuildException should have been thrown on destination file being a directory");
+ } catch(BuildException ex) {
+ assertContains("destfile is a directory", "destfile is a directory!", ex.getMessage());
+ }
+ }
+
+
+ @Test
+ public void testEchoToBadFileNoFail() {
+ buildRule.executeTarget("testEchoToBadFileNoFail");
+ assertContains("destfile is a directory!", buildRule.getLog());
+ }
+
+
+ @Test
+ public void testEchoToGoodFile() throws Exception {
+ buildRule.executeTarget("testEchoToGoodFile");
+ assertGoodFile();
+ }
+
+
+ @Test
+ public void testEchoToGoodFileXml() throws Exception {
+ buildRule.executeTarget("testEchoToGoodFileXml");
+
+ // read in the file
+ File f = createRelativeFile(GOOD_OUTFILE_XML);
+ FileReader fr = new FileReader(f);
+ BufferedReader br = new BufferedReader(fr);
+ try {
+ String read = null;
+ while ((read = br.readLine()) != null) {
+ if (read.indexOf("") >= 0) {
+ // found the property we set - it's good.
+ return;
+ }
+ }
+ fail("did not encounter set property in generated file.");
+ } finally {
+ try {
+ fr.close();
+ } catch(IOException e) {}
+ try {
+ br.close();
+ } catch(IOException e) {}
+ }
+ }
+
+
+ @Test
+ public void testEchoToGoodFileFail() throws Exception {
+ buildRule.executeTarget("testEchoToGoodFileFail");
+ assertGoodFile();
+ }
+
+
+ @Test
+ public void testEchoToGoodFileNoFail() throws Exception {
+ buildRule.executeTarget("testEchoToGoodFileNoFail");
+ assertGoodFile();
+ }
+
+ @Test
+ public void testEchoPrefix() throws Exception {
+ testEchoPrefixVarious("testEchoPrefix");
+ }
+
+ @Test
+ public void testEchoPrefixAsPropertyset() throws Exception {
+ testEchoPrefixVarious("testEchoPrefixAsPropertyset");
+ }
+
+ @Test
+ public void testEchoPrefixAsNegatedPropertyset() throws Exception {
+ testEchoPrefixVarious("testEchoPrefixAsNegatedPropertyset");
+ }
+
+ @Test
+ public void testEchoPrefixAsDoublyNegatedPropertyset() throws Exception {
+ testEchoPrefixVarious("testEchoPrefixAsDoublyNegatedPropertyset");
+ }
+
+ @Test
+ public void testWithPrefixAndRegex() throws Exception {
+ try {
+ buildRule.executeTarget("testWithPrefixAndRegex");
+ fail("BuildException should have been thrown on Prefix and RegEx beng set");
+ } catch (BuildException ex) {
+ assertEquals("The target must fail with prefix and regex attributes set", "Please specify either prefix or regex, but not both", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testWithEmptyPrefixAndRegex() throws Exception {
+ buildRule.executeTarget("testEchoWithEmptyPrefixToLog");
+ assertContains("test.property="+TEST_VALUE, buildRule.getLog());
+ }
+
+ @Test
+ public void testWithRegex() throws Exception {
+ assumeTrue("Test skipped because no regexp matcher is present.", RegexpMatcherFactory.regexpMatcherPresent(buildRule.getProject()));
+ buildRule.executeTarget("testWithRegex");
+ // the following line has been changed from checking ant.home to ant.version so the test will still work when run outside of an ant script
+ assertContains("ant.version=", buildRule.getFullLog());
+ }
+
+ private void testEchoPrefixVarious(String target) throws Exception {
+ buildRule.executeTarget(target);
+ Properties props = loadPropFile(PREFIX_OUTFILE);
+ assertEquals("prefix didn't include 'a.set' property",
+ "true", props.getProperty("a.set"));
+ assertNull("prefix failed to filter out property 'b.set'",
+ props.getProperty("b.set"));
+ }
+
+ protected Properties loadPropFile(String relativeFilename)
+ throws IOException {
+ File f = createRelativeFile(relativeFilename);
+ Properties props=new Properties();
+ InputStream in=null;
+ try {
+ in=new BufferedInputStream(new FileInputStream(f));
+ props.load(in);
+ } finally {
+ if(in!=null) {
+ try { in.close(); } catch(IOException e) {}
+ }
+ }
+ return props;
+ }
+
+ protected void assertGoodFile() throws Exception {
+ File f = createRelativeFile(GOOD_OUTFILE);
+ assertTrue("Did not create "+f.getAbsolutePath(),
+ f.exists());
+ Properties props=loadPropFile(GOOD_OUTFILE);
+ props.list(System.out);
+ assertEquals("test property not found ",
+ TEST_VALUE, props.getProperty("test.property"));
+ }
+
+
+ protected String toAbsolute(String filename) {
+ return createRelativeFile(filename).getAbsolutePath();
+ }
+
+
+ protected File createRelativeFile(String filename) {
+ if (filename.equals(".")) {
+ return buildRule.getProject().getBaseDir();
+ }
+ // else
+ return new File(buildRule.getProject().getBaseDir(), filename);
+ }
+}
+
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JavahTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JavahTest.java
index 8b02fff5f..6e318ad18 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JavahTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JavahTest.java
@@ -1,60 +1,60 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import java.io.File;
-
-import static org.junit.Assert.assertTrue;
-
-public class JavahTest {
-
- private final static String BUILD_XML =
- "src/etc/testcases/taskdefs/optional/javah/build.xml";
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject(BUILD_XML);
- }
-
- @After
- public void tearDown() {
- buildRule.executeTarget("tearDown");
- }
-
- @Test
- public void testSimpleCompile() {
- buildRule.executeTarget("simple-compile");
- assertTrue(new File(buildRule.getProject().getProperty("output"), "org_example_Foo.h")
- .exists());
- }
-
- @Test
- public void testCompileFileset() {
- buildRule.executeTarget("test-fileset");
- assertTrue(new File(buildRule.getProject().getProperty("output"), "org_example_Foo.h").exists());
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertTrue;
+
+public class JavahTest {
+
+ private final static String BUILD_XML =
+ "src/etc/testcases/taskdefs/optional/javah/build.xml";
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject(BUILD_XML);
+ }
+
+ @After
+ public void tearDown() {
+ buildRule.executeTarget("tearDown");
+ }
+
+ @Test
+ public void testSimpleCompile() {
+ buildRule.executeTarget("simple-compile");
+ assertTrue(new File(buildRule.getProject().getProperty("output"), "org_example_Foo.h")
+ .exists());
+ }
+
+ @Test
+ public void testCompileFileset() {
+ buildRule.executeTarget("test-fileset");
+ assertTrue(new File(buildRule.getProject().getProperty("output"), "org_example_Foo.h").exists());
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java
index 57475cc10..62ba085c0 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/JspcTest.java
@@ -1,200 +1,200 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional;
-
-import java.io.File;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.taskdefs.optional.jsp.Jasper41Mangler;
-import org.apache.tools.ant.taskdefs.optional.jsp.JspMangler;
-import org.apache.tools.ant.taskdefs.optional.jsp.JspNameMangler;
-import org.apache.tools.ant.taskdefs.optional.jsp.compilers.JspCompilerAdapter;
-import org.apache.tools.ant.taskdefs.optional.jsp.compilers.JspCompilerAdapterFactory;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * Tests the Jspc task.
- *
- * created 07 March 2002
- * @since Ant 1.5
- */
-public class JspcTest {
-
- private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/";
-
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject(TASKDEFS_DIR + "jspc.xml");
- }
-
-
-
- @Test
- public void testSimple() {
- executeJspCompile("testSimple", "simple_jsp.java");
- }
-
-
- @Test
- public void testUriroot() throws Exception {
- executeJspCompile("testUriroot", "uriroot_jsp.java");
- }
-
-
- @Test
- public void testXml() throws Exception {
- executeJspCompile("testXml", "xml_jsp.java");
- }
-
-
- /**
- * try a keyword in a file
- */
- @Test
- public void testKeyword() throws Exception {
- executeJspCompile("testKeyword", "default_jsp.java");
- }
-
-
- /**
- * what happens to 1nvalid-classname
- */
- @Test
- public void testInvalidClassname() throws Exception {
- executeJspCompile("testInvalidClassname",
- "_1nvalid_0002dclassname_jsp.java");
- }
-
-
- @Test
- public void testNoTld() throws Exception {
- try {
- buildRule.executeTarget("testNoTld");
- fail("Not found");
- } catch (BuildException ex) {
- assertEquals("Java returned: 9", ex.getMessage());
- }
- }
-
-
- @Test
- public void testNotAJspFile() throws Exception {
- buildRule.executeTarget("testNotAJspFile");
- }
-
- /**
- * webapp test is currently broken, because it picks up
- * on the missing_tld file, and bails.
- */
- @Ignore("picks up on the missing_tld file, and incorrectly bails")
- @Test
- public void testWebapp() throws Exception {
- buildRule.executeTarget("testWebapp");
- }
-
- /**
- * run a target then verify the named file gets created
- *
- * @param target Description of Parameter
- * @param javafile Description of Parameter
- */
- protected void executeJspCompile(String target, String javafile) {
- buildRule.executeTarget(target);
- assertJavaFileCreated(javafile);
- }
-
-
- /**
- * verify that a named file was created
- *
- * @param filename Description of Parameter
- */
- protected void assertJavaFileCreated(String filename) {
- File file = getOutputFile(filename);
- assertTrue("file " + filename + " not found", file.exists());
- assertTrue("file " + filename + " is empty", file.length() > 0);
- }
-
- /**
- * Gets the OutputFile attribute of the JspcTest object
- *
- * @param subpath Description of Parameter
- * @return The OutputFile value
- */
- protected File getOutputFile(String subpath) {
- return new File(buildRule.getProject().getProperty("output"), subpath);
- }
-
- /**
- * verify that we select the appropriate mangler
- */
- @Test
- public void testJasperNameManglerSelection() {
- JspCompilerAdapter adapter=
- JspCompilerAdapterFactory.getCompiler("jasper", null,null);
- JspMangler mangler=adapter.createMangler();
- assertTrue(mangler instanceof JspNameMangler);
- adapter= JspCompilerAdapterFactory.getCompiler("jasper41", null, null);
- mangler = adapter.createMangler();
- assertTrue(mangler instanceof Jasper41Mangler);
- }
-
- @Test
- public void testJasper41() {
- JspMangler mangler = new Jasper41Mangler();
- //java keywords are not special
- assertMapped(mangler, "for.jsp", "for_jsp");
- //underscores go in front of invalid start chars
- assertMapped(mangler, "0.jsp", "_0_jsp");
- //underscores at the front get an underscore too
- assertMapped(mangler, "_.jsp", "___jsp");
- //non java char at start => underscore then the the _hex value
- assertMapped(mangler, "-.jsp", "__0002d_jsp");
- //and paths are stripped
- char s = File.separatorChar;
- assertMapped(mangler, "" + s + s + "somewhere" + s + "file" + s + "index.jsp", "index_jsp");
- }
-
- /**
- * assert our mapping rules
- * @param mangler
- * @param filename
- * @param classname
- */
- protected void assertMapped(JspMangler mangler, String filename, String classname) {
- String mappedname = mangler.mapJspToJavaName(new File(filename));
- assertTrue(filename+" should have mapped to "+classname
- +" but instead mapped to "+mappedname,
- classname.equals(mappedname));
- }
-
-
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional;
+
+import java.io.File;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.taskdefs.optional.jsp.Jasper41Mangler;
+import org.apache.tools.ant.taskdefs.optional.jsp.JspMangler;
+import org.apache.tools.ant.taskdefs.optional.jsp.JspNameMangler;
+import org.apache.tools.ant.taskdefs.optional.jsp.compilers.JspCompilerAdapter;
+import org.apache.tools.ant.taskdefs.optional.jsp.compilers.JspCompilerAdapterFactory;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests the Jspc task.
+ *
+ * created 07 March 2002
+ * @since Ant 1.5
+ */
+public class JspcTest {
+
+ private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/";
+
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject(TASKDEFS_DIR + "jspc.xml");
+ }
+
+
+
+ @Test
+ public void testSimple() {
+ executeJspCompile("testSimple", "simple_jsp.java");
+ }
+
+
+ @Test
+ public void testUriroot() throws Exception {
+ executeJspCompile("testUriroot", "uriroot_jsp.java");
+ }
+
+
+ @Test
+ public void testXml() throws Exception {
+ executeJspCompile("testXml", "xml_jsp.java");
+ }
+
+
+ /**
+ * try a keyword in a file
+ */
+ @Test
+ public void testKeyword() throws Exception {
+ executeJspCompile("testKeyword", "default_jsp.java");
+ }
+
+
+ /**
+ * what happens to 1nvalid-classname
+ */
+ @Test
+ public void testInvalidClassname() throws Exception {
+ executeJspCompile("testInvalidClassname",
+ "_1nvalid_0002dclassname_jsp.java");
+ }
+
+
+ @Test
+ public void testNoTld() throws Exception {
+ try {
+ buildRule.executeTarget("testNoTld");
+ fail("Not found");
+ } catch (BuildException ex) {
+ assertEquals("Java returned: 9", ex.getMessage());
+ }
+ }
+
+
+ @Test
+ public void testNotAJspFile() throws Exception {
+ buildRule.executeTarget("testNotAJspFile");
+ }
+
+ /**
+ * webapp test is currently broken, because it picks up
+ * on the missing_tld file, and bails.
+ */
+ @Ignore("picks up on the missing_tld file, and incorrectly bails")
+ @Test
+ public void testWebapp() throws Exception {
+ buildRule.executeTarget("testWebapp");
+ }
+
+ /**
+ * run a target then verify the named file gets created
+ *
+ * @param target Description of Parameter
+ * @param javafile Description of Parameter
+ */
+ protected void executeJspCompile(String target, String javafile) {
+ buildRule.executeTarget(target);
+ assertJavaFileCreated(javafile);
+ }
+
+
+ /**
+ * verify that a named file was created
+ *
+ * @param filename Description of Parameter
+ */
+ protected void assertJavaFileCreated(String filename) {
+ File file = getOutputFile(filename);
+ assertTrue("file " + filename + " not found", file.exists());
+ assertTrue("file " + filename + " is empty", file.length() > 0);
+ }
+
+ /**
+ * Gets the OutputFile attribute of the JspcTest object
+ *
+ * @param subpath Description of Parameter
+ * @return The OutputFile value
+ */
+ protected File getOutputFile(String subpath) {
+ return new File(buildRule.getProject().getProperty("output"), subpath);
+ }
+
+ /**
+ * verify that we select the appropriate mangler
+ */
+ @Test
+ public void testJasperNameManglerSelection() {
+ JspCompilerAdapter adapter=
+ JspCompilerAdapterFactory.getCompiler("jasper", null,null);
+ JspMangler mangler=adapter.createMangler();
+ assertTrue(mangler instanceof JspNameMangler);
+ adapter= JspCompilerAdapterFactory.getCompiler("jasper41", null, null);
+ mangler = adapter.createMangler();
+ assertTrue(mangler instanceof Jasper41Mangler);
+ }
+
+ @Test
+ public void testJasper41() {
+ JspMangler mangler = new Jasper41Mangler();
+ //java keywords are not special
+ assertMapped(mangler, "for.jsp", "for_jsp");
+ //underscores go in front of invalid start chars
+ assertMapped(mangler, "0.jsp", "_0_jsp");
+ //underscores at the front get an underscore too
+ assertMapped(mangler, "_.jsp", "___jsp");
+ //non java char at start => underscore then the the _hex value
+ assertMapped(mangler, "-.jsp", "__0002d_jsp");
+ //and paths are stripped
+ char s = File.separatorChar;
+ assertMapped(mangler, "" + s + s + "somewhere" + s + "file" + s + "index.jsp", "index_jsp");
+ }
+
+ /**
+ * assert our mapping rules
+ * @param mangler
+ * @param filename
+ * @param classname
+ */
+ protected void assertMapped(JspMangler mangler, String filename, String classname) {
+ String mappedname = mangler.mapJspToJavaName(new File(filename));
+ assertTrue(filename+" should have mapped to "+classname
+ +" but instead mapped to "+mappedname,
+ classname.equals(mappedname));
+ }
+
+
+}
+
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java
index 53da2af41..3138e3adf 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/Native2AsciiTest.java
@@ -1,57 +1,57 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional;
-
-import java.io.File;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.util.FileUtils;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-public class Native2AsciiTest {
-
- private final static String BUILD_XML =
- "src/etc/testcases/taskdefs/optional/native2ascii/build.xml";
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject(BUILD_XML);
- }
-
- @After
- public void tearDown() {
- buildRule.executeTarget("tearDown");
- }
-
- @Test
- public void testIso8859_1() throws java.io.IOException {
- buildRule.executeTarget("testIso8859-1");
- File in = buildRule.getProject().resolveFile("expected/iso8859-1.test");
- File out = new File(buildRule.getProject().getProperty("output"), "iso8859-1.test");
- assertTrue(FileUtils.getFileUtils().contentEquals(in, out, true));
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional;
+
+import java.io.File;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.util.FileUtils;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class Native2AsciiTest {
+
+ private final static String BUILD_XML =
+ "src/etc/testcases/taskdefs/optional/native2ascii/build.xml";
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject(BUILD_XML);
+ }
+
+ @After
+ public void tearDown() {
+ buildRule.executeTarget("tearDown");
+ }
+
+ @Test
+ public void testIso8859_1() throws java.io.IOException {
+ buildRule.executeTarget("testIso8859-1");
+ File in = buildRule.getProject().resolveFile("expected/iso8859-1.test");
+ File out = new File(buildRule.getProject().getProperty("output"), "iso8859-1.test");
+ assertTrue(FileUtils.getFileUtils().contentEquals(in, out, true));
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java
index 7056ca90d..a403673bf 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PropertyFileTest.java
@@ -1,235 +1,235 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.util.Properties;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-/**
- * JUnit testcase that exercises the optional PropertyFile task in ant.
- * (this is really more of a functional test so far.., but it's enough to let
- * me start refactoring...)
- *
- *created October 2, 2001
- */
-
-public class PropertyFileTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() throws Exception {
- buildRule.configureProject(projectFilePath);
- buildRule.executeTarget("setUp");
- initTestPropFile();
- initBuildPropFile();
- buildRule.configureProject(projectFilePath);
- buildRule.getProject().setProperty(valueDoesNotGetOverwrittenPropertyFileKey,
- valueDoesNotGetOverwrittenPropertyFile);
- }
-
-
- @Test
- public void testNonExistingFile() {
- PropertyFile props = new PropertyFile();
- props.setProject( buildRule.getProject() );
- File file = new File("this-file-does-not-exist.properties");
- props.setFile(file);
- assertFalse("Properties file exists before test.", file.exists());
- props.execute();
- assertTrue("Properties file does not exist after test.", file.exists());
- file.delete();
- }
-
- /**
- * A unit test for JUnit- Exercises the propertyfile tasks ability to
- * update properties that are already defined-
- */
- @Test
- public void testUpdatesExistingProperties() throws Exception {
- Properties beforeUpdate = getTestProperties();
- assertEquals(FNAME, beforeUpdate.getProperty(FNAME_KEY));
- assertEquals(LNAME, beforeUpdate.getProperty(LNAME_KEY));
- assertEquals(EMAIL, beforeUpdate.getProperty(EMAIL_KEY));
- assertEquals(null, beforeUpdate.getProperty(PHONE_KEY));
- assertEquals(null, beforeUpdate.getProperty(AGE_KEY));
- assertEquals(null, beforeUpdate.getProperty(DATE_KEY));
-
- // ask ant to update the properties...
- buildRule.executeTarget("update-existing-properties");
-
- Properties afterUpdate = getTestProperties();
- assertEquals(NEW_FNAME, afterUpdate.getProperty(FNAME_KEY));
- assertEquals(NEW_LNAME, afterUpdate.getProperty(LNAME_KEY));
- assertEquals(NEW_EMAIL, afterUpdate.getProperty(EMAIL_KEY));
- assertEquals(NEW_PHONE, afterUpdate.getProperty(PHONE_KEY));
- assertEquals(NEW_AGE, afterUpdate.getProperty(AGE_KEY));
- assertEquals(NEW_DATE, afterUpdate.getProperty(DATE_KEY));
- }
-
- @Test
- public void testDeleteProperties() throws Exception {
- Properties beforeUpdate = getTestProperties();
- assertEquals("Property '" + FNAME_KEY + "' should exist before deleting",
- FNAME, beforeUpdate.getProperty(FNAME_KEY));
- assertEquals("Property '" + LNAME_KEY + "' should exist before deleting",
- LNAME, beforeUpdate.getProperty(LNAME_KEY));
-
- buildRule.executeTarget("delete-properties");
- Properties afterUpdate = getTestProperties();
-
- assertEquals("Property '" + LNAME_KEY + "' should exist after deleting",
- LNAME, afterUpdate.getProperty(LNAME_KEY));
- assertNull("Property '" + FNAME_KEY + "' should be deleted",
- afterUpdate.getProperty(FNAME_KEY));
- }
-
- @Test
- public void testExerciseDefaultAndIncrement() throws Exception {
- buildRule.executeTarget("exercise");
- assertEquals("3",buildRule.getProject().getProperty("int.with.default"));
- assertEquals("1",buildRule.getProject().getProperty("int.without.default"));
- assertEquals("-->",buildRule.getProject().getProperty("string.with.default"));
- assertEquals(".",buildRule.getProject().getProperty("string.without.default"));
- assertEquals("2002/01/21 12:18", buildRule.getProject().getProperty("ethans.birth"));
- assertEquals("2003/01/21", buildRule.getProject().getProperty("first.birthday"));
- assertEquals("0124", buildRule.getProject().getProperty("olderThanAWeek"));
- assertEquals("37", buildRule.getProject().getProperty("existing.prop"));
- assertEquals("6",buildRule.getProject().getProperty("int.without.value"));
- }
-
- @Test
- public void testValueDoesNotGetOverwritten() {
- // this test shows that the bug report 21505 is fixed
- buildRule.executeTarget("bugDemo1");
- buildRule.executeTarget("bugDemo2");
- assertEquals("5", buildRule.getProject().getProperty("foo"));
- }
-
-
- @Test
- @Ignore("Previously commented out")
- public void testDirect() throws Exception {
- PropertyFile pf = new PropertyFile();
- pf.setProject(buildRule.getProject());
- pf.setFile(new File(System.getProperty("root"), testPropsFilePath));
- PropertyFile.Entry entry = pf.createEntry();
-
- entry.setKey("date");
- entry.setValue("123");
- PropertyFile.Entry.Type type = new PropertyFile.Entry.Type();
- type.setValue("date");
- entry.setType(type);
-
- entry.setPattern("yyyy/MM/dd");
-
- PropertyFile.Entry.Operation operation = new PropertyFile.Entry.Operation();
- operation.setValue("+");
- pf.execute();
-
- Properties props = getTestProperties();
- assertEquals("yeehaw", props.getProperty("date"));
- }
-
-
- private Properties getTestProperties() throws Exception {
- Properties testProps = new Properties();
- FileInputStream propsFile = new FileInputStream(new File(buildRule.getOutputDir(), testPropsFilePath));
- testProps.load(propsFile);
- propsFile.close();
- return testProps;
- }
-
-
- private void initTestPropFile() throws IOException {
- Properties testProps = new Properties();
- testProps.put(FNAME_KEY, FNAME);
- testProps.put(LNAME_KEY, LNAME);
- testProps.put(EMAIL_KEY, EMAIL);
- testProps.put("existing.prop", "37");
-
- FileOutputStream fos = new FileOutputStream(new File(buildRule.getOutputDir(), testPropsFilePath));
- testProps.store(fos, "defaults");
- fos.close();
- }
-
-
- private void initBuildPropFile() throws IOException {
- Properties buildProps = new Properties();
- buildProps.put(testPropertyFileKey, testPropertyFile);
- buildProps.put(FNAME_KEY, NEW_FNAME);
- buildProps.put(LNAME_KEY, NEW_LNAME);
- buildProps.put(EMAIL_KEY, NEW_EMAIL);
- buildProps.put(PHONE_KEY, NEW_PHONE);
- buildProps.put(AGE_KEY, NEW_AGE);
- buildProps.put(DATE_KEY, NEW_DATE);
-
- FileOutputStream fos = new FileOutputStream(new File(buildRule.getOutputDir(), buildPropsFilePath));
- buildProps.store(fos, null);
- fos.close();
- }
-
- private static final String
- projectFilePath = "src/etc/testcases/taskdefs/optional/propertyfile.xml",
-
- testPropertyFile = "propertyfile.test.properties",
- testPropertyFileKey = "test.propertyfile",
- testPropsFilePath = testPropertyFile,
-
- valueDoesNotGetOverwrittenPropertyFile = "overwrite.test.properties",
- valueDoesNotGetOverwrittenPropertyFileKey = "overwrite.test.propertyfile",
- valueDoesNotGetOverwrittenPropsFilePath = valueDoesNotGetOverwrittenPropertyFile,
-
- buildPropsFilePath = "propertyfile.build.properties",
-
- FNAME = "Bruce",
- NEW_FNAME = "Clark",
- FNAME_KEY = "firstname",
-
- LNAME = "Banner",
- NEW_LNAME = "Kent",
- LNAME_KEY = "lastname",
-
- EMAIL = "incredible@hulk.com",
- NEW_EMAIL = "kc@superman.com",
- EMAIL_KEY = "email",
-
- NEW_PHONE = "(520) 555-1212",
- PHONE_KEY = "phone",
-
- NEW_AGE = "30",
- AGE_KEY = "age",
-
- NEW_DATE = "2001/01/01 12:45",
- DATE_KEY = "date";
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.util.Properties;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * JUnit testcase that exercises the optional PropertyFile task in ant.
+ * (this is really more of a functional test so far.., but it's enough to let
+ * me start refactoring...)
+ *
+ *created October 2, 2001
+ */
+
+public class PropertyFileTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() throws Exception {
+ buildRule.configureProject(projectFilePath);
+ buildRule.executeTarget("setUp");
+ initTestPropFile();
+ initBuildPropFile();
+ buildRule.configureProject(projectFilePath);
+ buildRule.getProject().setProperty(valueDoesNotGetOverwrittenPropertyFileKey,
+ valueDoesNotGetOverwrittenPropertyFile);
+ }
+
+
+ @Test
+ public void testNonExistingFile() {
+ PropertyFile props = new PropertyFile();
+ props.setProject( buildRule.getProject() );
+ File file = new File("this-file-does-not-exist.properties");
+ props.setFile(file);
+ assertFalse("Properties file exists before test.", file.exists());
+ props.execute();
+ assertTrue("Properties file does not exist after test.", file.exists());
+ file.delete();
+ }
+
+ /**
+ * A unit test for JUnit- Exercises the propertyfile tasks ability to
+ * update properties that are already defined-
+ */
+ @Test
+ public void testUpdatesExistingProperties() throws Exception {
+ Properties beforeUpdate = getTestProperties();
+ assertEquals(FNAME, beforeUpdate.getProperty(FNAME_KEY));
+ assertEquals(LNAME, beforeUpdate.getProperty(LNAME_KEY));
+ assertEquals(EMAIL, beforeUpdate.getProperty(EMAIL_KEY));
+ assertEquals(null, beforeUpdate.getProperty(PHONE_KEY));
+ assertEquals(null, beforeUpdate.getProperty(AGE_KEY));
+ assertEquals(null, beforeUpdate.getProperty(DATE_KEY));
+
+ // ask ant to update the properties...
+ buildRule.executeTarget("update-existing-properties");
+
+ Properties afterUpdate = getTestProperties();
+ assertEquals(NEW_FNAME, afterUpdate.getProperty(FNAME_KEY));
+ assertEquals(NEW_LNAME, afterUpdate.getProperty(LNAME_KEY));
+ assertEquals(NEW_EMAIL, afterUpdate.getProperty(EMAIL_KEY));
+ assertEquals(NEW_PHONE, afterUpdate.getProperty(PHONE_KEY));
+ assertEquals(NEW_AGE, afterUpdate.getProperty(AGE_KEY));
+ assertEquals(NEW_DATE, afterUpdate.getProperty(DATE_KEY));
+ }
+
+ @Test
+ public void testDeleteProperties() throws Exception {
+ Properties beforeUpdate = getTestProperties();
+ assertEquals("Property '" + FNAME_KEY + "' should exist before deleting",
+ FNAME, beforeUpdate.getProperty(FNAME_KEY));
+ assertEquals("Property '" + LNAME_KEY + "' should exist before deleting",
+ LNAME, beforeUpdate.getProperty(LNAME_KEY));
+
+ buildRule.executeTarget("delete-properties");
+ Properties afterUpdate = getTestProperties();
+
+ assertEquals("Property '" + LNAME_KEY + "' should exist after deleting",
+ LNAME, afterUpdate.getProperty(LNAME_KEY));
+ assertNull("Property '" + FNAME_KEY + "' should be deleted",
+ afterUpdate.getProperty(FNAME_KEY));
+ }
+
+ @Test
+ public void testExerciseDefaultAndIncrement() throws Exception {
+ buildRule.executeTarget("exercise");
+ assertEquals("3",buildRule.getProject().getProperty("int.with.default"));
+ assertEquals("1",buildRule.getProject().getProperty("int.without.default"));
+ assertEquals("-->",buildRule.getProject().getProperty("string.with.default"));
+ assertEquals(".",buildRule.getProject().getProperty("string.without.default"));
+ assertEquals("2002/01/21 12:18", buildRule.getProject().getProperty("ethans.birth"));
+ assertEquals("2003/01/21", buildRule.getProject().getProperty("first.birthday"));
+ assertEquals("0124", buildRule.getProject().getProperty("olderThanAWeek"));
+ assertEquals("37", buildRule.getProject().getProperty("existing.prop"));
+ assertEquals("6",buildRule.getProject().getProperty("int.without.value"));
+ }
+
+ @Test
+ public void testValueDoesNotGetOverwritten() {
+ // this test shows that the bug report 21505 is fixed
+ buildRule.executeTarget("bugDemo1");
+ buildRule.executeTarget("bugDemo2");
+ assertEquals("5", buildRule.getProject().getProperty("foo"));
+ }
+
+
+ @Test
+ @Ignore("Previously commented out")
+ public void testDirect() throws Exception {
+ PropertyFile pf = new PropertyFile();
+ pf.setProject(buildRule.getProject());
+ pf.setFile(new File(System.getProperty("root"), testPropsFilePath));
+ PropertyFile.Entry entry = pf.createEntry();
+
+ entry.setKey("date");
+ entry.setValue("123");
+ PropertyFile.Entry.Type type = new PropertyFile.Entry.Type();
+ type.setValue("date");
+ entry.setType(type);
+
+ entry.setPattern("yyyy/MM/dd");
+
+ PropertyFile.Entry.Operation operation = new PropertyFile.Entry.Operation();
+ operation.setValue("+");
+ pf.execute();
+
+ Properties props = getTestProperties();
+ assertEquals("yeehaw", props.getProperty("date"));
+ }
+
+
+ private Properties getTestProperties() throws Exception {
+ Properties testProps = new Properties();
+ FileInputStream propsFile = new FileInputStream(new File(buildRule.getOutputDir(), testPropsFilePath));
+ testProps.load(propsFile);
+ propsFile.close();
+ return testProps;
+ }
+
+
+ private void initTestPropFile() throws IOException {
+ Properties testProps = new Properties();
+ testProps.put(FNAME_KEY, FNAME);
+ testProps.put(LNAME_KEY, LNAME);
+ testProps.put(EMAIL_KEY, EMAIL);
+ testProps.put("existing.prop", "37");
+
+ FileOutputStream fos = new FileOutputStream(new File(buildRule.getOutputDir(), testPropsFilePath));
+ testProps.store(fos, "defaults");
+ fos.close();
+ }
+
+
+ private void initBuildPropFile() throws IOException {
+ Properties buildProps = new Properties();
+ buildProps.put(testPropertyFileKey, testPropertyFile);
+ buildProps.put(FNAME_KEY, NEW_FNAME);
+ buildProps.put(LNAME_KEY, NEW_LNAME);
+ buildProps.put(EMAIL_KEY, NEW_EMAIL);
+ buildProps.put(PHONE_KEY, NEW_PHONE);
+ buildProps.put(AGE_KEY, NEW_AGE);
+ buildProps.put(DATE_KEY, NEW_DATE);
+
+ FileOutputStream fos = new FileOutputStream(new File(buildRule.getOutputDir(), buildPropsFilePath));
+ buildProps.store(fos, null);
+ fos.close();
+ }
+
+ private static final String
+ projectFilePath = "src/etc/testcases/taskdefs/optional/propertyfile.xml",
+
+ testPropertyFile = "propertyfile.test.properties",
+ testPropertyFileKey = "test.propertyfile",
+ testPropsFilePath = testPropertyFile,
+
+ valueDoesNotGetOverwrittenPropertyFile = "overwrite.test.properties",
+ valueDoesNotGetOverwrittenPropertyFileKey = "overwrite.test.propertyfile",
+ valueDoesNotGetOverwrittenPropsFilePath = valueDoesNotGetOverwrittenPropertyFile,
+
+ buildPropsFilePath = "propertyfile.build.properties",
+
+ FNAME = "Bruce",
+ NEW_FNAME = "Clark",
+ FNAME_KEY = "firstname",
+
+ LNAME = "Banner",
+ NEW_LNAME = "Kent",
+ LNAME_KEY = "lastname",
+
+ EMAIL = "incredible@hulk.com",
+ NEW_EMAIL = "kc@superman.com",
+ EMAIL_KEY = "email",
+
+ NEW_PHONE = "(520) 555-1212",
+ PHONE_KEY = "phone",
+
+ NEW_AGE = "30",
+ AGE_KEY = "age",
+
+ NEW_DATE = "2001/01/01 12:45",
+ DATE_KEY = "date";
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PvcsTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PvcsTest.java
index cd7a43168..0f7aff709 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PvcsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/PvcsTest.java
@@ -1,79 +1,79 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.fail;
-
-public class PvcsTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/pvcs.xml");
- }
-
- @Test
- public void test1() {
- try {
- buildRule.executeTarget("test1");
- fail("Required argument repository not specified");
- } catch (BuildException ex) {
- //TODO check exception message
- }
- }
-
- @Test
- public void test2() {
- buildRule.executeTarget("test2");
- }
-
- @Test
- public void test3() {
- buildRule.executeTarget("test3");
- }
-
- @Test
- public void test4() {
- buildRule.executeTarget("test4");
- }
-
- @Test
- public void test5() {
- buildRule.executeTarget("test5");
- }
-
- @Test
- public void test6() {
- try {
- buildRule.executeTarget("test6");
- fail("Failed executing: /never/heard/of/a/directory/structure/like/this/pcli lvf -z " +
- "-aw -pr//ct4serv2/pvcs/monitor /. Exception: /never/heard/of/a/directory/structure/like/this/pcli: not found");
- } catch(BuildException ex) {
- //TODO assert exception message
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+public class PvcsTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/pvcs.xml");
+ }
+
+ @Test
+ public void test1() {
+ try {
+ buildRule.executeTarget("test1");
+ fail("Required argument repository not specified");
+ } catch (BuildException ex) {
+ //TODO check exception message
+ }
+ }
+
+ @Test
+ public void test2() {
+ buildRule.executeTarget("test2");
+ }
+
+ @Test
+ public void test3() {
+ buildRule.executeTarget("test3");
+ }
+
+ @Test
+ public void test4() {
+ buildRule.executeTarget("test4");
+ }
+
+ @Test
+ public void test5() {
+ buildRule.executeTarget("test5");
+ }
+
+ @Test
+ public void test6() {
+ try {
+ buildRule.executeTarget("test6");
+ fail("Failed executing: /never/heard/of/a/directory/structure/like/this/pcli lvf -z " +
+ "-aw -pr//ct4serv2/pvcs/monitor /. Exception: /never/heard/of/a/directory/structure/like/this/pcli: not found");
+ } catch(BuildException ex) {
+ //TODO assert exception message
+ }
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java
index b6c09a5cf..ad5973cb6 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ReplaceRegExpTest.java
@@ -1,132 +1,132 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.FileUtilities;
-import org.apache.tools.ant.util.FileUtils;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import java.util.Properties;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assume.assumeTrue;
-
-/**
- * JUnit Testcase for the optional replaceregexp task.
- *
- */
-public class ReplaceRegExpTest {
- private static final String PROJECT_PATH = "src/etc/testcases/taskdefs/optional";
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject(PROJECT_PATH + "/replaceregexp.xml");
- }
-
- @Test
- public void testReplace() throws IOException {
- Properties original = new Properties();
- FileInputStream propsFile = null;
- try {
- propsFile = new FileInputStream(new File(buildRule.getProject().getBaseDir() + "/replaceregexp.properties"));
- original.load(propsFile);
- } finally {
- if (propsFile != null) {
- propsFile.close();
- propsFile = null;
- }
- }
-
- assertEquals("Def", original.get("OldAbc"));
-
- buildRule.executeTarget("testReplace");
-
- Properties after = new Properties();
- try {
- propsFile = new FileInputStream(new File(buildRule.getOutputDir(), "test.properties"));
- after.load(propsFile);
- } finally {
- if (propsFile != null) {
- propsFile.close();
- }
- }
-
- assertNull(after.get("OldAbc"));
- assertEquals("AbcDef", after.get("NewProp"));
- }
-
- // inspired by bug 22541
- @Test
- public void testDirectoryDateDoesNotChange() {
- buildRule.executeTarget("touchDirectory");
- File myFile = buildRule.getOutputDir();
- long timeStampBefore = myFile.lastModified();
- buildRule.executeTarget("testDirectoryDateDoesNotChange");
- long timeStampAfter = myFile.lastModified();
- assertEquals("directory date should not change",
- timeStampBefore, timeStampAfter);
- }
-
- @Test
- public void testDontAddNewline1() throws IOException {
- buildRule.executeTarget("testDontAddNewline1");
- assertEquals(FileUtilities.getFileContents(new File(buildRule.getOutputDir(), "test.properties")),
- FileUtilities.getFileContents(new File(buildRule.getProject().getBaseDir(), "replaceregexp2.result.properties")));
- }
-
- @Test
- public void testDontAddNewline2() throws IOException {
- buildRule.executeTarget("testDontAddNewline2");
- assertEquals(FileUtilities.getFileContents(new File(buildRule.getOutputDir(), "test.properties")),
- FileUtilities.getFileContents(new File(buildRule.getProject().getBaseDir(), "replaceregexp2.result.properties")));
- }
-
- @Test
- public void testNoPreserveLastModified() throws Exception {
- buildRule.executeTarget("lastModifiedSetup");
- File testFile = new File(buildRule.getOutputDir(), "test.txt");
- assumeTrue(testFile.setLastModified(testFile.lastModified()
- - (FileUtils.getFileUtils().getFileTimestampGranularity() * 3)));
- long ts1 = testFile.lastModified();
- buildRule.executeTarget("testNoPreserve");
- assertTrue(ts1 < testFile.lastModified());
- }
-
- @Test
- public void testPreserveLastModified() throws Exception {
- buildRule.executeTarget("lastModifiedSetup");
- File testFile = new File(buildRule.getOutputDir(), "test.txt");
- assumeTrue(testFile.setLastModified(testFile.lastModified()
- - (FileUtils.getFileUtils().getFileTimestampGranularity() * 3)));
- long ts1 = testFile.lastModified();
- buildRule.executeTarget("testPreserve");
- assertEquals(ts1 , testFile.lastModified());
- }
-
-}// ReplaceRegExpTest
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.FileUtilities;
+import org.apache.tools.ant.util.FileUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.util.Properties;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assume.assumeTrue;
+
+/**
+ * JUnit Testcase for the optional replaceregexp task.
+ *
+ */
+public class ReplaceRegExpTest {
+ private static final String PROJECT_PATH = "src/etc/testcases/taskdefs/optional";
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject(PROJECT_PATH + "/replaceregexp.xml");
+ }
+
+ @Test
+ public void testReplace() throws IOException {
+ Properties original = new Properties();
+ FileInputStream propsFile = null;
+ try {
+ propsFile = new FileInputStream(new File(buildRule.getProject().getBaseDir() + "/replaceregexp.properties"));
+ original.load(propsFile);
+ } finally {
+ if (propsFile != null) {
+ propsFile.close();
+ propsFile = null;
+ }
+ }
+
+ assertEquals("Def", original.get("OldAbc"));
+
+ buildRule.executeTarget("testReplace");
+
+ Properties after = new Properties();
+ try {
+ propsFile = new FileInputStream(new File(buildRule.getOutputDir(), "test.properties"));
+ after.load(propsFile);
+ } finally {
+ if (propsFile != null) {
+ propsFile.close();
+ }
+ }
+
+ assertNull(after.get("OldAbc"));
+ assertEquals("AbcDef", after.get("NewProp"));
+ }
+
+ // inspired by bug 22541
+ @Test
+ public void testDirectoryDateDoesNotChange() {
+ buildRule.executeTarget("touchDirectory");
+ File myFile = buildRule.getOutputDir();
+ long timeStampBefore = myFile.lastModified();
+ buildRule.executeTarget("testDirectoryDateDoesNotChange");
+ long timeStampAfter = myFile.lastModified();
+ assertEquals("directory date should not change",
+ timeStampBefore, timeStampAfter);
+ }
+
+ @Test
+ public void testDontAddNewline1() throws IOException {
+ buildRule.executeTarget("testDontAddNewline1");
+ assertEquals(FileUtilities.getFileContents(new File(buildRule.getOutputDir(), "test.properties")),
+ FileUtilities.getFileContents(new File(buildRule.getProject().getBaseDir(), "replaceregexp2.result.properties")));
+ }
+
+ @Test
+ public void testDontAddNewline2() throws IOException {
+ buildRule.executeTarget("testDontAddNewline2");
+ assertEquals(FileUtilities.getFileContents(new File(buildRule.getOutputDir(), "test.properties")),
+ FileUtilities.getFileContents(new File(buildRule.getProject().getBaseDir(), "replaceregexp2.result.properties")));
+ }
+
+ @Test
+ public void testNoPreserveLastModified() throws Exception {
+ buildRule.executeTarget("lastModifiedSetup");
+ File testFile = new File(buildRule.getOutputDir(), "test.txt");
+ assumeTrue(testFile.setLastModified(testFile.lastModified()
+ - (FileUtils.getFileUtils().getFileTimestampGranularity() * 3)));
+ long ts1 = testFile.lastModified();
+ buildRule.executeTarget("testNoPreserve");
+ assertTrue(ts1 < testFile.lastModified());
+ }
+
+ @Test
+ public void testPreserveLastModified() throws Exception {
+ buildRule.executeTarget("lastModifiedSetup");
+ File testFile = new File(buildRule.getOutputDir(), "test.txt");
+ assumeTrue(testFile.setLastModified(testFile.lastModified()
+ - (FileUtils.getFileUtils().getFileTimestampGranularity() * 3)));
+ long ts1 = testFile.lastModified();
+ buildRule.executeTarget("testPreserve");
+ assertEquals(ts1 , testFile.lastModified());
+ }
+
+}// ReplaceRegExpTest
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoReferenceTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoReferenceTest.java
index 41803de64..d3ec1a3aa 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoReferenceTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoReferenceTest.java
@@ -1,45 +1,45 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-/**
- * Tests using an undefined reference.
- *
- * @since Ant 1.6
- */
-public class RhinoReferenceTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject(
- "src/etc/testcases/taskdefs/optional/script_reference.xml");
- }
-
- @Test
- public void testScript() {
- buildRule.executeTarget("script");
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Tests using an undefined reference.
+ *
+ * @since Ant 1.6
+ */
+public class RhinoReferenceTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject(
+ "src/etc/testcases/taskdefs/optional/script_reference.xml");
+ }
+
+ @Test
+ public void testScript() {
+ buildRule.executeTarget("script");
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
index 35576dcb6..d05cf0cc5 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RhinoScriptTest.java
@@ -1,67 +1,67 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-/**
- * Tests the examples of the <script> task docs.
- *
- * @since Ant 1.5.2
- */
-public class RhinoScriptTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/script.xml");
- }
-
- @Test
- public void testExample1() {
- buildRule.executeTarget("example1");
- int index = buildRule.getLog().indexOf("1");
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("4", index);
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("9", index);
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("16", index);
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("25", index);
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("36", index);
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("49", index);
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("64", index);
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("81", index);
- assertTrue(index > -1);
- index = buildRule.getLog().indexOf("100", index);
- assertTrue(index > -1);
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests the examples of the <script> task docs.
+ *
+ * @since Ant 1.5.2
+ */
+public class RhinoScriptTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/script.xml");
+ }
+
+ @Test
+ public void testExample1() {
+ buildRule.executeTarget("example1");
+ int index = buildRule.getLog().indexOf("1");
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("4", index);
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("9", index);
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("16", index);
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("25", index);
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("36", index);
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("49", index);
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("64", index);
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("81", index);
+ assertTrue(index > -1);
+ index = buildRule.getLog().indexOf("100", index);
+ assertTrue(index > -1);
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java
index ac4462d53..e69ffb4de 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/RpmTest.java
@@ -1,71 +1,71 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.taskdefs.Execute;
-import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
-import org.apache.tools.ant.types.Commandline;
-
-import org.junit.Test;
-
-import static org.junit.Assert.fail;
-import static org.apache.tools.ant.AntAssert.assertContains;
-
-public class RpmTest {
-
- @Test
- public void testShouldThrowExceptionWhenRpmFails() throws Exception {
- Rpm rpm = new MyRpm();
- rpm.setProject(new org.apache.tools.ant.Project());
- rpm.setFailOnError(true);
- // execute
- try {
- rpm.execute();
- fail("should have thrown a build exception");
- } catch (BuildException ex) {
- assertContains("' failed with exit code 2", ex.getMessage());
- }
- }
-
- @Test
- public void testShouldNotThrowExceptionWhenRpmFails() throws Exception {
- Rpm rpm = new MyRpm();
- rpm.execute();
- }
-
- // override some of the code so we can test the handling of the
- // return code only.
- public static class MyRpm extends Rpm {
- protected Execute getExecute(Commandline toExecute,
- ExecuteStreamHandler streamhandler) {
- return new Execute() {
- public int execute() {
- // 2 is != 0 and even, so it is considered
- // failure on any platform currently supported
- // by Execute#isFailure.
- return 2;
- }
- };
- }
-
- public void log(String msg, int msgLevel) {
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.Execute;
+import org.apache.tools.ant.taskdefs.ExecuteStreamHandler;
+import org.apache.tools.ant.types.Commandline;
+
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+import static org.apache.tools.ant.AntAssert.assertContains;
+
+public class RpmTest {
+
+ @Test
+ public void testShouldThrowExceptionWhenRpmFails() throws Exception {
+ Rpm rpm = new MyRpm();
+ rpm.setProject(new org.apache.tools.ant.Project());
+ rpm.setFailOnError(true);
+ // execute
+ try {
+ rpm.execute();
+ fail("should have thrown a build exception");
+ } catch (BuildException ex) {
+ assertContains("' failed with exit code 2", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testShouldNotThrowExceptionWhenRpmFails() throws Exception {
+ Rpm rpm = new MyRpm();
+ rpm.execute();
+ }
+
+ // override some of the code so we can test the handling of the
+ // return code only.
+ public static class MyRpm extends Rpm {
+ protected Execute getExecute(Commandline toExecute,
+ ExecuteStreamHandler streamhandler) {
+ return new Execute() {
+ public int execute() {
+ // 2 is != 0 and even, so it is considered
+ // failure on any platform currently supported
+ // by Execute#isFailure.
+ return 2;
+ }
+ };
+ }
+
+ public void log(String msg, int msgLevel) {
+ }
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/SchemaValidateTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/SchemaValidateTest.java
index 667c8904c..591400124 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/SchemaValidateTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/SchemaValidateTest.java
@@ -1,128 +1,128 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional;
-
-import org.apache.tools.ant.AntAssert;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.fail;
-
-/**
- * Test schema validation
- */
-
-public class SchemaValidateTest {
-
- /**
- * where tasks run
- */
- private final static String TASKDEFS_DIR =
- "src/etc/testcases/taskdefs/optional/";
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject(TASKDEFS_DIR + "schemavalidate.xml");
- }
-
- /**
- * test with no namespace
- */
- @Test
- public void testNoNamespace() throws Exception {
- buildRule.executeTarget("testNoNamespace");
- }
-
- /**
- * add namespace awareness.
- */
- @Test
- public void testNSMapping() throws Exception {
- buildRule.executeTarget("testNSMapping");
- }
-
- @Test
- public void testNoEmptySchemaNamespace() throws Exception {
- try {
- buildRule.executeTarget("testNoEmptySchemaNamespace");
- fail("Empty namespace URI");
- } catch (BuildException ex) {
- AntAssert.assertContains(SchemaValidate.SchemaLocation.ERROR_NO_URI, ex.getMessage());
- }
- }
-
- @Test
- public void testNoEmptySchemaLocation() throws Exception {
- try {
- buildRule.executeTarget("testNoEmptySchemaLocation");
- fail("Empty schema location");
- } catch (BuildException ex) {
- AntAssert.assertContains(SchemaValidate.SchemaLocation.ERROR_NO_LOCATION,
- ex.getMessage());
- }
- }
-
- @Test
- public void testNoFile() throws Exception {
- try {
- buildRule.executeTarget("testNoFile");
- fail("No file at file attribute");
- } catch (BuildException ex) {
- AntAssert.assertContains(SchemaValidate.SchemaLocation.ERROR_NO_FILE,
- ex.getMessage());
- }
- }
-
- @Test
- public void testNoDoubleSchemaLocation() throws Exception {
- try {
- buildRule.executeTarget("testNoDoubleSchemaLocation");
- fail("Two locations for schemas");
- } catch (BuildException ex) {
- AntAssert.assertContains(SchemaValidate.SchemaLocation.ERROR_TWO_LOCATIONS,
- ex.getMessage());
- }
- }
-
- @Test
- public void testNoDuplicateSchema() throws Exception {
- try {
- buildRule.executeTarget("testNoDuplicateSchema");
- fail("duplicate schemas with different values");
- } catch (BuildException ex) {
- AntAssert.assertContains(SchemaValidate.ERROR_DUPLICATE_SCHEMA,
- ex.getMessage());
- }
- }
-
- @Test
- public void testEqualsSchemasOK() throws Exception {
- buildRule.executeTarget("testEqualsSchemasOK");
- }
-
- @Test
- public void testFileset() throws Exception {
- buildRule.executeTarget("testFileset");
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional;
+
+import org.apache.tools.ant.AntAssert;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+/**
+ * Test schema validation
+ */
+
+public class SchemaValidateTest {
+
+ /**
+ * where tasks run
+ */
+ private final static String TASKDEFS_DIR =
+ "src/etc/testcases/taskdefs/optional/";
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject(TASKDEFS_DIR + "schemavalidate.xml");
+ }
+
+ /**
+ * test with no namespace
+ */
+ @Test
+ public void testNoNamespace() throws Exception {
+ buildRule.executeTarget("testNoNamespace");
+ }
+
+ /**
+ * add namespace awareness.
+ */
+ @Test
+ public void testNSMapping() throws Exception {
+ buildRule.executeTarget("testNSMapping");
+ }
+
+ @Test
+ public void testNoEmptySchemaNamespace() throws Exception {
+ try {
+ buildRule.executeTarget("testNoEmptySchemaNamespace");
+ fail("Empty namespace URI");
+ } catch (BuildException ex) {
+ AntAssert.assertContains(SchemaValidate.SchemaLocation.ERROR_NO_URI, ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testNoEmptySchemaLocation() throws Exception {
+ try {
+ buildRule.executeTarget("testNoEmptySchemaLocation");
+ fail("Empty schema location");
+ } catch (BuildException ex) {
+ AntAssert.assertContains(SchemaValidate.SchemaLocation.ERROR_NO_LOCATION,
+ ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testNoFile() throws Exception {
+ try {
+ buildRule.executeTarget("testNoFile");
+ fail("No file at file attribute");
+ } catch (BuildException ex) {
+ AntAssert.assertContains(SchemaValidate.SchemaLocation.ERROR_NO_FILE,
+ ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testNoDoubleSchemaLocation() throws Exception {
+ try {
+ buildRule.executeTarget("testNoDoubleSchemaLocation");
+ fail("Two locations for schemas");
+ } catch (BuildException ex) {
+ AntAssert.assertContains(SchemaValidate.SchemaLocation.ERROR_TWO_LOCATIONS,
+ ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testNoDuplicateSchema() throws Exception {
+ try {
+ buildRule.executeTarget("testNoDuplicateSchema");
+ fail("duplicate schemas with different values");
+ } catch (BuildException ex) {
+ AntAssert.assertContains(SchemaValidate.ERROR_DUPLICATE_SCHEMA,
+ ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testEqualsSchemasOK() throws Exception {
+ buildRule.executeTarget("testEqualsSchemasOK");
+ }
+
+ @Test
+ public void testFileset() throws Exception {
+ buildRule.executeTarget("testFileset");
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java
index 02281eb65..144414142 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/TraXLiaisonTest.java
@@ -1,129 +1,129 @@
-package org.apache.tools.ant.taskdefs.optional;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.ByteArrayInputStream;
-import java.io.File;
-import java.io.InputStream;
-import java.security.Permission;
-
-import junit.framework.AssertionFailedError;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.taskdefs.XSLTLiaison;
-import org.apache.tools.ant.taskdefs.XSLTLogger;
-import org.apache.tools.ant.util.JAXPUtils;
-import org.junit.After;
-import org.junit.Assume;
-import org.junit.Test;
-
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-/**
- * TraX XSLTLiaison testcase
- */
-public class TraXLiaisonTest extends AbstractXSLTLiaisonTest
- implements XSLTLogger {
-
-
- @After
- public void tearDown() {
- File f = new File("xalan2-redirect-out.tmp");
- if (f.exists()) {
- f.delete();
- }
- }
-
- public XSLTLiaison createLiaison() throws Exception {
- TraXLiaison l = new TraXLiaison();
- l.setLogger(this);
- return l;
- }
-
- @Test
- public void testXalan2Redirect() throws Exception {
- try {
- getClass().getClassLoader().loadClass("org.apache.xalan.lib.Redirect");
- } catch (Exception exc) {
- Assume.assumeNoException("xalan redirect is not on the classpath", exc);
- }
- File xsl = getFile("/taskdefs/optional/xalan-redirect-in.xsl");
- liaison.setStylesheet(xsl);
- File out = new File("xalan2-redirect-out-dummy.tmp");
- File in = getFile("/taskdefs/optional/xsltliaison-in.xsl");
- ClassLoader orig = Thread.currentThread().getContextClassLoader();
- try {
- liaison.addParam("xalan-version", "2");
- // Use the JRE's Xerces, not lib/optional/xerces.jar:
- Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) {
- public InputStream getResourceAsStream(String name) {
- if (name.startsWith("META-INF/services/")) {
- // work around JAXP #6723276 in JDK 6
- return new ByteArrayInputStream(new byte[0]);
- }
- return super.getResourceAsStream(name);
- }
- });
- // Tickle #52382:
- System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}});
- liaison.transform(in, out);
- } finally {
- out.delete();
- Thread.currentThread().setContextClassLoader(orig);
- System.setSecurityManager(null);
- }
- }
-
- @Test
- public void testMultipleTransform() throws Exception {
- File xsl = getFile("/taskdefs/optional/xsltliaison-in.xsl");
- liaison.setStylesheet(xsl);
- liaison.addParam("param", "value");
- File in = getFile("/taskdefs/optional/xsltliaison-in.xml");
- // test for 10 consecutives transform
- for (int i = 0; i < 50; i++){
- File out = new File("xsltliaison" + i + ".tmp");
- try {
- liaison.transform(in, out);
- } catch (Exception e){
- throw new BuildException("failed in transform " + i, e);
- } finally {
- out.delete();
- }
- }
- }
-
- @Test
- public void testSystemId(){
- File file = null;
- if ( File.separatorChar == '\\' ){
- file = new File("d:\\jdk");
- } else {
- file = new File("/user/local/bin");
- }
- String systemid = JAXPUtils.getSystemId(file);
- assertTrue("SystemIDs should start by file:/", systemid.startsWith("file:/"));
- assertTrue("SystemIDs should not start with file:////", !systemid.startsWith("file:////"));
- }
-
- public void log(String message) {
- throw new AssertionFailedError("Liaison sent message: "+message);
- }
-
-}
+package org.apache.tools.ant.taskdefs.optional;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.ByteArrayInputStream;
+import java.io.File;
+import java.io.InputStream;
+import java.security.Permission;
+
+import junit.framework.AssertionFailedError;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.taskdefs.XSLTLiaison;
+import org.apache.tools.ant.taskdefs.XSLTLogger;
+import org.apache.tools.ant.util.JAXPUtils;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Test;
+
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/**
+ * TraX XSLTLiaison testcase
+ */
+public class TraXLiaisonTest extends AbstractXSLTLiaisonTest
+ implements XSLTLogger {
+
+
+ @After
+ public void tearDown() {
+ File f = new File("xalan2-redirect-out.tmp");
+ if (f.exists()) {
+ f.delete();
+ }
+ }
+
+ public XSLTLiaison createLiaison() throws Exception {
+ TraXLiaison l = new TraXLiaison();
+ l.setLogger(this);
+ return l;
+ }
+
+ @Test
+ public void testXalan2Redirect() throws Exception {
+ try {
+ getClass().getClassLoader().loadClass("org.apache.xalan.lib.Redirect");
+ } catch (Exception exc) {
+ Assume.assumeNoException("xalan redirect is not on the classpath", exc);
+ }
+ File xsl = getFile("/taskdefs/optional/xalan-redirect-in.xsl");
+ liaison.setStylesheet(xsl);
+ File out = new File("xalan2-redirect-out-dummy.tmp");
+ File in = getFile("/taskdefs/optional/xsltliaison-in.xsl");
+ ClassLoader orig = Thread.currentThread().getContextClassLoader();
+ try {
+ liaison.addParam("xalan-version", "2");
+ // Use the JRE's Xerces, not lib/optional/xerces.jar:
+ Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) {
+ public InputStream getResourceAsStream(String name) {
+ if (name.startsWith("META-INF/services/")) {
+ // work around JAXP #6723276 in JDK 6
+ return new ByteArrayInputStream(new byte[0]);
+ }
+ return super.getResourceAsStream(name);
+ }
+ });
+ // Tickle #52382:
+ System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}});
+ liaison.transform(in, out);
+ } finally {
+ out.delete();
+ Thread.currentThread().setContextClassLoader(orig);
+ System.setSecurityManager(null);
+ }
+ }
+
+ @Test
+ public void testMultipleTransform() throws Exception {
+ File xsl = getFile("/taskdefs/optional/xsltliaison-in.xsl");
+ liaison.setStylesheet(xsl);
+ liaison.addParam("param", "value");
+ File in = getFile("/taskdefs/optional/xsltliaison-in.xml");
+ // test for 10 consecutives transform
+ for (int i = 0; i < 50; i++){
+ File out = new File("xsltliaison" + i + ".tmp");
+ try {
+ liaison.transform(in, out);
+ } catch (Exception e){
+ throw new BuildException("failed in transform " + i, e);
+ } finally {
+ out.delete();
+ }
+ }
+ }
+
+ @Test
+ public void testSystemId(){
+ File file = null;
+ if ( File.separatorChar == '\\' ){
+ file = new File("d:\\jdk");
+ } else {
+ file = new File("/user/local/bin");
+ }
+ String systemid = JAXPUtils.getSystemId(file);
+ assertTrue("SystemIDs should start by file:/", systemid.startsWith("file:/"));
+ assertTrue("SystemIDs should not start with file:////", !systemid.startsWith("file:////"));
+ }
+
+ public void log(String message) {
+ throw new AssertionFailedError("Liaison sent message: "+message);
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateCatalogTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateCatalogTest.java
index c9948bb9a..02b11a328 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateCatalogTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateCatalogTest.java
@@ -1,71 +1,71 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-/**
- * Tests the XMLValidate optional task with nested external catalogs.
- *
- * @see XmlValidateTest
- * @since Ant 1.6
- */
-public class XmlValidateCatalogTest {
-
- /**
- * where tasks run
- */
- private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/";
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject(TASKDEFS_DIR + "xmlvalidate.xml");
- }
-
-
- /**
- * catalogfiles fileset should be ignored
- * if resolver.jar is not present, but will
- * be used if it is. either way, test should
- * work b/c we have a nested dtd with the same
- * entity
- */
- @Test
- public void testXmlCatalogFiles() {
- buildRule.executeTarget("xmlcatalogfiles");
- }
-
- /**
- * Test nested catalogpath.
- * It should be ignored if resolver.jar is not
- * present, but will be used if it is. either
- * way, test should work b/c we have a nested
- * dtd with the same entity
- */
- @Test
- public void testXmlCatalogPath() {
- buildRule.executeTarget("xmlcatalogpath");
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Tests the XMLValidate optional task with nested external catalogs.
+ *
+ * @see XmlValidateTest
+ * @since Ant 1.6
+ */
+public class XmlValidateCatalogTest {
+
+ /**
+ * where tasks run
+ */
+ private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/";
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject(TASKDEFS_DIR + "xmlvalidate.xml");
+ }
+
+
+ /**
+ * catalogfiles fileset should be ignored
+ * if resolver.jar is not present, but will
+ * be used if it is. either way, test should
+ * work b/c we have a nested dtd with the same
+ * entity
+ */
+ @Test
+ public void testXmlCatalogFiles() {
+ buildRule.executeTarget("xmlcatalogfiles");
+ }
+
+ /**
+ * Test nested catalogpath.
+ * It should be ignored if resolver.jar is not
+ * present, but will be used if it is. either
+ * way, test should work b/c we have a nested
+ * dtd with the same entity
+ */
+ @Test
+ public void testXmlCatalogPath() {
+ buildRule.executeTarget("xmlcatalogpath");
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java
index 58f7a4b1f..869031f6c 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XmlValidateTest.java
@@ -1,193 +1,193 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.junit.internal.AssumptionViolatedException;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * Tests the XMLValidate optional task, by running targets in the test script
- * src/etc/testcases/taskdefs/optional/xmlvalidate.xml
- *
- *
- * @see XmlValidateCatalogTest
- * @since Ant 1.5
- */
-public class XmlValidateTest {
-
- /**
- * where tasks run
- */
- private final static String TASKDEFS_DIR =
- "src/etc/testcases/taskdefs/optional/";
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject(TASKDEFS_DIR + "xmlvalidate.xml");
- }
-
- /**
- * Basic inline 'dtd' element test.
- */
- @Test
- public void testValidate() throws Exception {
- buildRule.executeTarget("testValidate");
- }
-
- /**
- * Test indirect validation.
- */
- @Test
- public void testDeepValidate() throws Exception {
- buildRule.executeTarget("testDeepValidate");
- }
-
- @Test
- public void testXmlCatalog() {
- buildRule.executeTarget("xmlcatalog");
- }
-
- @Test
- public void testXmlCatalogViaRefid() {
- buildRule.executeTarget("xmlcatalogViaRefid");
- }
-
- /**
- * Test that the nested dtd element is used when resolver.jar is not
- * present. This test should pass either way.
- */
- @Test
- public void testXmlCatalogFiles() {
- buildRule.executeTarget("xmlcatalogfiles-override");
- }
-
- /**
- * Test nested catalogpath.
- * Test that the nested dtd element is used when resolver.jar is not
- * present. This test should pass either way.
- */
- @Test
- public void testXmlCatalogPath() {
- buildRule.executeTarget("xmlcatalogpath-override");
- }
-
- /**
- * Test nested xmlcatalog definitions
- */
- @Test
- public void testXmlCatalogNested() {
- buildRule.executeTarget("xmlcatalognested");
- }
-
- /**
- * Test xml schema validation
- */
- @Test
- public void testXmlSchemaGood() throws BuildException {
- try {
- buildRule.executeTarget("testSchemaGood");
- } catch (BuildException e) {
- if (e
- .getMessage()
- .endsWith(" doesn't recognize feature http://apache.org/xml/features/validation/schema")
- || e.getMessage().endsWith(
- " doesn't support feature http://apache.org/xml/features/validation/schema")) {
- throw new AssumptionViolatedException("parser doesn't support schema");
- } else {
- throw e;
- }
- }
- }
- /**
- * Test xml schema validation
- */
- @Test
- public void testXmlSchemaBad() {
- try {
- buildRule.executeTarget("testSchemaBad");
- fail("Should throw BuildException because 'Bad Schema Validation'");
-
- } catch (BuildException e) {
- if (e
- .getMessage()
- .endsWith(" doesn't recognize feature http://apache.org/xml/features/validation/schema")
- || e.getMessage().endsWith(
- " doesn't support feature http://apache.org/xml/features/validation/schema")) {
- throw new AssumptionViolatedException("parser doesn't support schema");
- } else {
- assertTrue(
- e.getMessage().indexOf("not a valid XML document") > -1);
- }
- }
- }
-
- /**
- * iso-2022-jp.xml is valid but wouldn't get recognized on systems
- * with a different native encoding.
- *
- * Bug 11279
- */
- @Test
- public void testIso2022Jp() {
- buildRule.executeTarget("testIso2022Jp");
- }
-
- /**
- * utf-8.xml is invalid as it contains non-UTF-8 characters, but
- * would pass on systems with a native iso-8859-1 (or similar)
- * encoding.
- *
- * Bug 11279
- */
- @Test
- public void testUtf8() {
- try {
- buildRule.executeTarget("testUtf8");
- fail("Invalid characters in file");
- } catch(BuildException ex) {
- //TODO assert exception message
- }
- }
-
- // Tests property element, using XML schema properties as an example.
- @Test
- public void testPropertySchemaForValidXML() {
- buildRule.executeTarget("testProperty.validXML");
- }
-
- @Test
- public void testPropertySchemaForInvalidXML() {
- try {
- buildRule.executeTarget("testProperty.invalidXML");
- fail("XML file does not satisfy schema");
- } catch(BuildException ex) {
- //TODO assert exception message
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.junit.internal.AssumptionViolatedException;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests the XMLValidate optional task, by running targets in the test script
+ * src/etc/testcases/taskdefs/optional/xmlvalidate.xml
+ *
+ *
+ * @see XmlValidateCatalogTest
+ * @since Ant 1.5
+ */
+public class XmlValidateTest {
+
+ /**
+ * where tasks run
+ */
+ private final static String TASKDEFS_DIR =
+ "src/etc/testcases/taskdefs/optional/";
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject(TASKDEFS_DIR + "xmlvalidate.xml");
+ }
+
+ /**
+ * Basic inline 'dtd' element test.
+ */
+ @Test
+ public void testValidate() throws Exception {
+ buildRule.executeTarget("testValidate");
+ }
+
+ /**
+ * Test indirect validation.
+ */
+ @Test
+ public void testDeepValidate() throws Exception {
+ buildRule.executeTarget("testDeepValidate");
+ }
+
+ @Test
+ public void testXmlCatalog() {
+ buildRule.executeTarget("xmlcatalog");
+ }
+
+ @Test
+ public void testXmlCatalogViaRefid() {
+ buildRule.executeTarget("xmlcatalogViaRefid");
+ }
+
+ /**
+ * Test that the nested dtd element is used when resolver.jar is not
+ * present. This test should pass either way.
+ */
+ @Test
+ public void testXmlCatalogFiles() {
+ buildRule.executeTarget("xmlcatalogfiles-override");
+ }
+
+ /**
+ * Test nested catalogpath.
+ * Test that the nested dtd element is used when resolver.jar is not
+ * present. This test should pass either way.
+ */
+ @Test
+ public void testXmlCatalogPath() {
+ buildRule.executeTarget("xmlcatalogpath-override");
+ }
+
+ /**
+ * Test nested xmlcatalog definitions
+ */
+ @Test
+ public void testXmlCatalogNested() {
+ buildRule.executeTarget("xmlcatalognested");
+ }
+
+ /**
+ * Test xml schema validation
+ */
+ @Test
+ public void testXmlSchemaGood() throws BuildException {
+ try {
+ buildRule.executeTarget("testSchemaGood");
+ } catch (BuildException e) {
+ if (e
+ .getMessage()
+ .endsWith(" doesn't recognize feature http://apache.org/xml/features/validation/schema")
+ || e.getMessage().endsWith(
+ " doesn't support feature http://apache.org/xml/features/validation/schema")) {
+ throw new AssumptionViolatedException("parser doesn't support schema");
+ } else {
+ throw e;
+ }
+ }
+ }
+ /**
+ * Test xml schema validation
+ */
+ @Test
+ public void testXmlSchemaBad() {
+ try {
+ buildRule.executeTarget("testSchemaBad");
+ fail("Should throw BuildException because 'Bad Schema Validation'");
+
+ } catch (BuildException e) {
+ if (e
+ .getMessage()
+ .endsWith(" doesn't recognize feature http://apache.org/xml/features/validation/schema")
+ || e.getMessage().endsWith(
+ " doesn't support feature http://apache.org/xml/features/validation/schema")) {
+ throw new AssumptionViolatedException("parser doesn't support schema");
+ } else {
+ assertTrue(
+ e.getMessage().indexOf("not a valid XML document") > -1);
+ }
+ }
+ }
+
+ /**
+ * iso-2022-jp.xml is valid but wouldn't get recognized on systems
+ * with a different native encoding.
+ *
+ * Bug 11279
+ */
+ @Test
+ public void testIso2022Jp() {
+ buildRule.executeTarget("testIso2022Jp");
+ }
+
+ /**
+ * utf-8.xml is invalid as it contains non-UTF-8 characters, but
+ * would pass on systems with a native iso-8859-1 (or similar)
+ * encoding.
+ *
+ * Bug 11279
+ */
+ @Test
+ public void testUtf8() {
+ try {
+ buildRule.executeTarget("testUtf8");
+ fail("Invalid characters in file");
+ } catch(BuildException ex) {
+ //TODO assert exception message
+ }
+ }
+
+ // Tests property element, using XML schema properties as an example.
+ @Test
+ public void testPropertySchemaForValidXML() {
+ buildRule.executeTarget("testProperty.validXML");
+ }
+
+ @Test
+ public void testPropertySchemaForInvalidXML() {
+ try {
+ buildRule.executeTarget("testProperty.invalidXML");
+ fail("XML file does not satisfy schema");
+ } catch(BuildException ex) {
+ //TODO assert exception message
+ }
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XsltTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XsltTest.java
index a5b71def9..594dadab7 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XsltTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/XsltTest.java
@@ -1,86 +1,86 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.fail;
-
-/**
- * Tests the {@link org.apache.tools.ant.taskdefs.XSLTProcess} task.
- * TODO merge with {@link org.apache.tools.ant.taskdefs.StyleTest}?
- * @since Ant 1.5
- */
-public class XsltTest {
-
- /**
- * where tasks run
- */
- private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/";
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject(TASKDEFS_DIR + "xslt.xml");
- }
-
-
- @Test
- public void testCatchNoDtd() {
- try {
- buildRule.executeTarget("testCatchNoDtd");
- fail("Expected failure");
- } catch(BuildException ex) {
- //TODO assert exception message
- }
- }
-
- @Test
- public void testCatalog() throws Exception {
- buildRule.executeTarget("testCatalog");
- }
-
- @Test
- public void testOutputProperty() throws Exception {
- buildRule.executeTarget("testOutputProperty");
- }
-
- @Test
- public void testXMLWithEntitiesInNonAsciiPath() throws Exception {
- buildRule.executeTarget("testXMLWithEntitiesInNonAsciiPath");
- }
-
- /**
- * check that the system id gets set properly on stylesheets.
- * @throws Exception if something goes wrong.
- */
- @Test
- public void testStyleSheetWithInclude() throws Exception {
- buildRule.executeTarget("testStyleSheetWithInclude");
- if (buildRule.getLog().indexOf("java.io.FileNotFoundException") != -1) {
- fail("xsl:include was not found");
- }
- }
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+/**
+ * Tests the {@link org.apache.tools.ant.taskdefs.XSLTProcess} task.
+ * TODO merge with {@link org.apache.tools.ant.taskdefs.StyleTest}?
+ * @since Ant 1.5
+ */
+public class XsltTest {
+
+ /**
+ * where tasks run
+ */
+ private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/";
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject(TASKDEFS_DIR + "xslt.xml");
+ }
+
+
+ @Test
+ public void testCatchNoDtd() {
+ try {
+ buildRule.executeTarget("testCatchNoDtd");
+ fail("Expected failure");
+ } catch(BuildException ex) {
+ //TODO assert exception message
+ }
+ }
+
+ @Test
+ public void testCatalog() throws Exception {
+ buildRule.executeTarget("testCatalog");
+ }
+
+ @Test
+ public void testOutputProperty() throws Exception {
+ buildRule.executeTarget("testOutputProperty");
+ }
+
+ @Test
+ public void testXMLWithEntitiesInNonAsciiPath() throws Exception {
+ buildRule.executeTarget("testXMLWithEntitiesInNonAsciiPath");
+ }
+
+ /**
+ * check that the system id gets set properly on stylesheets.
+ * @throws Exception if something goes wrong.
+ */
+ @Test
+ public void testStyleSheetWithInclude() throws Exception {
+ buildRule.executeTarget("testStyleSheetWithInclude");
+ if (buildRule.getLog().indexOf("java.io.FileNotFoundException") != -1) {
+ fail("xsl:include was not found");
+ }
+ }
+}
+
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java
index 95c1eb0b1..01e057561 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/depend/DependTest.java
@@ -1,213 +1,213 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.depend;
-
-import java.io.File;
-import java.util.Hashtable;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.FileUtilities;
-import org.apache.tools.ant.types.FileSet;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.apache.tools.ant.AntAssert.assertContains;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * Testcase for the Depend optional task.
- *
- */
-public class DependTest {
- public static final String RESULT_FILESET = "result";
-
- public static final String TEST_BUILD_FILE
- = "src/etc/testcases/taskdefs/optional/depend/depend.xml";
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject(TEST_BUILD_FILE);
- }
-
- /**
- * Test direct dependency removal
- */
- @Test
- public void testDirect() {
- buildRule.executeTarget("src1setup");
- buildRule.executeTarget("compile");
-
- FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5);
- FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5);
-
- buildRule.executeTarget("testdirect");
- Hashtable files = getResultFiles();
- assertEquals("Depend did not leave correct number of files", 3,
- files.size());
- assertTrue("Result did not contain A.class",
- files.containsKey("A.class"));
- assertTrue("Result did not contain D.class",
- files.containsKey("D.class"));
- }
-
- /**
- * Test dependency traversal (closure)
- */
- @Test
- public void testClosure() {
- buildRule.executeTarget("src1setup");
- buildRule.executeTarget("compile");
-
- FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5);
- FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5);
-
- buildRule.executeTarget("testclosure");
- Hashtable files = getResultFiles();
- assertTrue("Depend did not leave correct number of files",
- files.size() <= 2);
- assertTrue("Result did not contain D.class",
- files.containsKey("D.class"));
- }
-
- /**
- * Test that inner class dependencies trigger deletion of the outer class
- */
- @Test
- public void testInner() {
- buildRule.executeTarget("src2setup");
- buildRule.executeTarget("compile");
-
- FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5);
- FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5);
-
-
- buildRule.executeTarget("testinner");
- assertEquals("Depend did not leave correct number of files", 0,
- getResultFiles().size());
- }
-
- /**
- * Test that multi-leve inner class dependencies trigger deletion of
- * the outer class
- */
- @Test
- public void testInnerInner() {
- buildRule.executeTarget("src3setup");
- buildRule.executeTarget("compile");
-
- FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5);
- FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5);
-
- buildRule.executeTarget("testinnerinner");
- assertEquals("Depend did not leave correct number of files", 0,
- getResultFiles().size());
- }
-
- /**
- * Test that an exception is thrown when there is no source
- */
- @Test
- public void testNoSource() {
- try {
- buildRule.executeTarget("testnosource");
- fail("Build exception expected: No source specified");
- } catch(BuildException ex) {
- assertContains("srcdir attribute must be set", ex.getMessage());
- }
- }
-
- /**
- * Test that an exception is thrown when the source attribute is empty
- */
- @Test
- public void testEmptySource() {
- try {
- buildRule.executeTarget("testemptysource");
- fail("Build exception expected: No source specified");
- } catch(BuildException ex) {
- assertContains("srcdir attribute must be non-empty", ex.getMessage());
- }
- }
-
- /**
- * Read the result fileset into a Hashtable
- *
- * @return a Hashtable containing the names of the files in the result
- * fileset
- */
- private Hashtable getResultFiles() {
- FileSet resultFileSet = (FileSet) buildRule.getProject().getReference(RESULT_FILESET);
- DirectoryScanner scanner = resultFileSet.getDirectoryScanner(buildRule.getProject());
- String[] scannedFiles = scanner.getIncludedFiles();
- Hashtable files = new Hashtable();
- for (int i = 0; i < scannedFiles.length; ++i) {
- files.put(scannedFiles[i], scannedFiles[i]);
- }
- return files;
- }
-
-
- /**
- * Test mutual dependency between inner and outer do not cause both to be
- * deleted
- */
- @Test
- public void testInnerClosure() {
- buildRule.executeTarget("testinnerclosure");
- assertEquals("Depend did not leave correct number of files", 4,
- getResultFiles().size());
- }
-
- /**
- * Test the operation of the cache
- */
- @Test
- public void testCache() {
- buildRule.executeTarget("testcache");
- }
-
- /**
- * Test the detection and warning of non public classes
- */
- @Test
- public void testNonPublic() {
- buildRule.executeTarget("src5setup");
- buildRule.executeTarget("compile");
-
- FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5);
- FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5);
-
- buildRule.executeTarget("testnonpublic");
- String log = buildRule.getLog();
- assertContains("Expected warning about APrivate",
- "The class APrivate in file", log);
- assertContains("but has not been deleted because its source file "
- + "could not be determined",
- "The class APrivate in file", log);
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional.depend;
+
+import java.io.File;
+import java.util.Hashtable;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.FileUtilities;
+import org.apache.tools.ant.types.FileSet;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.apache.tools.ant.AntAssert.assertContains;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Testcase for the Depend optional task.
+ *
+ */
+public class DependTest {
+ public static final String RESULT_FILESET = "result";
+
+ public static final String TEST_BUILD_FILE
+ = "src/etc/testcases/taskdefs/optional/depend/depend.xml";
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject(TEST_BUILD_FILE);
+ }
+
+ /**
+ * Test direct dependency removal
+ */
+ @Test
+ public void testDirect() {
+ buildRule.executeTarget("src1setup");
+ buildRule.executeTarget("compile");
+
+ FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5);
+ FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5);
+
+ buildRule.executeTarget("testdirect");
+ Hashtable files = getResultFiles();
+ assertEquals("Depend did not leave correct number of files", 3,
+ files.size());
+ assertTrue("Result did not contain A.class",
+ files.containsKey("A.class"));
+ assertTrue("Result did not contain D.class",
+ files.containsKey("D.class"));
+ }
+
+ /**
+ * Test dependency traversal (closure)
+ */
+ @Test
+ public void testClosure() {
+ buildRule.executeTarget("src1setup");
+ buildRule.executeTarget("compile");
+
+ FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5);
+ FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5);
+
+ buildRule.executeTarget("testclosure");
+ Hashtable files = getResultFiles();
+ assertTrue("Depend did not leave correct number of files",
+ files.size() <= 2);
+ assertTrue("Result did not contain D.class",
+ files.containsKey("D.class"));
+ }
+
+ /**
+ * Test that inner class dependencies trigger deletion of the outer class
+ */
+ @Test
+ public void testInner() {
+ buildRule.executeTarget("src2setup");
+ buildRule.executeTarget("compile");
+
+ FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5);
+ FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5);
+
+
+ buildRule.executeTarget("testinner");
+ assertEquals("Depend did not leave correct number of files", 0,
+ getResultFiles().size());
+ }
+
+ /**
+ * Test that multi-leve inner class dependencies trigger deletion of
+ * the outer class
+ */
+ @Test
+ public void testInnerInner() {
+ buildRule.executeTarget("src3setup");
+ buildRule.executeTarget("compile");
+
+ FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5);
+ FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5);
+
+ buildRule.executeTarget("testinnerinner");
+ assertEquals("Depend did not leave correct number of files", 0,
+ getResultFiles().size());
+ }
+
+ /**
+ * Test that an exception is thrown when there is no source
+ */
+ @Test
+ public void testNoSource() {
+ try {
+ buildRule.executeTarget("testnosource");
+ fail("Build exception expected: No source specified");
+ } catch(BuildException ex) {
+ assertContains("srcdir attribute must be set", ex.getMessage());
+ }
+ }
+
+ /**
+ * Test that an exception is thrown when the source attribute is empty
+ */
+ @Test
+ public void testEmptySource() {
+ try {
+ buildRule.executeTarget("testemptysource");
+ fail("Build exception expected: No source specified");
+ } catch(BuildException ex) {
+ assertContains("srcdir attribute must be non-empty", ex.getMessage());
+ }
+ }
+
+ /**
+ * Read the result fileset into a Hashtable
+ *
+ * @return a Hashtable containing the names of the files in the result
+ * fileset
+ */
+ private Hashtable getResultFiles() {
+ FileSet resultFileSet = (FileSet) buildRule.getProject().getReference(RESULT_FILESET);
+ DirectoryScanner scanner = resultFileSet.getDirectoryScanner(buildRule.getProject());
+ String[] scannedFiles = scanner.getIncludedFiles();
+ Hashtable files = new Hashtable();
+ for (int i = 0; i < scannedFiles.length; ++i) {
+ files.put(scannedFiles[i], scannedFiles[i]);
+ }
+ return files;
+ }
+
+
+ /**
+ * Test mutual dependency between inner and outer do not cause both to be
+ * deleted
+ */
+ @Test
+ public void testInnerClosure() {
+ buildRule.executeTarget("testinnerclosure");
+ assertEquals("Depend did not leave correct number of files", 4,
+ getResultFiles().size());
+ }
+
+ /**
+ * Test the operation of the cache
+ */
+ @Test
+ public void testCache() {
+ buildRule.executeTarget("testcache");
+ }
+
+ /**
+ * Test the detection and warning of non public classes
+ */
+ @Test
+ public void testNonPublic() {
+ buildRule.executeTarget("src5setup");
+ buildRule.executeTarget("compile");
+
+ FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("tempsrc.dir")), 5);
+ FileUtilities.rollbackTimetamps(new File(buildRule.getProject().getProperty("classes.dir")), 5);
+
+ buildRule.executeTarget("testnonpublic");
+ String log = buildRule.getLog();
+ assertContains("Expected warning about APrivate",
+ "The class APrivate in file", log);
+ assertContains("but has not been deleted because its source file "
+ + "could not be determined",
+ "The class APrivate in file", log);
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java
index 6abc4f2d7..b8749c087 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/i18n/TranslateTest.java
@@ -1,87 +1,87 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.i18n;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-
-import static org.junit.Assert.assertTrue;
-
-/**
- * Tests the Translate task.
- *
- * @since Ant 1.6
- */
-public class TranslateTest {
-
- @Rule
- public final BuildFileRule buildRule = new BuildFileRule();
-
- static private final int BUF_SIZE = 32768;
-
- private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/i18n/translate";
-
-
-
- @Before
- public void setUp() {
- buildRule.configureProject(TASKDEFS_DIR + "/translate.xml");
- }
-
- @Test
- public void test1() throws IOException {
- buildRule.executeTarget("test1");
- assertTrue("translation of "+ TASKDEFS_DIR + "/input/template.txt",compareFiles(new File(buildRule.getProject().getBaseDir(), "expected/de/template.txt"),
- new File(buildRule.getOutputDir(), "de/template.txt")));
- }
- private boolean compareFiles(File file1, File file2) throws IOException {
- if (!file1.exists() || !file2.exists()) {
- return false;
- }
-
- if (file1.length() != file2.length()) {
- return false;
- }
-
- // byte - byte compare
- byte[] buffer1 = new byte[BUF_SIZE];
- byte[] buffer2 = new byte[BUF_SIZE];
-
- FileInputStream fis1 = new FileInputStream(file1);
- FileInputStream fis2 = new FileInputStream(file2);
- int index = 0;
- int read = 0;
- while ((read = fis1.read(buffer1)) != -1) {
- fis2.read(buffer2);
- for (int i = 0; i < read; ++i, ++index) {
- if (buffer1[i] != buffer2[i]) {
- return false;
- }
- }
- }
- return true;
- }
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional.i18n;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+
+import static org.junit.Assert.assertTrue;
+
+/**
+ * Tests the Translate task.
+ *
+ * @since Ant 1.6
+ */
+public class TranslateTest {
+
+ @Rule
+ public final BuildFileRule buildRule = new BuildFileRule();
+
+ static private final int BUF_SIZE = 32768;
+
+ private final static String TASKDEFS_DIR = "src/etc/testcases/taskdefs/optional/i18n/translate";
+
+
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject(TASKDEFS_DIR + "/translate.xml");
+ }
+
+ @Test
+ public void test1() throws IOException {
+ buildRule.executeTarget("test1");
+ assertTrue("translation of "+ TASKDEFS_DIR + "/input/template.txt",compareFiles(new File(buildRule.getProject().getBaseDir(), "expected/de/template.txt"),
+ new File(buildRule.getOutputDir(), "de/template.txt")));
+ }
+ private boolean compareFiles(File file1, File file2) throws IOException {
+ if (!file1.exists() || !file2.exists()) {
+ return false;
+ }
+
+ if (file1.length() != file2.length()) {
+ return false;
+ }
+
+ // byte - byte compare
+ byte[] buffer1 = new byte[BUF_SIZE];
+ byte[] buffer2 = new byte[BUF_SIZE];
+
+ FileInputStream fis1 = new FileInputStream(file1);
+ FileInputStream fis2 = new FileInputStream(file2);
+ int index = 0;
+ int read = 0;
+ while ((read = fis1.read(buffer1)) != -1) {
+ fis2.read(buffer2);
+ for (int i = 0; i < read; ++i, ++index) {
+ if (buffer1[i] != buffer2[i]) {
+ return false;
+ }
+ }
+ }
+ return true;
+ }
+}
+
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java
index be79262d0..a13a46658 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/image/ImageTest.java
@@ -1,133 +1,133 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.image;
-
-import org.apache.tools.ant.AntAssert;
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.util.FileUtils;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-
-import java.io.File;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assume.assumeTrue;
-
-
-/**
- * Tests the Image task.
- *
- * @since Ant 1.5
- */
-public class ImageTest {
-
- private final static String TASKDEFS_DIR =
- "src/etc/testcases/taskdefs/optional/image/";
- private final static String LARGEIMAGE = "largeimage.jpg";
-
- private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject(TASKDEFS_DIR + "image.xml");
- }
-
-
- @Test
- public void testEchoToLog() {
- buildRule.executeTarget("testEchoToLog");
- AntAssert.assertContains("Processing File", buildRule.getLog());
- }
-
- @Test
- public void testSimpleScale(){
- buildRule.executeTarget("testSimpleScale");
- AntAssert.assertContains("Processing File", buildRule.getLog());
-
- File f = new File(buildRule.getOutputDir(), LARGEIMAGE);
- assertTrue(
- "Did not create "+f.getAbsolutePath(),
- f.exists());
-
- }
-
- @Test
- public void testOverwriteTrue() throws InterruptedException {
- buildRule.executeTarget("testSimpleScale");
- AntAssert.assertContains("Processing File", buildRule.getLog());
- File f = new File(buildRule.getOutputDir(), LARGEIMAGE);
- assumeTrue("Could not change file modificaiton date",
- f.setLastModified(f.lastModified() - (FILE_UTILS.getFileTimestampGranularity() * 2)));
- long lastModified = f.lastModified();
- buildRule.executeTarget("testOverwriteTrue");
- AntAssert.assertContains("Processing File", buildRule.getLog());
- f = new File(buildRule.getOutputDir(), LARGEIMAGE);
- long overwrittenLastModified = f.lastModified();
- assertTrue("File was not overwritten.",
- lastModified < overwrittenLastModified);
- }
-
- @Test
- public void testOverwriteFalse() {
- buildRule.executeTarget("testSimpleScale");
- AntAssert.assertContains("Processing File", buildRule.getLog());
- File f = new File(buildRule.getOutputDir(), LARGEIMAGE);
- long lastModified = f.lastModified();
- buildRule.executeTarget("testOverwriteFalse");
- AntAssert.assertContains("Processing File", buildRule.getLog());
- f = new File(buildRule.getOutputDir(), LARGEIMAGE);
- long overwrittenLastModified = f.lastModified();
- assertTrue("File was overwritten.",
- lastModified == overwrittenLastModified);
- }
-
- @Test
- public void testSimpleScaleWithMapper() {
- buildRule.executeTarget("testSimpleScaleWithMapper");
- AntAssert.assertContains("Processing File", buildRule.getLog());
- File f = new File(buildRule.getOutputDir(), "scaled-" + LARGEIMAGE);
- assertTrue(
- "Did not create "+f.getAbsolutePath(),
- f.exists());
-
- }
-
- @Test
- @Ignore("Previously named in a manner to prevent execution")
- public void testFailOnError() {
- try {
- buildRule.executeTarget("testFailOnError");
- AntAssert.assertContains("Unable to process image stream", buildRule.getLog());
- }
- catch (RuntimeException re){
- assertTrue("Run time exception should say "
- + "'Unable to process image stream'. :"
- + re.toString(),
- re.toString()
- .indexOf("Unable to process image stream") > -1);
- }
- }
-
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional.image;
+
+import org.apache.tools.ant.AntAssert;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.util.FileUtils;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assume.assumeTrue;
+
+
+/**
+ * Tests the Image task.
+ *
+ * @since Ant 1.5
+ */
+public class ImageTest {
+
+ private final static String TASKDEFS_DIR =
+ "src/etc/testcases/taskdefs/optional/image/";
+ private final static String LARGEIMAGE = "largeimage.jpg";
+
+ private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject(TASKDEFS_DIR + "image.xml");
+ }
+
+
+ @Test
+ public void testEchoToLog() {
+ buildRule.executeTarget("testEchoToLog");
+ AntAssert.assertContains("Processing File", buildRule.getLog());
+ }
+
+ @Test
+ public void testSimpleScale(){
+ buildRule.executeTarget("testSimpleScale");
+ AntAssert.assertContains("Processing File", buildRule.getLog());
+
+ File f = new File(buildRule.getOutputDir(), LARGEIMAGE);
+ assertTrue(
+ "Did not create "+f.getAbsolutePath(),
+ f.exists());
+
+ }
+
+ @Test
+ public void testOverwriteTrue() throws InterruptedException {
+ buildRule.executeTarget("testSimpleScale");
+ AntAssert.assertContains("Processing File", buildRule.getLog());
+ File f = new File(buildRule.getOutputDir(), LARGEIMAGE);
+ assumeTrue("Could not change file modificaiton date",
+ f.setLastModified(f.lastModified() - (FILE_UTILS.getFileTimestampGranularity() * 2)));
+ long lastModified = f.lastModified();
+ buildRule.executeTarget("testOverwriteTrue");
+ AntAssert.assertContains("Processing File", buildRule.getLog());
+ f = new File(buildRule.getOutputDir(), LARGEIMAGE);
+ long overwrittenLastModified = f.lastModified();
+ assertTrue("File was not overwritten.",
+ lastModified < overwrittenLastModified);
+ }
+
+ @Test
+ public void testOverwriteFalse() {
+ buildRule.executeTarget("testSimpleScale");
+ AntAssert.assertContains("Processing File", buildRule.getLog());
+ File f = new File(buildRule.getOutputDir(), LARGEIMAGE);
+ long lastModified = f.lastModified();
+ buildRule.executeTarget("testOverwriteFalse");
+ AntAssert.assertContains("Processing File", buildRule.getLog());
+ f = new File(buildRule.getOutputDir(), LARGEIMAGE);
+ long overwrittenLastModified = f.lastModified();
+ assertTrue("File was overwritten.",
+ lastModified == overwrittenLastModified);
+ }
+
+ @Test
+ public void testSimpleScaleWithMapper() {
+ buildRule.executeTarget("testSimpleScaleWithMapper");
+ AntAssert.assertContains("Processing File", buildRule.getLog());
+ File f = new File(buildRule.getOutputDir(), "scaled-" + LARGEIMAGE);
+ assertTrue(
+ "Did not create "+f.getAbsolutePath(),
+ f.exists());
+
+ }
+
+ @Test
+ @Ignore("Previously named in a manner to prevent execution")
+ public void testFailOnError() {
+ try {
+ buildRule.executeTarget("testFailOnError");
+ AntAssert.assertContains("Unable to process image stream", buildRule.getLog());
+ }
+ catch (RuntimeException re){
+ assertTrue("Run time exception should say "
+ + "'Unable to process image stream'. :"
+ + re.toString(),
+ re.toString()
+ .indexOf("Unable to process image stream") > -1);
+ }
+ }
+
+}
+
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java
index 545b7cbc0..54c605517 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/jdepend/JDependTest.java
@@ -1,99 +1,99 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.jdepend;
-
-import org.apache.tools.ant.AntAssert;
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-/**
- * Testcase for the JDepend optional task.
- *
- */
-public class JDependTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject(
- "src/etc/testcases/taskdefs/optional/jdepend/jdepend.xml");
- }
-
- /**
- * Test simple
- */
- @Test
- public void testSimple() {
- buildRule.executeTarget("simple");
- AntAssert.assertContains("Package: org.apache.tools.ant.util.facade",
- buildRule.getOutput());
- }
-
- /**
- * Test xml
- */
- @Test
- public void testXml() {
- buildRule.executeTarget("xml");
- AntAssert.assertContains("", buildRule.getOutput());
- }
-
- /**
- * Test fork
- * - forked output goes to log
- */
- @Test
- public void testFork() {
- buildRule.executeTarget("fork");
- AntAssert.assertContains("Package: org.apache.tools.ant.util.facade", buildRule.getLog());
- }
-
- /**
- * Test fork xml
- */
- @Test
- public void testForkXml() {
- buildRule.executeTarget("fork-xml");
- AntAssert.assertContains("", buildRule.getLog());
- }
-
- /**
- * Test timeout
- */
- @Test
- public void testTimeout() {
- buildRule.executeTarget("fork-xml");
- AntAssert.assertContains( "JDepend FAILED - Timed out", buildRule.getLog());
- }
-
-
- /**
- * Test timeout without timing out
- */
- @Test
- public void testTimeoutNot() {
- buildRule.executeTarget("fork-timeout-not");
- AntAssert.assertContains("Package: org.apache.tools.ant.util.facade", buildRule.getLog());
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional.jdepend;
+
+import org.apache.tools.ant.AntAssert;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Testcase for the JDepend optional task.
+ *
+ */
+public class JDependTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject(
+ "src/etc/testcases/taskdefs/optional/jdepend/jdepend.xml");
+ }
+
+ /**
+ * Test simple
+ */
+ @Test
+ public void testSimple() {
+ buildRule.executeTarget("simple");
+ AntAssert.assertContains("Package: org.apache.tools.ant.util.facade",
+ buildRule.getOutput());
+ }
+
+ /**
+ * Test xml
+ */
+ @Test
+ public void testXml() {
+ buildRule.executeTarget("xml");
+ AntAssert.assertContains("", buildRule.getOutput());
+ }
+
+ /**
+ * Test fork
+ * - forked output goes to log
+ */
+ @Test
+ public void testFork() {
+ buildRule.executeTarget("fork");
+ AntAssert.assertContains("Package: org.apache.tools.ant.util.facade", buildRule.getLog());
+ }
+
+ /**
+ * Test fork xml
+ */
+ @Test
+ public void testForkXml() {
+ buildRule.executeTarget("fork-xml");
+ AntAssert.assertContains("", buildRule.getLog());
+ }
+
+ /**
+ * Test timeout
+ */
+ @Test
+ public void testTimeout() {
+ buildRule.executeTarget("fork-xml");
+ AntAssert.assertContains( "JDepend FAILED - Timed out", buildRule.getLog());
+ }
+
+
+ /**
+ * Test timeout without timing out
+ */
+ @Test
+ public void testTimeoutNot() {
+ buildRule.executeTarget("fork-timeout-not");
+ AntAssert.assertContains("Package: org.apache.tools.ant.util.facade", buildRule.getLog());
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java
index 52a12ecc0..a9694995e 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/BatchTestTest.java
@@ -1,121 +1,121 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.junit;
-
-
-import static org.junit.Assert.fail;
-import static org.junit.Assert.assertArrayEquals;
-
-import org.junit.Test;
-
-/**
- *
- * @author Marian Petras
- */
-public class BatchTestTest {
-
- @Test
- public void testParseTestMethodNamesList() {
- try {
- JUnitTest.parseTestMethodNamesList(null);
- fail("IllegalArgumentException expected when the param is ");
- } catch (IllegalArgumentException ex) {
- //this is an expected exception
- }
-
- assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList(""));
- assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList(" "));
- assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList(" "));
-
- checkParseCausesIAE(",");
- checkParseCausesIAE(" ,");
- checkParseCausesIAE(", ");
- checkParseCausesIAE(" , ");
- checkParseCausesIAE(",a");
- checkParseCausesIAE(" ,a");
- checkParseCausesIAE(" ,a");
- checkParseCausesIAE(" , a");
- checkParseCausesIAE(" ,a ");
- checkParseCausesIAE(" ,a ,");
- checkParseCausesIAE("ab,,cd");
- checkParseCausesIAE("ab, ,cd");
- checkParseCausesIAE("ab, ,cd");
- checkParseCausesIAE("ab, ,cd,");
- checkParseCausesIAE(",ab, ,cd,");
-
- assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc"));
- assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc "));
- assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc"));
- assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc "));
- assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc "));
- assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc,"));
- assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc, "));
- assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc ,"));
- assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc , "));
- assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc ,"));
-
- /* legal Java identifiers: */
- assertArrayEquals(new String[] {"a"}, JUnitTest.parseTestMethodNamesList("a"));
- assertArrayEquals(new String[] {"a1"}, JUnitTest.parseTestMethodNamesList("a1"));
- assertArrayEquals(new String[] {"a$"}, JUnitTest.parseTestMethodNamesList("a$"));
- assertArrayEquals(new String[] {"a$1"}, JUnitTest.parseTestMethodNamesList("a$1"));
- assertArrayEquals(new String[] {"_bc"}, JUnitTest.parseTestMethodNamesList("_bc"));
- assertArrayEquals(new String[] {"___"}, JUnitTest.parseTestMethodNamesList("___"));
-
- /* illegal Java identifiers: */
- checkParseCausesIAE("1");
- checkParseCausesIAE("1a");
- checkParseCausesIAE("1ab");
- checkParseCausesIAE("1abc");
- checkParseCausesIAE("1abc d");
- checkParseCausesIAE("1abc de");
- checkParseCausesIAE("1abc def");
- checkParseCausesIAE("1abc def,");
- checkParseCausesIAE(",1abc def");
-
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def"));
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def,"));
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def "));
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc, def"));
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc, def "));
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc ,def"));
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc ,def "));
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc , def"));
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc , def "));
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc,def"));
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc,def "));
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc, def"));
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc, def "));
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc ,def"));
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc ,def "));
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def"));
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def "));
- assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def ,"));
- }
-
- private static void checkParseCausesIAE(String param) {
- try {
- JUnitTest.parseTestMethodNamesList(param);
- fail("IllegalArgumentException expected when the param is \"" + param + '"');
- } catch (IllegalArgumentException ex) {
- //this is an expected exception
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertArrayEquals;
+
+import org.junit.Test;
+
+/**
+ *
+ * @author Marian Petras
+ */
+public class BatchTestTest {
+
+ @Test
+ public void testParseTestMethodNamesList() {
+ try {
+ JUnitTest.parseTestMethodNamesList(null);
+ fail("IllegalArgumentException expected when the param is ");
+ } catch (IllegalArgumentException ex) {
+ //this is an expected exception
+ }
+
+ assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList(""));
+ assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList(" "));
+ assertArrayEquals(new String[0], JUnitTest.parseTestMethodNamesList(" "));
+
+ checkParseCausesIAE(",");
+ checkParseCausesIAE(" ,");
+ checkParseCausesIAE(", ");
+ checkParseCausesIAE(" , ");
+ checkParseCausesIAE(",a");
+ checkParseCausesIAE(" ,a");
+ checkParseCausesIAE(" ,a");
+ checkParseCausesIAE(" , a");
+ checkParseCausesIAE(" ,a ");
+ checkParseCausesIAE(" ,a ,");
+ checkParseCausesIAE("ab,,cd");
+ checkParseCausesIAE("ab, ,cd");
+ checkParseCausesIAE("ab, ,cd");
+ checkParseCausesIAE("ab, ,cd,");
+ checkParseCausesIAE(",ab, ,cd,");
+
+ assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc"));
+ assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc "));
+ assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc"));
+ assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc "));
+ assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc "));
+ assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc,"));
+ assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc, "));
+ assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc ,"));
+ assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList("abc , "));
+ assertArrayEquals(new String[] {"abc"}, JUnitTest.parseTestMethodNamesList(" abc ,"));
+
+ /* legal Java identifiers: */
+ assertArrayEquals(new String[] {"a"}, JUnitTest.parseTestMethodNamesList("a"));
+ assertArrayEquals(new String[] {"a1"}, JUnitTest.parseTestMethodNamesList("a1"));
+ assertArrayEquals(new String[] {"a$"}, JUnitTest.parseTestMethodNamesList("a$"));
+ assertArrayEquals(new String[] {"a$1"}, JUnitTest.parseTestMethodNamesList("a$1"));
+ assertArrayEquals(new String[] {"_bc"}, JUnitTest.parseTestMethodNamesList("_bc"));
+ assertArrayEquals(new String[] {"___"}, JUnitTest.parseTestMethodNamesList("___"));
+
+ /* illegal Java identifiers: */
+ checkParseCausesIAE("1");
+ checkParseCausesIAE("1a");
+ checkParseCausesIAE("1ab");
+ checkParseCausesIAE("1abc");
+ checkParseCausesIAE("1abc d");
+ checkParseCausesIAE("1abc de");
+ checkParseCausesIAE("1abc def");
+ checkParseCausesIAE("1abc def,");
+ checkParseCausesIAE(",1abc def");
+
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def"));
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def,"));
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc,def "));
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc, def"));
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc, def "));
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc ,def"));
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc ,def "));
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc , def"));
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList("abc , def "));
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc,def"));
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc,def "));
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc, def"));
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc, def "));
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc ,def"));
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc ,def "));
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def"));
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def "));
+ assertArrayEquals(new String[] {"abc", "def"}, JUnitTest.parseTestMethodNamesList(" abc , def ,"));
+ }
+
+ private static void checkParseCausesIAE(String param) {
+ try {
+ JUnitTest.parseTestMethodNamesList(param);
+ fail("IllegalArgumentException expected when the param is \"" + param + '"');
+ } catch (IllegalArgumentException ex) {
+ //this is an expected exception
+ }
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java
index b72f69cc6..7591ada0b 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/DOMUtilTest.java
@@ -1,53 +1,53 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional.junit;
-
-import static org.junit.Assert.assertEquals;
-
-import java.io.IOException;
-import java.io.InputStream;
-
-import javax.xml.parsers.DocumentBuilder;
-
-import org.apache.tools.ant.util.JAXPUtils;
-import org.junit.Test;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-import org.xml.sax.SAXException;
-
-public class DOMUtilTest {
-
- @Test
- public void testListChildNodes() throws SAXException, IOException {
- DocumentBuilder db = JAXPUtils.getDocumentBuilder();
- InputStream is = this.getClass().getClassLoader().getResourceAsStream("taskdefs/optional/junit/matches.xml");
- Document doc = db.parse(is);
- NodeList nl = DOMUtil.listChildNodes(doc.getDocumentElement(), new FooNodeFilter(), true);
- assertEquals("expecting 3", 3, nl.getLength());
- }
-
- public class FooNodeFilter implements DOMUtil.NodeFilter {
- public boolean accept(Node node) {
- if (node.getNodeName().equals("foo")) {
- return true;
- }
- return false;
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+import static org.junit.Assert.assertEquals;
+
+import java.io.IOException;
+import java.io.InputStream;
+
+import javax.xml.parsers.DocumentBuilder;
+
+import org.apache.tools.ant.util.JAXPUtils;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.xml.sax.SAXException;
+
+public class DOMUtilTest {
+
+ @Test
+ public void testListChildNodes() throws SAXException, IOException {
+ DocumentBuilder db = JAXPUtils.getDocumentBuilder();
+ InputStream is = this.getClass().getClassLoader().getResourceAsStream("taskdefs/optional/junit/matches.xml");
+ Document doc = db.parse(is);
+ NodeList nl = DOMUtil.listChildNodes(doc.getDocumentElement(), new FooNodeFilter(), true);
+ assertEquals("expecting 3", 3, nl.getLength());
+ }
+
+ public class FooNodeFilter implements DOMUtil.NodeFilter {
+ public boolean accept(Node node) {
+ if (node.getNodeName().equals("foo")) {
+ return true;
+ }
+ return false;
+ }
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java
index 4baf74181..0c303c1ab 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitClassLoaderTest.java
@@ -1,37 +1,37 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional.junit;
-
-import static org.junit.Assert.assertSame;
-
-import org.junit.Test;
-
-/**
- * Test to ensure that the classloader loading JUnit testcase
- * is also the context classloader.
- *
- */
-public class JUnitClassLoaderTest {
-
- @Test
- public void testContextClassLoader(){
- ClassLoader context = Thread.currentThread().getContextClassLoader();
- ClassLoader caller = getClass().getClassLoader();
- assertSame(context, caller);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+import static org.junit.Assert.assertSame;
+
+import org.junit.Test;
+
+/**
+ * Test to ensure that the classloader loading JUnit testcase
+ * is also the context classloader.
+ *
+ */
+public class JUnitClassLoaderTest {
+
+ @Test
+ public void testContextClassLoader(){
+ ClassLoader context = Thread.currentThread().getContextClassLoader();
+ ClassLoader caller = getClass().getClassLoader();
+ assertSame(context, caller);
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java
index c5b6feb97..63eb19730 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitReportTest.java
@@ -1,211 +1,211 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.junit;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertTrue;
-import static org.apache.tools.ant.AntAssert.assertContains;
-import static org.junit.Assert.fail;
-
-import java.io.File;
-import java.io.FileReader;
-import java.io.InputStream;
-import java.net.URL;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.util.FileUtils;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-/**
- * Small testcase for the junitreporttask.
- * First test added to reproduce an fault, still a lot to improve
- *
- */
-public class JUnitReportTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/junitreport.xml");
- }
-
- /**
- * Verifies that no empty junit-noframes.html is generated when frames
- * output is selected via the default.
- * Needs reports1 task from junitreport.xml.
- */
- @Test
- public void testNoFileJUnitNoFrames() {
- buildRule.executeTarget("reports1");
- assertFalse("No file junit-noframes.html expected", (new File(System.getProperty("root"), "src/etc/testcases/taskdefs/optional/junitreport/test/html/junit-noframes.html").exists()));
-
- }
-
- public void assertIndexCreated() {
- if (!new File(buildRule.getProject().getProperty("output"), "html/index.html").exists()) {
- fail("No file index file found");
- }
-
- }
-
-
- @Test
- public void testEmptyFile() throws Exception {
- buildRule.executeTarget("testEmptyFile");
- assertIndexCreated();
- assertContains("Required text not found in log", XMLResultAggregator.WARNING_EMPTY_FILE, buildRule.getLog());
- }
-
- @Test
- public void testIncompleteFile() throws Exception {
- buildRule.executeTarget("testIncompleteFile");
- assertIndexCreated();
- assertContains("Required text not found in log", XMLResultAggregator.WARNING_IS_POSSIBLY_CORRUPTED, buildRule.getLog());
- }
-
- @Test
- public void testWrongElement() throws Exception {
- buildRule.executeTarget("testWrongElement");
- assertIndexCreated();
- assertContains("Required text not found in log", XMLResultAggregator.WARNING_INVALID_ROOT_ELEMENT, buildRule.getLog());
- }
-
- // Bugzilla Report 34963
- @Test
- public void testStackTraceLineBreaks() throws Exception {
- buildRule.executeTarget("testStackTraceLineBreaks");
- assertIndexCreated();
- FileReader r = null;
- try {
- r = new FileReader(new File(buildRule.getOutputDir(), "html/sampleproject/coins/0_CoinTest.html"));
- String report = FileUtils.readFully(r);
- assertContains("output must contain :\n" + report, "junit.framework.AssertionFailedError: DOEG ", report);
- assertContains("#51049: output must translate line breaks:\n" + report, "cur['line.separator'] = '\\r\\n';", report);
- } finally {
- FileUtils.close(r);
- }
- }
-
-
- // Bugzilla Report 38477
- @Test
- public void testSpecialSignsInSrcPath() throws Exception {
- buildRule.executeTarget("testSpecialSignsInSrcPath");
- File reportFile = new File(buildRule.getOutputDir(), "html/index.html");
- // tests one the file object
- assertTrue("No index.html present. Not generated?", reportFile.exists() );
- assertTrue("Cant read the report file.", reportFile.canRead() );
- assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
- // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
- URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
- InputStream reportStream = reportUrl.openStream();
- assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
- }
-
- @Test
- public void testSpecialSignsInHtmlPath() throws Exception {
- buildRule.executeTarget("testSpecialSignsInHtmlPath");
- File reportFile = new File(buildRule.getOutputDir(), "html# $%\u00A7&-!report/index.html");
- // tests one the file object
- assertTrue("No index.html present. Not generated?", reportFile.exists() );
- assertTrue("Cant read the report file.", reportFile.canRead() );
- assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
- // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
- URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
- InputStream reportStream = reportUrl.openStream();
- assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
- }
-
- //Bugzilla Report 39708
- @Test
- public void testWithStyleFromDir() throws Exception {
- buildRule.executeTarget("testWithStyleFromDir");
- File reportFile = new File(buildRule.getOutputDir(), "html/index.html");
- // tests one the file object
- assertTrue("No index.html present. Not generated?", reportFile.exists() );
- assertTrue("Cant read the report file.", reportFile.canRead() );
- assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
- // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
- URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
- InputStream reportStream = reportUrl.openStream();
- assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
- }
-
- //Bugzilla Report 40021
- @Test
- public void testNoFrames() throws Exception {
- buildRule.executeTarget("testNoFrames");
- File reportFile = new File(buildRule.getOutputDir(), "html/junit-noframes.html");
- // tests one the file object
- assertTrue("No junit-noframes.html present. Not generated?", reportFile.exists() );
- assertTrue("Cant read the report file.", reportFile.canRead() );
- assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
- // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
- URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
- InputStream reportStream = reportUrl.openStream();
- assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
- }
- //Bugzilla Report 39708
- @Test
- public void testWithStyleFromDirAndXslImport() throws Exception {
- buildRule.executeTarget("testWithStyleFromDirAndXslImport");
- File reportFile = new File(buildRule.getOutputDir(), "html/index.html");
- // tests one the file object
- assertTrue("No index.html present. Not generated?", reportFile.exists() );
- assertTrue("Cant read the report file.", reportFile.canRead() );
- assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
- // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
- URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
- InputStream reportStream = reportUrl.openStream();
- assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
- }
-
- @Test
- public void testWithStyleFromClasspath() throws Exception {
- buildRule.executeTarget("testWithStyleFromClasspath");
- File reportFile = new File(buildRule.getOutputDir(), "html/index.html");
- // tests one the file object
- assertTrue("No index.html present. Not generated?", reportFile.exists() );
- assertTrue("Cant read the report file.", reportFile.canRead() );
- assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
- // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
- URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
- InputStream reportStream = reportUrl.openStream();
- assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
- }
-
- @Test
- public void testWithParams() throws Exception {
- buildRule.executeTarget("testWithParams");
- assertContains("key1=value1,key2=value2", buildRule.getLog());
- File reportFile = new File(buildRule.getOutputDir(), "html/index.html");
- // tests one the file object
- assertTrue("No index.html present. Not generated?", reportFile.exists() );
- assertTrue("Cant read the report file.", reportFile.canRead() );
- assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
- // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
- URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
- InputStream reportStream = reportUrl.openStream();
- assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+import static org.apache.tools.ant.AntAssert.assertContains;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.InputStream;
+import java.net.URL;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.util.FileUtils;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+/**
+ * Small testcase for the junitreporttask.
+ * First test added to reproduce an fault, still a lot to improve
+ *
+ */
+public class JUnitReportTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/junitreport.xml");
+ }
+
+ /**
+ * Verifies that no empty junit-noframes.html is generated when frames
+ * output is selected via the default.
+ * Needs reports1 task from junitreport.xml.
+ */
+ @Test
+ public void testNoFileJUnitNoFrames() {
+ buildRule.executeTarget("reports1");
+ assertFalse("No file junit-noframes.html expected", (new File(System.getProperty("root"), "src/etc/testcases/taskdefs/optional/junitreport/test/html/junit-noframes.html").exists()));
+
+ }
+
+ public void assertIndexCreated() {
+ if (!new File(buildRule.getProject().getProperty("output"), "html/index.html").exists()) {
+ fail("No file index file found");
+ }
+
+ }
+
+
+ @Test
+ public void testEmptyFile() throws Exception {
+ buildRule.executeTarget("testEmptyFile");
+ assertIndexCreated();
+ assertContains("Required text not found in log", XMLResultAggregator.WARNING_EMPTY_FILE, buildRule.getLog());
+ }
+
+ @Test
+ public void testIncompleteFile() throws Exception {
+ buildRule.executeTarget("testIncompleteFile");
+ assertIndexCreated();
+ assertContains("Required text not found in log", XMLResultAggregator.WARNING_IS_POSSIBLY_CORRUPTED, buildRule.getLog());
+ }
+
+ @Test
+ public void testWrongElement() throws Exception {
+ buildRule.executeTarget("testWrongElement");
+ assertIndexCreated();
+ assertContains("Required text not found in log", XMLResultAggregator.WARNING_INVALID_ROOT_ELEMENT, buildRule.getLog());
+ }
+
+ // Bugzilla Report 34963
+ @Test
+ public void testStackTraceLineBreaks() throws Exception {
+ buildRule.executeTarget("testStackTraceLineBreaks");
+ assertIndexCreated();
+ FileReader r = null;
+ try {
+ r = new FileReader(new File(buildRule.getOutputDir(), "html/sampleproject/coins/0_CoinTest.html"));
+ String report = FileUtils.readFully(r);
+ assertContains("output must contain :\n" + report, "junit.framework.AssertionFailedError: DOEG ", report);
+ assertContains("#51049: output must translate line breaks:\n" + report, "cur['line.separator'] = '\\r\\n';", report);
+ } finally {
+ FileUtils.close(r);
+ }
+ }
+
+
+ // Bugzilla Report 38477
+ @Test
+ public void testSpecialSignsInSrcPath() throws Exception {
+ buildRule.executeTarget("testSpecialSignsInSrcPath");
+ File reportFile = new File(buildRule.getOutputDir(), "html/index.html");
+ // tests one the file object
+ assertTrue("No index.html present. Not generated?", reportFile.exists() );
+ assertTrue("Cant read the report file.", reportFile.canRead() );
+ assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
+ // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
+ URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
+ InputStream reportStream = reportUrl.openStream();
+ assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
+ }
+
+ @Test
+ public void testSpecialSignsInHtmlPath() throws Exception {
+ buildRule.executeTarget("testSpecialSignsInHtmlPath");
+ File reportFile = new File(buildRule.getOutputDir(), "html# $%\u00A7&-!report/index.html");
+ // tests one the file object
+ assertTrue("No index.html present. Not generated?", reportFile.exists() );
+ assertTrue("Cant read the report file.", reportFile.canRead() );
+ assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
+ // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
+ URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
+ InputStream reportStream = reportUrl.openStream();
+ assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
+ }
+
+ //Bugzilla Report 39708
+ @Test
+ public void testWithStyleFromDir() throws Exception {
+ buildRule.executeTarget("testWithStyleFromDir");
+ File reportFile = new File(buildRule.getOutputDir(), "html/index.html");
+ // tests one the file object
+ assertTrue("No index.html present. Not generated?", reportFile.exists() );
+ assertTrue("Cant read the report file.", reportFile.canRead() );
+ assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
+ // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
+ URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
+ InputStream reportStream = reportUrl.openStream();
+ assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
+ }
+
+ //Bugzilla Report 40021
+ @Test
+ public void testNoFrames() throws Exception {
+ buildRule.executeTarget("testNoFrames");
+ File reportFile = new File(buildRule.getOutputDir(), "html/junit-noframes.html");
+ // tests one the file object
+ assertTrue("No junit-noframes.html present. Not generated?", reportFile.exists() );
+ assertTrue("Cant read the report file.", reportFile.canRead() );
+ assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
+ // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
+ URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
+ InputStream reportStream = reportUrl.openStream();
+ assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
+ }
+ //Bugzilla Report 39708
+ @Test
+ public void testWithStyleFromDirAndXslImport() throws Exception {
+ buildRule.executeTarget("testWithStyleFromDirAndXslImport");
+ File reportFile = new File(buildRule.getOutputDir(), "html/index.html");
+ // tests one the file object
+ assertTrue("No index.html present. Not generated?", reportFile.exists() );
+ assertTrue("Cant read the report file.", reportFile.canRead() );
+ assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
+ // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
+ URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
+ InputStream reportStream = reportUrl.openStream();
+ assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
+ }
+
+ @Test
+ public void testWithStyleFromClasspath() throws Exception {
+ buildRule.executeTarget("testWithStyleFromClasspath");
+ File reportFile = new File(buildRule.getOutputDir(), "html/index.html");
+ // tests one the file object
+ assertTrue("No index.html present. Not generated?", reportFile.exists() );
+ assertTrue("Cant read the report file.", reportFile.canRead() );
+ assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
+ // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
+ URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
+ InputStream reportStream = reportUrl.openStream();
+ assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
+ }
+
+ @Test
+ public void testWithParams() throws Exception {
+ buildRule.executeTarget("testWithParams");
+ assertContains("key1=value1,key2=value2", buildRule.getLog());
+ File reportFile = new File(buildRule.getOutputDir(), "html/index.html");
+ // tests one the file object
+ assertTrue("No index.html present. Not generated?", reportFile.exists() );
+ assertTrue("Cant read the report file.", reportFile.canRead() );
+ assertTrue("File shouldn't be empty.", reportFile.length() > 0 );
+ // conversion to URL via FileUtils like in XMLResultAggregator, not as suggested in the bug report
+ URL reportUrl = new URL( FileUtils.getFileUtils().toURI(reportFile.getAbsolutePath()) );
+ InputStream reportStream = reportUrl.openStream();
+ assertTrue("This shouldn't be an empty stream.", reportStream.available() > 0);
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java
index 61504ad16..33fd3b053 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTaskTest.java
@@ -1,398 +1,398 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional.junit;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import static org.apache.tools.ant.AntAssert.assertNotContains;
-import static org.apache.tools.ant.AntAssert.assertContains;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.xpath.XPath;
-import javax.xml.xpath.XPathConstants;
-import javax.xml.xpath.XPathFactory;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.util.JavaEnvUtils;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-import org.w3c.dom.Document;
-import org.w3c.dom.Node;
-
-public class JUnitTaskTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- /**
- * The JUnit setup method.
- */
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit.xml");
- }
-
- @Test
- public void testCrash() {
- buildRule.executeTarget("crash");
- assertEquals("true", buildRule.getProject().getProperty("crashed"));
- }
-
- @Test
- public void testNoCrash() {
- buildRule.executeTarget("nocrash");
- assertNull(buildRule.getProject().getProperty("crashed"));
- }
-
- @Test
- public void testTimeout() {
- buildRule.executeTarget("timeout");
- assertEquals("true", buildRule.getProject().getProperty("timeout"));
- }
-
- @Test
- public void testNoTimeout() {
- buildRule.executeTarget("notimeout");
- assertNull(buildRule.getProject().getProperty("timeout"));
- }
-
- @Test
- public void testNonForkedCapture() throws IOException {
- buildRule.executeTarget("capture");
- assertNoPrint(buildRule.getLog(), "log");
- assertNoPrint(buildRule.getFullLog(), "debug log");
- }
-
- @Test
- public void testForkedCapture() throws IOException {
- buildRule.getProject().setProperty("fork", "true");
- testNonForkedCapture();
- // those would fail because of the way BuildFileRule captures output
- assertNoPrint(buildRule.getOutput(), "output");
- assertNoPrint(buildRule.getError(), "error output");
- assertOutput();
- }
-
- @Test
- public void testBatchTestForkOnceToDir() {
- assertResultFilesExist("testBatchTestForkOnceToDir", ".xml");
- }
-
- /** Bugzilla Report 32973 */
- @Test
- public void testBatchTestForkOnceExtension() {
- assertResultFilesExist("testBatchTestForkOnceExtension", ".foo");
- }
-
-
- /* Bugzilla Report 42984 */
- //TODO This scenario works from command line, but not from JUnit ...
- // Running these steps from the junit.xml-directory work
- // $ ant -f junit.xml failureRecorder.prepare
- // $ ant -f junit.xml failureRecorder.runtest
- // $ ant -f junit.xml failureRecorder.runtest
- // $ ant -f junit.xml failureRecorder.fixing
- // $ ant -f junit.xml failureRecorder.runtest
- // $ ant -f junit.xml failureRecorder.runtest
- // But running the JUnit testcase fails in 4th run.
- @Test
- public void testFailureRecorder() {
- if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_5)) {
- try {
- Class> clazz =Class.forName("junit.framework.JUnit4TestAdapter");
- Assume.assumeFalse("Skipping test since it fails with JUnit 4", clazz != null);
- } catch (ClassNotFoundException e) {
- // OK, this is JUnit3, can run test
- }
- }
-
- File testDir = new File(buildRule.getOutputDir(), "out");
- File collectorFile = new File(buildRule.getOutputDir(),
- "out/FailedTests.java");
-
- // ensure that there is a clean test environment
- assertFalse("Test directory '" + testDir.getAbsolutePath()
- + "' must not exist before the test preparation.",
- testDir.exists());
- assertFalse("The collector file '"
- + collectorFile.getAbsolutePath()
- + "'must not exist before the test preparation.",
- collectorFile.exists());
-
-
- // prepare the test environment
- buildRule.executeTarget("failureRecorder.prepare");
- assertTrue("Test directory '" + testDir.getAbsolutePath()
- + "' was not created.", testDir.exists());
- assertTrue("There should be one class.",
- (new File(testDir, "A.class")).exists());
- assertFalse("The collector file '"
- + collectorFile.getAbsolutePath()
- + "' should not exist before the 1st run.",
- collectorFile.exists());
-
-
- // 1st junit run: should do all tests - failing and not failing tests
- buildRule.executeTarget("failureRecorder.runtest");
- assertTrue("The collector file '" + collectorFile.getAbsolutePath()
- + "' should exist after the 1st run.",
- collectorFile.exists());
- // the passing test cases
- buildRule.executeTarget("A.test01");
- assertContains("1st run: should run A.test01", buildRule.getOutput());
- buildRule.executeTarget("B.test05");
- assertContains("1st run: should run B.test05", buildRule.getOutput());
- buildRule.executeTarget("B.test06");
- assertContains("1st run: should run B.test06", buildRule.getOutput());
- buildRule.executeTarget("C.test07");
- assertContains("1st run: should run C.test07", buildRule.getOutput());
- buildRule.executeTarget("C.test08");
- assertContains("1st run: should run C.test08", buildRule.getOutput());
- buildRule.executeTarget("C.test09");
- assertContains("1st run: should run C.test09", buildRule.getOutput());
- // the failing test cases
- buildRule.executeTarget("A.test02");
- assertContains("1st run: should run A.test02", buildRule.getOutput());
- buildRule.executeTarget("A.test03");
- assertContains("1st run: should run A.test03", buildRule.getOutput());
- buildRule.executeTarget("B.test04");
- assertContains("1st run: should run B.test04", buildRule.getOutput());
- buildRule.executeTarget("D.test10");
- assertContains("1st run: should run D.test10", buildRule.getOutput());
-
-
- // 2nd junit run: should do only failing tests
- buildRule.executeTarget("failureRecorder.runtest");
- assertTrue("The collector file '" + collectorFile.getAbsolutePath()
- + "' should exist after the 2nd run.",
- collectorFile.exists());
- // the passing test cases
- buildRule.executeTarget("A.test01");
- assertNotContains("2nd run: should not run A.test01", buildRule.getOutput());
- buildRule.executeTarget("B.test05");
- assertNotContains("2nd run: should not run A.test05", buildRule.getOutput());
- buildRule.executeTarget("B.test06");
- assertNotContains("2nd run: should not run B.test06", buildRule.getOutput());
- buildRule.executeTarget("C.test07");
- assertNotContains("2nd run: should not run C.test07", buildRule.getOutput());
- buildRule.executeTarget("C.test08");
- assertNotContains("2nd run: should not run C.test08", buildRule.getOutput());
- buildRule.executeTarget("C.test09");
- assertNotContains("2nd run: should not run C.test09", buildRule.getOutput());
- // the failing test cases
- buildRule.executeTarget("A.test02");
- assertContains("2nd run: should run A.test02", buildRule.getOutput());
- buildRule.executeTarget("A.test03");
- assertContains("2nd run: should run A.test03", buildRule.getOutput());
- buildRule.executeTarget("B.test04");
- assertContains("2nd run: should run B.test04", buildRule.getOutput());
- buildRule.executeTarget("D.test10");
- assertContains("2nd run: should run D.test10", buildRule.getOutput());
-
-
- // "fix" errors in class A
- buildRule.executeTarget("failureRecorder.fixing");
-
- // 3rd run: four running tests with two errors
- buildRule.executeTarget("failureRecorder.runtest");
- assertTrue("The collector file '" + collectorFile.getAbsolutePath()
- + "' should exist after the 3rd run.",
- collectorFile.exists());
- buildRule.executeTarget("A.test02");
- assertContains("3rd run: should run A.test02", buildRule.getOutput());
- buildRule.executeTarget("A.test03");
- assertContains("3rd run: should run A.test03", buildRule.getOutput());
- buildRule.executeTarget("B.test04");
- assertContains("3rd run: should run B.test04", buildRule.getOutput());
- buildRule.executeTarget("D.test10");
- assertContains("3rd run: should run D.test10", buildRule.getOutput());
-
-
- // 4rd run: two running tests with errors
- buildRule.executeTarget("failureRecorder.runtest");
- assertTrue("The collector file '" + collectorFile.getAbsolutePath()
- + "' should exist after the 4th run.",
- collectorFile.exists());
- //TODO: these two statements fail
- //buildRule.executeTarget("A.test02");assertNotContains("4th run: should not run A.test02", buildRule.getOutput());
- //buildRule.executeTarget("A.test03");assertNotContains("4th run: should not run A.test03", buildRule.getOutput());
- buildRule.executeTarget("B.test04");
- assertContains("4th run: should run B.test04", buildRule.getOutput());
- buildRule.executeTarget("D.test10");
- assertContains("4th run: should run D.test10", buildRule.getOutput());
-
- }
-
- @Test
- public void testBatchTestForkOnceCustomFormatter() {
- assertResultFilesExist("testBatchTestForkOnceCustomFormatter", "foo");
- }
-
- // Bugzilla Issue 45411
- @Test
- public void testMultilineAssertsNoFork() {
- buildRule.executeTarget("testMultilineAssertsNoFork");
- assertNotContains("messaged up", buildRule.getLog());
- assertNotContains("crashed)", buildRule.getLog());
- }
-
- // Bugzilla Issue 45411
- @Test
- public void testMultilineAssertsFork() {
- buildRule.executeTarget("testMultilineAssertsFork");
- assertNotContains("messaged up", buildRule.getLog());
- assertNotContains("crashed)", buildRule.getLog());
- }
-
- private void assertResultFilesExist(String target, String extension) {
- buildRule.executeTarget(target);
- assertResultFileExists("JUnitClassLoader", extension);
- assertResultFileExists("JUnitTestRunner", extension);
- assertResultFileExists("JUnitVersionHelper", extension);
- }
-
- private void assertResultFileExists(String classNameFragment, String ext) {
- assertTrue("result for " + classNameFragment + "Test" + ext + " exists",
-
- new File(buildRule.getOutputDir(), "TEST-org.apache.tools.ant."
- + "taskdefs.optional.junit."
- + classNameFragment + "Test" + ext)
- .exists());
- }
-
- private void assertNoPrint(String result, String where) {
- assertNotContains(where + " '" + result + "' must not contain print statement",
- "print to System.", result);
- }
-
- private void assertOutput() throws IOException {
- FileReader inner = new FileReader(new File(buildRule.getOutputDir(),
- "testlog.txt"));
- BufferedReader reader = new BufferedReader(inner);
- try {
- String line = reader.readLine();
- assertEquals("Testsuite: org.apache.tools.ant.taskdefs.optional.junit.Printer",
- line);
- line = reader.readLine();
- assertNotNull(line);
- assertTrue(line.startsWith("Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed:"));
- line = reader.readLine();
- assertEquals("------------- Standard Output ---------------",
- line);
- assertPrint(reader.readLine(), "static", "out");
- assertPrint(reader.readLine(), "constructor", "out");
- assertPrint(reader.readLine(), "method", "out");
- line = reader.readLine();
- assertEquals("------------- ---------------- ---------------",
- line);
- line = reader.readLine();
- assertEquals("------------- Standard Error -----------------",
- line);
- assertPrint(reader.readLine(), "static", "err");
- assertPrint(reader.readLine(), "constructor", "err");
- assertPrint(reader.readLine(), "method", "err");
- line = reader.readLine();
- assertEquals("------------- ---------------- ---------------",
- line);
- line = reader.readLine();
- assertEquals("", line);
- line = reader.readLine();
- assertNotNull(line);
- assertTrue(line.startsWith("Testcase: testNoCrash took "));
- } finally {
- inner.close();
- }
- }
-
- private void assertPrint(String line, String from, String to) {
- String search = from + " print to System." + to;
- assertEquals(search, line);
- }
-
- @Test
- public void testJUnit4Skip() throws Exception {
- buildRule.executeTarget("testSkippableTests");
-
- DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
- Document doc = dBuilder.parse(new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit4Skippable.xml"));
-
- assertEquals("Incorrect number of nodes created", 8, doc.getElementsByTagName("testcase").getLength());
-
- XPathFactory factory = XPathFactory.newInstance();
- XPath xpath = factory.newXPath();
-
- assertEquals("Incorrect number of skipped tests in header", 4, Integer.parseInt(xpath.compile("//testsuite/@skipped").evaluate(doc)));
- assertEquals("Incorrect number of error tests in header", 1, Integer.parseInt(xpath.compile("//testsuite/@errors").evaluate(doc)));
- assertEquals("Incorrect number of failure tests in header", 2, Integer.parseInt(xpath.compile("//testsuite/@failures").evaluate(doc)));
- assertEquals("Incorrect number of tests in header", 8, Integer.parseInt(xpath.compile("//testsuite/@tests").evaluate(doc)));
-
-
- assertEquals("Incorrect ignore message on explicit ignored test", "Please don't ignore me!", xpath.compile("//testsuite/testcase[@name='explicitIgnoreTest']/skipped/@message").evaluate(doc));
- assertEquals("No message should be set on Ignored tests with no Ignore annotation text", 0, ((Node)xpath.compile("//testsuite/testcase[@name='explicitlyIgnoreTestNoMessage']/skipped").evaluate(doc, XPathConstants.NODE)).getAttributes().getLength());
- assertEquals("Incorrect ignore message on implicit ignored test", "This test will be ignored", xpath.compile("//testsuite/testcase[@name='implicitlyIgnoreTest']/skipped/@message").evaluate(doc));
- assertNotNull("Implicit ignore test should have an ignore element", xpath.compile("//testsuite/testcase[@name='implicitlyIgnoreTestNoMessage']/skipped").evaluate(doc, XPathConstants.NODE));
-
- }
-
- @Test
- public void testTestMethods() throws Exception {
- buildRule.executeTarget("testTestMethods");
- }
-
- @Test
- public void testNonTestsSkipped() throws Exception {
-
- buildRule.executeTarget("testNonTests");
- assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.NonTestMissed.xml").exists());
- assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestMissed.xml").exists());
- assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.AbstractTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestMissed.xml").exists());
- assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.AbstractJUnit3TestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestMissed.xml").exists());
- assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestNotMissed.xml").exists());
- assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractJUnit3TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestNotMissed.xml").exists());
- assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestNotMissed.xml").exists());
- assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestNotMissed.xml").exists());
- assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestWithSuiteNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestWithSuiteNotMissed.xml").exists());
-
- buildRule.executeTarget("testNonTestsRun");
- assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.NonTestMissed.xml").exists());
- assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3NonTestMissed.xml").exists());
- assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestNotMissed.xml").exists());
- assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestNotMissed.xml").exists());
- assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestMissed.xml").exists());
- assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestNotMissed.xml").exists());
- assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractJUnit3TestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestMissed.xml").exists());
- assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3NonTestMissed.xml").exists());
- assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestWithSuiteNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestWithSuiteNotMissed.xml").exists());
-
-
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import static org.apache.tools.ant.AntAssert.assertNotContains;
+import static org.apache.tools.ant.AntAssert.assertContains;
+
+import java.io.BufferedReader;
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import javax.xml.parsers.DocumentBuilder;
+import javax.xml.parsers.DocumentBuilderFactory;
+import javax.xml.xpath.XPath;
+import javax.xml.xpath.XPathConstants;
+import javax.xml.xpath.XPathFactory;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.util.JavaEnvUtils;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+import org.w3c.dom.Document;
+import org.w3c.dom.Node;
+
+public class JUnitTaskTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ /**
+ * The JUnit setup method.
+ */
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit.xml");
+ }
+
+ @Test
+ public void testCrash() {
+ buildRule.executeTarget("crash");
+ assertEquals("true", buildRule.getProject().getProperty("crashed"));
+ }
+
+ @Test
+ public void testNoCrash() {
+ buildRule.executeTarget("nocrash");
+ assertNull(buildRule.getProject().getProperty("crashed"));
+ }
+
+ @Test
+ public void testTimeout() {
+ buildRule.executeTarget("timeout");
+ assertEquals("true", buildRule.getProject().getProperty("timeout"));
+ }
+
+ @Test
+ public void testNoTimeout() {
+ buildRule.executeTarget("notimeout");
+ assertNull(buildRule.getProject().getProperty("timeout"));
+ }
+
+ @Test
+ public void testNonForkedCapture() throws IOException {
+ buildRule.executeTarget("capture");
+ assertNoPrint(buildRule.getLog(), "log");
+ assertNoPrint(buildRule.getFullLog(), "debug log");
+ }
+
+ @Test
+ public void testForkedCapture() throws IOException {
+ buildRule.getProject().setProperty("fork", "true");
+ testNonForkedCapture();
+ // those would fail because of the way BuildFileRule captures output
+ assertNoPrint(buildRule.getOutput(), "output");
+ assertNoPrint(buildRule.getError(), "error output");
+ assertOutput();
+ }
+
+ @Test
+ public void testBatchTestForkOnceToDir() {
+ assertResultFilesExist("testBatchTestForkOnceToDir", ".xml");
+ }
+
+ /** Bugzilla Report 32973 */
+ @Test
+ public void testBatchTestForkOnceExtension() {
+ assertResultFilesExist("testBatchTestForkOnceExtension", ".foo");
+ }
+
+
+ /* Bugzilla Report 42984 */
+ //TODO This scenario works from command line, but not from JUnit ...
+ // Running these steps from the junit.xml-directory work
+ // $ ant -f junit.xml failureRecorder.prepare
+ // $ ant -f junit.xml failureRecorder.runtest
+ // $ ant -f junit.xml failureRecorder.runtest
+ // $ ant -f junit.xml failureRecorder.fixing
+ // $ ant -f junit.xml failureRecorder.runtest
+ // $ ant -f junit.xml failureRecorder.runtest
+ // But running the JUnit testcase fails in 4th run.
+ @Test
+ public void testFailureRecorder() {
+ if (JavaEnvUtils.isAtLeastJavaVersion(JavaEnvUtils.JAVA_1_5)) {
+ try {
+ Class> clazz =Class.forName("junit.framework.JUnit4TestAdapter");
+ Assume.assumeFalse("Skipping test since it fails with JUnit 4", clazz != null);
+ } catch (ClassNotFoundException e) {
+ // OK, this is JUnit3, can run test
+ }
+ }
+
+ File testDir = new File(buildRule.getOutputDir(), "out");
+ File collectorFile = new File(buildRule.getOutputDir(),
+ "out/FailedTests.java");
+
+ // ensure that there is a clean test environment
+ assertFalse("Test directory '" + testDir.getAbsolutePath()
+ + "' must not exist before the test preparation.",
+ testDir.exists());
+ assertFalse("The collector file '"
+ + collectorFile.getAbsolutePath()
+ + "'must not exist before the test preparation.",
+ collectorFile.exists());
+
+
+ // prepare the test environment
+ buildRule.executeTarget("failureRecorder.prepare");
+ assertTrue("Test directory '" + testDir.getAbsolutePath()
+ + "' was not created.", testDir.exists());
+ assertTrue("There should be one class.",
+ (new File(testDir, "A.class")).exists());
+ assertFalse("The collector file '"
+ + collectorFile.getAbsolutePath()
+ + "' should not exist before the 1st run.",
+ collectorFile.exists());
+
+
+ // 1st junit run: should do all tests - failing and not failing tests
+ buildRule.executeTarget("failureRecorder.runtest");
+ assertTrue("The collector file '" + collectorFile.getAbsolutePath()
+ + "' should exist after the 1st run.",
+ collectorFile.exists());
+ // the passing test cases
+ buildRule.executeTarget("A.test01");
+ assertContains("1st run: should run A.test01", buildRule.getOutput());
+ buildRule.executeTarget("B.test05");
+ assertContains("1st run: should run B.test05", buildRule.getOutput());
+ buildRule.executeTarget("B.test06");
+ assertContains("1st run: should run B.test06", buildRule.getOutput());
+ buildRule.executeTarget("C.test07");
+ assertContains("1st run: should run C.test07", buildRule.getOutput());
+ buildRule.executeTarget("C.test08");
+ assertContains("1st run: should run C.test08", buildRule.getOutput());
+ buildRule.executeTarget("C.test09");
+ assertContains("1st run: should run C.test09", buildRule.getOutput());
+ // the failing test cases
+ buildRule.executeTarget("A.test02");
+ assertContains("1st run: should run A.test02", buildRule.getOutput());
+ buildRule.executeTarget("A.test03");
+ assertContains("1st run: should run A.test03", buildRule.getOutput());
+ buildRule.executeTarget("B.test04");
+ assertContains("1st run: should run B.test04", buildRule.getOutput());
+ buildRule.executeTarget("D.test10");
+ assertContains("1st run: should run D.test10", buildRule.getOutput());
+
+
+ // 2nd junit run: should do only failing tests
+ buildRule.executeTarget("failureRecorder.runtest");
+ assertTrue("The collector file '" + collectorFile.getAbsolutePath()
+ + "' should exist after the 2nd run.",
+ collectorFile.exists());
+ // the passing test cases
+ buildRule.executeTarget("A.test01");
+ assertNotContains("2nd run: should not run A.test01", buildRule.getOutput());
+ buildRule.executeTarget("B.test05");
+ assertNotContains("2nd run: should not run A.test05", buildRule.getOutput());
+ buildRule.executeTarget("B.test06");
+ assertNotContains("2nd run: should not run B.test06", buildRule.getOutput());
+ buildRule.executeTarget("C.test07");
+ assertNotContains("2nd run: should not run C.test07", buildRule.getOutput());
+ buildRule.executeTarget("C.test08");
+ assertNotContains("2nd run: should not run C.test08", buildRule.getOutput());
+ buildRule.executeTarget("C.test09");
+ assertNotContains("2nd run: should not run C.test09", buildRule.getOutput());
+ // the failing test cases
+ buildRule.executeTarget("A.test02");
+ assertContains("2nd run: should run A.test02", buildRule.getOutput());
+ buildRule.executeTarget("A.test03");
+ assertContains("2nd run: should run A.test03", buildRule.getOutput());
+ buildRule.executeTarget("B.test04");
+ assertContains("2nd run: should run B.test04", buildRule.getOutput());
+ buildRule.executeTarget("D.test10");
+ assertContains("2nd run: should run D.test10", buildRule.getOutput());
+
+
+ // "fix" errors in class A
+ buildRule.executeTarget("failureRecorder.fixing");
+
+ // 3rd run: four running tests with two errors
+ buildRule.executeTarget("failureRecorder.runtest");
+ assertTrue("The collector file '" + collectorFile.getAbsolutePath()
+ + "' should exist after the 3rd run.",
+ collectorFile.exists());
+ buildRule.executeTarget("A.test02");
+ assertContains("3rd run: should run A.test02", buildRule.getOutput());
+ buildRule.executeTarget("A.test03");
+ assertContains("3rd run: should run A.test03", buildRule.getOutput());
+ buildRule.executeTarget("B.test04");
+ assertContains("3rd run: should run B.test04", buildRule.getOutput());
+ buildRule.executeTarget("D.test10");
+ assertContains("3rd run: should run D.test10", buildRule.getOutput());
+
+
+ // 4rd run: two running tests with errors
+ buildRule.executeTarget("failureRecorder.runtest");
+ assertTrue("The collector file '" + collectorFile.getAbsolutePath()
+ + "' should exist after the 4th run.",
+ collectorFile.exists());
+ //TODO: these two statements fail
+ //buildRule.executeTarget("A.test02");assertNotContains("4th run: should not run A.test02", buildRule.getOutput());
+ //buildRule.executeTarget("A.test03");assertNotContains("4th run: should not run A.test03", buildRule.getOutput());
+ buildRule.executeTarget("B.test04");
+ assertContains("4th run: should run B.test04", buildRule.getOutput());
+ buildRule.executeTarget("D.test10");
+ assertContains("4th run: should run D.test10", buildRule.getOutput());
+
+ }
+
+ @Test
+ public void testBatchTestForkOnceCustomFormatter() {
+ assertResultFilesExist("testBatchTestForkOnceCustomFormatter", "foo");
+ }
+
+ // Bugzilla Issue 45411
+ @Test
+ public void testMultilineAssertsNoFork() {
+ buildRule.executeTarget("testMultilineAssertsNoFork");
+ assertNotContains("messaged up", buildRule.getLog());
+ assertNotContains("crashed)", buildRule.getLog());
+ }
+
+ // Bugzilla Issue 45411
+ @Test
+ public void testMultilineAssertsFork() {
+ buildRule.executeTarget("testMultilineAssertsFork");
+ assertNotContains("messaged up", buildRule.getLog());
+ assertNotContains("crashed)", buildRule.getLog());
+ }
+
+ private void assertResultFilesExist(String target, String extension) {
+ buildRule.executeTarget(target);
+ assertResultFileExists("JUnitClassLoader", extension);
+ assertResultFileExists("JUnitTestRunner", extension);
+ assertResultFileExists("JUnitVersionHelper", extension);
+ }
+
+ private void assertResultFileExists(String classNameFragment, String ext) {
+ assertTrue("result for " + classNameFragment + "Test" + ext + " exists",
+
+ new File(buildRule.getOutputDir(), "TEST-org.apache.tools.ant."
+ + "taskdefs.optional.junit."
+ + classNameFragment + "Test" + ext)
+ .exists());
+ }
+
+ private void assertNoPrint(String result, String where) {
+ assertNotContains(where + " '" + result + "' must not contain print statement",
+ "print to System.", result);
+ }
+
+ private void assertOutput() throws IOException {
+ FileReader inner = new FileReader(new File(buildRule.getOutputDir(),
+ "testlog.txt"));
+ BufferedReader reader = new BufferedReader(inner);
+ try {
+ String line = reader.readLine();
+ assertEquals("Testsuite: org.apache.tools.ant.taskdefs.optional.junit.Printer",
+ line);
+ line = reader.readLine();
+ assertNotNull(line);
+ assertTrue(line.startsWith("Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed:"));
+ line = reader.readLine();
+ assertEquals("------------- Standard Output ---------------",
+ line);
+ assertPrint(reader.readLine(), "static", "out");
+ assertPrint(reader.readLine(), "constructor", "out");
+ assertPrint(reader.readLine(), "method", "out");
+ line = reader.readLine();
+ assertEquals("------------- ---------------- ---------------",
+ line);
+ line = reader.readLine();
+ assertEquals("------------- Standard Error -----------------",
+ line);
+ assertPrint(reader.readLine(), "static", "err");
+ assertPrint(reader.readLine(), "constructor", "err");
+ assertPrint(reader.readLine(), "method", "err");
+ line = reader.readLine();
+ assertEquals("------------- ---------------- ---------------",
+ line);
+ line = reader.readLine();
+ assertEquals("", line);
+ line = reader.readLine();
+ assertNotNull(line);
+ assertTrue(line.startsWith("Testcase: testNoCrash took "));
+ } finally {
+ inner.close();
+ }
+ }
+
+ private void assertPrint(String line, String from, String to) {
+ String search = from + " print to System." + to;
+ assertEquals(search, line);
+ }
+
+ @Test
+ public void testJUnit4Skip() throws Exception {
+ buildRule.executeTarget("testSkippableTests");
+
+ DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
+ DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
+ Document doc = dBuilder.parse(new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit4Skippable.xml"));
+
+ assertEquals("Incorrect number of nodes created", 8, doc.getElementsByTagName("testcase").getLength());
+
+ XPathFactory factory = XPathFactory.newInstance();
+ XPath xpath = factory.newXPath();
+
+ assertEquals("Incorrect number of skipped tests in header", 4, Integer.parseInt(xpath.compile("//testsuite/@skipped").evaluate(doc)));
+ assertEquals("Incorrect number of error tests in header", 1, Integer.parseInt(xpath.compile("//testsuite/@errors").evaluate(doc)));
+ assertEquals("Incorrect number of failure tests in header", 2, Integer.parseInt(xpath.compile("//testsuite/@failures").evaluate(doc)));
+ assertEquals("Incorrect number of tests in header", 8, Integer.parseInt(xpath.compile("//testsuite/@tests").evaluate(doc)));
+
+
+ assertEquals("Incorrect ignore message on explicit ignored test", "Please don't ignore me!", xpath.compile("//testsuite/testcase[@name='explicitIgnoreTest']/skipped/@message").evaluate(doc));
+ assertEquals("No message should be set on Ignored tests with no Ignore annotation text", 0, ((Node)xpath.compile("//testsuite/testcase[@name='explicitlyIgnoreTestNoMessage']/skipped").evaluate(doc, XPathConstants.NODE)).getAttributes().getLength());
+ assertEquals("Incorrect ignore message on implicit ignored test", "This test will be ignored", xpath.compile("//testsuite/testcase[@name='implicitlyIgnoreTest']/skipped/@message").evaluate(doc));
+ assertNotNull("Implicit ignore test should have an ignore element", xpath.compile("//testsuite/testcase[@name='implicitlyIgnoreTestNoMessage']/skipped").evaluate(doc, XPathConstants.NODE));
+
+ }
+
+ @Test
+ public void testTestMethods() throws Exception {
+ buildRule.executeTarget("testTestMethods");
+ }
+
+ @Test
+ public void testNonTestsSkipped() throws Exception {
+
+ buildRule.executeTarget("testNonTests");
+ assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.NonTestMissed.xml").exists());
+ assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestMissed.xml").exists());
+ assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.AbstractTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestMissed.xml").exists());
+ assertFalse("Test result should not exist as test was skipped - TEST-org.example.junit.AbstractJUnit3TestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestMissed.xml").exists());
+ assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestNotMissed.xml").exists());
+ assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractJUnit3TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestNotMissed.xml").exists());
+ assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestNotMissed.xml").exists());
+ assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestNotMissed.xml").exists());
+ assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestWithSuiteNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestWithSuiteNotMissed.xml").exists());
+
+ buildRule.executeTarget("testNonTestsRun");
+ assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.NonTestMissed.xml").exists());
+ assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3NonTestMissed.xml").exists());
+ assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestNotMissed.xml").exists());
+ assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3TestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3TestNotMissed.xml").exists());
+ assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestMissed.xml").exists());
+ assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractTestNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractTestNotMissed.xml").exists());
+ assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.AbstractJUnit3TestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.AbstractJUnit3TestMissed.xml").exists());
+ assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.JUnit3NonTestMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.JUnit3NonTestMissed.xml").exists());
+ assertTrue("Test result should exist as test was not skipped - TEST-org.example.junit.TestWithSuiteNotMissed.xml", new File(buildRule.getOutputDir(), "TEST-org.example.junit.TestWithSuiteNotMissed.xml").exists());
+
+
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java
index 38eaa142b..2b7acd48e 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestListenerTest.java
@@ -1,111 +1,111 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.junit;
-
-import static org.apache.tools.ant.AntAssert.assertContains;
-import static org.apache.tools.ant.AntAssert.assertNotContains;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-public class JUnitTestListenerTest{
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- // The captureToSummary test writes to stdout and stderr, good for
- // verifying that the TestListener support doesn't break anything.
- private static final String PASS_TEST_TARGET = "captureToSummary";
-
- // testNoCrash is the test invoked by the captureToSummary's junit task
- private static final String PASS_TEST = "testNoCrash";
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit.xml");
- }
-
-
- @Test
- public void testFullLogOutput() {
- buildRule.getProject().setProperty("enableEvents", "true");
- buildRule.executeTarget(PASS_TEST_TARGET);
- assertContains("expecting full log to have BuildListener events",
- JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog());
- }
-
- @Test
- public void testNoLogOutput() {
- buildRule.getProject().setProperty("enableEvents", "true");
- buildRule.executeTarget(PASS_TEST_TARGET);
- assertNotContains("expecting log to not have BuildListener events",
- JUnitTask.TESTLISTENER_PREFIX, buildRule.getLog());
- }
-
- @Test
- public void testTestCountFired() {
- buildRule.getProject().setProperty("enableEvents", "true");
- buildRule.executeTarget(PASS_TEST_TARGET);
- assertContains("expecting test count message", JUnitTask.TESTLISTENER_PREFIX +
- "tests to run: ", buildRule.getFullLog());
- }
-
- @Test
- public void testStartTestFired() {
- buildRule.getProject().setProperty("enableEvents", "true");
- buildRule.executeTarget(PASS_TEST_TARGET);
- assertContains("expecting test started message", JUnitTask.TESTLISTENER_PREFIX +
- "startTest(" + PASS_TEST + ")", buildRule.getFullLog());
- }
-
- @Test
- public void testEndTestFired() {
- buildRule.getProject().setProperty("enableEvents", "true");
- buildRule.executeTarget(PASS_TEST_TARGET);
- assertContains("expecting test ended message", JUnitTask.TESTLISTENER_PREFIX +
- "endTest(" + PASS_TEST + ")", buildRule.getFullLog());
- }
-
- @Test
- public void testNoFullLogOutputByDefault() {
- buildRule.executeTarget(PASS_TEST_TARGET);
- assertNotContains("expecting full log to not have BuildListener events",
- JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog());
- }
-
- @Test
- public void testFullLogOutputMagicProperty() {
- buildRule.getProject().setProperty(JUnitTask.ENABLE_TESTLISTENER_EVENTS, "true");
- buildRule.executeTarget(PASS_TEST_TARGET);
- assertContains("expecting full log to have BuildListener events",
- JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog());
- }
-
- @Test
- public void testNoFullLogOutputMagicPropertyWins() {
- buildRule.getProject().setProperty(JUnitTask.ENABLE_TESTLISTENER_EVENTS, "false");
- buildRule.getProject().setProperty("enableEvents", "true");
- buildRule.executeTarget(PASS_TEST_TARGET);
- assertNotContains("expecting full log to not have BuildListener events",
- JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog());
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+import static org.apache.tools.ant.AntAssert.assertContains;
+import static org.apache.tools.ant.AntAssert.assertNotContains;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class JUnitTestListenerTest{
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ // The captureToSummary test writes to stdout and stderr, good for
+ // verifying that the TestListener support doesn't break anything.
+ private static final String PASS_TEST_TARGET = "captureToSummary";
+
+ // testNoCrash is the test invoked by the captureToSummary's junit task
+ private static final String PASS_TEST = "testNoCrash";
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit.xml");
+ }
+
+
+ @Test
+ public void testFullLogOutput() {
+ buildRule.getProject().setProperty("enableEvents", "true");
+ buildRule.executeTarget(PASS_TEST_TARGET);
+ assertContains("expecting full log to have BuildListener events",
+ JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog());
+ }
+
+ @Test
+ public void testNoLogOutput() {
+ buildRule.getProject().setProperty("enableEvents", "true");
+ buildRule.executeTarget(PASS_TEST_TARGET);
+ assertNotContains("expecting log to not have BuildListener events",
+ JUnitTask.TESTLISTENER_PREFIX, buildRule.getLog());
+ }
+
+ @Test
+ public void testTestCountFired() {
+ buildRule.getProject().setProperty("enableEvents", "true");
+ buildRule.executeTarget(PASS_TEST_TARGET);
+ assertContains("expecting test count message", JUnitTask.TESTLISTENER_PREFIX +
+ "tests to run: ", buildRule.getFullLog());
+ }
+
+ @Test
+ public void testStartTestFired() {
+ buildRule.getProject().setProperty("enableEvents", "true");
+ buildRule.executeTarget(PASS_TEST_TARGET);
+ assertContains("expecting test started message", JUnitTask.TESTLISTENER_PREFIX +
+ "startTest(" + PASS_TEST + ")", buildRule.getFullLog());
+ }
+
+ @Test
+ public void testEndTestFired() {
+ buildRule.getProject().setProperty("enableEvents", "true");
+ buildRule.executeTarget(PASS_TEST_TARGET);
+ assertContains("expecting test ended message", JUnitTask.TESTLISTENER_PREFIX +
+ "endTest(" + PASS_TEST + ")", buildRule.getFullLog());
+ }
+
+ @Test
+ public void testNoFullLogOutputByDefault() {
+ buildRule.executeTarget(PASS_TEST_TARGET);
+ assertNotContains("expecting full log to not have BuildListener events",
+ JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog());
+ }
+
+ @Test
+ public void testFullLogOutputMagicProperty() {
+ buildRule.getProject().setProperty(JUnitTask.ENABLE_TESTLISTENER_EVENTS, "true");
+ buildRule.executeTarget(PASS_TEST_TARGET);
+ assertContains("expecting full log to have BuildListener events",
+ JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog());
+ }
+
+ @Test
+ public void testNoFullLogOutputMagicPropertyWins() {
+ buildRule.getProject().setProperty(JUnitTask.ENABLE_TESTLISTENER_EVENTS, "false");
+ buildRule.getProject().setProperty("enableEvents", "true");
+ buildRule.executeTarget(PASS_TEST_TARGET);
+ assertNotContains("expecting full log to not have BuildListener events",
+ JUnitTask.TESTLISTENER_PREFIX, buildRule.getFullLog());
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java
index a75c5cbe5..c0d33e6ef 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitTestRunnerTest.java
@@ -1,217 +1,217 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional.junit;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.io.PrintWriter;
-import java.io.StringWriter;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.TestCase;
-import junit.framework.TestSuite;
-
-import org.apache.tools.ant.BuildException;
-import org.junit.Test;
-
-/**
- * Small testcase for the runner, tests are very very very basics.
- * They must be enhanced with time.
- *
- */
-public class JUnitTestRunnerTest{
-
-
-
- // check that a valid method name generates no errors
- @Test
- public void testValidMethod(){
- TestRunner runner = createRunnerForTestMethod(ValidMethodTestCase.class,"testA");
- runner.run();
- assertEquals(runner.getFormatter().getError(), JUnitTestRunner.SUCCESS, runner.getRetCode());
- }
-
- // check that having an invalid method name generates an error
- @Test
- public void testInvalidMethod(){
- TestRunner runner = createRunnerForTestMethod(InvalidMethodTestCase.class,"testInvalid");
- runner.run();
- String error = runner.getFormatter().getError();
- // might be FAILURES or ERRORS depending on JUnit version?
- assertTrue(error, runner.getRetCode() != JUnitTestRunner.SUCCESS);
- }
-
- // check that having no suite generates no errors
- @Test
- public void testNoSuite(){
- TestRunner runner = createRunner(NoSuiteTestCase.class);
- runner.run();
- assertEquals(runner.getFormatter().getError(), JUnitTestRunner.SUCCESS, runner.getRetCode());
- }
-
- // check that a suite generates no errors
- @Test
- public void testSuite(){
- TestRunner runner = createRunner(SuiteTestCase.class);
- runner.run();
- assertEquals(runner.getFormatter().getError(), JUnitTestRunner.SUCCESS, runner.getRetCode());
- }
-
- // check that an invalid suite generates an error.
- @Test
- public void testInvalidSuite(){
- TestRunner runner = createRunner(InvalidSuiteTestCase.class);
- runner.run();
- String error = runner.getFormatter().getError();
- assertEquals(error, JUnitTestRunner.ERRORS, runner.getRetCode());
- assertTrue(error, error.indexOf("thrown on purpose") != -1);
- }
-
- // check that something which is not a testcase generates no errors
- // at first even though this is incorrect.
- @Test
- public void testNoTestCase(){
- TestRunner runner = createRunner(NoTestCase.class);
- runner.run();
- // On junit3 this is a FAILURE, on junit4 this is an ERROR
- int ret = runner.getRetCode();
-
- if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) {
- fail("Unexpected result " + ret + " from junit runner");
- }
- // JUnit3 test
- //assertEquals(runner.getFormatter().getError(), JUnitTestRunner.FAILURES, runner.getRetCode());
- }
-
- // check that an exception in the constructor is noticed
- @Test
- public void testInvalidTestCase(){
- TestRunner runner = createRunner(InvalidTestCase.class);
- runner.run();
- // On junit3 this is a FAILURE, on junit4 this is an ERROR
- int ret = runner.getRetCode();
- if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) {
- fail("Unexpected result " + ret + " from junit runner");
- }
- // JUNIT3 test
- //assertEquals(error, JUnitTestRunner.FAILURES, runner.getRetCode());
- //@fixme as of now does not report the original stacktrace.
- //assertTrue(error, error.indexOf("thrown on purpose") != -1);
- }
-
- protected TestRunner createRunner(Class> clazz){
- return new TestRunner(new JUnitTest(clazz.getName()), null,
- true, true, true);
- }
-
- protected TestRunner createRunnerForTestMethod(Class> clazz, String method){
- return new TestRunner(new JUnitTest(clazz.getName()), new String[] {method},
- true, true, true);
- }
-
- // the test runner that wrap the dummy formatter that interests us
- private final static class TestRunner extends JUnitTestRunner {
- private ResultFormatter formatter = new ResultFormatter();
- TestRunner(JUnitTest test, String[] methods, boolean haltonerror,
- boolean filtertrace, boolean haltonfailure){
- super(test, methods, haltonerror, filtertrace, haltonfailure,
- false, false, TestRunner.class.getClassLoader());
- // use the classloader that loaded this class otherwise
- // it will not be able to run inner classes if this test
- // is ran in non-forked mode.
- addFormatter(formatter);
- }
- ResultFormatter getFormatter(){
- return formatter;
- }
- }
-
- // dummy formatter just to catch the error
- private final static class ResultFormatter implements JUnitResultFormatter {
- private Throwable error;
- public void setSystemOutput(String output){}
- public void setSystemError(String output){}
- public void startTestSuite(JUnitTest suite) throws BuildException{}
- public void endTestSuite(JUnitTest suite) throws BuildException{}
- public void setOutput(java.io.OutputStream out){}
- public void startTest(junit.framework.Test t) {}
- public void endTest(junit.framework.Test test) {}
- public void addFailure(junit.framework.Test test, AssertionFailedError t) { }
- public void addError(junit.framework.Test test, Throwable t) {
- error = t;
- }
- String getError(){
- if (error == null){
- return "";
- }
- StringWriter sw = new StringWriter();
- error.printStackTrace(new PrintWriter(sw));
- return sw.toString();
- }
- }
-
- public static class NoTestCase {
- }
-
- public static class InvalidMethodTestCase extends TestCase {
- public InvalidMethodTestCase(String name){ super(name); }
- public void testA(){
- throw new NullPointerException("thrown on purpose");
- }
- }
-
- public static class ValidMethodTestCase extends TestCase {
- public ValidMethodTestCase(String name){ super(name); }
- public void testA(){
- // expected to be executed
- }
- public void testB(){
- // should not be executed
- throw new NullPointerException("thrown on purpose");
- }
- }
-
- public static class InvalidTestCase extends TestCase {
- public InvalidTestCase(String name){
- super(name);
- throw new NullPointerException("thrown on purpose");
- }
- }
-
- public static class NoSuiteTestCase extends TestCase {
- public NoSuiteTestCase(String name){ super(name); }
- public void testA(){}
- }
-
- public static class SuiteTestCase extends NoSuiteTestCase {
- public SuiteTestCase(String name){ super(name); }
- public static junit.framework.Test suite(){
- return new TestSuite(SuiteTestCase.class);
- }
- }
-
- public static class InvalidSuiteTestCase extends NoSuiteTestCase {
- public InvalidSuiteTestCase(String name){ super(name); }
- public static junit.framework.Test suite(){
- throw new NullPointerException("thrown on purpose");
- }
- }
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.io.PrintWriter;
+import java.io.StringWriter;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+
+import org.apache.tools.ant.BuildException;
+import org.junit.Test;
+
+/**
+ * Small testcase for the runner, tests are very very very basics.
+ * They must be enhanced with time.
+ *
+ */
+public class JUnitTestRunnerTest{
+
+
+
+ // check that a valid method name generates no errors
+ @Test
+ public void testValidMethod(){
+ TestRunner runner = createRunnerForTestMethod(ValidMethodTestCase.class,"testA");
+ runner.run();
+ assertEquals(runner.getFormatter().getError(), JUnitTestRunner.SUCCESS, runner.getRetCode());
+ }
+
+ // check that having an invalid method name generates an error
+ @Test
+ public void testInvalidMethod(){
+ TestRunner runner = createRunnerForTestMethod(InvalidMethodTestCase.class,"testInvalid");
+ runner.run();
+ String error = runner.getFormatter().getError();
+ // might be FAILURES or ERRORS depending on JUnit version?
+ assertTrue(error, runner.getRetCode() != JUnitTestRunner.SUCCESS);
+ }
+
+ // check that having no suite generates no errors
+ @Test
+ public void testNoSuite(){
+ TestRunner runner = createRunner(NoSuiteTestCase.class);
+ runner.run();
+ assertEquals(runner.getFormatter().getError(), JUnitTestRunner.SUCCESS, runner.getRetCode());
+ }
+
+ // check that a suite generates no errors
+ @Test
+ public void testSuite(){
+ TestRunner runner = createRunner(SuiteTestCase.class);
+ runner.run();
+ assertEquals(runner.getFormatter().getError(), JUnitTestRunner.SUCCESS, runner.getRetCode());
+ }
+
+ // check that an invalid suite generates an error.
+ @Test
+ public void testInvalidSuite(){
+ TestRunner runner = createRunner(InvalidSuiteTestCase.class);
+ runner.run();
+ String error = runner.getFormatter().getError();
+ assertEquals(error, JUnitTestRunner.ERRORS, runner.getRetCode());
+ assertTrue(error, error.indexOf("thrown on purpose") != -1);
+ }
+
+ // check that something which is not a testcase generates no errors
+ // at first even though this is incorrect.
+ @Test
+ public void testNoTestCase(){
+ TestRunner runner = createRunner(NoTestCase.class);
+ runner.run();
+ // On junit3 this is a FAILURE, on junit4 this is an ERROR
+ int ret = runner.getRetCode();
+
+ if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) {
+ fail("Unexpected result " + ret + " from junit runner");
+ }
+ // JUnit3 test
+ //assertEquals(runner.getFormatter().getError(), JUnitTestRunner.FAILURES, runner.getRetCode());
+ }
+
+ // check that an exception in the constructor is noticed
+ @Test
+ public void testInvalidTestCase(){
+ TestRunner runner = createRunner(InvalidTestCase.class);
+ runner.run();
+ // On junit3 this is a FAILURE, on junit4 this is an ERROR
+ int ret = runner.getRetCode();
+ if (ret != JUnitTestRunner.FAILURES && ret != JUnitTestRunner.ERRORS) {
+ fail("Unexpected result " + ret + " from junit runner");
+ }
+ // JUNIT3 test
+ //assertEquals(error, JUnitTestRunner.FAILURES, runner.getRetCode());
+ //@fixme as of now does not report the original stacktrace.
+ //assertTrue(error, error.indexOf("thrown on purpose") != -1);
+ }
+
+ protected TestRunner createRunner(Class> clazz){
+ return new TestRunner(new JUnitTest(clazz.getName()), null,
+ true, true, true);
+ }
+
+ protected TestRunner createRunnerForTestMethod(Class> clazz, String method){
+ return new TestRunner(new JUnitTest(clazz.getName()), new String[] {method},
+ true, true, true);
+ }
+
+ // the test runner that wrap the dummy formatter that interests us
+ private final static class TestRunner extends JUnitTestRunner {
+ private ResultFormatter formatter = new ResultFormatter();
+ TestRunner(JUnitTest test, String[] methods, boolean haltonerror,
+ boolean filtertrace, boolean haltonfailure){
+ super(test, methods, haltonerror, filtertrace, haltonfailure,
+ false, false, TestRunner.class.getClassLoader());
+ // use the classloader that loaded this class otherwise
+ // it will not be able to run inner classes if this test
+ // is ran in non-forked mode.
+ addFormatter(formatter);
+ }
+ ResultFormatter getFormatter(){
+ return formatter;
+ }
+ }
+
+ // dummy formatter just to catch the error
+ private final static class ResultFormatter implements JUnitResultFormatter {
+ private Throwable error;
+ public void setSystemOutput(String output){}
+ public void setSystemError(String output){}
+ public void startTestSuite(JUnitTest suite) throws BuildException{}
+ public void endTestSuite(JUnitTest suite) throws BuildException{}
+ public void setOutput(java.io.OutputStream out){}
+ public void startTest(junit.framework.Test t) {}
+ public void endTest(junit.framework.Test test) {}
+ public void addFailure(junit.framework.Test test, AssertionFailedError t) { }
+ public void addError(junit.framework.Test test, Throwable t) {
+ error = t;
+ }
+ String getError(){
+ if (error == null){
+ return "";
+ }
+ StringWriter sw = new StringWriter();
+ error.printStackTrace(new PrintWriter(sw));
+ return sw.toString();
+ }
+ }
+
+ public static class NoTestCase {
+ }
+
+ public static class InvalidMethodTestCase extends TestCase {
+ public InvalidMethodTestCase(String name){ super(name); }
+ public void testA(){
+ throw new NullPointerException("thrown on purpose");
+ }
+ }
+
+ public static class ValidMethodTestCase extends TestCase {
+ public ValidMethodTestCase(String name){ super(name); }
+ public void testA(){
+ // expected to be executed
+ }
+ public void testB(){
+ // should not be executed
+ throw new NullPointerException("thrown on purpose");
+ }
+ }
+
+ public static class InvalidTestCase extends TestCase {
+ public InvalidTestCase(String name){
+ super(name);
+ throw new NullPointerException("thrown on purpose");
+ }
+ }
+
+ public static class NoSuiteTestCase extends TestCase {
+ public NoSuiteTestCase(String name){ super(name); }
+ public void testA(){}
+ }
+
+ public static class SuiteTestCase extends NoSuiteTestCase {
+ public SuiteTestCase(String name){ super(name); }
+ public static junit.framework.Test suite(){
+ return new TestSuite(SuiteTestCase.class);
+ }
+ }
+
+ public static class InvalidSuiteTestCase extends NoSuiteTestCase {
+ public InvalidSuiteTestCase(String name){ super(name); }
+ public static junit.framework.Test suite(){
+ throw new NullPointerException("thrown on purpose");
+ }
+ }
+}
+
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java
index 8af3d23c9..b00bfde49 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/JUnitVersionHelperTest.java
@@ -1,102 +1,102 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional.junit;
-
-import static org.junit.Assert.assertEquals;
-import junit.framework.JUnit4TestAdapterCache;
-import junit.framework.TestCase;
-import junit.framework.TestResult;
-
-import org.junit.Test;
-import org.junit.runner.Description;
-
-/**
- */
-public class JUnitVersionHelperTest {
-
- @Test
- public void testMyOwnName() {
- assertEquals("testMyOwnName",
- JUnitVersionHelper.getTestCaseName(
- JUnit4TestAdapterCache.getDefault().asTest(
- Description.createTestDescription(JUnitVersionHelperTest.class, "testMyOwnName")
- )
- )
- );
- }
-
- @Test
- public void testNonTestCaseName() {
- assertEquals("I'm a foo",
- JUnitVersionHelper.getTestCaseName(new Foo1()));
- }
-
- @Test
- public void testNoStringReturn() {
- assertEquals("unknown",
- JUnitVersionHelper.getTestCaseName(new Foo2()));
- }
-
- @Test
- public void testNoGetName() {
- assertEquals("unknown",
- JUnitVersionHelper.getTestCaseName(new Foo3()));
- }
-
- @Test
- public void testNameNotGetName() {
- assertEquals("I'm a foo, too",
- JUnitVersionHelper.getTestCaseName(new Foo4()));
- }
-
- @Test
- public void testNull() {
- assertEquals("unknown", JUnitVersionHelper.getTestCaseName(null));
- }
-
- @Test
- public void testTestCaseSubClass() {
- assertEquals("overridden getName",
- JUnitVersionHelper.getTestCaseName(new Foo5()));
- }
-
- public static class Foo implements junit.framework.Test {
- public int countTestCases() {return 0;}
- public void run(TestResult result) {}
- }
-
- public static class Foo1 extends Foo {
- public String getName() {return "I'm a foo";}
- }
-
- public static class Foo2 extends Foo {
- public int getName() {return 1;}
- }
-
- public static class Foo3 extends Foo {
- }
-
- public static class Foo4 extends Foo {
- public String name() {return "I'm a foo, too";}
- }
-
- public static class Foo5 extends TestCase {
- public String getName() {return "overridden getName";}
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+import static org.junit.Assert.assertEquals;
+import junit.framework.JUnit4TestAdapterCache;
+import junit.framework.TestCase;
+import junit.framework.TestResult;
+
+import org.junit.Test;
+import org.junit.runner.Description;
+
+/**
+ */
+public class JUnitVersionHelperTest {
+
+ @Test
+ public void testMyOwnName() {
+ assertEquals("testMyOwnName",
+ JUnitVersionHelper.getTestCaseName(
+ JUnit4TestAdapterCache.getDefault().asTest(
+ Description.createTestDescription(JUnitVersionHelperTest.class, "testMyOwnName")
+ )
+ )
+ );
+ }
+
+ @Test
+ public void testNonTestCaseName() {
+ assertEquals("I'm a foo",
+ JUnitVersionHelper.getTestCaseName(new Foo1()));
+ }
+
+ @Test
+ public void testNoStringReturn() {
+ assertEquals("unknown",
+ JUnitVersionHelper.getTestCaseName(new Foo2()));
+ }
+
+ @Test
+ public void testNoGetName() {
+ assertEquals("unknown",
+ JUnitVersionHelper.getTestCaseName(new Foo3()));
+ }
+
+ @Test
+ public void testNameNotGetName() {
+ assertEquals("I'm a foo, too",
+ JUnitVersionHelper.getTestCaseName(new Foo4()));
+ }
+
+ @Test
+ public void testNull() {
+ assertEquals("unknown", JUnitVersionHelper.getTestCaseName(null));
+ }
+
+ @Test
+ public void testTestCaseSubClass() {
+ assertEquals("overridden getName",
+ JUnitVersionHelper.getTestCaseName(new Foo5()));
+ }
+
+ public static class Foo implements junit.framework.Test {
+ public int countTestCases() {return 0;}
+ public void run(TestResult result) {}
+ }
+
+ public static class Foo1 extends Foo {
+ public String getName() {return "I'm a foo";}
+ }
+
+ public static class Foo2 extends Foo {
+ public int getName() {return 1;}
+ }
+
+ public static class Foo3 extends Foo {
+ }
+
+ public static class Foo4 extends Foo {
+ public String name() {return "I'm a foo, too";}
+ }
+
+ public static class Foo5 extends TestCase {
+ public String getName() {return "overridden getName";}
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/NoVmCrash.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/NoVmCrash.java
index 392a92ee4..85fbee747 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/NoVmCrash.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/NoVmCrash.java
@@ -1,30 +1,30 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional.junit;
-
-import org.junit.Test;
-
-/**
- */
-public class NoVmCrash {
-
- @Test
- public void testNoCrash() {
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+import org.junit.Test;
+
+/**
+ */
+public class NoVmCrash {
+
+ @Test
+ public void testNoCrash() {
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Printer.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Printer.java
index 0200648db..c29077285 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Printer.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Printer.java
@@ -1,42 +1,42 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional.junit;
-
-import org.junit.Test;
-
-/**
- */
-public class Printer {
-
- public Printer() {
- System.err.println("constructor print to System.err");
- System.out.println("constructor print to System.out");
- }
-
- static {
- System.err.println("static print to System.err");
- System.out.println("static print to System.out");
- }
-
- @Test
- public void testNoCrash() {
- System.err.println("method print to System.err");
- System.out.println("method print to System.out");
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+import org.junit.Test;
+
+/**
+ */
+public class Printer {
+
+ public Printer() {
+ System.err.println("constructor print to System.err");
+ System.out.println("constructor print to System.out");
+ }
+
+ static {
+ System.err.println("static print to System.err");
+ System.out.println("static print to System.out");
+ }
+
+ @Test
+ public void testNoCrash() {
+ System.err.println("method print to System.err");
+ System.out.println("method print to System.out");
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java
index 150989483..0d0cb677f 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/Sleeper.java
@@ -1,30 +1,30 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional.junit;
-
-
-import org.junit.Test;
-
-public class Sleeper {
-
- @Test
- public void testSleep() throws InterruptedException {
- Thread.sleep(5 * 1000);
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+
+import org.junit.Test;
+
+public class Sleeper {
+
+ @Test
+ public void testSleep() throws InterruptedException {
+ Thread.sleep(5 * 1000);
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/SuiteMethodTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/SuiteMethodTest.java
index 14a09661a..207dda656 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/SuiteMethodTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/SuiteMethodTest.java
@@ -1,42 +1,42 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional.junit;
-
-import junit.framework.Test;
-import junit.framework.TestCase;
-
-/**
- * validates that the suite() method works in classes that don't
- * implement Test.
- */
-public class SuiteMethodTest {
-
- public static Test suite() {
- return new Nested("testMethod");
- }
-
- public static class Nested extends TestCase {
- public Nested(String name) {
- super(name);
- }
-
- public void testMethod() {
- assertTrue(true);
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+
+/**
+ * validates that the suite() method works in classes that don't
+ * implement Test.
+ */
+public class SuiteMethodTest {
+
+ public static Test suite() {
+ return new Nested("testMethod");
+ }
+
+ public static class Nested extends TestCase {
+ public Nested(String name) {
+ super(name);
+ }
+
+ public void testMethod() {
+ assertTrue(true);
+ }
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TearDownOnVmCrashTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TearDownOnVmCrashTest.java
index a85d9fea6..bfc6d312c 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TearDownOnVmCrashTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TearDownOnVmCrashTest.java
@@ -1,53 +1,53 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.junit;
-
-import static org.apache.tools.ant.AntAssert.assertContains;
-import static org.apache.tools.ant.AntAssert.assertNotContains;
-import static org.junit.Assert.assertEquals;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-public class TearDownOnVmCrashTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit/teardownlistener.xml");
- }
-
- @Test
- public void testNoTeardown() {
- buildRule.executeTarget("testNoTeardown");
- assertEquals("true", buildRule.getProject().getProperty("error"));
- assertNotContains("tearDown called on Timeout", buildRule.getOutput());
- }
-
- @Test
- public void testTeardown() {
- buildRule.executeTarget("testTeardown");
- assertEquals("true", buildRule.getProject().getProperty("error"));
- assertContains("tearDown called on Timeout", buildRule.getOutput());
- }
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+import static org.apache.tools.ant.AntAssert.assertContains;
+import static org.apache.tools.ant.AntAssert.assertNotContains;
+import static org.junit.Assert.assertEquals;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class TearDownOnVmCrashTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/junit/teardownlistener.xml");
+ }
+
+ @Test
+ public void testNoTeardown() {
+ buildRule.executeTarget("testNoTeardown");
+ assertEquals("true", buildRule.getProject().getProperty("error"));
+ assertNotContains("tearDown called on Timeout", buildRule.getOutput());
+ }
+
+ @Test
+ public void testTeardown() {
+ buildRule.executeTarget("testTeardown");
+ assertEquals("true", buildRule.getProject().getProperty("error"));
+ assertContains("tearDown called on Timeout", buildRule.getOutput());
+ }
}
\ No newline at end of file
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TestFormatter.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TestFormatter.java
index 27420d6f4..d40da0bef 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TestFormatter.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/TestFormatter.java
@@ -1,112 +1,112 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.junit;
-
-import java.io.IOException;
-import java.io.OutputStream;
-
-import junit.framework.AssertionFailedError;
-import junit.framework.Test;
-
-import org.apache.tools.ant.BuildException;
-
-public class TestFormatter implements JUnitResultFormatter {
-
- private static final byte[] grafitto = new byte[] {
- (byte) 'T', (byte) 'e', (byte) 's', (byte) 't', (byte) 'F', (byte) 'o',
- (byte) 'r', (byte) 'm', (byte) 'a', (byte) 't', (byte) 't', (byte) 'e',
- (byte) 'r', (byte) ' ', (byte) 'w', (byte) 'a', (byte) 's', (byte) ' ',
- (byte) 'h', (byte) 'e', (byte) 'r', (byte) 'e', 10
- };
-
- /**
- * Where to write the log to.
- */
- private OutputStream out;
-
- /**
- * Empty
- */
- public TestFormatter() {
- }
-
- /**
- * Empty
- */
- public void startTestSuite(JUnitTest suite) {
- }
- /**
- * Empty
- */
- public void startTest(Test t) {
- }
- /**
- * Empty
- */
- public void endTest(Test test) {
- }
- /**
- * Empty
- */
- public void addFailure(Test test, Throwable t) {
- }
- /**
- * Empty
- */
- public void addFailure(Test test, AssertionFailedError t) {
- }
- /**
- * Empty
- */
- public void addError(Test test, Throwable t) {
- }
- /**
- * Empty
- */
- public void setSystemOutput(String out) {
- }
- /**
- * Empty
- */
- public void setSystemError(String err) {
- }
-
- public void setOutput(OutputStream out) {
- this.out = out;
- }
-
- public void endTestSuite(JUnitTest suite) throws BuildException {
- if (out != null) {
- try {
- out.write(grafitto);
- out.flush();
- } catch (IOException ioex) {
- throw new BuildException("Unable to write output", ioex);
- } finally {
- if (out != System.out && out != System.err) {
- try {
- out.close();
- } catch (IOException e) {
- // ignore
- }
- }
- }
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+import java.io.IOException;
+import java.io.OutputStream;
+
+import junit.framework.AssertionFailedError;
+import junit.framework.Test;
+
+import org.apache.tools.ant.BuildException;
+
+public class TestFormatter implements JUnitResultFormatter {
+
+ private static final byte[] grafitto = new byte[] {
+ (byte) 'T', (byte) 'e', (byte) 's', (byte) 't', (byte) 'F', (byte) 'o',
+ (byte) 'r', (byte) 'm', (byte) 'a', (byte) 't', (byte) 't', (byte) 'e',
+ (byte) 'r', (byte) ' ', (byte) 'w', (byte) 'a', (byte) 's', (byte) ' ',
+ (byte) 'h', (byte) 'e', (byte) 'r', (byte) 'e', 10
+ };
+
+ /**
+ * Where to write the log to.
+ */
+ private OutputStream out;
+
+ /**
+ * Empty
+ */
+ public TestFormatter() {
+ }
+
+ /**
+ * Empty
+ */
+ public void startTestSuite(JUnitTest suite) {
+ }
+ /**
+ * Empty
+ */
+ public void startTest(Test t) {
+ }
+ /**
+ * Empty
+ */
+ public void endTest(Test test) {
+ }
+ /**
+ * Empty
+ */
+ public void addFailure(Test test, Throwable t) {
+ }
+ /**
+ * Empty
+ */
+ public void addFailure(Test test, AssertionFailedError t) {
+ }
+ /**
+ * Empty
+ */
+ public void addError(Test test, Throwable t) {
+ }
+ /**
+ * Empty
+ */
+ public void setSystemOutput(String out) {
+ }
+ /**
+ * Empty
+ */
+ public void setSystemError(String err) {
+ }
+
+ public void setOutput(OutputStream out) {
+ this.out = out;
+ }
+
+ public void endTestSuite(JUnitTest suite) throws BuildException {
+ if (out != null) {
+ try {
+ out.write(grafitto);
+ out.flush();
+ } catch (IOException ioex) {
+ throw new BuildException("Unable to write output", ioex);
+ } finally {
+ if (out != System.out && out != System.err) {
+ try {
+ out.close();
+ } catch (IOException e) {
+ // ignore
+ }
+ }
+ }
+ }
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/VmCrash.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/VmCrash.java
index 92d21b681..9c5e5898a 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/VmCrash.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/VmCrash.java
@@ -1,31 +1,31 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional.junit;
-
-import org.junit.Test;
-
-/**
- */
-public class VmCrash {
-
- @Test
- public void testCrash() {
- System.exit(0);
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+import org.junit.Test;
+
+/**
+ */
+public class VmCrash {
+
+ @Test
+ public void testCrash() {
+ System.exit(0);
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLFormatterWithCDATAOnSystemOut.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLFormatterWithCDATAOnSystemOut.java
index 3f464d872..f28bf72c3 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLFormatterWithCDATAOnSystemOut.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLFormatterWithCDATAOnSystemOut.java
@@ -1,83 +1,83 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional.junit;
-
-import java.io.File;
-import java.io.FileReader;
-import java.io.IOException;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.util.FileUtils;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-
-public class XMLFormatterWithCDATAOnSystemOut {
-
- private static final String DIR = "src/etc/testcases/taskdefs/optional/junit";
- private static final String REPORT =
- "TEST-" + XMLFormatterWithCDATAOnSystemOut.class.getName() + ".xml";
-
- private static final String TESTDATA =
- "" +
- "" +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- " " +
- "]]>" +
- "";
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Test
- public void testOutput() {
- System.out.println(TESTDATA);
- }
-
- @Test
- public void testBuildfile() throws IOException {
- buildRule.configureProject(DIR + "/cdataoutput.xml");
- if (buildRule.getProject().getProperty("cdata.inner") == null) {
- // avoid endless loop
- buildRule.executeTarget("run-junit");
- File f = buildRule.getProject().resolveFile(REPORT);
- FileReader reader = null;
- try {
- reader = new FileReader(f);
- String content = FileUtils.readFully(reader);
- assertTrue(content.indexOf("]]>"
- + "") > 0);
- } finally {
- if (reader != null) {
- reader.close();
- }
- f.delete();
- }
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+import java.io.File;
+import java.io.FileReader;
+import java.io.IOException;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.util.FileUtils;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+
+public class XMLFormatterWithCDATAOnSystemOut {
+
+ private static final String DIR = "src/etc/testcases/taskdefs/optional/junit";
+ private static final String REPORT =
+ "TEST-" + XMLFormatterWithCDATAOnSystemOut.class.getName() + ".xml";
+
+ private static final String TESTDATA =
+ "" +
+ "" +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ " " +
+ "]]>" +
+ "";
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Test
+ public void testOutput() {
+ System.out.println(TESTDATA);
+ }
+
+ @Test
+ public void testBuildfile() throws IOException {
+ buildRule.configureProject(DIR + "/cdataoutput.xml");
+ if (buildRule.getProject().getProperty("cdata.inner") == null) {
+ // avoid endless loop
+ buildRule.executeTarget("run-junit");
+ File f = buildRule.getProject().resolveFile(REPORT);
+ FileReader reader = null;
+ try {
+ reader = new FileReader(f);
+ String content = FileUtils.readFully(reader);
+ assertTrue(content.indexOf("]]>"
+ + "") > 0);
+ } finally {
+ if (reader != null) {
+ reader.close();
+ }
+ f.delete();
+ }
+ }
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java
index da67fec89..095a2f072 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/junit/XMLResultAggregatorTest.java
@@ -1,93 +1,93 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.junit;
-
-import static org.junit.Assert.assertTrue;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.PrintWriter;
-import java.security.Permission;
-
-import org.apache.tools.ant.DefaultLogger;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.Delete;
-import org.apache.tools.ant.types.FileSet;
-import org.junit.Assume;
-import org.junit.Test;
-
-public class XMLResultAggregatorTest {
-
- @Test
- public void testFrames() throws Exception {
- // For now, skip this test on JDK 6 (and below); see below for why:
- try {
- Class.forName("java.nio.file.Files");
- } catch (ClassNotFoundException x) {
- Assume.assumeNoException("Skip test on JDK 6 and below", x);
- }
- final File d = new File(System.getProperty("java.io.tmpdir"), "XMLResultAggregatorTest");
- if (d.exists()) {
- new Delete() {{removeDir(d);}}; // is there no utility method for this?
- }
- assertTrue(d.getAbsolutePath(), d.mkdir());
- File xml = new File(d, "x.xml");
- PrintWriter pw = new PrintWriter(new FileOutputStream(xml));
- try {
- pw.println("");
- pw.println(" ");
- pw.println("");
- pw.flush();
- } finally {
- pw.close();
- }
- XMLResultAggregator task = new XMLResultAggregator();
- task.setTodir(d);
- Project project = new Project();
- DefaultLogger logger = new DefaultLogger();
- logger.setOutputPrintStream(System.out);
- logger.setErrorPrintStream(System.err);
- logger.setMessageOutputLevel(Project.MSG_INFO);
- project.addBuildListener(logger);
- project.init();
- task.setProject(project);
- AggregateTransformer report = task.createReport();
- report.setTodir(d);
- FileSet fs = new FileSet();
- fs.setFile(xml);
- task.addFileSet(fs);
- /* getResourceAsStream override unnecessary on JDK 7. Ought to work around JAXP #6723276 in JDK 6, but causes a TypeCheckError in FunctionCall for reasons TBD:
- Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) {
- public InputStream getResourceAsStream(String name) {
- if (name.startsWith("META-INF/services/")) {
- return new ByteArrayInputStream(new byte[0]);
- }
- return super.getResourceAsStream(name);
- }
- });
- */
- // Use the JRE's Xerces, not lib/optional/xerces.jar:
- Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader().getParent());
- // Tickle #51668:
- System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}});
- task.execute();
- assertTrue(new File(d, "index.html").isFile());
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional.junit;
+
+import static org.junit.Assert.assertTrue;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.PrintWriter;
+import java.security.Permission;
+
+import org.apache.tools.ant.DefaultLogger;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.Delete;
+import org.apache.tools.ant.types.FileSet;
+import org.junit.Assume;
+import org.junit.Test;
+
+public class XMLResultAggregatorTest {
+
+ @Test
+ public void testFrames() throws Exception {
+ // For now, skip this test on JDK 6 (and below); see below for why:
+ try {
+ Class.forName("java.nio.file.Files");
+ } catch (ClassNotFoundException x) {
+ Assume.assumeNoException("Skip test on JDK 6 and below", x);
+ }
+ final File d = new File(System.getProperty("java.io.tmpdir"), "XMLResultAggregatorTest");
+ if (d.exists()) {
+ new Delete() {{removeDir(d);}}; // is there no utility method for this?
+ }
+ assertTrue(d.getAbsolutePath(), d.mkdir());
+ File xml = new File(d, "x.xml");
+ PrintWriter pw = new PrintWriter(new FileOutputStream(xml));
+ try {
+ pw.println("");
+ pw.println(" ");
+ pw.println("");
+ pw.flush();
+ } finally {
+ pw.close();
+ }
+ XMLResultAggregator task = new XMLResultAggregator();
+ task.setTodir(d);
+ Project project = new Project();
+ DefaultLogger logger = new DefaultLogger();
+ logger.setOutputPrintStream(System.out);
+ logger.setErrorPrintStream(System.err);
+ logger.setMessageOutputLevel(Project.MSG_INFO);
+ project.addBuildListener(logger);
+ project.init();
+ task.setProject(project);
+ AggregateTransformer report = task.createReport();
+ report.setTodir(d);
+ FileSet fs = new FileSet();
+ fs.setFile(xml);
+ task.addFileSet(fs);
+ /* getResourceAsStream override unnecessary on JDK 7. Ought to work around JAXP #6723276 in JDK 6, but causes a TypeCheckError in FunctionCall for reasons TBD:
+ Thread.currentThread().setContextClassLoader(new ClassLoader(ClassLoader.getSystemClassLoader().getParent()) {
+ public InputStream getResourceAsStream(String name) {
+ if (name.startsWith("META-INF/services/")) {
+ return new ByteArrayInputStream(new byte[0]);
+ }
+ return super.getResourceAsStream(name);
+ }
+ });
+ */
+ // Use the JRE's Xerces, not lib/optional/xerces.jar:
+ Thread.currentThread().setContextClassLoader(ClassLoader.getSystemClassLoader().getParent());
+ // Tickle #51668:
+ System.setSecurityManager(new SecurityManager() {public void checkPermission(Permission perm) {}});
+ task.execute();
+ assertTrue(new File(d, "index.html").isFile());
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java
index 1a22115ed..954a75bdb 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/net/FTPTest.java
@@ -1,879 +1,879 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional.net;
-
-import static org.apache.tools.ant.AntAssert.assertContains;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.File;
-import java.io.IOException;
-import java.util.Arrays;
-import java.util.HashMap;
-import java.util.Map;
-import java.util.Random;
-import java.util.Vector;
-
-import org.apache.commons.net.ftp.FTPClient;
-import org.apache.tools.ant.BuildEvent;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.DefaultLogger;
-import org.apache.tools.ant.DirectoryScanner;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.condition.Os;
-import org.apache.tools.ant.types.FileSet;
-import org.apache.tools.ant.util.RetryHandler;
-import org.apache.tools.ant.util.Retryable;
-import org.apache.tools.ant.util.regexp.RegexpMatcher;
-import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
-import org.junit.After;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-//FIXME these tests are more integration than unit tests and report errors badly
-public class FTPTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- // keep track of what operating systems are supported here.
- private boolean supportsSymlinks = Os.isFamily("unix");
-
- private FTPClient ftp;
-
- private boolean loginSuceeded = false;
-
- private String loginFailureMessage;
-
- private String tmpDir = null;
- private String remoteTmpDir = null;
- private String ftpFileSep = null;
- private myFTP myFTPTask = new myFTP();
-
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/net/ftp.xml");
- Project project = buildRule.getProject();
- project.executeTarget("setup");
- tmpDir = project.getProperty("tmp.dir");
- ftp = new FTPClient();
- ftpFileSep = project.getProperty("ftp.filesep");
- myFTPTask.setSeparator(ftpFileSep);
- myFTPTask.setProject(project);
- remoteTmpDir = myFTPTask.resolveFile(tmpDir);
- String remoteHost = project.getProperty("ftp.host");
- int port = Integer.parseInt(project.getProperty("ftp.port"));
- String remoteUser = project.getProperty("ftp.user");
- String password = project.getProperty("ftp.password");
- boolean connectionSucceeded = false;
- try {
- ftp.connect(remoteHost, port);
- connectionSucceeded = true;
- } catch (Exception ex) {
- loginFailureMessage = "could not connect to host " + remoteHost + " on port " + port;
- }
- if (connectionSucceeded) {
- try {
- ftp.login(remoteUser, password);
- loginSuceeded = true;
- } catch (IOException ioe) {
- loginFailureMessage = "could not log on to " + remoteHost + " as user " + remoteUser;
- }
- }
- }
-
- @After
- public void tearDown() {
- try {
- if (ftp!= null) {
- ftp.disconnect();
- }
- } catch (IOException ioe) {
- // do nothing
- }
- buildRule.getProject().executeTarget("cleanup");
- }
-
- private boolean changeRemoteDir(String remoteDir) {
- boolean result = true;
- try {
- ftp.cwd(remoteDir);
- }
- catch (Exception ex) {
- System.out.println("could not change directory to " + remoteTmpDir);
- result = false;
- }
- return result;
- }
-
- @Test
- public void test1() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
-
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha"});
- ds.scan();
- compareFiles(ds, new String[] {} ,new String[] {"alpha"});
- }
-
- @Test
- public void test2() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha/"});
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/beta.xml",
- "alpha/beta/gamma/gamma.xml"},
- new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
- }
-
- @Test
- public void test3() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/beta.xml",
- "alpha/beta/gamma/gamma.xml"},
- new String[] {"alpha", "alpha/beta",
- "alpha/beta/gamma"});
- }
-
- @Test
- public void testFullPathMatchesCaseSensitive() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"});
- ds.scan();
- compareFiles(ds, new String[] {}, new String[] {});
- }
-
- @Test
- public void testFullPathMatchesCaseInsensitive() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setCaseSensitive(false);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"});
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
- new String[] {});
- }
-
- @Test
- public void test2ButCaseInsensitive() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"ALPHA/"});
- ds.setCaseSensitive(false);
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/beta.xml",
- "alpha/beta/gamma/gamma.xml"},
- new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
- }
-
- @Test
- public void test2bisButCaseInsensitive() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha/BETA/gamma/"});
- ds.setCaseSensitive(false);
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
- new String[] {"alpha/beta/gamma"});
- }
-
- @Test
- public void testGetWithSelector() {
- buildRule.executeTarget("ftp-get-with-selector");
- assertContains("selectors are not supported in remote filesets", buildRule.getLog());
- FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector");
- DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject());
- dsDestination.scan();
- String [] sortedDestinationDirectories = dsDestination.getIncludedDirectories();
- String [] sortedDestinationFiles = dsDestination.getIncludedFiles();
- for (int counter = 0; counter < sortedDestinationDirectories.length; counter++) {
- sortedDestinationDirectories[counter] =
- sortedDestinationDirectories[counter].replace(File.separatorChar, '/');
- }
- for (int counter = 0; counter < sortedDestinationFiles.length; counter++) {
- sortedDestinationFiles[counter] =
- sortedDestinationFiles[counter].replace(File.separatorChar, '/');
- }
- FileSet fsSource = (FileSet) buildRule.getProject().getReference("fileset-source-without-selector");
- DirectoryScanner dsSource = fsSource.getDirectoryScanner(buildRule.getProject());
- dsSource.scan();
- compareFiles(dsSource, sortedDestinationFiles, sortedDestinationDirectories);
- }
-
- @Test
- public void testGetFollowSymlinksTrue() {
- Assume.assumeTrue("System does not support Symlinks", supportsSymlinks);
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- buildRule.getProject().executeTarget("ftp-get-directory-symbolic-link");
- FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector");
- DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject());
- dsDestination.scan();
- compareFiles(dsDestination, new String[] {"alpha/beta/gamma/gamma.xml"},
- new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
- }
-
- @Test
- public void testGetFollowSymlinksFalse() {
- Assume.assumeTrue("System does not support Symlinks", supportsSymlinks);
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- buildRule.getProject().executeTarget("ftp-get-directory-no-symbolic-link");
- FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector");
- DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject());
- dsDestination.scan();
- compareFiles(dsDestination, new String[] {},
- new String[] {});
- }
-
- @Test
- public void testAllowSymlinks() {
- Assume.assumeTrue("System does not support Symlinks", supportsSymlinks);
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- buildRule.getProject().executeTarget("symlink-setup");
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha/beta/gamma/"});
- ds.setFollowSymlinks(true);
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
- new String[] {"alpha/beta/gamma"});
- }
-
- @Test
- public void testProhibitSymlinks() {
- Assume.assumeTrue("System does not support Symlinks", supportsSymlinks);
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- buildRule.getProject().executeTarget("symlink-setup");
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha/beta/gamma/"});
- ds.setFollowSymlinks(false);
- ds.scan();
- compareFiles(ds, new String[] {}, new String[] {});
- }
-
- @Test
- public void testFileSymlink() {
- Assume.assumeTrue("System does not support Symlinks", supportsSymlinks);
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- buildRule.getProject().executeTarget("symlink-file-setup");
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha/beta/gamma/"});
- ds.setFollowSymlinks(true);
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
- new String[] {"alpha/beta/gamma"});
- }
-
- // father and child pattern test
- @Test
- public void testOrderOfIncludePatternsIrrelevant() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- String [] expectedFiles = {"alpha/beta/beta.xml",
- "alpha/beta/gamma/gamma.xml"};
- String [] expectedDirectories = {"alpha/beta", "alpha/beta/gamma" };
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha/be?a/**", "alpha/beta/gamma/"});
- ds.scan();
- compareFiles(ds, expectedFiles, expectedDirectories);
- // redo the test, but the 2 include patterns are inverted
- ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha/beta/gamma/", "alpha/be?a/**"});
- ds.scan();
- compareFiles(ds, expectedFiles, expectedDirectories);
- }
-
- @Test
- public void testPatternsDifferInCaseScanningSensitive() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha/", "ALPHA/"});
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/beta.xml",
- "alpha/beta/gamma/gamma.xml"},
- new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
- }
-
- @Test
- public void testPatternsDifferInCaseScanningInsensitive() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha/", "ALPHA/"});
- ds.setCaseSensitive(false);
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/beta.xml",
- "alpha/beta/gamma/gamma.xml"},
- new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
- }
-
- @Test
- public void testFullpathDiffersInCaseScanningSensitive() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {
- "alpha/beta/gamma/gamma.xml",
- "alpha/beta/gamma/GAMMA.XML"
- });
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
- new String[] {});
- }
-
- @Test
- public void testFullpathDiffersInCaseScanningInsensitive() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {
- "alpha/beta/gamma/gamma.xml",
- "alpha/beta/gamma/GAMMA.XML"
- });
- ds.setCaseSensitive(false);
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
- new String[] {});
- }
-
- @Test
- public void testParentDiffersInCaseScanningSensitive() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha/", "ALPHA/beta/"});
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/beta.xml",
- "alpha/beta/gamma/gamma.xml"},
- new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
- }
-
- @Test
- public void testParentDiffersInCaseScanningInsensitive() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {"alpha/", "ALPHA/beta/"});
- ds.setCaseSensitive(false);
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/beta.xml",
- "alpha/beta/gamma/gamma.xml"},
- new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
- }
-
- @Test
- public void testExcludeOneFile() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {
- "**/*.xml"
- });
- ds.setExcludes(new String[] {
- "alpha/beta/b*xml"
- });
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
- new String[] {});
- }
-
- @Test
- public void testExcludeHasPrecedence() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {
- "alpha/**"
- });
- ds.setExcludes(new String[] {
- "alpha/**"
- });
- ds.scan();
- compareFiles(ds, new String[] {},
- new String[] {});
-
- }
-
- @Test
- public void testAlternateIncludeExclude() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setIncludes(new String[] {
- "alpha/**",
- "alpha/beta/gamma/**"
- });
- ds.setExcludes(new String[] {
- "alpha/beta/**"
- });
- ds.scan();
- compareFiles(ds, new String[] {},
- new String[] {"alpha"});
-
- }
-
- @Test
- public void testAlternateExcludeInclude() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setExcludes(new String[] {
- "alpha/**",
- "alpha/beta/gamma/**"
- });
- ds.setIncludes(new String[] {
- "alpha/beta/**"
- });
- ds.scan();
- compareFiles(ds, new String[] {},
- new String[] {});
-
- }
-
- /**
- * Test inspired by Bug#1415.
- */
- @Test
- public void testChildrenOfExcludedDirectory() {
- Assume.assumeTrue(loginFailureMessage, loginSuceeded);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- buildRule.getProject().executeTarget("children-of-excluded-dir-setup");
- FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setExcludes(new String[] {"alpha/**"});
- ds.scan();
- compareFiles(ds, new String[] {"delta/delta.xml"},
- new String[] {"delta"});
-
- ds = myFTPTask.newScanner(ftp);
- Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
- ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
- ds.setExcludes(new String[] {"alpha"});
- ds.scan();
- compareFiles(ds, new String[] {"alpha/beta/beta.xml",
- "alpha/beta/gamma/gamma.xml",
- "delta/delta.xml"},
- new String[] {"alpha/beta", "alpha/beta/gamma", "delta"});
-
- }
-
- /**
- * This class enables the use of the log messages as a way of testing
- * the number of files actually transferred.
- * It uses the ant regular expression mechanism to get a regex parser
- * to parse the log output.
- */
- private class CountLogListener extends DefaultLogger {
- private Vector lastMatchGroups = null;
- private RegexpMatcher matcher = new RegexpMatcherFactory().newRegexpMatcher();
-
- /**
- * The only constructor for a CountLogListener
- * @param pattern a regular expression pattern. It should have
- * one parenthesized group and that group should contain the
- * number desired.
- */
- public CountLogListener(String pattern) {
- super();
- this.matcher.setPattern(pattern);
- }
-
-
- /*
- * @param event the build event that is being logged.
- */
- public void messageLogged(BuildEvent event) {
- String message = event.getMessage();
- if (this.matcher.matches(message)) {
- lastMatchGroups = this.matcher.getGroups(message);
- }
- super.messageLogged(event);
- }
-
- /**
- * returns the desired number that results from parsing the log
- * message
- * @return the number of files indicated in the desired message or -1
- * if a matching log message was never found.
- */
- public int getCount() {
- if (this.lastMatchGroups == null) {
- return -1;
- }
- return Integer.parseInt((String) this.lastMatchGroups.get(1));
- }
- }
-
- /**
- * This class enables the use of the log to count the number
- * of times a message has been emitted.
- */
- private class LogCounter extends DefaultLogger {
- private Map searchMap = new HashMap();
- private int matchCount;
-
- public void addLogMessageToSearch(String message) {
- searchMap.put(message, new Integer(0));
- }
-
- /*
- * @param event the build event that is being logged.
- */
- public void messageLogged(BuildEvent event) {
- String message = event.getMessage();
- Integer mcnt = (Integer) searchMap.get(message);
- if (null != mcnt) {
- searchMap.put(message, new Integer(mcnt.intValue() + 1));
- }
- super.messageLogged(event);
- }
-
- /**
- * @return the number of times that the looked for message was sent
- * to the log
- */
- public int getMatchCount(String message) {
- Integer mcnt = (Integer) searchMap.get(message);
- if (null != mcnt) {
- return mcnt.intValue();
- }
- return 0;
- }
- }
- /**
- * Tests the combination of the newer parameter and the
- * serverTimezoneConfig parameter in the PUT action. The default
- * configuration is an ftp server on localhost which formats
- * timestamps as GMT.
- */
- @Test
- public void testTimezonePut() {
- CountLogListener log = new CountLogListener("(\\d+) files? sent");
- buildRule.getProject().executeTarget("timed.test.setup");
- buildRule.getProject().addBuildListener(log);
- buildRule.getProject().executeTarget("timed.test.put.older");
- assertEquals(1, log.getCount());
- }
-
- /**
- * Tests the combination of the newer parameter and the
- * serverTimezoneConfig parameter in the GET action. The default
- * configuration is an ftp server on localhost which formats
- * timestamps as GMT.
- */
- @Test
- public void testTimezoneGet() {
- CountLogListener log = new CountLogListener("(\\d+) files? retrieved");
- buildRule.getProject().executeTarget("timed.test.setup");
- buildRule.getProject().addBuildListener(log);
- buildRule.getProject().executeTarget("timed.test.get.older");
- assertEquals(3, log.getCount());
- }
-
-
- /**
- * Tests that the presence of one of the server config params forces
- * the system type to Unix if not specified.
- */
- @Test
- public void testConfiguration1() {
- int[] expectedCounts = {
- 1,1,0,1,0,0,0
- };
- performConfigTest("configuration.1", expectedCounts);
-
- }
-
- /**
- * Tests the systemTypeKey attribute.
- */
- @Test
- public void testConfiguration2() {
- int[] expectedCounts = {
- 1,0,0,1,1,0,0
- };
- performConfigTest("configuration.2", expectedCounts);
-
- }
-
- /**
- * Tests the systemTypeKey attribute with UNIX specified.
- */
- @Test
- public void testConfiguration3() {
- int[] expectedCounts = {
- 1,0,1,0,0,1,0
- };
- performConfigTest("configuration.3", expectedCounts);
-
- }
-
- @Test
- public void testConfigurationLang() {
- int[] expectedCounts = {
- 1,1,0,0,0,0,1
- };
- performConfigTest("configuration.lang.good", expectedCounts);
-
- try {
- performConfigTest("configuration.lang.bad", expectedCounts);
- fail("BuildException Expected");
- } catch (Exception bx) {
- assertTrue(bx instanceof BuildException);
- }
- }
- /**
- * Tests the systemTypeKey attribute.
- */
- @Test
- public void testConfigurationNone() {
- int[] expectedCounts = {
- 0,0,0,0,0,0,0
- };
- performConfigTest("configuration.none", expectedCounts);
-
- }
-
- private void performConfigTest(String target, int[] expectedCounts) {
- String[] messages = new String[]{
- "custom configuration",
- "custom config: system key = default (UNIX)",
- "custom config: system key = UNIX",
- "custom config: server time zone ID = " + buildRule.getProject().getProperty("ftp.server.timezone"),
- "custom config: system key = WINDOWS",
- "custom config: default date format = yyyy/MM/dd HH:mm",
- "custom config: server language code = de"
-
- };
- LogCounter counter = new LogCounter();
- for (int i=0; i < messages.length; i++) {
- counter.addLogMessageToSearch(messages[i]);
- }
-
- buildRule.getProject().addBuildListener(counter);
- buildRule.getProject().executeTarget(target);
- for (int i=0; i < messages.length; i++) {
- assertEquals("target "+target+":message "+ i, expectedCounts[i], counter.getMatchCount(messages[i]));
- }
-
- }
-
-
- /**
- * this test is inspired by a user reporting that deletions of directories with the ftp task do not work
- */
- @Test
- public void testFTPDelete() {
- buildRule.getProject().executeTarget("ftp-delete");
- }
-
- private void compareFiles(DirectoryScanner ds, String[] expectedFiles,
- String[] expectedDirectories) {
- String includedFiles[] = ds.getIncludedFiles();
- String includedDirectories[] = ds.getIncludedDirectories();
- assertEquals("file present: ", expectedFiles.length,
- includedFiles.length);
- assertEquals("directories present: ", expectedDirectories.length,
- includedDirectories.length);
-
- for (int counter=0; counter < includedFiles.length; counter++) {
- includedFiles[counter] = includedFiles[counter].replace(File.separatorChar, '/');
- }
- Arrays.sort(includedFiles);
- for (int counter=0; counter < includedDirectories.length; counter++) {
- includedDirectories[counter] = includedDirectories[counter]
- .replace(File.separatorChar, '/');
- }
- Arrays.sort(includedDirectories);
- for (int counter=0; counter < includedFiles.length; counter++) {
- assertEquals(expectedFiles[counter], includedFiles[counter]);
- }
- for (int counter=0; counter < includedDirectories.length; counter++) {
- assertEquals(expectedDirectories[counter], includedDirectories[counter]);
- counter++;
- }
- }
- private static class myFTP extends FTP {
- public FTP.FTPDirectoryScanner newScanner(FTPClient client) {
- return new FTP.FTPDirectoryScanner(client);
- }
- // provide public visibility
- public String resolveFile(String file) {
- return super.resolveFile(file);
- }
- }
-
-
- public abstract static class myRetryableFTP extends FTP {
- private final int numberOfFailuresToSimulate;
- private int simulatedFailuresLeft;
-
- protected myRetryableFTP(int numberOfFailuresToSimulate) {
- this.numberOfFailuresToSimulate = numberOfFailuresToSimulate;
- this.simulatedFailuresLeft = numberOfFailuresToSimulate;
- }
-
- protected void getFile(FTPClient ftp, String dir, String filename)
- throws IOException, BuildException
- {
- if (this.simulatedFailuresLeft > 0) {
- this.simulatedFailuresLeft--;
- throw new IOException("Simulated failure for testing");
- }
- super.getFile(ftp, dir, filename);
- }
- protected void executeRetryable(RetryHandler h, Retryable r,
- String filename) throws IOException
- {
- this.simulatedFailuresLeft = this.numberOfFailuresToSimulate;
- super.executeRetryable(h, r, filename);
- }
- }
- public static class oneFailureFTP extends myRetryableFTP {
- public oneFailureFTP() {
- super(1);
- }
- }
- public static class twoFailureFTP extends myRetryableFTP {
- public twoFailureFTP() {
- super(2);
- }
- }
- public static class threeFailureFTP extends myRetryableFTP {
- public threeFailureFTP() {
- super(3);
- }
- }
-
- public static class randomFailureFTP extends myRetryableFTP {
- public randomFailureFTP() {
- super(new Random().nextInt(Short.MAX_VALUE));
- }
- }
- public void testGetWithSelectorRetryable1() {
- buildRule.getProject().addTaskDefinition("ftp", oneFailureFTP.class);
- try {
- buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
- } catch (BuildException bx) {
- fail("Two retries expected, failed after one.");
- }
- }
-
- @Test
- public void testGetWithSelectorRetryable2() {
- buildRule.getProject().addTaskDefinition("ftp", twoFailureFTP.class);
- try {
- buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
- } catch (BuildException bx) {
- fail("Two retries expected, failed after two.");
- }
- }
-
- @Test
- public void testGetWithSelectorRetryable3() {
- buildRule.getProject().addTaskDefinition("ftp", threeFailureFTP.class);
- try {
- buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
- fail("Two retries expected, continued after two.");
- } catch (BuildException bx) {
- }
- }
-
- @Test
- public void testGetWithSelectorRetryableRandom() {
- buildRule.getProject().addTaskDefinition("ftp", randomFailureFTP.class);
- try {
- buildRule.getProject().setProperty("ftp.retries", "forever");
- buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
- } catch (BuildException bx) {
- fail("Retry forever specified, but failed.");
- }
- }
-
- @Test
- public void testInitialCommand() {
- performCommandTest("test-initial-command", new int[] { 1,0 });
- }
-
- @Test
- public void testSiteAction() {
- performCommandTest("test-site-action", new int[] { 1,0 });
- }
-
- private void performCommandTest(String target, int[] expectedCounts) {
- String[] messages = new String[]{
- "Doing Site Command: umask 222",
- "Failed to issue Site Command: umask 222",
-
- };
- LogCounter counter = new LogCounter();
- for (int i=0; i < messages.length; i++) {
- counter.addLogMessageToSearch(messages[i]);
- }
-
- buildRule.getProject().addBuildListener(counter);
- buildRule.getProject().executeTarget(target);
- for (int i=0; i < messages.length; i++) {
- assertEquals("target "+target+":message "+ i, expectedCounts[i], counter.getMatchCount(messages[i]));
- }
-
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.net;
+
+import static org.apache.tools.ant.AntAssert.assertContains;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.Random;
+import java.util.Vector;
+
+import org.apache.commons.net.ftp.FTPClient;
+import org.apache.tools.ant.BuildEvent;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.DefaultLogger;
+import org.apache.tools.ant.DirectoryScanner;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.condition.Os;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.util.RetryHandler;
+import org.apache.tools.ant.util.Retryable;
+import org.apache.tools.ant.util.regexp.RegexpMatcher;
+import org.apache.tools.ant.util.regexp.RegexpMatcherFactory;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+//FIXME these tests are more integration than unit tests and report errors badly
+public class FTPTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ // keep track of what operating systems are supported here.
+ private boolean supportsSymlinks = Os.isFamily("unix");
+
+ private FTPClient ftp;
+
+ private boolean loginSuceeded = false;
+
+ private String loginFailureMessage;
+
+ private String tmpDir = null;
+ private String remoteTmpDir = null;
+ private String ftpFileSep = null;
+ private myFTP myFTPTask = new myFTP();
+
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/net/ftp.xml");
+ Project project = buildRule.getProject();
+ project.executeTarget("setup");
+ tmpDir = project.getProperty("tmp.dir");
+ ftp = new FTPClient();
+ ftpFileSep = project.getProperty("ftp.filesep");
+ myFTPTask.setSeparator(ftpFileSep);
+ myFTPTask.setProject(project);
+ remoteTmpDir = myFTPTask.resolveFile(tmpDir);
+ String remoteHost = project.getProperty("ftp.host");
+ int port = Integer.parseInt(project.getProperty("ftp.port"));
+ String remoteUser = project.getProperty("ftp.user");
+ String password = project.getProperty("ftp.password");
+ boolean connectionSucceeded = false;
+ try {
+ ftp.connect(remoteHost, port);
+ connectionSucceeded = true;
+ } catch (Exception ex) {
+ loginFailureMessage = "could not connect to host " + remoteHost + " on port " + port;
+ }
+ if (connectionSucceeded) {
+ try {
+ ftp.login(remoteUser, password);
+ loginSuceeded = true;
+ } catch (IOException ioe) {
+ loginFailureMessage = "could not log on to " + remoteHost + " as user " + remoteUser;
+ }
+ }
+ }
+
+ @After
+ public void tearDown() {
+ try {
+ if (ftp!= null) {
+ ftp.disconnect();
+ }
+ } catch (IOException ioe) {
+ // do nothing
+ }
+ buildRule.getProject().executeTarget("cleanup");
+ }
+
+ private boolean changeRemoteDir(String remoteDir) {
+ boolean result = true;
+ try {
+ ftp.cwd(remoteDir);
+ }
+ catch (Exception ex) {
+ System.out.println("could not change directory to " + remoteTmpDir);
+ result = false;
+ }
+ return result;
+ }
+
+ @Test
+ public void test1() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha"});
+ ds.scan();
+ compareFiles(ds, new String[] {} ,new String[] {"alpha"});
+ }
+
+ @Test
+ public void test2() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha/"});
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/beta.xml",
+ "alpha/beta/gamma/gamma.xml"},
+ new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
+ }
+
+ @Test
+ public void test3() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/beta.xml",
+ "alpha/beta/gamma/gamma.xml"},
+ new String[] {"alpha", "alpha/beta",
+ "alpha/beta/gamma"});
+ }
+
+ @Test
+ public void testFullPathMatchesCaseSensitive() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"});
+ ds.scan();
+ compareFiles(ds, new String[] {}, new String[] {});
+ }
+
+ @Test
+ public void testFullPathMatchesCaseInsensitive() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setCaseSensitive(false);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha/beta/gamma/GAMMA.XML"});
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
+ new String[] {});
+ }
+
+ @Test
+ public void test2ButCaseInsensitive() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"ALPHA/"});
+ ds.setCaseSensitive(false);
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/beta.xml",
+ "alpha/beta/gamma/gamma.xml"},
+ new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
+ }
+
+ @Test
+ public void test2bisButCaseInsensitive() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha/BETA/gamma/"});
+ ds.setCaseSensitive(false);
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
+ new String[] {"alpha/beta/gamma"});
+ }
+
+ @Test
+ public void testGetWithSelector() {
+ buildRule.executeTarget("ftp-get-with-selector");
+ assertContains("selectors are not supported in remote filesets", buildRule.getLog());
+ FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector");
+ DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject());
+ dsDestination.scan();
+ String [] sortedDestinationDirectories = dsDestination.getIncludedDirectories();
+ String [] sortedDestinationFiles = dsDestination.getIncludedFiles();
+ for (int counter = 0; counter < sortedDestinationDirectories.length; counter++) {
+ sortedDestinationDirectories[counter] =
+ sortedDestinationDirectories[counter].replace(File.separatorChar, '/');
+ }
+ for (int counter = 0; counter < sortedDestinationFiles.length; counter++) {
+ sortedDestinationFiles[counter] =
+ sortedDestinationFiles[counter].replace(File.separatorChar, '/');
+ }
+ FileSet fsSource = (FileSet) buildRule.getProject().getReference("fileset-source-without-selector");
+ DirectoryScanner dsSource = fsSource.getDirectoryScanner(buildRule.getProject());
+ dsSource.scan();
+ compareFiles(dsSource, sortedDestinationFiles, sortedDestinationDirectories);
+ }
+
+ @Test
+ public void testGetFollowSymlinksTrue() {
+ Assume.assumeTrue("System does not support Symlinks", supportsSymlinks);
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ buildRule.getProject().executeTarget("ftp-get-directory-symbolic-link");
+ FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector");
+ DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject());
+ dsDestination.scan();
+ compareFiles(dsDestination, new String[] {"alpha/beta/gamma/gamma.xml"},
+ new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
+ }
+
+ @Test
+ public void testGetFollowSymlinksFalse() {
+ Assume.assumeTrue("System does not support Symlinks", supportsSymlinks);
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ buildRule.getProject().executeTarget("ftp-get-directory-no-symbolic-link");
+ FileSet fsDestination = (FileSet) buildRule.getProject().getReference("fileset-destination-without-selector");
+ DirectoryScanner dsDestination = fsDestination.getDirectoryScanner(buildRule.getProject());
+ dsDestination.scan();
+ compareFiles(dsDestination, new String[] {},
+ new String[] {});
+ }
+
+ @Test
+ public void testAllowSymlinks() {
+ Assume.assumeTrue("System does not support Symlinks", supportsSymlinks);
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ buildRule.getProject().executeTarget("symlink-setup");
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha/beta/gamma/"});
+ ds.setFollowSymlinks(true);
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
+ new String[] {"alpha/beta/gamma"});
+ }
+
+ @Test
+ public void testProhibitSymlinks() {
+ Assume.assumeTrue("System does not support Symlinks", supportsSymlinks);
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ buildRule.getProject().executeTarget("symlink-setup");
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha/beta/gamma/"});
+ ds.setFollowSymlinks(false);
+ ds.scan();
+ compareFiles(ds, new String[] {}, new String[] {});
+ }
+
+ @Test
+ public void testFileSymlink() {
+ Assume.assumeTrue("System does not support Symlinks", supportsSymlinks);
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ buildRule.getProject().executeTarget("symlink-file-setup");
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha/beta/gamma/"});
+ ds.setFollowSymlinks(true);
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
+ new String[] {"alpha/beta/gamma"});
+ }
+
+ // father and child pattern test
+ @Test
+ public void testOrderOfIncludePatternsIrrelevant() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ String [] expectedFiles = {"alpha/beta/beta.xml",
+ "alpha/beta/gamma/gamma.xml"};
+ String [] expectedDirectories = {"alpha/beta", "alpha/beta/gamma" };
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha/be?a/**", "alpha/beta/gamma/"});
+ ds.scan();
+ compareFiles(ds, expectedFiles, expectedDirectories);
+ // redo the test, but the 2 include patterns are inverted
+ ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha/beta/gamma/", "alpha/be?a/**"});
+ ds.scan();
+ compareFiles(ds, expectedFiles, expectedDirectories);
+ }
+
+ @Test
+ public void testPatternsDifferInCaseScanningSensitive() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha/", "ALPHA/"});
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/beta.xml",
+ "alpha/beta/gamma/gamma.xml"},
+ new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
+ }
+
+ @Test
+ public void testPatternsDifferInCaseScanningInsensitive() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha/", "ALPHA/"});
+ ds.setCaseSensitive(false);
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/beta.xml",
+ "alpha/beta/gamma/gamma.xml"},
+ new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
+ }
+
+ @Test
+ public void testFullpathDiffersInCaseScanningSensitive() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {
+ "alpha/beta/gamma/gamma.xml",
+ "alpha/beta/gamma/GAMMA.XML"
+ });
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
+ new String[] {});
+ }
+
+ @Test
+ public void testFullpathDiffersInCaseScanningInsensitive() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {
+ "alpha/beta/gamma/gamma.xml",
+ "alpha/beta/gamma/GAMMA.XML"
+ });
+ ds.setCaseSensitive(false);
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
+ new String[] {});
+ }
+
+ @Test
+ public void testParentDiffersInCaseScanningSensitive() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha/", "ALPHA/beta/"});
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/beta.xml",
+ "alpha/beta/gamma/gamma.xml"},
+ new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
+ }
+
+ @Test
+ public void testParentDiffersInCaseScanningInsensitive() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {"alpha/", "ALPHA/beta/"});
+ ds.setCaseSensitive(false);
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/beta.xml",
+ "alpha/beta/gamma/gamma.xml"},
+ new String[] {"alpha", "alpha/beta", "alpha/beta/gamma"});
+ }
+
+ @Test
+ public void testExcludeOneFile() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {
+ "**/*.xml"
+ });
+ ds.setExcludes(new String[] {
+ "alpha/beta/b*xml"
+ });
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/gamma/gamma.xml"},
+ new String[] {});
+ }
+
+ @Test
+ public void testExcludeHasPrecedence() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {
+ "alpha/**"
+ });
+ ds.setExcludes(new String[] {
+ "alpha/**"
+ });
+ ds.scan();
+ compareFiles(ds, new String[] {},
+ new String[] {});
+
+ }
+
+ @Test
+ public void testAlternateIncludeExclude() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setIncludes(new String[] {
+ "alpha/**",
+ "alpha/beta/gamma/**"
+ });
+ ds.setExcludes(new String[] {
+ "alpha/beta/**"
+ });
+ ds.scan();
+ compareFiles(ds, new String[] {},
+ new String[] {"alpha"});
+
+ }
+
+ @Test
+ public void testAlternateExcludeInclude() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setExcludes(new String[] {
+ "alpha/**",
+ "alpha/beta/gamma/**"
+ });
+ ds.setIncludes(new String[] {
+ "alpha/beta/**"
+ });
+ ds.scan();
+ compareFiles(ds, new String[] {},
+ new String[] {});
+
+ }
+
+ /**
+ * Test inspired by Bug#1415.
+ */
+ @Test
+ public void testChildrenOfExcludedDirectory() {
+ Assume.assumeTrue(loginFailureMessage, loginSuceeded);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ buildRule.getProject().executeTarget("children-of-excluded-dir-setup");
+ FTP.FTPDirectoryScanner ds = myFTPTask.newScanner(ftp);
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setExcludes(new String[] {"alpha/**"});
+ ds.scan();
+ compareFiles(ds, new String[] {"delta/delta.xml"},
+ new String[] {"delta"});
+
+ ds = myFTPTask.newScanner(ftp);
+ Assume.assumeTrue("Could not change remote directory", changeRemoteDir(remoteTmpDir));
+ ds.setBasedir(new File(buildRule.getProject().getBaseDir(), "tmp"));
+ ds.setExcludes(new String[] {"alpha"});
+ ds.scan();
+ compareFiles(ds, new String[] {"alpha/beta/beta.xml",
+ "alpha/beta/gamma/gamma.xml",
+ "delta/delta.xml"},
+ new String[] {"alpha/beta", "alpha/beta/gamma", "delta"});
+
+ }
+
+ /**
+ * This class enables the use of the log messages as a way of testing
+ * the number of files actually transferred.
+ * It uses the ant regular expression mechanism to get a regex parser
+ * to parse the log output.
+ */
+ private class CountLogListener extends DefaultLogger {
+ private Vector lastMatchGroups = null;
+ private RegexpMatcher matcher = new RegexpMatcherFactory().newRegexpMatcher();
+
+ /**
+ * The only constructor for a CountLogListener
+ * @param pattern a regular expression pattern. It should have
+ * one parenthesized group and that group should contain the
+ * number desired.
+ */
+ public CountLogListener(String pattern) {
+ super();
+ this.matcher.setPattern(pattern);
+ }
+
+
+ /*
+ * @param event the build event that is being logged.
+ */
+ public void messageLogged(BuildEvent event) {
+ String message = event.getMessage();
+ if (this.matcher.matches(message)) {
+ lastMatchGroups = this.matcher.getGroups(message);
+ }
+ super.messageLogged(event);
+ }
+
+ /**
+ * returns the desired number that results from parsing the log
+ * message
+ * @return the number of files indicated in the desired message or -1
+ * if a matching log message was never found.
+ */
+ public int getCount() {
+ if (this.lastMatchGroups == null) {
+ return -1;
+ }
+ return Integer.parseInt((String) this.lastMatchGroups.get(1));
+ }
+ }
+
+ /**
+ * This class enables the use of the log to count the number
+ * of times a message has been emitted.
+ */
+ private class LogCounter extends DefaultLogger {
+ private Map searchMap = new HashMap();
+ private int matchCount;
+
+ public void addLogMessageToSearch(String message) {
+ searchMap.put(message, new Integer(0));
+ }
+
+ /*
+ * @param event the build event that is being logged.
+ */
+ public void messageLogged(BuildEvent event) {
+ String message = event.getMessage();
+ Integer mcnt = (Integer) searchMap.get(message);
+ if (null != mcnt) {
+ searchMap.put(message, new Integer(mcnt.intValue() + 1));
+ }
+ super.messageLogged(event);
+ }
+
+ /**
+ * @return the number of times that the looked for message was sent
+ * to the log
+ */
+ public int getMatchCount(String message) {
+ Integer mcnt = (Integer) searchMap.get(message);
+ if (null != mcnt) {
+ return mcnt.intValue();
+ }
+ return 0;
+ }
+ }
+ /**
+ * Tests the combination of the newer parameter and the
+ * serverTimezoneConfig parameter in the PUT action. The default
+ * configuration is an ftp server on localhost which formats
+ * timestamps as GMT.
+ */
+ @Test
+ public void testTimezonePut() {
+ CountLogListener log = new CountLogListener("(\\d+) files? sent");
+ buildRule.getProject().executeTarget("timed.test.setup");
+ buildRule.getProject().addBuildListener(log);
+ buildRule.getProject().executeTarget("timed.test.put.older");
+ assertEquals(1, log.getCount());
+ }
+
+ /**
+ * Tests the combination of the newer parameter and the
+ * serverTimezoneConfig parameter in the GET action. The default
+ * configuration is an ftp server on localhost which formats
+ * timestamps as GMT.
+ */
+ @Test
+ public void testTimezoneGet() {
+ CountLogListener log = new CountLogListener("(\\d+) files? retrieved");
+ buildRule.getProject().executeTarget("timed.test.setup");
+ buildRule.getProject().addBuildListener(log);
+ buildRule.getProject().executeTarget("timed.test.get.older");
+ assertEquals(3, log.getCount());
+ }
+
+
+ /**
+ * Tests that the presence of one of the server config params forces
+ * the system type to Unix if not specified.
+ */
+ @Test
+ public void testConfiguration1() {
+ int[] expectedCounts = {
+ 1,1,0,1,0,0,0
+ };
+ performConfigTest("configuration.1", expectedCounts);
+
+ }
+
+ /**
+ * Tests the systemTypeKey attribute.
+ */
+ @Test
+ public void testConfiguration2() {
+ int[] expectedCounts = {
+ 1,0,0,1,1,0,0
+ };
+ performConfigTest("configuration.2", expectedCounts);
+
+ }
+
+ /**
+ * Tests the systemTypeKey attribute with UNIX specified.
+ */
+ @Test
+ public void testConfiguration3() {
+ int[] expectedCounts = {
+ 1,0,1,0,0,1,0
+ };
+ performConfigTest("configuration.3", expectedCounts);
+
+ }
+
+ @Test
+ public void testConfigurationLang() {
+ int[] expectedCounts = {
+ 1,1,0,0,0,0,1
+ };
+ performConfigTest("configuration.lang.good", expectedCounts);
+
+ try {
+ performConfigTest("configuration.lang.bad", expectedCounts);
+ fail("BuildException Expected");
+ } catch (Exception bx) {
+ assertTrue(bx instanceof BuildException);
+ }
+ }
+ /**
+ * Tests the systemTypeKey attribute.
+ */
+ @Test
+ public void testConfigurationNone() {
+ int[] expectedCounts = {
+ 0,0,0,0,0,0,0
+ };
+ performConfigTest("configuration.none", expectedCounts);
+
+ }
+
+ private void performConfigTest(String target, int[] expectedCounts) {
+ String[] messages = new String[]{
+ "custom configuration",
+ "custom config: system key = default (UNIX)",
+ "custom config: system key = UNIX",
+ "custom config: server time zone ID = " + buildRule.getProject().getProperty("ftp.server.timezone"),
+ "custom config: system key = WINDOWS",
+ "custom config: default date format = yyyy/MM/dd HH:mm",
+ "custom config: server language code = de"
+
+ };
+ LogCounter counter = new LogCounter();
+ for (int i=0; i < messages.length; i++) {
+ counter.addLogMessageToSearch(messages[i]);
+ }
+
+ buildRule.getProject().addBuildListener(counter);
+ buildRule.getProject().executeTarget(target);
+ for (int i=0; i < messages.length; i++) {
+ assertEquals("target "+target+":message "+ i, expectedCounts[i], counter.getMatchCount(messages[i]));
+ }
+
+ }
+
+
+ /**
+ * this test is inspired by a user reporting that deletions of directories with the ftp task do not work
+ */
+ @Test
+ public void testFTPDelete() {
+ buildRule.getProject().executeTarget("ftp-delete");
+ }
+
+ private void compareFiles(DirectoryScanner ds, String[] expectedFiles,
+ String[] expectedDirectories) {
+ String includedFiles[] = ds.getIncludedFiles();
+ String includedDirectories[] = ds.getIncludedDirectories();
+ assertEquals("file present: ", expectedFiles.length,
+ includedFiles.length);
+ assertEquals("directories present: ", expectedDirectories.length,
+ includedDirectories.length);
+
+ for (int counter=0; counter < includedFiles.length; counter++) {
+ includedFiles[counter] = includedFiles[counter].replace(File.separatorChar, '/');
+ }
+ Arrays.sort(includedFiles);
+ for (int counter=0; counter < includedDirectories.length; counter++) {
+ includedDirectories[counter] = includedDirectories[counter]
+ .replace(File.separatorChar, '/');
+ }
+ Arrays.sort(includedDirectories);
+ for (int counter=0; counter < includedFiles.length; counter++) {
+ assertEquals(expectedFiles[counter], includedFiles[counter]);
+ }
+ for (int counter=0; counter < includedDirectories.length; counter++) {
+ assertEquals(expectedDirectories[counter], includedDirectories[counter]);
+ counter++;
+ }
+ }
+ private static class myFTP extends FTP {
+ public FTP.FTPDirectoryScanner newScanner(FTPClient client) {
+ return new FTP.FTPDirectoryScanner(client);
+ }
+ // provide public visibility
+ public String resolveFile(String file) {
+ return super.resolveFile(file);
+ }
+ }
+
+
+ public abstract static class myRetryableFTP extends FTP {
+ private final int numberOfFailuresToSimulate;
+ private int simulatedFailuresLeft;
+
+ protected myRetryableFTP(int numberOfFailuresToSimulate) {
+ this.numberOfFailuresToSimulate = numberOfFailuresToSimulate;
+ this.simulatedFailuresLeft = numberOfFailuresToSimulate;
+ }
+
+ protected void getFile(FTPClient ftp, String dir, String filename)
+ throws IOException, BuildException
+ {
+ if (this.simulatedFailuresLeft > 0) {
+ this.simulatedFailuresLeft--;
+ throw new IOException("Simulated failure for testing");
+ }
+ super.getFile(ftp, dir, filename);
+ }
+ protected void executeRetryable(RetryHandler h, Retryable r,
+ String filename) throws IOException
+ {
+ this.simulatedFailuresLeft = this.numberOfFailuresToSimulate;
+ super.executeRetryable(h, r, filename);
+ }
+ }
+ public static class oneFailureFTP extends myRetryableFTP {
+ public oneFailureFTP() {
+ super(1);
+ }
+ }
+ public static class twoFailureFTP extends myRetryableFTP {
+ public twoFailureFTP() {
+ super(2);
+ }
+ }
+ public static class threeFailureFTP extends myRetryableFTP {
+ public threeFailureFTP() {
+ super(3);
+ }
+ }
+
+ public static class randomFailureFTP extends myRetryableFTP {
+ public randomFailureFTP() {
+ super(new Random().nextInt(Short.MAX_VALUE));
+ }
+ }
+ public void testGetWithSelectorRetryable1() {
+ buildRule.getProject().addTaskDefinition("ftp", oneFailureFTP.class);
+ try {
+ buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
+ } catch (BuildException bx) {
+ fail("Two retries expected, failed after one.");
+ }
+ }
+
+ @Test
+ public void testGetWithSelectorRetryable2() {
+ buildRule.getProject().addTaskDefinition("ftp", twoFailureFTP.class);
+ try {
+ buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
+ } catch (BuildException bx) {
+ fail("Two retries expected, failed after two.");
+ }
+ }
+
+ @Test
+ public void testGetWithSelectorRetryable3() {
+ buildRule.getProject().addTaskDefinition("ftp", threeFailureFTP.class);
+ try {
+ buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
+ fail("Two retries expected, continued after two.");
+ } catch (BuildException bx) {
+ }
+ }
+
+ @Test
+ public void testGetWithSelectorRetryableRandom() {
+ buildRule.getProject().addTaskDefinition("ftp", randomFailureFTP.class);
+ try {
+ buildRule.getProject().setProperty("ftp.retries", "forever");
+ buildRule.getProject().executeTarget("ftp-get-with-selector-retryable");
+ } catch (BuildException bx) {
+ fail("Retry forever specified, but failed.");
+ }
+ }
+
+ @Test
+ public void testInitialCommand() {
+ performCommandTest("test-initial-command", new int[] { 1,0 });
+ }
+
+ @Test
+ public void testSiteAction() {
+ performCommandTest("test-site-action", new int[] { 1,0 });
+ }
+
+ private void performCommandTest(String target, int[] expectedCounts) {
+ String[] messages = new String[]{
+ "Doing Site Command: umask 222",
+ "Failed to issue Site Command: umask 222",
+
+ };
+ LogCounter counter = new LogCounter();
+ for (int i=0; i < messages.length; i++) {
+ counter.addLogMessageToSearch(messages[i]);
+ }
+
+ buildRule.getProject().addBuildListener(counter);
+ buildRule.getProject().executeTarget(target);
+ for (int i=0; i < messages.length; i++) {
+ assertEquals("target "+target+":message "+ i, expectedCounts[i], counter.getMatchCount(messages[i]));
+ }
+
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
index 5d4d4cf61..77c7036bc 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/script/ScriptDefTest.java
@@ -1,146 +1,146 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional.script;
-
-import org.apache.tools.ant.AntAssert;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.types.FileSet;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import java.io.File;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * Tests the examples of the <scriptdef> task.
- *
- * @since Ant 1.6
- */
-public class ScriptDefTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/script/scriptdef.xml");
- }
-
- @Test
- public void testSimple() {
- buildRule.executeTarget("simple");
- // get the fileset and its basedir
- Project p = buildRule.getProject();
- FileSet fileset = (FileSet) p.getReference("testfileset");
- File baseDir = fileset.getDir(p);
- String log = buildRule.getLog();
- assertTrue("Expecting attribute value printed",
- log.indexOf("Attribute attr1 = test") != -1);
-
- assertTrue("Expecting nested element value printed",
- log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1);
- }
-
- @Test
- public void testNoLang() {
- try {
- buildRule.executeTarget("nolang");
- fail("Absence of language attribute not detected");
- } catch(BuildException ex) {
- AntAssert.assertContains("requires a language attribute", ex.getMessage());
- }
- }
-
- @Test
- public void testNoName() {
- try {
- buildRule.executeTarget("noname");
- fail("Absence of name attribute not detected");
- } catch(BuildException ex) {
- AntAssert.assertContains("scriptdef requires a name attribute", ex.getMessage());
- }
- }
-
- @Test
- public void testNestedByClassName() {
- buildRule.executeTarget("nestedbyclassname");
- // get the fileset and its basedir
- Project p = buildRule.getProject();
- FileSet fileset = (FileSet) p.getReference("testfileset");
- File baseDir = fileset.getDir(p);
- String log = buildRule.getLog();
- assertTrue("Expecting attribute value to be printed",
- log.indexOf("Attribute attr1 = test") != -1);
-
- assertTrue("Expecting nested element value to be printed",
- log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1);
- }
-
- @Test
- public void testNoElement() {
- buildRule.executeTarget("noelement");
- assertEquals("Attribute attr1 = test", buildRule.getOutput().trim());
- }
-
- @Test
- public void testException() {
- try {
- buildRule.executeTarget("exception");
- fail("Should have thrown an exception in the script");
- } catch(BuildException ex) {
- AntAssert.assertContains("TypeError", ex.getMessage());
- }
- }
-
- @Test
- public void testDoubleDef() {
- buildRule.executeTarget("doubledef");
- String log = buildRule.getLog();
- assertTrue("Task1 did not execute",
- log.indexOf("Task1") != -1);
- assertTrue("Task2 did not execute",
- log.indexOf("Task2") != -1);
- }
-
- @Test
- public void testDoubleAttribute() {
- try {
- buildRule.executeTarget("doubleAttributeDef");
- fail("Should have detected duplicate attirbute definition");
- } catch(BuildException ex) {
- AntAssert.assertContains("attr1 attribute more than once", ex.getMessage());
- }
- }
-
- @Test
- public void testProperty() {
- buildRule.executeTarget("property");
- // get the fileset and its basedir
- String log = buildRule.getLog();
- assertTrue("Expecting property in attribute value replaced",
- log.indexOf("Attribute value = test") != -1);
- }
-
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.script;
+
+import org.apache.tools.ant.AntAssert;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.FileSet;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests the examples of the <scriptdef> task.
+ *
+ * @since Ant 1.6
+ */
+public class ScriptDefTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/script/scriptdef.xml");
+ }
+
+ @Test
+ public void testSimple() {
+ buildRule.executeTarget("simple");
+ // get the fileset and its basedir
+ Project p = buildRule.getProject();
+ FileSet fileset = (FileSet) p.getReference("testfileset");
+ File baseDir = fileset.getDir(p);
+ String log = buildRule.getLog();
+ assertTrue("Expecting attribute value printed",
+ log.indexOf("Attribute attr1 = test") != -1);
+
+ assertTrue("Expecting nested element value printed",
+ log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1);
+ }
+
+ @Test
+ public void testNoLang() {
+ try {
+ buildRule.executeTarget("nolang");
+ fail("Absence of language attribute not detected");
+ } catch(BuildException ex) {
+ AntAssert.assertContains("requires a language attribute", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testNoName() {
+ try {
+ buildRule.executeTarget("noname");
+ fail("Absence of name attribute not detected");
+ } catch(BuildException ex) {
+ AntAssert.assertContains("scriptdef requires a name attribute", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testNestedByClassName() {
+ buildRule.executeTarget("nestedbyclassname");
+ // get the fileset and its basedir
+ Project p = buildRule.getProject();
+ FileSet fileset = (FileSet) p.getReference("testfileset");
+ File baseDir = fileset.getDir(p);
+ String log = buildRule.getLog();
+ assertTrue("Expecting attribute value to be printed",
+ log.indexOf("Attribute attr1 = test") != -1);
+
+ assertTrue("Expecting nested element value to be printed",
+ log.indexOf("Fileset basedir = " + baseDir.getAbsolutePath()) != -1);
+ }
+
+ @Test
+ public void testNoElement() {
+ buildRule.executeTarget("noelement");
+ assertEquals("Attribute attr1 = test", buildRule.getOutput().trim());
+ }
+
+ @Test
+ public void testException() {
+ try {
+ buildRule.executeTarget("exception");
+ fail("Should have thrown an exception in the script");
+ } catch(BuildException ex) {
+ AntAssert.assertContains("TypeError", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testDoubleDef() {
+ buildRule.executeTarget("doubledef");
+ String log = buildRule.getLog();
+ assertTrue("Task1 did not execute",
+ log.indexOf("Task1") != -1);
+ assertTrue("Task2 did not execute",
+ log.indexOf("Task2") != -1);
+ }
+
+ @Test
+ public void testDoubleAttribute() {
+ try {
+ buildRule.executeTarget("doubleAttributeDef");
+ fail("Should have detected duplicate attirbute definition");
+ } catch(BuildException ex) {
+ AntAssert.assertContains("attr1 attribute more than once", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testProperty() {
+ buildRule.executeTarget("property");
+ // get the fileset and its basedir
+ String log = buildRule.getLog();
+ assertTrue("Expecting property in attribute value replaced",
+ log.indexOf("Attribute value = test") != -1);
+ }
+
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java
index c45ec17e8..aebc9e270 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/sos/SOSTest.java
@@ -1,351 +1,351 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional.sos;
-
-import java.io.File;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.types.Commandline;
-import org.apache.tools.ant.types.Path;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-/**
- * Testcase to ensure that command line generation and required attributes are
- * correct.
- *
- */
-public class SOSTest {
-
- private Commandline commandline;
-
- private static final String VSS_SERVER_PATH = "\\\\server\\vss\\srcsafe.ini";
- private static final String VSS_PROJECT_PATH = "/SourceRoot/Project";
- private static final String DS_VSS_PROJECT_PATH = "$/SourceRoot/Project";
- private static final String SOS_SERVER_PATH = "192.168.0.1:8888";
- private static final String SOS_USERNAME = "ant";
- private static final String SOS_PASSWORD = "rocks";
- private static final String LOCAL_PATH = "testdir";
- private static final String SRC_FILE = "Class1.java";
- private static final String SRC_LABEL = "label1";
- private static final String SRC_COMMENT = "I fixed a bug";
- private static final String SOS_HOME = "/home/user/.sos";
- private static final String VERSION = "007";
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
- private Project project;
-
- @Before
- public void setUp() {
- project = new Project();
- project.init();
- project.setBasedir(".");
- }
-
- @After
- public void tearDown() {
- File file = new File(project.getBaseDir(), LOCAL_PATH);
- if (file.exists()) {
- file.delete();
- }
- }
-
- /** Test SOSGetFile flags & commandline generation */
- @Test
- public void testGetFileFlags() {
- String[] sTestCmdLine = {"soscmd", "-command", "GetFile", "-file",
- SRC_FILE, "-revision", "007", "-server", SOS_SERVER_PATH, "-name",
- SOS_USERNAME, "-password", SOS_PASSWORD, "-database", VSS_SERVER_PATH,
- "-project", DS_VSS_PROJECT_PATH, "-verbose", "-nocompress",
- "-nocache", "-workdir", project.getBaseDir().getAbsolutePath()
- + File.separator + LOCAL_PATH};
-
- // Set up a SOSGet task
- SOSGet sosGet = new SOSGet();
- sosGet.setProject(project);
- sosGet.setVssServerPath(VSS_SERVER_PATH);
- sosGet.setSosServerPath(SOS_SERVER_PATH);
- sosGet.setProjectPath(VSS_PROJECT_PATH);
- sosGet.setFile(SRC_FILE);
- sosGet.setUsername(SOS_USERNAME);
- sosGet.setPassword(SOS_PASSWORD);
- sosGet.setVersion(VERSION);
- sosGet.setLocalPath(new Path(project, LOCAL_PATH));
- sosGet.setNoCache(true);
- sosGet.setNoCompress(true);
- sosGet.setVerbose(true);
- sosGet.setRecursive(true);
-
- commandline = sosGet.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /** Test SOSGetProject flags & commandline generation */
- @Test
- public void testGetProjectFlags() {
- String[] sTestCmdLine = {"soscmd", "-command", "GetProject", "-recursive",
- "-label", SRC_LABEL, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
- "-password", "", "-database", VSS_SERVER_PATH, "-project",
- DS_VSS_PROJECT_PATH, "", "", "-soshome", SOS_HOME, "-workdir",
- project.getBaseDir().getAbsolutePath()};
-
- // Set up a SOSGet task
- SOSGet sosGet = new SOSGet();
- sosGet.setProject(project);
- sosGet.setVssServerPath(VSS_SERVER_PATH);
- sosGet.setSosServerPath(SOS_SERVER_PATH);
- sosGet.setProjectPath(DS_VSS_PROJECT_PATH);
- sosGet.setLabel(SRC_LABEL);
- sosGet.setUsername(SOS_USERNAME);
- sosGet.setSosHome(SOS_HOME);
- sosGet.setNoCache(true);
- sosGet.setNoCompress(false);
- sosGet.setVerbose(false);
- sosGet.setRecursive(true);
-
- commandline = sosGet.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /** Tests SOSGet required attributes. */
- @Test
- public void testGetExceptions() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
- expectSpecificBuildException("sosget.1", "some cause", "sosserverpath attribute must be set!");
- expectSpecificBuildException("sosget.2", "some cause", "username attribute must be set!");
- expectSpecificBuildException("sosget.3", "some cause", "vssserverpath attribute must be set!");
- expectSpecificBuildException("sosget.4", "some cause", "projectpath attribute must be set!");
- }
-
- /** Test CheckInFile option flags */
- @Test
- public void testCheckinFileFlags() {
- String[] sTestCmdLine = {"soscmd", "-command", "CheckInFile", "-file",
- SRC_FILE, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
- "-password", SOS_PASSWORD, "-database", VSS_SERVER_PATH, "-project",
- DS_VSS_PROJECT_PATH, "-verbose", "-nocompress", "-nocache",
- "-workdir", project.getBaseDir().getAbsolutePath() + File.separator
- + LOCAL_PATH, "-log", SRC_COMMENT};
-
- // Set up a SOSCheckin task
- SOSCheckin sosCheckin = new SOSCheckin();
- sosCheckin.setProject(project);
- sosCheckin.setVssServerPath(VSS_SERVER_PATH);
- sosCheckin.setSosServerPath(SOS_SERVER_PATH);
- sosCheckin.setProjectPath(VSS_PROJECT_PATH);
- sosCheckin.setFile(SRC_FILE);
- sosCheckin.setComment(SRC_COMMENT);
- sosCheckin.setUsername(SOS_USERNAME);
- sosCheckin.setPassword(SOS_PASSWORD);
- sosCheckin.setLocalPath(new Path(project, LOCAL_PATH));
- sosCheckin.setNoCache(true);
- sosCheckin.setNoCompress(true);
- sosCheckin.setVerbose(true);
- sosCheckin.setRecursive(true);
-
- commandline = sosCheckin.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /** Test CheckInProject option flags */
- @Test
- public void testCheckinProjectFlags() {
- String[] sTestCmdLine = {"soscmd", "-command", "CheckInProject",
- "-recursive", "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
- "-password", "", "-database", VSS_SERVER_PATH, "-project",
- DS_VSS_PROJECT_PATH, "", "", "-soshome", SOS_HOME, "-workdir",
- project.getBaseDir().getAbsolutePath(), "-log", SRC_COMMENT,};
-
- // Set up a SOSCheckin task
- SOSCheckin sosCheckin = new SOSCheckin();
- sosCheckin.setProject(project);
- sosCheckin.setVssServerPath(VSS_SERVER_PATH);
- sosCheckin.setSosServerPath(SOS_SERVER_PATH);
- sosCheckin.setProjectPath(DS_VSS_PROJECT_PATH);
- sosCheckin.setComment(SRC_COMMENT);
- sosCheckin.setUsername(SOS_USERNAME);
- sosCheckin.setSosHome(SOS_HOME);
- sosCheckin.setNoCache(true);
- sosCheckin.setNoCompress(false);
- sosCheckin.setVerbose(false);
- sosCheckin.setRecursive(true);
-
- commandline = sosCheckin.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /** Test SOSCheckIn required attributes. */
- @Test
- public void testCheckinExceptions() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
- expectSpecificBuildException("soscheckin.1", "some cause", "sosserverpath attribute must be set!");
- expectSpecificBuildException("soscheckin.2", "some cause", "username attribute must be set!");
- expectSpecificBuildException("soscheckin.3", "some cause", "vssserverpath attribute must be set!");
- expectSpecificBuildException("soscheckin.4", "some cause", "projectpath attribute must be set!");
- }
-
- /** Test CheckOutFile option flags */
- @Test
- public void testCheckoutFileFlags() {
- String[] sTestCmdLine = {"soscmd", "-command", "CheckOutFile", "-file",
- SRC_FILE, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
- "-password", SOS_PASSWORD, "-database", VSS_SERVER_PATH, "-project",
- DS_VSS_PROJECT_PATH, "-verbose", "-nocompress", "-nocache",
- "-workdir", project.getBaseDir().getAbsolutePath()
- + File.separator + LOCAL_PATH};
-
- // Set up a SOSCheckout task
- SOSCheckout sosCheckout = new SOSCheckout();
- sosCheckout.setProject(project);
- sosCheckout.setVssServerPath(VSS_SERVER_PATH);
- sosCheckout.setSosServerPath(SOS_SERVER_PATH);
- sosCheckout.setProjectPath(DS_VSS_PROJECT_PATH);
- sosCheckout.setFile(SRC_FILE);
- sosCheckout.setUsername(SOS_USERNAME);
- sosCheckout.setPassword(SOS_PASSWORD);
- sosCheckout.setLocalPath(new Path(project, LOCAL_PATH));
- sosCheckout.setNoCache(true);
- sosCheckout.setNoCompress(true);
- sosCheckout.setVerbose(true);
- sosCheckout.setRecursive(true);
-
- commandline = sosCheckout.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /** Test CheckOutProject option flags */
- @Test
- public void testCheckoutProjectFlags() {
- String[] sTestCmdLine = {"soscmd", "-command", "CheckOutProject",
- "-recursive", "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
- "-password", "", "-database", VSS_SERVER_PATH, "-project",
- DS_VSS_PROJECT_PATH, "", "", "-soshome", SOS_HOME, "-workdir",
- project.getBaseDir().getAbsolutePath()};
-
- // Set up a sosCheckout task
- SOSCheckout sosCheckout = new SOSCheckout();
- sosCheckout.setProject(project);
- sosCheckout.setVssServerPath(VSS_SERVER_PATH);
- sosCheckout.setSosServerPath(SOS_SERVER_PATH);
- sosCheckout.setProjectPath(VSS_PROJECT_PATH);
- sosCheckout.setUsername(SOS_USERNAME);
- sosCheckout.setSosHome(SOS_HOME);
- sosCheckout.setNoCache(true);
- sosCheckout.setNoCompress(false);
- sosCheckout.setVerbose(false);
- sosCheckout.setRecursive(true);
-
- commandline = sosCheckout.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /** Test SOSCheckout required attributes. */
- @Test
- public void testCheckoutExceptions() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
- expectSpecificBuildException("soscheckout.1", "some cause", "sosserverpath attribute must be set!");
- expectSpecificBuildException("soscheckout.2", "some cause", "username attribute must be set!");
- expectSpecificBuildException("soscheckout.3", "some cause", "vssserverpath attribute must be set!");
- expectSpecificBuildException("soscheckout.4", "some cause", "projectpath attribute must be set!");
- }
-
- /** Test Label option flags */
- @Test
- public void testLabelFlags() {
- String[] sTestCmdLine = {"soscmd", "-command", "AddLabel", "-server",
- SOS_SERVER_PATH, "-name", SOS_USERNAME, "-password", "", "-database",
- VSS_SERVER_PATH, "-project", DS_VSS_PROJECT_PATH, "-label",
- SRC_LABEL, "-verbose", "-log", SRC_COMMENT};
-
- // Set up a sosCheckout task
- SOSLabel sosLabel = new SOSLabel();
- sosLabel.setVssServerPath(VSS_SERVER_PATH);
- sosLabel.setSosServerPath(SOS_SERVER_PATH);
- sosLabel.setProjectPath(DS_VSS_PROJECT_PATH);
- sosLabel.setUsername(SOS_USERNAME);
- sosLabel.setSosHome(SOS_HOME);
- sosLabel.setComment(SRC_COMMENT);
- sosLabel.setLabel(SRC_LABEL);
- sosLabel.setNoCache(true);
- sosLabel.setNoCompress(false);
- sosLabel.setVerbose(true);
-
- commandline = sosLabel.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /** Test SOSLabel required attributes. */
- @Test
- public void testLabelExceptions() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
- expectSpecificBuildException("soslabel.1", "some cause", "sosserverpath attribute must be set!");
- expectSpecificBuildException("soslabel.2", "some cause", "username attribute must be set!");
- expectSpecificBuildException("soslabel.3", "some cause", "vssserverpath attribute must be set!");
- expectSpecificBuildException("soslabel.4", "some cause", "projectpath attribute must be set!");
- expectSpecificBuildException("soslabel.5", "some cause", "label attribute must be set!");
- }
-
- private void expectSpecificBuildException(String target, String errorMessage,
- String exceptionMessage) {
- try {
- buildRule.executeTarget(target);
- fail(errorMessage);
- } catch(BuildException ex) {
- assertEquals(exceptionMessage, ex.getMessage());
- }
- }
-
- /**
- * Iterate through the generated command line comparing it to reference
- * one.
- *
- * @param sTestCmdLine The reference command line;
- * @param sGeneratedCmdLine The generated command line;
- */
- private void checkCommandLines(String[] sTestCmdLine, String[] sGeneratedCmdLine) {
- int length = sTestCmdLine.length;
- for (int i = 0; i < length; i++) {
- try {
- assertEquals("arg # " + String.valueOf(i),
- sTestCmdLine[i],
- sGeneratedCmdLine[i]);
- } catch (ArrayIndexOutOfBoundsException aioob) {
- fail("missing arg " + sTestCmdLine[i]);
- }
- }
- if (sGeneratedCmdLine.length > sTestCmdLine.length) {
- // We have extra elements
- fail("extra args");
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.sos;
+
+import java.io.File;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.types.Commandline;
+import org.apache.tools.ant.types.Path;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * Testcase to ensure that command line generation and required attributes are
+ * correct.
+ *
+ */
+public class SOSTest {
+
+ private Commandline commandline;
+
+ private static final String VSS_SERVER_PATH = "\\\\server\\vss\\srcsafe.ini";
+ private static final String VSS_PROJECT_PATH = "/SourceRoot/Project";
+ private static final String DS_VSS_PROJECT_PATH = "$/SourceRoot/Project";
+ private static final String SOS_SERVER_PATH = "192.168.0.1:8888";
+ private static final String SOS_USERNAME = "ant";
+ private static final String SOS_PASSWORD = "rocks";
+ private static final String LOCAL_PATH = "testdir";
+ private static final String SRC_FILE = "Class1.java";
+ private static final String SRC_LABEL = "label1";
+ private static final String SRC_COMMENT = "I fixed a bug";
+ private static final String SOS_HOME = "/home/user/.sos";
+ private static final String VERSION = "007";
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+ private Project project;
+
+ @Before
+ public void setUp() {
+ project = new Project();
+ project.init();
+ project.setBasedir(".");
+ }
+
+ @After
+ public void tearDown() {
+ File file = new File(project.getBaseDir(), LOCAL_PATH);
+ if (file.exists()) {
+ file.delete();
+ }
+ }
+
+ /** Test SOSGetFile flags & commandline generation */
+ @Test
+ public void testGetFileFlags() {
+ String[] sTestCmdLine = {"soscmd", "-command", "GetFile", "-file",
+ SRC_FILE, "-revision", "007", "-server", SOS_SERVER_PATH, "-name",
+ SOS_USERNAME, "-password", SOS_PASSWORD, "-database", VSS_SERVER_PATH,
+ "-project", DS_VSS_PROJECT_PATH, "-verbose", "-nocompress",
+ "-nocache", "-workdir", project.getBaseDir().getAbsolutePath()
+ + File.separator + LOCAL_PATH};
+
+ // Set up a SOSGet task
+ SOSGet sosGet = new SOSGet();
+ sosGet.setProject(project);
+ sosGet.setVssServerPath(VSS_SERVER_PATH);
+ sosGet.setSosServerPath(SOS_SERVER_PATH);
+ sosGet.setProjectPath(VSS_PROJECT_PATH);
+ sosGet.setFile(SRC_FILE);
+ sosGet.setUsername(SOS_USERNAME);
+ sosGet.setPassword(SOS_PASSWORD);
+ sosGet.setVersion(VERSION);
+ sosGet.setLocalPath(new Path(project, LOCAL_PATH));
+ sosGet.setNoCache(true);
+ sosGet.setNoCompress(true);
+ sosGet.setVerbose(true);
+ sosGet.setRecursive(true);
+
+ commandline = sosGet.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /** Test SOSGetProject flags & commandline generation */
+ @Test
+ public void testGetProjectFlags() {
+ String[] sTestCmdLine = {"soscmd", "-command", "GetProject", "-recursive",
+ "-label", SRC_LABEL, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
+ "-password", "", "-database", VSS_SERVER_PATH, "-project",
+ DS_VSS_PROJECT_PATH, "", "", "-soshome", SOS_HOME, "-workdir",
+ project.getBaseDir().getAbsolutePath()};
+
+ // Set up a SOSGet task
+ SOSGet sosGet = new SOSGet();
+ sosGet.setProject(project);
+ sosGet.setVssServerPath(VSS_SERVER_PATH);
+ sosGet.setSosServerPath(SOS_SERVER_PATH);
+ sosGet.setProjectPath(DS_VSS_PROJECT_PATH);
+ sosGet.setLabel(SRC_LABEL);
+ sosGet.setUsername(SOS_USERNAME);
+ sosGet.setSosHome(SOS_HOME);
+ sosGet.setNoCache(true);
+ sosGet.setNoCompress(false);
+ sosGet.setVerbose(false);
+ sosGet.setRecursive(true);
+
+ commandline = sosGet.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /** Tests SOSGet required attributes. */
+ @Test
+ public void testGetExceptions() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
+ expectSpecificBuildException("sosget.1", "some cause", "sosserverpath attribute must be set!");
+ expectSpecificBuildException("sosget.2", "some cause", "username attribute must be set!");
+ expectSpecificBuildException("sosget.3", "some cause", "vssserverpath attribute must be set!");
+ expectSpecificBuildException("sosget.4", "some cause", "projectpath attribute must be set!");
+ }
+
+ /** Test CheckInFile option flags */
+ @Test
+ public void testCheckinFileFlags() {
+ String[] sTestCmdLine = {"soscmd", "-command", "CheckInFile", "-file",
+ SRC_FILE, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
+ "-password", SOS_PASSWORD, "-database", VSS_SERVER_PATH, "-project",
+ DS_VSS_PROJECT_PATH, "-verbose", "-nocompress", "-nocache",
+ "-workdir", project.getBaseDir().getAbsolutePath() + File.separator
+ + LOCAL_PATH, "-log", SRC_COMMENT};
+
+ // Set up a SOSCheckin task
+ SOSCheckin sosCheckin = new SOSCheckin();
+ sosCheckin.setProject(project);
+ sosCheckin.setVssServerPath(VSS_SERVER_PATH);
+ sosCheckin.setSosServerPath(SOS_SERVER_PATH);
+ sosCheckin.setProjectPath(VSS_PROJECT_PATH);
+ sosCheckin.setFile(SRC_FILE);
+ sosCheckin.setComment(SRC_COMMENT);
+ sosCheckin.setUsername(SOS_USERNAME);
+ sosCheckin.setPassword(SOS_PASSWORD);
+ sosCheckin.setLocalPath(new Path(project, LOCAL_PATH));
+ sosCheckin.setNoCache(true);
+ sosCheckin.setNoCompress(true);
+ sosCheckin.setVerbose(true);
+ sosCheckin.setRecursive(true);
+
+ commandline = sosCheckin.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /** Test CheckInProject option flags */
+ @Test
+ public void testCheckinProjectFlags() {
+ String[] sTestCmdLine = {"soscmd", "-command", "CheckInProject",
+ "-recursive", "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
+ "-password", "", "-database", VSS_SERVER_PATH, "-project",
+ DS_VSS_PROJECT_PATH, "", "", "-soshome", SOS_HOME, "-workdir",
+ project.getBaseDir().getAbsolutePath(), "-log", SRC_COMMENT,};
+
+ // Set up a SOSCheckin task
+ SOSCheckin sosCheckin = new SOSCheckin();
+ sosCheckin.setProject(project);
+ sosCheckin.setVssServerPath(VSS_SERVER_PATH);
+ sosCheckin.setSosServerPath(SOS_SERVER_PATH);
+ sosCheckin.setProjectPath(DS_VSS_PROJECT_PATH);
+ sosCheckin.setComment(SRC_COMMENT);
+ sosCheckin.setUsername(SOS_USERNAME);
+ sosCheckin.setSosHome(SOS_HOME);
+ sosCheckin.setNoCache(true);
+ sosCheckin.setNoCompress(false);
+ sosCheckin.setVerbose(false);
+ sosCheckin.setRecursive(true);
+
+ commandline = sosCheckin.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /** Test SOSCheckIn required attributes. */
+ @Test
+ public void testCheckinExceptions() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
+ expectSpecificBuildException("soscheckin.1", "some cause", "sosserverpath attribute must be set!");
+ expectSpecificBuildException("soscheckin.2", "some cause", "username attribute must be set!");
+ expectSpecificBuildException("soscheckin.3", "some cause", "vssserverpath attribute must be set!");
+ expectSpecificBuildException("soscheckin.4", "some cause", "projectpath attribute must be set!");
+ }
+
+ /** Test CheckOutFile option flags */
+ @Test
+ public void testCheckoutFileFlags() {
+ String[] sTestCmdLine = {"soscmd", "-command", "CheckOutFile", "-file",
+ SRC_FILE, "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
+ "-password", SOS_PASSWORD, "-database", VSS_SERVER_PATH, "-project",
+ DS_VSS_PROJECT_PATH, "-verbose", "-nocompress", "-nocache",
+ "-workdir", project.getBaseDir().getAbsolutePath()
+ + File.separator + LOCAL_PATH};
+
+ // Set up a SOSCheckout task
+ SOSCheckout sosCheckout = new SOSCheckout();
+ sosCheckout.setProject(project);
+ sosCheckout.setVssServerPath(VSS_SERVER_PATH);
+ sosCheckout.setSosServerPath(SOS_SERVER_PATH);
+ sosCheckout.setProjectPath(DS_VSS_PROJECT_PATH);
+ sosCheckout.setFile(SRC_FILE);
+ sosCheckout.setUsername(SOS_USERNAME);
+ sosCheckout.setPassword(SOS_PASSWORD);
+ sosCheckout.setLocalPath(new Path(project, LOCAL_PATH));
+ sosCheckout.setNoCache(true);
+ sosCheckout.setNoCompress(true);
+ sosCheckout.setVerbose(true);
+ sosCheckout.setRecursive(true);
+
+ commandline = sosCheckout.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /** Test CheckOutProject option flags */
+ @Test
+ public void testCheckoutProjectFlags() {
+ String[] sTestCmdLine = {"soscmd", "-command", "CheckOutProject",
+ "-recursive", "-server", SOS_SERVER_PATH, "-name", SOS_USERNAME,
+ "-password", "", "-database", VSS_SERVER_PATH, "-project",
+ DS_VSS_PROJECT_PATH, "", "", "-soshome", SOS_HOME, "-workdir",
+ project.getBaseDir().getAbsolutePath()};
+
+ // Set up a sosCheckout task
+ SOSCheckout sosCheckout = new SOSCheckout();
+ sosCheckout.setProject(project);
+ sosCheckout.setVssServerPath(VSS_SERVER_PATH);
+ sosCheckout.setSosServerPath(SOS_SERVER_PATH);
+ sosCheckout.setProjectPath(VSS_PROJECT_PATH);
+ sosCheckout.setUsername(SOS_USERNAME);
+ sosCheckout.setSosHome(SOS_HOME);
+ sosCheckout.setNoCache(true);
+ sosCheckout.setNoCompress(false);
+ sosCheckout.setVerbose(false);
+ sosCheckout.setRecursive(true);
+
+ commandline = sosCheckout.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /** Test SOSCheckout required attributes. */
+ @Test
+ public void testCheckoutExceptions() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
+ expectSpecificBuildException("soscheckout.1", "some cause", "sosserverpath attribute must be set!");
+ expectSpecificBuildException("soscheckout.2", "some cause", "username attribute must be set!");
+ expectSpecificBuildException("soscheckout.3", "some cause", "vssserverpath attribute must be set!");
+ expectSpecificBuildException("soscheckout.4", "some cause", "projectpath attribute must be set!");
+ }
+
+ /** Test Label option flags */
+ @Test
+ public void testLabelFlags() {
+ String[] sTestCmdLine = {"soscmd", "-command", "AddLabel", "-server",
+ SOS_SERVER_PATH, "-name", SOS_USERNAME, "-password", "", "-database",
+ VSS_SERVER_PATH, "-project", DS_VSS_PROJECT_PATH, "-label",
+ SRC_LABEL, "-verbose", "-log", SRC_COMMENT};
+
+ // Set up a sosCheckout task
+ SOSLabel sosLabel = new SOSLabel();
+ sosLabel.setVssServerPath(VSS_SERVER_PATH);
+ sosLabel.setSosServerPath(SOS_SERVER_PATH);
+ sosLabel.setProjectPath(DS_VSS_PROJECT_PATH);
+ sosLabel.setUsername(SOS_USERNAME);
+ sosLabel.setSosHome(SOS_HOME);
+ sosLabel.setComment(SRC_COMMENT);
+ sosLabel.setLabel(SRC_LABEL);
+ sosLabel.setNoCache(true);
+ sosLabel.setNoCompress(false);
+ sosLabel.setVerbose(true);
+
+ commandline = sosLabel.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /** Test SOSLabel required attributes. */
+ @Test
+ public void testLabelExceptions() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/sos/sos.xml");
+ expectSpecificBuildException("soslabel.1", "some cause", "sosserverpath attribute must be set!");
+ expectSpecificBuildException("soslabel.2", "some cause", "username attribute must be set!");
+ expectSpecificBuildException("soslabel.3", "some cause", "vssserverpath attribute must be set!");
+ expectSpecificBuildException("soslabel.4", "some cause", "projectpath attribute must be set!");
+ expectSpecificBuildException("soslabel.5", "some cause", "label attribute must be set!");
+ }
+
+ private void expectSpecificBuildException(String target, String errorMessage,
+ String exceptionMessage) {
+ try {
+ buildRule.executeTarget(target);
+ fail(errorMessage);
+ } catch(BuildException ex) {
+ assertEquals(exceptionMessage, ex.getMessage());
+ }
+ }
+
+ /**
+ * Iterate through the generated command line comparing it to reference
+ * one.
+ *
+ * @param sTestCmdLine The reference command line;
+ * @param sGeneratedCmdLine The generated command line;
+ */
+ private void checkCommandLines(String[] sTestCmdLine, String[] sGeneratedCmdLine) {
+ int length = sTestCmdLine.length;
+ for (int i = 0; i < length; i++) {
+ try {
+ assertEquals("arg # " + String.valueOf(i),
+ sTestCmdLine[i],
+ sGeneratedCmdLine[i]);
+ } catch (ArrayIndexOutOfBoundsException aioob) {
+ fail("missing arg " + sTestCmdLine[i]);
+ }
+ }
+ if (sGeneratedCmdLine.length > sTestCmdLine.length) {
+ // We have extra elements
+ fail("extra args");
+ }
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/splash/SplashScreenTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/splash/SplashScreenTest.java
index fb0b3eaf4..b9fa0b552 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/splash/SplashScreenTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/splash/SplashScreenTest.java
@@ -1,50 +1,50 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.splash;
-
-import org.apache.tools.ant.Project;
-
-/**
- * This is an "interactive" test, it passes if the splash screen
- * disappears after the "finished" but before the "exiting" message.
- *
- * This even isn't a JUnit test case.
- *
- * @since Ant 1.5.2
- */
-public class SplashScreenTest {
-
- public static void main(String[] args) throws InterruptedException {
- Project p = new Project();
- SplashTask t = new SplashTask();
- t.setProject(p);
- t.execute();
-
- // give it some time to display
- Thread.sleep(2000);
-
- p.fireBuildFinished(null);
- System.err.println("finished");
-
- Thread.sleep(2000);
- System.err.println("exiting");
- System.exit(0);
- }
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional.splash;
+
+import org.apache.tools.ant.Project;
+
+/**
+ * This is an "interactive" test, it passes if the splash screen
+ * disappears after the "finished" but before the "exiting" message.
+ *
+ * This even isn't a JUnit test case.
+ *
+ * @since Ant 1.5.2
+ */
+public class SplashScreenTest {
+
+ public static void main(String[] args) throws InterruptedException {
+ Project p = new Project();
+ SplashTask t = new SplashTask();
+ t.setProject(p);
+ t.execute();
+
+ // give it some time to display
+ Thread.sleep(2000);
+
+ p.fireBuildFinished(null);
+ System.err.println("finished");
+
+ Thread.sleep(2000);
+ System.err.println("exiting");
+ System.exit(0);
+ }
+}
+
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java
index dff5b25a9..c1c136ff8 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/ssh/ScpTest.java
@@ -1,206 +1,206 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.taskdefs.optional.ssh;
-
-import java.io.File;
-import java.io.FileWriter;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Iterator;
-import java.util.List;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.condition.FilesMatch;
-import org.apache.tools.ant.types.FileSet;
-import org.apache.tools.ant.types.selectors.FilenameSelector;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * This is a unit test for the Scp task in Ant. It must be
- * configured with command line options in order for it to work.
- * Here are the options:
- *
- * scp.tmp This is a local path to a temporary
- * directory for this task to use.
- * scp.host This is the remote location of the form:
- * "user:password@host:/path/to/directory"
- * scp.port The port of the listening SSH service.
- * Defaults to 22. (optional)
- * scp.known.hosts The file containing the public keys of known
- * hosts. Must be a SSH2 version file, but
- * supports RSA and DSA keys. If it is not present
- * this task setTrust() to true. (optional)
- */
-public class ScpTest {
-
- private File tempDir;
- private String sshHostUri = System.getProperty("scp.host");
- private int port = Integer.parseInt( System.getProperty( "scp.port", "22" ) );
- private String knownHosts = System.getProperty("scp.known.hosts");
-
- private List cleanUpList = new ArrayList();
-
- public ScpTest() {
- if (System.getProperty("scp.tmp") != null) {
- tempDir = new File(System.getProperty("scp.tmp"));
- }
- }
-
- @Before
- public void setUp() {
- cleanUpList.clear();
- }
-
- @After
- public void tearDown() {
- for( Iterator i = cleanUpList.iterator(); i.hasNext(); ) {
- File file = (File) i.next();
- file.delete();
- }
- }
-
- @Test
- public void testSingleFileUploadAndDownload() throws IOException {
- assertNotNull("system property scp.tmp must be set", tempDir);
- File uploadFile = createTemporaryFile();
-
- // upload
- Scp scpTask = createTask();
- scpTask.setFile( uploadFile.getPath() );
- scpTask.setTodir( sshHostUri );
- scpTask.execute();
-
- File testFile = new File( tempDir.getPath() + File.separator +
- "download-testSingleFileUploadAndDownload.test" );
- addCleanup(testFile );
- assertFalse("Assert that the testFile does not exist.", testFile.exists());
-
- // download
- scpTask = createTask();
- scpTask.setFile( sshHostUri + "/" + uploadFile.getName() );
- scpTask.setTodir( testFile.getPath() );
- scpTask.execute();
-
- assertTrue( "Assert that the testFile exists.", testFile.exists() );
- compareFiles( uploadFile, testFile );
- }
-
- @Test
- public void testMultiUploadAndDownload() throws IOException {
- assertNotNull("system property scp.tmp must be set", tempDir);
- List uploadList = new ArrayList();
- for( int i = 0; i < 5; i++ ) {
- uploadList.add( createTemporaryFile() );
- }
-
- Scp scp = createTask();
- FilenameSelector selector = new FilenameSelector();
- selector.setName( "scp*" );
- FileSet fileset = new FileSet();
- fileset.setDir( tempDir );
- fileset.addFilename( selector );
- scp.addFileset( fileset );
- scp.setTodir( sshHostUri );
- scp.execute();
-
- File multi = new File( tempDir, "multi" );
- multi.mkdir();
- addCleanup( multi );
-
- Scp scp2 = createTask();
- scp2.setFile( sshHostUri + "/scp*" );
- scp2.setTodir( multi.getPath() );
- scp2.execute();
-
- FilesMatch match = new FilesMatch();
- for( Iterator i = uploadList.iterator(); i.hasNext(); ) {
- File f = (File)i.next();
- match.setFile1( f );
- File f2 = new File( multi, f.getName() );
- match.setFile2( f2 );
- assertTrue("Assert file '" + f.getPath() + "' and file '" +
- f2.getPath() + "'", match.eval() );
- }
- }
-
- @Test
- public void testRemoteToDir() throws IOException {
- Scp scpTask = createTask();
-
- // first try an invalid URI
- try {
- scpTask.setRemoteTodir( "host:/a/path/without/an/at" );
- fail("Expected a BuildException to be thrown due to invalid"
- + " remoteToDir");
- }
- catch (BuildException e)
- {
- // expected
- //TODO we should be asserting a value in here
- }
-
- // And this one should work
- scpTask.setRemoteTodir( "user:password@host:/a/path/with/an/at" );
- // no exception
- }
-
- public void addCleanup( File file ) {
- cleanUpList.add( file );
- }
-
- private void compareFiles(File src, File dest) {
- FilesMatch match = new FilesMatch();
- match.setFile1( src );
- match.setFile2( dest );
-
- assertTrue( "Assert files are equal.", match.eval() );
- }
-
- private File createTemporaryFile() throws IOException {
- File uploadFile;
- uploadFile = File.createTempFile( "scp", "test", tempDir );
- FileWriter writer = new FileWriter( uploadFile );
- writer.write("Can you hear me now?\n");
- writer.close();
- addCleanup( uploadFile );
- return uploadFile;
- }
-
- private Scp createTask() {
- Scp scp = new Scp();
- Project p = new Project();
- p.init();
- scp.setProject( p );
- if( knownHosts != null ) {
- scp.setKnownhosts( knownHosts );
- } else {
- scp.setTrust( true );
- }
- scp.setPort( port );
- return scp;
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.taskdefs.optional.ssh;
+
+import java.io.File;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.condition.FilesMatch;
+import org.apache.tools.ant.types.FileSet;
+import org.apache.tools.ant.types.selectors.FilenameSelector;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * This is a unit test for the Scp task in Ant. It must be
+ * configured with command line options in order for it to work.
+ * Here are the options:
+ *
+ * scp.tmp This is a local path to a temporary
+ * directory for this task to use.
+ * scp.host This is the remote location of the form:
+ * "user:password@host:/path/to/directory"
+ * scp.port The port of the listening SSH service.
+ * Defaults to 22. (optional)
+ * scp.known.hosts The file containing the public keys of known
+ * hosts. Must be a SSH2 version file, but
+ * supports RSA and DSA keys. If it is not present
+ * this task setTrust() to true. (optional)
+ */
+public class ScpTest {
+
+ private File tempDir;
+ private String sshHostUri = System.getProperty("scp.host");
+ private int port = Integer.parseInt( System.getProperty( "scp.port", "22" ) );
+ private String knownHosts = System.getProperty("scp.known.hosts");
+
+ private List cleanUpList = new ArrayList();
+
+ public ScpTest() {
+ if (System.getProperty("scp.tmp") != null) {
+ tempDir = new File(System.getProperty("scp.tmp"));
+ }
+ }
+
+ @Before
+ public void setUp() {
+ cleanUpList.clear();
+ }
+
+ @After
+ public void tearDown() {
+ for( Iterator i = cleanUpList.iterator(); i.hasNext(); ) {
+ File file = (File) i.next();
+ file.delete();
+ }
+ }
+
+ @Test
+ public void testSingleFileUploadAndDownload() throws IOException {
+ assertNotNull("system property scp.tmp must be set", tempDir);
+ File uploadFile = createTemporaryFile();
+
+ // upload
+ Scp scpTask = createTask();
+ scpTask.setFile( uploadFile.getPath() );
+ scpTask.setTodir( sshHostUri );
+ scpTask.execute();
+
+ File testFile = new File( tempDir.getPath() + File.separator +
+ "download-testSingleFileUploadAndDownload.test" );
+ addCleanup(testFile );
+ assertFalse("Assert that the testFile does not exist.", testFile.exists());
+
+ // download
+ scpTask = createTask();
+ scpTask.setFile( sshHostUri + "/" + uploadFile.getName() );
+ scpTask.setTodir( testFile.getPath() );
+ scpTask.execute();
+
+ assertTrue( "Assert that the testFile exists.", testFile.exists() );
+ compareFiles( uploadFile, testFile );
+ }
+
+ @Test
+ public void testMultiUploadAndDownload() throws IOException {
+ assertNotNull("system property scp.tmp must be set", tempDir);
+ List uploadList = new ArrayList();
+ for( int i = 0; i < 5; i++ ) {
+ uploadList.add( createTemporaryFile() );
+ }
+
+ Scp scp = createTask();
+ FilenameSelector selector = new FilenameSelector();
+ selector.setName( "scp*" );
+ FileSet fileset = new FileSet();
+ fileset.setDir( tempDir );
+ fileset.addFilename( selector );
+ scp.addFileset( fileset );
+ scp.setTodir( sshHostUri );
+ scp.execute();
+
+ File multi = new File( tempDir, "multi" );
+ multi.mkdir();
+ addCleanup( multi );
+
+ Scp scp2 = createTask();
+ scp2.setFile( sshHostUri + "/scp*" );
+ scp2.setTodir( multi.getPath() );
+ scp2.execute();
+
+ FilesMatch match = new FilesMatch();
+ for( Iterator i = uploadList.iterator(); i.hasNext(); ) {
+ File f = (File)i.next();
+ match.setFile1( f );
+ File f2 = new File( multi, f.getName() );
+ match.setFile2( f2 );
+ assertTrue("Assert file '" + f.getPath() + "' and file '" +
+ f2.getPath() + "'", match.eval() );
+ }
+ }
+
+ @Test
+ public void testRemoteToDir() throws IOException {
+ Scp scpTask = createTask();
+
+ // first try an invalid URI
+ try {
+ scpTask.setRemoteTodir( "host:/a/path/without/an/at" );
+ fail("Expected a BuildException to be thrown due to invalid"
+ + " remoteToDir");
+ }
+ catch (BuildException e)
+ {
+ // expected
+ //TODO we should be asserting a value in here
+ }
+
+ // And this one should work
+ scpTask.setRemoteTodir( "user:password@host:/a/path/with/an/at" );
+ // no exception
+ }
+
+ public void addCleanup( File file ) {
+ cleanUpList.add( file );
+ }
+
+ private void compareFiles(File src, File dest) {
+ FilesMatch match = new FilesMatch();
+ match.setFile1( src );
+ match.setFile2( dest );
+
+ assertTrue( "Assert files are equal.", match.eval() );
+ }
+
+ private File createTemporaryFile() throws IOException {
+ File uploadFile;
+ uploadFile = File.createTempFile( "scp", "test", tempDir );
+ FileWriter writer = new FileWriter( uploadFile );
+ writer.write("Can you hear me now?\n");
+ writer.close();
+ addCleanup( uploadFile );
+ return uploadFile;
+ }
+
+ private Scp createTask() {
+ Scp scp = new Scp();
+ Project p = new Project();
+ p.init();
+ scp.setProject( p );
+ if( knownHosts != null ) {
+ scp.setKnownhosts( knownHosts );
+ } else {
+ scp.setTrust( true );
+ }
+ scp.setPort( port );
+ return scp;
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java
index e36d6838b..0ac0746d1 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/unix/SymlinkTest.java
@@ -1,297 +1,297 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-/*
- * Since the initial version of this file was deveolped on the clock on
- * an NSF grant I should say the following boilerplate:
- *
- * This material is based upon work supported by the National Science
- * Foundaton under Grant No. EIA-0196404. Any opinions, findings, and
- * conclusions or recommendations expressed in this material are those
- * of the author and do not necessarily reflect the views of the
- * National Science Foundation.
- */
-
-package org.apache.tools.ant.taskdefs.optional.unix;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.taskdefs.condition.Os;
-
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.util.SymbolicLinkUtils;
-import org.junit.After;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.io.File;
-
-/**
- * Test cases for the Symlink task. Link creation, link deletion, recording
- * of links in multiple directories, and restoration of links recorded are
- * all tested. A separate test for the utility method Symlink.deleteSymlink
- * is not included because action="delete" only prints a message and calls
- * Symlink.deleteSymlink, making a separate test redundant.
- *
- */
-
-public class SymlinkTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- private boolean supportsSymlinks = Os.isFamily("unix");
-
- @Before
- public void setUp() {
- Assume.assumeTrue("Symlinks not supported on current operating system", supportsSymlinks);
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/unix/symlink.xml");
- buildRule.executeTarget("setUp");
- }
-
- @Test
- public void testSingle() {
- buildRule.executeTarget("test-single");
- Project p = buildRule.getProject();
- assertNotNull("Failed to create file",
- p.getProperty("test.single.file.created"));
- assertNotNull("Failed to create link",
- p.getProperty("test.single.link.created"));
- }
-
- @Test
- public void testDelete() {
- buildRule.executeTarget("test-delete");
- Project p = buildRule.getProject();
- String linkDeleted = p.getProperty("test.delete.link.still.there");
- assertNotNull("Actual file deleted by symlink",
- p.getProperty("test.delete.file.still.there"));
- if (linkDeleted != null) {
- fail(linkDeleted);
- }
- }
-
- @Test
- public void testRecord() {
- buildRule.executeTarget("test-record");
- Project p = buildRule.getProject();
-
- assertNotNull("Failed to create dir1",
- p.getProperty("test.record.dir1.created"));
-
- assertNotNull("Failed to create dir2",
- p.getProperty("test.record.dir2.created"));
-
- assertNotNull("Failed to create file1",
- p.getProperty("test.record.file1.created"));
-
- assertNotNull("Failed to create file2",
- p.getProperty("test.record.file2.created"));
-
- assertNotNull("Failed to create fileA",
- p.getProperty("test.record.fileA.created"));
-
- assertNotNull("Failed to create fileB",
- p.getProperty("test.record.fileB.created"));
-
- assertNotNull("Failed to create fileC",
- p.getProperty("test.record.fileC.created"));
-
- assertNotNull("Failed to create link1",
- p.getProperty("test.record.link1.created"));
-
- assertNotNull("Failed to create link2",
- p.getProperty("test.record.link2.created"));
-
- assertNotNull("Failed to create link3",
- p.getProperty("test.record.link3.created"));
-
- assertNotNull("Failed to create dirlink",
- p.getProperty("test.record.dirlink.created"));
-
- assertNotNull("Failed to create dirlink2",
- p.getProperty("test.record.dirlink2.created"));
-
- assertNotNull("Couldn't record links in dir1",
- p.getProperty("test.record.dir1.recorded"));
-
- assertNotNull("Couldn't record links in dir2",
- p.getProperty("test.record.dir2.recorded"));
-
- String dir3rec = p.getProperty("test.record.dir3.recorded");
-
- if (dir3rec != null) {
- fail(dir3rec);
- }
-
- }
-
- @Test
- public void testRecreate() {
- buildRule.executeTarget("test-recreate");
- Project p = buildRule.getProject();
- String link1Rem = p.getProperty("test.recreate.link1.not.removed");
- String link2Rem = p.getProperty("test.recreate.link2.not.removed");
- String link3Rem = p.getProperty("test.recreate.link3.not.removed");
- String dirlinkRem = p.getProperty("test.recreate.dirlink.not.removed");
- if (link1Rem != null) {
- fail(link1Rem);
- }
- if (link2Rem != null) {
- fail(link2Rem);
- }
- if (link3Rem != null) {
- fail(link3Rem);
- }
- if (dirlinkRem != null) {
- fail(dirlinkRem);
- }
- assertNotNull("Failed to recreate link1",
- p.getProperty("test.recreate.link1.recreated"));
- assertNotNull("Failed to recreate link2",
- p.getProperty("test.recreate.link2.recreated"));
- assertNotNull("Failed to recreate link3",
- p.getProperty("test.recreate.link3.recreated"));
- assertNotNull("Failed to recreate dirlink",
- p.getProperty("test.recreate.dirlink.recreated"));
-
- String doubleRecreate = p.getProperty("test.recreate.dirlink2.recreated.twice");
-
- if (doubleRecreate != null) {
- fail(doubleRecreate);
- }
-
- assertNotNull("Failed to alter dirlink3",
- p.getProperty("test.recreate.dirlink3.was.altered"));
- }
-
- @Test
- public void testSymbolicLinkUtilsMethods() throws Exception {
-
- buildRule.executeTarget("test-fileutils");
- SymbolicLinkUtils su = SymbolicLinkUtils.getSymbolicLinkUtils();
-
- java.io.File f = new File(buildRule.getOutputDir(), "file1");
- assertTrue(f.exists());
- assertFalse(f.isDirectory());
- assertTrue(f.isFile());
- assertFalse(su.isSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isSymbolicLink(f.getParentFile(),
- f.getName()));
- assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
- f.getName()));
-
- f = new File(buildRule.getOutputDir(), "dir1");
- assertTrue(f.exists());
- assertTrue(f.isDirectory());
- assertFalse(f.isFile());
- assertFalse(su.isSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isSymbolicLink(f.getParentFile(),
- f.getName()));
- assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
- f.getName()));
-
- f = new File(buildRule.getOutputDir(), "file2");
- assertFalse(f.exists());
- assertFalse(f.isDirectory());
- assertFalse(f.isFile());
- assertFalse(su.isSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isSymbolicLink(f.getParentFile(),
- f.getName()));
- assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
- f.getName()));
-
- f = new File(buildRule.getOutputDir(), "dir2");
- assertFalse(f.exists());
- assertFalse(f.isDirectory());
- assertFalse(f.isFile());
- assertFalse(su.isSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isSymbolicLink(f.getParentFile(),
- f.getName()));
- assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
- f.getName()));
-
-
- f = new File(buildRule.getOutputDir(), "file.there");
- assertTrue(f.exists());
- assertFalse(f.isDirectory());
- assertTrue(f.isFile());
- assertTrue(su.isSymbolicLink(f.getAbsolutePath()));
- assertTrue(su.isSymbolicLink(f.getParentFile(),
- f.getName()));
- assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
- f.getName()));
-
- f = new File(buildRule.getOutputDir(), "dir.there");
- assertTrue(f.exists());
- assertTrue(f.isDirectory());
- assertFalse(f.isFile());
- assertTrue(su.isSymbolicLink(f.getAbsolutePath()));
- assertTrue(su.isSymbolicLink(f.getParentFile(),
- f.getName()));
- assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
- assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
- f.getName()));
-
- // it is not possible to find out that symbolic links pointing
- // to inexistent files or directories are symbolic links
- // it used to be possible to detect this on Mac
- // this is not true under Snow Leopard and JDK 1.5
- // Removing special handling of MacOS until someone shouts
- // Antoine
- f = new File(buildRule.getOutputDir(), "file.notthere");
- assertFalse(f.exists());
- assertFalse(f.isDirectory());
- assertFalse(f.isFile());
- assertTrue(su.isSymbolicLink(f.getAbsolutePath()) == false);
- assertTrue(su.isSymbolicLink(f.getParentFile(), f.getName()) == false);
- assertTrue(su.isDanglingSymbolicLink(f.getAbsolutePath()));
- assertTrue(su.isDanglingSymbolicLink(f.getParentFile(),
- f.getName()));
-
- f = new File(buildRule.getOutputDir(), "dir.notthere");
- assertFalse(f.exists());
- assertFalse(f.isDirectory());
- assertFalse(f.isFile());
- assertTrue(su.isSymbolicLink(f.getAbsolutePath()) == false);
- assertTrue(su.isSymbolicLink(f.getParentFile(), f.getName()) == false);
- assertTrue(su.isDanglingSymbolicLink(f.getAbsolutePath()));
- assertTrue(su.isDanglingSymbolicLink(f.getParentFile(),
- f.getName()));
-
- }
-
- @After
- public void tearDown() {
- if (buildRule.getProject() != null) {
- buildRule.executeTarget("tearDown");
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+/*
+ * Since the initial version of this file was deveolped on the clock on
+ * an NSF grant I should say the following boilerplate:
+ *
+ * This material is based upon work supported by the National Science
+ * Foundaton under Grant No. EIA-0196404. Any opinions, findings, and
+ * conclusions or recommendations expressed in this material are those
+ * of the author and do not necessarily reflect the views of the
+ * National Science Foundation.
+ */
+
+package org.apache.tools.ant.taskdefs.optional.unix;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.taskdefs.condition.Os;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.util.SymbolicLinkUtils;
+import org.junit.After;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+
+/**
+ * Test cases for the Symlink task. Link creation, link deletion, recording
+ * of links in multiple directories, and restoration of links recorded are
+ * all tested. A separate test for the utility method Symlink.deleteSymlink
+ * is not included because action="delete" only prints a message and calls
+ * Symlink.deleteSymlink, making a separate test redundant.
+ *
+ */
+
+public class SymlinkTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ private boolean supportsSymlinks = Os.isFamily("unix");
+
+ @Before
+ public void setUp() {
+ Assume.assumeTrue("Symlinks not supported on current operating system", supportsSymlinks);
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/unix/symlink.xml");
+ buildRule.executeTarget("setUp");
+ }
+
+ @Test
+ public void testSingle() {
+ buildRule.executeTarget("test-single");
+ Project p = buildRule.getProject();
+ assertNotNull("Failed to create file",
+ p.getProperty("test.single.file.created"));
+ assertNotNull("Failed to create link",
+ p.getProperty("test.single.link.created"));
+ }
+
+ @Test
+ public void testDelete() {
+ buildRule.executeTarget("test-delete");
+ Project p = buildRule.getProject();
+ String linkDeleted = p.getProperty("test.delete.link.still.there");
+ assertNotNull("Actual file deleted by symlink",
+ p.getProperty("test.delete.file.still.there"));
+ if (linkDeleted != null) {
+ fail(linkDeleted);
+ }
+ }
+
+ @Test
+ public void testRecord() {
+ buildRule.executeTarget("test-record");
+ Project p = buildRule.getProject();
+
+ assertNotNull("Failed to create dir1",
+ p.getProperty("test.record.dir1.created"));
+
+ assertNotNull("Failed to create dir2",
+ p.getProperty("test.record.dir2.created"));
+
+ assertNotNull("Failed to create file1",
+ p.getProperty("test.record.file1.created"));
+
+ assertNotNull("Failed to create file2",
+ p.getProperty("test.record.file2.created"));
+
+ assertNotNull("Failed to create fileA",
+ p.getProperty("test.record.fileA.created"));
+
+ assertNotNull("Failed to create fileB",
+ p.getProperty("test.record.fileB.created"));
+
+ assertNotNull("Failed to create fileC",
+ p.getProperty("test.record.fileC.created"));
+
+ assertNotNull("Failed to create link1",
+ p.getProperty("test.record.link1.created"));
+
+ assertNotNull("Failed to create link2",
+ p.getProperty("test.record.link2.created"));
+
+ assertNotNull("Failed to create link3",
+ p.getProperty("test.record.link3.created"));
+
+ assertNotNull("Failed to create dirlink",
+ p.getProperty("test.record.dirlink.created"));
+
+ assertNotNull("Failed to create dirlink2",
+ p.getProperty("test.record.dirlink2.created"));
+
+ assertNotNull("Couldn't record links in dir1",
+ p.getProperty("test.record.dir1.recorded"));
+
+ assertNotNull("Couldn't record links in dir2",
+ p.getProperty("test.record.dir2.recorded"));
+
+ String dir3rec = p.getProperty("test.record.dir3.recorded");
+
+ if (dir3rec != null) {
+ fail(dir3rec);
+ }
+
+ }
+
+ @Test
+ public void testRecreate() {
+ buildRule.executeTarget("test-recreate");
+ Project p = buildRule.getProject();
+ String link1Rem = p.getProperty("test.recreate.link1.not.removed");
+ String link2Rem = p.getProperty("test.recreate.link2.not.removed");
+ String link3Rem = p.getProperty("test.recreate.link3.not.removed");
+ String dirlinkRem = p.getProperty("test.recreate.dirlink.not.removed");
+ if (link1Rem != null) {
+ fail(link1Rem);
+ }
+ if (link2Rem != null) {
+ fail(link2Rem);
+ }
+ if (link3Rem != null) {
+ fail(link3Rem);
+ }
+ if (dirlinkRem != null) {
+ fail(dirlinkRem);
+ }
+ assertNotNull("Failed to recreate link1",
+ p.getProperty("test.recreate.link1.recreated"));
+ assertNotNull("Failed to recreate link2",
+ p.getProperty("test.recreate.link2.recreated"));
+ assertNotNull("Failed to recreate link3",
+ p.getProperty("test.recreate.link3.recreated"));
+ assertNotNull("Failed to recreate dirlink",
+ p.getProperty("test.recreate.dirlink.recreated"));
+
+ String doubleRecreate = p.getProperty("test.recreate.dirlink2.recreated.twice");
+
+ if (doubleRecreate != null) {
+ fail(doubleRecreate);
+ }
+
+ assertNotNull("Failed to alter dirlink3",
+ p.getProperty("test.recreate.dirlink3.was.altered"));
+ }
+
+ @Test
+ public void testSymbolicLinkUtilsMethods() throws Exception {
+
+ buildRule.executeTarget("test-fileutils");
+ SymbolicLinkUtils su = SymbolicLinkUtils.getSymbolicLinkUtils();
+
+ java.io.File f = new File(buildRule.getOutputDir(), "file1");
+ assertTrue(f.exists());
+ assertFalse(f.isDirectory());
+ assertTrue(f.isFile());
+ assertFalse(su.isSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isSymbolicLink(f.getParentFile(),
+ f.getName()));
+ assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
+ f.getName()));
+
+ f = new File(buildRule.getOutputDir(), "dir1");
+ assertTrue(f.exists());
+ assertTrue(f.isDirectory());
+ assertFalse(f.isFile());
+ assertFalse(su.isSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isSymbolicLink(f.getParentFile(),
+ f.getName()));
+ assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
+ f.getName()));
+
+ f = new File(buildRule.getOutputDir(), "file2");
+ assertFalse(f.exists());
+ assertFalse(f.isDirectory());
+ assertFalse(f.isFile());
+ assertFalse(su.isSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isSymbolicLink(f.getParentFile(),
+ f.getName()));
+ assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
+ f.getName()));
+
+ f = new File(buildRule.getOutputDir(), "dir2");
+ assertFalse(f.exists());
+ assertFalse(f.isDirectory());
+ assertFalse(f.isFile());
+ assertFalse(su.isSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isSymbolicLink(f.getParentFile(),
+ f.getName()));
+ assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
+ f.getName()));
+
+
+ f = new File(buildRule.getOutputDir(), "file.there");
+ assertTrue(f.exists());
+ assertFalse(f.isDirectory());
+ assertTrue(f.isFile());
+ assertTrue(su.isSymbolicLink(f.getAbsolutePath()));
+ assertTrue(su.isSymbolicLink(f.getParentFile(),
+ f.getName()));
+ assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
+ f.getName()));
+
+ f = new File(buildRule.getOutputDir(), "dir.there");
+ assertTrue(f.exists());
+ assertTrue(f.isDirectory());
+ assertFalse(f.isFile());
+ assertTrue(su.isSymbolicLink(f.getAbsolutePath()));
+ assertTrue(su.isSymbolicLink(f.getParentFile(),
+ f.getName()));
+ assertFalse(su.isDanglingSymbolicLink(f.getAbsolutePath()));
+ assertFalse(su.isDanglingSymbolicLink(f.getParentFile(),
+ f.getName()));
+
+ // it is not possible to find out that symbolic links pointing
+ // to inexistent files or directories are symbolic links
+ // it used to be possible to detect this on Mac
+ // this is not true under Snow Leopard and JDK 1.5
+ // Removing special handling of MacOS until someone shouts
+ // Antoine
+ f = new File(buildRule.getOutputDir(), "file.notthere");
+ assertFalse(f.exists());
+ assertFalse(f.isDirectory());
+ assertFalse(f.isFile());
+ assertTrue(su.isSymbolicLink(f.getAbsolutePath()) == false);
+ assertTrue(su.isSymbolicLink(f.getParentFile(), f.getName()) == false);
+ assertTrue(su.isDanglingSymbolicLink(f.getAbsolutePath()));
+ assertTrue(su.isDanglingSymbolicLink(f.getParentFile(),
+ f.getName()));
+
+ f = new File(buildRule.getOutputDir(), "dir.notthere");
+ assertFalse(f.exists());
+ assertFalse(f.isDirectory());
+ assertFalse(f.isFile());
+ assertTrue(su.isSymbolicLink(f.getAbsolutePath()) == false);
+ assertTrue(su.isSymbolicLink(f.getParentFile(), f.getName()) == false);
+ assertTrue(su.isDanglingSymbolicLink(f.getAbsolutePath()));
+ assertTrue(su.isDanglingSymbolicLink(f.getParentFile(),
+ f.getName()));
+
+ }
+
+ @After
+ public void tearDown() {
+ if (buildRule.getProject() != null) {
+ buildRule.executeTarget("tearDown");
+ }
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java
index aa96d8d51..88a08de2e 100644
--- a/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java
+++ b/src/tests/junit/org/apache/tools/ant/taskdefs/optional/vss/MSVSSTest.java
@@ -1,475 +1,475 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.taskdefs.optional.vss;
-
-import java.io.File;
-import java.text.SimpleDateFormat;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.TimeZone;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.Location;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.Tstamp;
-import org.apache.tools.ant.types.Commandline;
-import org.apache.tools.ant.types.Path;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-/**
- * Testcase to ensure that command line generation and required attributes are correct.
- *
- */
-public class MSVSSTest implements MSVSSConstants {
-
- private Commandline commandline;
-
- private static final String VSS_PROJECT_PATH = "/SourceRoot/Project";
- private static final String DS_VSS_PROJECT_PATH = "$/SourceRoot/Project";
- private static final String VSS_USERNAME = "ant";
- private static final String VSS_PASSWORD = "rocks";
- private static final String LOCAL_PATH = "testdir";
- private static final String SRC_LABEL = "label1";
- private static final String LONG_LABEL = "123456789012345678901234567890";
- private static final String SRC_COMMENT = "I fixed a bug";
- private static final String VERSION = "007";
- private static final String DATE = "00-00-00";
- private static final String DATE2 = "01-01-01";
- private static final String OUTPUT = "output.log";
- private static final String SS_DIR = "c:/winnt".replace('/', File.separatorChar);
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
- private Project project;
-
- @Before
- public void setUp(){
- project = new Project();
- project.setBasedir(".");
- project.init();
- }
-
- @After
- public void tearDown() {
- File file = new File(project.getBaseDir(), LOCAL_PATH);
- if (file.exists()) {
- file.delete();
- }
- }
-
- @Test
- public void testGetCommandLine() {
- String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_GET, DS_VSS_PROJECT_PATH,
- MSVSS.FLAG_OVERRIDE_WORKING_DIR + project.getBaseDir()
- .getAbsolutePath()
- + File.separator + LOCAL_PATH, MSVSS.FLAG_AUTORESPONSE_DEF,
- MSVSS.FLAG_RECURSION, MSVSS.FLAG_VERSION + VERSION, MSVSS.FLAG_LOGIN
- + VSS_USERNAME + "," + VSS_PASSWORD, FLAG_FILETIME_UPDATED, FLAG_SKIP_WRITABLE};
-
- // Set up a VSSGet task
- MSVSSGET vssGet = new MSVSSGET();
- vssGet.setProject(project);
- vssGet.setRecursive(true);
- vssGet.setLocalpath(new Path(project, LOCAL_PATH));
- vssGet.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
- vssGet.setVersion(VERSION);
- vssGet.setQuiet(false);
- vssGet.setDate(DATE);
- vssGet.setLabel(SRC_LABEL);
- vssGet.setVsspath(VSS_PROJECT_PATH);
- MSVSS.CurrentModUpdated cmu = new MSVSS.CurrentModUpdated();
- cmu.setValue(TIME_UPDATED);
- vssGet.setFileTimeStamp(cmu);
- MSVSS.WritableFiles wf = new MSVSS.WritableFiles();
- wf.setValue(WRITABLE_SKIP);
- vssGet.setWritableFiles(wf);
-
- commandline = vssGet.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /** Tests VSSGet required attributes. */
- @Test
- public void testGetExceptions() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
- expectSpecificBuildException("vssget.1", "some cause", "vsspath attribute must be set!");
- }
-
- /** Tests Label commandline generation. */
- @Test
- public void testLabelCommandLine1() {
- String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_LABEL, DS_VSS_PROJECT_PATH,
- MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_YES,
- MSVSS.FLAG_LABEL + SRC_LABEL, MSVSS.FLAG_VERSION + VERSION, MSVSS.FLAG_LOGIN
- + VSS_USERNAME + "," + VSS_PASSWORD};
-
- // Set up a VSSLabel task
- MSVSSLABEL vssLabel = new MSVSSLABEL();
- vssLabel.setProject(project);
- vssLabel.setComment(SRC_COMMENT);
- vssLabel.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
- vssLabel.setVersion(VERSION);
- vssLabel.setAutoresponse("Y");
- vssLabel.setLabel(SRC_LABEL);
- vssLabel.setVsspath(VSS_PROJECT_PATH);
-
- commandline = vssLabel.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /** Tests Label commandline generation with a label of more than 31 chars. */
- @Test
- public void testLabelCommandLine2() {
- String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_LABEL, DS_VSS_PROJECT_PATH,
- MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_DEF,
- MSVSS.FLAG_LABEL + LONG_LABEL,
- MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD};
-
- // Set up a VSSLabel task
- MSVSSLABEL vssLabel = new MSVSSLABEL();
- vssLabel.setProject(project);
- vssLabel.setComment(SRC_COMMENT);
- vssLabel.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
- vssLabel.setLabel(LONG_LABEL + "blahblah");
- vssLabel.setVsspath(VSS_PROJECT_PATH);
-
- commandline = vssLabel.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /**
- * Test VSSLabel required attributes.
- */
- @Test
- public void testLabelExceptions() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
- expectSpecificBuildException("vsslabel.1", "some cause", "vsspath attribute must be set!");
- expectSpecificBuildException("vsslabel.2", "some cause", "label attribute must be set!");
- }
-
- /** Tests VSSHistory commandline generation with from label. */
- @Test
- public void testHistoryCommandLine1() {
- String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH,
- MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_LABEL + LONG_LABEL
- + MSVSS.VALUE_FROMLABEL + SRC_LABEL, MSVSS.FLAG_LOGIN + VSS_USERNAME
- + "," + VSS_PASSWORD, MSVSS.FLAG_OUTPUT + project.getBaseDir()
- .getAbsolutePath()
- + File.separator + OUTPUT};
-
- // Set up a VSSHistory task
- MSVSSHISTORY vssHistory = new MSVSSHISTORY();
- vssHistory.setProject(project);
-
- vssHistory.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
-
- vssHistory.setFromLabel(SRC_LABEL);
- vssHistory.setToLabel(LONG_LABEL + "blahblah");
- vssHistory.setVsspath(VSS_PROJECT_PATH);
- vssHistory.setRecursive(false);
- vssHistory.setOutput(new File(project.getBaseDir().getAbsolutePath(), OUTPUT));
-
- commandline = vssHistory.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /** Tests VSSHistory commandline generation with from date. */
- @Test
- public void testHistoryCommandLine2() {
- String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH,
- MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_DATE + DATE + MSVSS.VALUE_FROMDATE
- + DATE2, MSVSS.FLAG_RECURSION, MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD};
-
- // Set up a VSSHistory task
- MSVSSHISTORY vssHistory = new MSVSSHISTORY();
- vssHistory.setProject(project);
- vssHistory.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
- vssHistory.setFromDate(DATE2);
- vssHistory.setToDate(DATE);
- vssHistory.setVsspath(VSS_PROJECT_PATH);
- vssHistory.setRecursive(true);
-
- commandline = vssHistory.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /** Tests VSSHistory commandline generation with date calculation. */
- @Test
- public void testHistoryCommandLine3() {
- // Set up a Timestamp
- Tstamp tstamp = new Tstamp();
- Location location = new Location("src/etc/testcases/taskdefs/optional/vss/vss.xml");
- tstamp.setLocation(location);
- tstamp.setProject(project);
- Tstamp.CustomFormat format = tstamp.createFormat();
- format.setProperty("today");
- format.setPattern("HH:mm:ss z");
- format.setTimezone("GMT");
- Date date = Calendar.getInstance().getTime();
- format.execute(project, date, location);
- String today = project.getProperty("today");
-
- // Get today's date
- SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss z");
- sdf.setTimeZone( TimeZone.getTimeZone("GMT") );
- String expected = sdf.format(date);
-
- // Set up a VSSHistory task
- MSVSSHISTORY vssHistory = new MSVSSHISTORY();
- vssHistory.setProject(project);
- vssHistory.setLogin(VSS_USERNAME);
- vssHistory.setToDate(today);
- vssHistory.setVsspath(VSS_PROJECT_PATH);
-
- String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH,
- MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_DATE + expected, MSVSS.FLAG_LOGIN + VSS_USERNAME};
-
- commandline = vssHistory.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /**
- * Tests VSSHistory required attributes.
- */
- @Test
- public void testHistoryExceptions() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
- expectSpecificBuildException("vsshistory.1", "some cause", "vsspath attribute must be set!");
- }
-
- private void expectSpecificBuildException(String target, String failMessage,
- String exceptionMessage) {
- try {
- buildRule.executeTarget(target);
- fail(failMessage);
- } catch(BuildException ex) {
- assertEquals(exceptionMessage, ex.getMessage());
- }
- }
-
- /** Tests CheckIn commandline generation. */
- @Test
- public void testCheckinCommandLine() {
- String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_CHECKIN, DS_VSS_PROJECT_PATH,
- MSVSS.FLAG_AUTORESPONSE_NO, MSVSS.FLAG_WRITABLE, MSVSS.FLAG_LOGIN + VSS_USERNAME,
- MSVSS.FLAG_COMMENT + SRC_COMMENT};
-
- // Set up a VSSCheckIn task
- MSVSSCHECKIN vssCheckin = new MSVSSCHECKIN();
- vssCheckin.setProject(project);
- vssCheckin.setComment(SRC_COMMENT);
- vssCheckin.setLogin(VSS_USERNAME);
- vssCheckin.setAutoresponse("N");
- vssCheckin.setVsspath(VSS_PROJECT_PATH);
- vssCheckin.setWritable(true);
-
- commandline = vssCheckin.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /**
- * Test VSSCheckIn required attributes.
- */
- @Test
- public void testCheckinExceptions() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
- expectSpecificBuildException("vsscheckin.1", "some cause", "vsspath attribute must be set!");
- }
-
- /** Tests CheckOut commandline generation. */
- @Test
- public void testCheckoutCommandLine() {
- String[] sTestCmdLine = {SS_DIR + File.separator + MSVSS.SS_EXE, MSVSS.COMMAND_CHECKOUT,
- DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_RECURSION,
- MSVSS.FLAG_VERSION_DATE + DATE, MSVSS.FLAG_LOGIN + VSS_USERNAME,
- FLAG_FILETIME_MODIFIED, FLAG_NO_GET};
-
- // Set up a VSSCheckOut task
- MSVSSCHECKOUT vssCheckout = new MSVSSCHECKOUT();
- vssCheckout.setProject(project);
- vssCheckout.setLogin(VSS_USERNAME);
- vssCheckout.setVsspath(DS_VSS_PROJECT_PATH);
- vssCheckout.setRecursive(true);
- vssCheckout.setDate(DATE);
- vssCheckout.setLabel(SRC_LABEL);
- vssCheckout.setSsdir(SS_DIR);
- MSVSS.CurrentModUpdated cmu = new MSVSS.CurrentModUpdated();
- cmu.setValue(TIME_MODIFIED);
- vssCheckout.setFileTimeStamp(cmu);
- vssCheckout.setGetLocalCopy(false);
-
- commandline = vssCheckout.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /**
- * Test VSSCheckout required attributes.
- */
- @Test
- public void testCheckoutExceptions() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
- expectSpecificBuildException("vsscheckout.1", "some cause", "vsspath attribute must be set!");
- expectSpecificBuildException("vsscheckout.2", "some cause", "blah is not a legal value for this attribute");
- }
-
- /** Tests Add commandline generation. */
- @Test
- public void testAddCommandLine() {
- String[] sTestCmdLine = {SS_DIR + File.separator + MSVSS.SS_EXE, MSVSS.COMMAND_ADD,
- project.getBaseDir().getAbsolutePath() + File.separator + LOCAL_PATH,
- MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_RECURSION,
- MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD, MSVSS.FLAG_COMMENT + "-"};
-
- // Set up a VSSAdd task
- MSVSSADD vssAdd = new MSVSSADD();
- vssAdd.setProject(project);
- vssAdd.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
- vssAdd.setVsspath(DS_VSS_PROJECT_PATH);
- vssAdd.setRecursive(true);
- vssAdd.setSsdir(SS_DIR);
- vssAdd.setWritable(false);
- vssAdd.setLocalpath(new Path(project, LOCAL_PATH));
-
- commandline = vssAdd.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /**
- * Test VSSAdd required attributes.
- */
- @Test
- public void testAddExceptions() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
- expectSpecificBuildException("vssadd.1", "some cause", "localPath attribute must be set!");
- }
-
- /** Tests CP commandline generation. */
- @Test
- public void testCpCommandLine() {
- String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_CP,
- DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_LOGIN +
- VSS_USERNAME};
-
- // Set up a VSSCp task
- MSVSSCP vssCp = new MSVSSCP();
- vssCp.setProject(project);
- vssCp.setLogin(VSS_USERNAME);
- vssCp.setVsspath(DS_VSS_PROJECT_PATH);
-
- commandline = vssCp.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /**
- * Test VSSCP required attributes.
- */
- @Test
- public void testCpExceptions() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
- expectSpecificBuildException("vsscp.1", "some cause", "vsspath attribute must be set!");
- }
-
- /** Tests Create commandline generation. */
- @Test
- public void testCreateCommandLine() {
- String[] sTestCmdLine = { MSVSS.SS_EXE, MSVSS.COMMAND_CREATE,
- DS_VSS_PROJECT_PATH, MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_NO,
- MSVSS.FLAG_QUIET, MSVSS.FLAG_LOGIN + VSS_USERNAME};
-
- // Set up a VSSCreate task
- MSVSSCREATE vssCreate = new MSVSSCREATE();
- vssCreate.setProject(project);
- vssCreate.setComment(SRC_COMMENT);
- vssCreate.setLogin(VSS_USERNAME);
- vssCreate.setVsspath(DS_VSS_PROJECT_PATH);
- vssCreate.setFailOnError(true);
- vssCreate.setAutoresponse("N");
- vssCreate.setQuiet(true);
-
- commandline = vssCreate.buildCmdLine();
-
- checkCommandLines(sTestCmdLine, commandline.getCommandline());
- }
-
- /**
- * Test VSSCreate required attributes.
- */
- @Test
- public void testCreateExceptions() {
- buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
- expectSpecificBuildException("vsscreate.1", "some cause", "vsspath attribute must be set!");
- }
-
- /**
- * Iterate through the generated command line comparing it to reference one.
- * @param sTestCmdLine The reference command line;
- * @param sGeneratedCmdLine The generated command line;
- */
- private void checkCommandLines(String[] sTestCmdLine, String[] sGeneratedCmdLine) {
- int testLength = sTestCmdLine.length;
- int genLength = sGeneratedCmdLine.length;
-
- int genIndex = 0;
- int testIndex = 0;
-
- while (testIndex < testLength) {
- try {
- if (sGeneratedCmdLine[genIndex].equals("")) {
- genIndex++;
- continue;
- }
- assertEquals("arg # " + testIndex,
- sTestCmdLine[testIndex],
- sGeneratedCmdLine[genIndex]);
- testIndex++;
- genIndex++;
- } catch (ArrayIndexOutOfBoundsException aioob) {
- fail("missing arg " + sTestCmdLine[testIndex]);
- }
- }
-
- // Count the number of empty strings
- int cnt = 0;
- for (int i = 0; i < genLength; i++) {
- if (sGeneratedCmdLine[i].equals("")) {
- cnt++;
- }
- }
- if (genLength - cnt > sTestCmdLine.length) {
- // We have extra elements
- fail("extra args");
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.taskdefs.optional.vss;
+
+import java.io.File;
+import java.text.SimpleDateFormat;
+import java.util.Calendar;
+import java.util.Date;
+import java.util.TimeZone;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.Location;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.Tstamp;
+import org.apache.tools.ant.types.Commandline;
+import org.apache.tools.ant.types.Path;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * Testcase to ensure that command line generation and required attributes are correct.
+ *
+ */
+public class MSVSSTest implements MSVSSConstants {
+
+ private Commandline commandline;
+
+ private static final String VSS_PROJECT_PATH = "/SourceRoot/Project";
+ private static final String DS_VSS_PROJECT_PATH = "$/SourceRoot/Project";
+ private static final String VSS_USERNAME = "ant";
+ private static final String VSS_PASSWORD = "rocks";
+ private static final String LOCAL_PATH = "testdir";
+ private static final String SRC_LABEL = "label1";
+ private static final String LONG_LABEL = "123456789012345678901234567890";
+ private static final String SRC_COMMENT = "I fixed a bug";
+ private static final String VERSION = "007";
+ private static final String DATE = "00-00-00";
+ private static final String DATE2 = "01-01-01";
+ private static final String OUTPUT = "output.log";
+ private static final String SS_DIR = "c:/winnt".replace('/', File.separatorChar);
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+ private Project project;
+
+ @Before
+ public void setUp(){
+ project = new Project();
+ project.setBasedir(".");
+ project.init();
+ }
+
+ @After
+ public void tearDown() {
+ File file = new File(project.getBaseDir(), LOCAL_PATH);
+ if (file.exists()) {
+ file.delete();
+ }
+ }
+
+ @Test
+ public void testGetCommandLine() {
+ String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_GET, DS_VSS_PROJECT_PATH,
+ MSVSS.FLAG_OVERRIDE_WORKING_DIR + project.getBaseDir()
+ .getAbsolutePath()
+ + File.separator + LOCAL_PATH, MSVSS.FLAG_AUTORESPONSE_DEF,
+ MSVSS.FLAG_RECURSION, MSVSS.FLAG_VERSION + VERSION, MSVSS.FLAG_LOGIN
+ + VSS_USERNAME + "," + VSS_PASSWORD, FLAG_FILETIME_UPDATED, FLAG_SKIP_WRITABLE};
+
+ // Set up a VSSGet task
+ MSVSSGET vssGet = new MSVSSGET();
+ vssGet.setProject(project);
+ vssGet.setRecursive(true);
+ vssGet.setLocalpath(new Path(project, LOCAL_PATH));
+ vssGet.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
+ vssGet.setVersion(VERSION);
+ vssGet.setQuiet(false);
+ vssGet.setDate(DATE);
+ vssGet.setLabel(SRC_LABEL);
+ vssGet.setVsspath(VSS_PROJECT_PATH);
+ MSVSS.CurrentModUpdated cmu = new MSVSS.CurrentModUpdated();
+ cmu.setValue(TIME_UPDATED);
+ vssGet.setFileTimeStamp(cmu);
+ MSVSS.WritableFiles wf = new MSVSS.WritableFiles();
+ wf.setValue(WRITABLE_SKIP);
+ vssGet.setWritableFiles(wf);
+
+ commandline = vssGet.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /** Tests VSSGet required attributes. */
+ @Test
+ public void testGetExceptions() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
+ expectSpecificBuildException("vssget.1", "some cause", "vsspath attribute must be set!");
+ }
+
+ /** Tests Label commandline generation. */
+ @Test
+ public void testLabelCommandLine1() {
+ String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_LABEL, DS_VSS_PROJECT_PATH,
+ MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_YES,
+ MSVSS.FLAG_LABEL + SRC_LABEL, MSVSS.FLAG_VERSION + VERSION, MSVSS.FLAG_LOGIN
+ + VSS_USERNAME + "," + VSS_PASSWORD};
+
+ // Set up a VSSLabel task
+ MSVSSLABEL vssLabel = new MSVSSLABEL();
+ vssLabel.setProject(project);
+ vssLabel.setComment(SRC_COMMENT);
+ vssLabel.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
+ vssLabel.setVersion(VERSION);
+ vssLabel.setAutoresponse("Y");
+ vssLabel.setLabel(SRC_LABEL);
+ vssLabel.setVsspath(VSS_PROJECT_PATH);
+
+ commandline = vssLabel.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /** Tests Label commandline generation with a label of more than 31 chars. */
+ @Test
+ public void testLabelCommandLine2() {
+ String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_LABEL, DS_VSS_PROJECT_PATH,
+ MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_DEF,
+ MSVSS.FLAG_LABEL + LONG_LABEL,
+ MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD};
+
+ // Set up a VSSLabel task
+ MSVSSLABEL vssLabel = new MSVSSLABEL();
+ vssLabel.setProject(project);
+ vssLabel.setComment(SRC_COMMENT);
+ vssLabel.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
+ vssLabel.setLabel(LONG_LABEL + "blahblah");
+ vssLabel.setVsspath(VSS_PROJECT_PATH);
+
+ commandline = vssLabel.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /**
+ * Test VSSLabel required attributes.
+ */
+ @Test
+ public void testLabelExceptions() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
+ expectSpecificBuildException("vsslabel.1", "some cause", "vsspath attribute must be set!");
+ expectSpecificBuildException("vsslabel.2", "some cause", "label attribute must be set!");
+ }
+
+ /** Tests VSSHistory commandline generation with from label. */
+ @Test
+ public void testHistoryCommandLine1() {
+ String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH,
+ MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_LABEL + LONG_LABEL
+ + MSVSS.VALUE_FROMLABEL + SRC_LABEL, MSVSS.FLAG_LOGIN + VSS_USERNAME
+ + "," + VSS_PASSWORD, MSVSS.FLAG_OUTPUT + project.getBaseDir()
+ .getAbsolutePath()
+ + File.separator + OUTPUT};
+
+ // Set up a VSSHistory task
+ MSVSSHISTORY vssHistory = new MSVSSHISTORY();
+ vssHistory.setProject(project);
+
+ vssHistory.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
+
+ vssHistory.setFromLabel(SRC_LABEL);
+ vssHistory.setToLabel(LONG_LABEL + "blahblah");
+ vssHistory.setVsspath(VSS_PROJECT_PATH);
+ vssHistory.setRecursive(false);
+ vssHistory.setOutput(new File(project.getBaseDir().getAbsolutePath(), OUTPUT));
+
+ commandline = vssHistory.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /** Tests VSSHistory commandline generation with from date. */
+ @Test
+ public void testHistoryCommandLine2() {
+ String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH,
+ MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_DATE + DATE + MSVSS.VALUE_FROMDATE
+ + DATE2, MSVSS.FLAG_RECURSION, MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD};
+
+ // Set up a VSSHistory task
+ MSVSSHISTORY vssHistory = new MSVSSHISTORY();
+ vssHistory.setProject(project);
+ vssHistory.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
+ vssHistory.setFromDate(DATE2);
+ vssHistory.setToDate(DATE);
+ vssHistory.setVsspath(VSS_PROJECT_PATH);
+ vssHistory.setRecursive(true);
+
+ commandline = vssHistory.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /** Tests VSSHistory commandline generation with date calculation. */
+ @Test
+ public void testHistoryCommandLine3() {
+ // Set up a Timestamp
+ Tstamp tstamp = new Tstamp();
+ Location location = new Location("src/etc/testcases/taskdefs/optional/vss/vss.xml");
+ tstamp.setLocation(location);
+ tstamp.setProject(project);
+ Tstamp.CustomFormat format = tstamp.createFormat();
+ format.setProperty("today");
+ format.setPattern("HH:mm:ss z");
+ format.setTimezone("GMT");
+ Date date = Calendar.getInstance().getTime();
+ format.execute(project, date, location);
+ String today = project.getProperty("today");
+
+ // Get today's date
+ SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss z");
+ sdf.setTimeZone( TimeZone.getTimeZone("GMT") );
+ String expected = sdf.format(date);
+
+ // Set up a VSSHistory task
+ MSVSSHISTORY vssHistory = new MSVSSHISTORY();
+ vssHistory.setProject(project);
+ vssHistory.setLogin(VSS_USERNAME);
+ vssHistory.setToDate(today);
+ vssHistory.setVsspath(VSS_PROJECT_PATH);
+
+ String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_HISTORY, DS_VSS_PROJECT_PATH,
+ MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_VERSION_DATE + expected, MSVSS.FLAG_LOGIN + VSS_USERNAME};
+
+ commandline = vssHistory.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /**
+ * Tests VSSHistory required attributes.
+ */
+ @Test
+ public void testHistoryExceptions() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
+ expectSpecificBuildException("vsshistory.1", "some cause", "vsspath attribute must be set!");
+ }
+
+ private void expectSpecificBuildException(String target, String failMessage,
+ String exceptionMessage) {
+ try {
+ buildRule.executeTarget(target);
+ fail(failMessage);
+ } catch(BuildException ex) {
+ assertEquals(exceptionMessage, ex.getMessage());
+ }
+ }
+
+ /** Tests CheckIn commandline generation. */
+ @Test
+ public void testCheckinCommandLine() {
+ String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_CHECKIN, DS_VSS_PROJECT_PATH,
+ MSVSS.FLAG_AUTORESPONSE_NO, MSVSS.FLAG_WRITABLE, MSVSS.FLAG_LOGIN + VSS_USERNAME,
+ MSVSS.FLAG_COMMENT + SRC_COMMENT};
+
+ // Set up a VSSCheckIn task
+ MSVSSCHECKIN vssCheckin = new MSVSSCHECKIN();
+ vssCheckin.setProject(project);
+ vssCheckin.setComment(SRC_COMMENT);
+ vssCheckin.setLogin(VSS_USERNAME);
+ vssCheckin.setAutoresponse("N");
+ vssCheckin.setVsspath(VSS_PROJECT_PATH);
+ vssCheckin.setWritable(true);
+
+ commandline = vssCheckin.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /**
+ * Test VSSCheckIn required attributes.
+ */
+ @Test
+ public void testCheckinExceptions() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
+ expectSpecificBuildException("vsscheckin.1", "some cause", "vsspath attribute must be set!");
+ }
+
+ /** Tests CheckOut commandline generation. */
+ @Test
+ public void testCheckoutCommandLine() {
+ String[] sTestCmdLine = {SS_DIR + File.separator + MSVSS.SS_EXE, MSVSS.COMMAND_CHECKOUT,
+ DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_RECURSION,
+ MSVSS.FLAG_VERSION_DATE + DATE, MSVSS.FLAG_LOGIN + VSS_USERNAME,
+ FLAG_FILETIME_MODIFIED, FLAG_NO_GET};
+
+ // Set up a VSSCheckOut task
+ MSVSSCHECKOUT vssCheckout = new MSVSSCHECKOUT();
+ vssCheckout.setProject(project);
+ vssCheckout.setLogin(VSS_USERNAME);
+ vssCheckout.setVsspath(DS_VSS_PROJECT_PATH);
+ vssCheckout.setRecursive(true);
+ vssCheckout.setDate(DATE);
+ vssCheckout.setLabel(SRC_LABEL);
+ vssCheckout.setSsdir(SS_DIR);
+ MSVSS.CurrentModUpdated cmu = new MSVSS.CurrentModUpdated();
+ cmu.setValue(TIME_MODIFIED);
+ vssCheckout.setFileTimeStamp(cmu);
+ vssCheckout.setGetLocalCopy(false);
+
+ commandline = vssCheckout.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /**
+ * Test VSSCheckout required attributes.
+ */
+ @Test
+ public void testCheckoutExceptions() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
+ expectSpecificBuildException("vsscheckout.1", "some cause", "vsspath attribute must be set!");
+ expectSpecificBuildException("vsscheckout.2", "some cause", "blah is not a legal value for this attribute");
+ }
+
+ /** Tests Add commandline generation. */
+ @Test
+ public void testAddCommandLine() {
+ String[] sTestCmdLine = {SS_DIR + File.separator + MSVSS.SS_EXE, MSVSS.COMMAND_ADD,
+ project.getBaseDir().getAbsolutePath() + File.separator + LOCAL_PATH,
+ MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_RECURSION,
+ MSVSS.FLAG_LOGIN + VSS_USERNAME + "," + VSS_PASSWORD, MSVSS.FLAG_COMMENT + "-"};
+
+ // Set up a VSSAdd task
+ MSVSSADD vssAdd = new MSVSSADD();
+ vssAdd.setProject(project);
+ vssAdd.setLogin(VSS_USERNAME + "," + VSS_PASSWORD);
+ vssAdd.setVsspath(DS_VSS_PROJECT_PATH);
+ vssAdd.setRecursive(true);
+ vssAdd.setSsdir(SS_DIR);
+ vssAdd.setWritable(false);
+ vssAdd.setLocalpath(new Path(project, LOCAL_PATH));
+
+ commandline = vssAdd.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /**
+ * Test VSSAdd required attributes.
+ */
+ @Test
+ public void testAddExceptions() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
+ expectSpecificBuildException("vssadd.1", "some cause", "localPath attribute must be set!");
+ }
+
+ /** Tests CP commandline generation. */
+ @Test
+ public void testCpCommandLine() {
+ String[] sTestCmdLine = {MSVSS.SS_EXE, MSVSS.COMMAND_CP,
+ DS_VSS_PROJECT_PATH, MSVSS.FLAG_AUTORESPONSE_DEF, MSVSS.FLAG_LOGIN +
+ VSS_USERNAME};
+
+ // Set up a VSSCp task
+ MSVSSCP vssCp = new MSVSSCP();
+ vssCp.setProject(project);
+ vssCp.setLogin(VSS_USERNAME);
+ vssCp.setVsspath(DS_VSS_PROJECT_PATH);
+
+ commandline = vssCp.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /**
+ * Test VSSCP required attributes.
+ */
+ @Test
+ public void testCpExceptions() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
+ expectSpecificBuildException("vsscp.1", "some cause", "vsspath attribute must be set!");
+ }
+
+ /** Tests Create commandline generation. */
+ @Test
+ public void testCreateCommandLine() {
+ String[] sTestCmdLine = { MSVSS.SS_EXE, MSVSS.COMMAND_CREATE,
+ DS_VSS_PROJECT_PATH, MSVSS.FLAG_COMMENT + SRC_COMMENT, MSVSS.FLAG_AUTORESPONSE_NO,
+ MSVSS.FLAG_QUIET, MSVSS.FLAG_LOGIN + VSS_USERNAME};
+
+ // Set up a VSSCreate task
+ MSVSSCREATE vssCreate = new MSVSSCREATE();
+ vssCreate.setProject(project);
+ vssCreate.setComment(SRC_COMMENT);
+ vssCreate.setLogin(VSS_USERNAME);
+ vssCreate.setVsspath(DS_VSS_PROJECT_PATH);
+ vssCreate.setFailOnError(true);
+ vssCreate.setAutoresponse("N");
+ vssCreate.setQuiet(true);
+
+ commandline = vssCreate.buildCmdLine();
+
+ checkCommandLines(sTestCmdLine, commandline.getCommandline());
+ }
+
+ /**
+ * Test VSSCreate required attributes.
+ */
+ @Test
+ public void testCreateExceptions() {
+ buildRule.configureProject("src/etc/testcases/taskdefs/optional/vss/vss.xml");
+ expectSpecificBuildException("vsscreate.1", "some cause", "vsspath attribute must be set!");
+ }
+
+ /**
+ * Iterate through the generated command line comparing it to reference one.
+ * @param sTestCmdLine The reference command line;
+ * @param sGeneratedCmdLine The generated command line;
+ */
+ private void checkCommandLines(String[] sTestCmdLine, String[] sGeneratedCmdLine) {
+ int testLength = sTestCmdLine.length;
+ int genLength = sGeneratedCmdLine.length;
+
+ int genIndex = 0;
+ int testIndex = 0;
+
+ while (testIndex < testLength) {
+ try {
+ if (sGeneratedCmdLine[genIndex].equals("")) {
+ genIndex++;
+ continue;
+ }
+ assertEquals("arg # " + testIndex,
+ sTestCmdLine[testIndex],
+ sGeneratedCmdLine[genIndex]);
+ testIndex++;
+ genIndex++;
+ } catch (ArrayIndexOutOfBoundsException aioob) {
+ fail("missing arg " + sTestCmdLine[testIndex]);
+ }
+ }
+
+ // Count the number of empty strings
+ int cnt = 0;
+ for (int i = 0; i < genLength; i++) {
+ if (sGeneratedCmdLine[i].equals("")) {
+ cnt++;
+ }
+ }
+ if (genLength - cnt > sTestCmdLine.length) {
+ // We have extra elements
+ fail("extra args");
+ }
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/AbstractFileSetTest.java b/src/tests/junit/org/apache/tools/ant/types/AbstractFileSetTest.java
index aa4fd39c3..f344b155b 100644
--- a/src/tests/junit/org/apache/tools/ant/types/AbstractFileSetTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/AbstractFileSetTest.java
@@ -1,248 +1,248 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types;
-
-import java.io.File;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-/**
- * Base class for FileSetTest and DirSetTest.
- *
- *
This doesn't actually test much, mainly reference handling.
- *
- */
-
-public abstract class AbstractFileSetTest {
-
- private Project project;
-
-
- @Before
- public void setUp() {
- project = new Project();
- project.setBasedir(".");
- }
-
- protected abstract AbstractFileSet getInstance();
-
- protected final Project getProject() {
- return project;
- }
-
- @Test
- public final void testEmptyElementIfIsReference() {
- AbstractFileSet f = getInstance();
- f.setIncludes("**/*.java");
- try {
- f.setRefid(new Reference(getProject(), "dummyref"));
- fail("Can add reference to "
- + f.getDataTypeName()
- + " with elements from setIncludes");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute "
- + "when using refid", be.getMessage());
- }
-
- f = getInstance();
- f.createPatternSet();
- try {
- f.setRefid(new Reference(getProject(), "dummyref"));
- fail("Can add reference to "
- + f.getDataTypeName()
- + " with nested patternset element.");
- } catch (BuildException be) {
- assertEquals("You must not specify nested elements when "
- + "using refid", be.getMessage());
- }
-
- f = getInstance();
- f.createInclude();
- try {
- f.setRefid(new Reference(getProject(), "dummyref"));
- fail("Can add reference to "
- + f.getDataTypeName()
- + " with nested include element.");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute "
- + "when using refid", be.getMessage());
- }
-
- f = getInstance();
- f.setRefid(new Reference(getProject(), "dummyref"));
- try {
- f.setIncludes("**/*.java");
- fail("Can set includes in "
- + f.getDataTypeName()
- + " that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute "
- + "when using refid", be.getMessage());
- }
- try {
- f.setIncludesfile(new File("/a"));
- fail("Can set includesfile in "
- + f.getDataTypeName()
- + " that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute "
- + "when using refid", be.getMessage());
- }
- try {
- f.setExcludes("**/*.java");
- fail("Can set excludes in "
- + f.getDataTypeName()
- + " that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute "
- + "when using refid", be.getMessage());
- }
- try {
- f.setExcludesfile(new File("/a"));
- fail("Can set excludesfile in "
- + f.getDataTypeName()
- + " that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute "
- + "when using refid", be.getMessage());
- }
- try {
- f.setDir(project.resolveFile("."));
- fail("Can set dir in "
- + f.getDataTypeName()
- + " that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute "
- + "when using refid", be.getMessage());
- }
- try {
- f.createInclude();
- fail("Can add nested include in "
- + f.getDataTypeName()
- + " that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify nested elements when using "
- + "refid", be.getMessage());
- }
- try {
- f.createExclude();
- fail("Can add nested exclude in "
- + f.getDataTypeName()
- + " that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify nested elements when using "
- + "refid", be.getMessage());
- }
- try {
- f.createIncludesFile();
- fail("Can add nested includesfile in "
- + f.getDataTypeName()
- + " that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify nested elements when using "
- + "refid", be.getMessage());
- }
- try {
- f.createExcludesFile();
- fail("Can add nested excludesfile in "
- + f.getDataTypeName()
- + " that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify nested elements when using "
- + "refid", be.getMessage());
- }
- try {
- f.createPatternSet();
- fail("Can add nested patternset in "
- + f.getDataTypeName()
- + " that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify nested elements when using "
- + "refid", be.getMessage());
- }
- }
-
- @Test
- public void testCircularReferenceCheck() {
- AbstractFileSet f = getInstance();
- project.addReference("dummy", f);
- f.setRefid(new Reference(getProject(), "dummy"));
- try {
- f.getDir(project);
- fail("Can make " + f.getDataTypeName()
- + " a Reference to itself.");
- } catch (BuildException be) {
- assertEquals("This data type contains a circular reference.",
- be.getMessage());
- }
- try {
- f.getDirectoryScanner(project);
- fail("Can make " + f.getDataTypeName()
- + " a Reference to itself.");
- } catch (BuildException be) {
- assertEquals("This data type contains a circular reference.",
- be.getMessage());
- }
-
- // dummy1 --> dummy2 --> dummy3 --> dummy1
- AbstractFileSet f1 = getInstance();
- project.addReference("dummy1", f1);
- f1.setRefid(new Reference(getProject(), "dummy2"));
- AbstractFileSet f2 = getInstance();
- project.addReference("dummy2", f2);
- f2.setRefid(new Reference(getProject(), "dummy3"));
- AbstractFileSet f3 = getInstance();
- project.addReference("dummy3", f3);
- f3.setRefid(new Reference(getProject(), "dummy1"));
- try {
- f1.getDir(project);
- fail("Can make circular reference.");
- } catch (BuildException be) {
- assertEquals("This data type contains a circular reference.",
- be.getMessage());
- }
- try {
- f1.getDirectoryScanner(project);
- fail("Can make circular reference.");
- } catch (BuildException be) {
- assertEquals("This data type contains a circular reference.",
- be.getMessage());
- }
-
- // dummy1 --> dummy2 --> dummy3
- // (which has the Project's basedir as root).
- f1 = getInstance();
- project.addReference("dummy1", f1);
- f1.setRefid(new Reference(getProject(), "dummy2"));
- f2 = getInstance();
- project.addReference("dummy2", f2);
- f2.setRefid(new Reference(getProject(), "dummy3"));
- f3 = getInstance();
- project.addReference("dummy3", f3);
- f3.setDir(project.resolveFile("."));
- File dir = f1.getDir(project);
- assertEquals("Dir is basedir", dir, project.getBaseDir());
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types;
+
+import java.io.File;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * Base class for FileSetTest and DirSetTest.
+ *
+ *
This doesn't actually test much, mainly reference handling.
+ *
+ */
+
+public abstract class AbstractFileSetTest {
+
+ private Project project;
+
+
+ @Before
+ public void setUp() {
+ project = new Project();
+ project.setBasedir(".");
+ }
+
+ protected abstract AbstractFileSet getInstance();
+
+ protected final Project getProject() {
+ return project;
+ }
+
+ @Test
+ public final void testEmptyElementIfIsReference() {
+ AbstractFileSet f = getInstance();
+ f.setIncludes("**/*.java");
+ try {
+ f.setRefid(new Reference(getProject(), "dummyref"));
+ fail("Can add reference to "
+ + f.getDataTypeName()
+ + " with elements from setIncludes");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute "
+ + "when using refid", be.getMessage());
+ }
+
+ f = getInstance();
+ f.createPatternSet();
+ try {
+ f.setRefid(new Reference(getProject(), "dummyref"));
+ fail("Can add reference to "
+ + f.getDataTypeName()
+ + " with nested patternset element.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify nested elements when "
+ + "using refid", be.getMessage());
+ }
+
+ f = getInstance();
+ f.createInclude();
+ try {
+ f.setRefid(new Reference(getProject(), "dummyref"));
+ fail("Can add reference to "
+ + f.getDataTypeName()
+ + " with nested include element.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute "
+ + "when using refid", be.getMessage());
+ }
+
+ f = getInstance();
+ f.setRefid(new Reference(getProject(), "dummyref"));
+ try {
+ f.setIncludes("**/*.java");
+ fail("Can set includes in "
+ + f.getDataTypeName()
+ + " that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute "
+ + "when using refid", be.getMessage());
+ }
+ try {
+ f.setIncludesfile(new File("/a"));
+ fail("Can set includesfile in "
+ + f.getDataTypeName()
+ + " that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute "
+ + "when using refid", be.getMessage());
+ }
+ try {
+ f.setExcludes("**/*.java");
+ fail("Can set excludes in "
+ + f.getDataTypeName()
+ + " that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute "
+ + "when using refid", be.getMessage());
+ }
+ try {
+ f.setExcludesfile(new File("/a"));
+ fail("Can set excludesfile in "
+ + f.getDataTypeName()
+ + " that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute "
+ + "when using refid", be.getMessage());
+ }
+ try {
+ f.setDir(project.resolveFile("."));
+ fail("Can set dir in "
+ + f.getDataTypeName()
+ + " that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute "
+ + "when using refid", be.getMessage());
+ }
+ try {
+ f.createInclude();
+ fail("Can add nested include in "
+ + f.getDataTypeName()
+ + " that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify nested elements when using "
+ + "refid", be.getMessage());
+ }
+ try {
+ f.createExclude();
+ fail("Can add nested exclude in "
+ + f.getDataTypeName()
+ + " that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify nested elements when using "
+ + "refid", be.getMessage());
+ }
+ try {
+ f.createIncludesFile();
+ fail("Can add nested includesfile in "
+ + f.getDataTypeName()
+ + " that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify nested elements when using "
+ + "refid", be.getMessage());
+ }
+ try {
+ f.createExcludesFile();
+ fail("Can add nested excludesfile in "
+ + f.getDataTypeName()
+ + " that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify nested elements when using "
+ + "refid", be.getMessage());
+ }
+ try {
+ f.createPatternSet();
+ fail("Can add nested patternset in "
+ + f.getDataTypeName()
+ + " that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify nested elements when using "
+ + "refid", be.getMessage());
+ }
+ }
+
+ @Test
+ public void testCircularReferenceCheck() {
+ AbstractFileSet f = getInstance();
+ project.addReference("dummy", f);
+ f.setRefid(new Reference(getProject(), "dummy"));
+ try {
+ f.getDir(project);
+ fail("Can make " + f.getDataTypeName()
+ + " a Reference to itself.");
+ } catch (BuildException be) {
+ assertEquals("This data type contains a circular reference.",
+ be.getMessage());
+ }
+ try {
+ f.getDirectoryScanner(project);
+ fail("Can make " + f.getDataTypeName()
+ + " a Reference to itself.");
+ } catch (BuildException be) {
+ assertEquals("This data type contains a circular reference.",
+ be.getMessage());
+ }
+
+ // dummy1 --> dummy2 --> dummy3 --> dummy1
+ AbstractFileSet f1 = getInstance();
+ project.addReference("dummy1", f1);
+ f1.setRefid(new Reference(getProject(), "dummy2"));
+ AbstractFileSet f2 = getInstance();
+ project.addReference("dummy2", f2);
+ f2.setRefid(new Reference(getProject(), "dummy3"));
+ AbstractFileSet f3 = getInstance();
+ project.addReference("dummy3", f3);
+ f3.setRefid(new Reference(getProject(), "dummy1"));
+ try {
+ f1.getDir(project);
+ fail("Can make circular reference.");
+ } catch (BuildException be) {
+ assertEquals("This data type contains a circular reference.",
+ be.getMessage());
+ }
+ try {
+ f1.getDirectoryScanner(project);
+ fail("Can make circular reference.");
+ } catch (BuildException be) {
+ assertEquals("This data type contains a circular reference.",
+ be.getMessage());
+ }
+
+ // dummy1 --> dummy2 --> dummy3
+ // (which has the Project's basedir as root).
+ f1 = getInstance();
+ project.addReference("dummy1", f1);
+ f1.setRefid(new Reference(getProject(), "dummy2"));
+ f2 = getInstance();
+ project.addReference("dummy2", f2);
+ f2.setRefid(new Reference(getProject(), "dummy3"));
+ f3 = getInstance();
+ project.addReference("dummy3", f3);
+ f3.setDir(project.resolveFile("."));
+ File dir = f1.getDir(project);
+ assertEquals("Dir is basedir", dir, project.getBaseDir());
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/AddTypeTest.java b/src/tests/junit/org/apache/tools/ant/types/AddTypeTest.java
index 6c91a9afa..c037b0aa5 100644
--- a/src/tests/junit/org/apache/tools/ant/types/AddTypeTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/AddTypeTest.java
@@ -1,223 +1,223 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types;
-
-import org.apache.tools.ant.AntAssert;
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.taskdefs.condition.Condition;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.fail;
-
-public class AddTypeTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/types/addtype.xml");
- }
-
- @Test
- public void testAddPath() {
- buildRule.executeTarget("addpath");
- }
-
- @Test
- public void testAddCondition() {
- buildRule.executeTarget("addcondition");
- }
-
- @Test
- public void testAddFilter() {
- buildRule.executeTarget("addfilter");
- }
-
- @Test
- public void testAddSelector() {
- buildRule.executeTarget("addselector");
- }
-
- @Test
- public void testNestedA() {
- buildRule.executeTarget("nested.a");
- AntAssert.assertContains("add A called", buildRule.getLog());
- }
-
- @Test
- public void testNestedB() {
- buildRule.executeTarget("nested.b");
- AntAssert.assertContains( "add B called", buildRule.getLog());
- }
-
- @Test
- public void testNestedC() {
- buildRule.executeTarget("nested.c");
- AntAssert.assertContains( "add C called", buildRule.getLog());
- }
-
- @Test
- public void testNestedAB() {
- try {
- buildRule.executeTarget("nested.ab");
- fail("Build exception expected: Should have got ambiguous");
- } catch (BuildException ex) {
- AntAssert.assertContains("ambiguous", ex.getMessage());
- }
- }
-
- @Test
- public void testConditionType() {
- buildRule.executeTarget("condition.type");
- AntAssert.assertContains( "beforeafter", buildRule.getLog());
- }
-
- @Test
- public void testConditionTask() {
- buildRule.executeTarget("condition.task");
- AntAssert.assertContains( "My Condition execution", buildRule.getLog());
- }
-
- @Test
- public void testConditionConditionType() {
- buildRule.executeTarget("condition.condition.type");
- AntAssert.assertContains( "My Condition eval", buildRule.getLog());
- }
-
- @Test
- public void testConditionConditionTask() {
- try {
- buildRule.executeTarget("condition.condition.task");
- fail("Build exception expected: Task masking condition");
- } catch (BuildException ex) {
- AntAssert.assertContains("doesn't support the nested", ex.getMessage());
- }
- }
-
- @Test
- public void testAddConfigured() {
- buildRule.executeTarget("myaddconfigured");
- AntAssert.assertContains("value is Value Setexecute: value is Value Set",
- buildRule.getLog());
- }
-
- @Test
- public void testAddConfiguredValue() {
- buildRule.executeTarget("myaddconfiguredvalue");
- AntAssert.assertContains("value is Value Setexecute: value is Value Set",
- buildRule.getLog());
- }
-
- @Test
- public void testNamespace() {
- buildRule.executeTarget("namespacetest");
- }
-
- // The following will be used as types and tasks
-
- public static interface A {}
- public static interface B {}
- public static interface C extends A {}
- public static interface AB extends A, B {}
-
- public static class AImpl implements A{}
- public static class BImpl implements B{}
- public static class CImpl implements C{}
- public static class ABImpl implements AB{}
-
- public static class NestedContainer
- extends Task
- {
- public void add(A el) {
- log("add A called");
- }
- public void add(B el) {
- log("add B called");
- }
- public void add(C el) {
- log("add C called");
- }
- }
-
- public static class MyCondition
- implements Condition
- {
- Project project;
- public void setProject(Project project) {
- this.project = project;
- }
- public boolean eval() {
- project.log("My Condition eval");
- return true;
- }
- public void execute() {
- project.log("My Condition execution");
- }
- }
-
- public static class MyValue
- {
- private String text = "NOT SET YET";
- public void addText(String text) {
- this.text = text;
- }
- public String toString() {
- return text;
- }
- }
-
- public static class MyAddConfigured
- extends Task
- {
- MyValue value;
- public void addConfigured(MyValue value) {
- log("value is " + value);
- this.value = value;
- }
- public void add(MyValue value) {
- throw new BuildException("Should not be called");
- }
- public void execute() {
- log("execute: value is " + value);
- }
- }
-
- public static class MyAddConfiguredValue
- extends Task
- {
- MyValue value;
- public void addConfiguredValue(MyValue value) {
- log("value is " + value);
- this.value = value;
- }
- public void addValue(MyValue value) {
- throw new BuildException("Should not be called");
- }
- public void execute() {
- log("execute: value is " + value);
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types;
+
+import org.apache.tools.ant.AntAssert;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.apache.tools.ant.taskdefs.condition.Condition;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+public class AddTypeTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/types/addtype.xml");
+ }
+
+ @Test
+ public void testAddPath() {
+ buildRule.executeTarget("addpath");
+ }
+
+ @Test
+ public void testAddCondition() {
+ buildRule.executeTarget("addcondition");
+ }
+
+ @Test
+ public void testAddFilter() {
+ buildRule.executeTarget("addfilter");
+ }
+
+ @Test
+ public void testAddSelector() {
+ buildRule.executeTarget("addselector");
+ }
+
+ @Test
+ public void testNestedA() {
+ buildRule.executeTarget("nested.a");
+ AntAssert.assertContains("add A called", buildRule.getLog());
+ }
+
+ @Test
+ public void testNestedB() {
+ buildRule.executeTarget("nested.b");
+ AntAssert.assertContains( "add B called", buildRule.getLog());
+ }
+
+ @Test
+ public void testNestedC() {
+ buildRule.executeTarget("nested.c");
+ AntAssert.assertContains( "add C called", buildRule.getLog());
+ }
+
+ @Test
+ public void testNestedAB() {
+ try {
+ buildRule.executeTarget("nested.ab");
+ fail("Build exception expected: Should have got ambiguous");
+ } catch (BuildException ex) {
+ AntAssert.assertContains("ambiguous", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testConditionType() {
+ buildRule.executeTarget("condition.type");
+ AntAssert.assertContains( "beforeafter", buildRule.getLog());
+ }
+
+ @Test
+ public void testConditionTask() {
+ buildRule.executeTarget("condition.task");
+ AntAssert.assertContains( "My Condition execution", buildRule.getLog());
+ }
+
+ @Test
+ public void testConditionConditionType() {
+ buildRule.executeTarget("condition.condition.type");
+ AntAssert.assertContains( "My Condition eval", buildRule.getLog());
+ }
+
+ @Test
+ public void testConditionConditionTask() {
+ try {
+ buildRule.executeTarget("condition.condition.task");
+ fail("Build exception expected: Task masking condition");
+ } catch (BuildException ex) {
+ AntAssert.assertContains("doesn't support the nested", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testAddConfigured() {
+ buildRule.executeTarget("myaddconfigured");
+ AntAssert.assertContains("value is Value Setexecute: value is Value Set",
+ buildRule.getLog());
+ }
+
+ @Test
+ public void testAddConfiguredValue() {
+ buildRule.executeTarget("myaddconfiguredvalue");
+ AntAssert.assertContains("value is Value Setexecute: value is Value Set",
+ buildRule.getLog());
+ }
+
+ @Test
+ public void testNamespace() {
+ buildRule.executeTarget("namespacetest");
+ }
+
+ // The following will be used as types and tasks
+
+ public static interface A {}
+ public static interface B {}
+ public static interface C extends A {}
+ public static interface AB extends A, B {}
+
+ public static class AImpl implements A{}
+ public static class BImpl implements B{}
+ public static class CImpl implements C{}
+ public static class ABImpl implements AB{}
+
+ public static class NestedContainer
+ extends Task
+ {
+ public void add(A el) {
+ log("add A called");
+ }
+ public void add(B el) {
+ log("add B called");
+ }
+ public void add(C el) {
+ log("add C called");
+ }
+ }
+
+ public static class MyCondition
+ implements Condition
+ {
+ Project project;
+ public void setProject(Project project) {
+ this.project = project;
+ }
+ public boolean eval() {
+ project.log("My Condition eval");
+ return true;
+ }
+ public void execute() {
+ project.log("My Condition execution");
+ }
+ }
+
+ public static class MyValue
+ {
+ private String text = "NOT SET YET";
+ public void addText(String text) {
+ this.text = text;
+ }
+ public String toString() {
+ return text;
+ }
+ }
+
+ public static class MyAddConfigured
+ extends Task
+ {
+ MyValue value;
+ public void addConfigured(MyValue value) {
+ log("value is " + value);
+ this.value = value;
+ }
+ public void add(MyValue value) {
+ throw new BuildException("Should not be called");
+ }
+ public void execute() {
+ log("execute: value is " + value);
+ }
+ }
+
+ public static class MyAddConfiguredValue
+ extends Task
+ {
+ MyValue value;
+ public void addConfiguredValue(MyValue value) {
+ log("value is " + value);
+ this.value = value;
+ }
+ public void addValue(MyValue value) {
+ throw new BuildException("Should not be called");
+ }
+ public void execute() {
+ log("execute: value is " + value);
+ }
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/AssertionsTest.java b/src/tests/junit/org/apache/tools/ant/types/AssertionsTest.java
index 4210fc1a6..4bd26af6e 100644
--- a/src/tests/junit/org/apache/tools/ant/types/AssertionsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/AssertionsTest.java
@@ -1,125 +1,125 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.types;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Assume;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.apache.tools.ant.AntAssert.assertContains;
-import static org.junit.Assert.fail;
-
-/**
- * test assertion handling
- */
-public class AssertionsTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/types/assertions.xml");
- }
-
-
- /**
- * runs a test and expects an assertion thrown in forked code
- * @param target
- */
- private void expectAssertion(String target) {
- try {
- buildRule.executeTarget(target);
- fail("BuildException should have been thrown by assertion fail in task");
- } catch (BuildException ex) {
- assertContains("assertion not thrown in "+target, "Java returned: 1", ex.getMessage());
- }
- }
-
- @Test
- public void testClassname() {
- expectAssertion("test-classname");
- }
-
- @Test
- public void testPackage() {
- expectAssertion("test-package");
- }
-
- @Test
- public void testEmptyAssertions() {
- buildRule.executeTarget("test-empty-assertions");
- }
-
- @Test
- public void testDisable() {
- buildRule.executeTarget("test-disable");
- }
-
- @Test
- public void testOverride() {
- expectAssertion("test-override");
- }
-
- @Test
- public void testOverride2() {
- buildRule.executeTarget("test-override2");
- }
-
- @Test
- public void testReferences() {
- expectAssertion("test-references");
- }
-
- @Test
- public void testMultipleAssertions() {
- try {
- buildRule.executeTarget("test-multiple-assertions");
- fail("BuildException should have been thrown by assertion fail in task");
- } catch (BuildException ex) {
- assertContains("multiple assertions rejected", "Only one assertion declaration is allowed", ex.getMessage());
- }
- }
-
- @Test
- public void testReferenceAbuse() {
- try {
- buildRule.executeTarget("test-reference-abuse");
- fail("BuildException should have been thrown by reference abuse");
- } catch (BuildException ex) {
- assertContains("reference abuse rejected", "You must not specify", ex.getMessage());
- }
- }
-
- @Test
- public void testNofork() {
- Assume.assumeFalse("ran Ant tests with -ea and this would fail spuriously", AssertionsTest.class.desiredAssertionStatus());
- buildRule.executeTarget("test-nofork");
- assertContains("Assertion statements are currently ignored in non-forked mode", buildRule.getLog());
- }
-
- @Test
- public void testJUnit() {
- buildRule.executeTarget("test-junit");
- }
-}
-
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.apache.tools.ant.types;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.apache.tools.ant.AntAssert.assertContains;
+import static org.junit.Assert.fail;
+
+/**
+ * test assertion handling
+ */
+public class AssertionsTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/types/assertions.xml");
+ }
+
+
+ /**
+ * runs a test and expects an assertion thrown in forked code
+ * @param target
+ */
+ private void expectAssertion(String target) {
+ try {
+ buildRule.executeTarget(target);
+ fail("BuildException should have been thrown by assertion fail in task");
+ } catch (BuildException ex) {
+ assertContains("assertion not thrown in "+target, "Java returned: 1", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testClassname() {
+ expectAssertion("test-classname");
+ }
+
+ @Test
+ public void testPackage() {
+ expectAssertion("test-package");
+ }
+
+ @Test
+ public void testEmptyAssertions() {
+ buildRule.executeTarget("test-empty-assertions");
+ }
+
+ @Test
+ public void testDisable() {
+ buildRule.executeTarget("test-disable");
+ }
+
+ @Test
+ public void testOverride() {
+ expectAssertion("test-override");
+ }
+
+ @Test
+ public void testOverride2() {
+ buildRule.executeTarget("test-override2");
+ }
+
+ @Test
+ public void testReferences() {
+ expectAssertion("test-references");
+ }
+
+ @Test
+ public void testMultipleAssertions() {
+ try {
+ buildRule.executeTarget("test-multiple-assertions");
+ fail("BuildException should have been thrown by assertion fail in task");
+ } catch (BuildException ex) {
+ assertContains("multiple assertions rejected", "Only one assertion declaration is allowed", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testReferenceAbuse() {
+ try {
+ buildRule.executeTarget("test-reference-abuse");
+ fail("BuildException should have been thrown by reference abuse");
+ } catch (BuildException ex) {
+ assertContains("reference abuse rejected", "You must not specify", ex.getMessage());
+ }
+ }
+
+ @Test
+ public void testNofork() {
+ Assume.assumeFalse("ran Ant tests with -ea and this would fail spuriously", AssertionsTest.class.desiredAssertionStatus());
+ buildRule.executeTarget("test-nofork");
+ assertContains("Assertion statements are currently ignored in non-forked mode", buildRule.getLog());
+ }
+
+ @Test
+ public void testJUnit() {
+ buildRule.executeTarget("test-junit");
+ }
+}
+
+
diff --git a/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java b/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java
index c18ff5eee..b8ce90fa0 100644
--- a/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/CommandlineJavaTest.java
@@ -1,191 +1,191 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types;
-
-
-import org.apache.tools.ant.MagicNames;
-import org.apache.tools.ant.Project;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-/**
- * JUnit testcases for org.apache.tools.ant.CommandlineJava
- *
- */
-public class CommandlineJavaTest {
-
- private String cloneVm;
-
-
- private Project project;
-
- @Before
- public void setUp() {
- project = new Project();
- project.setBasedir(System.getProperty("root"));
- project.setProperty("build.sysclasspath", "ignore");
- cloneVm = System.getProperty("ant.build.clonevm");
- if (cloneVm != null) {
- System.setProperty("ant.build.clonevm", "false");
- }
- }
-
- @After
- public void tearDown() {
- if (cloneVm != null) {
- System.setProperty("ant.build.clonevm", cloneVm);
- }
- }
-
- @Test
- public void testGetCommandline() throws Exception {
- CommandlineJava c = new CommandlineJava();
- c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest");
- c.setClassname("junit.textui.TestRunner");
- c.createVmArgument().setValue("-Djava.compiler=NONE");
- String[] s = c.getCommandline();
- assertEquals("no classpath", 4, s.length);
- /*
- * After changing CommandlineJava to search for the java
- * executable, I don't know, how to tests the value returned
- * here without using the same logic as applied in the class
- * itself.
- *
- * assertTrue("no classpath", "java", s[0]);
- */
- assertEquals("no classpath", "-Djava.compiler=NONE", s[1]);
- assertEquals("no classpath", "junit.textui.TestRunner", s[2]);
- assertEquals("no classpath",
- "org.apache.tools.ant.CommandlineJavaTest", s[3]);
- try {
- c.clone();
- } catch (NullPointerException ex) {
- fail("cloning should work without classpath specified");
- }
-
- c.createClasspath(project).setLocation(project.resolveFile("build.xml"));
- c.createClasspath(project).setLocation(project.resolveFile(
- System.getProperty(MagicNames.ANT_HOME)+"/lib/ant.jar"));
- s = c.getCommandline();
- assertEquals("with classpath", 6, s.length);
- // assertEquals("with classpath", "java", s[0]);
- assertEquals("with classpath", "-Djava.compiler=NONE", s[1]);
- assertEquals("with classpath", "-classpath", s[2]);
- assertTrue("build.xml contained",
- s[3].indexOf("build.xml"+java.io.File.pathSeparator) >= 0);
- assertTrue("ant.jar contained", s[3].endsWith("ant.jar"));
- assertEquals("with classpath", "junit.textui.TestRunner", s[4]);
- assertEquals("with classpath",
- "org.apache.tools.ant.CommandlineJavaTest", s[5]);
- }
-
- @Test
- public void testJarOption() throws Exception {
- CommandlineJava c = new CommandlineJava();
- c.createArgument().setValue("arg1");
- c.setJar("myfile.jar");
- c.createVmArgument().setValue("-classic");
- c.createVmArgument().setValue("-Dx=y");
- String[] s = c.getCommandline();
- assertEquals("-classic", s[1]);
- assertEquals("-Dx=y", s[2]);
- assertEquals("-jar", s[3]);
- assertEquals("myfile.jar", s[4]);
- assertEquals("arg1", s[5]);
- }
-
- @Test
- public void testSysproperties() {
- String currentClasspath = System.getProperty("java.class.path");
- assertNotNull(currentClasspath);
- assertNull(System.getProperty("key"));
- CommandlineJava c = new CommandlineJava();
- Environment.Variable v = new Environment.Variable();
- v.setKey("key");
- v.setValue("value");
- c.addSysproperty(v);
-
- project.setProperty("key2", "value2");
- PropertySet ps = new PropertySet();
- ps.setProject(project);
- ps.appendName("key2");
- c.addSyspropertyset(ps);
-
- try {
- c.setSystemProperties();
- String newClasspath = System.getProperty("java.class.path");
- assertNotNull(newClasspath);
- assertEquals(currentClasspath, newClasspath);
- assertNotNull(System.getProperty("key"));
- assertEquals("value", System.getProperty("key"));
- assertTrue(System.getProperties().containsKey("java.class.path"));
- assertNotNull(System.getProperty("key2"));
- assertEquals("value2", System.getProperty("key2"));
- } finally {
- c.restoreSystemProperties();
- }
- assertNull(System.getProperty("key"));
- assertNull(System.getProperty("key2"));
- }
-
- @Test
- public void testAssertions() throws Exception {
- CommandlineJava c = new CommandlineJava();
- c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest");
- c.setClassname("junit.textui.TestRunner");
- c.createVmArgument().setValue("-Djava.compiler=NONE");
- Assertions a = new Assertions();
- a.setProject(project);
- Assertions.EnabledAssertion ea = new Assertions.EnabledAssertion();
- ea.setClass("junit.textui.TestRunner");
- a.addEnable(ea);
- c.setAssertions(a);
-
- String[] expected = new String[] {
- null,
- "-Djava.compiler=NONE",
- "-ea:junit.textui.TestRunner",
- "junit.textui.TestRunner",
- "org.apache.tools.ant.CommandlineJavaTest",
- };
-
- // only the second iteration would pass because of PR 27218
- for (int i = 0; i < 3; i++) {
- String[] s = c.getCommandline();
- assertEquals(expected.length, s.length);
- for (int j = 1; j < expected.length; j++) {
- assertEquals(expected[j], s[j]);
- }
- }
- CommandlineJava c2 = (CommandlineJava) c.clone();
- String[] s = c2.getCommandline();
- assertEquals(expected.length, s.length);
- for (int j = 1; j < expected.length; j++) {
- assertEquals(expected[j], s[j]);
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types;
+
+
+import org.apache.tools.ant.MagicNames;
+import org.apache.tools.ant.Project;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+/**
+ * JUnit testcases for org.apache.tools.ant.CommandlineJava
+ *
+ */
+public class CommandlineJavaTest {
+
+ private String cloneVm;
+
+
+ private Project project;
+
+ @Before
+ public void setUp() {
+ project = new Project();
+ project.setBasedir(System.getProperty("root"));
+ project.setProperty("build.sysclasspath", "ignore");
+ cloneVm = System.getProperty("ant.build.clonevm");
+ if (cloneVm != null) {
+ System.setProperty("ant.build.clonevm", "false");
+ }
+ }
+
+ @After
+ public void tearDown() {
+ if (cloneVm != null) {
+ System.setProperty("ant.build.clonevm", cloneVm);
+ }
+ }
+
+ @Test
+ public void testGetCommandline() throws Exception {
+ CommandlineJava c = new CommandlineJava();
+ c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest");
+ c.setClassname("junit.textui.TestRunner");
+ c.createVmArgument().setValue("-Djava.compiler=NONE");
+ String[] s = c.getCommandline();
+ assertEquals("no classpath", 4, s.length);
+ /*
+ * After changing CommandlineJava to search for the java
+ * executable, I don't know, how to tests the value returned
+ * here without using the same logic as applied in the class
+ * itself.
+ *
+ * assertTrue("no classpath", "java", s[0]);
+ */
+ assertEquals("no classpath", "-Djava.compiler=NONE", s[1]);
+ assertEquals("no classpath", "junit.textui.TestRunner", s[2]);
+ assertEquals("no classpath",
+ "org.apache.tools.ant.CommandlineJavaTest", s[3]);
+ try {
+ c.clone();
+ } catch (NullPointerException ex) {
+ fail("cloning should work without classpath specified");
+ }
+
+ c.createClasspath(project).setLocation(project.resolveFile("build.xml"));
+ c.createClasspath(project).setLocation(project.resolveFile(
+ System.getProperty(MagicNames.ANT_HOME)+"/lib/ant.jar"));
+ s = c.getCommandline();
+ assertEquals("with classpath", 6, s.length);
+ // assertEquals("with classpath", "java", s[0]);
+ assertEquals("with classpath", "-Djava.compiler=NONE", s[1]);
+ assertEquals("with classpath", "-classpath", s[2]);
+ assertTrue("build.xml contained",
+ s[3].indexOf("build.xml"+java.io.File.pathSeparator) >= 0);
+ assertTrue("ant.jar contained", s[3].endsWith("ant.jar"));
+ assertEquals("with classpath", "junit.textui.TestRunner", s[4]);
+ assertEquals("with classpath",
+ "org.apache.tools.ant.CommandlineJavaTest", s[5]);
+ }
+
+ @Test
+ public void testJarOption() throws Exception {
+ CommandlineJava c = new CommandlineJava();
+ c.createArgument().setValue("arg1");
+ c.setJar("myfile.jar");
+ c.createVmArgument().setValue("-classic");
+ c.createVmArgument().setValue("-Dx=y");
+ String[] s = c.getCommandline();
+ assertEquals("-classic", s[1]);
+ assertEquals("-Dx=y", s[2]);
+ assertEquals("-jar", s[3]);
+ assertEquals("myfile.jar", s[4]);
+ assertEquals("arg1", s[5]);
+ }
+
+ @Test
+ public void testSysproperties() {
+ String currentClasspath = System.getProperty("java.class.path");
+ assertNotNull(currentClasspath);
+ assertNull(System.getProperty("key"));
+ CommandlineJava c = new CommandlineJava();
+ Environment.Variable v = new Environment.Variable();
+ v.setKey("key");
+ v.setValue("value");
+ c.addSysproperty(v);
+
+ project.setProperty("key2", "value2");
+ PropertySet ps = new PropertySet();
+ ps.setProject(project);
+ ps.appendName("key2");
+ c.addSyspropertyset(ps);
+
+ try {
+ c.setSystemProperties();
+ String newClasspath = System.getProperty("java.class.path");
+ assertNotNull(newClasspath);
+ assertEquals(currentClasspath, newClasspath);
+ assertNotNull(System.getProperty("key"));
+ assertEquals("value", System.getProperty("key"));
+ assertTrue(System.getProperties().containsKey("java.class.path"));
+ assertNotNull(System.getProperty("key2"));
+ assertEquals("value2", System.getProperty("key2"));
+ } finally {
+ c.restoreSystemProperties();
+ }
+ assertNull(System.getProperty("key"));
+ assertNull(System.getProperty("key2"));
+ }
+
+ @Test
+ public void testAssertions() throws Exception {
+ CommandlineJava c = new CommandlineJava();
+ c.createArgument().setValue("org.apache.tools.ant.CommandlineJavaTest");
+ c.setClassname("junit.textui.TestRunner");
+ c.createVmArgument().setValue("-Djava.compiler=NONE");
+ Assertions a = new Assertions();
+ a.setProject(project);
+ Assertions.EnabledAssertion ea = new Assertions.EnabledAssertion();
+ ea.setClass("junit.textui.TestRunner");
+ a.addEnable(ea);
+ c.setAssertions(a);
+
+ String[] expected = new String[] {
+ null,
+ "-Djava.compiler=NONE",
+ "-ea:junit.textui.TestRunner",
+ "junit.textui.TestRunner",
+ "org.apache.tools.ant.CommandlineJavaTest",
+ };
+
+ // only the second iteration would pass because of PR 27218
+ for (int i = 0; i < 3; i++) {
+ String[] s = c.getCommandline();
+ assertEquals(expected.length, s.length);
+ for (int j = 1; j < expected.length; j++) {
+ assertEquals(expected[j], s[j]);
+ }
+ }
+ CommandlineJava c2 = (CommandlineJava) c.clone();
+ String[] s = c2.getCommandline();
+ assertEquals(expected.length, s.length);
+ for (int j = 1; j < expected.length; j++) {
+ assertEquals(expected[j], s[j]);
+ }
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java b/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java
index e8e444292..ca5fef26c 100644
--- a/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/CommandlineTest.java
@@ -1,180 +1,180 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types;
-
-import org.apache.tools.ant.BuildException;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-import static org.junit.Assert.assertNotNull;
-
-/**
- * JUnit 3 testcases for org.apache.tools.ant.CommandLine
- *
- */
-public class CommandlineTest {
-
- @Test
- public void testTokenizer() {
- String[] s = Commandline.translateCommandline("1 2 3");
- assertEquals("Simple case", 3, s.length);
- for (int i=0; i<3; i++) {
- assertEquals(""+(i+1), s[i]);
- }
-
- s = Commandline.translateCommandline("");
- assertEquals("empty string", 0, s.length);
-
- s = Commandline.translateCommandline(null);
- assertEquals("null", 0, s.length);
-
- s = Commandline.translateCommandline("1 \'2\' 3");
- assertEquals("Simple case with single quotes", 3, s.length);
- assertEquals("Single quotes have been stripped", "2", s[1]);
-
- s = Commandline.translateCommandline("1 \"2\" 3");
- assertEquals("Simple case with double quotes", 3, s.length);
- assertEquals("Double quotes have been stripped", "2", s[1]);
-
- s = Commandline.translateCommandline("1 \"2 3\" 4");
- assertEquals("Case with double quotes and whitespace", 3, s.length);
- assertEquals("Double quotes stripped, space included", "2 3", s[1]);
-
- s = Commandline.translateCommandline("1 \"2\'3\" 4");
- assertEquals("Case with double quotes around single quote", 3, s.length);
- assertEquals("Double quotes stripped, single quote included", "2\'3",
- s[1]);
-
- s = Commandline.translateCommandline("1 \'2 3\' 4");
- assertEquals("Case with single quotes and whitespace", 3, s.length);
- assertEquals("Single quotes stripped, space included", "2 3", s[1]);
-
- s = Commandline.translateCommandline("1 \'2\"3\' 4");
- assertEquals("Case with single quotes around double quote", 3, s.length);
- assertEquals("Single quotes stripped, double quote included", "2\"3",
- s[1]);
-
- // \ doesn't have a special meaning anymore - this is different from
- // what the Unix sh does but causes a lot of problems on DOS
- // based platforms otherwise
- s = Commandline.translateCommandline("1 2\\ 3 4");
- assertEquals("case with quoted whitespace", 4, s.length);
- assertEquals("backslash included", "2\\", s[1]);
-
- // "" should become a single empty argument, same for ''
- // PR 5906
- s = Commandline.translateCommandline("\"\" a");
- assertEquals("Doublequoted null arg prepend", 2, s.length);
- assertEquals("Doublequoted null arg prepend", "", s[0]);
- assertEquals("Doublequoted null arg prepend", "a", s[1]);
- s = Commandline.translateCommandline("a \"\"");
- assertEquals("Doublequoted null arg append", 2, s.length);
- assertEquals("Doublequoted null arg append", "a", s[0]);
- assertEquals("Doublequoted null arg append", "", s[1]);
- s = Commandline.translateCommandline("\"\"");
- assertEquals("Doublequoted null arg", 1, s.length);
- assertEquals("Doublequoted null arg", "", s[0]);
-
- s = Commandline.translateCommandline("\'\' a");
- assertEquals("Singlequoted null arg prepend", 2, s.length);
- assertEquals("Singlequoted null arg prepend", "", s[0]);
- assertEquals("Singlequoted null arg prepend", "a", s[1]);
- s = Commandline.translateCommandline("a \'\'");
- assertEquals("Singlequoted null arg append", 2, s.length);
- assertEquals("Singlequoted null arg append", "a", s[0]);
- assertEquals("Singlequoted null arg append", "", s[1]);
- s = Commandline.translateCommandline("\'\'");
- assertEquals("Singlequoted null arg", 1, s.length);
- assertEquals("Singlequoted null arg", "", s[0]);
-
- // now to the expected failures
-
- try {
- Commandline.translateCommandline("a \'b c");
- fail("unbalanced single quotes undetected");
- } catch (BuildException be) {
- assertEquals("unbalanced quotes in a \'b c", be.getMessage());
- }
-
- try {
- Commandline.translateCommandline("a \"b c");
- fail("unbalanced double quotes undetected");
- } catch (BuildException be) {
- assertEquals("unbalanced quotes in a \"b c", be.getMessage());
- }
- }
-
- @Test
- public void testToString() {
- assertEquals("", Commandline.toString(new String[0]));
- assertEquals("", Commandline.toString(null));
- assertEquals("1 2 3", Commandline.toString(new String[] {"1", "2", "3"}));
- assertEquals("1 \"2 3\"", Commandline.toString(new String[] {"1", "2 3"}));
- assertEquals("1 \"2\'3\"", Commandline.toString(new String[] {"1", "2\'3"}));
- assertEquals("1 \'2\"3\'", Commandline.toString(new String[] {"1", "2\"3"}));
- }
-
- @Test
- public void testAwkCommand() {
- Commandline c = new Commandline();
- c.setExecutable("awk");
- c.createArgument().setValue("'NR == 2 { print $NF }'");
- String[] s = c.getCommandline();
- assertNotNull(s);
- assertEquals(2, s.length);
- assertEquals("awk", s[0]);
- assertEquals("'NR == 2 { print $NF }'", s[1]);
- }
-
- @Test
- public void testPrefix() {
- Commandline c = new Commandline();
- Commandline.Argument a = c.createArgument();
- a.setValue("foo");
- a.setPrefix("-f=");
- String[] s = c.getCommandline();
- assertEquals(1, s.length);
- assertEquals("-f=foo", s[0]);
- }
-
- @Test
- public void testSuffix() {
- Commandline c = new Commandline();
- Commandline.Argument a = c.createArgument();
- a.setValue("foo");
- a.setSuffix(",1");
- String[] s = c.getCommandline();
- assertEquals(1, s.length);
- assertEquals("foo,1", s[0]);
- }
-
- @Test
- public void testPrefixSuffixLine() {
- Commandline c = new Commandline();
- Commandline.Argument a = c.createArgument();
- a.setLine("one two");
- a.setPrefix("number ");
- a.setSuffix(".");
- String[] s = c.getCommandline();
- assertEquals(2, s.length);
- assertEquals("number one.", s[0]);
- assertEquals("number two.", s[1]);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types;
+
+import org.apache.tools.ant.BuildException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * JUnit 3 testcases for org.apache.tools.ant.CommandLine
+ *
+ */
+public class CommandlineTest {
+
+ @Test
+ public void testTokenizer() {
+ String[] s = Commandline.translateCommandline("1 2 3");
+ assertEquals("Simple case", 3, s.length);
+ for (int i=0; i<3; i++) {
+ assertEquals(""+(i+1), s[i]);
+ }
+
+ s = Commandline.translateCommandline("");
+ assertEquals("empty string", 0, s.length);
+
+ s = Commandline.translateCommandline(null);
+ assertEquals("null", 0, s.length);
+
+ s = Commandline.translateCommandline("1 \'2\' 3");
+ assertEquals("Simple case with single quotes", 3, s.length);
+ assertEquals("Single quotes have been stripped", "2", s[1]);
+
+ s = Commandline.translateCommandline("1 \"2\" 3");
+ assertEquals("Simple case with double quotes", 3, s.length);
+ assertEquals("Double quotes have been stripped", "2", s[1]);
+
+ s = Commandline.translateCommandline("1 \"2 3\" 4");
+ assertEquals("Case with double quotes and whitespace", 3, s.length);
+ assertEquals("Double quotes stripped, space included", "2 3", s[1]);
+
+ s = Commandline.translateCommandline("1 \"2\'3\" 4");
+ assertEquals("Case with double quotes around single quote", 3, s.length);
+ assertEquals("Double quotes stripped, single quote included", "2\'3",
+ s[1]);
+
+ s = Commandline.translateCommandline("1 \'2 3\' 4");
+ assertEquals("Case with single quotes and whitespace", 3, s.length);
+ assertEquals("Single quotes stripped, space included", "2 3", s[1]);
+
+ s = Commandline.translateCommandline("1 \'2\"3\' 4");
+ assertEquals("Case with single quotes around double quote", 3, s.length);
+ assertEquals("Single quotes stripped, double quote included", "2\"3",
+ s[1]);
+
+ // \ doesn't have a special meaning anymore - this is different from
+ // what the Unix sh does but causes a lot of problems on DOS
+ // based platforms otherwise
+ s = Commandline.translateCommandline("1 2\\ 3 4");
+ assertEquals("case with quoted whitespace", 4, s.length);
+ assertEquals("backslash included", "2\\", s[1]);
+
+ // "" should become a single empty argument, same for ''
+ // PR 5906
+ s = Commandline.translateCommandline("\"\" a");
+ assertEquals("Doublequoted null arg prepend", 2, s.length);
+ assertEquals("Doublequoted null arg prepend", "", s[0]);
+ assertEquals("Doublequoted null arg prepend", "a", s[1]);
+ s = Commandline.translateCommandline("a \"\"");
+ assertEquals("Doublequoted null arg append", 2, s.length);
+ assertEquals("Doublequoted null arg append", "a", s[0]);
+ assertEquals("Doublequoted null arg append", "", s[1]);
+ s = Commandline.translateCommandline("\"\"");
+ assertEquals("Doublequoted null arg", 1, s.length);
+ assertEquals("Doublequoted null arg", "", s[0]);
+
+ s = Commandline.translateCommandline("\'\' a");
+ assertEquals("Singlequoted null arg prepend", 2, s.length);
+ assertEquals("Singlequoted null arg prepend", "", s[0]);
+ assertEquals("Singlequoted null arg prepend", "a", s[1]);
+ s = Commandline.translateCommandline("a \'\'");
+ assertEquals("Singlequoted null arg append", 2, s.length);
+ assertEquals("Singlequoted null arg append", "a", s[0]);
+ assertEquals("Singlequoted null arg append", "", s[1]);
+ s = Commandline.translateCommandline("\'\'");
+ assertEquals("Singlequoted null arg", 1, s.length);
+ assertEquals("Singlequoted null arg", "", s[0]);
+
+ // now to the expected failures
+
+ try {
+ Commandline.translateCommandline("a \'b c");
+ fail("unbalanced single quotes undetected");
+ } catch (BuildException be) {
+ assertEquals("unbalanced quotes in a \'b c", be.getMessage());
+ }
+
+ try {
+ Commandline.translateCommandline("a \"b c");
+ fail("unbalanced double quotes undetected");
+ } catch (BuildException be) {
+ assertEquals("unbalanced quotes in a \"b c", be.getMessage());
+ }
+ }
+
+ @Test
+ public void testToString() {
+ assertEquals("", Commandline.toString(new String[0]));
+ assertEquals("", Commandline.toString(null));
+ assertEquals("1 2 3", Commandline.toString(new String[] {"1", "2", "3"}));
+ assertEquals("1 \"2 3\"", Commandline.toString(new String[] {"1", "2 3"}));
+ assertEquals("1 \"2\'3\"", Commandline.toString(new String[] {"1", "2\'3"}));
+ assertEquals("1 \'2\"3\'", Commandline.toString(new String[] {"1", "2\"3"}));
+ }
+
+ @Test
+ public void testAwkCommand() {
+ Commandline c = new Commandline();
+ c.setExecutable("awk");
+ c.createArgument().setValue("'NR == 2 { print $NF }'");
+ String[] s = c.getCommandline();
+ assertNotNull(s);
+ assertEquals(2, s.length);
+ assertEquals("awk", s[0]);
+ assertEquals("'NR == 2 { print $NF }'", s[1]);
+ }
+
+ @Test
+ public void testPrefix() {
+ Commandline c = new Commandline();
+ Commandline.Argument a = c.createArgument();
+ a.setValue("foo");
+ a.setPrefix("-f=");
+ String[] s = c.getCommandline();
+ assertEquals(1, s.length);
+ assertEquals("-f=foo", s[0]);
+ }
+
+ @Test
+ public void testSuffix() {
+ Commandline c = new Commandline();
+ Commandline.Argument a = c.createArgument();
+ a.setValue("foo");
+ a.setSuffix(",1");
+ String[] s = c.getCommandline();
+ assertEquals(1, s.length);
+ assertEquals("foo,1", s[0]);
+ }
+
+ @Test
+ public void testPrefixSuffixLine() {
+ Commandline c = new Commandline();
+ Commandline.Argument a = c.createArgument();
+ a.setLine("one two");
+ a.setPrefix("number ");
+ a.setSuffix(".");
+ String[] s = c.getCommandline();
+ assertEquals(2, s.length);
+ assertEquals("number one.", s[0]);
+ assertEquals("number two.", s[1]);
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/DescriptionTest.java b/src/tests/junit/org/apache/tools/ant/types/DescriptionTest.java
index 90dbce7fe..f021228f3 100644
--- a/src/tests/junit/org/apache/tools/ant/types/DescriptionTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/DescriptionTest.java
@@ -1,59 +1,59 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-/**
- * FilterSet testing
- *
- */
-public class DescriptionTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Test
- public void test1() {
- buildRule.configureProject("src/etc/testcases/types/description1.xml");
- assertEquals("Single description failed", "Test Project Description", buildRule.getProject().getDescription());
- }
-
- @Test
- public void test2() {
- buildRule.configureProject("src/etc/testcases/types/description2.xml");
- assertEquals("Multi line description failed", "Multi Line\nProject Description", buildRule.getProject().getDescription());
- }
-
- @Test
- public void test3() {
- buildRule.configureProject("src/etc/testcases/types/description3.xml");
- assertEquals("Multi instance description failed", "Multi Instance Project Description", buildRule.getProject().getDescription());
- }
-
- @Test
- public void test4() {
- buildRule.configureProject("src/etc/testcases/types/description4.xml");
- assertEquals("Multi instance nested description failed", "Multi Instance Nested Project Description", buildRule.getProject().getDescription());
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * FilterSet testing
+ *
+ */
+public class DescriptionTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Test
+ public void test1() {
+ buildRule.configureProject("src/etc/testcases/types/description1.xml");
+ assertEquals("Single description failed", "Test Project Description", buildRule.getProject().getDescription());
+ }
+
+ @Test
+ public void test2() {
+ buildRule.configureProject("src/etc/testcases/types/description2.xml");
+ assertEquals("Multi line description failed", "Multi Line\nProject Description", buildRule.getProject().getDescription());
+ }
+
+ @Test
+ public void test3() {
+ buildRule.configureProject("src/etc/testcases/types/description3.xml");
+ assertEquals("Multi instance description failed", "Multi Instance Project Description", buildRule.getProject().getDescription());
+ }
+
+ @Test
+ public void test4() {
+ buildRule.configureProject("src/etc/testcases/types/description4.xml");
+ assertEquals("Multi instance nested description failed", "Multi Instance Nested Project Description", buildRule.getProject().getDescription());
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java b/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java
index 8c659ba79..4fd2b5a5a 100644
--- a/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/DirSetTest.java
@@ -1,94 +1,94 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types;
-
-import java.io.File;
-import java.io.FileOutputStream;
-import org.apache.tools.ant.BuildException;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-/**
- * JUnit 3 testcases for org.apache.tools.ant.types.DirSet.
- *
- */
-public class DirSetTest extends AbstractFileSetTest {
-
- protected AbstractFileSet getInstance() {
- return new DirSet();
- }
-
- @Test
- public void testFileSetIsNoDirSet() {
- DirSet ds = (DirSet) getInstance();
- ds.setProject(getProject());
- FileSet fs = new FileSet();
- fs.setProject(getProject());
- getProject().addReference("dummy", fs);
- ds.setRefid(new Reference(getProject(), "dummy"));
- try {
- ds.getDir(getProject());
- fail("DirSet created from FileSet reference");
- } catch (BuildException e) {
- assertEquals("dummy doesn\'t denote a DirSet", e.getMessage());
- }
-
- ds = (DirSet) getInstance();
- ds.setProject(getProject());
- getProject().addReference("dummy2", ds);
- fs.setRefid(new Reference(getProject(), "dummy2"));
- try {
- fs.getDir(getProject());
- fail("FileSet created from DirSet reference");
- } catch (BuildException e) {
- assertEquals("dummy2 doesn\'t denote a FileSet", e.getMessage());
- }
- }
-
- public void testToString() throws Exception {
- File tmp = File.createTempFile("DirSetTest", "");
- try {
- tmp.delete();
- File a = new File(tmp, "a");
- a.mkdirs();
- File b = new File(tmp, "b");
- File bc = new File(b, "c");
- bc.mkdirs();
- new FileOutputStream(new File(a, "x")).close();
- new FileOutputStream(new File(b, "x")).close();
- new FileOutputStream(new File(bc, "x")).close();
- DirSet ds = new DirSet();
- ds.setProject(getProject());
- ds.setDir(tmp);
- ds.setIncludes("b/");
- assertEquals("b;b" + File.separator + "c", ds.toString());
- } finally {
- new File(tmp, "a/x").delete();
- new File(tmp, "a").delete();
- new File(tmp, "b/c/x").delete();
- new File(tmp, "b/c").delete();
- new File(tmp, "b/x").delete();
- new File(tmp, "b").delete();
- tmp.delete();
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types;
+
+import java.io.File;
+import java.io.FileOutputStream;
+import org.apache.tools.ant.BuildException;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * JUnit 3 testcases for org.apache.tools.ant.types.DirSet.
+ *
+ */
+public class DirSetTest extends AbstractFileSetTest {
+
+ protected AbstractFileSet getInstance() {
+ return new DirSet();
+ }
+
+ @Test
+ public void testFileSetIsNoDirSet() {
+ DirSet ds = (DirSet) getInstance();
+ ds.setProject(getProject());
+ FileSet fs = new FileSet();
+ fs.setProject(getProject());
+ getProject().addReference("dummy", fs);
+ ds.setRefid(new Reference(getProject(), "dummy"));
+ try {
+ ds.getDir(getProject());
+ fail("DirSet created from FileSet reference");
+ } catch (BuildException e) {
+ assertEquals("dummy doesn\'t denote a DirSet", e.getMessage());
+ }
+
+ ds = (DirSet) getInstance();
+ ds.setProject(getProject());
+ getProject().addReference("dummy2", ds);
+ fs.setRefid(new Reference(getProject(), "dummy2"));
+ try {
+ fs.getDir(getProject());
+ fail("FileSet created from DirSet reference");
+ } catch (BuildException e) {
+ assertEquals("dummy2 doesn\'t denote a FileSet", e.getMessage());
+ }
+ }
+
+ public void testToString() throws Exception {
+ File tmp = File.createTempFile("DirSetTest", "");
+ try {
+ tmp.delete();
+ File a = new File(tmp, "a");
+ a.mkdirs();
+ File b = new File(tmp, "b");
+ File bc = new File(b, "c");
+ bc.mkdirs();
+ new FileOutputStream(new File(a, "x")).close();
+ new FileOutputStream(new File(b, "x")).close();
+ new FileOutputStream(new File(bc, "x")).close();
+ DirSet ds = new DirSet();
+ ds.setProject(getProject());
+ ds.setDir(tmp);
+ ds.setIncludes("b/");
+ assertEquals("b;b" + File.separator + "c", ds.toString());
+ } finally {
+ new File(tmp, "a/x").delete();
+ new File(tmp, "a").delete();
+ new File(tmp, "b/c/x").delete();
+ new File(tmp, "b/c").delete();
+ new File(tmp, "b/x").delete();
+ new File(tmp, "b").delete();
+ tmp.delete();
+ }
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java b/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java
index 0e2e241e2..7961b72e4 100644
--- a/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/EnumeratedAttributeTest.java
@@ -1,106 +1,106 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types;
-
-
-import org.apache.tools.ant.BuildException;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * JUnit testcases for org.apache.tools.ant.EnumeratedAttribute.
- */
-public class EnumeratedAttributeTest {
-
- private static String[] expected = {"a", "b", "c"};
-
- @Test
- public void testContains() {
- EnumeratedAttribute t1 = new TestNormal();
- for (int i=0; i dummy2 --> dummy3 --> dummy1
- FileList f1 = new FileList();
- buildRule.getProject().addReference("dummy1", f1);
- f1.setRefid(new Reference(buildRule.getProject(), "dummy2"));
- FileList f2 = new FileList();
- buildRule.getProject().addReference("dummy2", f2);
- f2.setRefid(new Reference(buildRule.getProject(), "dummy3"));
- FileList f3 = new FileList();
- buildRule.getProject().addReference("dummy3", f3);
- f3.setRefid(new Reference(buildRule.getProject(), "dummy1"));
- try {
- f1.getDir(buildRule.getProject());
- fail("Can make circular reference.");
- } catch (BuildException be) {
- assertEquals("This data type contains a circular reference.",
- be.getMessage());
- }
- try {
- f1.getFiles(buildRule.getProject());
- fail("Can make circular reference.");
- } catch (BuildException be) {
- assertEquals("This data type contains a circular reference.",
- be.getMessage());
- }
-
- // dummy1 --> dummy2 --> dummy3
- // (which has the Project's basedir as root).
- f1 = new FileList();
- buildRule.getProject().addReference("dummy1", f1);
- f1.setRefid(new Reference(buildRule.getProject(), "dummy2"));
- f2 = new FileList();
- buildRule.getProject().addReference("dummy2", f2);
- f2.setRefid(new Reference(buildRule.getProject(), "dummy3"));
- f3 = new FileList();
- buildRule.getProject().addReference("dummy3", f3);
- f3.setDir(buildRule.getProject().resolveFile("."));
- File dir = f1.getDir(buildRule.getProject());
- assertEquals("Dir is basedir", dir, buildRule.getProject().getBaseDir());
- }
-
- @Test
- public void testSimple() {
- buildRule.executeTarget("simple");
- assertEquals("/abc/a", buildRule.getLog());
- }
-
- @Test
- public void testDouble() {
- buildRule.executeTarget("double");
- assertEquals("/abc/a:/abc/b", buildRule.getLog());
- }
-
- @Test
- public void testNested() {
- buildRule.executeTarget("nested");
- assertEquals("/abc/a:/abc/b", buildRule.getLog());
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * Some tests for filelist.
+ */
+
+public class FileListTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/types/filelist.xml");
+ }
+
+ @Test
+ public void testEmptyElementIfIsReference() {
+ FileList f = new FileList();
+ f.setDir(buildRule.getProject().resolveFile("."));
+ try {
+ f.setRefid(new Reference(buildRule.getProject(), "dummyref"));
+ fail("Can add reference to FileList with directory attribute set.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute when using refid",
+ be.getMessage());
+ }
+
+ f = new FileList();
+ f.setFiles("foo.xml,c/d/bar.xml");
+ try {
+ f.setRefid(new Reference(buildRule.getProject(), "dummyref"));
+ fail("Can add reference to FileList with file attribute set.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute when using refid",
+ be.getMessage());
+ }
+
+ f = new FileList();
+ f.setRefid(new Reference(buildRule.getProject(), "dummyref"));
+ try {
+ f.setFiles("a/b/foo.java");
+ fail("Can set files in FileList that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute when using refid",
+ be.getMessage());
+ }
+ try {
+ f.setDir(buildRule.getProject().resolveFile("."));
+ fail("Can set dir in FileList that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute when using refid",
+ be.getMessage());
+ }
+ }
+
+ @Test
+ public void testCircularReferenceCheck() {
+ FileList f = new FileList();
+ buildRule.getProject().addReference("dummy", f);
+ f.setRefid(new Reference(buildRule.getProject(), "dummy"));
+ try {
+ f.getDir(buildRule.getProject());
+ fail("Can make FileList a Reference to itself.");
+ } catch (BuildException be) {
+ assertEquals("This data type contains a circular reference.",
+ be.getMessage());
+ }
+ try {
+ f.getFiles(buildRule.getProject());
+ fail("Can make FileList a Reference to itself.");
+ } catch (BuildException be) {
+ assertEquals("This data type contains a circular reference.",
+ be.getMessage());
+ }
+
+ // dummy1 --> dummy2 --> dummy3 --> dummy1
+ FileList f1 = new FileList();
+ buildRule.getProject().addReference("dummy1", f1);
+ f1.setRefid(new Reference(buildRule.getProject(), "dummy2"));
+ FileList f2 = new FileList();
+ buildRule.getProject().addReference("dummy2", f2);
+ f2.setRefid(new Reference(buildRule.getProject(), "dummy3"));
+ FileList f3 = new FileList();
+ buildRule.getProject().addReference("dummy3", f3);
+ f3.setRefid(new Reference(buildRule.getProject(), "dummy1"));
+ try {
+ f1.getDir(buildRule.getProject());
+ fail("Can make circular reference.");
+ } catch (BuildException be) {
+ assertEquals("This data type contains a circular reference.",
+ be.getMessage());
+ }
+ try {
+ f1.getFiles(buildRule.getProject());
+ fail("Can make circular reference.");
+ } catch (BuildException be) {
+ assertEquals("This data type contains a circular reference.",
+ be.getMessage());
+ }
+
+ // dummy1 --> dummy2 --> dummy3
+ // (which has the Project's basedir as root).
+ f1 = new FileList();
+ buildRule.getProject().addReference("dummy1", f1);
+ f1.setRefid(new Reference(buildRule.getProject(), "dummy2"));
+ f2 = new FileList();
+ buildRule.getProject().addReference("dummy2", f2);
+ f2.setRefid(new Reference(buildRule.getProject(), "dummy3"));
+ f3 = new FileList();
+ buildRule.getProject().addReference("dummy3", f3);
+ f3.setDir(buildRule.getProject().resolveFile("."));
+ File dir = f1.getDir(buildRule.getProject());
+ assertEquals("Dir is basedir", dir, buildRule.getProject().getBaseDir());
+ }
+
+ @Test
+ public void testSimple() {
+ buildRule.executeTarget("simple");
+ assertEquals("/abc/a", buildRule.getLog());
+ }
+
+ @Test
+ public void testDouble() {
+ buildRule.executeTarget("double");
+ assertEquals("/abc/a:/abc/b", buildRule.getLog());
+ }
+
+ @Test
+ public void testNested() {
+ buildRule.executeTarget("nested");
+ assertEquals("/abc/a:/abc/b", buildRule.getLog());
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/FileSetTest.java b/src/tests/junit/org/apache/tools/ant/types/FileSetTest.java
index 8a1c35ac0..f58a3f009 100644
--- a/src/tests/junit/org/apache/tools/ant/types/FileSetTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/FileSetTest.java
@@ -1,36 +1,36 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types;
-
-
-/**
- * JUnit 3 testcases for org.apache.tools.ant.types.FileSet.
- *
- *
This doesn't actually test much, mainly reference handling.
- *
- */
-
-public class FileSetTest extends AbstractFileSetTest {
-
-
- protected AbstractFileSet getInstance() {
- return new FileSet();
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types;
+
+
+/**
+ * JUnit 3 testcases for org.apache.tools.ant.types.FileSet.
+ *
+ *
This doesn't actually test much, mainly reference handling.
+ *
+ */
+
+public class FileSetTest extends AbstractFileSetTest {
+
+
+ protected AbstractFileSet getInstance() {
+ return new FileSet();
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/FilterSetTest.java b/src/tests/junit/org/apache/tools/ant/types/FilterSetTest.java
index f4df4a383..7122ea16a 100644
--- a/src/tests/junit/org/apache/tools/ant/types/FilterSetTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/FilterSetTest.java
@@ -1,239 +1,239 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.IOException;
-import java.util.Hashtable;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * FilterSet testing
- *
- */
-public class FilterSetTest {
-
- static private final int BUF_SIZE = 32768;
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/types/filterset.xml");
- }
-
- @After
- public void tearDown() {
- buildRule.executeTarget("cleanup");
- }
-
- @Test
- public void test1() throws IOException {
- buildRule.executeTarget("test1");
- assertTrue("Filterset 1 failed", compareFiles("src/etc/testcases/types/gold/filterset1.txt",
- "src/etc/testcases/types/dest1.txt"));
- }
-
- @Test
- public void test2() throws IOException {
- buildRule.executeTarget("test2");
- assertTrue("Filterset 2 failed", compareFiles("src/etc/testcases/types/gold/filterset2.txt",
- "src/etc/testcases/types/dest2.txt"));
- }
-
- @Test
- public void test3() throws IOException {
- buildRule.executeTarget("test3");
- assertTrue("Filterset 3 failed", compareFiles("src/etc/testcases/types/gold/filterset3.txt",
- "src/etc/testcases/types/dest3.txt"));
- }
-
- /**
- * This will test the recursive FilterSet. Which means that if
- * the filter value @test@ contains another filter value, it will
- * actually resolve.
- */
- @Test
- public void testRecursive() {
- String result = "it works line";
- String line="@test@ line";
- FilterSet fs = new FilterSet();
- fs.addFilter("test", "@test1@");
- fs.addFilter("test1","@test2@");
- fs.addFilter("test2", "it works");
- fs.setBeginToken("@");
- fs.setEndToken("@");
- assertEquals(result, fs.replaceTokens(line));
- }
-
- /**
- * Test to see what happens when the resolving occurs in an
- * infinite loop.
- */
- @Test
- public void testInfinite() {
- String result = "@test@ line testvalue";
- String line = "@test@ line @test3@";
- FilterSet fs = new FilterSet();
- fs.addFilter("test", "@test1@");
- fs.addFilter("test1","@test2@");
- fs.addFilter("test2", "@test@");
- fs.addFilter("test3", "testvalue");
- fs.setBeginToken("@");
- fs.setEndToken("@");
- assertEquals(result, fs.replaceTokens(line));
- }
-
- /**
- * Test to see what happens when the resolving occurs in
- * what would be an infinite loop, but with recursion disabled.
- */
- @Test
- public void testRecursionDisabled() {
- String result = "@test1@ line testvalue";
- String line = "@test@ line @test2@";
- FilterSet fs = new FilterSet();
- fs.addFilter("test", "@test1@");
- fs.addFilter("test1","@test@");
- fs.addFilter("test2", "testvalue");
- fs.setBeginToken("@");
- fs.setEndToken("@");
- fs.setRecurse(false);
- assertEquals(result, fs.replaceTokens(line));
- }
-
- @Test
- public void testNonInfiniteRecursiveMultipleOnSingleLine() {
- FilterSet filters = new FilterSet();
-
- filters.setBeginToken("<");
- filters.setEndToken(">");
-
- filters.addFilter("ul", "");
- filters.addFilter("/ul", "");
- filters.addFilter("li", "");
- filters.addFilter("/li", "");
-
- String result = "Item 1Item 2";
- String line = "
Item 1
Item 2
";
-
- assertEquals(result, filters.replaceTokens(line));
- }
-
- @Test
- public void testNestedFilterSets() {
- buildRule.executeTarget("test-nested-filtersets");
-
- FilterSet fs = (FilterSet) buildRule.getProject().getReference("1");
- Hashtable filters = fs.getFilterHash();
- assertEquals(1, filters.size());
- assertEquals("value1", filters.get("token1"));
-
- fs = (FilterSet) buildRule.getProject().getReference("2");
- filters = fs.getFilterHash();
- assertEquals(2, filters.size());
- assertEquals("1111", filters.get("aaaa"));
- assertEquals("2222", filters.get("bbbb"));
-
- fs = (FilterSet) buildRule.getProject().getReference("3");
- filters = fs.getFilterHash();
- assertEquals(1, filters.size());
- assertEquals("value4", filters.get("token4"));
-
- fs = (FilterSet) buildRule.getProject().getReference("5");
- filters = fs.getFilterHash();
- assertEquals(1, filters.size());
- assertEquals("value1", filters.get("token1"));
- }
-
- @Test
- public void testFiltersFileElement() {
- buildRule.executeTarget("testFiltersFileElement");
- }
-
- @Test
- public void testFiltersFileAttribute() {
- buildRule.executeTarget("testFiltersFileAttribute");
- }
-
- @Test
- public void testMultipleFiltersFiles() {
- buildRule.executeTarget("testMultipleFiltersFiles");
- }
-
- @Test
- public void testMissingFiltersFile() {
- try {
- buildRule.executeTarget("testMissingFiltersFile");
- fail("should fail due to missing filtersfile");
- } catch (BuildException ex) {
- //TODO assert exception text
- }
- }
-
- @Test
- public void testAllowMissingFiltersFile() {
- buildRule.executeTarget("testAllowMissingFiltersFile");
- }
-
- private boolean compareFiles(String name1, String name2) throws IOException {
- File file1 = new File(System.getProperty("root"), name1);
- File file2 = new File(System.getProperty("root"), name2);
-
-
- if (!file1.exists() || !file2.exists()) {
- return false;
- }
-
- if (file1.length() != file2.length()) {
- return false;
- }
-
- // byte - byte compare
- byte[] buffer1 = new byte[BUF_SIZE];
- byte[] buffer2 = new byte[BUF_SIZE];
-
- FileInputStream fis1 = new FileInputStream(file1);
- FileInputStream fis2 = new FileInputStream(file2);
- int index = 0;
- int read = 0;
- while ((read = fis1.read(buffer1)) != -1) {
- fis2.read(buffer2);
- for (int i = 0; i < read; ++i, ++index) {
- if (buffer1[i] != buffer2[i]) {
- return false;
- }
- }
- }
- return true;
-
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.IOException;
+import java.util.Hashtable;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * FilterSet testing
+ *
+ */
+public class FilterSetTest {
+
+ static private final int BUF_SIZE = 32768;
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/types/filterset.xml");
+ }
+
+ @After
+ public void tearDown() {
+ buildRule.executeTarget("cleanup");
+ }
+
+ @Test
+ public void test1() throws IOException {
+ buildRule.executeTarget("test1");
+ assertTrue("Filterset 1 failed", compareFiles("src/etc/testcases/types/gold/filterset1.txt",
+ "src/etc/testcases/types/dest1.txt"));
+ }
+
+ @Test
+ public void test2() throws IOException {
+ buildRule.executeTarget("test2");
+ assertTrue("Filterset 2 failed", compareFiles("src/etc/testcases/types/gold/filterset2.txt",
+ "src/etc/testcases/types/dest2.txt"));
+ }
+
+ @Test
+ public void test3() throws IOException {
+ buildRule.executeTarget("test3");
+ assertTrue("Filterset 3 failed", compareFiles("src/etc/testcases/types/gold/filterset3.txt",
+ "src/etc/testcases/types/dest3.txt"));
+ }
+
+ /**
+ * This will test the recursive FilterSet. Which means that if
+ * the filter value @test@ contains another filter value, it will
+ * actually resolve.
+ */
+ @Test
+ public void testRecursive() {
+ String result = "it works line";
+ String line="@test@ line";
+ FilterSet fs = new FilterSet();
+ fs.addFilter("test", "@test1@");
+ fs.addFilter("test1","@test2@");
+ fs.addFilter("test2", "it works");
+ fs.setBeginToken("@");
+ fs.setEndToken("@");
+ assertEquals(result, fs.replaceTokens(line));
+ }
+
+ /**
+ * Test to see what happens when the resolving occurs in an
+ * infinite loop.
+ */
+ @Test
+ public void testInfinite() {
+ String result = "@test@ line testvalue";
+ String line = "@test@ line @test3@";
+ FilterSet fs = new FilterSet();
+ fs.addFilter("test", "@test1@");
+ fs.addFilter("test1","@test2@");
+ fs.addFilter("test2", "@test@");
+ fs.addFilter("test3", "testvalue");
+ fs.setBeginToken("@");
+ fs.setEndToken("@");
+ assertEquals(result, fs.replaceTokens(line));
+ }
+
+ /**
+ * Test to see what happens when the resolving occurs in
+ * what would be an infinite loop, but with recursion disabled.
+ */
+ @Test
+ public void testRecursionDisabled() {
+ String result = "@test1@ line testvalue";
+ String line = "@test@ line @test2@";
+ FilterSet fs = new FilterSet();
+ fs.addFilter("test", "@test1@");
+ fs.addFilter("test1","@test@");
+ fs.addFilter("test2", "testvalue");
+ fs.setBeginToken("@");
+ fs.setEndToken("@");
+ fs.setRecurse(false);
+ assertEquals(result, fs.replaceTokens(line));
+ }
+
+ @Test
+ public void testNonInfiniteRecursiveMultipleOnSingleLine() {
+ FilterSet filters = new FilterSet();
+
+ filters.setBeginToken("<");
+ filters.setEndToken(">");
+
+ filters.addFilter("ul", "");
+ filters.addFilter("/ul", "");
+ filters.addFilter("li", "");
+ filters.addFilter("/li", "");
+
+ String result = "Item 1Item 2";
+ String line = "
Item 1
Item 2
";
+
+ assertEquals(result, filters.replaceTokens(line));
+ }
+
+ @Test
+ public void testNestedFilterSets() {
+ buildRule.executeTarget("test-nested-filtersets");
+
+ FilterSet fs = (FilterSet) buildRule.getProject().getReference("1");
+ Hashtable filters = fs.getFilterHash();
+ assertEquals(1, filters.size());
+ assertEquals("value1", filters.get("token1"));
+
+ fs = (FilterSet) buildRule.getProject().getReference("2");
+ filters = fs.getFilterHash();
+ assertEquals(2, filters.size());
+ assertEquals("1111", filters.get("aaaa"));
+ assertEquals("2222", filters.get("bbbb"));
+
+ fs = (FilterSet) buildRule.getProject().getReference("3");
+ filters = fs.getFilterHash();
+ assertEquals(1, filters.size());
+ assertEquals("value4", filters.get("token4"));
+
+ fs = (FilterSet) buildRule.getProject().getReference("5");
+ filters = fs.getFilterHash();
+ assertEquals(1, filters.size());
+ assertEquals("value1", filters.get("token1"));
+ }
+
+ @Test
+ public void testFiltersFileElement() {
+ buildRule.executeTarget("testFiltersFileElement");
+ }
+
+ @Test
+ public void testFiltersFileAttribute() {
+ buildRule.executeTarget("testFiltersFileAttribute");
+ }
+
+ @Test
+ public void testMultipleFiltersFiles() {
+ buildRule.executeTarget("testMultipleFiltersFiles");
+ }
+
+ @Test
+ public void testMissingFiltersFile() {
+ try {
+ buildRule.executeTarget("testMissingFiltersFile");
+ fail("should fail due to missing filtersfile");
+ } catch (BuildException ex) {
+ //TODO assert exception text
+ }
+ }
+
+ @Test
+ public void testAllowMissingFiltersFile() {
+ buildRule.executeTarget("testAllowMissingFiltersFile");
+ }
+
+ private boolean compareFiles(String name1, String name2) throws IOException {
+ File file1 = new File(System.getProperty("root"), name1);
+ File file2 = new File(System.getProperty("root"), name2);
+
+
+ if (!file1.exists() || !file2.exists()) {
+ return false;
+ }
+
+ if (file1.length() != file2.length()) {
+ return false;
+ }
+
+ // byte - byte compare
+ byte[] buffer1 = new byte[BUF_SIZE];
+ byte[] buffer2 = new byte[BUF_SIZE];
+
+ FileInputStream fis1 = new FileInputStream(file1);
+ FileInputStream fis2 = new FileInputStream(file2);
+ int index = 0;
+ int read = 0;
+ while ((read = fis1.read(buffer1)) != -1) {
+ fis2.read(buffer2);
+ for (int i = 0; i < read; ++i, ++index) {
+ if (buffer1[i] != buffer2[i]) {
+ return false;
+ }
+ }
+ }
+ return true;
+
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/FlexIntegerTest.java b/src/tests/junit/org/apache/tools/ant/types/FlexIntegerTest.java
index 3e08b2cbb..74355158b 100644
--- a/src/tests/junit/org/apache/tools/ant/types/FlexIntegerTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/FlexIntegerTest.java
@@ -1,74 +1,74 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.BuildException;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-public class FlexIntegerTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/types/flexinteger.xml");
- }
-
- @Test
- public void testFlexInteger() {
- buildRule.executeTarget("test");
- assertEquals(buildRule.getProject().getProperty("flexint.value1"), "10");
- assertEquals(buildRule.getProject().getProperty("flexint.value2"), "8");
- }
-
- // This class acts as a custom Ant task also
- // and uses these variables/methods in that mode
- private Project taskProject;
- String propName;
- private FlexInteger value;
-
-
-
- public void setPropName(String propName) {
- this.propName = propName;
- }
-
- public void setValue(FlexInteger value) {
- this.value = value;
- }
-
- public void setProject(Project project) {
- taskProject = project;
- }
-
- public void execute() {
- if (propName == null || value == null) {
- throw new BuildException("name and value required");
- }
-
- taskProject.setNewProperty(propName, value.toString());
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.BuildException;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+public class FlexIntegerTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/types/flexinteger.xml");
+ }
+
+ @Test
+ public void testFlexInteger() {
+ buildRule.executeTarget("test");
+ assertEquals(buildRule.getProject().getProperty("flexint.value1"), "10");
+ assertEquals(buildRule.getProject().getProperty("flexint.value2"), "8");
+ }
+
+ // This class acts as a custom Ant task also
+ // and uses these variables/methods in that mode
+ private Project taskProject;
+ String propName;
+ private FlexInteger value;
+
+
+
+ public void setPropName(String propName) {
+ this.propName = propName;
+ }
+
+ public void setValue(FlexInteger value) {
+ this.value = value;
+ }
+
+ public void setProject(Project project) {
+ taskProject = project;
+ }
+
+ public void execute() {
+ if (propName == null || value == null) {
+ throw new BuildException("name and value required");
+ }
+
+ taskProject.setNewProperty(propName, value.toString());
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/MapperTest.java b/src/tests/junit/org/apache/tools/ant/types/MapperTest.java
index 980f5cc27..8758238a4 100644
--- a/src/tests/junit/org/apache/tools/ant/types/MapperTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/MapperTest.java
@@ -1,235 +1,235 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.util.ChainedMapper;
-import org.apache.tools.ant.util.FileNameMapper;
-import org.apache.tools.ant.util.FlatFileNameMapper;
-import org.apache.tools.ant.util.GlobPatternMapper;
-import org.apache.tools.ant.util.MergingMapper;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * JUnit testcases for org.apache.tools.ant.types.Mapper.
- *
- */
-
-public class MapperTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- private Project project;
-
- @Before
- public void setUp() {
- project = new Project();
- project.setBasedir(".");
- }
-
- @Test
- public void testEmptyElementIfIsReference() {
- Mapper m = new Mapper(project);
- m.setFrom("*.java");
- try {
- m.setRefid(new Reference(project, "dummyref"));
- fail("Can add reference to Mapper with from attribute set");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute when using refid",
- be.getMessage());
- }
-
- m = new Mapper(project);
- m.setRefid(new Reference(project, "dummyref"));
- try {
- m.setFrom("*.java");
- fail("Can set from in Mapper that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute when using refid",
- be.getMessage());
- }
-
- m = new Mapper(project);
- m.setRefid(new Reference(project, "dummyref"));
- try {
- m.setTo("*.java");
- fail("Can set to in Mapper that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute when using refid",
- be.getMessage());
- }
- try {
- Mapper.MapperType mt = new Mapper.MapperType();
- mt.setValue("glob");
- m.setType(mt);
- fail("Can set type in Mapper that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute when using refid",
- be.getMessage());
- }
- }
-
- @Test
- public void testCircularReferenceCheck() {
- Mapper m = new Mapper(project);
- project.addReference("dummy", m);
- m.setRefid(new Reference(project, "dummy"));
- try {
- m.getImplementation();
- fail("Can make Mapper a Reference to itself.");
- } catch (BuildException be) {
- assertEquals("This data type contains a circular reference.",
- be.getMessage());
- }
-
- // dummy1 --> dummy2 --> dummy3 --> dummy1
- Mapper m1 = new Mapper(project);
- project.addReference("dummy1", m1);
- m1.setRefid(new Reference(project, "dummy2"));
- Mapper m2 = new Mapper(project);
- project.addReference("dummy2", m2);
- m2.setRefid(new Reference(project, "dummy3"));
- Mapper m3 = new Mapper(project);
- project.addReference("dummy3", m3);
- m3.setRefid(new Reference(project, "dummy1"));
- try {
- m1.getImplementation();
- fail("Can make circular reference.");
- } catch (BuildException be) {
- assertEquals("This data type contains a circular reference.",
- be.getMessage());
- }
-
- // dummy1 --> dummy2 --> dummy3
- // (which holds a glob mapper from "*.java" to "*.class"
- m1 = new Mapper(project);
- project.addReference("dummy1", m1);
- m1.setRefid(new Reference(project, "dummy2"));
- m2 = new Mapper(project);
- project.addReference("dummy2", m2);
- m2.setRefid(new Reference(project, "dummy3"));
- m3 = new Mapper(project);
- project.addReference("dummy3", m3);
- Mapper.MapperType mt = new Mapper.MapperType();
- mt.setValue("glob");
- m3.setType(mt);
- m3.setFrom("*.java");
- m3.setTo("*.class");
- FileNameMapper fmm = m1.getImplementation();
- assertTrue("should be glob", fmm instanceof GlobPatternMapper);
- String[] result = fmm.mapFileName("a.java");
- assertEquals("a.java should match", 1, result.length);
- assertEquals("a.class", result[0]);
- }
-
- @Test
- public void testNested() {
- Mapper mapper1 = new Mapper(project);
- Mapper.MapperType mt = new Mapper.MapperType();
- mt.setValue("glob");
- mapper1.setType(mt);
- mapper1.setFrom("from*");
- mapper1.setTo("to*");
-
- //mix element types
- FileNameMapper mapper2 = new FlatFileNameMapper();
- FileNameMapper mapper3 = new MergingMapper();
- mapper3.setTo("mergefile");
-
- Mapper container = new Mapper(project);
- container.addConfiguredMapper(mapper1);
- container.add(mapper2);
- container.add(mapper3);
-
- FileNameMapper fileNameMapper = container.getImplementation();
- String[] targets = fileNameMapper.mapFileName("fromfilename");
- assertNotNull("no filenames mapped", targets);
- assertEquals("wrong number of filenames mapped", 3, targets.length);
- List list = Arrays.asList(targets);
- assertTrue("cannot find expected target \"tofilename\"",
- list.contains("tofilename"));
- assertTrue("cannot find expected target \"fromfilename\"",
- list.contains("fromfilename"));
- assertTrue("cannot find expected target \"mergefile\"",
- list.contains("mergefile"));
- }
-
- @Test
- public void testChained() {
-
- // a --> b --> c --- def
- // \-- ghi
-
- FileNameMapper mapperAB = new GlobPatternMapper();
- mapperAB.setFrom("a");
- mapperAB.setTo("b");
-
- FileNameMapper mapperBC = new GlobPatternMapper();
- mapperBC.setFrom("b");
- mapperBC.setTo("c");
-
- //implicit composite
- Mapper mapperCX = new Mapper(project);
-
- FileNameMapper mapperDEF = new GlobPatternMapper();
- mapperDEF.setFrom("c");
- mapperDEF.setTo("def");
-
- FileNameMapper mapperGHI = new GlobPatternMapper();
- mapperGHI.setFrom("c");
- mapperGHI.setTo("ghi");
-
- mapperCX.add(mapperDEF);
- mapperCX.add(mapperGHI);
-
- Mapper chained = new Mapper(project);
- chained.setClassname(ChainedMapper.class.getName());
- chained.add(mapperAB);
- chained.add(mapperBC);
- chained.addConfiguredMapper(mapperCX);
-
- FileNameMapper fileNameMapper = chained.getImplementation();
- String[] targets = fileNameMapper.mapFileName("a");
- assertNotNull("no filenames mapped", targets);
- assertEquals("wrong number of filenames mapped", 2, targets.length);
- List list = Arrays.asList(targets);
- assertTrue("cannot find expected target \"def\"", list.contains("def"));
- assertTrue("cannot find expected target \"ghi\"", list.contains("ghi"));
- }
-
- @Test
- public void testCopyTaskWithTwoFilesets() {
- buildRule.configureProject("src/etc/testcases/types/mapper.xml");
- buildRule.executeTarget("test1");
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.util.ChainedMapper;
+import org.apache.tools.ant.util.FileNameMapper;
+import org.apache.tools.ant.util.FlatFileNameMapper;
+import org.apache.tools.ant.util.GlobPatternMapper;
+import org.apache.tools.ant.util.MergingMapper;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * JUnit testcases for org.apache.tools.ant.types.Mapper.
+ *
+ */
+
+public class MapperTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ private Project project;
+
+ @Before
+ public void setUp() {
+ project = new Project();
+ project.setBasedir(".");
+ }
+
+ @Test
+ public void testEmptyElementIfIsReference() {
+ Mapper m = new Mapper(project);
+ m.setFrom("*.java");
+ try {
+ m.setRefid(new Reference(project, "dummyref"));
+ fail("Can add reference to Mapper with from attribute set");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute when using refid",
+ be.getMessage());
+ }
+
+ m = new Mapper(project);
+ m.setRefid(new Reference(project, "dummyref"));
+ try {
+ m.setFrom("*.java");
+ fail("Can set from in Mapper that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute when using refid",
+ be.getMessage());
+ }
+
+ m = new Mapper(project);
+ m.setRefid(new Reference(project, "dummyref"));
+ try {
+ m.setTo("*.java");
+ fail("Can set to in Mapper that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute when using refid",
+ be.getMessage());
+ }
+ try {
+ Mapper.MapperType mt = new Mapper.MapperType();
+ mt.setValue("glob");
+ m.setType(mt);
+ fail("Can set type in Mapper that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute when using refid",
+ be.getMessage());
+ }
+ }
+
+ @Test
+ public void testCircularReferenceCheck() {
+ Mapper m = new Mapper(project);
+ project.addReference("dummy", m);
+ m.setRefid(new Reference(project, "dummy"));
+ try {
+ m.getImplementation();
+ fail("Can make Mapper a Reference to itself.");
+ } catch (BuildException be) {
+ assertEquals("This data type contains a circular reference.",
+ be.getMessage());
+ }
+
+ // dummy1 --> dummy2 --> dummy3 --> dummy1
+ Mapper m1 = new Mapper(project);
+ project.addReference("dummy1", m1);
+ m1.setRefid(new Reference(project, "dummy2"));
+ Mapper m2 = new Mapper(project);
+ project.addReference("dummy2", m2);
+ m2.setRefid(new Reference(project, "dummy3"));
+ Mapper m3 = new Mapper(project);
+ project.addReference("dummy3", m3);
+ m3.setRefid(new Reference(project, "dummy1"));
+ try {
+ m1.getImplementation();
+ fail("Can make circular reference.");
+ } catch (BuildException be) {
+ assertEquals("This data type contains a circular reference.",
+ be.getMessage());
+ }
+
+ // dummy1 --> dummy2 --> dummy3
+ // (which holds a glob mapper from "*.java" to "*.class"
+ m1 = new Mapper(project);
+ project.addReference("dummy1", m1);
+ m1.setRefid(new Reference(project, "dummy2"));
+ m2 = new Mapper(project);
+ project.addReference("dummy2", m2);
+ m2.setRefid(new Reference(project, "dummy3"));
+ m3 = new Mapper(project);
+ project.addReference("dummy3", m3);
+ Mapper.MapperType mt = new Mapper.MapperType();
+ mt.setValue("glob");
+ m3.setType(mt);
+ m3.setFrom("*.java");
+ m3.setTo("*.class");
+ FileNameMapper fmm = m1.getImplementation();
+ assertTrue("should be glob", fmm instanceof GlobPatternMapper);
+ String[] result = fmm.mapFileName("a.java");
+ assertEquals("a.java should match", 1, result.length);
+ assertEquals("a.class", result[0]);
+ }
+
+ @Test
+ public void testNested() {
+ Mapper mapper1 = new Mapper(project);
+ Mapper.MapperType mt = new Mapper.MapperType();
+ mt.setValue("glob");
+ mapper1.setType(mt);
+ mapper1.setFrom("from*");
+ mapper1.setTo("to*");
+
+ //mix element types
+ FileNameMapper mapper2 = new FlatFileNameMapper();
+ FileNameMapper mapper3 = new MergingMapper();
+ mapper3.setTo("mergefile");
+
+ Mapper container = new Mapper(project);
+ container.addConfiguredMapper(mapper1);
+ container.add(mapper2);
+ container.add(mapper3);
+
+ FileNameMapper fileNameMapper = container.getImplementation();
+ String[] targets = fileNameMapper.mapFileName("fromfilename");
+ assertNotNull("no filenames mapped", targets);
+ assertEquals("wrong number of filenames mapped", 3, targets.length);
+ List list = Arrays.asList(targets);
+ assertTrue("cannot find expected target \"tofilename\"",
+ list.contains("tofilename"));
+ assertTrue("cannot find expected target \"fromfilename\"",
+ list.contains("fromfilename"));
+ assertTrue("cannot find expected target \"mergefile\"",
+ list.contains("mergefile"));
+ }
+
+ @Test
+ public void testChained() {
+
+ // a --> b --> c --- def
+ // \-- ghi
+
+ FileNameMapper mapperAB = new GlobPatternMapper();
+ mapperAB.setFrom("a");
+ mapperAB.setTo("b");
+
+ FileNameMapper mapperBC = new GlobPatternMapper();
+ mapperBC.setFrom("b");
+ mapperBC.setTo("c");
+
+ //implicit composite
+ Mapper mapperCX = new Mapper(project);
+
+ FileNameMapper mapperDEF = new GlobPatternMapper();
+ mapperDEF.setFrom("c");
+ mapperDEF.setTo("def");
+
+ FileNameMapper mapperGHI = new GlobPatternMapper();
+ mapperGHI.setFrom("c");
+ mapperGHI.setTo("ghi");
+
+ mapperCX.add(mapperDEF);
+ mapperCX.add(mapperGHI);
+
+ Mapper chained = new Mapper(project);
+ chained.setClassname(ChainedMapper.class.getName());
+ chained.add(mapperAB);
+ chained.add(mapperBC);
+ chained.addConfiguredMapper(mapperCX);
+
+ FileNameMapper fileNameMapper = chained.getImplementation();
+ String[] targets = fileNameMapper.mapFileName("a");
+ assertNotNull("no filenames mapped", targets);
+ assertEquals("wrong number of filenames mapped", 2, targets.length);
+ List list = Arrays.asList(targets);
+ assertTrue("cannot find expected target \"def\"", list.contains("def"));
+ assertTrue("cannot find expected target \"ghi\"", list.contains("ghi"));
+ }
+
+ @Test
+ public void testCopyTaskWithTwoFilesets() {
+ buildRule.configureProject("src/etc/testcases/types/mapper.xml");
+ buildRule.executeTarget("test1");
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/PathTest.java b/src/tests/junit/org/apache/tools/ant/types/PathTest.java
index 2ad1819cf..4580629b0 100644
--- a/src/tests/junit/org/apache/tools/ant/types/PathTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/PathTest.java
@@ -1,579 +1,579 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types;
-
-import java.io.File;
-import java.util.Locale;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.taskdefs.condition.Os;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-/**
- * JUnit testcases for org.apache.tools.ant.types.Path
- *
- */
-
-public class PathTest {
-
- public static boolean isUnixStyle = File.pathSeparatorChar == ':';
- public static boolean isNetWare = Os.isFamily("netware");
-
- private Project project;
-
- @Before
- public void setUp() {
- project = new Project();
- project.setBasedir(System.getProperty("root"));
- }
-
- // actually tests constructor as well as setPath
- @Test
- public void testConstructorUnixStyle() {
- Path p = new Path(project, "/a:/b");
- String[] l = p.list();
- assertEquals("two items, Unix style", 2, l.length);
- if (isUnixStyle) {
- assertEquals("/a", l[0]);
- assertEquals("/b", l[1]);
- } else if (isNetWare) {
- assertEquals("\\a", l[0]);
- assertEquals("\\b", l[1]);
- } else {
- String base = new File(File.separator).getAbsolutePath();
- assertEquals(base + "a", l[0]);
- assertEquals(base + "b", l[1]);
- }
- }
-
- @Test
- public void testRelativePathUnixStyle() {
- project.setBasedir(new File(System.getProperty("root"), "src/etc").getAbsolutePath());
- Path p = new Path(project, "..:testcases");
- String[] l = p.list();
- assertEquals("two items, Unix style", 2, l.length);
- if (isUnixStyle) {
- assertTrue("test resolved relative to src/etc",
- l[0].endsWith("/src"));
- assertTrue("test resolved relative to src/etc",
- l[1].endsWith("/src/etc/testcases"));
- } else if (isNetWare) {
- assertTrue("test resolved relative to src/etc",
- l[0].endsWith("\\src"));
- assertTrue("test resolved relative to src/etc",
- l[1].endsWith("\\src\\etc\\testcases"));
- } else {
- assertTrue("test resolved relative to src/etc",
- l[0].endsWith("\\src"));
- assertTrue("test resolved relative to src/etc",
- l[1].endsWith("\\src\\etc\\testcases"));
- }
- }
-
- @Test
- public void testConstructorWindowsStyle() {
- Path p = new Path(project, "\\a;\\b");
- String[] l = p.list();
- assertEquals("two items, DOS style", 2, l.length);
- if (isUnixStyle) {
- assertEquals("/a", l[0]);
- assertEquals("/b", l[1]);
- } else if (isNetWare) {
- assertEquals("\\a", l[0]);
- assertEquals("\\b", l[1]);
- } else {
- String base = new File(File.separator).getAbsolutePath();
- assertEquals(base + "a", l[0]);
- assertEquals(base + "b", l[1]);
- }
-
- p = new Path(project, "c:\\test");
- l = p.list();
- if (isUnixStyle) {
- assertEquals("no drives on Unix", 2, l.length);
- assertTrue("c resolved relative to project\'s basedir",
- l[0].endsWith("/c"));
- assertEquals("/test", l[1]);
- } else if (isNetWare) {
- assertEquals("volumes on NetWare", 1, l.length);
- assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
- } else {
- assertEquals("drives on DOS", 1, l.length);
- assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
- }
-
- p = new Path(project, "c:\\test;d:\\programs");
- l = p.list();
- if (isUnixStyle) {
- assertEquals("no drives on Unix", 4, l.length);
- assertTrue("c resolved relative to project\'s basedir",
- l[0].endsWith("/c"));
- assertEquals("/test", l[1]);
- assertTrue("d resolved relative to project\'s basedir",
- l[2].endsWith("/d"));
- assertEquals("/programs", l[3]);
- } else if (isNetWare) {
- assertEquals("volumes on NetWare", 2, l.length);
- assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
- assertEquals("d:\\programs", l[1].toLowerCase(Locale.US));
- } else {
- assertEquals("drives on DOS", 2, l.length);
- assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
- assertEquals("d:\\programs", l[1].toLowerCase(Locale.US));
- }
-
- p = new Path(project, "c:/test");
- l = p.list();
- if (isUnixStyle) {
- assertEquals("no drives on Unix", 2, l.length);
- assertTrue("c resolved relative to project\'s basedir",
- l[0].endsWith("/c"));
- assertEquals("/test", l[1]);
- } else if (isNetWare) {
- assertEquals("volumes on NetWare", 1, l.length);
- assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
- } else {
- assertEquals("drives on DOS", 1, l.length);
- assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
- }
-
- p = new Path(project, "c:/test;d:/programs");
- l = p.list();
- if (isUnixStyle) {
- assertEquals("no drives on Unix", 4, l.length);
- assertTrue("c resolved relative to project\'s basedir",
- l[0].endsWith("/c"));
- assertEquals("/test", l[1]);
- assertTrue("d resolved relative to project\'s basedir",
- l[2].endsWith("/d"));
- assertEquals("/programs", l[3]);
- } else if (isNetWare) {
- assertEquals("volumes on NetWare", 2, l.length);
- assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
- assertEquals("d:\\programs", l[1].toLowerCase(Locale.US));
- } else {
- assertEquals("drives on DOS", 2, l.length);
- assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
- assertEquals("d:\\programs", l[1].toLowerCase(Locale.US));
- }
- }
-
- @Test
- public void testConstructorNetWareStyle() {
- // try a netware-volume length path, see how it is handled
- Path p = new Path(project, "sys:\\test");
- String[] l = p.list();
- if (isUnixStyle) {
- assertEquals("no drives on Unix", 2, l.length);
- assertTrue("sys resolved relative to project\'s basedir",
- l[0].endsWith("/sys"));
- assertEquals("/test", l[1]);
- } else if (isNetWare) {
- assertEquals("sys:\\test", l[0].toLowerCase(Locale.US));
- assertEquals("volumes on NetWare", 1, l.length);
- } else {
- assertEquals("no multiple character-length volumes on Windows", 2, l.length);
- assertTrue("sys resolved relative to project\'s basedir",
- l[0].endsWith("\\sys"));
- assertTrue("test resolved relative to project\'s basedir",
- l[1].endsWith("\\test"));
- }
-
- // try a multi-part netware-volume length path, see how it is handled
- p = new Path(project, "sys:\\test;dev:\\temp");
- l = p.list();
- if (isUnixStyle) {
- assertEquals("no drives on Unix", 4, l.length);
- assertTrue("sys resolved relative to project\'s basedir",
- l[0].endsWith("/sys"));
- assertEquals("/test", l[1]);
- assertTrue("dev resolved relative to project\'s basedir",
- l[2].endsWith("/dev"));
- assertEquals("/temp", l[3]);
- } else if (isNetWare) {
- assertEquals("volumes on NetWare", 2, l.length);
- assertEquals("sys:\\test", l[0].toLowerCase(Locale.US));
- assertEquals("dev:\\temp", l[1].toLowerCase(Locale.US));
- } else {
- assertEquals("no multiple character-length volumes on Windows", 4, l.length);
- assertTrue("sys resolved relative to project\'s basedir",
- l[0].endsWith("\\sys"));
- assertTrue("test resolved relative to project\'s basedir",
- l[1].endsWith("\\test"));
- assertTrue("dev resolved relative to project\'s basedir",
- l[2].endsWith("\\dev"));
- assertTrue("temp resolved relative to project\'s basedir",
- l[3].endsWith("\\temp"));
- }
-
- // try a netware-volume length path w/forward slash, see how it is handled
- p = new Path(project, "sys:/test");
- l = p.list();
- if (isUnixStyle) {
- assertEquals("no drives on Unix", 2, l.length);
- assertTrue("sys resolved relative to project\'s basedir",
- l[0].endsWith("/sys"));
- assertEquals("/test", l[1]);
- } else if (isNetWare) {
- assertEquals("volumes on NetWare", 1, l.length);
- assertEquals("sys:\\test", l[0].toLowerCase(Locale.US));
- } else {
- assertEquals("no multiple character-length volumes on Windows", 2, l.length);
- assertTrue("sys resolved relative to project\'s basedir",
- l[0].endsWith("\\sys"));
- assertTrue("test resolved relative to project\'s basedir",
- l[1].endsWith("\\test"));
- }
-
- // try a multi-part netware-volume length path w/forward slash, see how it is handled
- p = new Path(project, "sys:/test;dev:/temp");
- l = p.list();
- if (isUnixStyle) {
- assertEquals("no drives on Unix", 4, l.length);
- assertTrue("sys resolved relative to project\'s basedir",
- l[0].endsWith("/sys"));
- assertEquals("/test", l[1]);
- assertTrue("dev resolved relative to project\'s basedir",
- l[2].endsWith("/dev"));
- assertEquals("/temp", l[3]);
- } else if (isNetWare) {
- assertEquals("volumes on NetWare", 2, l.length);
- assertEquals("sys:\\test", l[0].toLowerCase(Locale.US));
- assertEquals("dev:\\temp", l[1].toLowerCase(Locale.US));
- } else {
- assertEquals("no multiple character-length volumes on Windows", 4, l.length);
- assertTrue("sys resolved relative to project\'s basedir",
- l[0].endsWith("\\sys"));
- assertTrue("test resolved relative to project\'s basedir",
- l[1].endsWith("\\test"));
- assertTrue("dev resolved relative to project\'s basedir",
- l[2].endsWith("\\dev"));
- assertTrue("temp resolved relative to project\'s basedir",
- l[3].endsWith("\\temp"));
- }
-
- // try a multi-part netware-volume length path with UNIX
- // separator (this testcase if from an actual bug that was
- // found, in AvailableTest, which uses PathTokenizer)
- p = new Path(project,
- "SYS:\\JAVA/lib/rt.jar:SYS:\\JAVA/lib/classes.zip");
- l = p.list();
- if (isUnixStyle) {
- assertEquals("no drives on Unix", 3, l.length);
- assertTrue("sys resolved relative to project\'s basedir",
- l[0].endsWith("/SYS"));
- assertEquals("/JAVA/lib/rt.jar", l[1]);
- assertEquals("/JAVA/lib/classes.zip", l[2]);
- } else if (isNetWare) {
- assertEquals("volumes on NetWare", 2, l.length);
- assertEquals("sys:\\java\\lib\\rt.jar", l[0].toLowerCase(Locale.US));
- assertEquals("sys:\\java\\lib\\classes.zip", l[1].toLowerCase(Locale.US));
- } else {
- assertEquals("no multiple character-length volumes on Windows", 3, l.length);
- assertTrue("sys resolved relative to project\'s basedir",
- l[0].endsWith("\\SYS"));
- assertTrue("java/lib/rt.jar resolved relative to project\'s basedir",
- l[1].endsWith("\\JAVA\\lib\\rt.jar"));
- assertTrue("java/lib/classes.zip resolved relative to project\'s basedir",
- l[2].endsWith("\\JAVA\\lib\\classes.zip"));
- }
- }
-
- @Test
- public void testConstructorMixedStyle() {
- Path p = new Path(project, "\\a;\\b:/c");
- String[] l = p.list();
- assertEquals("three items, mixed style", 3, l.length);
- if (isUnixStyle) {
- assertEquals("/a", l[0]);
- assertEquals("/b", l[1]);
- assertEquals("/c", l[2]);
- } else if (isNetWare) {
- assertEquals("\\a", l[0]);
- assertEquals("\\b", l[1]);
- assertEquals("\\c", l[2]);
- } else {
- String base = new File(File.separator).getAbsolutePath();
- assertEquals(base + "a", l[0]);
- assertEquals(base + "b", l[1]);
- assertEquals(base + "c", l[2]);
- }
- }
-
- @Test
- public void testSetLocation() {
- Path p = new Path(project);
- p.setLocation(new File(File.separatorChar+"a"));
- String[] l = p.list();
- if (isUnixStyle) {
- assertEquals(1, l.length);
- assertEquals("/a", l[0]);
- } else if (isNetWare) {
- assertEquals(1, l.length);
- assertEquals("\\a", l[0]);
- } else {
- assertEquals(1, l.length);
- assertEquals(":\\a", l[0].substring(1));
- }
- }
-
- @Test
- public void testAppending() {
- Path p = new Path(project, "/a:/b");
- String[] l = p.list();
- assertEquals("2 after construction", 2, l.length);
- p.setLocation(new File("/c"));
- l = p.list();
- assertEquals("3 after setLocation", 3, l.length);
- p.setPath("\\d;\\e");
- l = p.list();
- assertEquals("5 after setPath", 5, l.length);
- p.append(new Path(project, "\\f"));
- l = p.list();
- assertEquals("6 after append", 6, l.length);
- p.createPath().setLocation(new File("/g"));
- l = p.list();
- assertEquals("7 after append", 7, l.length);
- }
-
- @Test
- public void testEmpyPath() {
- Path p = new Path(project, "");
- String[] l = p.list();
- assertEquals("0 after construction", 0, l.length);
- p.setPath("");
- l = p.list();
- assertEquals("0 after setPath", 0, l.length);
- p.append(new Path(project));
- l = p.list();
- assertEquals("0 after append", 0, l.length);
- p.createPath();
- l = p.list();
- assertEquals("0 after append", 0, l.length);
- }
-
- @Test
- public void testUnique() {
- Path p = new Path(project, "/a:/a");
- String[] l = p.list();
- assertEquals("1 after construction", 1, l.length);
- String base = new File(File.separator).getAbsolutePath();
- p.setLocation(new File(base, "a"));
- l = p.list();
- assertEquals("1 after setLocation", 1, l.length);
- p.setPath("\\a;/a");
- l = p.list();
- assertEquals("1 after setPath", 1, l.length);
- p.append(new Path(project, "/a;\\a:\\a"));
- l = p.list();
- assertEquals("1 after append", 1, l.length);
- p.createPath().setPath("\\a:/a");
- l = p.list();
- assertEquals("1 after append", 1, l.length);
- }
-
- @Test
- public void testEmptyElementIfIsReference() {
- Path p = new Path(project, "/a:/a");
- try {
- p.setRefid(new Reference(project, "dummyref"));
- fail("Can add reference to Path with elements from constructor");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute when using refid",
- be.getMessage());
- }
-
- p = new Path(project);
- p.setLocation(new File("/a"));
- try {
- p.setRefid(new Reference(project, "dummyref"));
- fail("Can add reference to Path with elements from setLocation");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute when using refid",
- be.getMessage());
- }
-
- Path another = new Path(project, "/a:/a");
- project.addReference("dummyref", another);
- p = new Path(project);
- p.setRefid(new Reference(project, "dummyref"));
- try {
- p.setLocation(new File("/a"));
- fail("Can set location in Path that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute when using refid",
- be.getMessage());
- }
-
- try {
- p.setPath("/a;\\a");
- fail("Can set path in Path that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute when using refid",
- be.getMessage());
- }
-
- try {
- p.createPath();
- fail("Can create nested Path in Path that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify nested elements when using refid",
- be.getMessage());
- }
-
- try {
- p.createPathElement();
- fail("Can create nested PathElement in Path that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify nested elements when using refid",
- be.getMessage());
- }
-
- try {
- p.addFileset(new FileSet());
- fail("Can add nested FileSet in Path that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify nested elements when using refid",
- be.getMessage());
- }
-
- try {
- p.addFilelist(new FileList());
- fail("Can add nested FileList in Path that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify nested elements when using refid",
- be.getMessage());
- }
-
- try {
- p.addDirset(new DirSet());
- fail("Can add nested Dirset in Path that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify nested elements when using refid",
- be.getMessage());
- }
- }
-
- @Test
- public void testCircularReferenceCheck() {
- Path p = new Path(project);
- project.addReference("dummy", p);
- p.setRefid(new Reference(project, "dummy"));
- try {
- p.list();
- fail("Can make Path a Reference to itself.");
- } catch (BuildException be) {
- assertEquals("This data type contains a circular reference.",
- be.getMessage());
- }
-
- // dummy1 --> dummy2 --> dummy3 --> dummy1
- Path p1 = new Path(project);
- project.addReference("dummy1", p1);
- Path p2 = p1.createPath();
- project.addReference("dummy2", p2);
- Path p3 = p2.createPath();
- project.addReference("dummy3", p3);
- p3.setRefid(new Reference(project, "dummy1"));
- try {
- p1.list();
- fail("Can make circular reference.");
- } catch (BuildException be) {
- assertEquals("This data type contains a circular reference.",
- be.getMessage());
- }
-
- // dummy1 --> dummy2 --> dummy3 (with Path "/a")
- p1 = new Path(project);
- project.addReference("dummy1", p1);
- p2 = p1.createPath();
- project.addReference("dummy2", p2);
- p3 = p2.createPath();
- project.addReference("dummy3", p3);
- p3.setLocation(new File("/a"));
- String[] l = p1.list();
- assertEquals("One element buried deep inside a nested path structure",
- 1, l.length);
- if (isUnixStyle) {
- assertEquals("/a", l[0]);
- } else if (isNetWare) {
- assertEquals("\\a", l[0]);
- } else {
- assertEquals(":\\a", l[0].substring(1));
- }
- }
-
- @Test
- public void testFileList() {
- Path p = new Path(project);
- FileList f = new FileList();
- f.setProject(project);
- f.setDir(project.resolveFile("."));
- f.setFiles("build.xml");
- p.addFilelist(f);
- String[] l = p.list();
- assertEquals(1, l.length);
- assertEquals(project.resolveFile("build.xml").getAbsolutePath(), l[0]);
- }
-
- @Test
- public void testFileSet() {
- Path p = new Path(project);
- FileSet f = new FileSet();
- f.setProject(project);
- f.setDir(project.resolveFile("."));
- f.setIncludes("build.xml");
- p.addFileset(f);
- String[] l = p.list();
- assertEquals(1, l.length);
- assertEquals(project.resolveFile("build.xml").getAbsolutePath(), l[0]);
- }
-
- @Test
- public void testDirSet() {
- Path p = new Path(project);
- DirSet d = new DirSet();
- d.setProject(project);
- d.setDir(project.resolveFile("."));
- d.setIncludes("build");
- p.addDirset(d);
- String[] l = p.list();
- assertEquals(1, l.length);
- assertEquals(project.resolveFile("build").getAbsolutePath(), l[0]);
- }
-
- @Test
- public void testRecursion() {
- Path p = new Path(project);
- try {
- p.append(p);
- assertEquals(0, p.list().length);
- } catch (BuildException x) {
- String m = x.toString();
- assertTrue(m, m.indexOf("circular") != -1);
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types;
+
+import java.io.File;
+import java.util.Locale;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.taskdefs.condition.Os;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+/**
+ * JUnit testcases for org.apache.tools.ant.types.Path
+ *
+ */
+
+public class PathTest {
+
+ public static boolean isUnixStyle = File.pathSeparatorChar == ':';
+ public static boolean isNetWare = Os.isFamily("netware");
+
+ private Project project;
+
+ @Before
+ public void setUp() {
+ project = new Project();
+ project.setBasedir(System.getProperty("root"));
+ }
+
+ // actually tests constructor as well as setPath
+ @Test
+ public void testConstructorUnixStyle() {
+ Path p = new Path(project, "/a:/b");
+ String[] l = p.list();
+ assertEquals("two items, Unix style", 2, l.length);
+ if (isUnixStyle) {
+ assertEquals("/a", l[0]);
+ assertEquals("/b", l[1]);
+ } else if (isNetWare) {
+ assertEquals("\\a", l[0]);
+ assertEquals("\\b", l[1]);
+ } else {
+ String base = new File(File.separator).getAbsolutePath();
+ assertEquals(base + "a", l[0]);
+ assertEquals(base + "b", l[1]);
+ }
+ }
+
+ @Test
+ public void testRelativePathUnixStyle() {
+ project.setBasedir(new File(System.getProperty("root"), "src/etc").getAbsolutePath());
+ Path p = new Path(project, "..:testcases");
+ String[] l = p.list();
+ assertEquals("two items, Unix style", 2, l.length);
+ if (isUnixStyle) {
+ assertTrue("test resolved relative to src/etc",
+ l[0].endsWith("/src"));
+ assertTrue("test resolved relative to src/etc",
+ l[1].endsWith("/src/etc/testcases"));
+ } else if (isNetWare) {
+ assertTrue("test resolved relative to src/etc",
+ l[0].endsWith("\\src"));
+ assertTrue("test resolved relative to src/etc",
+ l[1].endsWith("\\src\\etc\\testcases"));
+ } else {
+ assertTrue("test resolved relative to src/etc",
+ l[0].endsWith("\\src"));
+ assertTrue("test resolved relative to src/etc",
+ l[1].endsWith("\\src\\etc\\testcases"));
+ }
+ }
+
+ @Test
+ public void testConstructorWindowsStyle() {
+ Path p = new Path(project, "\\a;\\b");
+ String[] l = p.list();
+ assertEquals("two items, DOS style", 2, l.length);
+ if (isUnixStyle) {
+ assertEquals("/a", l[0]);
+ assertEquals("/b", l[1]);
+ } else if (isNetWare) {
+ assertEquals("\\a", l[0]);
+ assertEquals("\\b", l[1]);
+ } else {
+ String base = new File(File.separator).getAbsolutePath();
+ assertEquals(base + "a", l[0]);
+ assertEquals(base + "b", l[1]);
+ }
+
+ p = new Path(project, "c:\\test");
+ l = p.list();
+ if (isUnixStyle) {
+ assertEquals("no drives on Unix", 2, l.length);
+ assertTrue("c resolved relative to project\'s basedir",
+ l[0].endsWith("/c"));
+ assertEquals("/test", l[1]);
+ } else if (isNetWare) {
+ assertEquals("volumes on NetWare", 1, l.length);
+ assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
+ } else {
+ assertEquals("drives on DOS", 1, l.length);
+ assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
+ }
+
+ p = new Path(project, "c:\\test;d:\\programs");
+ l = p.list();
+ if (isUnixStyle) {
+ assertEquals("no drives on Unix", 4, l.length);
+ assertTrue("c resolved relative to project\'s basedir",
+ l[0].endsWith("/c"));
+ assertEquals("/test", l[1]);
+ assertTrue("d resolved relative to project\'s basedir",
+ l[2].endsWith("/d"));
+ assertEquals("/programs", l[3]);
+ } else if (isNetWare) {
+ assertEquals("volumes on NetWare", 2, l.length);
+ assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
+ assertEquals("d:\\programs", l[1].toLowerCase(Locale.US));
+ } else {
+ assertEquals("drives on DOS", 2, l.length);
+ assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
+ assertEquals("d:\\programs", l[1].toLowerCase(Locale.US));
+ }
+
+ p = new Path(project, "c:/test");
+ l = p.list();
+ if (isUnixStyle) {
+ assertEquals("no drives on Unix", 2, l.length);
+ assertTrue("c resolved relative to project\'s basedir",
+ l[0].endsWith("/c"));
+ assertEquals("/test", l[1]);
+ } else if (isNetWare) {
+ assertEquals("volumes on NetWare", 1, l.length);
+ assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
+ } else {
+ assertEquals("drives on DOS", 1, l.length);
+ assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
+ }
+
+ p = new Path(project, "c:/test;d:/programs");
+ l = p.list();
+ if (isUnixStyle) {
+ assertEquals("no drives on Unix", 4, l.length);
+ assertTrue("c resolved relative to project\'s basedir",
+ l[0].endsWith("/c"));
+ assertEquals("/test", l[1]);
+ assertTrue("d resolved relative to project\'s basedir",
+ l[2].endsWith("/d"));
+ assertEquals("/programs", l[3]);
+ } else if (isNetWare) {
+ assertEquals("volumes on NetWare", 2, l.length);
+ assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
+ assertEquals("d:\\programs", l[1].toLowerCase(Locale.US));
+ } else {
+ assertEquals("drives on DOS", 2, l.length);
+ assertEquals("c:\\test", l[0].toLowerCase(Locale.US));
+ assertEquals("d:\\programs", l[1].toLowerCase(Locale.US));
+ }
+ }
+
+ @Test
+ public void testConstructorNetWareStyle() {
+ // try a netware-volume length path, see how it is handled
+ Path p = new Path(project, "sys:\\test");
+ String[] l = p.list();
+ if (isUnixStyle) {
+ assertEquals("no drives on Unix", 2, l.length);
+ assertTrue("sys resolved relative to project\'s basedir",
+ l[0].endsWith("/sys"));
+ assertEquals("/test", l[1]);
+ } else if (isNetWare) {
+ assertEquals("sys:\\test", l[0].toLowerCase(Locale.US));
+ assertEquals("volumes on NetWare", 1, l.length);
+ } else {
+ assertEquals("no multiple character-length volumes on Windows", 2, l.length);
+ assertTrue("sys resolved relative to project\'s basedir",
+ l[0].endsWith("\\sys"));
+ assertTrue("test resolved relative to project\'s basedir",
+ l[1].endsWith("\\test"));
+ }
+
+ // try a multi-part netware-volume length path, see how it is handled
+ p = new Path(project, "sys:\\test;dev:\\temp");
+ l = p.list();
+ if (isUnixStyle) {
+ assertEquals("no drives on Unix", 4, l.length);
+ assertTrue("sys resolved relative to project\'s basedir",
+ l[0].endsWith("/sys"));
+ assertEquals("/test", l[1]);
+ assertTrue("dev resolved relative to project\'s basedir",
+ l[2].endsWith("/dev"));
+ assertEquals("/temp", l[3]);
+ } else if (isNetWare) {
+ assertEquals("volumes on NetWare", 2, l.length);
+ assertEquals("sys:\\test", l[0].toLowerCase(Locale.US));
+ assertEquals("dev:\\temp", l[1].toLowerCase(Locale.US));
+ } else {
+ assertEquals("no multiple character-length volumes on Windows", 4, l.length);
+ assertTrue("sys resolved relative to project\'s basedir",
+ l[0].endsWith("\\sys"));
+ assertTrue("test resolved relative to project\'s basedir",
+ l[1].endsWith("\\test"));
+ assertTrue("dev resolved relative to project\'s basedir",
+ l[2].endsWith("\\dev"));
+ assertTrue("temp resolved relative to project\'s basedir",
+ l[3].endsWith("\\temp"));
+ }
+
+ // try a netware-volume length path w/forward slash, see how it is handled
+ p = new Path(project, "sys:/test");
+ l = p.list();
+ if (isUnixStyle) {
+ assertEquals("no drives on Unix", 2, l.length);
+ assertTrue("sys resolved relative to project\'s basedir",
+ l[0].endsWith("/sys"));
+ assertEquals("/test", l[1]);
+ } else if (isNetWare) {
+ assertEquals("volumes on NetWare", 1, l.length);
+ assertEquals("sys:\\test", l[0].toLowerCase(Locale.US));
+ } else {
+ assertEquals("no multiple character-length volumes on Windows", 2, l.length);
+ assertTrue("sys resolved relative to project\'s basedir",
+ l[0].endsWith("\\sys"));
+ assertTrue("test resolved relative to project\'s basedir",
+ l[1].endsWith("\\test"));
+ }
+
+ // try a multi-part netware-volume length path w/forward slash, see how it is handled
+ p = new Path(project, "sys:/test;dev:/temp");
+ l = p.list();
+ if (isUnixStyle) {
+ assertEquals("no drives on Unix", 4, l.length);
+ assertTrue("sys resolved relative to project\'s basedir",
+ l[0].endsWith("/sys"));
+ assertEquals("/test", l[1]);
+ assertTrue("dev resolved relative to project\'s basedir",
+ l[2].endsWith("/dev"));
+ assertEquals("/temp", l[3]);
+ } else if (isNetWare) {
+ assertEquals("volumes on NetWare", 2, l.length);
+ assertEquals("sys:\\test", l[0].toLowerCase(Locale.US));
+ assertEquals("dev:\\temp", l[1].toLowerCase(Locale.US));
+ } else {
+ assertEquals("no multiple character-length volumes on Windows", 4, l.length);
+ assertTrue("sys resolved relative to project\'s basedir",
+ l[0].endsWith("\\sys"));
+ assertTrue("test resolved relative to project\'s basedir",
+ l[1].endsWith("\\test"));
+ assertTrue("dev resolved relative to project\'s basedir",
+ l[2].endsWith("\\dev"));
+ assertTrue("temp resolved relative to project\'s basedir",
+ l[3].endsWith("\\temp"));
+ }
+
+ // try a multi-part netware-volume length path with UNIX
+ // separator (this testcase if from an actual bug that was
+ // found, in AvailableTest, which uses PathTokenizer)
+ p = new Path(project,
+ "SYS:\\JAVA/lib/rt.jar:SYS:\\JAVA/lib/classes.zip");
+ l = p.list();
+ if (isUnixStyle) {
+ assertEquals("no drives on Unix", 3, l.length);
+ assertTrue("sys resolved relative to project\'s basedir",
+ l[0].endsWith("/SYS"));
+ assertEquals("/JAVA/lib/rt.jar", l[1]);
+ assertEquals("/JAVA/lib/classes.zip", l[2]);
+ } else if (isNetWare) {
+ assertEquals("volumes on NetWare", 2, l.length);
+ assertEquals("sys:\\java\\lib\\rt.jar", l[0].toLowerCase(Locale.US));
+ assertEquals("sys:\\java\\lib\\classes.zip", l[1].toLowerCase(Locale.US));
+ } else {
+ assertEquals("no multiple character-length volumes on Windows", 3, l.length);
+ assertTrue("sys resolved relative to project\'s basedir",
+ l[0].endsWith("\\SYS"));
+ assertTrue("java/lib/rt.jar resolved relative to project\'s basedir",
+ l[1].endsWith("\\JAVA\\lib\\rt.jar"));
+ assertTrue("java/lib/classes.zip resolved relative to project\'s basedir",
+ l[2].endsWith("\\JAVA\\lib\\classes.zip"));
+ }
+ }
+
+ @Test
+ public void testConstructorMixedStyle() {
+ Path p = new Path(project, "\\a;\\b:/c");
+ String[] l = p.list();
+ assertEquals("three items, mixed style", 3, l.length);
+ if (isUnixStyle) {
+ assertEquals("/a", l[0]);
+ assertEquals("/b", l[1]);
+ assertEquals("/c", l[2]);
+ } else if (isNetWare) {
+ assertEquals("\\a", l[0]);
+ assertEquals("\\b", l[1]);
+ assertEquals("\\c", l[2]);
+ } else {
+ String base = new File(File.separator).getAbsolutePath();
+ assertEquals(base + "a", l[0]);
+ assertEquals(base + "b", l[1]);
+ assertEquals(base + "c", l[2]);
+ }
+ }
+
+ @Test
+ public void testSetLocation() {
+ Path p = new Path(project);
+ p.setLocation(new File(File.separatorChar+"a"));
+ String[] l = p.list();
+ if (isUnixStyle) {
+ assertEquals(1, l.length);
+ assertEquals("/a", l[0]);
+ } else if (isNetWare) {
+ assertEquals(1, l.length);
+ assertEquals("\\a", l[0]);
+ } else {
+ assertEquals(1, l.length);
+ assertEquals(":\\a", l[0].substring(1));
+ }
+ }
+
+ @Test
+ public void testAppending() {
+ Path p = new Path(project, "/a:/b");
+ String[] l = p.list();
+ assertEquals("2 after construction", 2, l.length);
+ p.setLocation(new File("/c"));
+ l = p.list();
+ assertEquals("3 after setLocation", 3, l.length);
+ p.setPath("\\d;\\e");
+ l = p.list();
+ assertEquals("5 after setPath", 5, l.length);
+ p.append(new Path(project, "\\f"));
+ l = p.list();
+ assertEquals("6 after append", 6, l.length);
+ p.createPath().setLocation(new File("/g"));
+ l = p.list();
+ assertEquals("7 after append", 7, l.length);
+ }
+
+ @Test
+ public void testEmpyPath() {
+ Path p = new Path(project, "");
+ String[] l = p.list();
+ assertEquals("0 after construction", 0, l.length);
+ p.setPath("");
+ l = p.list();
+ assertEquals("0 after setPath", 0, l.length);
+ p.append(new Path(project));
+ l = p.list();
+ assertEquals("0 after append", 0, l.length);
+ p.createPath();
+ l = p.list();
+ assertEquals("0 after append", 0, l.length);
+ }
+
+ @Test
+ public void testUnique() {
+ Path p = new Path(project, "/a:/a");
+ String[] l = p.list();
+ assertEquals("1 after construction", 1, l.length);
+ String base = new File(File.separator).getAbsolutePath();
+ p.setLocation(new File(base, "a"));
+ l = p.list();
+ assertEquals("1 after setLocation", 1, l.length);
+ p.setPath("\\a;/a");
+ l = p.list();
+ assertEquals("1 after setPath", 1, l.length);
+ p.append(new Path(project, "/a;\\a:\\a"));
+ l = p.list();
+ assertEquals("1 after append", 1, l.length);
+ p.createPath().setPath("\\a:/a");
+ l = p.list();
+ assertEquals("1 after append", 1, l.length);
+ }
+
+ @Test
+ public void testEmptyElementIfIsReference() {
+ Path p = new Path(project, "/a:/a");
+ try {
+ p.setRefid(new Reference(project, "dummyref"));
+ fail("Can add reference to Path with elements from constructor");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute when using refid",
+ be.getMessage());
+ }
+
+ p = new Path(project);
+ p.setLocation(new File("/a"));
+ try {
+ p.setRefid(new Reference(project, "dummyref"));
+ fail("Can add reference to Path with elements from setLocation");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute when using refid",
+ be.getMessage());
+ }
+
+ Path another = new Path(project, "/a:/a");
+ project.addReference("dummyref", another);
+ p = new Path(project);
+ p.setRefid(new Reference(project, "dummyref"));
+ try {
+ p.setLocation(new File("/a"));
+ fail("Can set location in Path that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute when using refid",
+ be.getMessage());
+ }
+
+ try {
+ p.setPath("/a;\\a");
+ fail("Can set path in Path that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute when using refid",
+ be.getMessage());
+ }
+
+ try {
+ p.createPath();
+ fail("Can create nested Path in Path that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify nested elements when using refid",
+ be.getMessage());
+ }
+
+ try {
+ p.createPathElement();
+ fail("Can create nested PathElement in Path that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify nested elements when using refid",
+ be.getMessage());
+ }
+
+ try {
+ p.addFileset(new FileSet());
+ fail("Can add nested FileSet in Path that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify nested elements when using refid",
+ be.getMessage());
+ }
+
+ try {
+ p.addFilelist(new FileList());
+ fail("Can add nested FileList in Path that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify nested elements when using refid",
+ be.getMessage());
+ }
+
+ try {
+ p.addDirset(new DirSet());
+ fail("Can add nested Dirset in Path that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify nested elements when using refid",
+ be.getMessage());
+ }
+ }
+
+ @Test
+ public void testCircularReferenceCheck() {
+ Path p = new Path(project);
+ project.addReference("dummy", p);
+ p.setRefid(new Reference(project, "dummy"));
+ try {
+ p.list();
+ fail("Can make Path a Reference to itself.");
+ } catch (BuildException be) {
+ assertEquals("This data type contains a circular reference.",
+ be.getMessage());
+ }
+
+ // dummy1 --> dummy2 --> dummy3 --> dummy1
+ Path p1 = new Path(project);
+ project.addReference("dummy1", p1);
+ Path p2 = p1.createPath();
+ project.addReference("dummy2", p2);
+ Path p3 = p2.createPath();
+ project.addReference("dummy3", p3);
+ p3.setRefid(new Reference(project, "dummy1"));
+ try {
+ p1.list();
+ fail("Can make circular reference.");
+ } catch (BuildException be) {
+ assertEquals("This data type contains a circular reference.",
+ be.getMessage());
+ }
+
+ // dummy1 --> dummy2 --> dummy3 (with Path "/a")
+ p1 = new Path(project);
+ project.addReference("dummy1", p1);
+ p2 = p1.createPath();
+ project.addReference("dummy2", p2);
+ p3 = p2.createPath();
+ project.addReference("dummy3", p3);
+ p3.setLocation(new File("/a"));
+ String[] l = p1.list();
+ assertEquals("One element buried deep inside a nested path structure",
+ 1, l.length);
+ if (isUnixStyle) {
+ assertEquals("/a", l[0]);
+ } else if (isNetWare) {
+ assertEquals("\\a", l[0]);
+ } else {
+ assertEquals(":\\a", l[0].substring(1));
+ }
+ }
+
+ @Test
+ public void testFileList() {
+ Path p = new Path(project);
+ FileList f = new FileList();
+ f.setProject(project);
+ f.setDir(project.resolveFile("."));
+ f.setFiles("build.xml");
+ p.addFilelist(f);
+ String[] l = p.list();
+ assertEquals(1, l.length);
+ assertEquals(project.resolveFile("build.xml").getAbsolutePath(), l[0]);
+ }
+
+ @Test
+ public void testFileSet() {
+ Path p = new Path(project);
+ FileSet f = new FileSet();
+ f.setProject(project);
+ f.setDir(project.resolveFile("."));
+ f.setIncludes("build.xml");
+ p.addFileset(f);
+ String[] l = p.list();
+ assertEquals(1, l.length);
+ assertEquals(project.resolveFile("build.xml").getAbsolutePath(), l[0]);
+ }
+
+ @Test
+ public void testDirSet() {
+ Path p = new Path(project);
+ DirSet d = new DirSet();
+ d.setProject(project);
+ d.setDir(project.resolveFile("."));
+ d.setIncludes("build");
+ p.addDirset(d);
+ String[] l = p.list();
+ assertEquals(1, l.length);
+ assertEquals(project.resolveFile("build").getAbsolutePath(), l[0]);
+ }
+
+ @Test
+ public void testRecursion() {
+ Path p = new Path(project);
+ try {
+ p.append(p);
+ assertEquals(0, p.list().length);
+ } catch (BuildException x) {
+ String m = x.toString();
+ assertTrue(m, m.indexOf("circular") != -1);
+ }
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java b/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java
index 065d757db..c88b49a5c 100644
--- a/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java
@@ -1,206 +1,206 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.Project;
-import org.junit.Before;
-import org.junit.Test;
-
-import java.io.File;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-/**
- * JUnit 3 testcases for org.apache.tools.ant.types.PatternSet.
- *
- *
This doesn't actually test much, mainly reference handling.
- *
- */
-
-public class PatternSetTest {
-
- private Project project;
-
- @Before
- public void setUp() {
- project = new Project();
- project.setBasedir(".");
- }
-
- @Test
- public void testEmptyElementIfIsReference() {
- PatternSet p = new PatternSet();
- p.setIncludes("**/*.java");
- try {
- p.setRefid(new Reference(project, "dummyref"));
- fail("Can add reference to PatternSet with elements from setIncludes");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute when using refid",
- be.getMessage());
- }
-
- p = new PatternSet();
- p.setRefid(new Reference(project, "dummyref"));
- try {
- p.setIncludes("**/*.java");
- fail("Can set includes in PatternSet that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute when using refid",
- be.getMessage());
- }
-
- p = new PatternSet();
- p.setRefid(new Reference(project, "dummyref"));
- try {
- p.setIncludesfile(new File("/a"));
- fail("Can set includesfile in PatternSet that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute when using refid",
- be.getMessage());
- }
- try {
- p.setExcludes("**/*.java");
- fail("Can set excludes in PatternSet that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute when using refid",
- be.getMessage());
- }
- try {
- p.setExcludesfile(new File("/a"));
- fail("Can set excludesfile in PatternSet that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify more than one attribute when using refid",
- be.getMessage());
- }
- try {
- p.createInclude();
- fail("Can add nested include in PatternSet that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify nested elements when using refid",
- be.getMessage());
- }
- try {
- p.createExclude();
- fail("Can add nested exclude in PatternSet that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify nested elements when using refid",
- be.getMessage());
- }
- try {
- p.createIncludesFile();
- fail("Can add nested includesfile in PatternSet that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify nested elements when using refid",
- be.getMessage());
- }
- try {
- p.createExcludesFile();
- fail("Can add nested excludesfile in PatternSet that is a reference.");
- } catch (BuildException be) {
- assertEquals("You must not specify nested elements when using refid",
- be.getMessage());
- }
- }
-
- @Test
- public void testCircularReferenceCheck() {
- PatternSet p = new PatternSet();
- project.addReference("dummy", p);
- p.setRefid(new Reference(project, "dummy"));
- try {
- p.getIncludePatterns(project);
- fail("Can make PatternSet a Reference to itself.");
- } catch (BuildException be) {
- assertEquals("This data type contains a circular reference.",
- be.getMessage());
- }
- try {
- p.getExcludePatterns(project);
- fail("Can make PatternSet a Reference to itself.");
- } catch (BuildException be) {
- assertEquals("This data type contains a circular reference.",
- be.getMessage());
- }
-
- // dummy1 --> dummy2 --> dummy3 --> dummy1
- PatternSet p1 = new PatternSet();
- project.addReference("dummy1", p1);
- p1.setRefid(new Reference(project, "dummy2"));
- PatternSet p2 = new PatternSet();
- project.addReference("dummy2", p2);
- p2.setRefid(new Reference(project, "dummy3"));
- PatternSet p3 = new PatternSet();
- project.addReference("dummy3", p3);
- p3.setRefid(new Reference(project, "dummy1"));
- try {
- p1.getIncludePatterns(project);
- fail("Can make circular reference.");
- } catch (BuildException be) {
- assertEquals("This data type contains a circular reference.",
- be.getMessage());
- }
- try {
- p1.getExcludePatterns(project);
- fail("Can make circular reference.");
- } catch (BuildException be) {
- assertEquals("This data type contains a circular reference.",
- be.getMessage());
- }
-
- // dummy1 --> dummy2 --> dummy3
- // (which holds patterns "include" and "exclude")
- p1 = new PatternSet();
- project.addReference("dummy1", p1);
- p1.setRefid(new Reference(project, "dummy2"));
- p2 = new PatternSet();
- project.addReference("dummy2", p2);
- p2.setRefid(new Reference(project, "dummy3"));
- p3 = new PatternSet();
- project.addReference("dummy3", p3);
- p3.setIncludes("include");
- p3.createExclude().setName("exclude");
- String[] i = p1.getIncludePatterns(project);
- assertEquals("One include pattern buried deep inside a nested patternset structure",
- 1, i.length);
- assertEquals("include", i[0]);
- i = p3.getExcludePatterns(project);
- assertEquals("One exclude pattern buried deep inside a nested patternset structure",
- 1, i.length);
- assertEquals("exclude", i[0]);
- }
-
- @Test
- public void testNestedPatternset() {
- PatternSet p = new PatternSet();
- p.setIncludes("**/*.java");
-
- PatternSet nested = new PatternSet();
- nested.setExcludes("**/*.class");
-
- p.addConfiguredPatternset(nested);
-
- String[] excludes = p.getExcludePatterns(project);
- String[] includes = p.getIncludePatterns(project);
-
- assertEquals("Includes","**/*.java", includes[0]);
- assertEquals("Excludes","**/*.class", excludes[0]);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.Project;
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * JUnit 3 testcases for org.apache.tools.ant.types.PatternSet.
+ *
+ *
This doesn't actually test much, mainly reference handling.
+ *
+ */
+
+public class PatternSetTest {
+
+ private Project project;
+
+ @Before
+ public void setUp() {
+ project = new Project();
+ project.setBasedir(".");
+ }
+
+ @Test
+ public void testEmptyElementIfIsReference() {
+ PatternSet p = new PatternSet();
+ p.setIncludes("**/*.java");
+ try {
+ p.setRefid(new Reference(project, "dummyref"));
+ fail("Can add reference to PatternSet with elements from setIncludes");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute when using refid",
+ be.getMessage());
+ }
+
+ p = new PatternSet();
+ p.setRefid(new Reference(project, "dummyref"));
+ try {
+ p.setIncludes("**/*.java");
+ fail("Can set includes in PatternSet that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute when using refid",
+ be.getMessage());
+ }
+
+ p = new PatternSet();
+ p.setRefid(new Reference(project, "dummyref"));
+ try {
+ p.setIncludesfile(new File("/a"));
+ fail("Can set includesfile in PatternSet that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute when using refid",
+ be.getMessage());
+ }
+ try {
+ p.setExcludes("**/*.java");
+ fail("Can set excludes in PatternSet that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute when using refid",
+ be.getMessage());
+ }
+ try {
+ p.setExcludesfile(new File("/a"));
+ fail("Can set excludesfile in PatternSet that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify more than one attribute when using refid",
+ be.getMessage());
+ }
+ try {
+ p.createInclude();
+ fail("Can add nested include in PatternSet that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify nested elements when using refid",
+ be.getMessage());
+ }
+ try {
+ p.createExclude();
+ fail("Can add nested exclude in PatternSet that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify nested elements when using refid",
+ be.getMessage());
+ }
+ try {
+ p.createIncludesFile();
+ fail("Can add nested includesfile in PatternSet that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify nested elements when using refid",
+ be.getMessage());
+ }
+ try {
+ p.createExcludesFile();
+ fail("Can add nested excludesfile in PatternSet that is a reference.");
+ } catch (BuildException be) {
+ assertEquals("You must not specify nested elements when using refid",
+ be.getMessage());
+ }
+ }
+
+ @Test
+ public void testCircularReferenceCheck() {
+ PatternSet p = new PatternSet();
+ project.addReference("dummy", p);
+ p.setRefid(new Reference(project, "dummy"));
+ try {
+ p.getIncludePatterns(project);
+ fail("Can make PatternSet a Reference to itself.");
+ } catch (BuildException be) {
+ assertEquals("This data type contains a circular reference.",
+ be.getMessage());
+ }
+ try {
+ p.getExcludePatterns(project);
+ fail("Can make PatternSet a Reference to itself.");
+ } catch (BuildException be) {
+ assertEquals("This data type contains a circular reference.",
+ be.getMessage());
+ }
+
+ // dummy1 --> dummy2 --> dummy3 --> dummy1
+ PatternSet p1 = new PatternSet();
+ project.addReference("dummy1", p1);
+ p1.setRefid(new Reference(project, "dummy2"));
+ PatternSet p2 = new PatternSet();
+ project.addReference("dummy2", p2);
+ p2.setRefid(new Reference(project, "dummy3"));
+ PatternSet p3 = new PatternSet();
+ project.addReference("dummy3", p3);
+ p3.setRefid(new Reference(project, "dummy1"));
+ try {
+ p1.getIncludePatterns(project);
+ fail("Can make circular reference.");
+ } catch (BuildException be) {
+ assertEquals("This data type contains a circular reference.",
+ be.getMessage());
+ }
+ try {
+ p1.getExcludePatterns(project);
+ fail("Can make circular reference.");
+ } catch (BuildException be) {
+ assertEquals("This data type contains a circular reference.",
+ be.getMessage());
+ }
+
+ // dummy1 --> dummy2 --> dummy3
+ // (which holds patterns "include" and "exclude")
+ p1 = new PatternSet();
+ project.addReference("dummy1", p1);
+ p1.setRefid(new Reference(project, "dummy2"));
+ p2 = new PatternSet();
+ project.addReference("dummy2", p2);
+ p2.setRefid(new Reference(project, "dummy3"));
+ p3 = new PatternSet();
+ project.addReference("dummy3", p3);
+ p3.setIncludes("include");
+ p3.createExclude().setName("exclude");
+ String[] i = p1.getIncludePatterns(project);
+ assertEquals("One include pattern buried deep inside a nested patternset structure",
+ 1, i.length);
+ assertEquals("include", i[0]);
+ i = p3.getExcludePatterns(project);
+ assertEquals("One exclude pattern buried deep inside a nested patternset structure",
+ 1, i.length);
+ assertEquals("exclude", i[0]);
+ }
+
+ @Test
+ public void testNestedPatternset() {
+ PatternSet p = new PatternSet();
+ p.setIncludes("**/*.java");
+
+ PatternSet nested = new PatternSet();
+ nested.setExcludes("**/*.class");
+
+ p.addConfiguredPatternset(nested);
+
+ String[] excludes = p.getExcludePatterns(project);
+ String[] includes = p.getIncludePatterns(project);
+
+ assertEquals("Includes","**/*.java", includes[0]);
+ assertEquals("Excludes","**/*.class", excludes[0]);
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/PermissionsTest.java b/src/tests/junit/org/apache/tools/ant/types/PermissionsTest.java
index 1e43fe1a1..37e643d08 100644
--- a/src/tests/junit/org/apache/tools/ant/types/PermissionsTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/PermissionsTest.java
@@ -1,158 +1,158 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types;
-
-import org.apache.tools.ant.ExitException;
-import org.junit.Before;
-import org.junit.Test;
-
-import static org.junit.Assert.fail;
-
-/**
- * JUnit 3 testcases for org.apache.tools.ant.types.Permissions.
- *
- */
-public class PermissionsTest {
-
- Permissions perms;
-
- @Before
- public void setUp() {
- perms = new Permissions();
- Permissions.Permission perm = new Permissions.Permission();
- // Grant extra permissions to read and write the user.* properties and read to the
- // java.home property
- perm.setActions("read, write");
- perm.setName("user.*");
- perm.setClass("java.util.PropertyPermission");
- perms.addConfiguredGrant(perm);
-
- perm = new Permissions.Permission();
- perm.setActions("read");
- perm.setName("java.home");
- perm.setClass("java.util.PropertyPermission");
- perms.addConfiguredGrant(perm);
-
- perm = new Permissions.Permission();
- perm.setActions("read");
- perm.setName("file.encoding");
- perm.setClass("java.util.PropertyPermission");
- perms.addConfiguredGrant(perm);
-
- // Revoke permission to write user.home (granted above via user.*), still able to read though.
- // and the default granted permission to read os.name.
- perm = new Permissions.Permission();
- perm.setActions("write");
- perm.setName("user.home");
- perm.setClass("java.util.PropertyPermission");
- perms.addConfiguredRevoke(perm);
-
- perm = new Permissions.Permission();
- perm.setActions("read");
- perm.setName("os.*");
- perm.setClass("java.util.PropertyPermission");
- perms.addConfiguredRevoke(perm);
- }
-
- /** Tests a permission that is granted per default. */
- @Test
- public void testDefaultGranted() {
- perms.setSecurityManager();
- try {
- System.getProperty("line.separator");
- } finally {
- perms.restoreSecurityManager();
- }
- }
-
- /** Tests a permission that has been granted later via wildcard. */
- @Test
- public void testGranted() {
- perms.setSecurityManager();
- try {
- String s = System.getProperty("user.name");
- System.setProperty("user.name", s);
- } finally {
- perms.restoreSecurityManager();
- }
- }
-
- /** Tests a permission that has been granted and revoked later. */
- @Test
- public void testGrantedAndRevoked() {
- perms.setSecurityManager();
- try {
- String s = System.getProperty("user.home");
- System.setProperty("user.home", s);
- fail("Could perform an action that should have been forbidden.");
- } catch (SecurityException e){
- // Was expected, test passes
- } finally {
- perms.restoreSecurityManager();
- }
- }
-
- /** Tests a permission that is granted as per default but revoked later via wildcard. */
- @Test
- public void testDefaultRevoked() {
- perms.setSecurityManager();
- try {
- System.getProperty("os.name");
- fail("Could perform an action that should have been forbidden.");
- } catch (SecurityException e){
- // Was expected, test passes
- } finally {
- perms.restoreSecurityManager();
- }
- }
- /** Tests a permission that has not been granted or revoked. */
- @Test
- public void testOther() {
- String ls = System.getProperty("line.separator");
- perms.setSecurityManager();
- try {
- System.setProperty("line.separator",ls);
- fail("Could perform an action that should have been forbidden.");
- } catch (SecurityException e){
- //TODO assert exception message
- // Was expected, test passes
- } finally {
- perms.restoreSecurityManager();
- }
- }
-
- /** Tests an exit condition. */
- @Test
- public void testExit() {
- perms.setSecurityManager();
- try {
- System.out.println("If this is the last line on standard out the testExit f.a.i.l.e.d");
- System.exit(3);
- fail("Totaly impossible that this fail is ever executed. Please let me know if it is!");
- } catch (ExitException e) {
- if (e.getStatus() != 3) {
- fail("Received wrong exit status in Exit Exception.");
- }
- System.out.println("testExit successful.");
- } finally {
- perms.restoreSecurityManager();
- }
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types;
+
+import org.apache.tools.ant.ExitException;
+import org.junit.Before;
+import org.junit.Test;
+
+import static org.junit.Assert.fail;
+
+/**
+ * JUnit 3 testcases for org.apache.tools.ant.types.Permissions.
+ *
+ */
+public class PermissionsTest {
+
+ Permissions perms;
+
+ @Before
+ public void setUp() {
+ perms = new Permissions();
+ Permissions.Permission perm = new Permissions.Permission();
+ // Grant extra permissions to read and write the user.* properties and read to the
+ // java.home property
+ perm.setActions("read, write");
+ perm.setName("user.*");
+ perm.setClass("java.util.PropertyPermission");
+ perms.addConfiguredGrant(perm);
+
+ perm = new Permissions.Permission();
+ perm.setActions("read");
+ perm.setName("java.home");
+ perm.setClass("java.util.PropertyPermission");
+ perms.addConfiguredGrant(perm);
+
+ perm = new Permissions.Permission();
+ perm.setActions("read");
+ perm.setName("file.encoding");
+ perm.setClass("java.util.PropertyPermission");
+ perms.addConfiguredGrant(perm);
+
+ // Revoke permission to write user.home (granted above via user.*), still able to read though.
+ // and the default granted permission to read os.name.
+ perm = new Permissions.Permission();
+ perm.setActions("write");
+ perm.setName("user.home");
+ perm.setClass("java.util.PropertyPermission");
+ perms.addConfiguredRevoke(perm);
+
+ perm = new Permissions.Permission();
+ perm.setActions("read");
+ perm.setName("os.*");
+ perm.setClass("java.util.PropertyPermission");
+ perms.addConfiguredRevoke(perm);
+ }
+
+ /** Tests a permission that is granted per default. */
+ @Test
+ public void testDefaultGranted() {
+ perms.setSecurityManager();
+ try {
+ System.getProperty("line.separator");
+ } finally {
+ perms.restoreSecurityManager();
+ }
+ }
+
+ /** Tests a permission that has been granted later via wildcard. */
+ @Test
+ public void testGranted() {
+ perms.setSecurityManager();
+ try {
+ String s = System.getProperty("user.name");
+ System.setProperty("user.name", s);
+ } finally {
+ perms.restoreSecurityManager();
+ }
+ }
+
+ /** Tests a permission that has been granted and revoked later. */
+ @Test
+ public void testGrantedAndRevoked() {
+ perms.setSecurityManager();
+ try {
+ String s = System.getProperty("user.home");
+ System.setProperty("user.home", s);
+ fail("Could perform an action that should have been forbidden.");
+ } catch (SecurityException e){
+ // Was expected, test passes
+ } finally {
+ perms.restoreSecurityManager();
+ }
+ }
+
+ /** Tests a permission that is granted as per default but revoked later via wildcard. */
+ @Test
+ public void testDefaultRevoked() {
+ perms.setSecurityManager();
+ try {
+ System.getProperty("os.name");
+ fail("Could perform an action that should have been forbidden.");
+ } catch (SecurityException e){
+ // Was expected, test passes
+ } finally {
+ perms.restoreSecurityManager();
+ }
+ }
+ /** Tests a permission that has not been granted or revoked. */
+ @Test
+ public void testOther() {
+ String ls = System.getProperty("line.separator");
+ perms.setSecurityManager();
+ try {
+ System.setProperty("line.separator",ls);
+ fail("Could perform an action that should have been forbidden.");
+ } catch (SecurityException e){
+ //TODO assert exception message
+ // Was expected, test passes
+ } finally {
+ perms.restoreSecurityManager();
+ }
+ }
+
+ /** Tests an exit condition. */
+ @Test
+ public void testExit() {
+ perms.setSecurityManager();
+ try {
+ System.out.println("If this is the last line on standard out the testExit f.a.i.l.e.d");
+ System.exit(3);
+ fail("Totaly impossible that this fail is ever executed. Please let me know if it is!");
+ } catch (ExitException e) {
+ if (e.getStatus() != 3) {
+ fail("Received wrong exit status in Exit Exception.");
+ }
+ System.out.println("testExit successful.");
+ } finally {
+ perms.restoreSecurityManager();
+ }
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/PolyTest.java b/src/tests/junit/org/apache/tools/ant/types/PolyTest.java
index 0d5e2ceb4..89f6268ba 100644
--- a/src/tests/junit/org/apache/tools/ant/types/PolyTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/PolyTest.java
@@ -1,79 +1,79 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types;
-
-import org.apache.tools.ant.AntAssert;
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-public class PolyTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/types/poly.xml");
- }
-
- @Test
- public void testFileSet() {
- buildRule.executeTarget("fileset");
- AntAssert.assertContains( "types.FileSet", buildRule.getLog());
- }
-
- @Test
- public void testFileSetAntType() {
- buildRule.executeTarget("fileset-ant-type");
- AntAssert.assertContains("types.PolyTest$MyFileSet", buildRule.getLog());
- }
-
- @Test
- public void testPath() {
- buildRule.executeTarget("path");
- AntAssert.assertContains( "types.Path", buildRule.getLog());
- }
-
- @Test
- public void testPathAntType() {
- buildRule.executeTarget("path-ant-type");
- AntAssert.assertContains( "types.PolyTest$MyPath", buildRule.getLog());
- }
-
- public static class MyFileSet extends FileSet {}
-
- public static class MyPath extends Path {
- public MyPath(Project project) {
- super(project);
- }
- }
-
- public static class MyTask extends Task {
- public void addPath(Path path) {
- log("class of path is " + path.getClass());
- }
- public void addFileset(FileSet fileset) {
- log("class of fileset is " + fileset.getClass());
- }
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types;
+
+import org.apache.tools.ant.AntAssert;
+import org.apache.tools.ant.BuildFileRule;
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+public class PolyTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/types/poly.xml");
+ }
+
+ @Test
+ public void testFileSet() {
+ buildRule.executeTarget("fileset");
+ AntAssert.assertContains( "types.FileSet", buildRule.getLog());
+ }
+
+ @Test
+ public void testFileSetAntType() {
+ buildRule.executeTarget("fileset-ant-type");
+ AntAssert.assertContains("types.PolyTest$MyFileSet", buildRule.getLog());
+ }
+
+ @Test
+ public void testPath() {
+ buildRule.executeTarget("path");
+ AntAssert.assertContains( "types.Path", buildRule.getLog());
+ }
+
+ @Test
+ public void testPathAntType() {
+ buildRule.executeTarget("path-ant-type");
+ AntAssert.assertContains( "types.PolyTest$MyPath", buildRule.getLog());
+ }
+
+ public static class MyFileSet extends FileSet {}
+
+ public static class MyPath extends Path {
+ public MyPath(Project project) {
+ super(project);
+ }
+ }
+
+ public static class MyTask extends Task {
+ public void addPath(Path path) {
+ log("class of path is " + path.getClass());
+ }
+ public void addFileset(FileSet fileset) {
+ log("class of fileset is " + fileset.getClass());
+ }
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java b/src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java
index f4c2abe0c..62c76f0dc 100644
--- a/src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/RedirectorElementTest.java
@@ -1,86 +1,86 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.apache.tools.ant.types;
-
-import org.apache.tools.ant.AntAssert;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.Project;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-public class RedirectorElementTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/types/redirector.xml", Project.MSG_VERBOSE);
- }
-
- @Test
- public void test1() {
- buildRule.executeTarget("test1");
- assertTrue((buildRule.getProject().
+ *
+ *
Note that the right way to call this is within a try block,
+ * with a finally clause that calls cleanupBed(). You place tests of
+ * the isSelected() method within the try block.
+ */
+ protected void makeBed() {
+ tbed = new TaskdefForMakingBed("setupfiles");
+ tbed.setUp();
+ tbed.makeTestbed();
+ }
+
+ /**
+ * Cleans up the testbed by calling a target in the
+ * src/etc/testcases/types/selectors.xml file.
+ */
+ protected void cleanupBed() {
+ if (tbed != null) {
+ tbed.tearDown();
+ tbed = null;
+ }
+ }
+
+
+ /**
+ *
Creates a mirror of the testbed for use in dependency checks.
+ *
+ *
Note that the right way to call this is within a try block,
+ * with a finally clause that calls cleanupMirror(). You place tests of
+ * the isSelected() method within the try block.
+ */
+ protected void makeMirror() {
+ tbed = new TaskdefForMakingBed("mirrorfiles");
+ tbed.setUp();
+ tbed.makeMirror();
+ }
+
+ /**
+ * Cleans up the mirror testbed by calling a target in the
+ * src/etc/testcases/types/selectors.xml file.
+ */
+ protected void cleanupMirror() {
+ if (tbed != null) {
+ tbed.deleteMirror();
+ tbed = null;
+ }
+ }
+
+ private class TaskdefForMakingBed extends BuildFileTest {
+
+ TaskdefForMakingBed(String name) {
+ super(name);
+ }
+
+ public void setUp() {
+ configureProject("src/etc/testcases/types/selectors.xml");
+ }
+
+ public void tearDown() {
+ try {
+ super.tearDown();
+ } catch (Exception exc) {
+ // ignore
+ }
+ }
+
+ public void makeTestbed() {
+ executeTarget("setupfiles");
+ }
+
+ public void makeMirror() {
+ executeTarget("mirrorfiles");
+ }
+
+ public void deleteMirror() {
+ executeTarget("tearDown");
+ }
+ }
+
+
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java
index 41e9c8309..6dc8d7235 100644
--- a/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsRegexpTest.java
@@ -1,56 +1,56 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types.selectors;
-
-import java.io.File;
-
-import org.apache.tools.ant.BuildFileRule;
-import org.junit.Before;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-
-
-public class ContainsRegexpTest {
-
- @Rule
- public BuildFileRule buildRule = new BuildFileRule();
-
- @Before
- public void setUp() {
- buildRule.configureProject("src/etc/testcases/types/selectors.xml");
- }
-
- @Test
- public void testContainsRegexp() {
- buildRule.executeTarget("containsregexp");
- File dir = new File(buildRule.getOutputDir(), "regexpseltestdest");
- File[] files = dir.listFiles();
- int filecount = files.length;
-
- if (filecount != 1) {
- assertEquals("ContainsRegexp test should have copied 1 file",
- 1, files.length);
-
- }
- }
-
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types.selectors;
+
+import java.io.File;
+
+import org.apache.tools.ant.BuildFileRule;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+
+public class ContainsRegexpTest {
+
+ @Rule
+ public BuildFileRule buildRule = new BuildFileRule();
+
+ @Before
+ public void setUp() {
+ buildRule.configureProject("src/etc/testcases/types/selectors.xml");
+ }
+
+ @Test
+ public void testContainsRegexp() {
+ buildRule.executeTarget("containsregexp");
+ File dir = new File(buildRule.getOutputDir(), "regexpseltestdest");
+ File[] files = dir.listFiles();
+ int filecount = files.length;
+
+ if (filecount != 1) {
+ assertEquals("ContainsRegexp test should have copied 1 file",
+ 1, files.length);
+
+ }
+ }
+
+}
+
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java
index 9a5a83fe1..822bf3edc 100644
--- a/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/ContainsSelectorTest.java
@@ -1,114 +1,114 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types.selectors;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.types.Parameter;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-/**
- * Tests Contains Selectors.
- *
- */
-public class ContainsSelectorTest {
-
- @Rule
- public final BaseSelectorRule selectorRule = new BaseSelectorRule();
-
-
- /**
- * Test the code that validates the selector.
- */
- @Test
- public void testValidate() {
- ContainsSelector s = new ContainsSelector();
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("ContainsSelector did not check for required field 'text'");
- } catch (BuildException be1) {
- assertEquals("The text attribute is required", be1.getMessage());
- }
-
- s = new ContainsSelector();
- Parameter param = new Parameter();
- param.setName("garbage in");
- param.setValue("garbage out");
- Parameter[] params = {param};
- s.setParameters(params);
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("ContainsSelector did not check for valid parameter element");
- } catch (BuildException be2) {
- assertEquals("Invalid parameter garbage in", be2.getMessage());
- }
-
- }
-
- /**
- * Tests to make sure that the selector is selecting files correctly.
- */
- @Test
- public void testSelectionBehaviour() {
- ContainsSelector s;
- String results;
-
-
- s = new ContainsSelector();
- s.setText("no such string in test files");
- results = selectorRule.selectionString(s);
- assertEquals("TFFFFFFFFFFT", results);
-
- s = new ContainsSelector();
- s.setText("Apache Ant");
- results = selectorRule.selectionString(s);
- assertEquals("TFFFTFFFFFFT", results);
-
- s = new ContainsSelector();
- s.setText("apache ant");
- s.setCasesensitive(true);
- results = selectorRule.selectionString(s);
- assertEquals("TFFFFFFFFFFT", results);
-
- s = new ContainsSelector();
- s.setText("apache ant");
- s.setCasesensitive(false);
- results = selectorRule.selectionString(s);
- assertEquals("TFFFTFFFFFFT", results);
-
- s = new ContainsSelector();
- s.setText("ApacheAnt");
- s.setIgnorewhitespace(true);
- results = selectorRule.selectionString(s);
- assertEquals("TFFFTFFFFFFT", results);
-
- s = new ContainsSelector();
- s.setText("A p a c h e A n t");
- s.setIgnorewhitespace(true);
- results = selectorRule.selectionString(s);
- assertEquals("TFFFTFFFFFFT", results);
-
-
-
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types.selectors;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.Parameter;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests Contains Selectors.
+ *
+ */
+public class ContainsSelectorTest {
+
+ @Rule
+ public final BaseSelectorRule selectorRule = new BaseSelectorRule();
+
+
+ /**
+ * Test the code that validates the selector.
+ */
+ @Test
+ public void testValidate() {
+ ContainsSelector s = new ContainsSelector();
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("ContainsSelector did not check for required field 'text'");
+ } catch (BuildException be1) {
+ assertEquals("The text attribute is required", be1.getMessage());
+ }
+
+ s = new ContainsSelector();
+ Parameter param = new Parameter();
+ param.setName("garbage in");
+ param.setValue("garbage out");
+ Parameter[] params = {param};
+ s.setParameters(params);
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("ContainsSelector did not check for valid parameter element");
+ } catch (BuildException be2) {
+ assertEquals("Invalid parameter garbage in", be2.getMessage());
+ }
+
+ }
+
+ /**
+ * Tests to make sure that the selector is selecting files correctly.
+ */
+ @Test
+ public void testSelectionBehaviour() {
+ ContainsSelector s;
+ String results;
+
+
+ s = new ContainsSelector();
+ s.setText("no such string in test files");
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFFFFFFFFFT", results);
+
+ s = new ContainsSelector();
+ s.setText("Apache Ant");
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFFTFFFFFFT", results);
+
+ s = new ContainsSelector();
+ s.setText("apache ant");
+ s.setCasesensitive(true);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFFFFFFFFFT", results);
+
+ s = new ContainsSelector();
+ s.setText("apache ant");
+ s.setCasesensitive(false);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFFTFFFFFFT", results);
+
+ s = new ContainsSelector();
+ s.setText("ApacheAnt");
+ s.setIgnorewhitespace(true);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFFTFFFFFFT", results);
+
+ s = new ContainsSelector();
+ s.setText("A p a c h e A n t");
+ s.setIgnorewhitespace(true);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFFTFFFFFFT", results);
+
+
+
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java
index 6e461bab4..43278f491 100644
--- a/src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/DateSelectorTest.java
@@ -1,229 +1,229 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types.selectors;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.types.Parameter;
-import org.junit.Assume;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-
-/**
- * Tests Date Selectors.
- *
- */
-public class DateSelectorTest {
-
- @Rule
- public final BaseSelectorRule selectorRule = new BaseSelectorRule();
-
-
- /**
- * Test the code that validates the selector.
- */
- @Test
- public void testValidate() {
- DateSelector s = new DateSelector();
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("DateSelector did not check for required fields");
- } catch (BuildException be1) {
- assertEquals("You must provide a datetime or the number of "
- + "milliseconds.", be1.getMessage());
- }
-
- s = new DateSelector();
- s.setDatetime("01/01/1969 01:01 AM");
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("DateSelector did not check for Datetime being in the "
- + "allowable range");
- } catch (BuildException be2) {
- assertEquals("Date of 01/01/1969 01:01 AM results in negative "
- + "milliseconds value relative to epoch (January 1, "
- + "1970, 00:00:00 GMT).", be2.getMessage());
- }
-
- s = new DateSelector();
- s.setDatetime("this is not a date");
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("DateSelector did not check for Datetime being in a "
- + "valid format");
- } catch (BuildException be3) {
- assertEquals("Date of this is not a date"
- + " Cannot be parsed correctly. It should be in"
- + " MM/DD/YYYY HH:MM AM_PM format.", be3.getMessage());
- }
-
- s = new DateSelector();
- Parameter param = new Parameter();
- param.setName("garbage in");
- param.setValue("garbage out");
- Parameter[] params = new Parameter[1];
- params[0] = param;
- s.setParameters(params);
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("DateSelector did not check for valid parameter element");
- } catch (BuildException be4) {
- assertEquals("Invalid parameter garbage in", be4.getMessage());
- }
-
- s = new DateSelector();
- param = new Parameter();
- param.setName("millis");
- param.setValue("garbage out");
- params[0] = param;
- s.setParameters(params);
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("DateSelector did not check for valid millis parameter");
- } catch (BuildException be5) {
- assertEquals("Invalid millisecond setting garbage out",
- be5.getMessage());
- }
-
- s = new DateSelector();
- param = new Parameter();
- param.setName("granularity");
- param.setValue("garbage out");
- params[0] = param;
- s.setParameters(params);
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("DateSelector did not check for valid granularity parameter");
- } catch (BuildException be6) {
- assertEquals("Invalid granularity setting garbage out",
- be6.getMessage());
- }
-
- }
-
- /**
- * Tests to make sure that the selector is selecting files correctly.
- */
- @Test
- public void testSelectionBehaviour() {
- DateSelector s;
- String results;
-
- DateSelector.TimeComparisons before = new
- DateSelector.TimeComparisons();
- before.setValue("before");
- DateSelector.TimeComparisons equal = new
- DateSelector.TimeComparisons();
- equal.setValue("equal");
- DateSelector.TimeComparisons after = new
- DateSelector.TimeComparisons();
- after.setValue("after");
-
-
- s = new DateSelector();
- s.setDatetime("10/10/1999 1:45 PM");
- s.setWhen(before);
- results = selectorRule.selectionString(s);
- assertEquals("TFFFFFFFFFFT", results);
-
- s = new DateSelector();
- s.setDatetime("10/10/1999 1:45 PM");
- s.setWhen(before);
- s.setCheckdirs(true);
- results = selectorRule.selectionString(s);
- assertEquals("FFFFFFFFFFFF", results);
-
- s = new DateSelector();
- s.setDatetime("10/10/1999 1:45 PM");
- s.setWhen(after);
- results = selectorRule.selectionString(s);
- assertEquals("TTTTTTTTTTTT", results);
-
- s = new DateSelector();
- s.setDatetime("11/21/2001 4:54 AM");
- s.setWhen(before);
- results = selectorRule.selectionString(s);
- assertEquals("TFTFFFFFFFFT", results);
-
- s = new DateSelector();
- s.setDatetime("11/21/2001 4:55 AM");
-
- long milliseconds = s.getMillis();
- s.setWhen(equal);
- results = selectorRule.selectionString(s);
- assertEquals("TTFFTFFFTTTT", results);
-
- s = new DateSelector();
- s.setMillis(milliseconds);
- s.setWhen(equal);
- results = selectorRule.selectionString(s);
- assertEquals("TTFFTFFFTTTT", results);
-
- s = new DateSelector();
- s.setDatetime("11/21/2001 4:56 AM");
- s.setWhen(after);
- results = selectorRule.selectionString(s);
- assertEquals("TFFTFTTTFFFT", results);
-
- s = new DateSelector();
- Parameter param1 = new Parameter();
- Parameter param2 = new Parameter();
- param1.setName("datetime");
- param1.setValue("11/21/2001 4:56 AM");
- param2.setName("when");
- param2.setValue("after");
- Parameter[] params = {param1,param2};
- s.setParameters(params);
- results = selectorRule.selectionString(s);
- assertEquals("TFFTFTTTFFFT", results);
-
- s = new DateSelector();
- long testtime = selectorRule.getMirrorFiles()[5].lastModified();
- s.setMillis(testtime);
- s.setWhen(after);
- s.setGranularity(2);
-
- // setup the modified timestamp to match what the test needs, although be aware that the 3rd and 4th
- // files don't exist so can't be changed, so don't try and loop over them
- for (int i = 1; i <=2; i++) {
- Assume.assumeTrue("Cannot setup file times for test", selectorRule.getMirrorFiles()[i].setLastModified(testtime - (3*60*60*100)));
- }
-
-
- results = selectorRule.mirrorSelectionString(s);
- assertEquals("TFFFFTTTTTTT", results);
-
- s = new DateSelector();
- testtime = selectorRule.getMirrorFiles()[6].lastModified();
- s.setMillis(testtime);
- s.setWhen(before);
- s.setGranularity(2);
- for (int i = 7; i <= 10; i++) {
- Assume.assumeTrue("Cannot setup file times for test", selectorRule.getMirrorFiles()[i].setLastModified(testtime + (3*60*60*100)));
- }
-
- results = selectorRule.mirrorSelectionString(s);
- assertEquals("TTTTTTTFFFFT", results);
-
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types.selectors;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.Parameter;
+import org.junit.Assume;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+
+/**
+ * Tests Date Selectors.
+ *
+ */
+public class DateSelectorTest {
+
+ @Rule
+ public final BaseSelectorRule selectorRule = new BaseSelectorRule();
+
+
+ /**
+ * Test the code that validates the selector.
+ */
+ @Test
+ public void testValidate() {
+ DateSelector s = new DateSelector();
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("DateSelector did not check for required fields");
+ } catch (BuildException be1) {
+ assertEquals("You must provide a datetime or the number of "
+ + "milliseconds.", be1.getMessage());
+ }
+
+ s = new DateSelector();
+ s.setDatetime("01/01/1969 01:01 AM");
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("DateSelector did not check for Datetime being in the "
+ + "allowable range");
+ } catch (BuildException be2) {
+ assertEquals("Date of 01/01/1969 01:01 AM results in negative "
+ + "milliseconds value relative to epoch (January 1, "
+ + "1970, 00:00:00 GMT).", be2.getMessage());
+ }
+
+ s = new DateSelector();
+ s.setDatetime("this is not a date");
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("DateSelector did not check for Datetime being in a "
+ + "valid format");
+ } catch (BuildException be3) {
+ assertEquals("Date of this is not a date"
+ + " Cannot be parsed correctly. It should be in"
+ + " MM/DD/YYYY HH:MM AM_PM format.", be3.getMessage());
+ }
+
+ s = new DateSelector();
+ Parameter param = new Parameter();
+ param.setName("garbage in");
+ param.setValue("garbage out");
+ Parameter[] params = new Parameter[1];
+ params[0] = param;
+ s.setParameters(params);
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("DateSelector did not check for valid parameter element");
+ } catch (BuildException be4) {
+ assertEquals("Invalid parameter garbage in", be4.getMessage());
+ }
+
+ s = new DateSelector();
+ param = new Parameter();
+ param.setName("millis");
+ param.setValue("garbage out");
+ params[0] = param;
+ s.setParameters(params);
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("DateSelector did not check for valid millis parameter");
+ } catch (BuildException be5) {
+ assertEquals("Invalid millisecond setting garbage out",
+ be5.getMessage());
+ }
+
+ s = new DateSelector();
+ param = new Parameter();
+ param.setName("granularity");
+ param.setValue("garbage out");
+ params[0] = param;
+ s.setParameters(params);
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("DateSelector did not check for valid granularity parameter");
+ } catch (BuildException be6) {
+ assertEquals("Invalid granularity setting garbage out",
+ be6.getMessage());
+ }
+
+ }
+
+ /**
+ * Tests to make sure that the selector is selecting files correctly.
+ */
+ @Test
+ public void testSelectionBehaviour() {
+ DateSelector s;
+ String results;
+
+ DateSelector.TimeComparisons before = new
+ DateSelector.TimeComparisons();
+ before.setValue("before");
+ DateSelector.TimeComparisons equal = new
+ DateSelector.TimeComparisons();
+ equal.setValue("equal");
+ DateSelector.TimeComparisons after = new
+ DateSelector.TimeComparisons();
+ after.setValue("after");
+
+
+ s = new DateSelector();
+ s.setDatetime("10/10/1999 1:45 PM");
+ s.setWhen(before);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFFFFFFFFFT", results);
+
+ s = new DateSelector();
+ s.setDatetime("10/10/1999 1:45 PM");
+ s.setWhen(before);
+ s.setCheckdirs(true);
+ results = selectorRule.selectionString(s);
+ assertEquals("FFFFFFFFFFFF", results);
+
+ s = new DateSelector();
+ s.setDatetime("10/10/1999 1:45 PM");
+ s.setWhen(after);
+ results = selectorRule.selectionString(s);
+ assertEquals("TTTTTTTTTTTT", results);
+
+ s = new DateSelector();
+ s.setDatetime("11/21/2001 4:54 AM");
+ s.setWhen(before);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFTFFFFFFFFT", results);
+
+ s = new DateSelector();
+ s.setDatetime("11/21/2001 4:55 AM");
+
+ long milliseconds = s.getMillis();
+ s.setWhen(equal);
+ results = selectorRule.selectionString(s);
+ assertEquals("TTFFTFFFTTTT", results);
+
+ s = new DateSelector();
+ s.setMillis(milliseconds);
+ s.setWhen(equal);
+ results = selectorRule.selectionString(s);
+ assertEquals("TTFFTFFFTTTT", results);
+
+ s = new DateSelector();
+ s.setDatetime("11/21/2001 4:56 AM");
+ s.setWhen(after);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFTFTTTFFFT", results);
+
+ s = new DateSelector();
+ Parameter param1 = new Parameter();
+ Parameter param2 = new Parameter();
+ param1.setName("datetime");
+ param1.setValue("11/21/2001 4:56 AM");
+ param2.setName("when");
+ param2.setValue("after");
+ Parameter[] params = {param1,param2};
+ s.setParameters(params);
+ results = selectorRule.selectionString(s);
+ assertEquals("TFFTFTTTFFFT", results);
+
+ s = new DateSelector();
+ long testtime = selectorRule.getMirrorFiles()[5].lastModified();
+ s.setMillis(testtime);
+ s.setWhen(after);
+ s.setGranularity(2);
+
+ // setup the modified timestamp to match what the test needs, although be aware that the 3rd and 4th
+ // files don't exist so can't be changed, so don't try and loop over them
+ for (int i = 1; i <=2; i++) {
+ Assume.assumeTrue("Cannot setup file times for test", selectorRule.getMirrorFiles()[i].setLastModified(testtime - (3*60*60*100)));
+ }
+
+
+ results = selectorRule.mirrorSelectionString(s);
+ assertEquals("TFFFFTTTTTTT", results);
+
+ s = new DateSelector();
+ testtime = selectorRule.getMirrorFiles()[6].lastModified();
+ s.setMillis(testtime);
+ s.setWhen(before);
+ s.setGranularity(2);
+ for (int i = 7; i <= 10; i++) {
+ Assume.assumeTrue("Cannot setup file times for test", selectorRule.getMirrorFiles()[i].setLastModified(testtime + (3*60*60*100)));
+ }
+
+ results = selectorRule.mirrorSelectionString(s);
+ assertEquals("TTTTTTTFFFFT", results);
+
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/DependSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/DependSelectorTest.java
index ec95878a8..078052fb4 100644
--- a/src/tests/junit/org/apache/tools/ant/types/selectors/DependSelectorTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/DependSelectorTest.java
@@ -1,185 +1,185 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types.selectors;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.types.Mapper;
-import org.junit.Rule;
-import org.junit.Test;
-
-import java.io.File;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-
-/**
- * Tests Depend Selectors
- *
- */
-public class DependSelectorTest {
-
- @Rule
- public final BaseSelectorRule selectorRule = new BaseSelectorRule();
-
- @Test
- public void testValidateSingleMapper() {
- try {
- DependSelector s = new DependSelector();
- s.createMapper();
- s.createMapper();
- fail("DependSelector allowed more than one nested mapper.");
- } catch (BuildException be1) {
- assertEquals("Cannot define more than one mapper",
- be1.getMessage());
- }
- }
-
-
- @Test
- public void testValidateRequiredFields() {
- try {
- DependSelector s = new DependSelector();
- s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0], selectorRule.getFiles()[0]);
- fail("DependSelector did not check for required fields");
- } catch (BuildException be2) {
- assertEquals("The targetdir attribute is required.",
- be2.getMessage());
- }
-
- }
-
- @Test
- public void testNoMapper() {
- DependSelector s = new DependSelector();
- s.setTargetdir(selectorRule.getBeddir());
-
- String results = selectorRule.selectionString(s);
- assertEquals("FFFFFFFFFFFF", results);
- }
-
- @Test
- public void testIdentityMapper() {
- DependSelector s = new DependSelector();
- s.setTargetdir(selectorRule.getBeddir());
-
- Mapper.MapperType identity = new Mapper.MapperType();
- identity.setValue("identity");
-
- Mapper m = s.createMapper();
- m.setType(identity);
-
- String results = selectorRule.selectionString(s);
- assertEquals("FFFFFFFFFFFF", results);
- }
-
- @Test
- public void testMergeMapper() {
- DependSelector s = new DependSelector();
- s.setTargetdir(selectorRule.getBeddir());
-
- Mapper.MapperType merge = new Mapper.MapperType();
- merge.setValue("merge");
-
- Mapper m = s.createMapper();
- m.setType(merge);
- m.setTo("asf-logo.gif.gz");
-
- String results = selectorRule.selectionString(s);
- assertEquals("TFFFFTTTFFF", results.substring(0,11));
- }
-
- @Test
- public void testMergeMapper2() {
- DependSelector s = new DependSelector();
- s.setTargetdir(selectorRule.getBeddir());
-
- Mapper.MapperType merge = new Mapper.MapperType();
- merge.setValue("merge");
-
- Mapper m = s.createMapper();
- m.setType(merge);
- m.setTo("asf-logo.gif.bz2");
- String results = selectorRule.selectionString(s);
- assertEquals("TTFTTTTTTTTT", results);
- }
-
- @Test
- public void testGlobMapperRelativePath() {
- DependSelector s = new DependSelector();
- File subdir = new File("selectortest/tar/bz2");
- s.setTargetdir(subdir);
-
- Mapper.MapperType glob = new Mapper.MapperType();
- glob.setValue("glob");
-
- Mapper m = s.createMapper();
- m.setType(glob);
- m.setFrom("*.bz2");
- m.setTo("*.tar.bz2");
-
- String results = selectorRule.selectionString(s);
- assertEquals("FFTFFFFFFTTF", results);
- }
-
- @Test
- public void testRestrictedGlobMapper() {
- DependSelector s = new DependSelector();
- File subdir = new File(selectorRule.getBeddir(), "tar/bz2");
- s.setTargetdir(subdir);
-
- Mapper.MapperType glob = new Mapper.MapperType();
- glob.setValue("glob");
-
- Mapper m = s.createMapper();
- m.setType(glob);
- m.setFrom("*.bz2");
- m.setTo("*.tar.bz2");
- String results = selectorRule.selectionString(s);
- assertEquals("FFFFFFFFFTTF", results);
- }
-
- @Test
- public void testSelectionNoMapper() {
- DependSelector s = new DependSelector();
- s.setTargetdir(new File(selectorRule.getOutputDir(), "selectortest2"));
- String results = selectorRule.selectionString(s);
- assertEquals("FFFTTFFFFFFF", results);
- }
-
-
- @Test
- public void testMirroredSelection() {
- DependSelector s = new DependSelector();
- s.setTargetdir(new File(selectorRule.getOutputDir(), "selectortest2/tar/bz2"));
-
- Mapper.MapperType glob = new Mapper.MapperType();
- glob.setValue("glob");
-
- Mapper m = s.createMapper();
- m.setType(glob);
- m.setFrom("*.bz2");
- m.setTo("*.tar.bz2");
- String results = selectorRule.mirrorSelectionString(s);
- assertEquals("FFFFFFFFFTTF", results);
- results = selectorRule.selectionString(s);
- assertEquals("FFFFFFFFFTTF", results);
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types.selectors;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.Mapper;
+import org.junit.Rule;
+import org.junit.Test;
+
+import java.io.File;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+
+/**
+ * Tests Depend Selectors
+ *
+ */
+public class DependSelectorTest {
+
+ @Rule
+ public final BaseSelectorRule selectorRule = new BaseSelectorRule();
+
+ @Test
+ public void testValidateSingleMapper() {
+ try {
+ DependSelector s = new DependSelector();
+ s.createMapper();
+ s.createMapper();
+ fail("DependSelector allowed more than one nested mapper.");
+ } catch (BuildException be1) {
+ assertEquals("Cannot define more than one mapper",
+ be1.getMessage());
+ }
+ }
+
+
+ @Test
+ public void testValidateRequiredFields() {
+ try {
+ DependSelector s = new DependSelector();
+ s.isSelected(selectorRule.getProject().getBaseDir(), selectorRule.getFilenames()[0], selectorRule.getFiles()[0]);
+ fail("DependSelector did not check for required fields");
+ } catch (BuildException be2) {
+ assertEquals("The targetdir attribute is required.",
+ be2.getMessage());
+ }
+
+ }
+
+ @Test
+ public void testNoMapper() {
+ DependSelector s = new DependSelector();
+ s.setTargetdir(selectorRule.getBeddir());
+
+ String results = selectorRule.selectionString(s);
+ assertEquals("FFFFFFFFFFFF", results);
+ }
+
+ @Test
+ public void testIdentityMapper() {
+ DependSelector s = new DependSelector();
+ s.setTargetdir(selectorRule.getBeddir());
+
+ Mapper.MapperType identity = new Mapper.MapperType();
+ identity.setValue("identity");
+
+ Mapper m = s.createMapper();
+ m.setType(identity);
+
+ String results = selectorRule.selectionString(s);
+ assertEquals("FFFFFFFFFFFF", results);
+ }
+
+ @Test
+ public void testMergeMapper() {
+ DependSelector s = new DependSelector();
+ s.setTargetdir(selectorRule.getBeddir());
+
+ Mapper.MapperType merge = new Mapper.MapperType();
+ merge.setValue("merge");
+
+ Mapper m = s.createMapper();
+ m.setType(merge);
+ m.setTo("asf-logo.gif.gz");
+
+ String results = selectorRule.selectionString(s);
+ assertEquals("TFFFFTTTFFF", results.substring(0,11));
+ }
+
+ @Test
+ public void testMergeMapper2() {
+ DependSelector s = new DependSelector();
+ s.setTargetdir(selectorRule.getBeddir());
+
+ Mapper.MapperType merge = new Mapper.MapperType();
+ merge.setValue("merge");
+
+ Mapper m = s.createMapper();
+ m.setType(merge);
+ m.setTo("asf-logo.gif.bz2");
+ String results = selectorRule.selectionString(s);
+ assertEquals("TTFTTTTTTTTT", results);
+ }
+
+ @Test
+ public void testGlobMapperRelativePath() {
+ DependSelector s = new DependSelector();
+ File subdir = new File("selectortest/tar/bz2");
+ s.setTargetdir(subdir);
+
+ Mapper.MapperType glob = new Mapper.MapperType();
+ glob.setValue("glob");
+
+ Mapper m = s.createMapper();
+ m.setType(glob);
+ m.setFrom("*.bz2");
+ m.setTo("*.tar.bz2");
+
+ String results = selectorRule.selectionString(s);
+ assertEquals("FFTFFFFFFTTF", results);
+ }
+
+ @Test
+ public void testRestrictedGlobMapper() {
+ DependSelector s = new DependSelector();
+ File subdir = new File(selectorRule.getBeddir(), "tar/bz2");
+ s.setTargetdir(subdir);
+
+ Mapper.MapperType glob = new Mapper.MapperType();
+ glob.setValue("glob");
+
+ Mapper m = s.createMapper();
+ m.setType(glob);
+ m.setFrom("*.bz2");
+ m.setTo("*.tar.bz2");
+ String results = selectorRule.selectionString(s);
+ assertEquals("FFFFFFFFFTTF", results);
+ }
+
+ @Test
+ public void testSelectionNoMapper() {
+ DependSelector s = new DependSelector();
+ s.setTargetdir(new File(selectorRule.getOutputDir(), "selectortest2"));
+ String results = selectorRule.selectionString(s);
+ assertEquals("FFFTTFFFFFFF", results);
+ }
+
+
+ @Test
+ public void testMirroredSelection() {
+ DependSelector s = new DependSelector();
+ s.setTargetdir(new File(selectorRule.getOutputDir(), "selectortest2/tar/bz2"));
+
+ Mapper.MapperType glob = new Mapper.MapperType();
+ glob.setValue("glob");
+
+ Mapper m = s.createMapper();
+ m.setType(glob);
+ m.setFrom("*.bz2");
+ m.setTo("*.tar.bz2");
+ String results = selectorRule.mirrorSelectionString(s);
+ assertEquals("FFFFFFFFFTTF", results);
+ results = selectorRule.selectionString(s);
+ assertEquals("FFFFFFFFFTTF", results);
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/DepthSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/DepthSelectorTest.java
index 391fb27dd..924995cb1 100644
--- a/src/tests/junit/org/apache/tools/ant/types/selectors/DepthSelectorTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/DepthSelectorTest.java
@@ -1,147 +1,147 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types.selectors;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.types.Parameter;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-/**
- * Tests Depth Selectors
- *
- */
-public class DepthSelectorTest {
-
- @Rule
- public final BaseSelectorRule selectorRule = new BaseSelectorRule();
-
-
- /**
- * Test the code that validates the selector.
- */
- @Test
- public void testValidate() {
- DepthSelector s = new DepthSelector();
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("DepthSelector did not check for required fields");
- } catch (BuildException be1) {
- assertEquals("You must set at least one of the min or the " +
- "max levels.", be1.getMessage());
- }
-
- s = new DepthSelector();
- s.setMin(5);
- s.setMax(2);
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("DepthSelector did not check for maximum being higher "
- + "than minimum");
- } catch (BuildException be2) {
- assertEquals("The maximum depth is lower than the minimum.",
- be2.getMessage());
- }
-
- s = new DepthSelector();
- Parameter param = new Parameter();
- param.setName("garbage in");
- param.setValue("garbage out");
- Parameter[] params = new Parameter[1];
- params[0] = param;
- s.setParameters(params);
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("DepthSelector did not check for valid parameter element");
- } catch (BuildException be3) {
- assertEquals("Invalid parameter garbage in", be3.getMessage());
- }
-
- s = new DepthSelector();
- param = new Parameter();
- param.setName("min");
- param.setValue("garbage out");
- params[0] = param;
- s.setParameters(params);
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("DepthSelector accepted bad minimum as parameter");
- } catch (BuildException be4) {
- assertEquals("Invalid minimum value garbage out",
- be4.getMessage());
- }
-
- s = new DepthSelector();
- param = new Parameter();
- param.setName("max");
- param.setValue("garbage out");
- params[0] = param;
- s.setParameters(params);
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("DepthSelector accepted bad maximum as parameter");
- } catch (BuildException be5) {
- assertEquals("Invalid maximum value garbage out",
- be5.getMessage());
- }
-
- }
-
- /**
- * Tests to make sure that the selector is selecting files correctly.
- */
- @Test
- public void testSelectionBehaviour() {
- DepthSelector s;
- String results;
-
- s = new DepthSelector();
- s.setMin(20);
- s.setMax(25);
- results = selectorRule.selectionString(s);
- assertEquals("FFFFFFFFFFFF", results);
-
- s = new DepthSelector();
- s.setMin(0);
- results = selectorRule.selectionString(s);
- assertEquals("TTTTTTTTTTTT", results);
-
- s = new DepthSelector();
- s.setMin(1);
- results = selectorRule.selectionString(s);
- assertEquals("FFFFFTTTTTTT", results);
-
- s = new DepthSelector();
- s.setMax(0);
- results = selectorRule.selectionString(s);
- assertEquals("TTTTTFFFFFFF", results);
-
- s = new DepthSelector();
- s.setMin(1);
- s.setMax(1);
- results = selectorRule.selectionString(s);
- assertEquals("FFFFFTTTFFFT", results);
-
-
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types.selectors;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.Parameter;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests Depth Selectors
+ *
+ */
+public class DepthSelectorTest {
+
+ @Rule
+ public final BaseSelectorRule selectorRule = new BaseSelectorRule();
+
+
+ /**
+ * Test the code that validates the selector.
+ */
+ @Test
+ public void testValidate() {
+ DepthSelector s = new DepthSelector();
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("DepthSelector did not check for required fields");
+ } catch (BuildException be1) {
+ assertEquals("You must set at least one of the min or the " +
+ "max levels.", be1.getMessage());
+ }
+
+ s = new DepthSelector();
+ s.setMin(5);
+ s.setMax(2);
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("DepthSelector did not check for maximum being higher "
+ + "than minimum");
+ } catch (BuildException be2) {
+ assertEquals("The maximum depth is lower than the minimum.",
+ be2.getMessage());
+ }
+
+ s = new DepthSelector();
+ Parameter param = new Parameter();
+ param.setName("garbage in");
+ param.setValue("garbage out");
+ Parameter[] params = new Parameter[1];
+ params[0] = param;
+ s.setParameters(params);
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("DepthSelector did not check for valid parameter element");
+ } catch (BuildException be3) {
+ assertEquals("Invalid parameter garbage in", be3.getMessage());
+ }
+
+ s = new DepthSelector();
+ param = new Parameter();
+ param.setName("min");
+ param.setValue("garbage out");
+ params[0] = param;
+ s.setParameters(params);
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("DepthSelector accepted bad minimum as parameter");
+ } catch (BuildException be4) {
+ assertEquals("Invalid minimum value garbage out",
+ be4.getMessage());
+ }
+
+ s = new DepthSelector();
+ param = new Parameter();
+ param.setName("max");
+ param.setValue("garbage out");
+ params[0] = param;
+ s.setParameters(params);
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("DepthSelector accepted bad maximum as parameter");
+ } catch (BuildException be5) {
+ assertEquals("Invalid maximum value garbage out",
+ be5.getMessage());
+ }
+
+ }
+
+ /**
+ * Tests to make sure that the selector is selecting files correctly.
+ */
+ @Test
+ public void testSelectionBehaviour() {
+ DepthSelector s;
+ String results;
+
+ s = new DepthSelector();
+ s.setMin(20);
+ s.setMax(25);
+ results = selectorRule.selectionString(s);
+ assertEquals("FFFFFFFFFFFF", results);
+
+ s = new DepthSelector();
+ s.setMin(0);
+ results = selectorRule.selectionString(s);
+ assertEquals("TTTTTTTTTTTT", results);
+
+ s = new DepthSelector();
+ s.setMin(1);
+ results = selectorRule.selectionString(s);
+ assertEquals("FFFFFTTTTTTT", results);
+
+ s = new DepthSelector();
+ s.setMax(0);
+ results = selectorRule.selectionString(s);
+ assertEquals("TTTTTFFFFFFF", results);
+
+ s = new DepthSelector();
+ s.setMin(1);
+ s.setMax(1);
+ results = selectorRule.selectionString(s);
+ assertEquals("FFFFFTTTFFFT", results);
+
+
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/FilenameSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/FilenameSelectorTest.java
index ce7729a87..121f4334f 100644
--- a/src/tests/junit/org/apache/tools/ant/types/selectors/FilenameSelectorTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/FilenameSelectorTest.java
@@ -1,115 +1,115 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types.selectors;
-
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.types.Parameter;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-/**
- * Tests Filename Selectors
- *
- */
-public class FilenameSelectorTest {
-
- @Rule
- public final BaseSelectorRule selectorRule = new BaseSelectorRule();
-
- /**
- * Test the code that validates the selector.
- */
- @Test
- public void testValidate() {
- FilenameSelector s = new FilenameSelector();
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("FilenameSelector did not check for required fields");
- } catch (BuildException be1) {
- assertEquals("The name or regex attribute is required", be1.getMessage());
- }
-
- s = new FilenameSelector();
- Parameter param = new Parameter();
- param.setName("garbage in");
- param.setValue("garbage out");
- Parameter[] params = {param};
- s.setParameters(params);
- try {
- s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
- fail("FilenameSelector did not check for valid parameter element");
- } catch (BuildException be2) {
- assertEquals("Invalid parameter garbage in", be2.getMessage());
- }
-
- }
-
- /**
- * Tests to make sure that the selector is selecting files correctly.
- */
- @Test
- public void testSelectionBehaviour() {
- FilenameSelector s;
- String results;
-
-
- s = new FilenameSelector();
- s.setName("no match possible");
- results = selectorRule.selectionString(s);
- assertEquals("FFFFFFFFFFFF", results);
-
- s = new FilenameSelector();
- s.setName("*.gz");
- results = selectorRule.selectionString(s);
- // This is turned off temporarily. There appears to be a bug
- // in SelectorUtils.matchPattern() where it is recursive on
- // Windows even if no ** is in pattern.
- //assertEquals("FFFTFFFFFFFF", results); // Unix
- // vs
- //assertEquals("FFFTFFFFTFFF", results); // Windows
-
- s = new FilenameSelector();
- s.setName("**/*.gz");
- s.setNegate(true);
- results = selectorRule.selectionString(s);
- assertEquals("TTTFTTTFFTTT", results);
-
- s = new FilenameSelector();
- s.setName("**/*.GZ");
- s.setCasesensitive(false);
- results = selectorRule.selectionString(s);
- assertEquals("FFFTFFFTTFFF", results);
-
- s = new FilenameSelector();
- Parameter param1 = new Parameter();
- param1.setName("name");
- param1.setValue("**/*.bz2");
- Parameter[] params = {param1};
- s.setParameters(params);
- results = selectorRule.selectionString(s);
- assertEquals("FFTFFFFFFTTF", results);
-
-
-
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types.selectors;
+
+import org.apache.tools.ant.BuildException;
+import org.apache.tools.ant.types.Parameter;
+import org.junit.Rule;
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+/**
+ * Tests Filename Selectors
+ *
+ */
+public class FilenameSelectorTest {
+
+ @Rule
+ public final BaseSelectorRule selectorRule = new BaseSelectorRule();
+
+ /**
+ * Test the code that validates the selector.
+ */
+ @Test
+ public void testValidate() {
+ FilenameSelector s = new FilenameSelector();
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("FilenameSelector did not check for required fields");
+ } catch (BuildException be1) {
+ assertEquals("The name or regex attribute is required", be1.getMessage());
+ }
+
+ s = new FilenameSelector();
+ Parameter param = new Parameter();
+ param.setName("garbage in");
+ param.setValue("garbage out");
+ Parameter[] params = {param};
+ s.setParameters(params);
+ try {
+ s.isSelected(selectorRule.getProject().getBaseDir(),selectorRule.getFilenames()[0],selectorRule.getFiles()[0]);
+ fail("FilenameSelector did not check for valid parameter element");
+ } catch (BuildException be2) {
+ assertEquals("Invalid parameter garbage in", be2.getMessage());
+ }
+
+ }
+
+ /**
+ * Tests to make sure that the selector is selecting files correctly.
+ */
+ @Test
+ public void testSelectionBehaviour() {
+ FilenameSelector s;
+ String results;
+
+
+ s = new FilenameSelector();
+ s.setName("no match possible");
+ results = selectorRule.selectionString(s);
+ assertEquals("FFFFFFFFFFFF", results);
+
+ s = new FilenameSelector();
+ s.setName("*.gz");
+ results = selectorRule.selectionString(s);
+ // This is turned off temporarily. There appears to be a bug
+ // in SelectorUtils.matchPattern() where it is recursive on
+ // Windows even if no ** is in pattern.
+ //assertEquals("FFFTFFFFFFFF", results); // Unix
+ // vs
+ //assertEquals("FFFTFFFFTFFF", results); // Windows
+
+ s = new FilenameSelector();
+ s.setName("**/*.gz");
+ s.setNegate(true);
+ results = selectorRule.selectionString(s);
+ assertEquals("TTTFTTTFFTTT", results);
+
+ s = new FilenameSelector();
+ s.setName("**/*.GZ");
+ s.setCasesensitive(false);
+ results = selectorRule.selectionString(s);
+ assertEquals("FFFTFFFTTFFF", results);
+
+ s = new FilenameSelector();
+ Parameter param1 = new Parameter();
+ param1.setName("name");
+ param1.setValue("**/*.bz2");
+ Parameter[] params = {param1};
+ s.setParameters(params);
+ results = selectorRule.selectionString(s);
+ assertEquals("FFTFFFFFFTTF", results);
+
+
+
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/MockAlgorithm.java b/src/tests/junit/org/apache/tools/ant/types/selectors/MockAlgorithm.java
index 458c83fe8..c7419522e 100644
--- a/src/tests/junit/org/apache/tools/ant/types/selectors/MockAlgorithm.java
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/MockAlgorithm.java
@@ -1,37 +1,37 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types.selectors;
-
-
-import java.io.File;
-import org.apache.tools.ant.types.selectors.modifiedselector.Algorithm;
-
-public class MockAlgorithm implements Algorithm {
- public boolean isValid() {
- return true;
- }
-
- public String getValue(File file) {
- return "TEST";
- }
-
- public String toString() {
- return "MockAlgorithm@" + hashCode();
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types.selectors;
+
+
+import java.io.File;
+import org.apache.tools.ant.types.selectors.modifiedselector.Algorithm;
+
+public class MockAlgorithm implements Algorithm {
+ public boolean isValid() {
+ return true;
+ }
+
+ public String getValue(File file) {
+ return "TEST";
+ }
+
+ public String toString() {
+ return "MockAlgorithm@" + hashCode();
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/MockCache.java b/src/tests/junit/org/apache/tools/ant/types/selectors/MockCache.java
index e501a6b80..6fc87f3d9 100644
--- a/src/tests/junit/org/apache/tools/ant/types/selectors/MockCache.java
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/MockCache.java
@@ -1,68 +1,68 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types.selectors;
-
-
-import java.util.Iterator;
-import org.apache.tools.ant.types.selectors.modifiedselector.Cache;
-
-public class MockCache implements Cache {
-
- public boolean debug = false;
- public boolean saved = false;
-
-
- public MockCache() {
- log("()");
- }
-
- public boolean isValid() {
- log(".isValid()");
- return true;
- }
- public void delete() {
- log(".delete()");
- }
- public void load() {
- log(".load()");
- }
- public void save() {
- log(".save()");
- saved = true;
- }
- public Object get(Object key) {
- log(".get("+key+")");
- return key;
- }
- public void put(Object key, Object value) {
- log(".put("+key+", "+value+")");
- saved = false;
- }
- public Iterator iterator() {
- log("iterator()");
- return null;
- }
- public String toString() {
- return "MockCache@" + hashCode();
- }
-
- private void log(String msg) {
- if (debug) System.out.println(this+msg);
- }
-}//class-MockCache
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types.selectors;
+
+
+import java.util.Iterator;
+import org.apache.tools.ant.types.selectors.modifiedselector.Cache;
+
+public class MockCache implements Cache {
+
+ public boolean debug = false;
+ public boolean saved = false;
+
+
+ public MockCache() {
+ log("()");
+ }
+
+ public boolean isValid() {
+ log(".isValid()");
+ return true;
+ }
+ public void delete() {
+ log(".delete()");
+ }
+ public void load() {
+ log(".load()");
+ }
+ public void save() {
+ log(".save()");
+ saved = true;
+ }
+ public Object get(Object key) {
+ log(".get("+key+")");
+ return key;
+ }
+ public void put(Object key, Object value) {
+ log(".put("+key+", "+value+")");
+ saved = false;
+ }
+ public Iterator iterator() {
+ log("iterator()");
+ return null;
+ }
+ public String toString() {
+ return "MockCache@" + hashCode();
+ }
+
+ private void log(String msg) {
+ if (debug) System.out.println(this+msg);
+ }
+}//class-MockCache
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/MockComparator.java b/src/tests/junit/org/apache/tools/ant/types/selectors/MockComparator.java
index a7c155396..fdbb75d0f 100644
--- a/src/tests/junit/org/apache/tools/ant/types/selectors/MockComparator.java
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/MockComparator.java
@@ -1,32 +1,32 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types.selectors;
-
-import java.util.Comparator;
-
-public class MockComparator implements Comparator {
-
- public int compare(Object o1, Object o2) {
- return 0;
- }
-
- public String toString() {
- return "MockComparator";
- }
-}//class-MockCache
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.ant.types.selectors;
+
+import java.util.Comparator;
+
+public class MockComparator implements Comparator {
+
+ public int compare(Object o1, Object o2) {
+ return 0;
+ }
+
+ public String toString() {
+ return "MockComparator";
+ }
+}//class-MockCache
diff --git a/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java b/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
index 80dd6dfa8..e83c5b711 100644
--- a/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
+++ b/src/tests/junit/org/apache/tools/ant/types/selectors/ModifiedSelectorTest.java
@@ -1,1062 +1,1062 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.ant.types.selectors;
-
-
-// Java
-import java.io.File;
-import java.text.RuleBasedCollator;
-import java.util.Comparator;
-import java.util.Iterator;
-
-import org.apache.tools.ant.AntAssert;
-import org.apache.tools.ant.BuildException;
-import org.apache.tools.ant.BuildFileRule;
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Target;
-import org.apache.tools.ant.Task;
-import org.apache.tools.ant.types.Parameter;
-import org.apache.tools.ant.types.Path;
-import org.apache.tools.ant.types.selectors.modifiedselector.Algorithm;
-import org.apache.tools.ant.types.selectors.modifiedselector.Cache;
-import org.apache.tools.ant.types.selectors.modifiedselector.ChecksumAlgorithm;
-import org.apache.tools.ant.types.selectors.modifiedselector.DigestAlgorithm;
-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.Assume;
-import org.junit.Before;
-import org.junit.Ignore;
-import org.junit.Rule;
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-
-/**
- * Unit tests for ModifiedSelector.
- *
- * @since Ant 1.6
- */
-public class ModifiedSelectorTest {
-
- @Rule
- public final BaseSelectorRule selectorRule = new BaseSelectorRule();
-
- /** Utilities used for file operations */
- private static final FileUtils FILE_UTILS = FileUtils.getFileUtils();
-
- // ===================== attributes =====================
-
-
- /** Path where the testclasses are. */
- private Path testclasses = null;
-
-
-
-
- // ===================== JUnit stuff =====================
-
-
- @Before
- public void setUp() {
- // init the testclasses path object
- Project prj = selectorRule.getProject();
- testclasses = new Path(prj, prj.getProperty("build.tests.value"));
- }
-
-
- // ======= testcases for the attributes and nested elements of the selector =====
-
-
- /** Test right use of cache names. */
- @Test
- public void testValidateWrongCache() {
- String name = "this-is-not-a-valid-cache-name";
- try {
- ModifiedSelector.CacheName cacheName = new ModifiedSelector.CacheName();
- cacheName.setValue(name);
- fail("CacheSelector.CacheName accepted invalid value.");
- } catch (BuildException be) {
- assertEquals(name + " is not a legal value for this attribute",
- be.getMessage());
- }
- }
-
-
- /** Test right use of cache names. */
- @Test
- public void testValidateWrongAlgorithm() {
- String name = "this-is-not-a-valid-algorithm-name";
- try {
- ModifiedSelector.AlgorithmName algoName
- = new ModifiedSelector.AlgorithmName();
- algoName.setValue(name);
- fail("CacheSelector.AlgorithmName accepted invalid value.");
- } catch (BuildException be) {
- assertEquals(name + " is not a legal value for this attribute",
- be.getMessage());
- }
- }
-
-
- /** Test right use of comparator names. */
- @Test
- public void testValidateWrongComparator() {
- String name = "this-is-not-a-valid-comparator-name";
- try {
- ModifiedSelector.ComparatorName compName
- = new ModifiedSelector.ComparatorName();
- compName.setValue(name);
- fail("ModifiedSelector.ComparatorName accepted invalid value.");
- } catch (BuildException be) {
- assertEquals(name + " is not a legal value for this attribute",
- be.getMessage());
- }
- }
-
-
- @Test
- public void testIllegalCustomAlgorithm() {
- try {
- getAlgoName("java.lang.Object");
- fail("Illegal classname used.");
- } catch (BuildException e) {
- assertEquals("Wrong exception message.",
- "Specified class (java.lang.Object) is not an Algorithm.",
- e.getMessage());
-
- }
- }
-
-
- @Test
- public void testNonExistentCustomAlgorithm() {
- try {
- getAlgoName("non.existent.custom.Algorithm");
- fail("does 'non.existent.custom.Algorithm' really exist?");
- } catch (BuildException e) {
- assertEquals("Wrong exception message.",
- "Specified class (non.existent.custom.Algorithm) not found.",
- e.getMessage());
-
- }
- }
-
- @Test
- public void testCustomAlgorithm() {
- String algo = getAlgoName("org.apache.tools.ant.types.selectors.modifiedselector.HashvalueAlgorithm");
- assertTrue("Wrong algorithm used: "+algo, algo.startsWith("HashvalueAlgorithm"));
- }
-
- @Test
- public void testCustomAlgorithm2() {
- String algo = getAlgoName("org.apache.tools.ant.types.selectors.MockAlgorithm");
- assertTrue("Wrong algorithm used: "+algo, algo.startsWith("MockAlgorithm"));
- }
-
-
- @Test
- public void testCustomClasses() {
- Assume.assumeNotNull("Ant home not set", selectorRule.getProject().getProperty("ant.home") );
- BFT bft = new BFT();
- bft.setUp();
- try {
- // do the actions
- bft.doTarget("modifiedselectortest-customClasses");
- // do the checks - the buildfile stores the fileset as property
- String fsFullValue = bft.getProperty("fs.full.value");
- String fsModValue = bft.getProperty("fs.mod.value");
-
- assertNotNull("'fs.full.value' must be set.", fsFullValue);
- assertTrue("'fs.full.value' must not be null.", !"".equals(fsFullValue));
- assertTrue("'fs.full.value' must contain ant.bat.", fsFullValue.indexOf("ant.bat")>-1);
-
- assertNotNull("'fs.mod.value' must be set.", fsModValue);
- // must be empty according to the Mock* implementations
- assertTrue("'fs.mod.value' must be empty.", "".equals(fsModValue));
- // don't catch the JUnit exceptions
- } finally {
- bft.doTarget("modifiedselectortest-scenario-clean");
- bft.deletePropertiesfile();
- bft.tearDown();
- }
- }
-
-
- @Test
- public void testDelayUpdateTaskFinished() {
- doDelayUpdateTest(1);
- }
-
-
- @Test
- public void testDelayUpdateTargetFinished() {
- doDelayUpdateTest(2);
- }
-
-
- @Test
- public void testDelayUpdateBuildFinished() {
- doDelayUpdateTest(3);
- }
-
-
- public void doDelayUpdateTest(int kind) {
- // no check for 1<=kind<=3 - only internal use therefore check it
- // while development
-
- // readable form of parameter kind
- String[] kinds = {"task", "target", "build"};
-
- // setup the "Ant project"
- MockProject project = new MockProject();
- File base = new File("base");
- File file1 = new File("file1");
- File file2 = new File("file2");
-
- // setup the selector
- ModifiedSelector sel = new ModifiedSelector();
- sel.setProject(project);
- sel.setUpdate(true);
- sel.setDelayUpdate(true);
- // sorry - otherwise we will get a ClassCastException because the MockCache
- // is loaded by two different classloader ...
- sel.setClassLoader(this.getClass().getClassLoader());
- sel.addClasspath(testclasses);
-
- sel.setAlgorithmClass("org.apache.tools.ant.types.selectors.MockAlgorithm");
- sel.setCacheClass("org.apache.tools.ant.types.selectors.MockCache");
- sel.configure();
-
- // get the cache, so we can check our things
- MockCache cache = (MockCache)sel.getCache();
-
- // the test
- assertFalse("Cache must not be saved before 1st selection.", cache.saved);
- sel.isSelected(base, "file1", file1);
- assertFalse("Cache must not be saved after 1st selection.", cache.saved);
- sel.isSelected(base, "file2", file2);
- assertFalse("Cache must not be saved after 2nd selection.", cache.saved);
- switch (kind) {
- case 1 : project.fireTaskFinished(); break;
- case 2 : project.fireTargetFinished(); break;
- case 3 : project.fireBuildFinished(); break;
- }
- assertTrue("Cache must be saved after " + kinds[kind-1] + "Finished-Event.", cache.saved);
-
- // MockCache doesnt create a file - therefore no cleanup needed
- }
-
-
- /**
- * Extracts the real used algorithm name from the ModifiedSelector using
- * its toString() method.
- * @param classname the classname from the algorithm to use
- * @return the algorithm part from the toString() (without brackets)
- */
- private String getAlgoName(String classname) {
- ModifiedSelector sel = new ModifiedSelector();
- sel.setProject(selectorRule.getProject());
- // add the test classes to its classpath
- sel.addClasspath(testclasses);
- sel.setAlgorithmClass(classname);
- // let the selector do its checks
- sel.validate();
- // extract the algorithm name (and config) from the selectors output
- String s1 = sel.toString();
- int posStart = s1.indexOf("algorithm=") + 10;
- int posEnd = s1.indexOf(" comparator=");
- String algo = s1.substring(posStart, posEnd);
- // '<' and '>' are only used if the algorithm has properties
- if (algo.startsWith("<")) algo = algo.substring(1);
- if (algo.endsWith(">")) algo = algo.substring(0, algo.length()-1);
- // return the clean value
- return algo;
- }
-
-
- // ================ testcases for the cache implementations ================
-
-
- /**
- * Propertycache must have a set 'cachefile' attribute.
- * The default in ModifiedSelector "cache.properties" is set by the selector.
- */
- @Test
- public void testPropcacheInvalid() {
- Cache cache = new PropertiesfileCache();
- if (cache.isValid())
- fail("PropertyfilesCache does not check its configuration.");
- }
-
-
- @Test
- public void testPropertyfileCache() {
- PropertiesfileCache cache = new PropertiesfileCache();
- File cachefile = new File("cache.properties");
- cache.setCachefile(cachefile);
- doTest(cache);
- assertFalse("Cache file not deleted.", cachefile.exists());
- }
-
-
- /** Checks whether a cache file is created. */
- @Test
- public void testCreatePropertiesCacheDirect() {
- File cachefile = new File(selectorRule.getProject().getBaseDir(), "cachefile.properties");
-
- PropertiesfileCache cache = new PropertiesfileCache();
- cache.setCachefile(cachefile);
-
- cache.put("key", "value");
- cache.save();
-
- assertTrue("Cachefile not created.", cachefile.exists());
-
- cache.delete();
- assertFalse("Cachefile not deleted.", cachefile.exists());
- }
-
-
- /** Checks whether a cache file is created. */
- @Test
- public void testCreatePropertiesCacheViaModifiedSelector() {
- File cachefile = new File(selectorRule.getProject().getBaseDir(), "cachefile.properties");
-
- // Configure the selector
- ModifiedSelector s = new ModifiedSelector();
- s.setDelayUpdate(false);
- s.addParam("cache.cachefile", cachefile);
-
- ModifiedSelector.CacheName cacheName = new ModifiedSelector.CacheName();
- cacheName.setValue("propertyfile");
- s.setCache(cacheName);
-
- s.setUpdate(true);
-
- selectorRule.selectionString(s);
-
- // evaluate correctness
- assertTrue("Cache file is not created.", cachefile.exists());
- cachefile.delete();
-
- }
-
-
- /**
- * In earlier implementations there were problems with the order
- * of the s. The scenario was
- *
- *
- *
- *
- *
It was important first to set the cache and then to set
- * the cache's configuration parameters. That results in the reorganized
- * configure() method of ModifiedSelector. This testcase tests that.
- */
- @Test
- public void testCreatePropertiesCacheViaCustomSelector() {
- File cachefile = FILE_UTILS.createTempFile("tmp-cache-", ".properties", null, false, false);
-
- // Configure the selector
-
- ExtendSelector s = new ExtendSelector();
- s.setClassname("org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector");
- s.addParam(createParam("update", "true"));
- s.addParam(createParam("cache.cachefile", cachefile.getAbsolutePath()));
- s.addParam(createParam("cache", "propertyfile"));
-
- selectorRule.selectionString(s);
-
- // evaluate correctness
- assertTrue("Cache file is not created.", cachefile.exists());
- cachefile.delete();
-
- }
-
-
- @Test
- @Ignore("same logic as on algorithm, no testcases created")
- public void testCustomCache() {
- // same logic as on algorithm, no testcases created
- }
-
-
- /**
- * Test the interface semantic of Caches.
- * This method does some common test for cache implementations.
- * A cache must return a stored value and a valid iterator.
- * After calling the delete() the cache must be empty.
- *
- * @param cache configured test object
- */
- protected void doTest(Cache cache) {
- assertTrue("Cache not proper configured.", cache.isValid());
-
- String key1 = "key1";
- String value1 = "value1";
- String key2 = "key2";
- String value2 = "value2";
-
- // given cache must be empty
- Iterator it1 = cache.iterator();
- assertFalse("Cache is not empty", it1.hasNext());
-
- // cache must return a stored value
- cache.put(key1, value1);
- cache.put(key2, value2);
- assertEquals("cache returned wrong value", value1, cache.get(key1));
- assertEquals("cache returned wrong value", value2, cache.get(key2));
-
- // test the iterator
- Iterator it2 = cache.iterator();
- Object returned = it2.next();
- boolean ok = (key1.equals(returned) || key2.equals(returned));
- String msg = "Iterator returned unexpected value."
- + " key1.equals(returned)="+key1.equals(returned)
- + " key2.equals(returned)="+key2.equals(returned)
- + " returned="+returned
- + " ok="+ok;
- assertTrue(msg, ok);
-
- // clear the cache
- cache.delete();
- Iterator it3 = cache.iterator();
- assertFalse("Cache is not empty", it3.hasNext());
- }
-
-
- // ============== testcases for the algorithm implementations ==============
-
-
- @Test
- public void testHashvalueAlgorithm() {
- HashvalueAlgorithm algo = new HashvalueAlgorithm();
- doTest(algo);
- }
-
-
- @Test
- public void testDigestAlgorithmMD5() {
- DigestAlgorithm algo = new DigestAlgorithm();
- algo.setAlgorithm("MD5");
- doTest(algo);
- }
-
-
- @Test
- public void testDigestAlgorithmSHA() {
- DigestAlgorithm algo = new DigestAlgorithm();
- algo.setAlgorithm("SHA");
- doTest(algo);
- }
-
-
- @Test
- public void testChecksumAlgorithm() {
- ChecksumAlgorithm algo = new ChecksumAlgorithm();
- doTest(algo);
- }
-
-
- @Test
- public void testChecksumAlgorithmCRC() {
- ChecksumAlgorithm algo = new ChecksumAlgorithm();
- algo.setAlgorithm("CRC");
- doTest(algo);
- }
-
-
- @Test
- public void testChecksumAlgorithmAdler() {
- ChecksumAlgorithm algo = new ChecksumAlgorithm();
- algo.setAlgorithm("Adler");
- doTest(algo);
- }
-
-
- /**
- * Test the interface semantic of Algorithms.
- * This method does some common test for algorithm implementations.
- * An algorithm must return always the same value for the same file and
- * it must not return null.
- *
- * @param algo configured test object
- */
- protected void doTest(Algorithm algo) {
- assertTrue("Algorithm not proper configured.", algo.isValid());
- for (int i=0; i
- *
- */
- static final ZipShort UNRECOGNIZED_HEADER = new ZipShort(0x5555);
-
- private AsiExtraField a;
- private UnrecognizedExtraField dummy;
- private byte[] data;
- private byte[] aLocal;
-
- @Before
- public void setUp() {
- a = new AsiExtraField();
- a.setMode(0755);
- a.setDirectory(true);
- dummy = new UnrecognizedExtraField();
- dummy.setHeaderId(UNRECOGNIZED_HEADER);
- dummy.setLocalFileDataData(new byte[] {0});
- dummy.setCentralDirectoryData(new byte[] {0});
-
- aLocal = a.getLocalFileDataData();
- byte[] dummyLocal = dummy.getLocalFileDataData();
- data = new byte[4 + aLocal.length + 4 + dummyLocal.length];
- System.arraycopy(a.getHeaderId().getBytes(), 0, data, 0, 2);
- System.arraycopy(a.getLocalFileDataLength().getBytes(), 0, data, 2, 2);
- System.arraycopy(aLocal, 0, data, 4, aLocal.length);
- System.arraycopy(dummy.getHeaderId().getBytes(), 0, data,
- 4+aLocal.length, 2);
- System.arraycopy(dummy.getLocalFileDataLength().getBytes(), 0, data,
- 4+aLocal.length+2, 2);
- System.arraycopy(dummyLocal, 0, data,
- 4+aLocal.length+4, dummyLocal.length);
-
- }
-
- /**
- * test parser.
- */
- @Test
- public void testParse() throws Exception {
- ZipExtraField[] ze = ExtraFieldUtils.parse(data);
- assertEquals("number of fields", 2, ze.length);
- assertTrue("type field 1", ze[0] instanceof AsiExtraField);
- assertEquals("mode field 1", 040755,
- ((AsiExtraField) ze[0]).getMode());
- assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField);
- assertEquals("data length field 2", 1,
- ze[1].getLocalFileDataLength().getValue());
-
- byte[] data2 = new byte[data.length-1];
- System.arraycopy(data, 0, data2, 0, data2.length);
- try {
- ExtraFieldUtils.parse(data2);
- fail("data should be invalid");
- } catch (Exception e) {
- assertEquals("message",
- "bad extra field starting at "+(4 + aLocal.length)
- + ". Block length of 1 bytes exceeds remaining data of 0 bytes.",
- e.getMessage());
- }
- }
-
- @Test
- public void testParseWithRead() throws Exception {
- ZipExtraField[] ze =
- ExtraFieldUtils.parse(data, true,
- ExtraFieldUtils.UnparseableExtraField.READ);
- assertEquals("number of fields", 2, ze.length);
- assertTrue("type field 1", ze[0] instanceof AsiExtraField);
- assertEquals("mode field 1", 040755,
- ((AsiExtraField) ze[0]).getMode());
- assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField);
- assertEquals("data length field 2", 1,
- ze[1].getLocalFileDataLength().getValue());
-
- byte[] data2 = new byte[data.length-1];
- System.arraycopy(data, 0, data2, 0, data2.length);
- ze = ExtraFieldUtils.parse(data2, true,
- ExtraFieldUtils.UnparseableExtraField.READ);
- assertEquals("number of fields", 2, ze.length);
- assertTrue("type field 1", ze[0] instanceof AsiExtraField);
- assertEquals("mode field 1", 040755,
- ((AsiExtraField) ze[0]).getMode());
- assertTrue("type field 2", ze[1] instanceof UnparseableExtraFieldData);
- assertEquals("data length field 2", 4,
- ze[1].getLocalFileDataLength().getValue());
- for (int i = 0; i < 4; i++) {
- assertEquals("byte number " + i,
- data2[data.length - 5 + i],
- ze[1].getLocalFileDataData()[i]);
- }
- }
-
- @Test
- public void testParseWithSkip() throws Exception {
- ZipExtraField[] ze =
- ExtraFieldUtils.parse(data, true,
- ExtraFieldUtils.UnparseableExtraField.SKIP);
- assertEquals("number of fields", 2, ze.length);
- assertTrue("type field 1", ze[0] instanceof AsiExtraField);
- assertEquals("mode field 1", 040755,
- ((AsiExtraField) ze[0]).getMode());
- assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField);
- assertEquals("data length field 2", 1,
- ze[1].getLocalFileDataLength().getValue());
-
- byte[] data2 = new byte[data.length-1];
- System.arraycopy(data, 0, data2, 0, data2.length);
- ze = ExtraFieldUtils.parse(data2, true,
- ExtraFieldUtils.UnparseableExtraField.SKIP);
- assertEquals("number of fields", 1, ze.length);
- assertTrue("type field 1", ze[0] instanceof AsiExtraField);
- assertEquals("mode field 1", 040755,
- ((AsiExtraField) ze[0]).getMode());
- }
-
- /**
- * Test merge methods
- */
- @Test
- public void testMerge() {
- byte[] local =
- ExtraFieldUtils.mergeLocalFileDataData(new ZipExtraField[] {a, dummy});
- assertEquals("local length", data.length, local.length);
- for (int i=0; iUsed to be ZipShort(1) but this is the ID of the Zip64 extra
+ * field.
+ */
+ static final ZipShort UNRECOGNIZED_HEADER = new ZipShort(0x5555);
+
+ private AsiExtraField a;
+ private UnrecognizedExtraField dummy;
+ private byte[] data;
+ private byte[] aLocal;
+
+ @Before
+ public void setUp() {
+ a = new AsiExtraField();
+ a.setMode(0755);
+ a.setDirectory(true);
+ dummy = new UnrecognizedExtraField();
+ dummy.setHeaderId(UNRECOGNIZED_HEADER);
+ dummy.setLocalFileDataData(new byte[] {0});
+ dummy.setCentralDirectoryData(new byte[] {0});
+
+ aLocal = a.getLocalFileDataData();
+ byte[] dummyLocal = dummy.getLocalFileDataData();
+ data = new byte[4 + aLocal.length + 4 + dummyLocal.length];
+ System.arraycopy(a.getHeaderId().getBytes(), 0, data, 0, 2);
+ System.arraycopy(a.getLocalFileDataLength().getBytes(), 0, data, 2, 2);
+ System.arraycopy(aLocal, 0, data, 4, aLocal.length);
+ System.arraycopy(dummy.getHeaderId().getBytes(), 0, data,
+ 4+aLocal.length, 2);
+ System.arraycopy(dummy.getLocalFileDataLength().getBytes(), 0, data,
+ 4+aLocal.length+2, 2);
+ System.arraycopy(dummyLocal, 0, data,
+ 4+aLocal.length+4, dummyLocal.length);
+
+ }
+
+ /**
+ * test parser.
+ */
+ @Test
+ public void testParse() throws Exception {
+ ZipExtraField[] ze = ExtraFieldUtils.parse(data);
+ assertEquals("number of fields", 2, ze.length);
+ assertTrue("type field 1", ze[0] instanceof AsiExtraField);
+ assertEquals("mode field 1", 040755,
+ ((AsiExtraField) ze[0]).getMode());
+ assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField);
+ assertEquals("data length field 2", 1,
+ ze[1].getLocalFileDataLength().getValue());
+
+ byte[] data2 = new byte[data.length-1];
+ System.arraycopy(data, 0, data2, 0, data2.length);
+ try {
+ ExtraFieldUtils.parse(data2);
+ fail("data should be invalid");
+ } catch (Exception e) {
+ assertEquals("message",
+ "bad extra field starting at "+(4 + aLocal.length)
+ + ". Block length of 1 bytes exceeds remaining data of 0 bytes.",
+ e.getMessage());
+ }
+ }
+
+ @Test
+ public void testParseWithRead() throws Exception {
+ ZipExtraField[] ze =
+ ExtraFieldUtils.parse(data, true,
+ ExtraFieldUtils.UnparseableExtraField.READ);
+ assertEquals("number of fields", 2, ze.length);
+ assertTrue("type field 1", ze[0] instanceof AsiExtraField);
+ assertEquals("mode field 1", 040755,
+ ((AsiExtraField) ze[0]).getMode());
+ assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField);
+ assertEquals("data length field 2", 1,
+ ze[1].getLocalFileDataLength().getValue());
+
+ byte[] data2 = new byte[data.length-1];
+ System.arraycopy(data, 0, data2, 0, data2.length);
+ ze = ExtraFieldUtils.parse(data2, true,
+ ExtraFieldUtils.UnparseableExtraField.READ);
+ assertEquals("number of fields", 2, ze.length);
+ assertTrue("type field 1", ze[0] instanceof AsiExtraField);
+ assertEquals("mode field 1", 040755,
+ ((AsiExtraField) ze[0]).getMode());
+ assertTrue("type field 2", ze[1] instanceof UnparseableExtraFieldData);
+ assertEquals("data length field 2", 4,
+ ze[1].getLocalFileDataLength().getValue());
+ for (int i = 0; i < 4; i++) {
+ assertEquals("byte number " + i,
+ data2[data.length - 5 + i],
+ ze[1].getLocalFileDataData()[i]);
+ }
+ }
+
+ @Test
+ public void testParseWithSkip() throws Exception {
+ ZipExtraField[] ze =
+ ExtraFieldUtils.parse(data, true,
+ ExtraFieldUtils.UnparseableExtraField.SKIP);
+ assertEquals("number of fields", 2, ze.length);
+ assertTrue("type field 1", ze[0] instanceof AsiExtraField);
+ assertEquals("mode field 1", 040755,
+ ((AsiExtraField) ze[0]).getMode());
+ assertTrue("type field 2", ze[1] instanceof UnrecognizedExtraField);
+ assertEquals("data length field 2", 1,
+ ze[1].getLocalFileDataLength().getValue());
+
+ byte[] data2 = new byte[data.length-1];
+ System.arraycopy(data, 0, data2, 0, data2.length);
+ ze = ExtraFieldUtils.parse(data2, true,
+ ExtraFieldUtils.UnparseableExtraField.SKIP);
+ assertEquals("number of fields", 1, ze.length);
+ assertTrue("type field 1", ze[0] instanceof AsiExtraField);
+ assertEquals("mode field 1", 040755,
+ ((AsiExtraField) ze[0]).getMode());
+ }
+
+ /**
+ * Test merge methods
+ */
+ @Test
+ public void testMerge() {
+ byte[] local =
+ ExtraFieldUtils.mergeLocalFileDataData(new ZipExtraField[] {a, dummy});
+ assertEquals("local length", data.length, local.length);
+ for (int i=0; i2 {print $1;}' CP1252.TXT
- byte[] b =
- new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
- 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
- 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
- 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
- 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
- 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
- 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
- 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
- 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
- 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
- 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
- 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
- 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
- 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
- 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
- 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
- (byte) 0x80, (byte) 0x82, (byte) 0x83, (byte) 0x84,
- (byte) 0x85, (byte) 0x86, (byte) 0x87, (byte) 0x88,
- (byte) 0x89, (byte) 0x8A, (byte) 0x8B, (byte) 0x8C,
- (byte) 0x8E, (byte) 0x91, (byte) 0x92, (byte) 0x93,
- (byte) 0x94, (byte) 0x95, (byte) 0x96, (byte) 0x97,
- (byte) 0x98, (byte) 0x99, (byte) 0x9A, (byte) 0x9B,
- (byte) 0x9C, (byte) 0x9E, (byte) 0x9F, (byte) 0xA0,
- (byte) 0xA1, (byte) 0xA2, (byte) 0xA3, (byte) 0xA4,
- (byte) 0xA5, (byte) 0xA6, (byte) 0xA7, (byte) 0xA8,
- (byte) 0xA9, (byte) 0xAA, (byte) 0xAB, (byte) 0xAC,
- (byte) 0xAD, (byte) 0xAE, (byte) 0xAF, (byte) 0xB0,
- (byte) 0xB1, (byte) 0xB2, (byte) 0xB3, (byte) 0xB4,
- (byte) 0xB5, (byte) 0xB6, (byte) 0xB7, (byte) 0xB8,
- (byte) 0xB9, (byte) 0xBA, (byte) 0xBB, (byte) 0xBC,
- (byte) 0xBD, (byte) 0xBE, (byte) 0xBF, (byte) 0xC0,
- (byte) 0xC1, (byte) 0xC2, (byte) 0xC3, (byte) 0xC4,
- (byte) 0xC5, (byte) 0xC6, (byte) 0xC7, (byte) 0xC8,
- (byte) 0xC9, (byte) 0xCA, (byte) 0xCB, (byte) 0xCC,
- (byte) 0xCD, (byte) 0xCE, (byte) 0xCF, (byte) 0xD0,
- (byte) 0xD1, (byte) 0xD2, (byte) 0xD3, (byte) 0xD4,
- (byte) 0xD5, (byte) 0xD6, (byte) 0xD7, (byte) 0xD8,
- (byte) 0xD9, (byte) 0xDA, (byte) 0xDB, (byte) 0xDC,
- (byte) 0xDD, (byte) 0xDE, (byte) 0xDF, (byte) 0xE0,
- (byte) 0xE1, (byte) 0xE2, (byte) 0xE3, (byte) 0xE4,
- (byte) 0xE5, (byte) 0xE6, (byte) 0xE7, (byte) 0xE8,
- (byte) 0xE9, (byte) 0xEA, (byte) 0xEB, (byte) 0xEC,
- (byte) 0xED, (byte) 0xEE, (byte) 0xEF, (byte) 0xF0,
- (byte) 0xF1, (byte) 0xF2, (byte) 0xF3, (byte) 0xF4,
- (byte) 0xF5, (byte) 0xF6, (byte) 0xF7, (byte) 0xF8,
- (byte) 0xF9, (byte) 0xFA, (byte) 0xFB, (byte) 0xFC,
- (byte) 0xFD, (byte) 0xFE, (byte) 0xFF };
-
- doSimpleEncodingTest("Cp1252",b);
- }
-
- private static void assertByteEquals(byte[] expected, ByteBuffer actual) {
-
- assertEquals(expected.length, actual.limit());
-
- for (int i = 0; i < expected.length; ++i) {
-
- byte a = actual.get();
- assertEquals(expected[i], a);
- }
-
- }
-
- private void doSimpleEncodingTest(String name, byte[] testBytes)
- throws IOException {
-
- ZipEncoding enc = ZipEncodingHelper.getZipEncoding(name);
-
- if (testBytes == null) {
-
- testBytes = new byte[256];
- for (int i = 0; i < 256; ++i) {
- testBytes[i] = (byte) i;
- }
- }
-
- String decoded = enc.decode(testBytes);
-
- assertEquals(true, enc.canEncode(decoded));
-
- ByteBuffer encoded = enc.encode(decoded);
-
- assertByteEquals(testBytes, encoded);
-
- assertEquals(false, enc.canEncode(UNENC_STRING));
- assertByteEquals("%U2016".getBytes("US-ASCII"), enc.encode(UNENC_STRING));
- assertEquals(false, enc.canEncode(BAD_STRING));
- assertByteEquals(BAD_STRING_ENC.getBytes("US-ASCII"),
- enc.encode(BAD_STRING));
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.tools.zip;
+
+import java.io.IOException;
+import java.nio.ByteBuffer;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+
+/**
+ * Test zip encodings.
+ */
+public class ZipEncodingTest {
+ private static final String UNENC_STRING = "\u2016";
+
+ // stress test for internal grow method.
+ private static final String BAD_STRING =
+ "\u2016\u2015\u2016\u2015\u2016\u2015\u2016\u2015\u2016\u2015\u2016";
+
+ private static final String BAD_STRING_ENC =
+ "%U2016%U2015%U2016%U2015%U2016%U2015%U2016%U2015%U2016%U2015%U2016";
+
+ @Test
+ public void testSimpleCp437Encoding() throws IOException {
+
+ doSimpleEncodingTest("Cp437", null);
+ }
+
+ @Test
+ public void testSimpleCp850Encoding() throws IOException {
+
+ doSimpleEncodingTest("Cp850", null);
+ }
+
+ @Test
+ public void testNioCp1252Encoding() throws IOException {
+ // CP1252 has some undefined code points, these are
+ // the defined ones
+ // retrieved by
+ // awk '/^0x/ && NF>2 {print $1;}' CP1252.TXT
+ byte[] b =
+ new byte[] { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
+ 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
+ 0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x17,
+ 0x18, 0x19, 0x1A, 0x1B, 0x1C, 0x1D, 0x1E, 0x1F,
+ 0x20, 0x21, 0x22, 0x23, 0x24, 0x25, 0x26, 0x27,
+ 0x28, 0x29, 0x2A, 0x2B, 0x2C, 0x2D, 0x2E, 0x2F,
+ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,
+ 0x38, 0x39, 0x3A, 0x3B, 0x3C, 0x3D, 0x3E, 0x3F,
+ 0x40, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,
+ 0x48, 0x49, 0x4A, 0x4B, 0x4C, 0x4D, 0x4E, 0x4F,
+ 0x50, 0x51, 0x52, 0x53, 0x54, 0x55, 0x56, 0x57,
+ 0x58, 0x59, 0x5A, 0x5B, 0x5C, 0x5D, 0x5E, 0x5F,
+ 0x60, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
+ 0x68, 0x69, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F,
+ 0x70, 0x71, 0x72, 0x73, 0x74, 0x75, 0x76, 0x77,
+ 0x78, 0x79, 0x7A, 0x7B, 0x7C, 0x7D, 0x7E, 0x7F,
+ (byte) 0x80, (byte) 0x82, (byte) 0x83, (byte) 0x84,
+ (byte) 0x85, (byte) 0x86, (byte) 0x87, (byte) 0x88,
+ (byte) 0x89, (byte) 0x8A, (byte) 0x8B, (byte) 0x8C,
+ (byte) 0x8E, (byte) 0x91, (byte) 0x92, (byte) 0x93,
+ (byte) 0x94, (byte) 0x95, (byte) 0x96, (byte) 0x97,
+ (byte) 0x98, (byte) 0x99, (byte) 0x9A, (byte) 0x9B,
+ (byte) 0x9C, (byte) 0x9E, (byte) 0x9F, (byte) 0xA0,
+ (byte) 0xA1, (byte) 0xA2, (byte) 0xA3, (byte) 0xA4,
+ (byte) 0xA5, (byte) 0xA6, (byte) 0xA7, (byte) 0xA8,
+ (byte) 0xA9, (byte) 0xAA, (byte) 0xAB, (byte) 0xAC,
+ (byte) 0xAD, (byte) 0xAE, (byte) 0xAF, (byte) 0xB0,
+ (byte) 0xB1, (byte) 0xB2, (byte) 0xB3, (byte) 0xB4,
+ (byte) 0xB5, (byte) 0xB6, (byte) 0xB7, (byte) 0xB8,
+ (byte) 0xB9, (byte) 0xBA, (byte) 0xBB, (byte) 0xBC,
+ (byte) 0xBD, (byte) 0xBE, (byte) 0xBF, (byte) 0xC0,
+ (byte) 0xC1, (byte) 0xC2, (byte) 0xC3, (byte) 0xC4,
+ (byte) 0xC5, (byte) 0xC6, (byte) 0xC7, (byte) 0xC8,
+ (byte) 0xC9, (byte) 0xCA, (byte) 0xCB, (byte) 0xCC,
+ (byte) 0xCD, (byte) 0xCE, (byte) 0xCF, (byte) 0xD0,
+ (byte) 0xD1, (byte) 0xD2, (byte) 0xD3, (byte) 0xD4,
+ (byte) 0xD5, (byte) 0xD6, (byte) 0xD7, (byte) 0xD8,
+ (byte) 0xD9, (byte) 0xDA, (byte) 0xDB, (byte) 0xDC,
+ (byte) 0xDD, (byte) 0xDE, (byte) 0xDF, (byte) 0xE0,
+ (byte) 0xE1, (byte) 0xE2, (byte) 0xE3, (byte) 0xE4,
+ (byte) 0xE5, (byte) 0xE6, (byte) 0xE7, (byte) 0xE8,
+ (byte) 0xE9, (byte) 0xEA, (byte) 0xEB, (byte) 0xEC,
+ (byte) 0xED, (byte) 0xEE, (byte) 0xEF, (byte) 0xF0,
+ (byte) 0xF1, (byte) 0xF2, (byte) 0xF3, (byte) 0xF4,
+ (byte) 0xF5, (byte) 0xF6, (byte) 0xF7, (byte) 0xF8,
+ (byte) 0xF9, (byte) 0xFA, (byte) 0xFB, (byte) 0xFC,
+ (byte) 0xFD, (byte) 0xFE, (byte) 0xFF };
+
+ doSimpleEncodingTest("Cp1252",b);
+ }
+
+ private static void assertByteEquals(byte[] expected, ByteBuffer actual) {
+
+ assertEquals(expected.length, actual.limit());
+
+ for (int i = 0; i < expected.length; ++i) {
+
+ byte a = actual.get();
+ assertEquals(expected[i], a);
+ }
+
+ }
+
+ private void doSimpleEncodingTest(String name, byte[] testBytes)
+ throws IOException {
+
+ ZipEncoding enc = ZipEncodingHelper.getZipEncoding(name);
+
+ if (testBytes == null) {
+
+ testBytes = new byte[256];
+ for (int i = 0; i < 256; ++i) {
+ testBytes[i] = (byte) i;
+ }
+ }
+
+ String decoded = enc.decode(testBytes);
+
+ assertEquals(true, enc.canEncode(decoded));
+
+ ByteBuffer encoded = enc.encode(decoded);
+
+ assertByteEquals(testBytes, encoded);
+
+ assertEquals(false, enc.canEncode(UNENC_STRING));
+ assertByteEquals("%U2016".getBytes("US-ASCII"), enc.encode(UNENC_STRING));
+ assertEquals(false, enc.canEncode(BAD_STRING));
+ assertByteEquals(BAD_STRING_ENC.getBytes("US-ASCII"),
+ enc.encode(BAD_STRING));
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/zip/ZipEntryTest.java b/src/tests/junit/org/apache/tools/zip/ZipEntryTest.java
index 3c21f6f3a..804547a21 100644
--- a/src/tests/junit/org/apache/tools/zip/ZipEntryTest.java
+++ b/src/tests/junit/org/apache/tools/zip/ZipEntryTest.java
@@ -1,228 +1,228 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.zip;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.fail;
-
-/**
- * JUnit 3 testcases for org.apache.tools.zip.ZipEntry.
- *
- */
-public class ZipEntryTest {
-
-
- /**
- * test handling of extra fields
- */
- @Test
- public void testExtraFields() {
- AsiExtraField a = new AsiExtraField();
- a.setDirectory(true);
- a.setMode(0755);
- UnrecognizedExtraField u = new UnrecognizedExtraField();
- u.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
- u.setLocalFileDataData(new byte[0]);
-
- ZipEntry ze = new ZipEntry("test/");
- ze.setExtraFields(new ZipExtraField[] {a, u});
- byte[] data1 = ze.getExtra();
- ZipExtraField[] result = ze.getExtraFields();
- assertEquals("first pass", 2, result.length);
- assertSame(a, result[0]);
- assertSame(u, result[1]);
-
- UnrecognizedExtraField u2 = new UnrecognizedExtraField();
- u2.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
- u2.setLocalFileDataData(new byte[] {1});
-
- ze.addExtraField(u2);
- byte[] data2 = ze.getExtra();
- result = ze.getExtraFields();
- assertEquals("second pass", 2, result.length);
- assertSame(a, result[0]);
- assertSame(u2, result[1]);
- assertEquals("length second pass", data1.length+1, data2.length);
-
- UnrecognizedExtraField u3 = new UnrecognizedExtraField();
- u3.setHeaderId(new ZipShort(2));
- u3.setLocalFileDataData(new byte[] {1});
- ze.addExtraField(u3);
- result = ze.getExtraFields();
- assertEquals("third pass", 3, result.length);
-
- ze.removeExtraField(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
- byte[] data3 = ze.getExtra();
- result = ze.getExtraFields();
- assertEquals("fourth pass", 2, result.length);
- assertSame(a, result[0]);
- assertSame(u3, result[1]);
- assertEquals("length fourth pass", data2.length, data3.length);
-
- try {
- ze.removeExtraField(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
- fail("should be no such element");
- } catch (java.util.NoSuchElementException nse) {
- //TODO assert exception values
- }
- }
-
- /**
- * test handling of extra fields via central directory
- */
- @Test
- public void testExtraFieldMerging() {
- AsiExtraField a = new AsiExtraField();
- a.setDirectory(true);
- a.setMode(0755);
- UnrecognizedExtraField u = new UnrecognizedExtraField();
- u.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
- u.setLocalFileDataData(new byte[0]);
-
- ZipEntry ze = new ZipEntry("test/");
- ze.setExtraFields(new ZipExtraField[] {a, u});
-
- // merge
- // Header-ID 1 + length 1 + one byte of data
- byte[] b = ExtraFieldUtilsTest.UNRECOGNIZED_HEADER.getBytes();
- ze.setCentralDirectoryExtra(new byte[] {b[0], b[1], 1, 0, 127});
-
- ZipExtraField[] result = ze.getExtraFields();
- assertEquals("first pass", 2, result.length);
- assertSame(a, result[0]);
- assertEquals(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER,
- result[1].getHeaderId());
- assertEquals(new ZipShort(0), result[1].getLocalFileDataLength());
- assertEquals(new ZipShort(1), result[1].getCentralDirectoryLength());
-
- // add new
- // Header-ID 2 + length 0
- ze.setCentralDirectoryExtra(new byte[] {2, 0, 0, 0});
-
- result = ze.getExtraFields();
- assertEquals("second pass", 3, result.length);
-
- // merge
- // Header-ID 2 + length 1 + one byte of data
- ze.setExtra(new byte[] {2, 0, 1, 0, 127});
-
- result = ze.getExtraFields();
- assertEquals("third pass", 3, result.length);
- assertSame(a, result[0]);
- assertEquals(new ZipShort(2), result[2].getHeaderId());
- assertEquals(new ZipShort(1), result[2].getLocalFileDataLength());
- assertEquals(new ZipShort(0), result[2].getCentralDirectoryLength());
- }
-
- /**
- * test handling of extra fields
- */
- @Test
- public void testAddAsFirstExtraField() {
- AsiExtraField a = new AsiExtraField();
- a.setDirectory(true);
- a.setMode(0755);
- UnrecognizedExtraField u = new UnrecognizedExtraField();
- u.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
- u.setLocalFileDataData(new byte[0]);
-
- ZipEntry ze = new ZipEntry("test/");
- ze.setExtraFields(new ZipExtraField[] {a, u});
- byte[] data1 = ze.getExtra();
-
- UnrecognizedExtraField u2 = new UnrecognizedExtraField();
- u2.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
- u2.setLocalFileDataData(new byte[] {1});
-
- ze.addAsFirstExtraField(u2);
- byte[] data2 = ze.getExtra();
- ZipExtraField[] result = ze.getExtraFields();
- assertEquals("second pass", 2, result.length);
- assertSame(u2, result[0]);
- assertSame(a, result[1]);
- assertEquals("length second pass", data1.length + 1, data2.length);
-
- UnrecognizedExtraField u3 = new UnrecognizedExtraField();
- u3.setHeaderId(new ZipShort(2));
- u3.setLocalFileDataData(new byte[] {1});
- ze.addAsFirstExtraField(u3);
- result = ze.getExtraFields();
- assertEquals("third pass", 3, result.length);
- assertSame(u3, result[0]);
- assertSame(u2, result[1]);
- assertSame(a, result[2]);
- }
-
- @Test
- public void testUnixMode() {
- ZipEntry ze = new ZipEntry("foo");
- assertEquals(0, ze.getPlatform());
- ze.setUnixMode(0755);
- assertEquals(3, ze.getPlatform());
- assertEquals(0755,
- (ze.getExternalAttributes() >> 16) & 0xFFFF);
- assertEquals(0, ze.getExternalAttributes() & 0xFFFF);
-
- ze.setUnixMode(0444);
- assertEquals(3, ze.getPlatform());
- assertEquals(0444,
- (ze.getExternalAttributes() >> 16) & 0xFFFF);
- assertEquals(1, ze.getExternalAttributes() & 0xFFFF);
-
- ze = new ZipEntry("foo/");
- assertEquals(0, ze.getPlatform());
- ze.setUnixMode(0777);
- assertEquals(3, ze.getPlatform());
- assertEquals(0777,
- (ze.getExternalAttributes() >> 16) & 0xFFFF);
- assertEquals(0x10, ze.getExternalAttributes() & 0xFFFF);
-
- ze.setUnixMode(0577);
- assertEquals(3, ze.getPlatform());
- assertEquals(0577,
- (ze.getExternalAttributes() >> 16) & 0xFFFF);
- assertEquals(0x11, ze.getExternalAttributes() & 0xFFFF);
- }
-
- /**
- * Test case for
- * COMPRESS-94.
- */
- @Test
- public void testNotEquals() {
- ZipEntry entry1 = new ZipEntry("foo");
- ZipEntry entry2 = new ZipEntry("bar");
- assertFalse(entry1.equals(entry2));
- }
-
- @Test
- public void testCopyConstructor() throws Exception {
- ZipEntry archiveEntry = new ZipEntry("fred");
- archiveEntry.setUnixMode(0664);
- archiveEntry.setMethod(ZipEntry.DEFLATED);
- archiveEntry.getGeneralPurposeBit().useStrongEncryption(true);
- ZipEntry copy = new ZipEntry(archiveEntry);
- assertEquals(archiveEntry, copy);
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.zip;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
+
+/**
+ * JUnit 3 testcases for org.apache.tools.zip.ZipEntry.
+ *
+ */
+public class ZipEntryTest {
+
+
+ /**
+ * test handling of extra fields
+ */
+ @Test
+ public void testExtraFields() {
+ AsiExtraField a = new AsiExtraField();
+ a.setDirectory(true);
+ a.setMode(0755);
+ UnrecognizedExtraField u = new UnrecognizedExtraField();
+ u.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
+ u.setLocalFileDataData(new byte[0]);
+
+ ZipEntry ze = new ZipEntry("test/");
+ ze.setExtraFields(new ZipExtraField[] {a, u});
+ byte[] data1 = ze.getExtra();
+ ZipExtraField[] result = ze.getExtraFields();
+ assertEquals("first pass", 2, result.length);
+ assertSame(a, result[0]);
+ assertSame(u, result[1]);
+
+ UnrecognizedExtraField u2 = new UnrecognizedExtraField();
+ u2.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
+ u2.setLocalFileDataData(new byte[] {1});
+
+ ze.addExtraField(u2);
+ byte[] data2 = ze.getExtra();
+ result = ze.getExtraFields();
+ assertEquals("second pass", 2, result.length);
+ assertSame(a, result[0]);
+ assertSame(u2, result[1]);
+ assertEquals("length second pass", data1.length+1, data2.length);
+
+ UnrecognizedExtraField u3 = new UnrecognizedExtraField();
+ u3.setHeaderId(new ZipShort(2));
+ u3.setLocalFileDataData(new byte[] {1});
+ ze.addExtraField(u3);
+ result = ze.getExtraFields();
+ assertEquals("third pass", 3, result.length);
+
+ ze.removeExtraField(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
+ byte[] data3 = ze.getExtra();
+ result = ze.getExtraFields();
+ assertEquals("fourth pass", 2, result.length);
+ assertSame(a, result[0]);
+ assertSame(u3, result[1]);
+ assertEquals("length fourth pass", data2.length, data3.length);
+
+ try {
+ ze.removeExtraField(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
+ fail("should be no such element");
+ } catch (java.util.NoSuchElementException nse) {
+ //TODO assert exception values
+ }
+ }
+
+ /**
+ * test handling of extra fields via central directory
+ */
+ @Test
+ public void testExtraFieldMerging() {
+ AsiExtraField a = new AsiExtraField();
+ a.setDirectory(true);
+ a.setMode(0755);
+ UnrecognizedExtraField u = new UnrecognizedExtraField();
+ u.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
+ u.setLocalFileDataData(new byte[0]);
+
+ ZipEntry ze = new ZipEntry("test/");
+ ze.setExtraFields(new ZipExtraField[] {a, u});
+
+ // merge
+ // Header-ID 1 + length 1 + one byte of data
+ byte[] b = ExtraFieldUtilsTest.UNRECOGNIZED_HEADER.getBytes();
+ ze.setCentralDirectoryExtra(new byte[] {b[0], b[1], 1, 0, 127});
+
+ ZipExtraField[] result = ze.getExtraFields();
+ assertEquals("first pass", 2, result.length);
+ assertSame(a, result[0]);
+ assertEquals(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER,
+ result[1].getHeaderId());
+ assertEquals(new ZipShort(0), result[1].getLocalFileDataLength());
+ assertEquals(new ZipShort(1), result[1].getCentralDirectoryLength());
+
+ // add new
+ // Header-ID 2 + length 0
+ ze.setCentralDirectoryExtra(new byte[] {2, 0, 0, 0});
+
+ result = ze.getExtraFields();
+ assertEquals("second pass", 3, result.length);
+
+ // merge
+ // Header-ID 2 + length 1 + one byte of data
+ ze.setExtra(new byte[] {2, 0, 1, 0, 127});
+
+ result = ze.getExtraFields();
+ assertEquals("third pass", 3, result.length);
+ assertSame(a, result[0]);
+ assertEquals(new ZipShort(2), result[2].getHeaderId());
+ assertEquals(new ZipShort(1), result[2].getLocalFileDataLength());
+ assertEquals(new ZipShort(0), result[2].getCentralDirectoryLength());
+ }
+
+ /**
+ * test handling of extra fields
+ */
+ @Test
+ public void testAddAsFirstExtraField() {
+ AsiExtraField a = new AsiExtraField();
+ a.setDirectory(true);
+ a.setMode(0755);
+ UnrecognizedExtraField u = new UnrecognizedExtraField();
+ u.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
+ u.setLocalFileDataData(new byte[0]);
+
+ ZipEntry ze = new ZipEntry("test/");
+ ze.setExtraFields(new ZipExtraField[] {a, u});
+ byte[] data1 = ze.getExtra();
+
+ UnrecognizedExtraField u2 = new UnrecognizedExtraField();
+ u2.setHeaderId(ExtraFieldUtilsTest.UNRECOGNIZED_HEADER);
+ u2.setLocalFileDataData(new byte[] {1});
+
+ ze.addAsFirstExtraField(u2);
+ byte[] data2 = ze.getExtra();
+ ZipExtraField[] result = ze.getExtraFields();
+ assertEquals("second pass", 2, result.length);
+ assertSame(u2, result[0]);
+ assertSame(a, result[1]);
+ assertEquals("length second pass", data1.length + 1, data2.length);
+
+ UnrecognizedExtraField u3 = new UnrecognizedExtraField();
+ u3.setHeaderId(new ZipShort(2));
+ u3.setLocalFileDataData(new byte[] {1});
+ ze.addAsFirstExtraField(u3);
+ result = ze.getExtraFields();
+ assertEquals("third pass", 3, result.length);
+ assertSame(u3, result[0]);
+ assertSame(u2, result[1]);
+ assertSame(a, result[2]);
+ }
+
+ @Test
+ public void testUnixMode() {
+ ZipEntry ze = new ZipEntry("foo");
+ assertEquals(0, ze.getPlatform());
+ ze.setUnixMode(0755);
+ assertEquals(3, ze.getPlatform());
+ assertEquals(0755,
+ (ze.getExternalAttributes() >> 16) & 0xFFFF);
+ assertEquals(0, ze.getExternalAttributes() & 0xFFFF);
+
+ ze.setUnixMode(0444);
+ assertEquals(3, ze.getPlatform());
+ assertEquals(0444,
+ (ze.getExternalAttributes() >> 16) & 0xFFFF);
+ assertEquals(1, ze.getExternalAttributes() & 0xFFFF);
+
+ ze = new ZipEntry("foo/");
+ assertEquals(0, ze.getPlatform());
+ ze.setUnixMode(0777);
+ assertEquals(3, ze.getPlatform());
+ assertEquals(0777,
+ (ze.getExternalAttributes() >> 16) & 0xFFFF);
+ assertEquals(0x10, ze.getExternalAttributes() & 0xFFFF);
+
+ ze.setUnixMode(0577);
+ assertEquals(3, ze.getPlatform());
+ assertEquals(0577,
+ (ze.getExternalAttributes() >> 16) & 0xFFFF);
+ assertEquals(0x11, ze.getExternalAttributes() & 0xFFFF);
+ }
+
+ /**
+ * Test case for
+ * COMPRESS-94.
+ */
+ @Test
+ public void testNotEquals() {
+ ZipEntry entry1 = new ZipEntry("foo");
+ ZipEntry entry2 = new ZipEntry("bar");
+ assertFalse(entry1.equals(entry2));
+ }
+
+ @Test
+ public void testCopyConstructor() throws Exception {
+ ZipEntry archiveEntry = new ZipEntry("fred");
+ archiveEntry.setUnixMode(0664);
+ archiveEntry.setMethod(ZipEntry.DEFLATED);
+ archiveEntry.getGeneralPurposeBit().useStrongEncryption(true);
+ ZipEntry copy = new ZipEntry(archiveEntry);
+ assertEquals(archiveEntry, copy);
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/zip/ZipLongTest.java b/src/tests/junit/org/apache/tools/zip/ZipLongTest.java
index a7ece044e..8ec801958 100644
--- a/src/tests/junit/org/apache/tools/zip/ZipLongTest.java
+++ b/src/tests/junit/org/apache/tools/zip/ZipLongTest.java
@@ -1,94 +1,94 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.zip;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
-
-/**
- * JUnit testcases for org.apache.tools.zip.ZipLong.
- *
- */
-public class ZipLongTest {
-
- /**
- * Test conversion to bytes.
- */
- @Test
- public void testToBytes() {
- ZipLong zl = new ZipLong(0x12345678);
- byte[] result = zl.getBytes();
- assertEquals("length getBytes", 4, result.length);
- assertEquals("first byte getBytes", 0x78, result[0]);
- assertEquals("second byte getBytes", 0x56, result[1]);
- assertEquals("third byte getBytes", 0x34, result[2]);
- assertEquals("fourth byte getBytes", 0x12, result[3]);
- }
-
- /**
- * Test conversion from bytes.
- */
- @Test
- public void testFromBytes() {
- byte[] val = new byte[] {0x78, 0x56, 0x34, 0x12};
- ZipLong zl = new ZipLong(val);
- assertEquals("value from bytes", 0x12345678, zl.getValue());
- }
-
- /**
- * Test the contract of the equals method.
- */
- @Test
- public void testEquals() {
- ZipLong zl = new ZipLong(0x12345678);
- ZipLong zl2 = new ZipLong(0x12345678);
- ZipLong zl3 = new ZipLong(0x87654321);
-
- assertTrue("reflexive", zl.equals(zl));
-
- assertTrue("works", zl.equals(zl2));
- assertTrue("works, part two", !zl.equals(zl3));
-
- assertTrue("symmetric", zl2.equals(zl));
-
- assertTrue("null handling", !zl.equals(null));
- assertTrue("non ZipLong handling", !zl.equals(new Integer(0x1234)));
- }
-
- /**
- * Test sign handling.
- */
- @Test
- public void testSign() {
- ZipLong zl = new ZipLong(new byte[] {(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF});
- assertEquals(0x00000000FFFFFFFFl, zl.getValue());
- }
-
- @Test
- public void testClone() {
- ZipLong s1 = new ZipLong(42);
- ZipLong s2 = (ZipLong) s1.clone();
- assertNotSame(s1, s2);
- assertEquals(s1, s2);
- assertEquals(s1.getValue(), s2.getValue());
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.zip;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * JUnit testcases for org.apache.tools.zip.ZipLong.
+ *
+ */
+public class ZipLongTest {
+
+ /**
+ * Test conversion to bytes.
+ */
+ @Test
+ public void testToBytes() {
+ ZipLong zl = new ZipLong(0x12345678);
+ byte[] result = zl.getBytes();
+ assertEquals("length getBytes", 4, result.length);
+ assertEquals("first byte getBytes", 0x78, result[0]);
+ assertEquals("second byte getBytes", 0x56, result[1]);
+ assertEquals("third byte getBytes", 0x34, result[2]);
+ assertEquals("fourth byte getBytes", 0x12, result[3]);
+ }
+
+ /**
+ * Test conversion from bytes.
+ */
+ @Test
+ public void testFromBytes() {
+ byte[] val = new byte[] {0x78, 0x56, 0x34, 0x12};
+ ZipLong zl = new ZipLong(val);
+ assertEquals("value from bytes", 0x12345678, zl.getValue());
+ }
+
+ /**
+ * Test the contract of the equals method.
+ */
+ @Test
+ public void testEquals() {
+ ZipLong zl = new ZipLong(0x12345678);
+ ZipLong zl2 = new ZipLong(0x12345678);
+ ZipLong zl3 = new ZipLong(0x87654321);
+
+ assertTrue("reflexive", zl.equals(zl));
+
+ assertTrue("works", zl.equals(zl2));
+ assertTrue("works, part two", !zl.equals(zl3));
+
+ assertTrue("symmetric", zl2.equals(zl));
+
+ assertTrue("null handling", !zl.equals(null));
+ assertTrue("non ZipLong handling", !zl.equals(new Integer(0x1234)));
+ }
+
+ /**
+ * Test sign handling.
+ */
+ @Test
+ public void testSign() {
+ ZipLong zl = new ZipLong(new byte[] {(byte)0xFF, (byte)0xFF, (byte)0xFF, (byte)0xFF});
+ assertEquals(0x00000000FFFFFFFFl, zl.getValue());
+ }
+
+ @Test
+ public void testClone() {
+ ZipLong s1 = new ZipLong(42);
+ ZipLong s2 = (ZipLong) s1.clone();
+ assertNotSame(s1, s2);
+ assertEquals(s1, s2);
+ assertEquals(s1.getValue(), s2.getValue());
+ }
+}
diff --git a/src/tests/junit/org/apache/tools/zip/ZipOutputStreamTest.java b/src/tests/junit/org/apache/tools/zip/ZipOutputStreamTest.java
index a69db6c18..7040782cf 100644
--- a/src/tests/junit/org/apache/tools/zip/ZipOutputStreamTest.java
+++ b/src/tests/junit/org/apache/tools/zip/ZipOutputStreamTest.java
@@ -1,73 +1,73 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.zip;
-
-import org.junit.Before;
-import org.junit.Test;
-
-import java.util.Calendar;
-import java.util.Date;
-
-import static org.junit.Assert.assertEquals;
-
-public class ZipOutputStreamTest {
-
- private Date time;
- private ZipLong zl;
-
- @Before
- public void setUp() throws Exception {
- time = new Date();
- Calendar cal = Calendar.getInstance();
- cal.setTime(time);
- int year = cal.get(Calendar.YEAR);
- int month = cal.get(Calendar.MONTH) + 1;
- long value = ((year - 1980) << 25)
- | (month << 21)
- | (cal.get(Calendar.DAY_OF_MONTH) << 16)
- | (cal.get(Calendar.HOUR_OF_DAY) << 11)
- | (cal.get(Calendar.MINUTE) << 5)
- | (cal.get(Calendar.SECOND) >> 1);
-
- byte[] result = new byte[4];
- result[0] = (byte) ((value & 0xFF));
- result[1] = (byte) ((value & 0xFF00) >> 8);
- result[2] = (byte) ((value & 0xFF0000) >> 16);
- result[3] = (byte) ((value & 0xFF000000L) >> 24);
- zl = new ZipLong(result);
- }
-
-
- @Test
- public void testZipLong() throws Exception {
- ZipLong test = ZipOutputStream.toDosTime(time);
- assertEquals(test.getValue(), zl.getValue());
- }
-
- @Test
- public void testAdjustToLong() {
- assertEquals((long) Integer.MAX_VALUE,
- ZipOutputStream.adjustToLong(Integer.MAX_VALUE));
- assertEquals(((long) Integer.MAX_VALUE) + 1,
- ZipOutputStream.adjustToLong(Integer.MAX_VALUE + 1));
- assertEquals(2 * ((long) Integer.MAX_VALUE),
- ZipOutputStream.adjustToLong(2 * Integer.MAX_VALUE));
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.zip;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.util.Calendar;
+import java.util.Date;
+
+import static org.junit.Assert.assertEquals;
+
+public class ZipOutputStreamTest {
+
+ private Date time;
+ private ZipLong zl;
+
+ @Before
+ public void setUp() throws Exception {
+ time = new Date();
+ Calendar cal = Calendar.getInstance();
+ cal.setTime(time);
+ int year = cal.get(Calendar.YEAR);
+ int month = cal.get(Calendar.MONTH) + 1;
+ long value = ((year - 1980) << 25)
+ | (month << 21)
+ | (cal.get(Calendar.DAY_OF_MONTH) << 16)
+ | (cal.get(Calendar.HOUR_OF_DAY) << 11)
+ | (cal.get(Calendar.MINUTE) << 5)
+ | (cal.get(Calendar.SECOND) >> 1);
+
+ byte[] result = new byte[4];
+ result[0] = (byte) ((value & 0xFF));
+ result[1] = (byte) ((value & 0xFF00) >> 8);
+ result[2] = (byte) ((value & 0xFF0000) >> 16);
+ result[3] = (byte) ((value & 0xFF000000L) >> 24);
+ zl = new ZipLong(result);
+ }
+
+
+ @Test
+ public void testZipLong() throws Exception {
+ ZipLong test = ZipOutputStream.toDosTime(time);
+ assertEquals(test.getValue(), zl.getValue());
+ }
+
+ @Test
+ public void testAdjustToLong() {
+ assertEquals((long) Integer.MAX_VALUE,
+ ZipOutputStream.adjustToLong(Integer.MAX_VALUE));
+ assertEquals(((long) Integer.MAX_VALUE) + 1,
+ ZipOutputStream.adjustToLong(Integer.MAX_VALUE + 1));
+ assertEquals(2 * ((long) Integer.MAX_VALUE),
+ ZipOutputStream.adjustToLong(2 * Integer.MAX_VALUE));
+ }
+
+}
diff --git a/src/tests/junit/org/apache/tools/zip/ZipShortTest.java b/src/tests/junit/org/apache/tools/zip/ZipShortTest.java
index a6aa3e78b..4b9747137 100644
--- a/src/tests/junit/org/apache/tools/zip/ZipShortTest.java
+++ b/src/tests/junit/org/apache/tools/zip/ZipShortTest.java
@@ -1,92 +1,92 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.apache.tools.zip;
-
-import org.junit.Test;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertTrue;
-
-/**
- * JUnit 3 testcases for org.apache.tools.zip.ZipShort.
- *
- */
-public class ZipShortTest {
-
- /**
- * Test conversion to bytes.
- */
- @Test
- public void testToBytes() {
- ZipShort zs = new ZipShort(0x1234);
- byte[] result = zs.getBytes();
- assertEquals("length getBytes", 2, result.length);
- assertEquals("first byte getBytes", 0x34, result[0]);
- assertEquals("second byte getBytes", 0x12, result[1]);
- }
-
- /**
- * Test conversion from bytes.
- */
- @Test
- public void testFromBytes() {
- byte[] val = new byte[] {0x34, 0x12};
- ZipShort zs = new ZipShort(val);
- assertEquals("value from bytes", 0x1234, zs.getValue());
- }
-
- /**
- * Test the contract of the equals method.
- */
- @Test
- public void testEquals() {
- ZipShort zs = new ZipShort(0x1234);
- ZipShort zs2 = new ZipShort(0x1234);
- ZipShort zs3 = new ZipShort(0x5678);
-
- assertTrue("reflexive", zs.equals(zs));
-
- assertTrue("works", zs.equals(zs2));
- assertTrue("works, part two", !zs.equals(zs3));
-
- assertTrue("symmetric", zs2.equals(zs));
-
- assertTrue("null handling", !zs.equals(null));
- assertTrue("non ZipShort handling", !zs.equals(new Integer(0x1234)));
- }
-
- /**
- * Test sign handling.
- */
- @Test
- public void testSign() {
- ZipShort zs = new ZipShort(new byte[] {(byte)0xFF, (byte)0xFF});
- assertEquals(0x0000FFFF, zs.getValue());
- }
-
- @Test
- public void testClone() {
- ZipShort s1 = new ZipShort(42);
- ZipShort s2 = (ZipShort) s1.clone();
- assertNotSame(s1, s2);
- assertEquals(s1, s2);
- assertEquals(s1.getValue(), s2.getValue());
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.apache.tools.zip;
+
+import org.junit.Test;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotSame;
+import static org.junit.Assert.assertTrue;
+
+/**
+ * JUnit 3 testcases for org.apache.tools.zip.ZipShort.
+ *
+ */
+public class ZipShortTest {
+
+ /**
+ * Test conversion to bytes.
+ */
+ @Test
+ public void testToBytes() {
+ ZipShort zs = new ZipShort(0x1234);
+ byte[] result = zs.getBytes();
+ assertEquals("length getBytes", 2, result.length);
+ assertEquals("first byte getBytes", 0x34, result[0]);
+ assertEquals("second byte getBytes", 0x12, result[1]);
+ }
+
+ /**
+ * Test conversion from bytes.
+ */
+ @Test
+ public void testFromBytes() {
+ byte[] val = new byte[] {0x34, 0x12};
+ ZipShort zs = new ZipShort(val);
+ assertEquals("value from bytes", 0x1234, zs.getValue());
+ }
+
+ /**
+ * Test the contract of the equals method.
+ */
+ @Test
+ public void testEquals() {
+ ZipShort zs = new ZipShort(0x1234);
+ ZipShort zs2 = new ZipShort(0x1234);
+ ZipShort zs3 = new ZipShort(0x5678);
+
+ assertTrue("reflexive", zs.equals(zs));
+
+ assertTrue("works", zs.equals(zs2));
+ assertTrue("works, part two", !zs.equals(zs3));
+
+ assertTrue("symmetric", zs2.equals(zs));
+
+ assertTrue("null handling", !zs.equals(null));
+ assertTrue("non ZipShort handling", !zs.equals(new Integer(0x1234)));
+ }
+
+ /**
+ * Test sign handling.
+ */
+ @Test
+ public void testSign() {
+ ZipShort zs = new ZipShort(new byte[] {(byte)0xFF, (byte)0xFF});
+ assertEquals(0x0000FFFF, zs.getValue());
+ }
+
+ @Test
+ public void testClone() {
+ ZipShort s1 = new ZipShort(42);
+ ZipShort s2 = (ZipShort) s1.clone();
+ assertNotSame(s1, s2);
+ assertEquals(s1, s2);
+ assertEquals(s1.getValue(), s2.getValue());
+ }
+}
diff --git a/src/tests/junit/org/example/junit/JUnit4Skippable.java b/src/tests/junit/org/example/junit/JUnit4Skippable.java
index aa89ab7da..e71345c4b 100644
--- a/src/tests/junit/org/example/junit/JUnit4Skippable.java
+++ b/src/tests/junit/org/example/junit/JUnit4Skippable.java
@@ -1,74 +1,74 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.example.junit;
-
-import org.junit.Assume;
-import org.junit.Ignore;
-import org.junit.Test;
-
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-public class JUnit4Skippable {
-
- @Test
- public void passingTest() {
- assertTrue("This test passed", true);
- }
-
- @Ignore("Please don't ignore me!")
- @Test
- public void explicitIgnoreTest() {
- fail("This test should be skipped");
- }
-
- @Test
- public void implicitlyIgnoreTest() {
- Assume.assumeFalse("This test will be ignored", true);
- fail("I told you, this test should have been ignored!");
- }
-
- @Test
- @Ignore
- public void explicitlyIgnoreTestNoMessage() {
- fail("This test should be skipped");
- }
-
- @Test
- public void implicitlyIgnoreTestNoMessage() {
- Assume.assumeFalse(true);
- fail("I told you, this test should have been ignored!");
- }
-
- @Test
- public void failingTest() {
- fail("I told you this test was going to fail");
- }
-
- @Test
- public void failingTestNoMessage() {
- fail();
- }
-
- @Test
- public void errorTest() {
- throw new RuntimeException("Whoops, this test went wrong");
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.example.junit;
+
+import org.junit.Assume;
+import org.junit.Ignore;
+import org.junit.Test;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+public class JUnit4Skippable {
+
+ @Test
+ public void passingTest() {
+ assertTrue("This test passed", true);
+ }
+
+ @Ignore("Please don't ignore me!")
+ @Test
+ public void explicitIgnoreTest() {
+ fail("This test should be skipped");
+ }
+
+ @Test
+ public void implicitlyIgnoreTest() {
+ Assume.assumeFalse("This test will be ignored", true);
+ fail("I told you, this test should have been ignored!");
+ }
+
+ @Test
+ @Ignore
+ public void explicitlyIgnoreTestNoMessage() {
+ fail("This test should be skipped");
+ }
+
+ @Test
+ public void implicitlyIgnoreTestNoMessage() {
+ Assume.assumeFalse(true);
+ fail("I told you, this test should have been ignored!");
+ }
+
+ @Test
+ public void failingTest() {
+ fail("I told you this test was going to fail");
+ }
+
+ @Test
+ public void failingTestNoMessage() {
+ fail();
+ }
+
+ @Test
+ public void errorTest() {
+ throw new RuntimeException("Whoops, this test went wrong");
+ }
+
+}
diff --git a/src/tests/junit/org/example/junit/MultilineAsserts.java b/src/tests/junit/org/example/junit/MultilineAsserts.java
index 06e10390d..1b0cc59ba 100644
--- a/src/tests/junit/org/example/junit/MultilineAsserts.java
+++ b/src/tests/junit/org/example/junit/MultilineAsserts.java
@@ -1,27 +1,27 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.example.junit;
-
-import junit.framework.TestCase;
-
-public class MultilineAsserts extends TestCase {
- public void testFoo() { assertTrue("testFoo \nmessed up", false); }
- public void testBar() { assertTrue("testBar \ndidn't work", true); }
- public void testFee() { assertTrue("testFee \ncrashed", false); }
- public void testFie() { assertTrue("testFie \nbroke", true); }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.example.junit;
+
+import junit.framework.TestCase;
+
+public class MultilineAsserts extends TestCase {
+ public void testFoo() { assertTrue("testFoo \nmessed up", false); }
+ public void testBar() { assertTrue("testBar \ndidn't work", true); }
+ public void testFee() { assertTrue("testFee \ncrashed", false); }
+ public void testFie() { assertTrue("testFie \nbroke", true); }
+}
diff --git a/src/tests/junit/org/example/junit/Output.java b/src/tests/junit/org/example/junit/Output.java
index a7135f7b3..a536a47c4 100644
--- a/src/tests/junit/org/example/junit/Output.java
+++ b/src/tests/junit/org/example/junit/Output.java
@@ -1,37 +1,37 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.example.junit;
-
-import junit.framework.TestCase;
-
-/**
- * Not really a test of Ant but a test that is run by the test of the
- * junit task. Confused?
- *
- * @since Ant 1.5
- */
-public class Output extends TestCase {
-
- public Output(String s) {
- super(s);
- }
-
- public void testOutput() {
- System.out.println("foo");
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.example.junit;
+
+import junit.framework.TestCase;
+
+/**
+ * Not really a test of Ant but a test that is run by the test of the
+ * junit task. Confused?
+ *
+ * @since Ant 1.5
+ */
+public class Output extends TestCase {
+
+ public Output(String s) {
+ super(s);
+ }
+
+ public void testOutput() {
+ System.out.println("foo");
+ }
+}
diff --git a/src/tests/junit/org/example/junit/ThreadedOutput.java b/src/tests/junit/org/example/junit/ThreadedOutput.java
index 91f462a21..f5ee38dd8 100644
--- a/src/tests/junit/org/example/junit/ThreadedOutput.java
+++ b/src/tests/junit/org/example/junit/ThreadedOutput.java
@@ -1,43 +1,43 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.example.junit;
-
-import junit.framework.TestCase;
-
-/**
- * Not really a test of Ant but a test that is run by the test of the
- * junit task. Confused?
- *
- * @since Ant 1.5
- */
-public class ThreadedOutput extends TestCase {
-
- public ThreadedOutput(String s) {
- super(s);
- }
-
- public void testOutput() throws InterruptedException {
- Thread t = new Thread(new Runnable() {
- public void run() {
- System.out.println("foo");
- }
- });
- t.start();
- t.join();
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.example.junit;
+
+import junit.framework.TestCase;
+
+/**
+ * Not really a test of Ant but a test that is run by the test of the
+ * junit task. Confused?
+ *
+ * @since Ant 1.5
+ */
+public class ThreadedOutput extends TestCase {
+
+ public ThreadedOutput(String s) {
+ super(s);
+ }
+
+ public void testOutput() throws InterruptedException {
+ Thread t = new Thread(new Runnable() {
+ public void run() {
+ System.out.println("foo");
+ }
+ });
+ t.start();
+ t.join();
+ }
+}
diff --git a/src/tests/junit/org/example/junit/Timeout.java b/src/tests/junit/org/example/junit/Timeout.java
index 6a42ee758..54cb4e74a 100644
--- a/src/tests/junit/org/example/junit/Timeout.java
+++ b/src/tests/junit/org/example/junit/Timeout.java
@@ -1,32 +1,32 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.example.junit;
-
-import org.junit.After;
-import org.junit.Test;
-
-public class Timeout {
- @Test
- public void testTimeout() throws InterruptedException {
- Thread.sleep(5000);
- }
- @After
- public void tearDown() {
- System.out.println("tearDown called on Timeout");
- }
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.example.junit;
+
+import org.junit.After;
+import org.junit.Test;
+
+public class Timeout {
+ @Test
+ public void testTimeout() throws InterruptedException {
+ Thread.sleep(5000);
+ }
+ @After
+ public void tearDown() {
+ System.out.println("tearDown called on Timeout");
+ }
+}
diff --git a/src/tests/junit/org/example/junit/XmlParserTest.java b/src/tests/junit/org/example/junit/XmlParserTest.java
index e5fae55f8..57d74f081 100644
--- a/src/tests/junit/org/example/junit/XmlParserTest.java
+++ b/src/tests/junit/org/example/junit/XmlParserTest.java
@@ -1,58 +1,58 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-package org.example.junit;
-
-import org.junit.Test;
-import org.xml.sax.SAXException;
-import org.xml.sax.XMLReader;
-import org.xml.sax.helpers.XMLReaderFactory;
-
-import static org.junit.Assert.assertNotNull;
-
-/**
- * created Aug 12, 2004 1:39:59 PM
- */
-
-public class XmlParserTest {
-
-
- @Test
- public void testXercesIsPresent() throws SAXException {
- XMLReader xerces;
- xerces = XMLReaderFactory.createXMLReader(
- "org.apache.xerces.parsers.SAXParser");
- assertNotNull(xerces);
- }
-
- @Test
- public void testXercesHandlesSchema() throws SAXException {
- XMLReader xerces;
- xerces = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
- xerces.setFeature("http://apache.org/xml/features/validation/schema",
- true);
- }
-
- @Test
- public void testParserHandlesSchema() throws SAXException {
- XMLReader xerces;
- xerces = XMLReaderFactory.createXMLReader();
- xerces.setFeature("http://apache.org/xml/features/validation/schema",
- true);
- }
-
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+package org.example.junit;
+
+import org.junit.Test;
+import org.xml.sax.SAXException;
+import org.xml.sax.XMLReader;
+import org.xml.sax.helpers.XMLReaderFactory;
+
+import static org.junit.Assert.assertNotNull;
+
+/**
+ * created Aug 12, 2004 1:39:59 PM
+ */
+
+public class XmlParserTest {
+
+
+ @Test
+ public void testXercesIsPresent() throws SAXException {
+ XMLReader xerces;
+ xerces = XMLReaderFactory.createXMLReader(
+ "org.apache.xerces.parsers.SAXParser");
+ assertNotNull(xerces);
+ }
+
+ @Test
+ public void testXercesHandlesSchema() throws SAXException {
+ XMLReader xerces;
+ xerces = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");
+ xerces.setFeature("http://apache.org/xml/features/validation/schema",
+ true);
+ }
+
+ @Test
+ public void testParserHandlesSchema() throws SAXException {
+ XMLReader xerces;
+ xerces = XMLReaderFactory.createXMLReader();
+ xerces.setFeature("http://apache.org/xml/features/validation/schema",
+ true);
+ }
+
+}
diff --git a/src/tests/junit/org/example/tasks/TaskdefTestContainerTask.java b/src/tests/junit/org/example/tasks/TaskdefTestContainerTask.java
index a566d5c1f..0e0a599d6 100644
--- a/src/tests/junit/org/example/tasks/TaskdefTestContainerTask.java
+++ b/src/tests/junit/org/example/tasks/TaskdefTestContainerTask.java
@@ -1,25 +1,25 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.example.tasks;
-
-import org.apache.tools.ant.taskdefs.Sequential;
-
-public class TaskdefTestContainerTask extends Sequential {
- public TaskdefTestContainerTask() {}
-}
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.example.tasks;
+
+import org.apache.tools.ant.taskdefs.Sequential;
+
+public class TaskdefTestContainerTask extends Sequential {
+ public TaskdefTestContainerTask() {}
+}
diff --git a/src/tests/junit/org/example/tasks/TaskdefTestSimpleTask.java b/src/tests/junit/org/example/tasks/TaskdefTestSimpleTask.java
index bce8cd503..4c0bc692a 100644
--- a/src/tests/junit/org/example/tasks/TaskdefTestSimpleTask.java
+++ b/src/tests/junit/org/example/tasks/TaskdefTestSimpleTask.java
@@ -1,45 +1,45 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.example.tasks;
-
-import org.apache.tools.ant.Project;
-import org.apache.tools.ant.Task;
-
-public class TaskdefTestSimpleTask extends Task {
-
- public class Echo {
- Echo() {}
- private String message = null;
- public void setMessage(String s) {message = s;}
- }
-
- public TaskdefTestSimpleTask() {}
-
- private Echo echo;
- public Echo createEcho() {
- echo = new Echo();
- return echo;
- }
-
- public void execute() {
- log("simpletask: "+echo.message, Project.MSG_INFO);
- }
-
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.example.tasks;
+
+import org.apache.tools.ant.Project;
+import org.apache.tools.ant.Task;
+
+public class TaskdefTestSimpleTask extends Task {
+
+ public class Echo {
+ Echo() {}
+ private String message = null;
+ public void setMessage(String s) {message = s;}
+ }
+
+ public TaskdefTestSimpleTask() {}
+
+ private Echo echo;
+ public Echo createEcho() {
+ echo = new Echo();
+ return echo;
+ }
+
+ public void execute() {
+ log("simpletask: "+echo.message, Project.MSG_INFO);
+ }
+
+}
+
diff --git a/src/tests/junit/org/example/tasks/antlib.xml b/src/tests/junit/org/example/tasks/antlib.xml
index b920da7eb..2d8765793 100644
--- a/src/tests/junit/org/example/tasks/antlib.xml
+++ b/src/tests/junit/org/example/tasks/antlib.xml
@@ -1,26 +1,26 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/tests/junit/org/example/tasks/antlib2.xml b/src/tests/junit/org/example/tasks/antlib2.xml
index b920da7eb..2d8765793 100644
--- a/src/tests/junit/org/example/tasks/antlib2.xml
+++ b/src/tests/junit/org/example/tasks/antlib2.xml
@@ -1,26 +1,26 @@
-
-
-
-
-
-
-
-
-
-
-
+
+
+
+
+
+
+
+
+
+
+
diff --git a/src/tests/junit/org/example/types/TypedefTestType.java b/src/tests/junit/org/example/types/TypedefTestType.java
index 235b76f61..80eef2202 100644
--- a/src/tests/junit/org/example/types/TypedefTestType.java
+++ b/src/tests/junit/org/example/types/TypedefTestType.java
@@ -1,25 +1,25 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * The ASF licenses this file to You under the Apache License, Version 2.0
- * (the "License"); you may not use this file except in compliance with
- * the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- *
- */
-
-package org.example.types;
-
-import org.apache.tools.ant.ProjectComponent;
-
-public class TypedefTestType extends ProjectComponent {
-}
-
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *
+ */
+
+package org.example.types;
+
+import org.apache.tools.ant.ProjectComponent;
+
+public class TypedefTestType extends ProjectComponent {
+}
+