T6306137.java revision 553
0N/A/*
1879N/A * Copyright (c) 2005, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
1472N/A * published by the Free Software Foundation.
0N/A *
1472N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
0N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
0N/A * or visit www.oracle.com if you need additional information or have any
1472N/A * questions.
1472N/A */
1472N/A
0N/A/*
0N/A * @test
0N/A * @bug 6306137
1879N/A * @summary JSR 199: encoding option doesn't affect standard file manager
1879N/A * @author Peter von der Ahé
1879N/A * @ignore
1879N/A * Need to make the contentCache in JavacFileManager be aware of changes to the encoding.
1879N/A * Need to propogate -source (and -encoding?) down to the JavacFileManager
1879N/A */
1879N/A
1879N/Aimport java.io.File;
1879N/Aimport java.util.Arrays;
2073N/Aimport javax.tools.*;
2073N/A
2073N/Apublic class T6306137 {
2073N/A boolean error;
2073N/A final StandardJavaFileManager fm;
2073N/A final JavaCompiler compiler;
1879N/A Iterable<? extends JavaFileObject> files;
0N/A DiagnosticListener<JavaFileObject> dl;
0N/A
0N/A T6306137() {
0N/A dl = new DiagnosticListener<JavaFileObject>() {
0N/A public void report(Diagnostic<? extends JavaFileObject> message) {
0N/A if (message.getKind() == Diagnostic.Kind.ERROR)
0N/A error = true;
0N/A System.out.println(message.getSource()
0N/A +":"+message.getStartPosition()+":"
0N/A +message.getStartPosition()+":"+message.getPosition());
System.out.println(message.toString());
System.out.format("Found problem: %s%n", message.getCode());
System.out.flush();
}
};
compiler = ToolProvider.getSystemJavaCompiler();
fm = compiler.getStandardFileManager(dl, null, null);
String srcdir = System.getProperty("test.src");
files =
fm.getJavaFileObjectsFromFiles(Arrays.asList(new File(srcdir, "T6306137.java")));
}
void test(String encoding, boolean good) {
error = false;
Iterable<String> args = Arrays.asList("-source", "6", "-encoding", encoding, "-d", ".");
compiler.getTask(null, fm, dl, args, null, files).call();
if (error == good) {
if (error) {
throw new AssertionError("Error reported");
} else {
throw new AssertionError("No error reported");
}
}
}
public static void main(String[] args) {
T6306137 self = new T6306137();
self.test("utf-8", true);
self.test("ascii", false);
self.test("utf-8", true);
}
}