22 */ |
22 */ |
23 |
23 |
24 /** |
24 /** |
25 * @test |
25 * @test |
26 * @bug 7175845 |
26 * @bug 7175845 |
27 * @modules jdk.jartool/sun.tools.jar |
27 * @modules jdk.jartool |
28 * @summary jar -uf should not change file permission |
28 * @summary jar -uf should not change file permission |
29 */ |
29 */ |
30 |
30 |
31 import java.io.*; |
31 import java.io.*; |
32 import java.nio.file.*; |
32 import java.nio.file.*; |
33 import java.nio.file.attribute.*; |
33 import java.nio.file.attribute.*; |
34 import java.util.Set; |
34 import java.util.Set; |
35 import sun.tools.jar.Main; |
35 import java.util.spi.ToolProvider; |
36 |
36 |
37 public class UpdateJar { |
37 public class UpdateJar { |
|
38 private static final ToolProvider JAR_TOOL = ToolProvider.findFirst("jar") |
|
39 .orElseThrow(() -> |
|
40 new RuntimeException("jar tool not found") |
|
41 ); |
38 |
42 |
39 private static void cleanup(String... fnames) throws Throwable { |
43 private static void cleanup(String... fnames) throws Throwable { |
40 for (String fname : fnames) { |
44 for (String fname : fnames) { |
41 Files.deleteIfExists(Paths.get(fname)); |
45 Files.deleteIfExists(Paths.get(fname)); |
42 } |
46 } |
53 FileOutputStream fos1 = new FileOutputStream(e1)) { |
57 FileOutputStream fos1 = new FileOutputStream(e1)) { |
54 fos0.write(0); |
58 fos0.write(0); |
55 fos1.write(0); |
59 fos1.write(0); |
56 } |
60 } |
57 String[] jarArgs = new String[] {"cfM0", jar, e0}; |
61 String[] jarArgs = new String[] {"cfM0", jar, e0}; |
58 if (!new Main(System.out, System.err, "jar").run(jarArgs)) { |
62 if (JAR_TOOL.run(System.out, System.err, jarArgs) != 0) { |
59 fail("Could not create jar file."); |
63 fail("Could not create jar file."); |
60 } |
64 } |
61 Set<PosixFilePermission> pm = Files.getPosixFilePermissions(Paths.get(jar)); |
65 Set<PosixFilePermission> pm = Files.getPosixFilePermissions(Paths.get(jar)); |
62 jarArgs = new String[] {"uf", jar, e1}; |
66 jarArgs = new String[] {"uf", jar, e1}; |
63 if (!new Main(System.out, System.err, "jar").run(jarArgs)) { |
67 if (JAR_TOOL.run(System.out, System.err, jarArgs) != 0) { |
64 fail("Could not create jar file."); |
68 fail("Could not create jar file."); |
65 } |
69 } |
66 equal(pm, Files.getPosixFilePermissions(Paths.get(jar))); |
70 equal(pm, Files.getPosixFilePermissions(Paths.get(jar))); |
67 } finally { |
71 } finally { |
68 cleanup(jar, e0, e1); |
72 cleanup(jar, e0, e1); |