/* * Copyright (c) 2006, 2010, Oracle and/or its affiliates. All rights reserved. * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * This code is free software; you can redistribute it and/or modify it * under the terms of the GNU General Public License version 2 only, as * published by the Free Software Foundation. * * This code is distributed in the hope that it will be useful, but WITHOUT * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License * version 2 for more details (a copy is included in the LICENSE file that * accompanied this code). * * You should have received a copy of the GNU General Public License version * 2 along with this work; if not, write to the Free Software Foundation, * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. * * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA * or visit www.oracle.com if you need additional information or have any * questions.
*/
/** * @test * @bug 6434207 6442687 6984046 * @modules jdk.jartool * @summary Ensure that jar ufm actually updates the * existing jar file's manifest with contents of the * manifest file.
*/
staticvoid testManifestExistence() throws Throwable { // Create a file to put in a jar file
File existence = createTextFile("existence");
// Create a jar file, specifying a Main-Class final String jarFileName = "um-existence.jar"; new File(jarFileName).delete(); // remove pre-existing first! int status = JAR_TOOL.run(out, err, "cfe", jarFileName, "Hello", existence.getPath());
check(status == 0);
checkManifest(jarFileName, "Hello");
// Update that jar file by changing the Main-Class
status = JAR_TOOL.run(out, err, "ufe", jarFileName, "Bye");
check(status == 0);
checkManifest(jarFileName, "Bye");
}
staticvoid testManifestContents() throws Throwable { // Create some strings we expect to find in the updated manifest final String animal = "Name: animal/marsupial"; final String specTitle = "Specification-Title: Wombat";
// Create a text file with manifest entries
File manifestOrig = File.createTempFile("manifestOrig", ".txt"); if (!debug) manifestOrig.deleteOnExit();
PrintWriter pw = new PrintWriter(manifestOrig);
pw.println("Manifest-Version: 1.0");
pw.println("Created-By: 1.7.0-internal (Oracle Corporation)");
pw.println("");
pw.println(animal);
pw.println(specTitle);
pw.close();
File hello = createTextFile("hello");
// Create a jar file final String jarFileName = "um-test.jar"; new File(jarFileName).delete(); // remove pre-existing first! int status = JAR_TOOL.run(out, err, "cfm", jarFileName,
manifestOrig.getPath(), hello.getPath());
check(status == 0);
// Create a new manifest, to use in updating the jar file.
File manifestUpdate = File.createTempFile("manifestUpdate", ".txt"); if (!debug) manifestUpdate.deleteOnExit();
pw = new PrintWriter(manifestUpdate); final String createdBy = "Created-By: 1.7.0-special (Oracle Corporation)"; final String specVersion = "Specification-Version: 1.0.0.0";
pw.println(createdBy); // replaces line in the original
pw.println("");
pw.println(animal);
pw.println(specVersion); // addition to animal/marsupial section
pw.close();
// Update jar file with manifest
status = JAR_TOOL.run(out, err, "ufm",
jarFileName, manifestUpdate.getPath());
check(status == 0);
// Extract jar, and verify contents of manifest file
File f = new File(jarFileName); if (!debug) f.deleteOnExit();
ZipFile zf = new ZipFile(f);
ZipEntry ze = zf.getEntry("META-INF/MANIFEST.MF");
BufferedReader r = new BufferedReader( new InputStreamReader(zf.getInputStream(ze)));
r.readLine(); // skip Manifest-Version
check(r.readLine().equals(createdBy));
r.readLine(); // skip blank line
check(r.readLine().equals(animal));
String s = r.readLine(); if (s.equals(specVersion)) {
check(r.readLine().equals(specTitle));
} elseif (s.equals(specTitle)) {
check(r.readLine().equals(specVersion));
} else {
fail("did not match specVersion nor specTitle");
}
zf.close();
}
static File createTextFile(String name) throws Throwable { // Create a text file to put in a jar file
File rc = File.createTempFile(name, ".txt"); if (!debug) rc.deleteOnExit();
PrintWriter pw = new PrintWriter(rc);
pw.println("hello, world");
pw.close(); return rc;
}
staticvoid checkManifest(String jarFileName, String mainClass) throws Throwable {
File f = new File(jarFileName); if (!debug) f.deleteOnExit();
ZipFile zf = new ZipFile(f);
ZipEntry ze = zf.getEntry("META-INF/MANIFEST.MF");
BufferedReader r = new BufferedReader( new InputStreamReader(zf.getInputStream(ze)));
String line = r.readLine(); while (line != null && !(line.startsWith("Main-Class:"))) {
line = r.readLine();
} if (line == null) {
fail("Didn't find Main-Class in manifest");
} else {
check(line.equals("Main-Class: " + mainClass));
}
zf.close();
}
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.14Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.