Skip to content

Commit e43a589

Browse files
authored
Remove first character for delegating args to CodeServer (#9940)
fix for #9939
1 parent 34b2a44 commit e43a589

File tree

3 files changed

+211
-1
lines changed

3 files changed

+211
-1
lines changed

dev/core/src/com/google/gwt/dev/shell/SuperDevListener.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import com.google.gwt.dev.DevMode.HostedModeOptions;
2424
import com.google.gwt.dev.cfg.ModuleDef;
2525
import com.google.gwt.dev.util.arg.OptionMethodNameDisplayMode;
26+
import com.google.gwt.thirdparty.guava.common.annotations.VisibleForTesting;
2627
import com.google.gwt.thirdparty.guava.common.base.Stopwatch;
2728
import com.google.gwt.thirdparty.guava.common.collect.ListMultimap;
2829
import com.google.gwt.thirdparty.guava.common.collect.Lists;
@@ -63,6 +64,11 @@ public int getSocketPort() {
6364
return codeServerPort;
6465
}
6566

67+
@VisibleForTesting
68+
List<String> getCodeServerArgs() {
69+
return codeServerArgs;
70+
}
71+
6672
@Override
6773
public URL makeStartupUrl(String url) throws UnableToCompleteException {
6874
try {
@@ -174,7 +180,7 @@ private static List<String> makeCodeServerArgs(HostedModeOptions options, int po
174180
args.add(regex.substring(1));
175181
} else {
176182
args.add("-includeJsInteropExports");
177-
args.add(regex);
183+
args.add(regex.startsWith("+") ? regex.substring(1) : regex);
178184
}
179185
}
180186
if (!options.isIncrementalCompileEnabled()) {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
/*
2+
* Copyright 2024 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
package com.google.gwt.dev;
15+
16+
/**
17+
* Make {@link com.google.gwt.dev.DevMode.HostedModeOptionsImpl} visible as mock for tests..
18+
*/
19+
public class HostedModeOptionsMock extends DevMode.HostedModeOptionsImpl {
20+
}
Lines changed: 184 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,184 @@
1+
/*
2+
* Copyright 2024 Google Inc.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
5+
* in compliance with the License. You may obtain a copy of the License at
6+
*
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* Unless required by applicable law or agreed to in writing, software distributed under the License
10+
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
11+
* or implied. See the License for the specific language governing permissions and limitations under
12+
* the License.
13+
*/
14+
package com.google.gwt.dev.shell;
15+
16+
import com.google.gwt.core.ext.TreeLogger;
17+
import com.google.gwt.dev.DevMode;
18+
import com.google.gwt.dev.HostedModeOptionsMock;
19+
import com.google.gwt.dev.jjs.JsOutputOption;
20+
import com.google.gwt.dev.util.arg.OptionMethodNameDisplayMode;
21+
import com.google.gwt.dev.util.arg.SourceLevel;
22+
import com.google.gwt.thirdparty.guava.common.collect.ImmutableList;
23+
import com.google.gwt.util.regexfilter.WhitelistRegexFilter;
24+
25+
import junit.framework.TestCase;
26+
27+
import java.io.File;
28+
import java.io.IOException;
29+
import java.nio.file.Files;
30+
import java.util.ArrayList;
31+
import java.util.List;
32+
33+
/**
34+
* A wide variety of tests on {@link SuperDevListener}.
35+
*/
36+
public class SuperDevListenerTest extends TestCase {
37+
private static final int TEST_PORT = 9998;
38+
private static final String MODULE_NAME = "Test_Module_Name";
39+
private final TreeLogger treeLogger = new FailErrorLogger();
40+
private final DevMode.HostedModeOptions options = new HostedModeOptionsMock();
41+
private final WhitelistRegexFilter whitelistRegexFilter = new WhitelistRegexFilter();
42+
private File warDir;
43+
@Override
44+
public void setUp() throws IOException {
45+
warDir = Files.createTempDirectory("war-file").toFile();
46+
warDir.deleteOnExit();
47+
setUpOptions(options);
48+
}
49+
50+
private void setUpOptions(DevMode.HostedModeOptions optionsToPrepare) {
51+
optionsToPrepare.setCodeServerPort(TEST_PORT);
52+
optionsToPrepare.setSourceLevel(SourceLevel.JAVA17);
53+
optionsToPrepare.setWarDir(warDir);
54+
optionsToPrepare.setOutput(JsOutputOption.DETAILED);
55+
optionsToPrepare.setGenerateJsInteropExports(false);
56+
optionsToPrepare.setIncrementalCompileEnabled(true);
57+
optionsToPrepare.setMethodNameDisplayMode(OptionMethodNameDisplayMode.Mode.NONE);
58+
optionsToPrepare.setStrict(false);
59+
optionsToPrepare.setModuleNames(ImmutableList.of(MODULE_NAME));
60+
}
61+
62+
public void testDefaultArgs() {
63+
final SuperDevListener superDevListener = new SuperDevListener(treeLogger, options);
64+
final List<String> codeServerArgs = superDevListener.getCodeServerArgs();
65+
assertEquals("Wrong default arguments", 10, codeServerArgs.size());
66+
assertTrue("Precompile flag should set", codeServerArgs.contains("-noprecompile"));
67+
assertTrue("Port should set", codeServerArgs.contains("-port"));
68+
assertTrue("Port should set", codeServerArgs.contains(Integer.toString(TEST_PORT)));
69+
assertTrue("SourceLevel should set", codeServerArgs.contains("-sourceLevel"));
70+
assertTrue("SourceLevel should set", codeServerArgs.contains(SourceLevel.JAVA17.getStringValue()));
71+
assertTrue("LauncherDir should set", codeServerArgs.contains("-launcherDir"));
72+
assertTrue("LauncherDir should set", codeServerArgs.contains(warDir.getAbsolutePath()));
73+
assertTrue("Style should set", codeServerArgs.contains("-style"));
74+
assertTrue("Style should set", codeServerArgs.contains("DETAILED"));
75+
assertTrue("Module name should set", codeServerArgs.contains(MODULE_NAME));
76+
}
77+
78+
public void testDefaultNonSuperDevModePort() {
79+
final int port = 9997;
80+
options.setCodeServerPort(port);
81+
final SuperDevListener superDevListener = new SuperDevListener(treeLogger, options);
82+
final List<String> codeServerArgs = superDevListener.getCodeServerArgs();
83+
assertTrue("Port should set", codeServerArgs.contains("-port"));
84+
assertTrue("SuperDevMode Default port should set", codeServerArgs.contains("9876"));
85+
}
86+
87+
public void testWithJsInteropAndSingleIncludeAndExclude() {
88+
options.setGenerateJsInteropExports(true);
89+
options.getJsInteropExportFilter().add("-com.google.gwt.exclude.First");
90+
options.getJsInteropExportFilter().add("com.google.gwt.include.First");
91+
92+
final SuperDevListener superDevListener = new SuperDevListener(treeLogger, options);
93+
final List<String> codeServerArgs = superDevListener.getCodeServerArgs();
94+
assertTrue("GenerateJsInteropExports should set", codeServerArgs.contains("-generateJsInteropExports"));
95+
assertTrue("ExcludeJsInteropExports should set", codeServerArgs.contains("-excludeJsInteropExports"));
96+
assertTrue("ExcludeJsInteropExports should set", codeServerArgs.contains("com.google.gwt.exclude.First"));
97+
assertTrue("IncludeJsInteropExports should set", codeServerArgs.contains("-includeJsInteropExports"));
98+
assertTrue("IncludeJsInteropExports should set", codeServerArgs.contains("com.google.gwt.include.First"));
99+
}
100+
101+
public void testWithJsInteropIncludesAndExcludes() {
102+
options.setGenerateJsInteropExports(true);
103+
options.getJsInteropExportFilter().add("-com.google.gwt.exclude.First");
104+
options.getJsInteropExportFilter().add("com.google.gwt.include.First");
105+
options.getJsInteropExportFilter().add("-com.google.gwt.exclude.Second");
106+
options.getJsInteropExportFilter().add("com.google.gwt.include.Second");
107+
108+
final SuperDevListener superDevListener = new SuperDevListener(treeLogger, options);
109+
final List<String> codeServerArgs = superDevListener.getCodeServerArgs();
110+
final int generateJsExportsIndex = codeServerArgs.indexOf("-generateJsInteropExports") + 1;
111+
final List<String> expectedJsExports = createExpectedJsIncludesAndExcludesgetStrings();
112+
113+
assertTrue("GenerateJsInteropExports should set", generateJsExportsIndex > 0);
114+
final List<String> actualJsExports = codeServerArgs.subList(generateJsExportsIndex, codeServerArgs.size());
115+
for (int expectedIndex = 0; expectedIndex < expectedJsExports.size(); expectedIndex++) {
116+
assertEquals("Setting for JS export not found", expectedJsExports.get(expectedIndex),
117+
actualJsExports.get(expectedIndex));
118+
}
119+
}
120+
121+
public void testWithJsInteropAndCustomRegexFilter() {
122+
final HostedModeOptionsMockWithCustomRegexFilter customOptions = new HostedModeOptionsMockWithCustomRegexFilter();
123+
setUpOptions(customOptions);
124+
customOptions.setGenerateJsInteropExports(true);
125+
customOptions.getJsInteropExportFilter().add("-com.google.gwt.exclude.First");
126+
customOptions.getJsInteropExportFilter().add("com.google.gwt.include.First");
127+
customOptions.getJsInteropExportFilter().add("-com.google.gwt.exclude.Second");
128+
customOptions.getJsInteropExportFilter().add("com.google.gwt.include.Second");
129+
customOptions.getJsInteropExportFilter().add("+com.google.gwt.include.Third");
130+
customOptions.getJsInteropExportFilter().add("*com.google.gwt.include.Fourth");
131+
132+
final SuperDevListener superDevListener = new SuperDevListener(treeLogger, customOptions);
133+
final List<String> codeServerArgs = superDevListener.getCodeServerArgs();
134+
final int generateJsExportsIndex = codeServerArgs.indexOf("-generateJsInteropExports") + 1;
135+
final List<String> expectedJsExports = createExpectedJsIncludesAndExcludesgetStrings();
136+
expectedJsExports.add("-includeJsInteropExports");
137+
expectedJsExports.add("com.google.gwt.include.Third");
138+
expectedJsExports.add("-includeJsInteropExports");
139+
expectedJsExports.add("*com.google.gwt.include.Fourth");
140+
141+
assertTrue("GenerateJsInteropExports should set", generateJsExportsIndex > 0);
142+
final List<String> actualJsExports = codeServerArgs.subList(generateJsExportsIndex, codeServerArgs.size());
143+
for (int expectedIndex = 0; expectedIndex < expectedJsExports.size(); expectedIndex++) {
144+
assertEquals("Setting for JS export not found", expectedJsExports.get(expectedIndex),
145+
actualJsExports.get(expectedIndex));
146+
}
147+
}
148+
149+
private static List<String> createExpectedJsIncludesAndExcludesgetStrings() {
150+
final List<String> expectedJsExports = new ArrayList<>();
151+
expectedJsExports.add("-excludeJsInteropExports");
152+
expectedJsExports.add("com.google.gwt.exclude.First");
153+
expectedJsExports.add("-includeJsInteropExports");
154+
expectedJsExports.add("com.google.gwt.include.First");
155+
expectedJsExports.add("-excludeJsInteropExports");
156+
expectedJsExports.add("com.google.gwt.exclude.Second");
157+
expectedJsExports.add("-includeJsInteropExports");
158+
expectedJsExports.add("com.google.gwt.include.Second");
159+
return expectedJsExports;
160+
}
161+
162+
private static class HostedModeOptionsMockWithCustomRegexFilter extends HostedModeOptionsMock {
163+
private final WhitelistRegexFilter whitelistRegexFilter = new CustomWhitelistRegexFilter();
164+
@Override
165+
public WhitelistRegexFilter getJsInteropExportFilter() {
166+
return whitelistRegexFilter;
167+
}
168+
}
169+
private static class CustomWhitelistRegexFilter extends WhitelistRegexFilter {
170+
private final List<String> values = new ArrayList<>();
171+
@Override
172+
public List<String> getValues() {
173+
return values;
174+
}
175+
@Override
176+
public void add(String regex) {
177+
values.add(regex);
178+
}
179+
@Override
180+
public void addAll(List<String> newValues) {
181+
values.addAll(newValues);
182+
}
183+
}
184+
}

0 commit comments

Comments
 (0)