You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by oleg shteynbuk <os...@nyc.rr.com> on 2004/08/03 19:40:59 UTC

Using Ant Tasks Outside of Ant

Hi,

Recently I have used Ant from Java for the first time and Ant docs 
chapter "Using Ant Tasks Outside of Ant" was very helpful, but it might 
well be that this chapter was written long time ago as in the source 
code there is a notice that use of protected members is deprecated and 
you should not be accessing this variables directly use access methods 
instead, and if protected members are not accessed directly you don't 
need derived nested class. Then code sample in docs could look like this:

    static public Project createProject() {
        Project project = new Project();
        project.init();
        return project;
    }

    static public void unzip(String zipFilepath, String destinationDir) {

        Expand expander = new Expand();
        expander.setProject(createProject());
        expander.setTaskType("unzip");
        expander.setTaskName("unzip");
        expander.setOwningTarget(new Target());

        expander.setSrc(new File(zipFilepath));
        expander.setDest(new File(destinationDir));
        expander.execute();

    }

two lines
        Project project = new Project();
        project.init();
       
were refactored into createProject() function as in my case it is used 
for several tasks but for code sample it could be inlined into unzip() 
function.

Also i have spend some time looking for mapping of Java classes to 
corresponding Ant tasks and maybe adding to docs sentence like this 
"Java classes could have different names from the corresponding Ant 
tasks, look at the org/apache/tools/ant/taskdefs/defaults.properties 
file for mapping" could help first time users.

I'm just curious if other folks think that it could be useful.


Oleg


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