From f94f308514a3c29c5bbbb69e54d59a496c72e164 Mon Sep 17 00:00:00 2001 From: Henry Jen Date: Thu, 24 Oct 2024 18:32:21 -0700 Subject: [PATCH] 8342930: New tests from JDK-8335912 are failing --- src/jdk.jartool/share/man/jar.1 | 11 +++++++++++ test/jdk/ProblemList.txt | 3 --- test/jdk/tools/jar/ExtractFilesTest.java | 16 ++++++++++------ test/jdk/tools/jar/MultipleManifestTest.java | 8 ++++++-- 4 files changed, 27 insertions(+), 11 deletions(-) diff --git a/src/jdk.jartool/share/man/jar.1 b/src/jdk.jartool/share/man/jar.1 index 865925cd07518..a88653753eebe 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 e015ad1832069..d6403f980393a 100644 --- a/test/jdk/ProblemList.txt +++ b/test/jdk/ProblemList.txt @@ -723,9 +723,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 b829b770fc802..26e0d103d5123 100644 --- a/test/jdk/tools/jar/ExtractFilesTest.java +++ b/test/jdk/tools/jar/ExtractFilesTest.java @@ -88,7 +88,7 @@ public void testExtract() throws IOException { " inflated: testfile1" + nl + " inflated: testfile2" + nl; rm("META-INF testfile1 testfile2"); - Assertions.assertArrayEquals(baos.toByteArray(), output.getBytes()); + assertOutputContains(output); } /** @@ -105,7 +105,7 @@ public void testOverwrite() throws IOException { " 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 @@ public void testKeptOldFile() throws IOException { 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 @@ public void testGnuOptionsKeptOldFile() throws IOException { 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 @@ public void testGnuLongOptionsKeptOldFile() throws IOException { 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 @@ public void testWarningOnInvalidKeepOption() throws IOException { "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 951ce4bb8908b..231f6ba1ec656 100644 --- a/test/jdk/tools/jar/MultipleManifestTest.java +++ b/test/jdk/tools/jar/MultipleManifestTest.java @@ -154,7 +154,7 @@ public void testOverwrite() throws IOException { " 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 @@ public void testKeptOldFile() throws IOException { " 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 @@ private void jar(String cmdline) throws IOException { } } + private void assertOutputContains(String expected) { + Assertions.assertTrue(baos.toString().contains(expected)); + } + private void println() throws IOException { System.out.println(new String(baos.toByteArray())); }