I need to script an ant build which reads in the existing version from a META-INF/manifest.mf file and appends to it.
The updating should be possible using the ANT manifest task, however I've had trouble reading the existing version.
As the manifest entries are use key: value rather than key= value I cant read them in using ANT's loadproperties task.
Has anyone done this/ have any ideas?
Thanks
To grep the value of a key from a Manifest use loadproperties, here's a macrodef to get you going =
optionally you may use nested filterchains within loadproperties
You need to be careful using
<loadproperties>
on a manifest: though it appears to work with short values, it fails when the line-length exceeds 70 characters because of the odd way manifest entries wrap. The resulting values are truncated.I wrote a
<scriptdef>
that does what you ask, though it's not fully tested yet.I'm sure the JavaScript can be improved--I'm no expert--but it seems to work well-enough for me (running AntUnit tests to make sure my OSGi manifests are created correctly.) As an added bonus it loads from either a jar (or ear or war) file or a stand-alone manifest file.
Thanks All,
FYI this is my final code, tested working
This appends a revision number (4th element) to a version without a revision or replaces the revision for a version that already has one.
The
<manifest>
task should do exactly what you want. It will append new Manifest key=value pairs to an existing Manifest. Any idea why you can't use it?You can use the
<concat>
task with the various filter readers, and then load the result with the<loadproperties>
task. It takes a bit of elbow grease, but it might be a way to read in your damaged Manifest file this way, get the values, and then rewrite a new Manifest file with those old values.I'd have to see a sample of your existing Manifest and what you want to add to it in order to figure out exactly what you need.