Fri, 28 Apr 2017 14:30:11 -0700
Merge
ohrstrom@1504 | 1 | /* |
ohrstrom@1504 | 2 | * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. |
ohrstrom@1504 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
ohrstrom@1504 | 4 | * |
ohrstrom@1504 | 5 | * This code is free software; you can redistribute it and/or modify it |
ohrstrom@1504 | 6 | * under the terms of the GNU General Public License version 2 only, as |
ohrstrom@1504 | 7 | * published by the Free Software Foundation. |
ohrstrom@1504 | 8 | * |
ohrstrom@1504 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
ohrstrom@1504 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
ohrstrom@1504 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
ohrstrom@1504 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
ohrstrom@1504 | 13 | * accompanied this code). |
ohrstrom@1504 | 14 | * |
ohrstrom@1504 | 15 | * You should have received a copy of the GNU General Public License version |
ohrstrom@1504 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
ohrstrom@1504 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
ohrstrom@1504 | 18 | * |
ohrstrom@1504 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
ohrstrom@1504 | 20 | * or visit www.oracle.com if you need additional information or have any |
ohrstrom@1504 | 21 | * questions. |
ohrstrom@1504 | 22 | */ |
ohrstrom@1504 | 23 | |
ohrstrom@1504 | 24 | /* |
ohrstrom@1504 | 25 | * @test |
ohrstrom@1504 | 26 | * @summary Test all aspects of sjavac. |
ohrstrom@1504 | 27 | * |
ohrstrom@1504 | 28 | * @bug 8004658 |
ohrstrom@1504 | 29 | * @summary Add internal smart javac wrapper to solve JEP 139 |
ohrstrom@1504 | 30 | * |
jjg@1516 | 31 | * @run main SJavacWrapper |
ohrstrom@1504 | 32 | */ |
ohrstrom@1504 | 33 | |
ohrstrom@1504 | 34 | import java.io.*; |
jjg@1516 | 35 | import java.lang.reflect.Method; |
ohrstrom@1504 | 36 | import java.net.*; |
ohrstrom@1504 | 37 | |
ohrstrom@1504 | 38 | |
ohrstrom@1504 | 39 | public |
jjg@1516 | 40 | class SJavacWrapper { |
ohrstrom@1504 | 41 | |
ohrstrom@1504 | 42 | public static void main(String... args) throws Exception { |
jjg@1516 | 43 | URL url = SJavacWrapper.class.getClassLoader().getResource("com/sun/tools/sjavac/Main.class"); |
ohrstrom@1504 | 44 | if (url == null) { |
ohrstrom@1504 | 45 | // No sjavac in the classpath. |
jjg@1516 | 46 | System.out.println("sjavac not available: pass by default"); |
ohrstrom@1504 | 47 | return; |
ohrstrom@1504 | 48 | } |
ohrstrom@1504 | 49 | |
jjg@1516 | 50 | File testSrc = new File(System.getProperty("test.src")); |
jjg@1516 | 51 | File sjavac_java = new File(testSrc, "SJavac.java"); |
jjg@1516 | 52 | File testClasses = new File(System.getProperty("test.classes")); |
jjg@1516 | 53 | File sjavac_class = new File(testClasses, "SJavac.class"); |
jjg@1516 | 54 | if (sjavac_class.lastModified() < sjavac_java.lastModified()) { |
jjg@1516 | 55 | String[] javac_args = { "-d", testClasses.getPath(), sjavac_java.getPath() }; |
jjg@1516 | 56 | System.err.println("Recompiling SJavac.java"); |
jjg@1516 | 57 | int rc = com.sun.tools.javac.Main.compile(javac_args); |
jjg@1516 | 58 | if (rc != 0) |
jjg@1516 | 59 | throw new Exception("compilation failed"); |
jjg@1516 | 60 | } |
jjg@1516 | 61 | |
jjg@1516 | 62 | Class<?> sjavac = Class.forName("SJavac"); |
jjg@1516 | 63 | Method sjavac_main = sjavac.getMethod("main", String[].class); |
jjg@1516 | 64 | sjavac_main.invoke(null, new Object[] { args }); |
ohrstrom@1504 | 65 | } |
ohrstrom@1504 | 66 | |
ohrstrom@1504 | 67 | } |