use of sun.tools.jar.Main in project jdk8u_jdk by JetBrains.
the class ChangeDir method doTest.
static void doTest(String sep) throws Throwable {
Path topDir = Files.createTempDirectory("delete");
try {
Files.deleteIfExists(Paths.get(jarName));
// Create a subdirectory "a/b"
Path testDir = Files.createDirectories(topDir.resolve("a").resolve("b"));
// Create file in that subdirectory
Path testFile = testDir.resolve(fileName);
Files.createFile(testFile);
// Create a jar file from that subdirectory, but with a // in the
// path name.
List<String> argList = new ArrayList<String>();
argList.add("cf");
argList.add(jarName);
argList.add("-C");
// Note double 'sep' is intentional
argList.add(topDir.toString() + sep + "a" + sep + sep + "b");
argList.add(fileName);
Main jarTool = new Main(System.out, System.err, "jar");
if (!jarTool.run(argList.toArray(new String[argList.size()]))) {
fail("Could not create jar file.");
}
// Check that the entry for hello.txt does *not* have a pathname.
try (JarFile jf = new JarFile(jarName)) {
for (Enumeration<JarEntry> i = jf.entries(); i.hasMoreElements(); ) {
JarEntry je = i.nextElement();
String name = je.getName();
if (name.indexOf(fileName) != -1) {
if (name.indexOf(fileName) != 0) {
fail(String.format("Expected '%s' but got '%s'%n", fileName, name));
} else {
pass();
}
}
}
}
} finally {
cleanup(topDir);
Files.deleteIfExists(Paths.get(jarName));
}
}
use of sun.tools.jar.Main in project jdk8u_jdk by JetBrains.
the class JarBackSlash method testJarList.
private static void testJarList(String jarFile) throws IOException {
List<String> argList = new ArrayList<String>();
argList.add("-tvf");
argList.add(jarFile);
argList.add(JARBACKSLASH + File.separatorChar + DIR + File.separatorChar + FILENAME);
String[] jarArgs = new String[argList.size()];
jarArgs = argList.toArray(jarArgs);
PipedOutputStream pipedOutput = new PipedOutputStream();
PipedInputStream pipedInput = new PipedInputStream(pipedOutput);
PrintStream out = new PrintStream(pipedOutput);
Main jarTool = new Main(out, System.err, "jar");
if (!jarTool.run(jarArgs)) {
fail("Could not list jar file.");
}
out.flush();
check(pipedInput.available() > 0);
}
use of sun.tools.jar.Main in project jdk8u_jdk by JetBrains.
the class UpdateManifest method testManifestContents.
static void 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";
// remove pre-existing first!
new File(jarFileName).delete();
Main jartool = new Main(out, err, "jar");
boolean status = jartool.run(new String[] { "cfm", jarFileName, manifestOrig.getPath(), hello.getPath() });
check(status);
// 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";
// replaces line in the original
pw.println(createdBy);
pw.println("");
pw.println(animal);
// addition to animal/marsupial section
pw.println(specVersion);
pw.close();
// Update jar file with manifest
jartool = new Main(out, err, "jar");
status = jartool.run(new String[] { "ufm", jarFileName, manifestUpdate.getPath() });
check(status);
// 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)));
// skip Manifest-Version
r.readLine();
check(r.readLine().equals(createdBy));
// skip blank line
r.readLine();
check(r.readLine().equals(animal));
String s = r.readLine();
if (s.equals(specVersion)) {
check(r.readLine().equals(specTitle));
} else if (s.equals(specTitle)) {
check(r.readLine().equals(specVersion));
} else {
fail("did not match specVersion nor specTitle");
}
zf.close();
}
use of sun.tools.jar.Main in project jdk8u_jdk by JetBrains.
the class JarEntryTime method realMain.
public static void realMain(String[] args) throws Throwable {
File dirOuter = new File("outer");
File dirInner = new File(dirOuter, "inner");
File jarFile = new File("JarEntryTime.jar");
// Remove any leftovers from prior run
cleanup(dirInner);
cleanup(dirOuter);
jarFile.delete();
/* Create a directory structure
* outer/
* inner/
* foo.txt
* Set the lastModified dates so that outer is created now, inner
* yesterday, and foo.txt created "earlier".
*/
check(dirOuter.mkdir());
check(dirInner.mkdir());
File fileInner = new File(dirInner, "foo.txt");
try (PrintWriter pw = new PrintWriter(fileInner)) {
pw.println("hello, world");
}
// Get the "now" from the "last-modified-time" of the last file we
// just created, instead of the "System.currentTimeMillis()", to
// workaround the possible "time difference" due to nfs.
final long now = fileInner.lastModified();
final long earlier = now - (60L * 60L * 6L * 1000L);
final long yesterday = now - (60L * 60L * 24L * 1000L);
check(dirOuter.setLastModified(now));
check(dirInner.setLastModified(yesterday));
check(fileInner.setLastModified(earlier));
// Make a jar file from that directory structure
Main jartool = new Main(System.out, System.err, "jar");
check(jartool.run(new String[] { "cf", jarFile.getName(), dirOuter.getName() }));
check(jarFile.exists());
check(cleanup(dirInner));
check(cleanup(dirOuter));
// Extract and check that the last modified values are those specified
// in the archive
extractJar(jarFile, false);
check(dirOuter.exists());
check(dirInner.exists());
check(fileInner.exists());
checkFileTime(dirOuter.lastModified(), now);
checkFileTime(dirInner.lastModified(), yesterday);
checkFileTime(fileInner.lastModified(), earlier);
check(cleanup(dirInner));
check(cleanup(dirOuter));
// Extract and check the last modified values are the current times.
// See sun.tools.jar.Main
extractJar(jarFile, true);
check(dirOuter.exists());
check(dirInner.exists());
check(fileInner.exists());
checkFileTime(dirOuter.lastModified(), now);
checkFileTime(dirInner.lastModified(), now);
checkFileTime(fileInner.lastModified(), now);
check(cleanup(dirInner));
check(cleanup(dirOuter));
check(jarFile.delete());
}
use of sun.tools.jar.Main in project jdk8u_jdk by JetBrains.
the class UpdateManifest method testManifestExistence.
static void 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";
// remove pre-existing first!
new File(jarFileName).delete();
Main jartool = new Main(out, err, "jar");
boolean status = jartool.run(new String[] { "cfe", jarFileName, "Hello", existence.getPath() });
check(status);
checkManifest(jarFileName, "Hello");
// Update that jar file by changing the Main-Class
jartool = new Main(out, err, "jar");
status = jartool.run(new String[] { "ufe", jarFileName, "Bye" });
check(status);
checkManifest(jarFileName, "Bye");
}
Aggregations