AtFileTest.java revision 3678:3dbcbc28ea1b
1/* 2 * Copyright (c) 2016, Oracle and/or its affiliates. All rights reserved. 3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. 4 * 5 * This code is free software; you can redistribute it and/or modify it 6 * under the terms of the GNU General Public License version 2 only, as 7 * published by the Free Software Foundation. 8 * 9 * This code is distributed in the hope that it will be useful, but WITHOUT 10 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or 11 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 12 * version 2 for more details (a copy is included in the LICENSE file that 13 * accompanied this code). 14 * 15 * You should have received a copy of the GNU General Public License version 16 * 2 along with this work; if not, write to the Free Software Foundation, 17 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. 18 * 19 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 20 * or visit www.oracle.com if you need additional information or have any 21 * questions. 22 */ 23 24/* 25 * @test 26 * @bug 8166472 8162810 27 * @summary Align javac support for at-files with launcher support 28 * @modules jdk.compiler/com.sun.tools.javac.main 29 */ 30 31import java.io.IOException; 32import java.io.StringReader; 33import java.util.ArrayList; 34import java.util.Arrays; 35import java.util.List; 36 37import com.sun.tools.javac.main.CommandLine.Tokenizer; 38 39public class AtFileTest { 40 41 public static void main(String... args) throws IOException { 42 AtFileTest t = new AtFileTest(); 43 if (args.length > 0) { 44 System.out.println(String.join(" ", args)); 45 } else { 46 t.run(); 47 } 48 } 49 50 void run() throws IOException { 51 test("-version -cp \"c:\\\\java libs\\\\one.jar\" \n", 52 "-version", "-cp", "c:\\java libs\\one.jar"); 53 54 // note the open quote at the end 55 test("com.foo.Panda \"Furious 5\"\fand\t'Shi Fu' \"escape\tprison", 56 "com.foo.Panda", "Furious 5", "and", "Shi Fu", "escape\tprison"); 57 58 test("escaped chars testing \"\\a\\b\\c\\f\\n\\r\\t\\v\\9\\6\\23\\82\\28\\377\\477\\278\\287\"", 59 "escaped", "chars", "testing", "abc\f\n\r\tv96238228377477278287"); 60 61 test("\"mix 'single quote' in double\" 'mix \"double quote\" in single' partial\"quote me\"this", 62 "mix 'single quote' in double", "mix \"double quote\" in single", "partialquote methis"); 63 64 test("line one #comment\n'line #2' #rest are comment\r\n#comment on line 3\nline 4 #comment to eof", 65 "line", "one", "line #2", "line", "4"); 66 67 test("This is an \"open quote \n across line\n\t, note for WS.", 68 "This", "is", "an", "open quote ", "across", "line", ",", "note", "for", "WS."); 69 70 test("Try \"this \\\\\\\\ escape\\n double quote \\\" in open quote", 71 "Try", "this \\\\ escape\n double quote \" in open quote"); 72 73 test("'-Dmy.quote.single'='Property in single quote. Here a double quote\" Add some slashes \\\\/'", 74 "-Dmy.quote.single=Property in single quote. Here a double quote\" Add some slashes \\/"); 75 76 test("\"Open quote to \n new \"line \\\n\r third\\\n\r\\\tand\ffourth\"", 77 "Open quote to ", "new", "line third\tand\ffourth"); 78 79 test("c:\\\"partial quote\"\\lib", 80 "c:\\partial quote\\lib"); 81 } 82 83 void test(String full, String... expect) throws IOException { 84 System.out.println("test: >>>" + full + "<<<"); 85 List<String> found = expand(full); 86 if (found.equals(Arrays.asList(expect))) { 87 System.out.println("OK"); 88 } else { 89 for (int i = 0; i < Math.max(found.size(), expect.length); i++) { 90 if (i < found.size()) { 91 System.out.println("found[" + i + "]: >>>" + found.get(i) + "<<<"); 92 } 93 if (i < expect.length) { 94 System.out.println("expect[" + i + "]: >>>" + expect[i] + "<<<"); 95 } 96 } 97 } 98 System.out.println(); 99 } 100 101 List<String> expand(String full) throws IOException { 102 Tokenizer t = new Tokenizer(new StringReader(full)); 103 List<String> result = new ArrayList<>(); 104 String s; 105 while ((s = t.nextToken()) != null) { 106// System.err.println("token: " + s); 107 result.add(s); 108 } 109 return result; 110 111 } 112} 113