Browse Source

Add a few more tests - and fix the bugs found by them.

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@721510 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 16 years ago
parent
commit
027f5c7965
2 changed files with 78 additions and 2 deletions
  1. +19
    -2
      src/main/org/apache/tools/ant/types/resources/Archives.java
  2. +59
    -0
      src/tests/antunit/types/resources/archives-test.xml

+ 19
- 2
src/main/org/apache/tools/ant/types/resources/Archives.java View File

@@ -25,6 +25,7 @@ import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.Project;
import org.apache.tools.ant.types.ArchiveFileSet;
import org.apache.tools.ant.types.DataType;
import org.apache.tools.ant.types.Reference;
import org.apache.tools.ant.types.Resource;
import org.apache.tools.ant.types.ResourceCollection;
import org.apache.tools.ant.types.TarFileSet;
@@ -51,6 +52,7 @@ public class Archives extends DataType
if (isReference()) {
throw noChildrenAllowed();
}
setChecked(false);
return zips;
}

@@ -62,6 +64,7 @@ public class Archives extends DataType
if (isReference()) {
throw noChildrenAllowed();
}
setChecked(false);
return tars;
}

@@ -72,6 +75,7 @@ public class Archives extends DataType
if (isReference()) {
return ((Archives) getCheckedRef()).size();
}
dieOnCircularReference();
int total = 0;
for (Iterator i = grabArchives(); i.hasNext(); ) {
total += ((ResourceCollection) i.next()).size();
@@ -86,6 +90,7 @@ public class Archives extends DataType
if (isReference()) {
return ((Archives) getCheckedRef()).iterator();
}
dieOnCircularReference();
List l = new LinkedList();
for (Iterator i = grabArchives(); i.hasNext(); ) {
l.addAll(CollectionUtils
@@ -99,12 +104,24 @@ public class Archives extends DataType
*/
public boolean isFilesystemOnly() {
if (isReference()) {
return ((MappedResourceCollection) getCheckedRef())
.isFilesystemOnly();
return ((Archives) getCheckedRef()).isFilesystemOnly();
}
dieOnCircularReference();
return false;
}

/**
* Overrides the base version.
* @param r the Reference to set.
*/
public void setRefid(Reference r) {
if (zips.getResourceCollections().size() > 0
|| tars.getResourceCollections().size() > 0) {
throw tooManyAttributes();
}
super.setRefid(r);
}

/**
* Implement clone. The nested resource collections are cloned as
* well.


+ 59
- 0
src/tests/antunit/types/resources/archives-test.xml View File

@@ -34,4 +34,63 @@
<au:assertFileExists
file="${output}/org/apache/tools/ant/BuildFileTest.class"/>
</target>

<target name="testMixingZipsAndTars">
<mkdir dir="${output}"/>
<tar destfile="${output}/test.tar.gz" compression="gzip">
<fileset file="${ant.file}"/>
</tar>
<copy todir="${output}">
<archives>
<zips>
<fileset dir="../../../../../build/lib"
includes="ant-launcher.jar"/>
</zips>
<tars>
<gzipresource>
<file file="${output}/test.tar.gz"/>
</gzipresource>
</tars>
</archives>
</copy>
<au:assertFileExists
file="${output}/org/apache/tools/ant/launch/Launcher.class"/>
<basename property="filename" file="${ant.file}"/>
<au:assertFileExists file="${output}/${filename}"/>
</target>

<target name="testReference">
<mkdir dir="${output}"/>
<archives id="ref">
<zips>
<fileset dir="../../../../../build/lib"
includes="ant-launcher.jar"/>
</zips>
</archives>
<copy todir="${output}">
<archives refid="ref"/>
</copy>
<au:assertFileExists
file="${output}/org/apache/tools/ant/launch/Launcher.class"/>
</target>

<target name="testCircularReference">
<au:expectfailure
message="This data type contains a circular reference.">
<copy todir="${output}">
<archives id="ref">
<zips>
<archives refid="ref"/>
</zips>
</archives>
</copy>
</au:expectfailure>
<au:expectfailure
message="This data type contains a circular reference.">
<copy todir="${output}">
<archives refid="ref"/>
</copy>
</au:expectfailure>
</target>

</project>

Loading…
Cancel
Save