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