Return-Path: Delivered-To: apmail-ant-user-archive@www.apache.org Received: (qmail 57003 invoked from network); 16 Sep 2003 12:28:28 -0000 Received: from daedalus.apache.org (HELO mail.apache.org) (208.185.179.12) by minotaur-2.apache.org with SMTP; 16 Sep 2003 12:28:28 -0000 Received: (qmail 13267 invoked by uid 500); 16 Sep 2003 12:28:04 -0000 Delivered-To: apmail-ant-user-archive@ant.apache.org Received: (qmail 13118 invoked by uid 500); 16 Sep 2003 12:28:03 -0000 Mailing-List: contact user-help@ant.apache.org; run by ezmlm Precedence: bulk List-Unsubscribe: List-Subscribe: List-Help: List-Post: List-Id: "Ant Users List" Reply-To: "Ant Users List" Delivered-To: mailing list user@ant.apache.org Received: (qmail 12991 invoked from network); 16 Sep 2003 12:28:01 -0000 Received: from unknown (HELO dnsinet.rzf-nrw.de) (193.109.238.66) by daedalus.apache.org with SMTP; 16 Sep 2003 12:28:01 -0000 Received: from z011104.bk.fin.local (z011104.bk.fin.local [193.109.238.140]) by dnsinet.rzf-nrw.de (8.12.9/8.12.9) with ESMTP id h8GCRwJ9012581 for ; Tue, 16 Sep 2003 14:27:58 +0200 Received: by z011104.bk.fin.local with Internet Mail Service (5.5.2653.19) id ; Tue, 16 Sep 2003 14:28:00 +0200 Message-ID: <879A5AD5DD0ED511891F0003473A9B5608FF6FB3@Z011004> From: Jan.Materne@rzf.fin-nrw.de To: user@ant.apache.org Subject: RE: prepend file to multiple files Date: Tue, 16 Sep 2003 14:27:59 +0200 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2653.19) Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C37C4D.F732E660" X-Spam-Rating: daedalus.apache.org 1.6.2 0/1000/N X-Spam-Rating: minotaur-2.apache.org 1.6.2 0/1000/N ------_=_NextPart_001_01C37C4D.F732E660 Content-Type: text/plain; charset="iso-8859-1" Quick hack. I think I will do a little more work (test, doc) and commit that. --8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<- ------8-<----- package org.apache.tools.ant.filters; import java.io.IOException; import java.io.Reader; import java.io.File; import java.io.BufferedReader; import java.io.FileReader; import org.apache.tools.ant.types.Parameter; public final class ConcatReader extends BaseParamFilterReader implements ChainableReader { private File before; private File after; Reader beforeReader = new EmptyReader(); Reader afterReader = new EmptyReader(); public ConcatReader() { super(); } public ConcatReader(final Reader in) { super(in); } public final int read() throws IOException { if (!getInitialized()) { initialize(); setInitialized(true); } int ch = -1; ch = beforeReader.read(); if (ch == -1) { ch = super.read(); } if (ch == -1) { ch = afterReader.read(); } return ch; } public final void setBefore(final File before) { this.before = before; } public final File getBefore() { return before; } public final void setAfter(final File after) { this.after = after; } public final File getAfter() { return after; } public final Reader chain(final Reader rdr) { ConcatReader newFilter = new ConcatReader(rdr); newFilter.setBefore(getBefore()); newFilter.setAfter(getAfter()); newFilter.setInitialized(true); return newFilter; } private final void initialize() throws IOException { // get parameters Parameter[] params = getParameters(); if (params != null) { for (int i = 0; i < params.length; i++) { if ("before".equals(params[i].getName())) { before = new File(params[i].getValue()); continue; } if ("after".equals(params[i].getName())) { after = new File(params[i].getValue()); continue; } } } if (before!=null) { beforeReader = new BufferedReader(new FileReader(before)); } if (after!=null) { afterReader = new BufferedReader(new FileReader(after)); } } private class EmptyReader extends Reader { public int read(char[] ch, int i1, int i2) { return -1; } public void close() {} } } --8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<- ------8-<----- --8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<-------8-<- ------8-<----- That little test works for me. Thoughts? Jan > -----Original Message----- > From: Daniel M. Bikel [mailto:dbikel@linc.cis.upenn.edu] > Sent: Monday, September 15, 2003 6:56 PM > To: user@ant.apache.org > Subject: prepend file to multiple files > > > Hi. I need to prepend a short license description (contained > in file) to > all my source files when they are copied to the deployment > "src" directory. > Even though there have been similar posts on this list, I > cannot find a way > to do this. Put another way, I have a "src" directory which I want to > recursively copy to a "deploy/src" directory (this is easily > done using the > copy task), *but* I also want every file ending up in > deploy/src to have a > license prepended to the beginning, and I want to do this *without* > modiyfing my original source files (i.e,. I *could* modify > every one of my > existing source files to contain the line /* @LICENSE@ */, > but I don't want > to do this). > > Thanks in advance! > > --Dan. > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: user-unsubscribe@ant.apache.org > For additional commands, e-mail: user-help@ant.apache.org > ------_=_NextPart_001_01C37C4D.F732E660--