aoqi@0: /* aoqi@0: * Copyright (c) 2006, 2013, Oracle and/or its affiliates. All rights reserved. aoqi@0: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. aoqi@0: * aoqi@0: * This code is free software; you can redistribute it and/or modify it aoqi@0: * under the terms of the GNU General Public License version 2 only, as aoqi@0: * published by the Free Software Foundation. aoqi@0: * aoqi@0: * This code is distributed in the hope that it will be useful, but WITHOUT aoqi@0: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or aoqi@0: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License aoqi@0: * version 2 for more details (a copy is included in the LICENSE file that aoqi@0: * accompanied this code). aoqi@0: * aoqi@0: * You should have received a copy of the GNU General Public License version aoqi@0: * 2 along with this work; if not, write to the Free Software Foundation, aoqi@0: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. aoqi@0: * aoqi@0: * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA aoqi@0: * or visit www.oracle.com if you need additional information or have any aoqi@0: * questions. aoqi@0: */ aoqi@0: aoqi@0: /* aoqi@0: * @test aoqi@0: * @bug 6437999 aoqi@0: * @summary Unit test for encoding argument to standard file manager aoqi@0: * @author Peter von der Ah\u00e9 aoqi@0: * @library ../lib aoqi@0: * @build ToolTester aoqi@0: * @compile T6437999.java aoqi@0: * @run main T6437999 aoqi@0: */ aoqi@0: aoqi@0: import java.io.File; aoqi@0: import java.io.IOException; aoqi@0: import java.nio.charset.Charset; aoqi@0: import java.nio.file.Files; aoqi@0: import java.util.ArrayList; aoqi@0: import java.util.Collections; aoqi@0: import java.util.List; aoqi@0: import javax.tools.*; aoqi@0: import static java.nio.file.StandardOpenOption.*; aoqi@0: aoqi@0: public class T6437999 extends ToolTester { aoqi@0: final File testFile = new File("Utf8.java"); aoqi@0: T6437999() throws IOException { aoqi@0: createTestFile(); aoqi@0: } aoqi@0: final void createTestFile() throws IOException { aoqi@0: List scratch = new ArrayList<>(); aoqi@0: scratch.add("// @author Peter von der Ah" + (char) 0xe9); aoqi@0: scratch.add("class Utf8{}"); aoqi@0: Files.write(testFile.toPath(), scratch, Charset.forName("UTF-8"), aoqi@0: CREATE, TRUNCATE_EXISTING); aoqi@0: } aoqi@0: aoqi@0: static class MyDiagnosticListener implements DiagnosticListener { aoqi@0: boolean error = false; aoqi@0: public void report(Diagnostic diagnostic) { aoqi@0: error |= diagnostic.getKind() == Diagnostic.Kind.ERROR; aoqi@0: System.out.println(diagnostic); aoqi@0: } aoqi@0: } aoqi@0: aoqi@0: void test(String... args) { aoqi@0: Iterable sourceLevel = Collections.singleton("6"); aoqi@0: MyDiagnosticListener dl = new MyDiagnosticListener(); aoqi@0: StandardJavaFileManager fm; aoqi@0: Iterable files; aoqi@0: aoqi@0: dl.error = false; aoqi@0: fm = getFileManager(tool, dl, Charset.forName("ASCII")); aoqi@0: fm.handleOption("-source", sourceLevel.iterator()); aoqi@0: files = fm.getJavaFileObjects(testFile); aoqi@0: tool.getTask(null, fm, null, null, null, files).call(); aoqi@0: if (!dl.error) aoqi@0: throw new AssertionError("No error in ASCII mode"); aoqi@0: aoqi@0: dl.error = false; aoqi@0: fm = getFileManager(tool, dl, Charset.forName("UTF-8")); aoqi@0: fm.handleOption("-source", sourceLevel.iterator()); aoqi@0: files = fm.getJavaFileObjects(testFile); aoqi@0: task = tool.getTask(null, fm, null, null, null, files); aoqi@0: if (dl.error) aoqi@0: throw new AssertionError("Error in UTF-8 mode"); aoqi@0: } aoqi@0: public static void main(String... args) throws IOException { aoqi@0: new T6437999().test(args); aoqi@0: } aoqi@0: }