diff options
author | Jake Petroules <jake.petroules@petroules.com> | 2015-02-02 22:38:55 -0800 |
---|---|---|
committer | Jake Petroules <jake.petroules@petroules.com> | 2015-07-22 13:24:09 +0000 |
commit | d6e5db9d8f3771023465e13757e35fc752d7126c (patch) | |
tree | 86bae84d74ff004de9377bf50891f25edfaff9a3 /share/qbs/modules/java | |
parent | a3cb59b277698ba92cdfde0ccc215e93b96ae92f (diff) | |
download | qbs-d6e5db9d8f3771023465e13757e35fc752d7126c.tar.gz |
Add manifest support in Java module.
The existing manifest property was never declared, so this never worked
in the first place. Additionally, add aggregation capabilities similar
to how Info.plist is handled in the DarwinGCC module.
Change-Id: I93e35936bdfd271adc2892bf2288d2f66d4f87a8
Reviewed-by: Christian Kandeler <christian.kandeler@theqtcompany.com>
Diffstat (limited to 'share/qbs/modules/java')
-rw-r--r-- | share/qbs/modules/java/JavaModule.qbs | 69 | ||||
-rw-r--r-- | share/qbs/modules/java/utils.js | 32 |
2 files changed, 98 insertions, 3 deletions
diff --git a/share/qbs/modules/java/JavaModule.qbs b/share/qbs/modules/java/JavaModule.qbs index 70dd6477b..e39999c3c 100644 --- a/share/qbs/modules/java/JavaModule.qbs +++ b/share/qbs/modules/java/JavaModule.qbs @@ -33,6 +33,7 @@ import qbs.FileInfo import qbs.ModUtils import qbs.Probes import qbs.Process +import qbs.TextFile import "utils.js" as JavaUtils @@ -75,6 +76,30 @@ Module { description: "version of the Java runtime to generate compatible bytecode for" } + property var manifest: { + return { + "Manifest-Version": "1.0", + "Class-Path": manifestClassPath ? manifestClassPath.join(" ") : undefined + }; + } + + PropertyOptions { + name: "manifest" + description: "properties to add to the manifest file when building a JAR" + } + + property path manifestFile + PropertyOptions { + name: "manifestFile" + description: "manifest file to embed when building a JAR" + } + + property stringList manifestClassPath + PropertyOptions { + name: "manifestClassPath" + description: "entries to add to the manifest's Class-Path when building a JAR" + } + property bool warningsAsErrors: false property pathList jdkIncludePaths: { @@ -189,12 +214,50 @@ Module { } prepare: { - var i; + var i, key; var flags = "cf"; var args = [output.filePath]; - var manifestFile = ModUtils.moduleProperty(product, "manifest"); - if (manifestFile) { + var manifestFile = ModUtils.moduleProperty(product, "manifestFile"); + var manifest = ModUtils.moduleProperty(product, "manifest"); + var aggregateManifest = JavaUtils.manifestContents(manifestFile) || {}; + + // Add local key-value pairs (overrides equivalent keys specified in the file if + // one was given) + for (key in manifest) { + if (manifest.hasOwnProperty(key)) + aggregateManifest[key] = manifest[key]; + } + + for (key in aggregateManifest) { + if (aggregateManifest.hasOwnProperty(key) && aggregateManifest[key] === undefined) + delete aggregateManifest[key]; + } + + // Use default manifest unless we actually have properties to set + var needsManifestFile = manifestFile !== undefined || aggregateManifest !== {"Manifest-Version": "1.0"}; + + manifestFile = FileInfo.joinPaths(product.buildDirectory, "manifest.mf"); + + var mf; + try { + mf = new TextFile(manifestFile, TextFile.WriteOnly); + + // Ensure that manifest version comes first + mf.write("Manifest-Version: " + (aggregateManifest["Manifest-Version"] || "1.0") + "\n"); + delete aggregateManifest["Manifest-Version"]; + + for (key in aggregateManifest) + mf.write(key + ": " + aggregateManifest[key] + "\n"); + + mf.write("\n"); + } finally { + if (mf) { + mf.close(); + } + } + + if (needsManifestFile) { flags += "m"; args.push(manifestFile); } diff --git a/share/qbs/modules/java/utils.js b/share/qbs/modules/java/utils.js index c3ece67e2..7533e3dcc 100644 --- a/share/qbs/modules/java/utils.js +++ b/share/qbs/modules/java/utils.js @@ -237,6 +237,10 @@ function helperOverrideArgs(product, tool) { } function outputArtifacts(product, inputs) { + // Handle the case where a product depends on Java but has no Java sources + if (!inputs["java.java"] || inputs["java.java"].length === 0) + return []; + // We need to ensure that the output directory is created first, because the Java compiler // internally checks that it is present before performing any actions File.makePath(ModUtils.moduleProperty(product, "classFilesDir")); @@ -255,3 +259,31 @@ function outputArtifacts(product, inputs) { process.close(); } } + +function manifestContents(filePath) { + if (filePath === undefined) + return undefined; + + var contents, file; + try { + file = new TextFile(filePath); + contents = file.readAll(); + } finally { + if (file) { + file.close(); + } + } + + if (contents) { + var dict = {}; + var lines = contents.split(/[\r\n]/g); + for (var i in lines) { + var kv = lines[i].split(":"); + if (kv.length !== 2) + return undefined; + dict[kv[0]] = kv[1]; + } + + return dict; + } +} |