|
|
@@ -55,218 +55,42 @@ |
|
|
package org.apache.tools.ant.types; |
|
|
package org.apache.tools.ant.types; |
|
|
|
|
|
|
|
|
import org.apache.tools.ant.BuildException; |
|
|
import org.apache.tools.ant.BuildException; |
|
|
import org.apache.tools.ant.Project; |
|
|
|
|
|
|
|
|
|
|
|
import junit.framework.TestCase; |
|
|
|
|
|
import junit.framework.AssertionFailedError; |
|
|
|
|
|
|
|
|
|
|
|
import java.io.File; |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
/** |
|
|
* JUnit 3 testcases for org.apache.tools.ant.types.DirSet. |
|
|
* JUnit 3 testcases for org.apache.tools.ant.types.DirSet. |
|
|
* |
|
|
* |
|
|
* <p>This doesn't actually test much, mainly reference handling. |
|
|
|
|
|
* |
|
|
|
|
|
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> |
|
|
* @author <a href="mailto:stefan.bodewig@epost.de">Stefan Bodewig</a> |
|
|
*/ |
|
|
*/ |
|
|
|
|
|
|
|
|
public class DirSetTest extends TestCase { |
|
|
|
|
|
|
|
|
|
|
|
private Project project; |
|
|
|
|
|
|
|
|
public class DirSetTest extends FileSetTest { |
|
|
|
|
|
|
|
|
public DirSetTest(String name) { |
|
|
public DirSetTest(String name) { |
|
|
super(name); |
|
|
super(name); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void setUp() { |
|
|
|
|
|
project = new Project(); |
|
|
|
|
|
project.setBasedir("."); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testEmptyElementIfIsReference() { |
|
|
|
|
|
DirSet f = new DirSet(); |
|
|
|
|
|
f.setIncludes("**/*.java"); |
|
|
|
|
|
try { |
|
|
|
|
|
f.setRefid(new Reference("dummyref")); |
|
|
|
|
|
fail("Can add reference to DirSet with elements from setIncludes"); |
|
|
|
|
|
} catch (BuildException be) { |
|
|
|
|
|
assertEquals("You must not specify more than one attribute when using refid", |
|
|
|
|
|
be.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
f = new DirSet(); |
|
|
|
|
|
f.createPatternSet(); |
|
|
|
|
|
try { |
|
|
|
|
|
f.setRefid(new Reference("dummyref")); |
|
|
|
|
|
fail("Can add reference to DirSet with nested patternset element."); |
|
|
|
|
|
} catch (BuildException be) { |
|
|
|
|
|
assertEquals("You must not specify nested elements when using refid", |
|
|
|
|
|
be.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
f = new DirSet(); |
|
|
|
|
|
f.createInclude(); |
|
|
|
|
|
try { |
|
|
|
|
|
f.setRefid(new Reference("dummyref")); |
|
|
|
|
|
fail("Can add reference to DirSet with nested include element."); |
|
|
|
|
|
} catch (BuildException be) { |
|
|
|
|
|
assertEquals("You must not specify more than one attribute when using refid", |
|
|
|
|
|
be.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
f = new DirSet(); |
|
|
|
|
|
f.setRefid(new Reference("dummyref")); |
|
|
|
|
|
try { |
|
|
|
|
|
f.setIncludes("**/*.java"); |
|
|
|
|
|
fail("Can set includes in DirSet 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 DirSet 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 DirSet 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 DirSet 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 DirSet 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 DirSet 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 DirSet 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 DirSet 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 DirSet 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 DirSet that is a reference."); |
|
|
|
|
|
} catch (BuildException be) { |
|
|
|
|
|
assertEquals("You must not specify nested elements when using refid", |
|
|
|
|
|
be.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void testCircularReferenceCheck() { |
|
|
|
|
|
DirSet f = new DirSet(); |
|
|
|
|
|
project.addReference("dummy", f); |
|
|
|
|
|
f.setRefid(new Reference("dummy")); |
|
|
|
|
|
try { |
|
|
|
|
|
f.getDir(project); |
|
|
|
|
|
fail("Can make DirSet a Reference to itself."); |
|
|
|
|
|
} catch (BuildException be) { |
|
|
|
|
|
assertEquals("This data type contains a circular reference.", |
|
|
|
|
|
be.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
try { |
|
|
|
|
|
f.getDirectoryScanner(project); |
|
|
|
|
|
fail("Can make DirSet a Reference to itself."); |
|
|
|
|
|
} catch (BuildException be) { |
|
|
|
|
|
assertEquals("This data type contains a circular reference.", |
|
|
|
|
|
be.getMessage()); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// dummy1 --> dummy2 --> dummy3 --> dummy1 |
|
|
|
|
|
DirSet f1 = new DirSet(); |
|
|
|
|
|
project.addReference("dummy1", f1); |
|
|
|
|
|
f1.setRefid(new Reference("dummy2")); |
|
|
|
|
|
DirSet f2 = new DirSet(); |
|
|
|
|
|
project.addReference("dummy2", f2); |
|
|
|
|
|
f2.setRefid(new Reference("dummy3")); |
|
|
|
|
|
DirSet f3 = new DirSet(); |
|
|
|
|
|
project.addReference("dummy3", f3); |
|
|
|
|
|
f3.setRefid(new Reference("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 = new DirSet(); |
|
|
|
|
|
project.addReference("dummy1", f1); |
|
|
|
|
|
f1.setRefid(new Reference("dummy2")); |
|
|
|
|
|
f2 = new DirSet(); |
|
|
|
|
|
project.addReference("dummy2", f2); |
|
|
|
|
|
f2.setRefid(new Reference("dummy3")); |
|
|
|
|
|
f3 = new DirSet(); |
|
|
|
|
|
project.addReference("dummy3", f3); |
|
|
|
|
|
f3.setDir(project.resolveFile(".")); |
|
|
|
|
|
File dir = f1.getDir(project); |
|
|
|
|
|
assertEquals("Dir is basedir", dir, project.getBaseDir()); |
|
|
|
|
|
|
|
|
protected FileSet getInstance() { |
|
|
|
|
|
return new DirSet(); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
public void testFileSetIsNoDirSet() { |
|
|
public void testFileSetIsNoDirSet() { |
|
|
DirSet ds = new DirSet(); |
|
|
|
|
|
ds.setProject(project); |
|
|
|
|
|
|
|
|
DirSet ds = (DirSet) getInstance(); |
|
|
|
|
|
ds.setProject(getProject()); |
|
|
FileSet fs = new FileSet(); |
|
|
FileSet fs = new FileSet(); |
|
|
fs.setProject(project); |
|
|
|
|
|
project.addReference("dummy", fs); |
|
|
|
|
|
|
|
|
fs.setProject(getProject()); |
|
|
|
|
|
getProject().addReference("dummy", fs); |
|
|
ds.setRefid(new Reference("dummy")); |
|
|
ds.setRefid(new Reference("dummy")); |
|
|
try { |
|
|
try { |
|
|
ds.getDir(project); |
|
|
|
|
|
|
|
|
ds.getDir(getProject()); |
|
|
fail("DirSet created from FileSet reference"); |
|
|
fail("DirSet created from FileSet reference"); |
|
|
} catch (BuildException e) { |
|
|
} catch (BuildException e) { |
|
|
assertEquals("dummy doesn\'t denote a dirset", e.getMessage()); |
|
|
assertEquals("dummy doesn\'t denote a dirset", e.getMessage()); |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
ds = new DirSet(); |
|
|
|
|
|
ds.setProject(project); |
|
|
|
|
|
project.addReference("dummy2", ds); |
|
|
|
|
|
|
|
|
ds = (DirSet) getInstance(); |
|
|
|
|
|
ds.setProject(getProject()); |
|
|
|
|
|
getProject().addReference("dummy2", ds); |
|
|
fs.setRefid(new Reference("dummy2")); |
|
|
fs.setRefid(new Reference("dummy2")); |
|
|
try { |
|
|
try { |
|
|
fs.getDir(project); |
|
|
|
|
|
|
|
|
fs.getDir(getProject()); |
|
|
fail("FileSet created from DirSet reference"); |
|
|
fail("FileSet created from DirSet reference"); |
|
|
} catch (BuildException e) { |
|
|
} catch (BuildException e) { |
|
|
assertEquals("dummy2 doesn\'t denote a fileset", e.getMessage()); |
|
|
assertEquals("dummy2 doesn\'t denote a fileset", e.getMessage()); |
|
|
|