Skip to content

Commit

Permalink
add extra JPMS open flags for Java 9 and up (#894)
Browse files Browse the repository at this point in the history
  • Loading branch information
elefeint authored Aug 8, 2022
1 parent acf4d31 commit 727ff8b
Show file tree
Hide file tree
Showing 4 changed files with 611 additions and 3 deletions.
2 changes: 1 addition & 1 deletion appengine-plugins-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<!-- Errorprone check exclusions; see https://errorprone.info/docs/flags -->
<errorprone_exclusions>com.google.cloud.tools.appengine.operations.DevServerTest,com.google.cloud.tools.appengine.operations.cloudsdk.serialization.AppEngineDeployResult,com.google.cloud.tools.io.FilePermissionsTest,com.google.cloud.tools.managedcloudsdk.install.InstallerFactoryTest,com.google.cloud.tools.appengine.AppEngineDescriptorTest,com.google.cloud.tools.appengine.operations.cloudsdk.serialization.CloudSdkVersionTest,com.google.cloud.tools.appengine.operations.GenRepoInfoFileTest,com.google.cloud.tools.appengine.operations.DeploymentTest,com.google.cloud.tools.appengine.operations.AuthTest,com.google.cloud.tools.appengine.configuration.RunConfigurationTest</errorprone_exclusions>
<errorprone_exclusions>com.google.cloud.tools.appengine.operations.DevServerJava8Test,com.google.cloud.tools.appengine.operations.DevServerJava9OrAboveTest,com.google.cloud.tools.appengine.operations.cloudsdk.serialization.AppEngineDeployResult,com.google.cloud.tools.io.FilePermissionsTest,com.google.cloud.tools.managedcloudsdk.install.InstallerFactoryTest,com.google.cloud.tools.appengine.AppEngineDescriptorTest,com.google.cloud.tools.appengine.operations.cloudsdk.serialization.CloudSdkVersionTest,com.google.cloud.tools.appengine.operations.GenRepoInfoFileTest,com.google.cloud.tools.appengine.operations.DeploymentTest,com.google.cloud.tools.appengine.operations.AuthTest,com.google.cloud.tools.appengine.configuration.RunConfigurationTest</errorprone_exclusions>
</properties>

<dependencies>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package com.google.cloud.tools.appengine.operations;

import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION;

import com.google.cloud.tools.appengine.AppEngineDescriptor;
import com.google.cloud.tools.appengine.AppEngineException;
import com.google.cloud.tools.appengine.configuration.RunConfiguration;
Expand Down Expand Up @@ -80,6 +82,16 @@ public void run(RunConfiguration config) throws AppEngineException {
jvmArguments.addAll(config.getJvmFlags());
}

if (!JAVA_SPECIFICATION_VERSION.value().equals("1.8")) {
// Due to JPMS restrictions, Java11 or later need more flags:
jvmArguments.add("--add-opens");
jvmArguments.add("java.base/java.net=ALL-UNNAMED");
jvmArguments.add("--add-opens");
jvmArguments.add("java.base/sun.net.www.protocol.http=ALL-UNNAMED");
jvmArguments.add("--add-opens");
jvmArguments.add("java.base/sun.net.www.protocol.https=ALL-UNNAMED");
}

arguments.addAll(DevAppServerArgs.get("default_gcs_bucket", config.getDefaultGcsBucketName()));
arguments.addAll(DevAppServerArgs.get("application", config.getProjectId()));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2016 Google LLC.
* Copyright 2016-2022 Google LLC.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -16,6 +16,8 @@

package com.google.cloud.tools.appengine.operations;

import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION;
import static org.junit.Assume.assumeTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.times;
Expand All @@ -39,6 +41,7 @@
import java.util.logging.LogRecord;
import org.junit.Assert;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand All @@ -49,7 +52,7 @@

/** Unit tests for {@link DevServer}. */
@RunWith(MockitoJUnitRunner.class)
public class DevServerTest {
public class DevServerJava8Test {

@Rule public TemporaryFolder temporaryFolder = new TemporaryFolder();
private Path fakeJavaSdkHome;
Expand All @@ -74,6 +77,12 @@ public class DevServerTest {
private final Map<String, String> expectedJava8Environment =
ImmutableMap.of("GAE_ENV", "localdev", "GAE_RUNTIME", "java8");

@BeforeClass
public static void disableIfJavaVersionAbove8() {
assumeTrue(
"DevServerTestJava8 requires Java 8", JAVA_SPECIFICATION_VERSION.value().equals("1.8"));
}

@Before
public void setUp() throws IOException {
devServer = Mockito.spy(new DevServer(sdk, devAppServerRunner));
Expand Down
Loading

0 comments on commit 727ff8b

Please sign in to comment.