1/* 2 * Copyright (c) 2011, 2015, 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 * @bug 6987384 27 * @summary -XprintProcessorRoundsInfo message printed with different timing than previous 28 * @library /tools/javac/lib 29 * @modules java.compiler 30 * jdk.compiler 31 * @build JavacTestingAbstractProcessor Test TestWithXstdout 32 * @run main TestWithXstdout 33 */ 34 35import java.io.*; 36import java.nio.charset.*; 37import java.nio.file.*; 38import java.util.*; 39 40public class TestWithXstdout { 41 public static void main(String... args) throws Exception { 42 File testSrc = new File(System.getProperty("test.src")); 43 String testClasses = System.getProperty("test.classes", "."); 44 String testClassPath = System.getProperty("test.class.path", testClasses); 45 File stdout = new File("stdout.out"); 46 run_javac("-XDrawDiagnostics", 47 "-XprintProcessorInfo", 48 "-Werror", 49 "-proc:only", 50 "-processor", "Test", 51 "-Xstdout", stdout.getPath(), 52 "-classpath", testClassPath, 53 new File(testSrc, "Test.java").getPath()); 54 boolean ok = compare(stdout, new File(testSrc, "Test.out")); 55 if (!ok) 56 throw new Exception("differences found"); 57 } 58 59 static void run_javac(String... args) throws IOException, InterruptedException { 60 File javaHome = new File(System.getProperty("java.home")); 61 File javac = new File(new File(javaHome, "bin"), "javac"); 62 63 List<String> opts = new ArrayList<>(); 64 opts.add(javac.getPath()); 65 66 String toolOpts = System.getProperty("test.tool.vm.opts"); 67 if (toolOpts != null && !"".equals(toolOpts.trim())) { 68 opts.addAll(Arrays.asList(toolOpts.trim().split("[\\s]+"))); 69 } 70 opts.addAll(Arrays.asList(args)); 71 System.out.println("exec: " + opts); 72 ProcessBuilder pb = new ProcessBuilder(opts); 73 pb.redirectErrorStream(); 74 Process p = pb.start(); 75 try (BufferedReader r = new BufferedReader(new InputStreamReader(p.getInputStream()))) { 76 String line; 77 while ((line = r.readLine()) != null) 78 System.out.println(); 79 } 80 int rc = p.waitFor(); 81 if (rc != 0) 82 System.out.println("javac exited, rc=" + rc); 83 } 84 85 static boolean compare(File a, File b) throws IOException { 86 List<String> aLines = Files.readAllLines(a.toPath(), Charset.defaultCharset()); 87 List<String> bLines = Files.readAllLines(b.toPath(), Charset.defaultCharset()); 88 System.out.println(a + ": " + aLines.size() + " lines"); 89 System.out.println(b + ": " + bLines.size() + " lines"); 90 return aLines.equals(bLines); 91 } 92} 93