ant-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Dominique Devienne <DDevie...@lgc.com>
Subject RE: Accessing manifest information from within an ant build
Date Tue, 26 Nov 2002 16:52:24 GMT
I think this should answer your question ;-) --DD

PS: My longest and most complex JavaScript ever ;-)

P:\org_apache\antx>%ANT_HOME%\bin\ant -f jar-version-script.xml
Buildfile: jar-version-script.xml

test:
   [script] C:\pro\jdk1.4\jre\lib\charsets.jar <not-found>
   [script] C:\pro\jdk1.4\jre\lib\jaws.jar <not-found>
   [script] C:\pro\jdk1.4\jre\lib\jce.jar <not-found>
   [script] C:\pro\jdk1.4\jre\lib\jsse.jar 1.4
   [script] C:\pro\jdk1.4\jre\lib\rt.jar 1.4.0
   [script] C:\pro\jdk1.4\jre\lib\sunrsasign.jar <not-found>

BUILD SUCCESSFUL
Total time: 1 second
P:\org_apache\antx>type jar-version-script.xml
<?xml version="1.0"?>

<!-- ANT build file to test a specific feature or bug of ANT.
     Dominique Devienne <ddevienne@lgc.com>     November 2002
  -->
<project name="jar-version" default="test">

  <target name="test">
    <fileset id="jars" dir="${java.home}/lib" includes="*.jar" />

    <!-- Iterate over the fileset, printing the filenames.
         Then attempt to open each file as a JAR, and read its manifest
         to extract the specification version, if any. -->
    <script language="javascript"><![CDATA[
      prj = self.getProject();
      jars = prj.getReference("jars");
      dir = new java.io.File(jars.getDir(prj));
      filenames = jars.getDirectoryScanner(prj).getIncludedFiles();
      for (var i = 0; i < filenames.length; ++i) {
        file = new java.io.File(dir, filenames[i]);
        jar = new java.util.jar.JarFile(file);
        name = java.util.jar.Attributes.Name.IMPLEMENTATION_VERSION;
        version = jar.getManifest().getMainAttributes().getValue(name);
        version = (version == null)? "<not-found>": version;
        java.lang.System.out.println(file + " " + version);
      }
    ]]></script>
  </target>

</project>

P:\org_apache\antx>

-----Original Message-----
From: Frank Carver [mailto:frank@efsol.com] 
Sent: Saturday, November 23, 2002 2:47 AM
To: Ant Users List
Subject: RE: Accessing manifest information from within an ant build


Dominique Devienne <DDevienne@lgc.com> said:

> I don't think so. Not directly. I'd define a fileset of your JARs, and
write
> a small JavaScript to look over it, and use JDK's
>
> import java.util.jar.*;
> new JarFile(filename).getManifest().getMainAttributes().getValue(
>   Attributes.Name.IMPLEMENTATATION_VERSION);
>
> Almost a one liner ;-) --DD

That looks neat.  Can you expand a little on the "look over it" part.  I
don't
know to get the filenames out of a fileset like that, and a variation on
this
approach would be a great solution for a couple other problems which have
popped
up on this list over the last few weeks.

--
To unsubscribe, e-mail:   <mailto:ant-user-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:ant-user-help@jakarta.apache.org>


Mime
View raw message