You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by bo...@apache.org on 2015/04/18 22:26:43 UTC
[13/22] ant git commit: fix some lineends
http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/MapperTest.java
----------------------------------------------------------------------
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 980f5cc..8758238 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");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/PathTest.java
----------------------------------------------------------------------
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 2ad1819..4580629 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);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/ant/blob/1ae68097/src/tests/junit/org/apache/tools/ant/types/PatternSetTest.java
----------------------------------------------------------------------
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 065d757..c88b49a 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.
- *
- * <p>This doesn't actually test much, mainly reference handling.</p>
- *
- */
-
-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.
+ *
+ * <p>This doesn't actually test much, mainly reference handling.</p>
+ *
+ */
+
+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]);
+ }
+}