Return-Path: Delivered-To: apmail-jakarta-ant-user-archive@jakarta.apache.org Received: (qmail 62205 invoked by uid 500); 3 May 2001 17:36:48 -0000 Mailing-List: contact ant-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: Reply-To: ant-user@jakarta.apache.org Delivered-To: mailing list ant-user@jakarta.apache.org Received: (qmail 62155 invoked from network); 3 May 2001 17:36:39 -0000 Message-ID: From: Aarti Chandnani To: "'ant-user@jakarta.apache.org'" Subject: SetManifestProperty Task Date: Thu, 3 May 2001 10:35:10 -0700 MIME-Version: 1.0 X-Mailer: Internet Mail Service (5.5.2650.21) Content-Type: multipart/mixed; boundary="----_=_NextPart_000_01C0D3F7.66BFE9D0" X-Spam-Rating: h31.sny.collab.net 1.6.2 0/1000/N This message is in MIME format. Since your mail reader does not understand this format, some or all of this message may not be legible. ------_=_NextPart_000_01C0D3F7.66BFE9D0 Content-Type: multipart/alternative; boundary="----_=_NextPart_001_01C0D3F7.66BFE9D0" ------_=_NextPart_001_01C0D3F7.66BFE9D0 Content-Type: text/plain; charset="iso-8859-1" Hi, I have written a task called SetManifestProperty. I thought I will pass it on, and anyone who needs it can use it! This is something what i needed, I wonder if anyone out there needs it too... Anyways what this task does is: It is used to set the attribute value of an entry in the Manifest file. there are 3 attributes: viz filename,property & value All attributes are required. Example: If you have a file called Manifest.mf which looks like this: Manifest-Version: 1.1 Package-Version: 2.1 ...............etc and now you run the result will be Manifest-Version: 1.1 Package-Version: NIGHTLY ..................etc Thus you can change any value of any entry in the Manifest file and then use it to make your jar! <> -Aarti ------_=_NextPart_001_01C0D3F7.66BFE9D0 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable SetManifestProperty Task

Hi,

I have written a task called = SetManifestProperty.
I thought I will pass it on, and = anyone who needs it can use it!

This is something what i needed, I = wonder if anyone out there needs it too...
Anyways what this task does = is:

It is used to set the attribute value = of an entry in the Manifest file.
 there are 3 attributes:
 viz filename,property & = value
 All attributes are = required.
 Example:
 If you have a file called = Manifest.mf
 which looks like this:

   Manifest-Version: = 1.1
   Package-Version: = 2.1
   = ...............etc

 and now you run

   <SetManifestProperty = filename=3D"Manifest.mf" = property=3D"Package-Version" = value=3D"NIGHTLY"/>

   the result will be
   Manifest-Version: = 1.1
   Package-Version: = NIGHTLY
   = ..................etc
 
 Thus you can change any value = of any entry in the Manifest file and then use it to make your jar! =

= <<SetManifestProperty.java>>

-Aarti

------_=_NextPart_001_01C0D3F7.66BFE9D0-- ------_=_NextPart_000_01C0D3F7.66BFE9D0 Content-Type: application/octet-stream; name="SetManifestProperty.java" Content-Disposition: attachment; filename="SetManifestProperty.java" /** This is used to set the attribute value of an entry in the Manifest file. * there are 3 attributes: * viz filename,property & value * All attributes are required. * Example: * If you have a file called Manifest.mf * which looks like this: * Manifest-Version: 1.1 * Package-Version: 2.1 * ...............etc * and now you run * * the result will be * Manifest-Version: 1.1 * Package-Version: NIGHTLY * ..................etc * @author Aarti Chandnani achandnani@xuma.com * 02 May 2001 **/ package org.apache.tools.ant.taskdefs.optional; import org.apache.tools.ant.*; import java.util.jar.*; import java.io.*; import java.util.*; public class SetManifestProperty extends Task { private String filename; private String property; private String value; /** * Sets the filename attribute. */ public void setFilename(String filename) { this.filename = filename; }//setFilename /** * Sets the property attribute **/ public void setProperty(String property) { this.property = property; }//setProperty /** * Sets the value attribute **/ public void setValue(String value) { this.value = value; }//setValue /** * Does the work. * * @exception BuildException if someting goes wrong with the build */ public void execute() throws BuildException { try { FileInputStream fi = new FileInputStream(filename); Manifest man = new Manifest(fi); Attributes at = new Attributes(man.getMainAttributes()); at.putValue(property,value); fi.close(); Set se = at.entrySet(); Iterator it = se.iterator(); int i =0; while(it.hasNext()) { String old = new String(it.next().toString()); String newone = new String(old.replace('=',':')); StringBuffer sub = new StringBuffer(newone); sub = sub.insert(newone.indexOf(':')+1," "); newone = new String(sub); if(i==0) write(filename,newone); else append(filename,newone); i++; }//while }//try catch (Exception e) { System.out.println("caught exception " + e); throw new BuildException(e); }//catch }//execute private void write(String filename,String s) throws Exception { PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(filename))); out.print(s.trim() + "\n"); out.close(); }//write private void append(String filename,String s) throws Exception { PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter(filename,true))); out.println(s); out.close(); }//append }//class ------_=_NextPart_000_01C0D3F7.66BFE9D0--