author | jjg |
Fri, 11 Jul 2008 14:59:48 -0700 | |
changeset 865 | 21668f049d28 |
parent 810 | e4b6a6d206e6 |
child 1205 | b316e32eb90c |
permissions | -rw-r--r-- |
655
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
1 |
/* |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
2 |
* Copyright 2007-2008 Sun Microsystems, Inc. All Rights Reserved. |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
4 |
* |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
7 |
* published by the Free Software Foundation. Sun designates this |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
8 |
* particular file as subject to the "Classpath" exception as provided |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
9 |
* by Sun in the LICENSE file that accompanied this code. |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
10 |
* |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
15 |
* accompanied this code). |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
16 |
* |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
17 |
* You should have received a copy of the GNU General Public License version |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
20 |
* |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
21 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
23 |
* have any questions. |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
24 |
*/ |
1ebc7ce89018
6705945: com.sun.tools.javac.zip files do not have valid copyright
jjg
parents:
10
diff
changeset
|
25 |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
655
diff
changeset
|
26 |
package com.sun.tools.javac.file; |
10 | 27 |
|
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
655
diff
changeset
|
28 |
import java.io.File; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
655
diff
changeset
|
29 |
import java.io.FileNotFoundException; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
655
diff
changeset
|
30 |
import java.io.IOException; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
655
diff
changeset
|
31 |
import java.io.RandomAccessFile; |
10 | 32 |
import java.text.MessageFormat; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
655
diff
changeset
|
33 |
import java.util.ArrayList; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
655
diff
changeset
|
34 |
import java.util.Arrays; |
865
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
810
diff
changeset
|
35 |
import java.util.Calendar; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
655
diff
changeset
|
36 |
import java.util.Collections; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
655
diff
changeset
|
37 |
import java.util.HashMap; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
655
diff
changeset
|
38 |
import java.util.HashSet; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
655
diff
changeset
|
39 |
import java.util.Iterator; |
10 | 40 |
import java.util.List; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
655
diff
changeset
|
41 |
import java.util.Map; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
655
diff
changeset
|
42 |
import java.util.Set; |
10 | 43 |
import java.util.concurrent.locks.ReentrantLock; |
731
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
655
diff
changeset
|
44 |
import java.util.zip.DataFormatException; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
655
diff
changeset
|
45 |
import java.util.zip.Inflater; |
1dd22bdb9ca5
6714364: refactor javac File handling code into new javac.file package
jjg
parents:
655
diff
changeset
|
46 |
import java.util.zip.ZipException; |
10 | 47 |
|
48 |
/** This class implements building of index of a zip archive and access to it's context. |
|
49 |
* It also uses prebuild index if available. It supports invocations where it will |
|
50 |
* serialize an optimized zip index file to disk. |
|
51 |
* |
|
52 |
* In oreder to use secondary index file make sure the option "usezipindex" is in the Options object, |
|
53 |
* when JavacFileManager is invoked. (You can pass "-XDusezipindex" on the command line. |
|
54 |
* |
|
55 |
* Location where to look for/generate optimized zip index files can be provided using |
|
56 |
* "-XDcachezipindexdir=<directory>". If this flag is not provided, the dfault location is |
|
57 |
* the value of the "java.io.tmpdir" system property. |
|
58 |
* |
|
59 |
* If key "-XDwritezipindexfiles" is specified, there will be new optimized index file |
|
60 |
* created for each archive, used by the compiler for compilation, at location, |
|
61 |
* specified by "cachezipindexdir" option. |
|
62 |
* |
|
63 |
* If nonBatchMode option is specified (-XDnonBatchMode) the compiler will use timestamp |
|
64 |
* checking to reindex the zip files if it is needed. In batch mode the timestamps are not checked |
|
65 |
* and the compiler uses the cached indexes. |
|
66 |
*/ |
|
67 |
public class ZipFileIndex { |
|
68 |
private static final String MIN_CHAR = String.valueOf(Character.MIN_VALUE); |
|
69 |
private static final String MAX_CHAR = String.valueOf(Character.MAX_VALUE); |
|
70 |
||
71 |
public final static long NOT_MODIFIED = Long.MIN_VALUE; |
|
72 |
||
73 |
private static Map<File, ZipFileIndex> zipFileIndexCache = new HashMap<File, ZipFileIndex>(); |
|
74 |
private static ReentrantLock lock = new ReentrantLock(); |
|
75 |
||
76 |
private static boolean NON_BATCH_MODE = System.getProperty("nonBatchMode") != null;// TODO: Use -XD compiler switch for this. |
|
77 |
||
78 |
private Map<String, DirectoryEntry> directories = Collections.<String, DirectoryEntry>emptyMap(); |
|
79 |
private Set<String> allDirs = Collections.<String>emptySet(); |
|
80 |
||
81 |
// ZipFileIndex data entries |
|
82 |
private File zipFile; |
|
83 |
private long zipFileLastModified = NOT_MODIFIED; |
|
84 |
private RandomAccessFile zipRandomFile; |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
85 |
private Entry[] entries; |
10 | 86 |
|
87 |
private boolean readFromIndex = false; |
|
88 |
private File zipIndexFile = null; |
|
89 |
private boolean triedToReadIndex = false; |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
90 |
final String symbolFilePrefix; |
10 | 91 |
private int symbolFilePrefixLength = 0; |
92 |
private boolean hasPopulatedData = false; |
|
93 |
private long lastReferenceTimeStamp = NOT_MODIFIED; |
|
94 |
||
95 |
private boolean usePreindexedCache = false; |
|
96 |
private String preindexedCacheLocation = null; |
|
97 |
||
98 |
private boolean writeIndex = false; |
|
99 |
||
100 |
/** |
|
101 |
* Returns a list of all ZipFileIndex entries |
|
102 |
* |
|
103 |
* @return A list of ZipFileIndex entries, or an empty list |
|
104 |
*/ |
|
105 |
public static List<ZipFileIndex> getZipFileIndexes() { |
|
106 |
return getZipFileIndexes(false); |
|
107 |
} |
|
108 |
||
109 |
/** |
|
110 |
* Returns a list of all ZipFileIndex entries |
|
111 |
* |
|
112 |
* @param openedOnly If true it returns a list of only opened ZipFileIndex entries, otherwise |
|
113 |
* all ZipFileEntry(s) are included into the list. |
|
114 |
* @return A list of ZipFileIndex entries, or an empty list |
|
115 |
*/ |
|
116 |
public static List<ZipFileIndex> getZipFileIndexes(boolean openedOnly) { |
|
117 |
List<ZipFileIndex> zipFileIndexes = new ArrayList<ZipFileIndex>(); |
|
118 |
lock.lock(); |
|
119 |
try { |
|
120 |
zipFileIndexes.addAll(zipFileIndexCache.values()); |
|
121 |
||
122 |
if (openedOnly) { |
|
123 |
for(ZipFileIndex elem : zipFileIndexes) { |
|
124 |
if (!elem.isOpen()) { |
|
125 |
zipFileIndexes.remove(elem); |
|
126 |
} |
|
127 |
} |
|
128 |
} |
|
129 |
} |
|
130 |
finally { |
|
131 |
lock.unlock(); |
|
132 |
} |
|
133 |
return zipFileIndexes; |
|
134 |
} |
|
135 |
||
136 |
public boolean isOpen() { |
|
137 |
lock.lock(); |
|
138 |
try { |
|
139 |
return zipRandomFile != null; |
|
140 |
} |
|
141 |
finally { |
|
142 |
lock.unlock(); |
|
143 |
} |
|
144 |
} |
|
145 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
146 |
public static ZipFileIndex getZipFileIndex(File zipFile, String symbolFilePrefix, boolean useCache, String cacheLocation, boolean writeIndex) throws IOException { |
10 | 147 |
ZipFileIndex zi = null; |
148 |
lock.lock(); |
|
149 |
try { |
|
150 |
zi = getExistingZipIndex(zipFile); |
|
151 |
||
152 |
if (zi == null || (zi != null && zipFile.lastModified() != zi.zipFileLastModified)) { |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
153 |
zi = new ZipFileIndex(zipFile, symbolFilePrefix, writeIndex, |
10 | 154 |
useCache, cacheLocation); |
155 |
zipFileIndexCache.put(zipFile, zi); |
|
156 |
} |
|
157 |
} |
|
158 |
finally { |
|
159 |
lock.unlock(); |
|
160 |
} |
|
161 |
return zi; |
|
162 |
} |
|
163 |
||
164 |
public static ZipFileIndex getExistingZipIndex(File zipFile) { |
|
165 |
lock.lock(); |
|
166 |
try { |
|
167 |
return zipFileIndexCache.get(zipFile); |
|
168 |
} |
|
169 |
finally { |
|
170 |
lock.unlock(); |
|
171 |
} |
|
172 |
} |
|
173 |
||
174 |
public static void clearCache() { |
|
175 |
lock.lock(); |
|
176 |
try { |
|
177 |
zipFileIndexCache.clear(); |
|
178 |
} |
|
179 |
finally { |
|
180 |
lock.unlock(); |
|
181 |
} |
|
182 |
} |
|
183 |
||
184 |
public static void clearCache(long timeNotUsed) { |
|
185 |
lock.lock(); |
|
186 |
try { |
|
187 |
Iterator<File> cachedFileIterator = zipFileIndexCache.keySet().iterator(); |
|
188 |
while (cachedFileIterator.hasNext()) { |
|
189 |
File cachedFile = cachedFileIterator.next(); |
|
190 |
ZipFileIndex cachedZipIndex = zipFileIndexCache.get(cachedFile); |
|
191 |
if (cachedZipIndex != null) { |
|
192 |
long timeToTest = cachedZipIndex.lastReferenceTimeStamp + timeNotUsed; |
|
193 |
if (timeToTest < cachedZipIndex.lastReferenceTimeStamp || // Overflow... |
|
194 |
System.currentTimeMillis() > timeToTest) { |
|
195 |
zipFileIndexCache.remove(cachedFile); |
|
196 |
} |
|
197 |
} |
|
198 |
} |
|
199 |
} |
|
200 |
finally { |
|
201 |
lock.unlock(); |
|
202 |
} |
|
203 |
} |
|
204 |
||
205 |
public static void removeFromCache(File file) { |
|
206 |
lock.lock(); |
|
207 |
try { |
|
208 |
zipFileIndexCache.remove(file); |
|
209 |
} |
|
210 |
finally { |
|
211 |
lock.unlock(); |
|
212 |
} |
|
213 |
} |
|
214 |
||
215 |
/** Sets already opened list of ZipFileIndexes from an outside client |
|
216 |
* of the compiler. This functionality should be used in a non-batch clients of the compiler. |
|
217 |
*/ |
|
218 |
public static void setOpenedIndexes(List<ZipFileIndex>indexes) throws IllegalStateException { |
|
219 |
lock.lock(); |
|
220 |
try { |
|
221 |
if (zipFileIndexCache.isEmpty()) { |
|
222 |
throw new IllegalStateException("Setting opened indexes should be called only when the ZipFileCache is empty. Call JavacFileManager.flush() before calling this method."); |
|
223 |
} |
|
224 |
||
225 |
for (ZipFileIndex zfi : indexes) { |
|
226 |
zipFileIndexCache.put(zfi.zipFile, zfi); |
|
227 |
} |
|
228 |
} |
|
229 |
finally { |
|
230 |
lock.unlock(); |
|
231 |
} |
|
232 |
} |
|
233 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
234 |
private ZipFileIndex(File zipFile, String symbolFilePrefix, boolean writeIndex, |
10 | 235 |
boolean useCache, String cacheLocation) throws IOException { |
236 |
this.zipFile = zipFile; |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
237 |
this.symbolFilePrefix = symbolFilePrefix; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
238 |
this.symbolFilePrefixLength = (symbolFilePrefix == null ? 0 : |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
239 |
symbolFilePrefix.getBytes("UTF-8").length); |
10 | 240 |
this.writeIndex = writeIndex; |
241 |
this.usePreindexedCache = useCache; |
|
242 |
this.preindexedCacheLocation = cacheLocation; |
|
243 |
||
244 |
if (zipFile != null) { |
|
245 |
this.zipFileLastModified = zipFile.lastModified(); |
|
246 |
} |
|
247 |
||
248 |
// Validate integrity of the zip file |
|
249 |
checkIndex(); |
|
250 |
} |
|
251 |
||
252 |
public String toString() { |
|
253 |
return "ZipFileIndex of file:(" + zipFile + ")"; |
|
254 |
} |
|
255 |
||
256 |
// Just in case... |
|
257 |
protected void finalize() { |
|
258 |
closeFile(); |
|
259 |
} |
|
260 |
||
261 |
private boolean isUpToDate() { |
|
262 |
if (zipFile != null && |
|
263 |
((!NON_BATCH_MODE) || zipFileLastModified == zipFile.lastModified()) && |
|
264 |
hasPopulatedData) { |
|
265 |
return true; |
|
266 |
} |
|
267 |
||
268 |
return false; |
|
269 |
} |
|
270 |
||
271 |
/** |
|
272 |
* Here we need to make sure that the ZipFileIndex is valid. Check the timestamp of the file and |
|
273 |
* if its the same as the one at the time the index was build we don't need to reopen anything. |
|
274 |
*/ |
|
275 |
private void checkIndex() throws IOException { |
|
276 |
boolean isUpToDate = true; |
|
277 |
if (!isUpToDate()) { |
|
278 |
closeFile(); |
|
279 |
isUpToDate = false; |
|
280 |
} |
|
281 |
||
282 |
if (zipRandomFile != null || isUpToDate) { |
|
283 |
lastReferenceTimeStamp = System.currentTimeMillis(); |
|
284 |
return; |
|
285 |
} |
|
286 |
||
287 |
hasPopulatedData = true; |
|
288 |
||
289 |
if (readIndex()) { |
|
290 |
lastReferenceTimeStamp = System.currentTimeMillis(); |
|
291 |
return; |
|
292 |
} |
|
293 |
||
294 |
directories = Collections.<String, DirectoryEntry>emptyMap(); |
|
295 |
allDirs = Collections.<String>emptySet(); |
|
296 |
||
297 |
try { |
|
298 |
openFile(); |
|
299 |
long totalLength = zipRandomFile.length(); |
|
300 |
ZipDirectory directory = new ZipDirectory(zipRandomFile, 0L, totalLength, this); |
|
301 |
directory.buildIndex(); |
|
302 |
} finally { |
|
303 |
if (zipRandomFile != null) { |
|
304 |
closeFile(); |
|
305 |
} |
|
306 |
} |
|
307 |
||
308 |
lastReferenceTimeStamp = System.currentTimeMillis(); |
|
309 |
} |
|
310 |
||
311 |
private void openFile() throws FileNotFoundException { |
|
312 |
if (zipRandomFile == null && zipFile != null) { |
|
313 |
zipRandomFile = new RandomAccessFile(zipFile, "r"); |
|
314 |
} |
|
315 |
} |
|
316 |
||
317 |
private void cleanupState() { |
|
318 |
// Make sure there is a valid but empty index if the file doesn't exist |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
319 |
entries = Entry.EMPTY_ARRAY; |
10 | 320 |
directories = Collections.<String, DirectoryEntry>emptyMap(); |
321 |
zipFileLastModified = NOT_MODIFIED; |
|
322 |
allDirs = Collections.<String>emptySet(); |
|
323 |
} |
|
324 |
||
325 |
public void close() { |
|
326 |
lock.lock(); |
|
327 |
try { |
|
328 |
writeIndex(); |
|
329 |
closeFile(); |
|
330 |
} |
|
331 |
finally { |
|
332 |
lock.unlock(); |
|
333 |
} |
|
334 |
} |
|
335 |
||
336 |
private void closeFile() { |
|
337 |
if (zipRandomFile != null) { |
|
338 |
try { |
|
339 |
zipRandomFile.close(); |
|
340 |
} catch (IOException ex) { |
|
341 |
} |
|
342 |
zipRandomFile = null; |
|
343 |
} |
|
344 |
} |
|
345 |
||
346 |
/** |
|
347 |
* Returns the ZipFileIndexEntry for an absolute path, if there is one. |
|
348 |
*/ |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
349 |
Entry getZipIndexEntry(String path) { |
10 | 350 |
if (File.separatorChar != '/') { |
351 |
path = path.replace('/', File.separatorChar); |
|
352 |
} |
|
353 |
lock.lock(); |
|
354 |
try { |
|
355 |
checkIndex(); |
|
356 |
String lookFor = ""; |
|
357 |
int lastSepIndex = path.lastIndexOf(File.separatorChar); |
|
358 |
boolean noSeparator = false; |
|
359 |
if (lastSepIndex == -1) { |
|
360 |
noSeparator = true; |
|
361 |
} |
|
362 |
||
363 |
DirectoryEntry de = directories.get(noSeparator ? "" : path.substring(0, lastSepIndex)); |
|
364 |
||
365 |
lookFor = path.substring(noSeparator ? 0 : lastSepIndex + 1); |
|
366 |
||
367 |
return de == null ? null : de.getEntry(lookFor); |
|
368 |
} |
|
369 |
catch (IOException e) { |
|
370 |
return null; |
|
371 |
} |
|
372 |
finally { |
|
373 |
lock.unlock(); |
|
374 |
} |
|
375 |
} |
|
376 |
||
377 |
/** |
|
378 |
* Returns a javac List of filenames within an absolute path in the ZipFileIndex. |
|
379 |
*/ |
|
380 |
public com.sun.tools.javac.util.List<String> getFiles(String path) { |
|
381 |
if (File.separatorChar != '/') { |
|
382 |
path = path.replace('/', File.separatorChar); |
|
383 |
} |
|
384 |
||
385 |
lock.lock(); |
|
386 |
try { |
|
387 |
checkIndex(); |
|
388 |
||
389 |
DirectoryEntry de = directories.get(path); |
|
390 |
com.sun.tools.javac.util.List<String> ret = de == null ? null : de.getFiles(); |
|
391 |
||
392 |
if (ret == null) { |
|
393 |
return com.sun.tools.javac.util.List.<String>nil(); |
|
394 |
} |
|
395 |
return ret; |
|
396 |
} |
|
397 |
catch (IOException e) { |
|
398 |
return com.sun.tools.javac.util.List.<String>nil(); |
|
399 |
} |
|
400 |
finally { |
|
401 |
lock.unlock(); |
|
402 |
} |
|
403 |
} |
|
404 |
||
405 |
public List<String> getAllDirectories(String path) { |
|
406 |
||
407 |
if (File.separatorChar != '/') { |
|
408 |
path = path.replace('/', File.separatorChar); |
|
409 |
} |
|
410 |
||
411 |
lock.lock(); |
|
412 |
try { |
|
413 |
checkIndex(); |
|
414 |
path = path.intern(); |
|
415 |
||
416 |
DirectoryEntry de = directories.get(path); |
|
417 |
com.sun.tools.javac.util.List<String> ret = de == null ? null : de.getDirectories(); |
|
418 |
||
419 |
if (ret == null) { |
|
420 |
return com.sun.tools.javac.util.List.<String>nil(); |
|
421 |
} |
|
422 |
||
423 |
return ret; |
|
424 |
} |
|
425 |
catch (IOException e) { |
|
426 |
return com.sun.tools.javac.util.List.<String>nil(); |
|
427 |
} |
|
428 |
finally { |
|
429 |
lock.unlock(); |
|
430 |
} |
|
431 |
} |
|
432 |
||
433 |
public Set<String> getAllDirectories() { |
|
434 |
lock.lock(); |
|
435 |
try { |
|
436 |
checkIndex(); |
|
437 |
if (allDirs == Collections.EMPTY_SET) { |
|
438 |
Set<String> alldirs = new HashSet<String>(); |
|
439 |
Iterator<String> dirsIter = directories.keySet().iterator(); |
|
440 |
while (dirsIter.hasNext()) { |
|
441 |
alldirs.add(new String(dirsIter.next())); |
|
442 |
} |
|
443 |
||
444 |
allDirs = alldirs; |
|
445 |
} |
|
446 |
||
447 |
return allDirs; |
|
448 |
} |
|
449 |
catch (IOException e) { |
|
450 |
return Collections.<String>emptySet(); |
|
451 |
} |
|
452 |
finally { |
|
453 |
lock.unlock(); |
|
454 |
} |
|
455 |
} |
|
456 |
||
457 |
/** |
|
458 |
* Tests if a specific path exists in the zip. This method will return true |
|
459 |
* for file entries and directories. |
|
460 |
* |
|
461 |
* @param path A path within the zip. |
|
462 |
* @return True if the path is a file or dir, false otherwise. |
|
463 |
*/ |
|
464 |
public boolean contains(String path) { |
|
465 |
lock.lock(); |
|
466 |
try { |
|
467 |
checkIndex(); |
|
468 |
return getZipIndexEntry(path) != null; |
|
469 |
} |
|
470 |
catch (IOException e) { |
|
471 |
return false; |
|
472 |
} |
|
473 |
finally { |
|
474 |
lock.unlock(); |
|
475 |
} |
|
476 |
} |
|
477 |
||
478 |
public boolean isDirectory(String path) throws IOException { |
|
479 |
lock.lock(); |
|
480 |
try { |
|
481 |
// The top level in a zip file is always a directory. |
|
482 |
if (path.length() == 0) { |
|
483 |
lastReferenceTimeStamp = System.currentTimeMillis(); |
|
484 |
return true; |
|
485 |
} |
|
486 |
||
487 |
if (File.separatorChar != '/') |
|
488 |
path = path.replace('/', File.separatorChar); |
|
489 |
checkIndex(); |
|
490 |
return directories.get(path) != null; |
|
491 |
} |
|
492 |
finally { |
|
493 |
lock.unlock(); |
|
494 |
} |
|
495 |
} |
|
496 |
||
497 |
public long getLastModified(String path) throws IOException { |
|
498 |
lock.lock(); |
|
499 |
try { |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
500 |
Entry entry = getZipIndexEntry(path); |
10 | 501 |
if (entry == null) |
502 |
throw new FileNotFoundException(); |
|
503 |
return entry.getLastModified(); |
|
504 |
} |
|
505 |
finally { |
|
506 |
lock.unlock(); |
|
507 |
} |
|
508 |
} |
|
509 |
||
510 |
public int length(String path) throws IOException { |
|
511 |
lock.lock(); |
|
512 |
try { |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
513 |
Entry entry = getZipIndexEntry(path); |
10 | 514 |
if (entry == null) |
515 |
throw new FileNotFoundException(); |
|
516 |
||
517 |
if (entry.isDir) { |
|
518 |
return 0; |
|
519 |
} |
|
520 |
||
521 |
byte[] header = getHeader(entry); |
|
522 |
// entry is not compressed? |
|
523 |
if (get2ByteLittleEndian(header, 8) == 0) { |
|
524 |
return entry.compressedSize; |
|
525 |
} else { |
|
526 |
return entry.size; |
|
527 |
} |
|
528 |
} |
|
529 |
finally { |
|
530 |
lock.unlock(); |
|
531 |
} |
|
532 |
} |
|
533 |
||
534 |
public byte[] read(String path) throws IOException { |
|
535 |
lock.lock(); |
|
536 |
try { |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
537 |
Entry entry = getZipIndexEntry(path); |
10 | 538 |
if (entry == null) |
539 |
throw new FileNotFoundException(MessageFormat.format("Path not found in ZIP: {0}", path)); |
|
540 |
return read(entry); |
|
541 |
} |
|
542 |
finally { |
|
543 |
lock.unlock(); |
|
544 |
} |
|
545 |
} |
|
546 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
547 |
byte[] read(Entry entry) throws IOException { |
10 | 548 |
lock.lock(); |
549 |
try { |
|
550 |
openFile(); |
|
551 |
byte[] result = readBytes(entry); |
|
552 |
closeFile(); |
|
553 |
return result; |
|
554 |
} |
|
555 |
finally { |
|
556 |
lock.unlock(); |
|
557 |
} |
|
558 |
} |
|
559 |
||
560 |
public int read(String path, byte[] buffer) throws IOException { |
|
561 |
lock.lock(); |
|
562 |
try { |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
563 |
Entry entry = getZipIndexEntry(path); |
10 | 564 |
if (entry == null) |
565 |
throw new FileNotFoundException(); |
|
566 |
return read(entry, buffer); |
|
567 |
} |
|
568 |
finally { |
|
569 |
lock.unlock(); |
|
570 |
} |
|
571 |
} |
|
572 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
573 |
int read(Entry entry, byte[] buffer) |
10 | 574 |
throws IOException { |
575 |
lock.lock(); |
|
576 |
try { |
|
577 |
int result = readBytes(entry, buffer); |
|
578 |
return result; |
|
579 |
} |
|
580 |
finally { |
|
581 |
lock.unlock(); |
|
582 |
} |
|
583 |
} |
|
584 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
585 |
private byte[] readBytes(Entry entry) throws IOException { |
10 | 586 |
byte[] header = getHeader(entry); |
587 |
int csize = entry.compressedSize; |
|
588 |
byte[] cbuf = new byte[csize]; |
|
589 |
zipRandomFile.skipBytes(get2ByteLittleEndian(header, 26) + get2ByteLittleEndian(header, 28)); |
|
590 |
zipRandomFile.readFully(cbuf, 0, csize); |
|
591 |
||
592 |
// is this compressed - offset 8 in the ZipEntry header |
|
593 |
if (get2ByteLittleEndian(header, 8) == 0) |
|
594 |
return cbuf; |
|
595 |
||
596 |
int size = entry.size; |
|
597 |
byte[] buf = new byte[size]; |
|
598 |
if (inflate(cbuf, buf) != size) |
|
599 |
throw new ZipException("corrupted zip file"); |
|
600 |
||
601 |
return buf; |
|
602 |
} |
|
603 |
||
604 |
/** |
|
605 |
* |
|
606 |
*/ |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
607 |
private int readBytes(Entry entry, byte[] buffer) throws IOException { |
10 | 608 |
byte[] header = getHeader(entry); |
609 |
||
610 |
// entry is not compressed? |
|
611 |
if (get2ByteLittleEndian(header, 8) == 0) { |
|
612 |
zipRandomFile.skipBytes(get2ByteLittleEndian(header, 26) + get2ByteLittleEndian(header, 28)); |
|
613 |
int offset = 0; |
|
614 |
int size = buffer.length; |
|
615 |
while (offset < size) { |
|
616 |
int count = zipRandomFile.read(buffer, offset, size - offset); |
|
617 |
if (count == -1) |
|
618 |
break; |
|
619 |
offset += count; |
|
620 |
} |
|
621 |
return entry.size; |
|
622 |
} |
|
623 |
||
624 |
int csize = entry.compressedSize; |
|
625 |
byte[] cbuf = new byte[csize]; |
|
626 |
zipRandomFile.skipBytes(get2ByteLittleEndian(header, 26) + get2ByteLittleEndian(header, 28)); |
|
627 |
zipRandomFile.readFully(cbuf, 0, csize); |
|
628 |
||
629 |
int count = inflate(cbuf, buffer); |
|
630 |
if (count == -1) |
|
631 |
throw new ZipException("corrupted zip file"); |
|
632 |
||
633 |
return entry.size; |
|
634 |
} |
|
635 |
||
636 |
//---------------------------------------------------------------------------- |
|
637 |
// Zip utilities |
|
638 |
//---------------------------------------------------------------------------- |
|
639 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
640 |
private byte[] getHeader(Entry entry) throws IOException { |
10 | 641 |
zipRandomFile.seek(entry.offset); |
642 |
byte[] header = new byte[30]; |
|
643 |
zipRandomFile.readFully(header); |
|
644 |
if (get4ByteLittleEndian(header, 0) != 0x04034b50) |
|
645 |
throw new ZipException("corrupted zip file"); |
|
646 |
if ((get2ByteLittleEndian(header, 6) & 1) != 0) |
|
647 |
throw new ZipException("encrypted zip file"); // offset 6 in the header of the ZipFileEntry |
|
648 |
return header; |
|
649 |
} |
|
650 |
||
651 |
/* |
|
652 |
* Inflate using the java.util.zip.Inflater class |
|
653 |
*/ |
|
654 |
private static Inflater inflater; |
|
655 |
private int inflate(byte[] src, byte[] dest) { |
|
656 |
||
657 |
// construct the inflater object or reuse an existing one |
|
658 |
if (inflater == null) |
|
659 |
inflater = new Inflater(true); |
|
660 |
||
661 |
synchronized (inflater) { |
|
662 |
inflater.reset(); |
|
663 |
inflater.setInput(src); |
|
664 |
try { |
|
665 |
return inflater.inflate(dest); |
|
666 |
} catch (DataFormatException ex) { |
|
667 |
return -1; |
|
668 |
} |
|
669 |
} |
|
670 |
} |
|
671 |
||
672 |
/** |
|
673 |
* return the two bytes buf[pos], buf[pos+1] as an unsigned integer in little |
|
674 |
* endian format. |
|
675 |
*/ |
|
676 |
private static int get2ByteLittleEndian(byte[] buf, int pos) { |
|
677 |
return (buf[pos] & 0xFF) + ((buf[pos+1] & 0xFF) << 8); |
|
678 |
} |
|
679 |
||
680 |
/** |
|
681 |
* return the 4 bytes buf[i..i+3] as an integer in little endian format. |
|
682 |
*/ |
|
683 |
private static int get4ByteLittleEndian(byte[] buf, int pos) { |
|
684 |
return (buf[pos] & 0xFF) + ((buf[pos + 1] & 0xFF) << 8) + |
|
685 |
((buf[pos + 2] & 0xFF) << 16) + ((buf[pos + 3] & 0xFF) << 24); |
|
686 |
} |
|
687 |
||
688 |
/* ---------------------------------------------------------------------------- |
|
689 |
* ZipDirectory |
|
690 |
* ----------------------------------------------------------------------------*/ |
|
691 |
||
692 |
private class ZipDirectory { |
|
693 |
private String lastDir; |
|
694 |
private int lastStart; |
|
695 |
private int lastLen; |
|
696 |
||
697 |
byte[] zipDir; |
|
698 |
RandomAccessFile zipRandomFile = null; |
|
699 |
ZipFileIndex zipFileIndex = null; |
|
700 |
||
701 |
public ZipDirectory(RandomAccessFile zipRandomFile, long start, long end, ZipFileIndex index) throws IOException { |
|
702 |
this.zipRandomFile = zipRandomFile; |
|
703 |
this.zipFileIndex = index; |
|
704 |
||
705 |
findCENRecord(start, end); |
|
706 |
} |
|
707 |
||
708 |
/* |
|
709 |
* Reads zip file central directory. |
|
710 |
* For more details see readCEN in zip_util.c from the JDK sources. |
|
711 |
* This is a Java port of that function. |
|
712 |
*/ |
|
713 |
private void findCENRecord(long start, long end) throws IOException { |
|
714 |
long totalLength = end - start; |
|
715 |
int endbuflen = 1024; |
|
716 |
byte[] endbuf = new byte[endbuflen]; |
|
717 |
long endbufend = end - start; |
|
718 |
||
719 |
// There is a variable-length field after the dir offset record. We need to do consequential search. |
|
720 |
while (endbufend >= 22) { |
|
721 |
if (endbufend < endbuflen) |
|
722 |
endbuflen = (int)endbufend; |
|
723 |
long endbufpos = endbufend - endbuflen; |
|
724 |
zipRandomFile.seek(start + endbufpos); |
|
725 |
zipRandomFile.readFully(endbuf, 0, endbuflen); |
|
726 |
int i = endbuflen - 22; |
|
727 |
while (i >= 0 && |
|
728 |
!(endbuf[i] == 0x50 && |
|
729 |
endbuf[i + 1] == 0x4b && |
|
730 |
endbuf[i + 2] == 0x05 && |
|
731 |
endbuf[i + 3] == 0x06 && |
|
732 |
endbufpos + i + 22 + |
|
733 |
get2ByteLittleEndian(endbuf, i + 20) == totalLength)) { |
|
734 |
i--; |
|
735 |
} |
|
736 |
||
737 |
if (i >= 0) { |
|
738 |
zipDir = new byte[get4ByteLittleEndian(endbuf, i + 12) + 2]; |
|
739 |
zipDir[0] = endbuf[i + 10]; |
|
740 |
zipDir[1] = endbuf[i + 11]; |
|
741 |
zipRandomFile.seek(start + get4ByteLittleEndian(endbuf, i + 16)); |
|
742 |
zipRandomFile.readFully(zipDir, 2, zipDir.length - 2); |
|
743 |
return; |
|
744 |
} else { |
|
745 |
endbufend = endbufpos + 21; |
|
746 |
} |
|
747 |
} |
|
748 |
throw new ZipException("cannot read zip file"); |
|
749 |
} |
|
750 |
private void buildIndex() throws IOException { |
|
751 |
int entryCount = get2ByteLittleEndian(zipDir, 0); |
|
752 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
753 |
entries = new Entry[entryCount]; |
10 | 754 |
// Add each of the files |
755 |
if (entryCount > 0) { |
|
756 |
directories = new HashMap<String, DirectoryEntry>(); |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
757 |
ArrayList<Entry> entryList = new ArrayList<Entry>(); |
10 | 758 |
int pos = 2; |
759 |
for (int i = 0; i < entryCount; i++) { |
|
760 |
pos = readEntry(pos, entryList, directories); |
|
761 |
} |
|
762 |
||
763 |
// Add the accumulated dirs into the same list |
|
764 |
Iterator i = directories.keySet().iterator(); |
|
765 |
while (i.hasNext()) { |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
766 |
Entry zipFileIndexEntry = new Entry( (String) i.next()); |
10 | 767 |
zipFileIndexEntry.isDir = true; |
768 |
entryList.add(zipFileIndexEntry); |
|
769 |
} |
|
770 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
771 |
entries = entryList.toArray(new Entry[entryList.size()]); |
10 | 772 |
Arrays.sort(entries); |
773 |
} else { |
|
774 |
cleanupState(); |
|
775 |
} |
|
776 |
} |
|
777 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
778 |
private int readEntry(int pos, List<Entry> entryList, |
10 | 779 |
Map<String, DirectoryEntry> directories) throws IOException { |
780 |
if (get4ByteLittleEndian(zipDir, pos) != 0x02014b50) { |
|
781 |
throw new ZipException("cannot read zip file entry"); |
|
782 |
} |
|
783 |
||
784 |
int dirStart = pos + 46; |
|
785 |
int fileStart = dirStart; |
|
786 |
int fileEnd = fileStart + get2ByteLittleEndian(zipDir, pos + 28); |
|
787 |
||
788 |
if (zipFileIndex.symbolFilePrefixLength != 0 && |
|
789 |
((fileEnd - fileStart) >= symbolFilePrefixLength)) { |
|
790 |
dirStart += zipFileIndex.symbolFilePrefixLength; |
|
791 |
fileStart += zipFileIndex.symbolFilePrefixLength; |
|
792 |
} |
|
793 |
||
794 |
// Use the OS's path separator. Keep the position of the last one. |
|
795 |
for (int index = fileStart; index < fileEnd; index++) { |
|
796 |
byte nextByte = zipDir[index]; |
|
797 |
if (nextByte == (byte)'\\' || nextByte == (byte)'/') { |
|
798 |
zipDir[index] = (byte)File.separatorChar; |
|
799 |
fileStart = index + 1; |
|
800 |
} |
|
801 |
} |
|
802 |
||
803 |
String directory = null; |
|
804 |
if (fileStart == dirStart) |
|
805 |
directory = ""; |
|
806 |
else if (lastDir != null && lastLen == fileStart - dirStart - 1) { |
|
807 |
int index = lastLen - 1; |
|
808 |
while (zipDir[lastStart + index] == zipDir[dirStart + index]) { |
|
809 |
if (index == 0) { |
|
810 |
directory = lastDir; |
|
811 |
break; |
|
812 |
} |
|
813 |
index--; |
|
814 |
} |
|
815 |
} |
|
816 |
||
817 |
// Sub directories |
|
818 |
if (directory == null) { |
|
819 |
lastStart = dirStart; |
|
820 |
lastLen = fileStart - dirStart - 1; |
|
821 |
||
822 |
directory = new String(zipDir, dirStart, lastLen, "UTF-8").intern(); |
|
823 |
lastDir = directory; |
|
824 |
||
825 |
// Enter also all the parent directories |
|
826 |
String tempDirectory = directory; |
|
827 |
||
828 |
while (directories.get(tempDirectory) == null) { |
|
829 |
directories.put(tempDirectory, new DirectoryEntry(tempDirectory, zipFileIndex)); |
|
830 |
int separator = tempDirectory.lastIndexOf(File.separatorChar); |
|
831 |
if (separator == -1) |
|
832 |
break; |
|
833 |
tempDirectory = tempDirectory.substring(0, separator); |
|
834 |
} |
|
835 |
} |
|
836 |
else { |
|
837 |
directory = directory.intern(); |
|
838 |
if (directories.get(directory) == null) { |
|
839 |
directories.put(directory, new DirectoryEntry(directory, zipFileIndex)); |
|
840 |
} |
|
841 |
} |
|
842 |
||
843 |
// For each dir create also a file |
|
844 |
if (fileStart != fileEnd) { |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
845 |
Entry entry = new Entry(directory, |
10 | 846 |
new String(zipDir, fileStart, fileEnd - fileStart, "UTF-8")); |
847 |
||
848 |
entry.setNativeTime(get4ByteLittleEndian(zipDir, pos + 12)); |
|
849 |
entry.compressedSize = get4ByteLittleEndian(zipDir, pos + 20); |
|
850 |
entry.size = get4ByteLittleEndian(zipDir, pos + 24); |
|
851 |
entry.offset = get4ByteLittleEndian(zipDir, pos + 42); |
|
852 |
entryList.add(entry); |
|
853 |
} |
|
854 |
||
855 |
return pos + 46 + |
|
856 |
get2ByteLittleEndian(zipDir, pos + 28) + |
|
857 |
get2ByteLittleEndian(zipDir, pos + 30) + |
|
858 |
get2ByteLittleEndian(zipDir, pos + 32); |
|
859 |
} |
|
860 |
} |
|
861 |
||
862 |
/** |
|
863 |
* Returns the last modified timestamp of a zip file. |
|
864 |
* @return long |
|
865 |
*/ |
|
866 |
public long getZipFileLastModified() throws IOException { |
|
867 |
lock.lock(); |
|
868 |
try { |
|
869 |
checkIndex(); |
|
870 |
return zipFileLastModified; |
|
871 |
} |
|
872 |
finally { |
|
873 |
lock.unlock(); |
|
874 |
} |
|
875 |
} |
|
876 |
||
877 |
/** ------------------------------------------------------------------------ |
|
878 |
* DirectoryEntry class |
|
879 |
* -------------------------------------------------------------------------*/ |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
880 |
|
10 | 881 |
static class DirectoryEntry { |
882 |
private boolean filesInited; |
|
883 |
private boolean directoriesInited; |
|
884 |
private boolean zipFileEntriesInited; |
|
885 |
private boolean entriesInited; |
|
886 |
||
887 |
private long writtenOffsetOffset = 0; |
|
888 |
||
889 |
private String dirName; |
|
890 |
||
891 |
private com.sun.tools.javac.util.List<String> zipFileEntriesFiles = com.sun.tools.javac.util.List.<String>nil(); |
|
892 |
private com.sun.tools.javac.util.List<String> zipFileEntriesDirectories = com.sun.tools.javac.util.List.<String>nil(); |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
893 |
private com.sun.tools.javac.util.List<Entry> zipFileEntries = com.sun.tools.javac.util.List.<Entry>nil(); |
10 | 894 |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
895 |
private List<Entry> entries = new ArrayList<Entry>(); |
10 | 896 |
|
897 |
private ZipFileIndex zipFileIndex; |
|
898 |
||
899 |
private int numEntries; |
|
900 |
||
901 |
DirectoryEntry(String dirName, ZipFileIndex index) { |
|
902 |
filesInited = false; |
|
903 |
directoriesInited = false; |
|
904 |
entriesInited = false; |
|
905 |
||
906 |
if (File.separatorChar == '/') { |
|
907 |
dirName.replace('\\', '/'); |
|
908 |
} |
|
909 |
else { |
|
910 |
dirName.replace('/', '\\'); |
|
911 |
} |
|
912 |
||
913 |
this.dirName = dirName.intern(); |
|
914 |
this.zipFileIndex = index; |
|
915 |
} |
|
916 |
||
917 |
private com.sun.tools.javac.util.List<String> getFiles() { |
|
918 |
if (filesInited) { |
|
919 |
return zipFileEntriesFiles; |
|
920 |
} |
|
921 |
||
922 |
initEntries(); |
|
923 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
924 |
for (Entry e : entries) { |
10 | 925 |
if (!e.isDir) { |
926 |
zipFileEntriesFiles = zipFileEntriesFiles.append(e.name); |
|
927 |
} |
|
928 |
} |
|
929 |
filesInited = true; |
|
930 |
return zipFileEntriesFiles; |
|
931 |
} |
|
932 |
||
933 |
private com.sun.tools.javac.util.List<String> getDirectories() { |
|
934 |
if (directoriesInited) { |
|
935 |
return zipFileEntriesFiles; |
|
936 |
} |
|
937 |
||
938 |
initEntries(); |
|
939 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
940 |
for (Entry e : entries) { |
10 | 941 |
if (e.isDir) { |
942 |
zipFileEntriesDirectories = zipFileEntriesDirectories.append(e.name); |
|
943 |
} |
|
944 |
} |
|
945 |
||
946 |
directoriesInited = true; |
|
947 |
||
948 |
return zipFileEntriesDirectories; |
|
949 |
} |
|
950 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
951 |
private com.sun.tools.javac.util.List<Entry> getEntries() { |
10 | 952 |
if (zipFileEntriesInited) { |
953 |
return zipFileEntries; |
|
954 |
} |
|
955 |
||
956 |
initEntries(); |
|
957 |
||
958 |
zipFileEntries = com.sun.tools.javac.util.List.nil(); |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
959 |
for (Entry zfie : entries) { |
10 | 960 |
zipFileEntries = zipFileEntries.append(zfie); |
961 |
} |
|
962 |
||
963 |
zipFileEntriesInited = true; |
|
964 |
||
965 |
return zipFileEntries; |
|
966 |
} |
|
967 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
968 |
private Entry getEntry(String rootName) { |
10 | 969 |
initEntries(); |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
970 |
int index = Collections.binarySearch(entries, new Entry(dirName, rootName)); |
10 | 971 |
if (index < 0) { |
972 |
return null; |
|
973 |
} |
|
974 |
||
975 |
return entries.get(index); |
|
976 |
} |
|
977 |
||
978 |
private void initEntries() { |
|
979 |
if (entriesInited) { |
|
980 |
return; |
|
981 |
} |
|
982 |
||
983 |
if (!zipFileIndex.readFromIndex) { |
|
984 |
int from = -Arrays.binarySearch(zipFileIndex.entries, |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
985 |
new Entry(dirName, ZipFileIndex.MIN_CHAR)) - 1; |
10 | 986 |
int to = -Arrays.binarySearch(zipFileIndex.entries, |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
987 |
new Entry(dirName, MAX_CHAR)) - 1; |
10 | 988 |
|
989 |
boolean emptyList = false; |
|
990 |
||
991 |
for (int i = from; i < to; i++) { |
|
992 |
entries.add(zipFileIndex.entries[i]); |
|
993 |
} |
|
994 |
} else { |
|
995 |
File indexFile = zipFileIndex.getIndexFile(); |
|
996 |
if (indexFile != null) { |
|
997 |
RandomAccessFile raf = null; |
|
998 |
try { |
|
999 |
raf = new RandomAccessFile(indexFile, "r"); |
|
1000 |
raf.seek(writtenOffsetOffset); |
|
1001 |
||
1002 |
for (int nFiles = 0; nFiles < numEntries; nFiles++) { |
|
1003 |
// Read the name bytes |
|
1004 |
int zfieNameBytesLen = raf.readInt(); |
|
1005 |
byte [] zfieNameBytes = new byte[zfieNameBytesLen]; |
|
1006 |
raf.read(zfieNameBytes); |
|
1007 |
String eName = new String(zfieNameBytes, "UTF-8"); |
|
1008 |
||
1009 |
// Read isDir |
|
1010 |
boolean eIsDir = raf.readByte() == (byte)0 ? false : true; |
|
1011 |
||
1012 |
// Read offset of bytes in the real Jar/Zip file |
|
1013 |
int eOffset = raf.readInt(); |
|
1014 |
||
1015 |
// Read size of the file in the real Jar/Zip file |
|
1016 |
int eSize = raf.readInt(); |
|
1017 |
||
1018 |
// Read compressed size of the file in the real Jar/Zip file |
|
1019 |
int eCsize = raf.readInt(); |
|
1020 |
||
1021 |
// Read java time stamp of the file in the real Jar/Zip file |
|
1022 |
long eJavaTimestamp = raf.readLong(); |
|
1023 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1024 |
Entry rfie = new Entry(dirName, eName); |
10 | 1025 |
rfie.isDir = eIsDir; |
1026 |
rfie.offset = eOffset; |
|
1027 |
rfie.size = eSize; |
|
1028 |
rfie.compressedSize = eCsize; |
|
1029 |
rfie.javatime = eJavaTimestamp; |
|
1030 |
entries.add(rfie); |
|
1031 |
} |
|
1032 |
} catch (Throwable t) { |
|
1033 |
// Do nothing |
|
1034 |
} finally { |
|
1035 |
try { |
|
1036 |
if (raf == null) { |
|
1037 |
raf.close(); |
|
1038 |
} |
|
1039 |
} catch (Throwable t) { |
|
1040 |
// Do nothing |
|
1041 |
} |
|
1042 |
} |
|
1043 |
} |
|
1044 |
} |
|
1045 |
||
1046 |
entriesInited = true; |
|
1047 |
} |
|
1048 |
||
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1049 |
List<Entry> getEntriesAsCollection() { |
10 | 1050 |
initEntries(); |
1051 |
||
1052 |
return entries; |
|
1053 |
} |
|
1054 |
} |
|
1055 |
||
1056 |
private boolean readIndex() { |
|
1057 |
if (triedToReadIndex || !usePreindexedCache) { |
|
1058 |
return false; |
|
1059 |
} |
|
1060 |
||
1061 |
boolean ret = false; |
|
1062 |
lock.lock(); |
|
1063 |
try { |
|
1064 |
triedToReadIndex = true; |
|
1065 |
RandomAccessFile raf = null; |
|
1066 |
try { |
|
1067 |
File indexFileName = getIndexFile(); |
|
1068 |
raf = new RandomAccessFile(indexFileName, "r"); |
|
1069 |
||
1070 |
long fileStamp = raf.readLong(); |
|
1071 |
if (zipFile.lastModified() != fileStamp) { |
|
1072 |
ret = false; |
|
1073 |
} else { |
|
1074 |
directories = new HashMap<String, DirectoryEntry>(); |
|
1075 |
int numDirs = raf.readInt(); |
|
1076 |
for (int nDirs = 0; nDirs < numDirs; nDirs++) { |
|
1077 |
int dirNameBytesLen = raf.readInt(); |
|
1078 |
byte [] dirNameBytes = new byte[dirNameBytesLen]; |
|
1079 |
raf.read(dirNameBytes); |
|
1080 |
||
1081 |
String dirNameStr = new String(dirNameBytes, "UTF-8"); |
|
1082 |
DirectoryEntry de = new DirectoryEntry(dirNameStr, this); |
|
1083 |
de.numEntries = raf.readInt(); |
|
1084 |
de.writtenOffsetOffset = raf.readLong(); |
|
1085 |
directories.put(dirNameStr, de); |
|
1086 |
} |
|
1087 |
ret = true; |
|
1088 |
zipFileLastModified = fileStamp; |
|
1089 |
} |
|
1090 |
} catch (Throwable t) { |
|
1091 |
// Do nothing |
|
1092 |
} finally { |
|
1093 |
if (raf != null) { |
|
1094 |
try { |
|
1095 |
raf.close(); |
|
1096 |
} catch (Throwable tt) { |
|
1097 |
// Do nothing |
|
1098 |
} |
|
1099 |
} |
|
1100 |
} |
|
1101 |
if (ret == true) { |
|
1102 |
readFromIndex = true; |
|
1103 |
} |
|
1104 |
} |
|
1105 |
finally { |
|
1106 |
lock.unlock(); |
|
1107 |
} |
|
1108 |
||
1109 |
return ret; |
|
1110 |
} |
|
1111 |
||
1112 |
private boolean writeIndex() { |
|
1113 |
boolean ret = false; |
|
1114 |
if (readFromIndex || !usePreindexedCache) { |
|
1115 |
return true; |
|
1116 |
} |
|
1117 |
||
1118 |
if (!writeIndex) { |
|
1119 |
return true; |
|
1120 |
} |
|
1121 |
||
1122 |
File indexFile = getIndexFile(); |
|
1123 |
if (indexFile == null) { |
|
1124 |
return false; |
|
1125 |
} |
|
1126 |
||
1127 |
RandomAccessFile raf = null; |
|
1128 |
long writtenSoFar = 0; |
|
1129 |
try { |
|
1130 |
raf = new RandomAccessFile(indexFile, "rw"); |
|
1131 |
||
1132 |
raf.writeLong(zipFileLastModified); |
|
1133 |
writtenSoFar += 8; |
|
1134 |
||
1135 |
||
1136 |
Iterator<String> iterDirName = directories.keySet().iterator(); |
|
1137 |
List<DirectoryEntry> directoriesToWrite = new ArrayList<DirectoryEntry>(); |
|
1138 |
Map<String, Long> offsets = new HashMap<String, Long>(); |
|
1139 |
raf.writeInt(directories.keySet().size()); |
|
1140 |
writtenSoFar += 4; |
|
1141 |
||
1142 |
while(iterDirName.hasNext()) { |
|
1143 |
String dirName = iterDirName.next(); |
|
1144 |
DirectoryEntry dirEntry = directories.get(dirName); |
|
1145 |
||
1146 |
directoriesToWrite.add(dirEntry); |
|
1147 |
||
1148 |
// Write the dir name bytes |
|
1149 |
byte [] dirNameBytes = dirName.getBytes("UTF-8"); |
|
1150 |
int dirNameBytesLen = dirNameBytes.length; |
|
1151 |
raf.writeInt(dirNameBytesLen); |
|
1152 |
writtenSoFar += 4; |
|
1153 |
||
1154 |
raf.write(dirNameBytes); |
|
1155 |
writtenSoFar += dirNameBytesLen; |
|
1156 |
||
1157 |
// Write the number of files in the dir |
|
1158 |
List dirEntries = dirEntry.getEntriesAsCollection(); |
|
1159 |
raf.writeInt(dirEntries.size()); |
|
1160 |
writtenSoFar += 4; |
|
1161 |
||
1162 |
offsets.put(dirName, new Long(writtenSoFar)); |
|
1163 |
||
1164 |
// Write the offset of the file's data in the dir |
|
1165 |
dirEntry.writtenOffsetOffset = 0L; |
|
1166 |
raf.writeLong(0L); |
|
1167 |
writtenSoFar += 8; |
|
1168 |
} |
|
1169 |
||
1170 |
for (DirectoryEntry de : directoriesToWrite) { |
|
1171 |
// Fix up the offset in the directory table |
|
1172 |
long currFP = raf.getFilePointer(); |
|
1173 |
||
1174 |
long offsetOffset = offsets.get(de.dirName).longValue(); |
|
1175 |
raf.seek(offsetOffset); |
|
1176 |
raf.writeLong(writtenSoFar); |
|
1177 |
||
1178 |
raf.seek(currFP); |
|
1179 |
||
1180 |
// Now write each of the files in the DirectoryEntry |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1181 |
List<Entry> entries = de.getEntriesAsCollection(); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1182 |
for (Entry zfie : entries) { |
10 | 1183 |
// Write the name bytes |
1184 |
byte [] zfieNameBytes = zfie.name.getBytes("UTF-8"); |
|
1185 |
int zfieNameBytesLen = zfieNameBytes.length; |
|
1186 |
raf.writeInt(zfieNameBytesLen); |
|
1187 |
writtenSoFar += 4; |
|
1188 |
raf.write(zfieNameBytes); |
|
1189 |
writtenSoFar += zfieNameBytesLen; |
|
1190 |
||
1191 |
// Write isDir |
|
1192 |
raf.writeByte(zfie.isDir ? (byte)1 : (byte)0); |
|
1193 |
writtenSoFar += 1; |
|
1194 |
||
1195 |
// Write offset of bytes in the real Jar/Zip file |
|
1196 |
raf.writeInt(zfie.offset); |
|
1197 |
writtenSoFar += 4; |
|
1198 |
||
1199 |
// Write size of the file in the real Jar/Zip file |
|
1200 |
raf.writeInt(zfie.size); |
|
1201 |
writtenSoFar += 4; |
|
1202 |
||
1203 |
// Write compressed size of the file in the real Jar/Zip file |
|
1204 |
raf.writeInt(zfie.compressedSize); |
|
1205 |
writtenSoFar += 4; |
|
1206 |
||
1207 |
// Write java time stamp of the file in the real Jar/Zip file |
|
1208 |
raf.writeLong(zfie.getLastModified()); |
|
1209 |
writtenSoFar += 8; |
|
1210 |
} |
|
1211 |
} |
|
1212 |
} catch (Throwable t) { |
|
1213 |
// Do nothing |
|
1214 |
} finally { |
|
1215 |
try { |
|
1216 |
if (raf != null) { |
|
1217 |
raf.close(); |
|
1218 |
} |
|
1219 |
} catch(IOException ioe) { |
|
1220 |
// Do nothing |
|
1221 |
} |
|
1222 |
} |
|
1223 |
||
1224 |
return ret; |
|
1225 |
} |
|
1226 |
||
1227 |
public boolean writeZipIndex() { |
|
1228 |
lock.lock(); |
|
1229 |
try { |
|
1230 |
return writeIndex(); |
|
1231 |
} |
|
1232 |
finally { |
|
1233 |
lock.unlock(); |
|
1234 |
} |
|
1235 |
} |
|
1236 |
||
1237 |
private File getIndexFile() { |
|
1238 |
if (zipIndexFile == null) { |
|
1239 |
if (zipFile == null) { |
|
1240 |
return null; |
|
1241 |
} |
|
1242 |
||
1243 |
zipIndexFile = new File((preindexedCacheLocation == null ? "" : preindexedCacheLocation) + |
|
1244 |
zipFile.getName() + ".index"); |
|
1245 |
} |
|
1246 |
||
1247 |
return zipIndexFile; |
|
1248 |
} |
|
1249 |
||
1250 |
public File getZipFile() { |
|
1251 |
return zipFile; |
|
1252 |
} |
|
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1253 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1254 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1255 |
static class Entry implements Comparable<Entry> { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1256 |
public static final Entry[] EMPTY_ARRAY = {}; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1257 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1258 |
// Directory related |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1259 |
String dir; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1260 |
boolean isDir; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1261 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1262 |
// File related |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1263 |
String name; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1264 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1265 |
int offset; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1266 |
int size; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1267 |
int compressedSize; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1268 |
long javatime; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1269 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1270 |
private int nativetime; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1271 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1272 |
public Entry(String path) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1273 |
int separator = path.lastIndexOf(File.separatorChar); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1274 |
if (separator == -1) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1275 |
dir = "".intern(); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1276 |
name = path; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1277 |
} else { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1278 |
dir = path.substring(0, separator).intern(); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1279 |
name = path.substring(separator + 1); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1280 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1281 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1282 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1283 |
public Entry(String directory, String name) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1284 |
this.dir = directory.intern(); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1285 |
this.name = name; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1286 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1287 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1288 |
public String getName() { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1289 |
if (dir == null || dir.length() == 0) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1290 |
return name; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1291 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1292 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1293 |
StringBuilder sb = new StringBuilder(); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1294 |
sb.append(dir); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1295 |
sb.append(File.separatorChar); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1296 |
sb.append(name); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1297 |
return sb.toString(); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1298 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1299 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1300 |
public String getFileName() { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1301 |
return name; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1302 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1303 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1304 |
public long getLastModified() { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1305 |
if (javatime == 0) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1306 |
javatime = dosToJavaTime(nativetime); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1307 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1308 |
return javatime; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1309 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1310 |
|
865
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
810
diff
changeset
|
1311 |
// based on dosToJavaTime in java.util.Zip, but avoiding the |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
810
diff
changeset
|
1312 |
// use of deprecated Date constructor |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
810
diff
changeset
|
1313 |
private static long dosToJavaTime(int dtime) { |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
810
diff
changeset
|
1314 |
Calendar c = Calendar.getInstance(); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
810
diff
changeset
|
1315 |
c.set(Calendar.YEAR, ((dtime >> 25) & 0x7f) + 1980); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
810
diff
changeset
|
1316 |
c.set(Calendar.MONTH, ((dtime >> 21) & 0x0f) - 1); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
810
diff
changeset
|
1317 |
c.set(Calendar.DATE, ((dtime >> 16) & 0x1f)); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
810
diff
changeset
|
1318 |
c.set(Calendar.HOUR_OF_DAY, ((dtime >> 11) & 0x1f)); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
810
diff
changeset
|
1319 |
c.set(Calendar.MINUTE, ((dtime >> 5) & 0x3f)); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
810
diff
changeset
|
1320 |
c.set(Calendar.SECOND, ((dtime << 1) & 0x3e)); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
810
diff
changeset
|
1321 |
c.set(Calendar.MILLISECOND, 0); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
810
diff
changeset
|
1322 |
return c.getTimeInMillis(); |
810
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1323 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1324 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1325 |
void setNativeTime(int natTime) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1326 |
nativetime = natTime; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1327 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1328 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1329 |
public boolean isDirectory() { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1330 |
return isDir; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1331 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1332 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1333 |
public int compareTo(Entry other) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1334 |
String otherD = other.dir; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1335 |
if (dir != otherD) { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1336 |
int c = dir.compareTo(otherD); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1337 |
if (c != 0) |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1338 |
return c; |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1339 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1340 |
return name.compareTo(other.name); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1341 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1342 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1343 |
|
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1344 |
public String toString() { |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1345 |
return isDir ? ("Dir:" + dir + " : " + name) : |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1346 |
(dir + ":" + name); |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1347 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1348 |
} |
e4b6a6d206e6
6714365: refactor JavacFileManager to move nested classes to top level
jjg
parents:
731
diff
changeset
|
1349 |
|
10 | 1350 |
} |