jjg@71: /* ksrini@2227: * Copyright (c) 2008, 2013, Oracle and/or its affiliates. All rights reserved. jjg@71: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. jjg@71: * jjg@71: * This code is free software; you can redistribute it and/or modify it jjg@71: * under the terms of the GNU General Public License version 2 only, as jjg@71: * published by the Free Software Foundation. jjg@71: * jjg@71: * This code is distributed in the hope that it will be useful, but WITHOUT jjg@71: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or jjg@71: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License jjg@71: * version 2 for more details (a copy is included in the LICENSE file that jjg@71: * accompanied this code). jjg@71: * jjg@71: * You should have received a copy of the GNU General Public License version jjg@71: * 2 along with this work; if not, write to the Free Software Foundation, jjg@71: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. jjg@71: * ohair@554: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohair@554: * or visit www.oracle.com if you need additional information or have any ohair@554: * questions. jjg@71: */ jjg@71: jjg@71: /* jjg@71: * @test jjg@71: * @bug 6725036 emc@1870: * @ignore 8016760: failure of regression test langtools/tools/javac/T6725036.java jjg@71: * @summary javac returns incorrect value for lastModifiedTime() when jjg@71: * source is a zip file archive jjg@71: */ jjg@71: jjg@71: import java.io.File; jjg@71: import java.util.Date; jjg@71: import java.util.jar.JarEntry; jjg@71: import java.util.jar.JarFile; jjg@71: import javax.tools.JavaFileObject; jjg@71: jjg@71: import com.sun.tools.javac.file.JavacFileManager; jjg@103: import com.sun.tools.javac.file.RelativePath.RelativeFile; jjg@71: import com.sun.tools.javac.file.ZipFileIndex; jjg@71: import com.sun.tools.javac.file.ZipFileIndexArchive; jjg@839: import com.sun.tools.javac.file.ZipFileIndexCache; jjg@71: import com.sun.tools.javac.util.Context; jjg@71: jjg@71: public class T6725036 { jjg@71: public static void main(String... args) throws Exception { jjg@71: new T6725036().run(); jjg@71: } jjg@71: jjg@71: void run() throws Exception { jjg@103: RelativeFile TEST_ENTRY_NAME = new RelativeFile("java/lang/String.class"); jjg@71: jjg@71: File f = new File(System.getProperty("java.home")); jjg@71: if (!f.getName().equals("jre")) jjg@71: f = new File(f, "jre"); jjg@71: File rt_jar = new File(new File(f, "lib"), "rt.jar"); jjg@71: jjg@71: JarFile j = new JarFile(rt_jar); jjg@103: JarEntry je = j.getJarEntry(TEST_ENTRY_NAME.getPath()); jjg@71: long jarEntryTime = je.getTime(); jjg@71: jjg@839: ZipFileIndexCache zfic = ZipFileIndexCache.getSharedInstance(); jjg@839: ZipFileIndex zfi = zfic.getZipFileIndex(rt_jar, null, false, null, false); jjg@71: long zfiTime = zfi.getLastModified(TEST_ENTRY_NAME); jjg@71: jjg@103: check(je, jarEntryTime, zfi + ":" + TEST_ENTRY_NAME.getPath(), zfiTime); jjg@71: jjg@71: Context context = new Context(); jjg@71: JavacFileManager fm = new JavacFileManager(context, false, null); jjg@71: ZipFileIndexArchive zfia = new ZipFileIndexArchive(fm, zfi); jjg@71: JavaFileObject jfo = jjg@103: zfia.getFileObject(TEST_ENTRY_NAME.dirname(), jjg@103: TEST_ENTRY_NAME.basename()); jjg@71: long jfoTime = jfo.getLastModified(); jjg@71: jjg@71: check(je, jarEntryTime, jfo, jfoTime); jjg@71: jjg@71: if (errors > 0) jjg@71: throw new Exception(errors + " occurred"); jjg@71: } jjg@71: jjg@71: void check(Object ref, long refTime, Object test, long testTime) { jjg@71: if (refTime == testTime) jjg@71: return; jjg@71: System.err.println("Error: "); jjg@71: System.err.println("Expected: " + getText(ref, refTime)); jjg@71: System.err.println(" Found: " + getText(test, testTime)); jjg@71: errors++; jjg@71: } jjg@71: jjg@71: String getText(Object x, long t) { jjg@71: return String.format("%14d", t) + " (" + new Date(t) + ") from " + x; jjg@71: } jjg@71: jjg@71: int errors; jjg@71: }