Jam*_*arr 0 ant build manifest
我需要编写一个ant build,它从META-INF/manifest.mf文件读入现有版本并附加到它.
应该可以使用ANT 清单任务进行更新,但是我在阅读现有版本时遇到了麻烦.
由于清单条目是use key:value而不是key = value,因此我无法使用ANT的loadproperties任务读取它们.
有没有人这样做/有任何想法?
谢谢
您需要小心使用<loadproperties>
清单:尽管它似乎使用短值,但是当行长度超过70个字符时,由于清单条目包装的奇怪方式,它会失败.结果值被截断.
我写了一个<scriptdef>
按照你的要求做的,尽管还没有完全测试过.
<!--
Loads entries from a manifest file.
@jar The jar from where to read
@file A manifest file to read
@prefix A prefix to prepend
@section The name of the manifest section to load
-->
<scriptdef name="loadmf" language="javascript" loaderRef="sharedbuild-loaderRef">
<attribute name="jar" />
<attribute name="file" />
<attribute name="prefix" />
<attribute name="section" />
<![CDATA[
var jarname = attributes.get("jar");
var filename = attributes.get("file");
if (jarname != null && filename != null) {
self.fail("Only one of jar or file is required");
}
var prefix = attributes.get("prefix");
if (prefix == null) {
prefix = "";
}
var section = attributes.get("section");
var manifest;
if (jarname != null) {
var jarfile = new java.util.jar.JarFile(new java.io.File(jarname));
manifest = jarfile.getManifest();
} else if (filename != null) {
manifest = new java.util.jar.Manifest(new java.io.FileInputStream(new java.io.File(filename)));
} else {
self.fail("One of jar or file is required");
}
if (manifest == null) {
self.log("No manifest in " + jar);
} else {
var attributes = (section == null) ? manifest.getMainAttributes() : manifest.getAttributes(section);
if (attributes != null) {
var iter = attributes.entrySet().iterator();
while (iter.hasNext()) {
var entry = iter.next();
project.setProperty(prefix + entry.getKey(), entry.getValue());
}
}
}
]]>
</scriptdef>
Run Code Online (Sandbox Code Playgroud)
我确信JavaScript可以改进 - 我不是专家 - 但它似乎对我来说运行良好(运行AntUnit测试以确保我的OSGi清单正确创建.)作为额外的奖励,它从jar(或ear或war)文件或独立的清单文件.
归档时间: |
|
查看次数: |
9590 次 |
最近记录: |