author | chegar |
Fri, 02 Mar 2018 10:18:48 +0000 | |
branch | http-client-branch |
changeset 56225 | 348ae78efb60 |
parent 48327 | d2a837cf9ff1 |
child 48691 | 554cb38e0caf |
permissions | -rw-r--r-- |
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
1 |
/* |
44257
3220d2ac3cee
8176709: JarFileSystem::isMultiReleaseJar is incorrect
redestad
parents:
43193
diff
changeset
|
2 |
* Copyright (c) 2015, 2017, Oracle and/or its affiliates. All rights reserved. |
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
4 |
* |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. Oracle designates this |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
10 |
* |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
15 |
* accompanied this code). |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
16 |
* |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
20 |
* |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
22 |
* or visit www.oracle.com if you need additional information or have any |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
23 |
* questions. |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
24 |
*/ |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
25 |
|
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
26 |
package jdk.nio.zipfs; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
27 |
|
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
28 |
import java.io.IOException; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
29 |
import java.io.InputStream; |
38432
892603099bb0
8144062: Move jdk.Version to java.lang.Runtime.Version
iris
parents:
37803
diff
changeset
|
30 |
import java.lang.Runtime.Version; |
44257
3220d2ac3cee
8176709: JarFileSystem::isMultiReleaseJar is incorrect
redestad
parents:
43193
diff
changeset
|
31 |
import java.nio.file.NoSuchFileException; |
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
32 |
import java.nio.file.Path; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
33 |
import java.util.Arrays; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
34 |
import java.util.HashMap; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
35 |
import java.util.Map; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
36 |
import java.util.TreeMap; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
37 |
import java.util.function.Consumer; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
38 |
import java.util.function.Function; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
39 |
import java.util.jar.Attributes; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
40 |
import java.util.jar.Manifest; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
41 |
|
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
42 |
/** |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
43 |
* Adds aliasing to ZipFileSystem to support multi-release jar files. An alias map |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
44 |
* is created by {@link JarFileSystem#createVersionedLinks(int)}. The map is then |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
45 |
* consulted when an entry is looked up in {@link JarFileSystem#getEntry(byte[])} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
46 |
* to determine if the entry has a corresponding versioned entry. If so, the |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
47 |
* versioned entry is returned. |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
48 |
* |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
49 |
* @author Steve Drach |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
50 |
*/ |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
51 |
|
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
52 |
class JarFileSystem extends ZipFileSystem { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
53 |
private Function<byte[],byte[]> lookup; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
54 |
|
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
55 |
@Override |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
36012
diff
changeset
|
56 |
IndexNode getInode(byte[] path) { |
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
57 |
// check for an alias to a versioned entry |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
58 |
byte[] versionedPath = lookup.apply(path); |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
36012
diff
changeset
|
59 |
return versionedPath == null ? super.getInode(path) : super.getInode(versionedPath); |
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
60 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
61 |
|
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
62 |
JarFileSystem(ZipFileSystemProvider provider, Path zfpath, Map<String,?> env) |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
63 |
throws IOException { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
64 |
super(provider, zfpath, env); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
65 |
lookup = path -> path; // lookup needs to be set before isMultiReleaseJar is called |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
66 |
// because it eventually calls getEntry |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
67 |
if (isMultiReleaseJar()) { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
68 |
int version; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
69 |
Object o = env.get("multi-release"); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
70 |
if (o instanceof String) { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
71 |
String s = (String)o; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
72 |
if (s.equals("runtime")) { |
48327 | 73 |
version = Runtime.version().feature(); |
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
74 |
} else { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
75 |
version = Integer.parseInt(s); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
76 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
77 |
} else if (o instanceof Integer) { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
78 |
version = (Integer)o; |
36012
2d47efae7da3
8150163: JarFileSystem support for MRJARs should use the JDK specific Version API
chegar
parents:
34835
diff
changeset
|
79 |
} else if (o instanceof Version) { |
48327 | 80 |
version = ((Version)o).feature(); |
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
81 |
} else { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
82 |
throw new IllegalArgumentException("env parameter must be String, Integer, " |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
83 |
+ "or Version"); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
84 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
85 |
lookup = createVersionedLinks(version < 0 ? 0 : version); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
86 |
setReadOnly(); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
87 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
88 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
89 |
|
44257
3220d2ac3cee
8176709: JarFileSystem::isMultiReleaseJar is incorrect
redestad
parents:
43193
diff
changeset
|
90 |
private boolean isMultiReleaseJar() throws IOException { |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
36012
diff
changeset
|
91 |
try (InputStream is = newInputStream(getBytes("/META-INF/MANIFEST.MF"))) { |
44257
3220d2ac3cee
8176709: JarFileSystem::isMultiReleaseJar is incorrect
redestad
parents:
43193
diff
changeset
|
92 |
String multiRelease = new Manifest(is).getMainAttributes() |
3220d2ac3cee
8176709: JarFileSystem::isMultiReleaseJar is incorrect
redestad
parents:
43193
diff
changeset
|
93 |
.getValue(Attributes.Name.MULTI_RELEASE); |
3220d2ac3cee
8176709: JarFileSystem::isMultiReleaseJar is incorrect
redestad
parents:
43193
diff
changeset
|
94 |
return "true".equalsIgnoreCase(multiRelease); |
3220d2ac3cee
8176709: JarFileSystem::isMultiReleaseJar is incorrect
redestad
parents:
43193
diff
changeset
|
95 |
} catch (NoSuchFileException x) { |
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
96 |
return false; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
97 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
98 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
99 |
|
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
100 |
/** |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
101 |
* create a map of aliases for versioned entries, for example: |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
102 |
* version/PackagePrivate.class -> META-INF/versions/9/version/PackagePrivate.class |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
103 |
* version/PackagePrivate.java -> META-INF/versions/9/version/PackagePrivate.java |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
104 |
* version/Version.class -> META-INF/versions/10/version/Version.class |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
105 |
* version/Version.java -> META-INF/versions/10/version/Version.java |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
106 |
* |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
107 |
* then wrap the map in a function that getEntry can use to override root |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
108 |
* entry lookup for entries that have corresponding versioned entries |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
109 |
*/ |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
110 |
private Function<byte[],byte[]> createVersionedLinks(int version) { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
111 |
HashMap<IndexNode,byte[]> aliasMap = new HashMap<>(); |
37803
ac955d7f5271
8150496: (zipfs) Fix performance issues in zip-fs
sherman
parents:
36012
diff
changeset
|
112 |
getVersionMap(version, getInode(getBytes("/META-INF/versions"))).values() |
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
113 |
.forEach(versionNode -> { // for each META-INF/versions/{n} directory |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
114 |
// put all the leaf inodes, i.e. entries, into the alias map |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
115 |
// possibly shadowing lower versioned entries |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
116 |
walk(versionNode, entryNode -> { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
117 |
byte[] rootName = getRootName(versionNode, entryNode); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
118 |
if (rootName != null) { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
119 |
IndexNode rootNode = getInode(rootName); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
120 |
if (rootNode == null) { // no matching root node, make a virtual one |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
121 |
rootNode = IndexNode.keyOf(rootName); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
122 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
123 |
aliasMap.put(rootNode, entryNode.name); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
124 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
125 |
}); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
126 |
}); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
127 |
return path -> aliasMap.get(IndexNode.keyOf(path)); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
128 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
129 |
|
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
130 |
/** |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
131 |
* create a sorted version map of version -> inode, for inodes <= max version |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
132 |
* 9 -> META-INF/versions/9 |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
133 |
* 10 -> META-INF/versions/10 |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
134 |
*/ |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
135 |
private TreeMap<Integer, IndexNode> getVersionMap(int version, IndexNode metaInfVersions) { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
136 |
TreeMap<Integer,IndexNode> map = new TreeMap<>(); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
137 |
IndexNode child = metaInfVersions.child; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
138 |
while (child != null) { |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
40528
diff
changeset
|
139 |
Integer key = getVersion(child.name, metaInfVersions.name.length + 1); |
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
140 |
if (key != null && key <= version) { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
141 |
map.put(key, child); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
142 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
143 |
child = child.sibling; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
144 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
145 |
return map; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
146 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
147 |
|
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
148 |
/** |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
149 |
* extract the integer version number -- META-INF/versions/9 returns 9 |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
150 |
*/ |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
151 |
private Integer getVersion(byte[] name, int offset) { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
152 |
try { |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
40528
diff
changeset
|
153 |
return Integer.parseInt(getString(Arrays.copyOfRange(name, offset, name.length))); |
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
154 |
} catch (NumberFormatException x) { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
155 |
// ignore this even though it might indicate issues with the JAR structure |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
156 |
return null; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
157 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
158 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
159 |
|
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
160 |
/** |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
161 |
* walk the IndexNode tree processing all leaf nodes |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
162 |
*/ |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
163 |
private void walk(IndexNode inode, Consumer<IndexNode> process) { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
164 |
if (inode == null) return; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
165 |
if (inode.isDir()) { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
166 |
walk(inode.child, process); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
167 |
} else { |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
168 |
process.accept(inode); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
169 |
} |
40528
c2d4a13ab15a
8164389: jdk.nio.zipfs.JarFileSystem does not completely traverse the versioned entries in a multi-release jar file
sdrach
parents:
38432
diff
changeset
|
170 |
walk(inode.sibling, process); |
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
171 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
172 |
|
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
173 |
/** |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
174 |
* extract the root name from a versioned entry name |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
175 |
* given inode for META-INF/versions/9/foo/bar.class |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
176 |
* and prefix META-INF/versions/9/ |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
177 |
* returns foo/bar.class |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
178 |
*/ |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
179 |
private byte[] getRootName(IndexNode prefix, IndexNode inode) { |
43193
a8e490921d20
8172921: Zip filesystem performance improvement and code cleanup
sherman
parents:
40528
diff
changeset
|
180 |
int offset = prefix.name.length; |
34835
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
181 |
byte[] fullName = inode.name; |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
182 |
return Arrays.copyOfRange(fullName, offset, fullName.length); |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
183 |
} |
ee52702b8d1b
8144355: JDK 9 changes to ZipFileSystem to support multi-release jar files
sdrach
parents:
diff
changeset
|
184 |
} |