<target name="run_java">
<java classname="input">
<arg value="input.txt"/>
<arg value="subst.sed"/>
<arg value="output.txt"/>
<classpath>
<pathelement location="."/>
<pathelement path="${java.class.path}"/>
</classpath>
</java>
</target>
Here is the source for input.javaimport java.lang.*;import java.io.*;public
class input{ public static void main(String args[]) { BufferedWriter
writer=null; try { String
replacement_strings[]={"<string>foo.jar</string>","<string>bar.jar</string>"
}; String input_file = null; String subst_file=null;
String output_file=null; try { input_file =
(args[0]!=null) ? args[0] : "input_file.txt"; subst_file =
(args[1]!=null) ? args[1] : "subst.sed"; output_file =
(args[2]!=null) ? args[2] : "output_file.txt"; }
catch(ArrayIndexOutOfBoundsException ioe) { System.out.println("USAGE
java input NameOfInputFile NameOfsubstFile NameOfOutputFile");
System.exit(0); } BufferedReader reader = new BufferedReader(new
FileReader(input_file)); BufferedReader sed_reader = new BufferedReader(new
FileReader(subst_file)); writer = new BufferedWriter(new
FileWriter(output_file)); for(int i=0; i<2; i++) { String buff =
reader.readLine(); int last_char = buff.length(); String sed_buff =
sed_reader.readLine(); try { if(buff.length() == 0) {
System.out.println("There is no data in the input file aborting");
System.exit(0); } } catch(NullPointerException npe) {
System.out.println("There is nothing in the input file aborting");
System.exit(0); } int place_holder = buff.indexOf("@REPLACEME@");
String before = new String(buff.getBytes(),0,place_holder); int start =
place_holder; int len = buff.length()-place_holder; int offset =
last_char-(place_holder+new String("@REPLACEME@").length()); String after
= new String(buff.getBytes(),len,offset); StringBuffer string_to_write=new
StringBuffer(before); if(place_holder!= -1) {
string_to_write.append(sed_buff); string_to_write.append(after); }
//write it out... writer.write(new String(string_to_write),0,new
String(string_to_write).length()); writer.write("\n"); }
writer.close(); } //end try.. catch(java.io.IOException ioe)
{ System.out.println("IOException thrown message =
oe.getMessage()); } }}----- Original Message -----
From: "Paul J. Lucas" <[EMAIL PROTECTED]>
To: "Martin Gainty" <[EMAIL PROTECTED]>
Sent: Wednesday, February 20, 2008 5:05 PM
Subject: Re: Filter on copy with directory contents
> 1. I was looking for an all-ant solution. I know how to do it with
> other tools.
>
> 2. Your solution doesn't solve my problem. As I originally stated, I
> want to replace @REPLACEME@ with the entire contents of a directory.
> There is exactly one @REPLACEME@ in the original file. There are
> *not* @REPLACEME1@, @REPLACEME2@, etc. How can I know how many files
> are in the directory in advance? Your solution requires one
> @REPLACEMEn@ for each file.
>
> - Paul
>
>
> On Feb 20, 2008, at 1:55 PM, Martin Gainty wrote:
>
> > Paul-
> >
> > you can with sed
> >
> > input.txt contents:
> > @REPLACEME1@
> > @REPLACEME2@
> >
> > subst.sed contents:
> > s/@REPLACEME1@/foo.jar/g
> > s/@REPLACEME2@/bar.jar/g
> >
> > sed -f subst.sed input.txt > output.txt
> >
> > cat output.txt
> > foo.jar
> > bar.jar
> >
> > wrap it into an ant exec and you're all set.
>
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]