test/tools/javac/T6725036.java

Wed, 27 May 2009 22:34:43 -0700

author
darcy
date
Wed, 27 May 2009 22:34:43 -0700
changeset 289
84061bd68019
parent 103
e571266ae14f
child 554
9d9f26857129
permissions
-rw-r--r--

6843761: Update langtools tests to remove unncessary -source and -target options
Reviewed-by: jjg

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

mercurial