< prev index next >

jdk/test/tools/jar/UpdateManifest.java

Print this page

        

@@ -22,26 +22,31 @@
  */
 
 /**
  * @test
  * @bug 6434207 6442687 6984046
- * @modules jdk.jartool/sun.tools.jar
+ * @modules jdk.jartool
  * @summary Ensure that jar ufm actually updates the
  * existing jar file's manifest with contents of the
  * manifest file.
  */
 
 import java.io.*;
 import java.util.logging.*;
+import java.util.spi.ToolProvider;
 import java.util.zip.*;
-import sun.tools.jar.Main;
 
 public class UpdateManifest {
     static PrintStream out = System.out;
     static PrintStream err = System.err;
     static boolean debug = true;
 
+    static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar")
+        .orElseThrow(() ->
+            new RuntimeException("jar tool not found")
+        );
+
     static final Logger JAR_LOGGER = Logger.getLogger("java.util.jar");
 
     public static void realMain(String[] args) throws Throwable {
         if (args.length == 0) {
             debug = false;

@@ -62,21 +67,18 @@
         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!
-        Main jartool = new Main(out, err, "jar");
-        boolean status = jartool.run(
-            new String[] { "cfe", jarFileName, "Hello", existence.getPath() });
-        check(status);
+        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
-        jartool = new Main(out, err, "jar");
-        status = jartool.run(
-            new String[] { "ufe", jarFileName, "Bye" });
-        check(status);
+        status = JAR_TOOL.run(out, err, "ufe", jarFileName, "Bye");
+        check(status == 0);
         checkManifest(jarFileName, "Bye");
     }
 
     static void testManifestContents() throws Throwable {
         // Create some strings we expect to find in the updated manifest

@@ -99,15 +101,13 @@
         File hello = createTextFile("hello");
 
         // Create a jar file
         final String jarFileName = "um-test.jar";
         new File(jarFileName).delete(); // remove pre-existing first!
-        Main jartool = new Main(out, err, "jar");
-        boolean status = jartool.run(
-                                new String[] {"cfm", jarFileName,
-                                    manifestOrig.getPath(), hello.getPath() });
-        check(status);
+        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);

@@ -120,14 +120,13 @@
         pw.println(animal);
         pw.println(specVersion); // addition to animal/marsupial section
         pw.close();
 
         // Update jar file with manifest
-        jartool = new Main(out, err, "jar");
-        status = jartool.run(
-            new String[] { "ufm", jarFileName, manifestUpdate.getPath() });
-        check(status);
+        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);
< prev index next >