diff options
author | Jake Petroules <jake.petroules@qt.io> | 2017-05-08 11:30:13 -0700 |
---|---|---|
committer | Jake Petroules <jake.petroules@qt.io> | 2017-05-09 16:51:40 +0000 |
commit | 9d2f9d85d07fffa82f4e832d1810d163104d07e5 (patch) | |
tree | d43d121c23c979f02ba5f039fa715b96a7dfb0ef | |
parent | 2bde55de3926567daa58c9fd279c7e6022a5802f (diff) |
Track Java manifest files as artifacts in the build graph
Change-Id: I4e5df616d49b51286a3df83f11807408b59c4fe3
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
-rw-r--r-- | doc/reference/modules/java-module.qdoc | 21 | ||||
-rw-r--r-- | share/qbs/modules/java/JavaModule.qbs | 44 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata-java/java/Manifest.mf | 1 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata-java/java/Manifest2.mf | 2 | ||||
-rw-r--r-- | tests/auto/blackbox/testdata-java/java/vehicles.qbs | 8 | ||||
-rw-r--r-- | tests/auto/blackbox/tst_blackboxjava.cpp | 3 |
6 files changed, 60 insertions, 19 deletions
diff --git a/doc/reference/modules/java-module.qdoc b/doc/reference/modules/java-module.qdoc index 8a3511ac5..6b0ba6e8e 100644 --- a/doc/reference/modules/java-module.qdoc +++ b/doc/reference/modules/java-module.qdoc @@ -152,17 +152,9 @@ \li 1.4.2 \li undefined \li The properties to add to the manifest file when building a JAR. - The contents of this property will be aggregated with the values from \c{manifestFile}. - If \c{manifest} and \c{manifestFile} contain the same key, the former will take - precedence. If undefined, will not be taken into account. - \row - \li manifestFile - \li path - \li 1.4.2 - \li undefined - \li The manifest file to embed when building a JAR. - The contents of this file will be aggregated with the values in \c{manifest}. - If \c{manifestFile} and \c{manifest} contain the same key, the latter will take + The contents of this property will be aggregated with the values from any files tagged + \c{"java.manifest"} (see below). + If \c{manifest} and a manifest file contain the same key, the former will take precedence. If undefined, will not be taken into account. \row \li manifestClassPath @@ -204,6 +196,13 @@ \li \c{*.java} \li 1.4 \li Source files with this tag serve as inputs to the rule running the \c javac tool. + \row + \li \c{"java.manifest"} + \li \c{*.mf} + \li 1.8 + \li The contents of files with this tag will be aggregated with the values in + \c{java.manifest}. If a manifest file and \c{java.manifest} contain the same key, the + latter will take precedence. If undefined, will not be taken into account. \endtable */ diff --git a/share/qbs/modules/java/JavaModule.qbs b/share/qbs/modules/java/JavaModule.qbs index 147d7b003..468200023 100644 --- a/share/qbs/modules/java/JavaModule.qbs +++ b/share/qbs/modules/java/JavaModule.qbs @@ -89,10 +89,18 @@ Module { description: "properties to add to the manifest file when building a JAR" } + // TODO: Remove in 1.9 property path manifestFile PropertyOptions { name: "manifestFile" - description: "manifest file to embed when building a JAR" + description: "Use files tagged \"java.manifest\" instead." + removalVersion: "1.9" + } + Group { + name: "Manifest" + prefix: product.sourceDirectory + "/" + files: java.manifestFile ? [java.manifestFile] : [] + fileTags: ["java.manifest"] } property stringList manifestClassPath @@ -175,6 +183,11 @@ Module { fileTags: ["java.java"] } + FileTagger { + patterns: ["*.mf"] + fileTags: ["java.manifest"] + } + Group { name: "io.qt.qbs.internal.java-helper" files: { @@ -226,7 +239,7 @@ Module { } Rule { - inputs: ["java.class"] + inputs: ["java.class", "java.manifest"] multiplex: true Artifact { @@ -239,12 +252,28 @@ Module { var flags = "cf"; var args = [output.filePath]; - var manifestFile = ModUtils.moduleProperty(product, "manifestFile"); - var manifest = ModUtils.moduleProperty(product, "manifest"); - var aggregateManifest = JavaUtils.manifestContents(manifestFile) || {}; + var aggregateManifest = {}; + var manifestFiles = (inputs["java.manifest"] || []).map(function (a) { return a.filePath; }); + manifestFiles.forEach(function (manifestFile) { + var mf = JavaUtils.manifestContents(manifestFile); + for (key in mf) { + if (mf.hasOwnProperty(key)) { + var oldValue = aggregateManifest[key]; + var newValue = mf[key]; + if (oldValue !== undefined && oldValue !== newValue) { + throw new Error("Conflicting values '" + + oldValue + "' and '" + + newValue + "' for manifest file key '" + key + "'"); + } + + aggregateManifest[key] = newValue; + } + } + }); // Add local key-value pairs (overrides equivalent keys specified in the file if // one was given) + var manifest = product.java.manifest; for (key in manifest) { if (manifest.hasOwnProperty(key)) aggregateManifest[key] = manifest[key]; @@ -256,9 +285,10 @@ Module { } // Use default manifest unless we actually have properties to set - var needsManifestFile = manifestFile !== undefined || aggregateManifest !== {"Manifest-Version": "1.0"}; + var needsManifestFile = manifestFiles.length > 0 + || aggregateManifest !== {"Manifest-Version": "1.0"}; - manifestFile = FileInfo.joinPaths(product.buildDirectory, "manifest.mf"); + var manifestFile = FileInfo.joinPaths(product.buildDirectory, "manifest.mf"); var mf; try { diff --git a/tests/auto/blackbox/testdata-java/java/Manifest.mf b/tests/auto/blackbox/testdata-java/java/Manifest.mf new file mode 100644 index 000000000..2da157c8b --- /dev/null +++ b/tests/auto/blackbox/testdata-java/java/Manifest.mf @@ -0,0 +1 @@ +Some-Property: Some-Value diff --git a/tests/auto/blackbox/testdata-java/java/Manifest2.mf b/tests/auto/blackbox/testdata-java/java/Manifest2.mf new file mode 100644 index 000000000..17433ea7e --- /dev/null +++ b/tests/auto/blackbox/testdata-java/java/Manifest2.mf @@ -0,0 +1,2 @@ +Some-Property: Some-Value +Additional-Property: Additional-Value diff --git a/tests/auto/blackbox/testdata-java/java/vehicles.qbs b/tests/auto/blackbox/testdata-java/java/vehicles.qbs index 0a8c4a62e..2e048c634 100644 --- a/tests/auto/blackbox/testdata-java/java/vehicles.qbs +++ b/tests/auto/blackbox/testdata-java/java/vehicles.qbs @@ -86,7 +86,13 @@ Project { Depends { name: "native" } name: "jar_file" entryPoint: "Vehicles" - files: ["Jet.java", "Ship.java", "Vehicles.java"] + files: ["Jet.java", "Ship.java", "Vehicles.java", "Manifest.mf", "Manifest2.mf"] + + java.manifest: { + var mf = original; + mf["Extra-Property"] = "Crazy-Value"; + return mf; + } Group { fileTagsFilter: ["java.jar"] diff --git a/tests/auto/blackbox/tst_blackboxjava.cpp b/tests/auto/blackbox/tst_blackboxjava.cpp index 1f397b800..097fabca8 100644 --- a/tests/auto/blackbox/tst_blackboxjava.cpp +++ b/tests/auto/blackbox/tst_blackboxjava.cpp @@ -199,6 +199,9 @@ void TestBlackboxJava::java() const QByteArray stdOut = process.readAllStandardOutput(); QVERIFY2(stdOut.contains("Class-Path: car_jar.jar random_stuff.jar"), stdOut.constData()); QVERIFY2(stdOut.contains("Main-Class: Vehicles"), stdOut.constData()); + QVERIFY2(stdOut.contains("Some-Property: Some-Value"), stdOut.constData()); + QVERIFY2(stdOut.contains("Additional-Property: Additional-Value"), stdOut.constData()); + QVERIFY2(stdOut.contains("Extra-Property: Crazy-Value"), stdOut.constData()); } } |