Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I use Java in an Ant buildfile?

I'm trying to write a custom scriptselector, and to do so I need to read the contents of each file.

Is there a way to use java, and not javascript, as the language of a scriptselector? If not, is there a way, silly as it sounds, to read the File object?

<scriptselector language="javascript">
    f = self.getFile();
    println(f);
    //how to read the File?
    self.setSelected(true);
</scriptselector>
like image 838
marc esher Avatar asked Dec 21 '10 18:12

marc esher


People also ask

Does Ant use Java?

Apache Ant is a software tool for automating software build processes which originated from the Apache Tomcat project in early 2000 as a replacement for the Make build tool of Unix. It is similar to Make, but is implemented using the Java language and requires the Java platform.

What is Ant tool in Java?

Ant is a Java-based build tool created as part of the Apache open-source project. You can think of it as a Java version of make. Ant scripts have a structure and are written in XML. Similar to make, Ant targets can depend on other targets. For example, Ant is used in the context of plug-in development in the build.


1 Answers

Here's how. Something along the lines of:

<scriptselector language="javascript">
    importPackage(java.io);
    importPackage(org.apache.tools.ant.util);

    fileUtils = FileUtils.getFileUtils();
    f = self.getFile();
    println(f);
    if( f.getAbsolutePath().endsWith(".xyz") ){
        fis = new FileInputStream(f.getAbsolutePath());
        isr = new InputStreamReader(fis);
        println('reading it!');
        fileContents = fileUtils.readFully(isr);
        println(fileContents);
        self.setSelected(true);
    }
</scriptselector>
like image 191
marc esher Avatar answered Oct 01 '22 07:10

marc esher