Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Text manipulation in ant

Tags:

ant

Given an ant fileset, I need to perform some sed-like manipulations on it, condense it to a multi-line string (with effectively one line per file), and output the result to a text file.

What ant task am I looking for?

like image 792
skiphoppy Avatar asked Jan 23 '23 04:01

skiphoppy


2 Answers

The Ant script task allows you to implement a task in a scripting language. If you have JDK 1.6 installed, Ant can execute JavaScript without needing any additional dependent libraries. The JavaScript code can read a fileset, transform the file names, and write them to a file.

  <fileset id="jars" dir="${lib.dir}">
    <include name="*.jar"/>
  </fileset>

  <target name="init">
    <script language="javascript"><![CDATA[
        var out = new java.io.PrintWriter(new java.io.FileWriter('jars.txt'));

        var iJar = project.getReference('jars').iterator();
        while (iJar.hasNext()) {
            var jar = new String(iJar.next());
            out.println(jar);
        }

        out.close();
    ]]></script>
  </target>
like image 73
Chin Huang Avatar answered Apr 21 '23 06:04

Chin Huang


Try the ReplaceRegExp optional task.

ReplaceRegExp is a directory based task for replacing the occurrence of a given regular expression with a substitution pattern in a selected file or set of files.

There are a few examples near the bottom of the page to get you started.

like image 31
Rich Seller Avatar answered Apr 21 '23 06:04

Rich Seller