langtools/test/tools/sjavac/SJavacWrapper.java
changeset 15380 ac6c46b447d1
parent 15368 2577ddb7e710
child 24067 76e7b6bbbd85
equal deleted inserted replaced
15379:c483442d0939 15380:ac6c46b447d1
       
     1 /*
       
     2  * Copyright (c) 2013, Oracle and/or its affiliates. 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 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.
       
    22  */
       
    23 
       
    24 /*
       
    25  * @test
       
    26  * @summary Test all aspects of sjavac.
       
    27  *
       
    28  * @bug 8004658
       
    29  * @summary Add internal smart javac wrapper to solve JEP 139
       
    30  *
       
    31  * @run main SJavacWrapper
       
    32  */
       
    33 
       
    34 import java.io.*;
       
    35 import java.lang.reflect.Method;
       
    36 import java.net.*;
       
    37 
       
    38 
       
    39 public
       
    40 class SJavacWrapper {
       
    41 
       
    42     public static void main(String... args) throws Exception {
       
    43         URL url = SJavacWrapper.class.getClassLoader().getResource("com/sun/tools/sjavac/Main.class");
       
    44         if (url == null) {
       
    45             // No sjavac in the classpath.
       
    46             System.out.println("sjavac not available: pass by default");
       
    47             return;
       
    48         }
       
    49 
       
    50         File testSrc = new File(System.getProperty("test.src"));
       
    51         File sjavac_java = new File(testSrc, "SJavac.java");
       
    52         File testClasses = new File(System.getProperty("test.classes"));
       
    53         File sjavac_class = new File(testClasses, "SJavac.class");
       
    54         if (sjavac_class.lastModified() < sjavac_java.lastModified()) {
       
    55             String[] javac_args = { "-d", testClasses.getPath(), sjavac_java.getPath() };
       
    56             System.err.println("Recompiling SJavac.java");
       
    57             int rc = com.sun.tools.javac.Main.compile(javac_args);
       
    58             if (rc != 0)
       
    59                 throw new Exception("compilation failed");
       
    60         }
       
    61 
       
    62         Class<?> sjavac = Class.forName("SJavac");
       
    63         Method sjavac_main = sjavac.getMethod("main", String[].class);
       
    64         sjavac_main.invoke(null, new Object[] { args });
       
    65     }
       
    66 
       
    67 }