author | mcimadamore |
Wed, 26 Oct 2016 15:41:25 +0100 | |
changeset 41856 | 13a056e8f16e |
parent 36778 | e04318f39f92 |
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 |
/* |
36526 | 2 |
* Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved. |
865
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 |
* |
5520 | 19 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
20 |
* or visit www.oracle.com if you need additional information or have any |
|
21 |
* questions. |
|
865
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 |
26527
e422a50bf4f9
8055996: Remove @ignore from tools/javac/T6725036.java
sogoel
parents:
22448
diff
changeset
|
26 |
* @bug 6725036 8016760 |
865
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 |
27579 | 29 |
* @library /tools/lib |
30730
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27858
diff
changeset
|
30 |
* @modules jdk.compiler/com.sun.tools.javac.api |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27858
diff
changeset
|
31 |
* jdk.compiler/com.sun.tools.javac.file |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27858
diff
changeset
|
32 |
* jdk.compiler/com.sun.tools.javac.main |
d3ce7619db2c
8076543: Add @modules as needed to the langtools tests
akulyakh
parents:
27858
diff
changeset
|
33 |
* jdk.compiler/com.sun.tools.javac.util |
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
34 |
* @build toolbox.ToolBox toolbox.JarTask |
27579 | 35 |
* @run main T6725036 |
865
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 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
38 |
import java.io.File; |
27579 | 39 |
import java.io.IOException; |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
30730
diff
changeset
|
40 |
import java.util.Collections; |
865
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
41 |
import java.util.Date; |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
42 |
import java.util.jar.JarEntry; |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
43 |
import java.util.jar.JarFile; |
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
30730
diff
changeset
|
44 |
|
27579 | 45 |
import javax.tools.*; |
865
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 |
import com.sun.tools.javac.file.JavacFileManager; |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
865
diff
changeset
|
48 |
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
|
49 |
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
|
50 |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
51 |
import toolbox.JarTask; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
52 |
import toolbox.ToolBox; |
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
53 |
|
865
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
54 |
public class T6725036 { |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
55 |
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
|
56 |
new T6725036().run(); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
57 |
} |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
58 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
59 |
void run() throws Exception { |
1205
b316e32eb90c
6508981: cleanup file separator handling in JavacFileManager
jjg
parents:
865
diff
changeset
|
60 |
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
|
61 |
|
27579 | 62 |
File testJar = createJar("test.jar", "java.lang.*"); |
63 |
||
64 |
try (JarFile j = new JarFile(testJar)) { |
|
65 |
JarEntry je = j.getJarEntry(TEST_ENTRY_NAME.getPath()); |
|
66 |
long jarEntryTime = je.getTime(); |
|
865
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
67 |
|
27579 | 68 |
Context context = new Context(); |
69 |
JavacFileManager fm = new JavacFileManager(context, false, null); |
|
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
30730
diff
changeset
|
70 |
fm.setLocation(StandardLocation.CLASS_PATH, Collections.singletonList(testJar)); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
30730
diff
changeset
|
71 |
FileObject fo = |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
30730
diff
changeset
|
72 |
fm.getFileForInput(StandardLocation.CLASS_PATH, "", TEST_ENTRY_NAME.getPath()); |
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
30730
diff
changeset
|
73 |
long jfoTime = fo.getLastModified(); |
27579 | 74 |
|
34560
b6a567b677f7
8059976: Convert JavacFileManager to use java.nio.file internally
jjg
parents:
30730
diff
changeset
|
75 |
check(je, jarEntryTime, fo, jfoTime); |
865
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
76 |
|
27579 | 77 |
if (errors > 0) |
78 |
throw new Exception(errors + " occurred"); |
|
79 |
} |
|
80 |
} |
|
865
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
81 |
|
27579 | 82 |
File createJar(String name, String... paths) throws IOException { |
83 |
JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); |
|
84 |
try (JavaFileManager fm = comp.getStandardFileManager(null, null, null)) { |
|
85 |
File f = new File(name); |
|
86 |
ToolBox tb = new ToolBox(); |
|
36778
e04318f39f92
8152897: refactor ToolBox to allow reduced documented dependencies
jjg
parents:
36526
diff
changeset
|
87 |
new JarTask(tb, name) |
27579 | 88 |
.files(fm, StandardLocation.PLATFORM_CLASS_PATH, paths) |
89 |
.run(); |
|
90 |
return f; |
|
91 |
} |
|
865
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 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
94 |
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
|
95 |
if (refTime == testTime) |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
96 |
return; |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
97 |
System.err.println("Error: "); |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
98 |
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
|
99 |
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
|
100 |
errors++; |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
101 |
} |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
102 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
103 |
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
|
104 |
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
|
105 |
} |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
106 |
|
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
107 |
int errors; |
21668f049d28
6725036: javac returns incorrect value for lastModifiedTime() when source is a zip file archive
jjg
parents:
diff
changeset
|
108 |
} |