Skip to content

Commit

Permalink
Remove first character for delegating args to CodeServer (#9940)
Browse files Browse the repository at this point in the history
fix for #9939
  • Loading branch information
MCMicS committed Apr 7, 2024
1 parent 34b2a44 commit e43a589
Show file tree
Hide file tree
Showing 3 changed files with 211 additions and 1 deletion.
8 changes: 7 additions & 1 deletion dev/core/src/com/google/gwt/dev/shell/SuperDevListener.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import com.google.gwt.dev.DevMode.HostedModeOptions;
import com.google.gwt.dev.cfg.ModuleDef;
import com.google.gwt.dev.util.arg.OptionMethodNameDisplayMode;
import com.google.gwt.thirdparty.guava.common.annotations.VisibleForTesting;
import com.google.gwt.thirdparty.guava.common.base.Stopwatch;
import com.google.gwt.thirdparty.guava.common.collect.ListMultimap;
import com.google.gwt.thirdparty.guava.common.collect.Lists;
Expand Down Expand Up @@ -63,6 +64,11 @@ public int getSocketPort() {
return codeServerPort;
}

@VisibleForTesting
List<String> getCodeServerArgs() {
return codeServerArgs;
}

@Override
public URL makeStartupUrl(String url) throws UnableToCompleteException {
try {
Expand Down Expand Up @@ -174,7 +180,7 @@ private static List<String> makeCodeServerArgs(HostedModeOptions options, int po
args.add(regex.substring(1));
} else {
args.add("-includeJsInteropExports");
args.add(regex);
args.add(regex.startsWith("+") ? regex.substring(1) : regex);
}
}
if (!options.isIncrementalCompileEnabled()) {
Expand Down
20 changes: 20 additions & 0 deletions dev/core/test/com/google/gwt/dev/HostedModeOptionsMock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/*
* Copyright 2024 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.gwt.dev;

/**
* Make {@link com.google.gwt.dev.DevMode.HostedModeOptionsImpl} visible as mock for tests..
*/
public class HostedModeOptionsMock extends DevMode.HostedModeOptionsImpl {
}
184 changes: 184 additions & 0 deletions dev/core/test/com/google/gwt/dev/shell/SuperDevListenerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
/*
* Copyright 2024 Google Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
* in compliance with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License
* is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
* or implied. See the License for the specific language governing permissions and limitations under
* the License.
*/
package com.google.gwt.dev.shell;

import com.google.gwt.core.ext.TreeLogger;
import com.google.gwt.dev.DevMode;
import com.google.gwt.dev.HostedModeOptionsMock;
import com.google.gwt.dev.jjs.JsOutputOption;
import com.google.gwt.dev.util.arg.OptionMethodNameDisplayMode;
import com.google.gwt.dev.util.arg.SourceLevel;
import com.google.gwt.thirdparty.guava.common.collect.ImmutableList;
import com.google.gwt.util.regexfilter.WhitelistRegexFilter;

import junit.framework.TestCase;

import java.io.File;
import java.io.IOException;
import java.nio.file.Files;
import java.util.ArrayList;
import java.util.List;

/**
* A wide variety of tests on {@link SuperDevListener}.
*/
public class SuperDevListenerTest extends TestCase {
private static final int TEST_PORT = 9998;
private static final String MODULE_NAME = "Test_Module_Name";
private final TreeLogger treeLogger = new FailErrorLogger();
private final DevMode.HostedModeOptions options = new HostedModeOptionsMock();
private final WhitelistRegexFilter whitelistRegexFilter = new WhitelistRegexFilter();
private File warDir;
@Override
public void setUp() throws IOException {
warDir = Files.createTempDirectory("war-file").toFile();
warDir.deleteOnExit();
setUpOptions(options);
}

private void setUpOptions(DevMode.HostedModeOptions optionsToPrepare) {
optionsToPrepare.setCodeServerPort(TEST_PORT);
optionsToPrepare.setSourceLevel(SourceLevel.JAVA17);
optionsToPrepare.setWarDir(warDir);
optionsToPrepare.setOutput(JsOutputOption.DETAILED);
optionsToPrepare.setGenerateJsInteropExports(false);
optionsToPrepare.setIncrementalCompileEnabled(true);
optionsToPrepare.setMethodNameDisplayMode(OptionMethodNameDisplayMode.Mode.NONE);
optionsToPrepare.setStrict(false);
optionsToPrepare.setModuleNames(ImmutableList.of(MODULE_NAME));
}

public void testDefaultArgs() {
final SuperDevListener superDevListener = new SuperDevListener(treeLogger, options);
final List<String> codeServerArgs = superDevListener.getCodeServerArgs();
assertEquals("Wrong default arguments", 10, codeServerArgs.size());
assertTrue("Precompile flag should set", codeServerArgs.contains("-noprecompile"));
assertTrue("Port should set", codeServerArgs.contains("-port"));
assertTrue("Port should set", codeServerArgs.contains(Integer.toString(TEST_PORT)));
assertTrue("SourceLevel should set", codeServerArgs.contains("-sourceLevel"));
assertTrue("SourceLevel should set", codeServerArgs.contains(SourceLevel.JAVA17.getStringValue()));
assertTrue("LauncherDir should set", codeServerArgs.contains("-launcherDir"));
assertTrue("LauncherDir should set", codeServerArgs.contains(warDir.getAbsolutePath()));
assertTrue("Style should set", codeServerArgs.contains("-style"));
assertTrue("Style should set", codeServerArgs.contains("DETAILED"));
assertTrue("Module name should set", codeServerArgs.contains(MODULE_NAME));
}

public void testDefaultNonSuperDevModePort() {
final int port = 9997;
options.setCodeServerPort(port);
final SuperDevListener superDevListener = new SuperDevListener(treeLogger, options);
final List<String> codeServerArgs = superDevListener.getCodeServerArgs();
assertTrue("Port should set", codeServerArgs.contains("-port"));
assertTrue("SuperDevMode Default port should set", codeServerArgs.contains("9876"));
}

public void testWithJsInteropAndSingleIncludeAndExclude() {
options.setGenerateJsInteropExports(true);
options.getJsInteropExportFilter().add("-com.google.gwt.exclude.First");
options.getJsInteropExportFilter().add("com.google.gwt.include.First");

final SuperDevListener superDevListener = new SuperDevListener(treeLogger, options);
final List<String> codeServerArgs = superDevListener.getCodeServerArgs();
assertTrue("GenerateJsInteropExports should set", codeServerArgs.contains("-generateJsInteropExports"));
assertTrue("ExcludeJsInteropExports should set", codeServerArgs.contains("-excludeJsInteropExports"));
assertTrue("ExcludeJsInteropExports should set", codeServerArgs.contains("com.google.gwt.exclude.First"));
assertTrue("IncludeJsInteropExports should set", codeServerArgs.contains("-includeJsInteropExports"));
assertTrue("IncludeJsInteropExports should set", codeServerArgs.contains("com.google.gwt.include.First"));
}

public void testWithJsInteropIncludesAndExcludes() {
options.setGenerateJsInteropExports(true);
options.getJsInteropExportFilter().add("-com.google.gwt.exclude.First");
options.getJsInteropExportFilter().add("com.google.gwt.include.First");
options.getJsInteropExportFilter().add("-com.google.gwt.exclude.Second");
options.getJsInteropExportFilter().add("com.google.gwt.include.Second");

final SuperDevListener superDevListener = new SuperDevListener(treeLogger, options);
final List<String> codeServerArgs = superDevListener.getCodeServerArgs();
final int generateJsExportsIndex = codeServerArgs.indexOf("-generateJsInteropExports") + 1;
final List<String> expectedJsExports = createExpectedJsIncludesAndExcludesgetStrings();

assertTrue("GenerateJsInteropExports should set", generateJsExportsIndex > 0);
final List<String> actualJsExports = codeServerArgs.subList(generateJsExportsIndex, codeServerArgs.size());
for (int expectedIndex = 0; expectedIndex < expectedJsExports.size(); expectedIndex++) {
assertEquals("Setting for JS export not found", expectedJsExports.get(expectedIndex),
actualJsExports.get(expectedIndex));
}
}

public void testWithJsInteropAndCustomRegexFilter() {
final HostedModeOptionsMockWithCustomRegexFilter customOptions = new HostedModeOptionsMockWithCustomRegexFilter();
setUpOptions(customOptions);
customOptions.setGenerateJsInteropExports(true);
customOptions.getJsInteropExportFilter().add("-com.google.gwt.exclude.First");
customOptions.getJsInteropExportFilter().add("com.google.gwt.include.First");
customOptions.getJsInteropExportFilter().add("-com.google.gwt.exclude.Second");
customOptions.getJsInteropExportFilter().add("com.google.gwt.include.Second");
customOptions.getJsInteropExportFilter().add("+com.google.gwt.include.Third");
customOptions.getJsInteropExportFilter().add("*com.google.gwt.include.Fourth");

final SuperDevListener superDevListener = new SuperDevListener(treeLogger, customOptions);
final List<String> codeServerArgs = superDevListener.getCodeServerArgs();
final int generateJsExportsIndex = codeServerArgs.indexOf("-generateJsInteropExports") + 1;
final List<String> expectedJsExports = createExpectedJsIncludesAndExcludesgetStrings();
expectedJsExports.add("-includeJsInteropExports");
expectedJsExports.add("com.google.gwt.include.Third");
expectedJsExports.add("-includeJsInteropExports");
expectedJsExports.add("*com.google.gwt.include.Fourth");

assertTrue("GenerateJsInteropExports should set", generateJsExportsIndex > 0);
final List<String> actualJsExports = codeServerArgs.subList(generateJsExportsIndex, codeServerArgs.size());
for (int expectedIndex = 0; expectedIndex < expectedJsExports.size(); expectedIndex++) {
assertEquals("Setting for JS export not found", expectedJsExports.get(expectedIndex),
actualJsExports.get(expectedIndex));
}
}

private static List<String> createExpectedJsIncludesAndExcludesgetStrings() {
final List<String> expectedJsExports = new ArrayList<>();
expectedJsExports.add("-excludeJsInteropExports");
expectedJsExports.add("com.google.gwt.exclude.First");
expectedJsExports.add("-includeJsInteropExports");
expectedJsExports.add("com.google.gwt.include.First");
expectedJsExports.add("-excludeJsInteropExports");
expectedJsExports.add("com.google.gwt.exclude.Second");
expectedJsExports.add("-includeJsInteropExports");
expectedJsExports.add("com.google.gwt.include.Second");
return expectedJsExports;
}

private static class HostedModeOptionsMockWithCustomRegexFilter extends HostedModeOptionsMock {
private final WhitelistRegexFilter whitelistRegexFilter = new CustomWhitelistRegexFilter();
@Override
public WhitelistRegexFilter getJsInteropExportFilter() {
return whitelistRegexFilter;
}
}
private static class CustomWhitelistRegexFilter extends WhitelistRegexFilter {
private final List<String> values = new ArrayList<>();
@Override
public List<String> getValues() {
return values;
}
@Override
public void add(String regex) {
values.add(regex);
}
@Override
public void addAll(List<String> newValues) {
values.addAll(newValues);
}
}
}

0 comments on commit e43a589

Please sign in to comment.