You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@ant.apache.org by Patrick Aikens <pa...@gmail.com> on 2008/04/08 23:27:52 UTC

Custom Selectors

I'm trying to write a custom selector.  It works fine, except that
isSelected is never called.  This is using 1.6.5, with the .jar for
the selector in ant's lib directory and the jar contains an
antlib.xml.  Here's the pared down version.
Yes, isSelected is set to throw an exception if it's ever called - I
figure that's good enough until I can get it working.  The build file
used below runs successfully.  I see the "Foop!test.file" when I run
ant so it's instantiating my class and parsing the antlib just fine,
but no exception is thrown.

build file:
-----------
<?xml version="1.0" ?>
<project name="anttest" xmlns:test="antlib:test.anttask">
  <dirset dir="${basedir}">
    <test:containsfile file="test.file"/>
  </dirset>
</project>

Source:
----------
package test.anttask;

import java.io.File;
import org.apache.tools.ant.BuildException;
import org.apache.tools.ant.types.selectors.BaseExtendSelector;

public class ContainsFileSelector extends BaseExtendSelector {
    private String file;
    public void setFile(String s) {
        System.out.println("Foop!" + s);
        file = s;
    }

    @Override
    public boolean isSelected(File basedir, String filename, File
checkFile) throws BuildException {
        throw new BuildException("Yep, at least we're selecting");
    }
}


-- 
SELECT * FROM users WHERE clue > 0

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Custom Selectors

Posted by Patrick Aikens <pa...@gmail.com>.
You know, that makes sense *smacks head*.  I put it on the back burner 
today, but I'll try it in the morning.  Thanks!

Bruce Atherton wrote:
> The reason is that you have only defined your sets of directories. They 
> aren't resolved until you use them. Try doing something with the dirset 
> and see if you get your exception. I used:
> 
> <?xml version="1.0" ?>
> <project name="anttest">
>  <copy todir="/tmp" >
>    <fileset dir="." >
>        <custom classname="test.anttask.ContainsFileSelector" 
> classpath="." >
>          <param name="file" value="test.file"/>
>        </custom>
>    </fileset>
>  </copy>
> </project>
> 
> and got:
> 
> Buildfile: build.xml
> 
> BUILD FAILED
> /sandbox/test/ant/build.xml:3: Yep, at least we're selecting
> 
> Total time: 0 seconds
> 
> 
> Patrick Aikens wrote:
>> I'm trying to write a custom selector.  It works fine, except that
>> isSelected is never called.  This is using 1.6.5, with the .jar for
>> the selector in ant's lib directory and the jar contains an
>> antlib.xml.  Here's the pared down version.
>> Yes, isSelected is set to throw an exception if it's ever called - I
>> figure that's good enough until I can get it working.  The build file
>> used below runs successfully.  I see the "Foop!test.file" when I run
>> ant so it's instantiating my class and parsing the antlib just fine,
>> but no exception is thrown.
>>
>> build file:
>> -----------
>> <?xml version="1.0" ?>
>> <project name="anttest" xmlns:test="antlib:test.anttask">
>>   <dirset dir="${basedir}">
>>     <test:containsfile file="test.file"/>
>>   </dirset>
>> </project>
>>
>> Source:
>> ----------
>> package test.anttask;
>>
>> import java.io.File;
>> import org.apache.tools.ant.BuildException;
>> import org.apache.tools.ant.types.selectors.BaseExtendSelector;
>>
>> public class ContainsFileSelector extends BaseExtendSelector {
>>     private String file;
>>     public void setFile(String s) {
>>         System.out.println("Foop!" + s);
>>         file = s;
>>     }
>>
>>     @Override
>>     public boolean isSelected(File basedir, String filename, File
>> checkFile) throws BuildException {
>>         throw new BuildException("Yep, at least we're selecting");
>>     }
>> }
>>
>>
>>   
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
> For additional commands, e-mail: user-help@ant.apache.org
> 


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org


Re: Custom Selectors

Posted by Bruce Atherton <br...@callenish.com>.
The reason is that you have only defined your sets of directories. They 
aren't resolved until you use them. Try doing something with the dirset 
and see if you get your exception. I used:

<?xml version="1.0" ?>
<project name="anttest">
  <copy todir="/tmp" >
    <fileset dir="." >
        <custom classname="test.anttask.ContainsFileSelector" 
classpath="." >
          <param name="file" value="test.file"/>
        </custom>
    </fileset>
  </copy>
</project>

and got:

Buildfile: build.xml

BUILD FAILED
/sandbox/test/ant/build.xml:3: Yep, at least we're selecting

Total time: 0 seconds


Patrick Aikens wrote:
> I'm trying to write a custom selector.  It works fine, except that
> isSelected is never called.  This is using 1.6.5, with the .jar for
> the selector in ant's lib directory and the jar contains an
> antlib.xml.  Here's the pared down version.
> Yes, isSelected is set to throw an exception if it's ever called - I
> figure that's good enough until I can get it working.  The build file
> used below runs successfully.  I see the "Foop!test.file" when I run
> ant so it's instantiating my class and parsing the antlib just fine,
> but no exception is thrown.
>
> build file:
> -----------
> <?xml version="1.0" ?>
> <project name="anttest" xmlns:test="antlib:test.anttask">
>   <dirset dir="${basedir}">
>     <test:containsfile file="test.file"/>
>   </dirset>
> </project>
>
> Source:
> ----------
> package test.anttask;
>
> import java.io.File;
> import org.apache.tools.ant.BuildException;
> import org.apache.tools.ant.types.selectors.BaseExtendSelector;
>
> public class ContainsFileSelector extends BaseExtendSelector {
>     private String file;
>     public void setFile(String s) {
>         System.out.println("Foop!" + s);
>         file = s;
>     }
>
>     @Override
>     public boolean isSelected(File basedir, String filename, File
> checkFile) throws BuildException {
>         throw new BuildException("Yep, at least we're selecting");
>     }
> }
>
>
>   


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@ant.apache.org
For additional commands, e-mail: user-help@ant.apache.org