Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
PojavLauncherTeam
GitHub Repository: PojavLauncherTeam/mobile
Path: blob/master/test/jdk/tools/launcher/ToolsOpts.java
41144 views
1
/*
2
* Copyright (c) 2012, 2017, 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 8002091
27
* @summary Test options patterns for javac,javap and javadoc using
28
* javac as a test launcher. Create a dummy javac and intercept options to check
29
* reception of options as passed through the launcher without having to launch
30
* javac. Only -J and -cp ./* options should be consumed by the launcher.
31
* @modules jdk.compiler
32
* jdk.zipfs
33
* @run main ToolsOpts
34
* @author ssides
35
*/
36
37
import java.io.File;
38
import java.io.IOException;
39
import java.util.ArrayList;
40
import java.util.List;
41
42
public class ToolsOpts extends TestHelper {
43
static String[][] optionPatterns = {
44
{"-J-Xmx128m"},
45
{"-J-version"},
46
{"-J-XshowSettings:vm"},
47
{"-J-Xdiag"},
48
{"-J-showversion"},
49
{"-J-version", "-option"},
50
{"-option"},
51
{"-option:sub"},
52
{"-option:sub-"},
53
{"-option:sub1,sub2"}, // -option:list
54
{"-option:{sub1,sub2,sub3}"}, // -option:{list}
55
{"-option:{{sub1,sub2,sub3}}"},// -option:{{list}}
56
{"-option/c:/export/date/tmp"},
57
{"-option=value"},
58
{"-Dpk1.pk2.pk3"}, // dot in option
59
{"-Dpk1.pk2=value"}, // dot in option followed by =value
60
{"@<filename>"},
61
{"-option", "http://site.com", "http://site.org"},
62
{"-option", "name", "p1:p2.."},
63
{"-All these non-options show launchers pass options as is to tool."},
64
{"-option"},
65
{"-option:sub"},
66
{"-option:sub-"},
67
{"-option", "<path>"},
68
{"-option", "<file>"},
69
{"-option", "<dir>"},
70
{"-option", "http://a/b/c/g;x?y#s"},
71
{"-option", "<html code>"},
72
{"-option", "name1:name2"},
73
{"-option", "3"},
74
{"option1", "-J-version", "option2"},
75
{"option1", "-J-version", "-J-XshowSettings:vm", "option2"},};
76
77
static void init() throws IOException {
78
79
// A tool which simulates com.sun.tools.javac.Main argument processing,
80
// intercepts options passed via the javac launcher.
81
final String mainJava = "Main" + JAVA_FILE_EXT;
82
List<String> contents = new ArrayList<>();
83
contents.add("package com.sun.tools.javac;");
84
contents.add("public class Main {");
85
contents.add(" public static void main(String... args) {\n");
86
contents.add(" for (String x : args) {\n");
87
contents.add(" if(x.compareTo(\" \")!=0)\n");
88
contents.add(" System.out.println(x);\n");
89
contents.add(" }\n");
90
contents.add(" }\n");
91
contents.add("}\n");
92
String mainJavaPath = "patch-src/com/sun/tools/javac/" + mainJava;
93
File mainJavaFile = new File(mainJavaPath.replace('/', File.separatorChar));
94
mainJavaFile.getParentFile().mkdirs();
95
createFile(mainJavaFile, contents);
96
97
// compile Main.java into directory to override classes in jdk.compiler
98
new File("jdk.compiler").mkdir();
99
compile("--patch-module", "jdk.compiler=patch-src",
100
"-d", "jdk.compiler",
101
mainJavaFile.toString());
102
}
103
104
static void pass(String msg) {
105
System.out.println("pass: " + msg);
106
}
107
108
static void errout(String msg) {
109
System.err.println(msg);
110
}
111
112
// Return position of -J option or -1 is does not contain a -J option.
113
static int indexOfJoption(String[] opts) {
114
for (int i = 0; i < opts.length; i++) {
115
if (opts[i].startsWith("-J")) {
116
return i;
117
}
118
}
119
return -1;
120
}
121
122
/*
123
* Check that J options a) are not passed to tool, and b) do the right thing,
124
* that is, they should be passed to java launcher and work as expected.
125
*/
126
static void checkJoptionOutput(TestResult tr, String[] opts) throws IOException {
127
// Check -J-version options are not passed but do what they should.
128
String jopts = "";
129
for (String pat : opts) {
130
jopts = jopts.concat(pat + " ");
131
if (tr.contains("-J")) {
132
throw new RuntimeException(
133
"failed: output should not contain option " + pat);
134
}
135
if (pat.compareTo("-J-version") == 0 ||
136
pat.compareTo("-J-showversion") == 0) {
137
if (!tr.contains("java version") &&
138
!tr.contains("openjdk version")) {
139
throw new RuntimeException("failed: " + pat +
140
" should display a version string.");
141
}
142
} else if (pat.compareTo("-J-XshowSettings:VM") == 0) {
143
if (!tr.contains("VM settings")) {
144
throw new RuntimeException("failed: " + pat +
145
" should have display VM settings.");
146
}
147
}
148
}
149
pass("Joption check: " + jopts);
150
}
151
152
/*
153
* Feed each option pattern in optionPatterns array to javac launcher with
154
* checking program preempting javac. Check that option received by 'dummy'
155
* javac is the one passed on the command line.
156
*/
157
static void runTestOptions() throws IOException {
158
init();
159
TestResult tr;
160
int jpos = -1;
161
String xPatch = "-J--patch-module=jdk.compiler=jdk.compiler";
162
for (String arg[] : optionPatterns) {
163
jpos = indexOfJoption(arg);
164
//Build a cmd string for output in results reporting.
165
String cmdString = javacCmd + " " + xPatch;
166
for (String opt : arg) {
167
cmdString = cmdString.concat(" " + opt);
168
}
169
switch (arg.length) {
170
case 1:
171
tr = doExec(javacCmd, xPatch, arg[0]);
172
break;
173
case 2:
174
tr = doExec(javacCmd, xPatch, arg[0], arg[1]);
175
break;
176
case 3:
177
tr = doExec(javacCmd, xPatch, arg[0], arg[1], arg[2]);
178
break;
179
case 4:
180
tr = doExec(javacCmd, xPatch, arg[0], arg[1], arg[2], arg[3]);
181
break;
182
default:
183
tr = null;
184
break;
185
}
186
187
//-Joptions should not be passed to tool
188
if (jpos > -1) {
189
checkJoptionOutput(tr, arg);
190
if (tr.contains(arg[jpos])) {
191
throw new RuntimeException(
192
"failed! Should not have passed -J option to tool.\n"
193
+ "CMD: " + cmdString);
194
}
195
} else {
196
// check that each non -J option was passed to tool. It looks for each arg in the output.
197
// Irrelevant lines in the output are skipped. Arguments order is checked as well.
198
int j = 0;
199
List<String> output = tr.testOutput;
200
for (int i = 0; i < arg.length; i++) {
201
boolean found = false;
202
for (; j < output.size(); j++) {
203
if (output.get(j).equals(arg[i])) {
204
pass("check " + output.get(j) + " == " + arg[i]);
205
found = true;
206
break;
207
}
208
}
209
if (!found) {
210
throw new RuntimeException(
211
"failed! Should have passed non -J option [" + arg[i] + "] to tool.\n"
212
+ "CMD: " + cmdString);
213
}
214
}
215
}
216
pass(cmdString);
217
}
218
}
219
220
public static void main(String... args) throws IOException {
221
runTestOptions();
222
}
223
}
224
225