Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Automate adding multiple "sections" to the manifest?

Tags:

java

manifest

ant

I'm using ant to generate the MANIFEST.MF for a .jar, and I need to add multiple manifest <section> blocks based on a list of files in a directory. However, I need to automate the process to do this at build-time since the list will change between development and deployment.

For example:

<manifest file="MANIFEST.MF">
  <foreach files="./*">
    <section name="section">
      <attribute name="Attribute-Name" value="$file"/>
    </section>
  </foreach>
</manifest>

I've looked at foreach from Ant-contrib but it doesn't look like it will work in this instance.

Is this possible?

like image 892
Phillip B Oldham Avatar asked Sep 23 '10 14:09

Phillip B Oldham


1 Answers

You can do this with the Manifest task

<manifest file="MANIFEST.MF">
    <section name="section">
        <attribute name="Attribute-Name" value="value"/>
    </section>
    <section name="section/class1.class">
        <attribute name="Second-Attribute-Name" value="otherValue"/>
    </section>
</manifest>

It will generate this manifest :

Manifest-Version: 1.0
Created-By: Apache Ant 1.7

Name: section
Attribute-Name: value

Name: section/class1.class
Second-Attribute-Name: otherValue

You can maintain two different custom tasks to handle the different cases, and call the right one at the right moment.


For an "automatic" management :

<target name="manifest-generation">
    <foreach param="file" target="manifest">
        <path>
            <fileset dir=".">
                <include name="**/*.class"/>
            </fileset>
        </path>
    </foreach>
</target>

<target name="manifest">
    <manifest file="MANIFEST.MF" mode="update">
        <section name="${file}">
            <attribute name="Attribute-Name" value="value"/>
        </section>
    </manifest>
</target>
like image 126
Colin Hebert Avatar answered Nov 11 '22 12:11

Colin Hebert