diff --git a/src/jdk.jartool/share/man/jar.1 b/src/jdk.jartool/share/man/jar.1 index 865925cd075..a88653753ee 100644 --- a/src/jdk.jartool/share/man/jar.1 +++ b/src/jdk.jartool/share/man/jar.1 @@ -118,6 +118,9 @@ Updates an existing JAR file. .TP \f[V]-x\f[R] or \f[V]--extract\f[R] Extracts the named (or all) files from the archive. +If a file with the same name appears more than once in the archive, each +copy will be extracted, with later copies overwriting (replacing) +earlier copies unless -k is specified. .TP \f[V]-d\f[R] or \f[V]--describe-module\f[R] Prints the module descriptor or automatic module name. @@ -212,6 +215,14 @@ time-zone format, to use for the timestamp of the entries, e.g. .TP \f[V]--dir\f[R] \f[I]DIR\f[R] Directory into which the JAR file will be extracted. +.TP +\f[V]-k\f[R] or \f[V]--keep-old-files\f[R] +Do not overwrite existing files. +If a Jar file entry with the same name exists in the target directory, +the existing file will not be overwritten. +As a result, if a file appears more than once in an archive, later +copies will not overwrite earlier copies. +Also note that some file system can be case insensitive. .SH OTHER OPTIONS .PP The following options are recognized by the \f[V]jar\f[R] command and diff --git a/test/jdk/ProblemList.txt b/test/jdk/ProblemList.txt index 091d1e9cd28..b37787b5f7e 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -724,9 +724,6 @@ javax/swing/JMenuItem/ActionListenerCalledTwice/ActionListenerCalledTwiceTest.ja # core_tools -tools/jar/ExtractFilesTest.java 8342930 generic-all -tools/jar/MultipleManifestTest.java 8342930 generic-all - ############################################################################ diff --git a/test/jdk/tools/jar/ExtractFilesTest.java b/test/jdk/tools/jar/ExtractFilesTest.java index b829b770fc8..26e0d103d51 100644 --- a/test/jdk/tools/jar/ExtractFilesTest.java +++ b/test/jdk/tools/jar/ExtractFilesTest.java @@ -88,7 +88,7 @@ import jdk.test.lib.util.FileUtils; " inflated: testfile1" + nl + " inflated: testfile2" + nl; rm("META-INF testfile1 testfile2"); - Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes()); + assertOutputContains(output); } /** @@ -105,7 +105,7 @@ import jdk.test.lib.util.FileUtils; " inflated: testfile2" + nl; Assertions.assertEquals("testfile1", cat("testfile1")); rm("META-INF testfile1 testfile2"); - Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes()); + assertOutputContains(output); } /** @@ -123,7 +123,7 @@ import jdk.test.lib.util.FileUtils; Assertions.assertEquals("", cat("testfile1")); Assertions.assertEquals("testfile2", cat("testfile2")); rm("META-INF testfile1 testfile2"); - Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes()); + assertOutputContains(output); } /** @@ -141,7 +141,7 @@ import jdk.test.lib.util.FileUtils; Assertions.assertEquals("", cat("testfile1")); Assertions.assertEquals("", cat("testfile2")); rm("META-INF testfile1 testfile2"); - Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes()); + assertOutputContains(output); } /** @@ -159,7 +159,7 @@ import jdk.test.lib.util.FileUtils; Assertions.assertEquals("testfile1", cat("testfile1")); Assertions.assertEquals("", cat("testfile2")); rm("META-INF testfile1 testfile2"); - Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes()); + assertOutputContains(output); } /** @@ -175,10 +175,14 @@ import jdk.test.lib.util.FileUtils; "testfile1" + nl + "testfile2" + nl; - Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes()); + assertOutputContains(output); Assertions.assertEquals("Warning: The --keep-old-files/-k/k option is not valid with current usage, will be ignored." + nl, err); } + private void assertOutputContains(String expected) { + Assertions.assertTrue(baos.toString().contains(expected)); + } + private Stream mkpath(String... args) { return Arrays.stream(args).map(d -> Path.of(".", d.split("/"))); } diff --git a/test/jdk/tools/jar/MultipleManifestTest.java b/test/jdk/tools/jar/MultipleManifestTest.java index 951ce4bb890..231f6ba1ec6 100644 --- a/test/jdk/tools/jar/MultipleManifestTest.java +++ b/test/jdk/tools/jar/MultipleManifestTest.java @@ -154,7 +154,7 @@ class MultipleManifestTest { " inflated: entry1.txt" + nl + " inflated: META-INF/MANIFEST.MF" + nl + " inflated: entry2.txt" + nl; - Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes()); + assertOutputContains(output); } /** @@ -170,7 +170,7 @@ class MultipleManifestTest { " inflated: entry1.txt" + nl + " skipped: META-INF/MANIFEST.MF exists" + nl + " inflated: entry2.txt" + nl; - Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes()); + assertOutputContains(output); } private String getManifestVersion() throws IOException { @@ -199,6 +199,10 @@ class MultipleManifestTest { } } + private void assertOutputContains(String expected) { + Assertions.assertTrue(baos.toString().contains(expected)); + } + private void println() throws IOException { System.out.println(new String(baos.toByteArray())); }