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>
jjg@872 | 1 | /* |
jjg@872 | 2 | * Copyright (c) 2011, Oracle and/or its affiliates. All rights reserved. |
jjg@872 | 3 | * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
jjg@872 | 4 | * |
jjg@872 | 5 | * This code is free software; you can redistribute it and/or modify it |
jjg@872 | 6 | * under the terms of the GNU General Public License version 2 only, as |
jjg@872 | 7 | * published by the Free Software Foundation. |
jjg@872 | 8 | * |
jjg@872 | 9 | * This code is distributed in the hope that it will be useful, but WITHOUT |
jjg@872 | 10 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
jjg@872 | 11 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
jjg@872 | 12 | * version 2 for more details (a copy is included in the LICENSE file that |
jjg@872 | 13 | * accompanied this code). |
jjg@872 | 14 | * |
jjg@872 | 15 | * You should have received a copy of the GNU General Public License version |
jjg@872 | 16 | * 2 along with this work; if not, write to the Free Software Foundation, |
jjg@872 | 17 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
jjg@872 | 18 | * |
jjg@872 | 19 | * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
jjg@872 | 20 | * or visit www.oracle.com if you need additional information or have any |
jjg@872 | 21 | * questions. |
jjg@872 | 22 | */ |
jjg@872 | 23 | |
jjg@872 | 24 | /** |
jjg@872 | 25 | * @test |
jjg@872 | 26 | * @bug 7018098 |
jjg@872 | 27 | * @summary CacheFSInfo persists too long |
jjg@872 | 28 | * @library ../lib |
jjg@872 | 29 | * @build JavacTestingAbstractProcessor T7018098 |
jjg@872 | 30 | * @run main T7018098 |
jjg@872 | 31 | */ |
jjg@872 | 32 | |
jjg@872 | 33 | import java.io.*; |
jjg@872 | 34 | import java.util.*; |
jjg@872 | 35 | import javax.annotation.processing.RoundEnvironment; |
jjg@872 | 36 | import javax.annotation.processing.SupportedOptions; |
jjg@872 | 37 | import javax.lang.model.element.TypeElement; |
jjg@872 | 38 | import javax.tools.Diagnostic; |
jjg@872 | 39 | |
jjg@872 | 40 | import com.sun.tools.javac.file.FSInfo; |
jjg@872 | 41 | import com.sun.tools.javac.processing.JavacProcessingEnvironment; |
jjg@872 | 42 | import com.sun.tools.javac.util.Context; |
jjg@872 | 43 | |
jjg@872 | 44 | @SupportedOptions("expect") |
jjg@872 | 45 | public class T7018098 extends JavacTestingAbstractProcessor { |
jjg@872 | 46 | public static void main(String... args) throws Exception { |
jjg@872 | 47 | new T7018098().run(); |
jjg@872 | 48 | } |
jjg@872 | 49 | |
jjg@872 | 50 | static File testDir = new File("T7018098.dir"); |
jjg@872 | 51 | |
jjg@872 | 52 | void run() throws Exception { |
jjg@872 | 53 | String myName = T7018098.class.getSimpleName(); |
jjg@872 | 54 | File testSrc = new File(System.getProperty("test.src")); |
jjg@872 | 55 | File file = new File(testSrc, myName + ".java"); |
jjg@872 | 56 | |
jjg@872 | 57 | _assert(!testDir.exists()); |
jjg@872 | 58 | |
jjg@872 | 59 | compile( |
jjg@872 | 60 | "-proc:only", |
jjg@872 | 61 | "-processor", myName, |
jjg@872 | 62 | "-Aexpect=false", |
jjg@872 | 63 | file.getPath()); |
jjg@872 | 64 | |
jjg@872 | 65 | testDir.mkdirs(); |
jjg@872 | 66 | _assert(testDir.exists()); |
jjg@872 | 67 | |
jjg@872 | 68 | compile( |
jjg@872 | 69 | "-proc:only", |
jjg@872 | 70 | "-processor", myName, |
jjg@872 | 71 | "-Aexpect=true", |
jjg@872 | 72 | file.getPath()); |
jjg@872 | 73 | } |
jjg@872 | 74 | |
jjg@872 | 75 | void _assert(boolean cond) { |
jjg@872 | 76 | if (!cond) |
jjg@872 | 77 | throw new AssertionError(); |
jjg@872 | 78 | } |
jjg@872 | 79 | |
jjg@872 | 80 | void compile(String... args) throws Exception { |
jjg@872 | 81 | StringWriter sw = new StringWriter(); |
jjg@872 | 82 | PrintWriter pw = new PrintWriter(sw); |
jjg@872 | 83 | int rc = com.sun.tools.javac.Main.compile(args, pw); |
jjg@872 | 84 | pw.close(); |
jjg@872 | 85 | String out = sw.toString(); |
jjg@872 | 86 | if (!out.isEmpty()) |
jjg@872 | 87 | System.err.println(out); |
jjg@872 | 88 | if (rc != 0) |
jjg@872 | 89 | throw new Exception("compilation failed unexpectedly: rc=" + rc); |
jjg@872 | 90 | } |
jjg@872 | 91 | |
jjg@872 | 92 | //--------------- |
jjg@872 | 93 | |
jjg@872 | 94 | @Override |
jjg@872 | 95 | public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) { |
jjg@872 | 96 | Context context = ((JavacProcessingEnvironment) processingEnv).getContext(); |
jjg@872 | 97 | FSInfo fsInfo = context.get(FSInfo.class); |
jjg@872 | 98 | |
jjg@872 | 99 | round++; |
jjg@872 | 100 | if (round == 1) { |
jjg@872 | 101 | boolean expect = Boolean.valueOf(options.get("expect")); |
jjg@872 | 102 | checkEqual("cache result", fsInfo.isDirectory(testDir), expect); |
jjg@872 | 103 | initialFSInfo = fsInfo; |
jjg@872 | 104 | } else { |
jjg@872 | 105 | checkEqual("fsInfo", fsInfo, initialFSInfo); |
jjg@872 | 106 | } |
jjg@872 | 107 | |
jjg@872 | 108 | return true; |
jjg@872 | 109 | } |
jjg@872 | 110 | |
jjg@872 | 111 | <T> void checkEqual(String label, T actual, T expected) { |
jjg@872 | 112 | if (actual != expected) |
jjg@872 | 113 | messager.printMessage(Diagnostic.Kind.ERROR, |
jjg@872 | 114 | "Unexpected value for " + label |
jjg@872 | 115 | + "; expected: " + expected |
jjg@872 | 116 | + "; found: " + actual); |
jjg@872 | 117 | } |
jjg@872 | 118 | |
jjg@872 | 119 | int round = 0; |
jjg@872 | 120 | FSInfo initialFSInfo; |
jjg@872 | 121 | } |