modify containsselector to function as a resourceselector; add test. alphabetize resource selectors antlib. git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@449103 13f79535-47bb-0310-9956-ffa450edef68master
| @@ -457,6 +457,8 @@ platforms. | |||||
| by a majority of nested resource selectors.</li> | by a majority of nested resource selectors.</li> | ||||
| <li><a href="selectors.html#modified">modified</a> - select resources which | <li><a href="selectors.html#modified">modified</a> - select resources which | ||||
| content has changed.</li> | content has changed.</li> | ||||
| <li><a href="selectors.html#containsselect">contains</a> - select resources | |||||
| containing a particular text string.</li> | |||||
| </ul> | </ul> | ||||
| <h4><a name="rsel.name">name</a></h4> | <h4><a name="rsel.name">name</a></h4> | ||||
| @@ -98,6 +98,10 @@ | |||||
| the files defined by that fileset to only those which contain the | the files defined by that fileset to only those which contain the | ||||
| string specified by the <code>text</code> attribute. | string specified by the <code>text</code> attribute. | ||||
| .</p> | .</p> | ||||
| <p>The <code><contains></code> selector can be used as a | |||||
| ResourceSelector (see the | |||||
| <a href="resources.html#restrict"><restrict></a> | |||||
| ResourceCollection).</p> | |||||
| <table border="1" cellpadding="2" cellspacing="0"> | <table border="1" cellpadding="2" cellspacing="0"> | ||||
| <tr> | <tr> | ||||
| @@ -676,7 +680,10 @@ | |||||
| The comparison, computing of the hashvalue and the store is done by implementation | The comparison, computing of the hashvalue and the store is done by implementation | ||||
| of special interfaces. Therefore they may provide additional parameters.</p> | of special interfaces. Therefore they may provide additional parameters.</p> | ||||
| <p>The <code><modified></code> selector can be used as ResourceSelector. | |||||
| <p>The <code><modified></code> selector can be used as a | |||||
| ResourceSelector (see the | |||||
| <a href="resources.html#restrict"><restrict></a> | |||||
| ResourceCollection). | |||||
| In that case it maps simple file resources to files and does its job. If the | In that case it maps simple file resources to files and does its job. If the | ||||
| resource is from another type, the <code><modified></code> selector tries | resource is from another type, the <code><modified></code> selector tries | ||||
| to (<b>attention!</b>) copy the content into a local file for computing the | to (<b>attention!</b>) copy the content into a local file for computing the | ||||
| @@ -1,418 +0,0 @@ | |||||
| <project default="all" | |||||
| xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <target name="testname1"> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="2"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <resource name="foo" /> | |||||
| <resource name="bar" /> | |||||
| <resource name="baz" /> | |||||
| <resource name="boo" /> | |||||
| <resource name="bang" /> | |||||
| </resources> | |||||
| <rsel:name name="ba?" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="testname2"> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="3"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <file file="foo" /> | |||||
| <resource name="foo" /> | |||||
| <file file="foo" basedir="${basedir}" /> | |||||
| </resources> | |||||
| <rsel:name name="foo" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="name" depends="testname1,testname2" /> | |||||
| <target name="testexists"> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="1"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <file file="idonotexist" /> | |||||
| <resource name="foo" /> | |||||
| <resource name="foo" exists="false" /> | |||||
| </resources> | |||||
| <rsel:exists /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="testinstanceoftype1"> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="2"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <file file="foo" /> | |||||
| <url url="http://ant.apache.org/index.html" /> | |||||
| <resource name="foo" /> | |||||
| <string value="foo" /> | |||||
| <file file="bar" /> | |||||
| </resources> | |||||
| <rsel:instanceof type="file" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="testinstanceoftype2"> | |||||
| <typedef name="file" uri="test" | |||||
| classname="org.apache.tools.ant.types.resources.FileResource" /> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="1"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <url file="foo" /> | |||||
| <file file="bar" xmlns="test" /> | |||||
| </resources> | |||||
| <rsel:instanceof type="test:file" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="testinstanceoftype3"> | |||||
| <typedef name="file" uri="test" | |||||
| classname="org.apache.tools.ant.types.resources.FileResource" /> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="1"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <url file="foo" /> | |||||
| <file file="bar" xmlns="test" /> | |||||
| </resources> | |||||
| <rsel:instanceof type="file" uri="test" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="testinstanceoftype" | |||||
| depends="testinstanceoftype1,testinstanceoftype2,testinstanceoftype3" /> | |||||
| <target name="testinstanceofclass"> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="7"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <filelist dir="${basedir}" files="a,b,c,d,e,f,g" /> | |||||
| </resources> | |||||
| <rsel:instanceof class="org.apache.tools.ant.types.Resource" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="instanceof" depends="testinstanceoftype,testinstanceofclass" /> | |||||
| <target name="testtype"> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="2"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <file file="${basedir}" /> | |||||
| <file file="${ant.file}" /> | |||||
| <resource directory="true" /> | |||||
| <resource directory="false" /> | |||||
| </resources> | |||||
| <rsel:type type="dir" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="testdate"> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="3"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <resource lastmodified="4" /> | |||||
| <resource lastmodified="5" /> | |||||
| <resource lastmodified="6" /> | |||||
| <resource lastmodified="7" /> | |||||
| <resource lastmodified="8" /> | |||||
| </resources> | |||||
| <rsel:date when="after" millis="5" granularity="0" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="testsize"> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="4"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <resource size="4" /> | |||||
| <resource size="5" /> | |||||
| <resource size="6" /> | |||||
| <resource size="7" /> | |||||
| <resource size="8" /> | |||||
| </resources> | |||||
| <rsel:size when="le" size="7" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="testand"> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="1"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <string value="fee" /> | |||||
| <resource name="fi" size="3" /> | |||||
| <resource name="fo" /> | |||||
| <resource name="fum" /> | |||||
| </resources> | |||||
| <and xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <name name="f?" /> | |||||
| <size size="3" /> | |||||
| </and> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="testor"> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="3"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <string value="fee" /> | |||||
| <resource name="fi" size="3" /> | |||||
| <resource name="fo" /> | |||||
| <resource name="fum" /> | |||||
| </resources> | |||||
| <or xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <name name="f?" /> | |||||
| <size size="3" /> | |||||
| </or> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="testnot"> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="2"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <string value="fee" /> | |||||
| <resource name="fi" size="3" /> | |||||
| <resource name="fo" /> | |||||
| <resource name="fum" /> | |||||
| </resources> | |||||
| <not xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <size size="3" /> | |||||
| </not> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="testnone"> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="1"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <string value="fee" /> | |||||
| <resource name="fi" size="3" /> | |||||
| <resource name="fo" /> | |||||
| <resource name="fum" /> | |||||
| </resources> | |||||
| <none xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <name name="f?" /> | |||||
| <size size="3" /> | |||||
| </none> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="testmajority1"> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="2"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <string value="fee" /> | |||||
| <resource name="fi" size="3" /> | |||||
| <resource name="fo" /> | |||||
| <resource name="fum" /> | |||||
| </resources> | |||||
| <majority xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <name name="f?" /> | |||||
| <size size="3" /> | |||||
| <instanceof type="string" /> | |||||
| </majority> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="testmajority2"> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="3"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <string value="fee" /> | |||||
| <resource name="fi" size="3" /> | |||||
| <resource name="fo" /> | |||||
| <resource name="fum" /> | |||||
| </resources> | |||||
| <majority xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <name name="f?" /> | |||||
| <size size="3" /> | |||||
| <instanceof type="resource" /> | |||||
| </majority> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="testmajority3"> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="3"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <string value="fee" /> | |||||
| <resource name="fi" size="3" /> | |||||
| <resource name="fo" /> | |||||
| <resource name="fum" /> | |||||
| </resources> | |||||
| <majority allowtie="true" | |||||
| xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <name name="f?" /> | |||||
| <size size="3" /> | |||||
| <instanceof type="string" /> | |||||
| <exists /> | |||||
| </majority> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="testmajority4"> | |||||
| <fail> | |||||
| <condition> | |||||
| <not> | |||||
| <resourcecount when="equal" count="2"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <string value="fee" /> | |||||
| <resource name="fi" size="3" /> | |||||
| <resource name="fo" /> | |||||
| <resource name="fum" /> | |||||
| </resources> | |||||
| <majority allowtie="false" | |||||
| xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <name name="f?" /> | |||||
| <size size="3" /> | |||||
| <instanceof type="string" /> | |||||
| <exists /> | |||||
| </majority> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </not> | |||||
| </condition> | |||||
| </fail> | |||||
| </target> | |||||
| <target name="majority" | |||||
| depends="testmajority1,testmajority2,testmajority3,testmajority4" /> | |||||
| <target name="logical" | |||||
| depends="testand,testor,testnone,testnot,majority" /> | |||||
| <target name="all" | |||||
| depends="name,testexists,instanceof,testtype,testdate,testsize,logical" /> | |||||
| <!-- | |||||
| The tests for oata.types.selectors.ModifiedSelectorTest as | |||||
| ResourceSelector are in its test-buildfile src\etc\testcases\types\selectors.xml. | |||||
| --> | |||||
| </project> | |||||
| @@ -27,14 +27,18 @@ import java.io.InputStreamReader; | |||||
| import org.apache.tools.ant.BuildException; | import org.apache.tools.ant.BuildException; | ||||
| import org.apache.tools.ant.Project; | import org.apache.tools.ant.Project; | ||||
| import org.apache.tools.ant.types.Parameter; | import org.apache.tools.ant.types.Parameter; | ||||
| import org.apache.tools.ant.types.Resource; | |||||
| import org.apache.tools.ant.types.resources.FileResource; | |||||
| import org.apache.tools.ant.types.resources.selectors.ResourceSelector; | |||||
| import org.apache.tools.ant.util.FileUtils; | |||||
| /** | /** | ||||
| * Selector that filters files based on whether they contain a | |||||
| * Selector that filters files/resources based on whether they contain a | |||||
| * particular string. | * particular string. | ||||
| * | * | ||||
| * @since 1.5 | * @since 1.5 | ||||
| */ | */ | ||||
| public class ContainsSelector extends BaseExtendSelector { | |||||
| public class ContainsSelector extends BaseExtendSelector implements ResourceSelector { | |||||
| private String contains = null; | private String contains = null; | ||||
| private boolean casesensitive = true; | private boolean casesensitive = true; | ||||
| @@ -61,19 +65,11 @@ public class ContainsSelector extends BaseExtendSelector { | |||||
| */ | */ | ||||
| public String toString() { | public String toString() { | ||||
| StringBuffer buf = new StringBuffer("{containsselector text: "); | StringBuffer buf = new StringBuffer("{containsselector text: "); | ||||
| buf.append(contains); | |||||
| buf.append('"').append(contains).append('"'); | |||||
| buf.append(" casesensitive: "); | buf.append(" casesensitive: "); | ||||
| if (casesensitive) { | |||||
| buf.append("true"); | |||||
| } else { | |||||
| buf.append("false"); | |||||
| } | |||||
| buf.append(casesensitive ? "true" : "false"); | |||||
| buf.append(" ignorewhitespace: "); | buf.append(" ignorewhitespace: "); | ||||
| if (ignorewhitespace) { | |||||
| buf.append("true"); | |||||
| } else { | |||||
| buf.append("false"); | |||||
| } | |||||
| buf.append(ignorewhitespace ? "true" : "false"); | |||||
| buf.append("}"); | buf.append("}"); | ||||
| return buf.toString(); | return buf.toString(); | ||||
| } | } | ||||
| @@ -153,11 +149,22 @@ public class ContainsSelector extends BaseExtendSelector { | |||||
| * @return whether the file should be selected or not | * @return whether the file should be selected or not | ||||
| */ | */ | ||||
| public boolean isSelected(File basedir, String filename, File file) { | public boolean isSelected(File basedir, String filename, File file) { | ||||
| return isSelected(new FileResource(file)); | |||||
| } | |||||
| /** | |||||
| * The heart of the matter. This is where the selector gets to decide | |||||
| * on the inclusion of a Resource. | |||||
| * | |||||
| * @param r the Resource to check. | |||||
| * @return whether the Resource is selected. | |||||
| */ | |||||
| public boolean isSelected(Resource r) { | |||||
| // throw BuildException on error | // throw BuildException on error | ||||
| validate(); | validate(); | ||||
| if (file.isDirectory()) { | |||||
| if (r.isDirectory()) { | |||||
| return true; | return true; | ||||
| } | } | ||||
| @@ -170,8 +177,12 @@ public class ContainsSelector extends BaseExtendSelector { | |||||
| } | } | ||||
| BufferedReader in = null; | BufferedReader in = null; | ||||
| try { | try { | ||||
| in = new BufferedReader(new InputStreamReader( | |||||
| new FileInputStream(file))); | |||||
| in = new BufferedReader(new InputStreamReader(r.getInputStream())); | |||||
| } catch (Exception e) { | |||||
| throw new BuildException("Could not get InputStream from " | |||||
| + r.toLongString(), e); | |||||
| } | |||||
| try { | |||||
| String teststr = in.readLine(); | String teststr = in.readLine(); | ||||
| while (teststr != null) { | while (teststr != null) { | ||||
| if (!casesensitive) { | if (!casesensitive) { | ||||
| @@ -187,16 +198,9 @@ public class ContainsSelector extends BaseExtendSelector { | |||||
| } | } | ||||
| return false; | return false; | ||||
| } catch (IOException ioe) { | } catch (IOException ioe) { | ||||
| throw new BuildException("Could not read file " + filename); | |||||
| throw new BuildException("Could not read " + r.toLongString()); | |||||
| } finally { | } finally { | ||||
| if (in != null) { | |||||
| try { | |||||
| in.close(); | |||||
| } catch (Exception e) { | |||||
| throw new BuildException("Could not close file " | |||||
| + filename); | |||||
| } | |||||
| } | |||||
| FileUtils.close(in); | |||||
| } | } | ||||
| } | } | ||||
| @@ -1,26 +1,28 @@ | |||||
| <antlib> | <antlib> | ||||
| <typedef name="name" | |||||
| classname="org.apache.tools.ant.types.resources.selectors.Name" /> | |||||
| <typedef name="not" | |||||
| classname="org.apache.tools.ant.types.resources.selectors.Not" /> | |||||
| <typedef name="none" | |||||
| classname="org.apache.tools.ant.types.resources.selectors.None" /> | |||||
| <typedef name="and" | <typedef name="and" | ||||
| classname="org.apache.tools.ant.types.resources.selectors.And" /> | classname="org.apache.tools.ant.types.resources.selectors.And" /> | ||||
| <typedef name="or" | |||||
| classname="org.apache.tools.ant.types.resources.selectors.Or" /> | |||||
| <typedef name="contains" | |||||
| classname="org.apache.tools.ant.types.selectors.ContainsSelector" /> | |||||
| <typedef name="date" | |||||
| classname="org.apache.tools.ant.types.resources.selectors.Date" /> | |||||
| <typedef name="exists" | <typedef name="exists" | ||||
| classname="org.apache.tools.ant.types.resources.selectors.Exists" /> | classname="org.apache.tools.ant.types.resources.selectors.Exists" /> | ||||
| <typedef name="type" | |||||
| classname="org.apache.tools.ant.types.resources.selectors.Type" /> | |||||
| <typedef name="majority" | |||||
| classname="org.apache.tools.ant.types.resources.selectors.Majority" /> | |||||
| <typedef name="instanceof" | <typedef name="instanceof" | ||||
| classname="org.apache.tools.ant.types.resources.selectors.InstanceOf" /> | classname="org.apache.tools.ant.types.resources.selectors.InstanceOf" /> | ||||
| <typedef name="size" | |||||
| classname="org.apache.tools.ant.types.resources.selectors.Size" /> | |||||
| <typedef name="date" | |||||
| classname="org.apache.tools.ant.types.resources.selectors.Date" /> | |||||
| <typedef name="majority" | |||||
| classname="org.apache.tools.ant.types.resources.selectors.Majority" /> | |||||
| <typedef name="modified" | <typedef name="modified" | ||||
| classname="org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector" /> | classname="org.apache.tools.ant.types.selectors.modifiedselector.ModifiedSelector" /> | ||||
| <typedef name="name" | |||||
| classname="org.apache.tools.ant.types.resources.selectors.Name" /> | |||||
| <typedef name="none" | |||||
| classname="org.apache.tools.ant.types.resources.selectors.None" /> | |||||
| <typedef name="not" | |||||
| classname="org.apache.tools.ant.types.resources.selectors.Not" /> | |||||
| <typedef name="or" | |||||
| classname="org.apache.tools.ant.types.resources.selectors.Or" /> | |||||
| <typedef name="size" | |||||
| classname="org.apache.tools.ant.types.resources.selectors.Size" /> | |||||
| <typedef name="type" | |||||
| classname="org.apache.tools.ant.types.resources.selectors.Type" /> | |||||
| </antlib> | </antlib> | ||||
| @@ -0,0 +1,362 @@ | |||||
| <project default="all" xmlns:au="antlib:org.apache.ant.antunit" | |||||
| xmlns:rsel="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <target name="testname1"> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="2"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <resource name="foo" /> | |||||
| <resource name="bar" /> | |||||
| <resource name="baz" /> | |||||
| <resource name="boo" /> | |||||
| <resource name="bang" /> | |||||
| </resources> | |||||
| <rsel:name name="ba?" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="testname2"> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="3"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <file file="foo" /> | |||||
| <resource name="foo" /> | |||||
| <file file="foo" basedir="${basedir}" /> | |||||
| </resources> | |||||
| <rsel:name name="foo" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="name" depends="testname1,testname2" /> | |||||
| <target name="testexists"> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="1"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <file file="idonotexist" /> | |||||
| <resource name="foo" /> | |||||
| <resource name="foo" exists="false" /> | |||||
| </resources> | |||||
| <rsel:exists /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="testinstanceoftype1"> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="2"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <file file="foo" /> | |||||
| <url url="http://ant.apache.org/index.html" /> | |||||
| <resource name="foo" /> | |||||
| <string value="foo" /> | |||||
| <file file="bar" /> | |||||
| </resources> | |||||
| <rsel:instanceof type="file" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="testinstanceoftype2"> | |||||
| <typedef name="file" uri="test" | |||||
| classname="org.apache.tools.ant.types.resources.FileResource" /> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="1"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <url file="foo" /> | |||||
| <file file="bar" xmlns="test" /> | |||||
| </resources> | |||||
| <rsel:instanceof type="test:file" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="testinstanceoftype3"> | |||||
| <typedef name="file" uri="test" | |||||
| classname="org.apache.tools.ant.types.resources.FileResource" /> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="1"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <url file="foo" /> | |||||
| <file file="bar" xmlns="test" /> | |||||
| </resources> | |||||
| <rsel:instanceof type="file" uri="test" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="testinstanceoftype" | |||||
| depends="testinstanceoftype1,testinstanceoftype2,testinstanceoftype3" /> | |||||
| <target name="testinstanceofclass"> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="7"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <filelist dir="${basedir}" files="a,b,c,d,e,f,g" /> | |||||
| </resources> | |||||
| <rsel:instanceof class="org.apache.tools.ant.types.Resource" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="instanceof" depends="testinstanceoftype,testinstanceofclass" /> | |||||
| <target name="testtype"> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="2"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <file file="${basedir}" /> | |||||
| <file file="${ant.file}" /> | |||||
| <resource directory="true" /> | |||||
| <resource directory="false" /> | |||||
| </resources> | |||||
| <rsel:type type="dir" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="testdate"> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="3"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <resource lastmodified="4" /> | |||||
| <resource lastmodified="5" /> | |||||
| <resource lastmodified="6" /> | |||||
| <resource lastmodified="7" /> | |||||
| <resource lastmodified="8" /> | |||||
| </resources> | |||||
| <rsel:date when="after" millis="5" granularity="0" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="testsize"> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="4"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <resource size="4" /> | |||||
| <resource size="5" /> | |||||
| <resource size="6" /> | |||||
| <resource size="7" /> | |||||
| <resource size="8" /> | |||||
| </resources> | |||||
| <rsel:size when="le" size="7" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="testand"> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="1"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <string value="fee" /> | |||||
| <resource name="fi" size="3" /> | |||||
| <resource name="fo" /> | |||||
| <resource name="fum" /> | |||||
| </resources> | |||||
| <and xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <name name="f?" /> | |||||
| <size size="3" /> | |||||
| </and> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="testor"> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="3"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <string value="fee" /> | |||||
| <resource name="fi" size="3" /> | |||||
| <resource name="fo" /> | |||||
| <resource name="fum" /> | |||||
| </resources> | |||||
| <or xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <name name="f?" /> | |||||
| <size size="3" /> | |||||
| </or> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="testnot"> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="2"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <string value="fee" /> | |||||
| <resource name="fi" size="3" /> | |||||
| <resource name="fo" /> | |||||
| <resource name="fum" /> | |||||
| </resources> | |||||
| <not xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <size size="3" /> | |||||
| </not> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="testnone"> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="1"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <string value="fee" /> | |||||
| <resource name="fi" size="3" /> | |||||
| <resource name="fo" /> | |||||
| <resource name="fum" /> | |||||
| </resources> | |||||
| <none xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <name name="f?" /> | |||||
| <size size="3" /> | |||||
| </none> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="testmajority1"> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="2"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <string value="fee" /> | |||||
| <resource name="fi" size="3" /> | |||||
| <resource name="fo" /> | |||||
| <resource name="fum" /> | |||||
| </resources> | |||||
| <majority xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <name name="f?" /> | |||||
| <size size="3" /> | |||||
| <instanceof type="string" /> | |||||
| </majority> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="testmajority2"> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="3"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <string value="fee" /> | |||||
| <resource name="fi" size="3" /> | |||||
| <resource name="fo" /> | |||||
| <resource name="fum" /> | |||||
| </resources> | |||||
| <majority xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <name name="f?" /> | |||||
| <size size="3" /> | |||||
| <instanceof type="resource" /> | |||||
| </majority> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="testmajority3"> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="3"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <string value="fee" /> | |||||
| <resource name="fi" size="3" /> | |||||
| <resource name="fo" /> | |||||
| <resource name="fum" /> | |||||
| </resources> | |||||
| <majority allowtie="true" | |||||
| xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <name name="f?" /> | |||||
| <size size="3" /> | |||||
| <instanceof type="string" /> | |||||
| <exists /> | |||||
| </majority> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="testmajority4"> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="2"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <string value="fee" /> | |||||
| <resource name="fi" size="3" /> | |||||
| <resource name="fo" /> | |||||
| <resource name="fum" /> | |||||
| </resources> | |||||
| <majority allowtie="false" | |||||
| xmlns="antlib:org.apache.tools.ant.types.resources.selectors"> | |||||
| <name name="f?" /> | |||||
| <size size="3" /> | |||||
| <instanceof type="string" /> | |||||
| <exists /> | |||||
| </majority> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="testcontains"> | |||||
| <au:assertTrue> | |||||
| <resourcecount when="equal" count="2"> | |||||
| <restrict> | |||||
| <resources> | |||||
| <string value="foo" /> | |||||
| <string value="bar" /> | |||||
| <string value="baz" /> | |||||
| </resources> | |||||
| <contains text="b" | |||||
| xmlns="antlib:org.apache.tools.ant.types.resources.selectors" /> | |||||
| </restrict> | |||||
| </resourcecount> | |||||
| </au:assertTrue> | |||||
| </target> | |||||
| <target name="majority" | |||||
| depends="testmajority1,testmajority2,testmajority3,testmajority4" /> | |||||
| <target name="logical" | |||||
| depends="testand,testor,testnone,testnot,majority" /> | |||||
| <target name="all" | |||||
| depends="name,testexists,instanceof,testtype,testdate,testsize,testcontains,logical" /> | |||||
| <!-- | |||||
| The tests for oata.types.selectors.ModifiedSelectorTest as | |||||
| ResourceSelector are in its test-buildfile src\etc\testcases\types\selectors.xml. | |||||
| --> | |||||
| </project> | |||||
| @@ -1,101 +0,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.BuildFileTest; | |||||
| public class ResourceSelectorsTest extends BuildFileTest { | |||||
| public ResourceSelectorsTest(String name) { | |||||
| super(name); | |||||
| } | |||||
| public void setUp() { | |||||
| configureProject("src/etc/testcases/types/resources/selectors/build.xml"); | |||||
| } | |||||
| public void testname1() { | |||||
| executeTarget("testname1"); | |||||
| } | |||||
| public void testname2() { | |||||
| executeTarget("testname2"); | |||||
| } | |||||
| public void testexists() { | |||||
| executeTarget("testexists"); | |||||
| } | |||||
| public void testinstanceoftype1() { | |||||
| executeTarget("testinstanceoftype1"); | |||||
| } | |||||
| public void testinstanceoftype2() { | |||||
| executeTarget("testinstanceoftype2"); | |||||
| } | |||||
| public void testinstanceofclass() { | |||||
| executeTarget("testinstanceofclass"); | |||||
| } | |||||
| public void testtype() { | |||||
| executeTarget("testtype"); | |||||
| } | |||||
| public void testdate() { | |||||
| executeTarget("testdate"); | |||||
| } | |||||
| public void testsize() { | |||||
| executeTarget("testsize"); | |||||
| } | |||||
| public void testand() { | |||||
| executeTarget("testand"); | |||||
| } | |||||
| public void testor() { | |||||
| executeTarget("testor"); | |||||
| } | |||||
| public void testnot() { | |||||
| executeTarget("testnot"); | |||||
| } | |||||
| public void testnone() { | |||||
| executeTarget("testnone"); | |||||
| } | |||||
| public void testmajority1() { | |||||
| executeTarget("testmajority1"); | |||||
| } | |||||
| public void testmajority2() { | |||||
| executeTarget("testmajority2"); | |||||
| } | |||||
| public void testmajority3() { | |||||
| executeTarget("testmajority3"); | |||||
| } | |||||
| public void testmajority4() { | |||||
| executeTarget("testmajority4"); | |||||
| } | |||||
| } | |||||