ohrstrom@1504: /* ohrstrom@1504: * Copyright (c) 2013, Oracle and/or its affiliates. All rights reserved. ohrstrom@1504: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. ohrstrom@1504: * ohrstrom@1504: * This code is free software; you can redistribute it and/or modify it ohrstrom@1504: * under the terms of the GNU General Public License version 2 only, as ohrstrom@1504: * published by the Free Software Foundation. ohrstrom@1504: * ohrstrom@1504: * This code is distributed in the hope that it will be useful, but WITHOUT ohrstrom@1504: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or ohrstrom@1504: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License ohrstrom@1504: * version 2 for more details (a copy is included in the LICENSE file that ohrstrom@1504: * accompanied this code). ohrstrom@1504: * ohrstrom@1504: * You should have received a copy of the GNU General Public License version ohrstrom@1504: * 2 along with this work; if not, write to the Free Software Foundation, ohrstrom@1504: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. ohrstrom@1504: * ohrstrom@1504: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA ohrstrom@1504: * or visit www.oracle.com if you need additional information or have any ohrstrom@1504: * questions. ohrstrom@1504: */ ohrstrom@1504: ohrstrom@1504: /* ohrstrom@1504: * @test ohrstrom@1504: * @summary Test all aspects of sjavac. ohrstrom@1504: * ohrstrom@1504: * @bug 8004658 ohrstrom@1504: * @summary Add internal smart javac wrapper to solve JEP 139 ohrstrom@1504: * jjg@1516: * @run main SJavacWrapper ohrstrom@1504: */ ohrstrom@1504: ohrstrom@1504: import java.io.*; jjg@1516: import java.lang.reflect.Method; ohrstrom@1504: import java.net.*; ohrstrom@1504: ohrstrom@1504: ohrstrom@1504: public jjg@1516: class SJavacWrapper { ohrstrom@1504: ohrstrom@1504: public static void main(String... args) throws Exception { jjg@1516: URL url = SJavacWrapper.class.getClassLoader().getResource("com/sun/tools/sjavac/Main.class"); ohrstrom@1504: if (url == null) { ohrstrom@1504: // No sjavac in the classpath. jjg@1516: System.out.println("sjavac not available: pass by default"); ohrstrom@1504: return; ohrstrom@1504: } ohrstrom@1504: jjg@1516: File testSrc = new File(System.getProperty("test.src")); jjg@1516: File sjavac_java = new File(testSrc, "SJavac.java"); jjg@1516: File testClasses = new File(System.getProperty("test.classes")); jjg@1516: File sjavac_class = new File(testClasses, "SJavac.class"); jjg@1516: if (sjavac_class.lastModified() < sjavac_java.lastModified()) { jjg@1516: String[] javac_args = { "-d", testClasses.getPath(), sjavac_java.getPath() }; jjg@1516: System.err.println("Recompiling SJavac.java"); jjg@1516: int rc = com.sun.tools.javac.Main.compile(javac_args); jjg@1516: if (rc != 0) jjg@1516: throw new Exception("compilation failed"); jjg@1516: } jjg@1516: jjg@1516: Class sjavac = Class.forName("SJavac"); jjg@1516: Method sjavac_main = sjavac.getMethod("main", String[].class); jjg@1516: sjavac_main.invoke(null, new Object[] { args }); ohrstrom@1504: } ohrstrom@1504: ohrstrom@1504: }