author | jjg |
Mon, 11 Jan 2010 14:05:21 -0800 | |
changeset 4699 | e58edf3542b3 |
parent 1205 | b316e32eb90c |
child 5520 | 86e4b9a9da40 |
permissions | -rw-r--r-- |
865
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
1 |
/* |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
2 |
* Copyright 2008 Sun Microsystems, Inc. All Rights Reserved. |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
4 |
* |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
5 |
* This code is free software; you can redistribute it and/or modify it |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
7 |
* published by the Free Software Foundation. |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
8 |
* |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
9 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
10 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
11 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
12 |
* version 2 for more details (a copy is included in the LICENSE file that |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
13 |
* accompanied this code). |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
14 |
* |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License version |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
16 |
* 2 along with this work; if not, write to the Free Software Foundation, |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
17 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
18 |
* |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
19 |
* Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
20 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
21 |
* have any questions. |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
22 |
*/ |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
23 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
24 |
/* |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
25 |
* @test |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
26 |
* @bug 6725036 |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
27 |
* @summary javac returns incorrect value for lastModifiedTime() when |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
28 |
* source is a zip file archive |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
29 |
*/ |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
30 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
31 |
import java.io.File; |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
32 |
import java.util.Date; |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
33 |
import java.util.jar.JarEntry; |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
34 |
import java.util.jar.JarFile; |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
35 |
import javax.tools.JavaFileObject; |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
36 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
37 |
import com.sun.tools.javac.file.JavacFileManager; |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
865
diff
changeset
|
38 |
import com.sun.tools.javac.file.RelativePath.RelativeFile; |
865
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
39 |
import com.sun.tools.javac.file.ZipFileIndex; |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
40 |
import com.sun.tools.javac.file.ZipFileIndexArchive; |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
41 |
import com.sun.tools.javac.util.Context; |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
42 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
43 |
public class T6725036 { |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
44 |
public static void main(String... args) throws Exception { |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
45 |
new T6725036().run(); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
46 |
} |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
47 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
48 |
void run() throws Exception { |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
865
diff
changeset
|
49 |
RelativeFile TEST_ENTRY_NAME = new RelativeFile("java/lang/String.class"); |
865
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
50 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
51 |
File f = new File(System.getProperty("java.home")); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
52 |
if (!f.getName().equals("jre")) |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
53 |
f = new File(f, "jre"); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
54 |
File rt_jar = new File(new File(f, "lib"), "rt.jar"); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
55 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
56 |
JarFile j = new JarFile(rt_jar); |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
865
diff
changeset
|
57 |
JarEntry je = j.getJarEntry(TEST_ENTRY_NAME.getPath()); |
865
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
58 |
long jarEntryTime = je.getTime(); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
59 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
60 |
ZipFileIndex zfi = |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
61 |
ZipFileIndex.getZipFileIndex(rt_jar, null, false, null, false); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
62 |
long zfiTime = zfi.getLastModified(TEST_ENTRY_NAME); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
63 |
|
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
865
diff
changeset
|
64 |
check(je, jarEntryTime, zfi + ":" + TEST_ENTRY_NAME.getPath(), zfiTime); |
865
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
65 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
66 |
Context context = new Context(); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
67 |
JavacFileManager fm = new JavacFileManager(context, false, null); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
68 |
ZipFileIndexArchive zfia = new ZipFileIndexArchive(fm, zfi); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
69 |
JavaFileObject jfo = |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
865
diff
changeset
|
70 |
zfia.getFileObject(TEST_ENTRY_NAME.dirname(), |
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
865
diff
changeset
|
71 |
TEST_ENTRY_NAME.basename()); |
865
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
72 |
long jfoTime = jfo.getLastModified(); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
73 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
74 |
check(je, jarEntryTime, jfo, jfoTime); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
75 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
76 |
if (errors > 0) |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
77 |
throw new Exception(errors + " occurred"); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
78 |
} |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
79 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
80 |
void check(Object ref, long refTime, Object test, long testTime) { |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
81 |
if (refTime == testTime) |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
82 |
return; |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
83 |
System.err.println("Error: "); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
84 |
System.err.println("Expected: " + getText(ref, refTime)); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
85 |
System.err.println(" Found: " + getText(test, testTime)); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
86 |
errors++; |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
87 |
} |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
88 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
89 |
String getText(Object x, long t) { |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
90 |
return String.format("%14d", t) + " (" + new Date(t) + ") from " + x; |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
91 |
} |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
92 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
93 |
int errors; |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
94 |
} |