Thu, 07 Jun 2012 20:30:57 -0700
7170079: Adjustments to build-infra makefiles
Reviewed-by: ohair, ohrstrom, ihse, jonas
Contributed-by: jonas <jonas.oreland@oracle.com>, erikj <erik.joelsson@oracle.com>, ihse <magnus.ihse.bursie@oracle.com>, tgranat <torbjorn.granat@oracle.com>, ykantser <yekaterina.kantserova@oracle.com>
aoqi@0 | 1 | /* |
aoqi@0 | 2 | * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
aoqi@0 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
aoqi@0 | 4 | * |
aoqi@0 | 5 | * This code is free software; you can redistribute it and/or modify it |
aoqi@0 | 6 | * under the terms of the GNU General Public License version 2 only, as |
aoqi@0 | 7 | * published by the Free Software Foundation. |
aoqi@0 | 8 | * |
aoqi@0 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
aoqi@0 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
aoqi@0 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
aoqi@0 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
aoqi@0 | 13 | * accompanied this code). |
aoqi@0 | 14 | * |
aoqi@0 | 15 | * You should have received a copy of the GNU General Public License version |
aoqi@0 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
aoqi@0 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
aoqi@0 | 18 | * |
aoqi@0 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
aoqi@0 | 20 | * or visit www.oracle.com if you need additional information or have any |
aoqi@0 | 21 | * questions. |
aoqi@0 | 22 | */ |
aoqi@0 | 23 | |
aoqi@0 | 24 | /* |
aoqi@0 | 25 | * @test |
aoqi@0 | 26 | * @bug 7068451 |
aoqi@0 | 27 | * @summary Regression: javac compiles fixed sources against previous, |
aoqi@0 | 28 | * not current, version of generated sources |
aoqi@0 | 29 | */ |
aoqi@0 | 30 | |
aoqi@0 | 31 | import java.io.File; |
aoqi@0 | 32 | import java.io.FileNotFoundException; |
aoqi@0 | 33 | import java.io.FileWriter; |
aoqi@0 | 34 | import java.io.IOException; |
aoqi@0 | 35 | import java.io.Writer; |
aoqi@0 | 36 | import java.util.Arrays; |
aoqi@0 | 37 | import java.util.Collections; |
aoqi@0 | 38 | import java.util.List; |
aoqi@0 | 39 | import java.util.Set; |
aoqi@0 | 40 | import javax.annotation.processing.AbstractProcessor; |
aoqi@0 | 41 | import javax.annotation.processing.Filer; |
aoqi@0 | 42 | import javax.annotation.processing.Messager; |
aoqi@0 | 43 | import javax.annotation.processing.RoundEnvironment; |
aoqi@0 | 44 | import javax.annotation.processing.SupportedAnnotationTypes; |
aoqi@0 | 45 | import javax.lang.model.SourceVersion; |
aoqi@0 | 46 | import javax.lang.model.element.TypeElement; |
aoqi@0 | 47 | import javax.tools.Diagnostic.Kind; |
aoqi@0 | 48 | import javax.tools.JavaCompiler; |
aoqi@0 | 49 | import javax.tools.JavaCompiler.CompilationTask; |
aoqi@0 | 50 | import javax.tools.StandardLocation; |
aoqi@0 | 51 | import javax.tools.ToolProvider; |
aoqi@0 | 52 | |
aoqi@0 | 53 | public class T7068451 { |
aoqi@0 | 54 | public static void main(String[] args) throws Exception { |
aoqi@0 | 55 | new T7068451().run(); |
aoqi@0 | 56 | } |
aoqi@0 | 57 | |
aoqi@0 | 58 | void run() throws Exception { |
aoqi@0 | 59 | JavaCompiler compiler = ToolProvider.getSystemJavaCompiler(); |
aoqi@0 | 60 | System.err.println("using " + compiler.getClass() + " from " + compiler.getClass().getProtectionDomain().getCodeSource()); |
aoqi@0 | 61 | |
aoqi@0 | 62 | File tmp = new File("tmp"); |
aoqi@0 | 63 | tmp.mkdir(); |
aoqi@0 | 64 | for (File f: tmp.listFiles()) |
aoqi@0 | 65 | f.delete(); |
aoqi@0 | 66 | |
aoqi@0 | 67 | File input = writeFile(tmp, "X.java", "package p; class X { { p.C.first(); } }"); |
aoqi@0 | 68 | |
aoqi@0 | 69 | List<String> opts = Arrays.asList( |
aoqi@0 | 70 | "-s", tmp.getPath(), |
aoqi@0 | 71 | "-d", tmp.getPath(), |
aoqi@0 | 72 | "-XprintRounds"); |
aoqi@0 | 73 | |
aoqi@0 | 74 | System.err.println(); |
aoqi@0 | 75 | System.err.println("FIRST compilation"); |
aoqi@0 | 76 | System.err.println(); |
aoqi@0 | 77 | |
aoqi@0 | 78 | CompilationTask task = compiler.getTask(null, null, null, opts, null, |
aoqi@0 | 79 | compiler.getStandardFileManager(null, null, null).getJavaFileObjects(input)); |
aoqi@0 | 80 | task.setProcessors(Collections.singleton(new Proc("first"))); |
aoqi@0 | 81 | check("compilation", task.call()); |
aoqi@0 | 82 | |
aoqi@0 | 83 | writeFile(tmp, "X.java", "package p; class X { { p.C.second(); } }"); |
aoqi@0 | 84 | |
aoqi@0 | 85 | //Thread.sleep(2000); |
aoqi@0 | 86 | |
aoqi@0 | 87 | System.err.println(); |
aoqi@0 | 88 | System.err.println("SECOND compilation"); |
aoqi@0 | 89 | System.err.println(); |
aoqi@0 | 90 | |
aoqi@0 | 91 | task = compiler.getTask(null, null, null, opts, null, |
aoqi@0 | 92 | compiler.getStandardFileManager(null, null, null).getJavaFileObjects(input)); |
aoqi@0 | 93 | task.setProcessors(Collections.singleton(new Proc("second"))); |
aoqi@0 | 94 | check("compilation", task.call()); |
aoqi@0 | 95 | |
aoqi@0 | 96 | //Thread.sleep(2000); |
aoqi@0 | 97 | |
aoqi@0 | 98 | System.err.println(); |
aoqi@0 | 99 | System.err.println("SECOND compilation, REPEATED"); |
aoqi@0 | 100 | System.err.println(); |
aoqi@0 | 101 | |
aoqi@0 | 102 | task = compiler.getTask(null, null, null, opts, null, |
aoqi@0 | 103 | compiler.getStandardFileManager(null, null, null).getJavaFileObjects(input)); |
aoqi@0 | 104 | task.setProcessors(Collections.singleton(new Proc("second"))); |
aoqi@0 | 105 | check("compilation", task.call()); |
aoqi@0 | 106 | } |
aoqi@0 | 107 | |
aoqi@0 | 108 | void check(String msg, boolean ok) { |
aoqi@0 | 109 | System.err.println(msg + ": " + (ok ? "ok" : "failed")); |
aoqi@0 | 110 | if (!ok) |
aoqi@0 | 111 | throw new AssertionError(msg); |
aoqi@0 | 112 | } |
aoqi@0 | 113 | |
aoqi@0 | 114 | static File writeFile(File base, String path, String body) throws IOException { |
aoqi@0 | 115 | File f = new File(base, path); |
aoqi@0 | 116 | FileWriter out = new FileWriter(f); |
aoqi@0 | 117 | out.write(body); |
aoqi@0 | 118 | out.close(); |
aoqi@0 | 119 | System.err.println("wrote " + path + ": " + body); |
aoqi@0 | 120 | return f; |
aoqi@0 | 121 | } |
aoqi@0 | 122 | |
aoqi@0 | 123 | @SupportedAnnotationTypes("*") |
aoqi@0 | 124 | private static class Proc extends AbstractProcessor { |
aoqi@0 | 125 | final String m; |
aoqi@0 | 126 | Proc(String m) { |
aoqi@0 | 127 | this.m = m; |
aoqi@0 | 128 | } |
aoqi@0 | 129 | |
aoqi@0 | 130 | int count; |
aoqi@0 | 131 | @Override public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
aoqi@0 | 132 | if (roundEnv.processingOver() || count++ > 0) { |
aoqi@0 | 133 | return false; |
aoqi@0 | 134 | } |
aoqi@0 | 135 | |
aoqi@0 | 136 | Filer filer = processingEnv.getFiler(); |
aoqi@0 | 137 | Messager messager = processingEnv.getMessager(); |
aoqi@0 | 138 | |
aoqi@0 | 139 | System.err.println("running Proc"); |
aoqi@0 | 140 | try { |
aoqi@0 | 141 | int len = filer.getResource(StandardLocation.SOURCE_OUTPUT, "p", "C.java").getCharContent(false).length(); |
aoqi@0 | 142 | messager.printMessage(Kind.NOTE, "C.java: found previous content of length " + len); |
aoqi@0 | 143 | } catch (FileNotFoundException x) { |
aoqi@0 | 144 | messager.printMessage(Kind.NOTE, "C.java: not previously there"); |
aoqi@0 | 145 | } catch (IOException x) { |
aoqi@0 | 146 | messager.printMessage(Kind.ERROR, "while reading: " + x); |
aoqi@0 | 147 | } |
aoqi@0 | 148 | |
aoqi@0 | 149 | try { |
aoqi@0 | 150 | String body = "package p; public class C { public static void " + m + "() {} }"; |
aoqi@0 | 151 | Writer w = filer.createSourceFile("p.C").openWriter(); |
aoqi@0 | 152 | w.write(body); |
aoqi@0 | 153 | w.close(); |
aoqi@0 | 154 | messager.printMessage(Kind.NOTE, "C.java: wrote new content: " + body); |
aoqi@0 | 155 | } catch (IOException x) { |
aoqi@0 | 156 | messager.printMessage(Kind.ERROR, "while writing: " + x); |
aoqi@0 | 157 | } |
aoqi@0 | 158 | |
aoqi@0 | 159 | return true; |
aoqi@0 | 160 | } |
aoqi@0 | 161 | |
aoqi@0 | 162 | @Override |
aoqi@0 | 163 | public SourceVersion getSupportedSourceVersion() { |
aoqi@0 | 164 | return SourceVersion.latest(); |
aoqi@0 | 165 | } |
aoqi@0 | 166 | } |
aoqi@0 | 167 | } |
aoqi@0 | 168 |