jdk/test/tools/jar/index/MetaInf.java
changeset 41484 834b7539ada3
parent 30820 0d4717a011d3
equal deleted inserted replaced
41483:99e81f03a628 41484:834b7539ada3
    22  */
    22  */
    23 
    23 
    24 /*
    24 /*
    25  * @test
    25  * @test
    26  * @bug 4408526 6854795
    26  * @bug 4408526 6854795
    27  * @modules jdk.jartool/sun.tools.jar
    27  * @modules jdk.jartool
    28  * @summary Index the non-meta files in META-INF, such as META-INF/services.
    28  * @summary Index the non-meta files in META-INF, such as META-INF/services.
    29  */
    29  */
    30 
    30 
    31 import java.io.*;
    31 import java.io.*;
    32 import java.util.Arrays;
    32 import java.util.Arrays;
    33 import java.util.jar.*;
    33 import java.util.jar.*;
    34 import sun.tools.jar.Main;
    34 import java.util.spi.ToolProvider;
    35 import java.util.zip.ZipFile;
    35 import java.util.zip.ZipFile;
    36 
    36 
    37 public class MetaInf {
    37 public class MetaInf {
       
    38     static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar")
       
    39         .orElseThrow(() ->
       
    40             new RuntimeException("jar tool not found")
       
    41         );
    38 
    42 
    39     static String jarName = "a.jar";
    43     static String jarName = "a.jar";
    40     static String INDEX = "META-INF/INDEX.LIST";
    44     static String INDEX = "META-INF/INDEX.LIST";
    41     static String SERVICES = "META-INF/services";
    45     static String SERVICES = "META-INF/services";
    42     static String contents =
    46     static String contents =
    43         System.getProperty("test.src") + File.separatorChar + "jarcontents";
    47         System.getProperty("test.src") + File.separatorChar + "jarcontents";
    44 
    48 
    45     static void run(String ... args) {
    49     static void run(String ... args) {
    46         if (! new Main(System.out, System.err, "jar").run(args))
    50         if (JAR_TOOL.run(System.out, System.err, args) != 0)
    47             throw new Error("jar failed: args=" + Arrays.toString(args));
    51             throw new Error("jar failed: args=" + Arrays.toString(args));
    48     }
    52     }
    49 
    53 
    50     static void copy(File from, File to) throws IOException {
    54     static void copy(File from, File to) throws IOException {
    51         FileInputStream in = new FileInputStream(from);
    55         FileInputStream in = new FileInputStream(from);