Thu, 10 Oct 2013 14:58:04 +0200
8001931: The new build system whitespace cleanup
Reviewed-by: tbell, simonis, erikj
aoqi@0 | 1 | |
aoqi@0 | 2 | /* |
aoqi@0 | 3 | * @test /nodynamiccopyright/ |
aoqi@0 | 4 | * @bug 7144981 |
aoqi@0 | 5 | * @summary javac should ignore ignorable characters in input |
aoqi@0 | 6 | * @run main IgnoreIgnorableCharactersInInput |
aoqi@0 | 7 | */ |
aoqi@0 | 8 | |
aoqi@0 | 9 | import com.sun.source.util.JavacTask; |
aoqi@0 | 10 | import java.io.File; |
aoqi@0 | 11 | import java.net.URI; |
aoqi@0 | 12 | import java.util.Arrays; |
aoqi@0 | 13 | import java.util.Set; |
aoqi@0 | 14 | import java.util.TreeSet; |
aoqi@0 | 15 | import javax.tools.JavaCompiler; |
aoqi@0 | 16 | import javax.tools.JavaFileObject; |
aoqi@0 | 17 | import javax.tools.SimpleJavaFileObject; |
aoqi@0 | 18 | import javax.tools.ToolProvider; |
aoqi@0 | 19 | |
aoqi@0 | 20 | public class IgnoreIgnorableCharactersInInput { |
aoqi@0 | 21 | |
aoqi@0 | 22 | public static void main(String... args) throws Exception { |
aoqi@0 | 23 | new IgnoreIgnorableCharactersInInput().run(); |
aoqi@0 | 24 | } |
aoqi@0 | 25 | |
aoqi@0 | 26 | void run() throws Exception { |
aoqi@0 | 27 | JavaCompiler comp = ToolProvider.getSystemJavaCompiler(); |
aoqi@0 | 28 | File classesDir = new File(System.getProperty("user.dir"), "classes"); |
aoqi@0 | 29 | classesDir.mkdirs(); |
aoqi@0 | 30 | JavaSource[] sources = new JavaSource[]{ |
aoqi@0 | 31 | new JavaSource("TestOneIgnorableChar", "AA\\u0000BB"), |
aoqi@0 | 32 | new JavaSource("TestMultipleIgnorableChar", "AA\\u0000\\u0000\\u0000BB")}; |
aoqi@0 | 33 | JavacTask ct = (JavacTask)comp.getTask(null, null, null, |
aoqi@0 | 34 | Arrays.asList("-d", classesDir.getPath()), |
aoqi@0 | 35 | null, Arrays.asList(sources)); |
aoqi@0 | 36 | try { |
aoqi@0 | 37 | if (!ct.call()) { |
aoqi@0 | 38 | throw new AssertionError("Error thrown when compiling test cases"); |
aoqi@0 | 39 | } |
aoqi@0 | 40 | } catch (Throwable ex) { |
aoqi@0 | 41 | throw new AssertionError("Error thrown when compiling test cases"); |
aoqi@0 | 42 | } |
aoqi@0 | 43 | check(classesDir, |
aoqi@0 | 44 | "TestOneIgnorableChar.class", |
aoqi@0 | 45 | "TestOneIgnorableChar$AABB.class", |
aoqi@0 | 46 | "TestMultipleIgnorableChar.class", |
aoqi@0 | 47 | "TestMultipleIgnorableChar$AABB.class"); |
aoqi@0 | 48 | if (errors > 0) |
aoqi@0 | 49 | throw new AssertionError("There are some errors in the test check the error output"); |
aoqi@0 | 50 | } |
aoqi@0 | 51 | |
aoqi@0 | 52 | /** |
aoqi@0 | 53 | * Check that a directory contains the expected files. |
aoqi@0 | 54 | */ |
aoqi@0 | 55 | void check(File dir, String... paths) { |
aoqi@0 | 56 | Set<String> found = new TreeSet<String>(Arrays.asList(dir.list())); |
aoqi@0 | 57 | Set<String> expect = new TreeSet<String>(Arrays.asList(paths)); |
aoqi@0 | 58 | if (found.equals(expect)) |
aoqi@0 | 59 | return; |
aoqi@0 | 60 | for (String f: found) { |
aoqi@0 | 61 | if (!expect.contains(f)) |
aoqi@0 | 62 | error("Unexpected file found: " + f); |
aoqi@0 | 63 | } |
aoqi@0 | 64 | for (String e: expect) { |
aoqi@0 | 65 | if (!found.contains(e)) |
aoqi@0 | 66 | error("Expected file not found: " + e); |
aoqi@0 | 67 | } |
aoqi@0 | 68 | } |
aoqi@0 | 69 | |
aoqi@0 | 70 | int errors; |
aoqi@0 | 71 | |
aoqi@0 | 72 | void error(String msg) { |
aoqi@0 | 73 | System.err.println(msg); |
aoqi@0 | 74 | errors++; |
aoqi@0 | 75 | } |
aoqi@0 | 76 | |
aoqi@0 | 77 | class JavaSource extends SimpleJavaFileObject { |
aoqi@0 | 78 | |
aoqi@0 | 79 | String internalSource = |
aoqi@0 | 80 | "public class #O {public class #I {} }"; |
aoqi@0 | 81 | public JavaSource(String outerClassName, String innerClassName) { |
aoqi@0 | 82 | super(URI.create(outerClassName + ".java"), JavaFileObject.Kind.SOURCE); |
aoqi@0 | 83 | internalSource = |
aoqi@0 | 84 | internalSource.replace("#O", outerClassName).replace("#I", innerClassName); |
aoqi@0 | 85 | } |
aoqi@0 | 86 | |
aoqi@0 | 87 | @Override |
aoqi@0 | 88 | public CharSequence getCharContent(boolean ignoreEncodingErrors) { |
aoqi@0 | 89 | return internalSource; |
aoqi@0 | 90 | } |
aoqi@0 | 91 | } |
aoqi@0 | 92 | } |