forked from SeleniumHQ/selenium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadd_missing_dirs.patch
76 lines (72 loc) · 3.23 KB
/
add_missing_dirs.patch
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
diff --git a/private/tools/java/rules/jvm/external/jar/MergeJars.java b/private/tools/java/rules/jvm/external/jar/MergeJars.java
index 3efe36a1..d6ce9cc7 100644
--- a/private/tools/java/rules/jvm/external/jar/MergeJars.java
+++ b/private/tools/java/rules/jvm/external/jar/MergeJars.java
@@ -118,7 +118,6 @@ public static void main(String[] args) throws IOException {
Map<String, Path> fileToSourceJar = new TreeMap<>();
Map<String, byte[]> fileHashCodes = new HashMap<>();
- Set<String> createdDirectories = new HashSet<>();
for (Path source : sources) {
try (InputStream fis = Files.newInputStream(source);
ZipInputStream zis = new ZipInputStream(fis)) {
@@ -144,10 +143,7 @@ public static void main(String[] args) throws IOException {
continue;
}
- if (entry.isDirectory() && createdDirectories.add(entry.getName())) {
- fileToSourceJar.put(entry.getName(), source);
- createdDirectories.add(entry.getName());
- } else {
+ if (!entry.isDirectory()) {
// Duplicate files, however may not be. We need the hash to determine
// whether we should do anything.
byte[] hash = hash(zis);
@@ -175,6 +171,9 @@ public static void main(String[] args) throws IOException {
// Now create the output jar
Files.createDirectories(out.getParent());
+
+ Set<String> createdDirectories = new HashSet<>();
+
try (OutputStream os = Files.newOutputStream(out);
JarOutputStream jos = new JarOutputStream(os)) {
jos.setMethod(DEFLATED);
diff --git a/tests/com/jvm/external/jar/MergeJarsTest.java b/tests/com/jvm/external/jar/MergeJarsTest.java
index 2421ff47..f9c76bbd 100644
--- a/tests/com/jvm/external/jar/MergeJarsTest.java
+++ b/tests/com/jvm/external/jar/MergeJarsTest.java
@@ -435,6 +435,26 @@ public void orderingOfAutomaticallyCreatedDirectoriesIsConduciveToSensibleUnpack
assertTrue(indexOfQux > indexOfBaz);
}
+ @Test
+ public void shouldCreateIntermediateDirectoriesEvenIfTheyExistInTheSourceJar() throws IOException {
+ Path input = temp.newFile("example.jar").toPath();
+ createJar(input, ImmutableMap.of(
+ "foo/", "",
+ "foo/bar", "",
+ "foo/bar/baz.txt", "cheese"));
+
+ Path output = temp.newFile("out.jar").toPath();
+
+ MergeJars.main(new String[] {
+ "--output", output.toAbsolutePath().toString(),
+ "--sources", input.toAbsolutePath().toString(),
+ });
+
+ List<String> dirNames = readDirNames(output);
+ assertTrue(dirNames.contains("foo/"));
+ assertTrue(dirNames.contains("foo/bar/"));
+ }
+
@Test
public void mergedJarManifestSpecialAttributesAreHandled() throws IOException {
// This is required to allow JarInputStream to read the manifest properly
@@ -471,7 +491,9 @@ private void createJar(Path outputTo, Map<String, String> pathToContents) throws
for (Map.Entry<String, String> entry : pathToContents.entrySet()) {
ZipEntry ze = new StableZipEntry(entry.getKey());
zos.putNextEntry(ze);
- zos.write(entry.getValue().getBytes(UTF_8));
+ if (!ze.isDirectory()) {
+ zos.write(entry.getValue().getBytes(UTF_8));
+ }
zos.closeEntry();
}
}