Skip to content

Commit a224675

Browse files
ludochgae-java-bot
authored andcommitted
Fix #13
PiperOrigin-RevId: 466000250 Change-Id: I3fdd59c3cf0400ae7a7758b13d7621f080c8e0f4
1 parent bcb69c0 commit a224675

2 files changed

Lines changed: 33 additions & 40 deletions

File tree

lib/tools_api/src/main/java/com/google/appengine/tools/KickStart.java

Lines changed: 14 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,11 @@
1616

1717
package com.google.appengine.tools;
1818

19+
import static com.google.common.base.StandardSystemProperty.JAVA_CLASS_PATH;
1920
import static com.google.common.base.StandardSystemProperty.JAVA_HOME;
21+
import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION;
2022
import static com.google.common.base.StandardSystemProperty.OS_NAME;
23+
import static com.google.common.base.StandardSystemProperty.USER_DIR;
2124

2225
import com.google.appengine.tools.development.DevAppServerMain;
2326
import com.google.apphosting.utils.config.AppEngineConfigException;
@@ -95,19 +98,6 @@ public class KickStart {
9598
private static final String SDK_ROOT_FLAG = "--sdk_root";
9699
private static final String SDK_ROOT_ERROR_MESSAGE = SDK_ROOT_FLAG + "=<path> expected";
97100

98-
private static final String ENABLE_JACOCO_FLAG = "--enable_jacoco";
99-
private static final String ENABLE_JACOCO_ERROR_MESSAGE =
100-
ENABLE_JACOCO_FLAG + "=true|false expected.";
101-
private static final String JACOCO_AGENT_JAR_FLAG = "--jacoco_agent_jar";
102-
private static final String JACOCO_AGENT_JAR_ERROR_MESSAGE =
103-
JACOCO_AGENT_JAR_FLAG + "=<path> expected.";
104-
private static final String JACOCO_AGENT_ARGS_FLAG = "--jacoco_agent_args";
105-
private static final String JACOCO_AGENT_ARGS_ERROR_MESSAGE =
106-
JACOCO_AGENT_ARGS_FLAG + "=<jacoco agent args> expected.";
107-
private static final String JACOCO_EXEC_FLAG = "--jacoco_exec";
108-
private static final String JACOCO_EXEC_ERROR_MESSAGE =
109-
JACOCO_EXEC_FLAG + "=<path> expected.";
110-
111101
private Process serverProcess = null;
112102

113103
static class AppEnvironment {
@@ -136,10 +126,6 @@ private KickStart(String[] args) {
136126

137127
List<String> jvmArgs = new ArrayList<>();
138128
ArrayList<String> appServerArgs = new ArrayList<>();
139-
boolean enableJacoco = false;
140-
String jacocoAgentJarArg = null;
141-
String jacocoAgentArgs = "";
142-
String jacocoExecArg = "jacoco.exec";
143129

144130
List<String> command = builder.command();
145131
command.add(javaExe);
@@ -160,14 +146,6 @@ private KickStart(String[] args) {
160146
} else if (args[i].startsWith(START_ON_FIRST_THREAD_FLAG)) {
161147
startOnFirstThread =
162148
Boolean.parseBoolean(extractValue(args[i], START_ON_FIRST_THREAD_ERROR_MESSAGE));
163-
} else if (args[i].startsWith(ENABLE_JACOCO_FLAG)) {
164-
enableJacoco = "true".equals(extractValue(args[i], ENABLE_JACOCO_ERROR_MESSAGE));
165-
} else if (args[i].startsWith(JACOCO_AGENT_JAR_FLAG)) {
166-
jacocoAgentJarArg = extractValue(args[i], JACOCO_AGENT_JAR_ERROR_MESSAGE);
167-
} else if (args[i].startsWith(JACOCO_AGENT_ARGS_FLAG)) {
168-
jacocoAgentArgs = extractValue(args[i], JACOCO_AGENT_ARGS_ERROR_MESSAGE);
169-
} else if (args[i].startsWith(JACOCO_EXEC_FLAG)) {
170-
jacocoExecArg = extractValue(args[i], JACOCO_EXEC_ERROR_MESSAGE);
171149
} else if (args[i].equals("--test_mode")) {
172150
testMode = true;
173151
} else if (entryClass == null) {
@@ -202,10 +180,19 @@ private KickStart(String[] args) {
202180
// For more details, see http://b/issue?id=1709075.
203181
jvmArgs.add("-XstartOnFirstThread");
204182
}
183+
if (!JAVA_SPECIFICATION_VERSION.value().equals("1.8")) {
184+
// Java11 or later need more flags:
185+
jvmArgs.add("--add-opens");
186+
jvmArgs.add("java.base/java.net=ALL-UNNAMED");
187+
jvmArgs.add("--add-opens");
188+
jvmArgs.add("java.base/sun.net.www.protocol.http=ALL-UNNAMED");
189+
jvmArgs.add("--add-opens");
190+
jvmArgs.add("java.base/sun.net.www.protocol.https=ALL-UNNAMED");
191+
}
205192

206193
// Whatever classpath we were invoked with might have been relative.
207194
// We make all paths in the classpath absolute.
208-
String classpath = System.getProperty("java.class.path");
195+
String classpath = JAVA_CLASS_PATH.value();
209196
if (classpath == null) {
210197
throw new IllegalArgumentException("classpath must not be null");
211198
}
@@ -256,24 +243,13 @@ private KickStart(String[] args) {
256243
}
257244
jvmArgs.add("-Dfile.encoding=" + encoding);
258245

259-
if (enableJacoco) {
260-
jvmArgs.add("-D--enable_all_permissions=true");
261-
String jacocoAgentJar = new File(jacocoAgentJarArg).getAbsolutePath();
262-
if (!jacocoAgentArgs.isEmpty()) {
263-
jacocoAgentArgs = jacocoAgentArgs + ",";
264-
}
265-
jacocoAgentArgs += "destfile=" + new File(jacocoExecArg).getAbsolutePath();
266-
jvmArgs.add("-javaagent:" + jacocoAgentJar + "=" + jacocoAgentArgs);
267-
}
268-
269246
// Build up the command
270247
command.addAll(jvmArgs);
271248
command.add("-classpath");
272249
command.add(newClassPath.toString());
273250
command.add(entryClass);
274251
// Pass the current working directory so relative files can be interpreted the natural way.
275-
command.add("--property=kickstart.user.dir=" + System.getProperty("user.dir"));
276-
command.add("--no_java_agent");
252+
command.add("--property=kickstart.user.dir=" + USER_DIR.value());
277253

278254
command.addAll(absoluteAppServerArgs);
279255
// Setup environment variables.

lib/tools_api/src/test/java/com/google/appengine/tools/KickStartTest.java

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818

1919
import static com.google.common.base.StandardSystemProperty.JAVA_CLASS_PATH;
2020
import static com.google.common.base.StandardSystemProperty.JAVA_HOME;
21+
import static com.google.common.base.StandardSystemProperty.JAVA_SPECIFICATION_VERSION;
2122
import static com.google.common.base.StandardSystemProperty.PATH_SEPARATOR;
2223
import static com.google.common.truth.Truth.assertThat;
2324
import static com.google.common.truth.Truth.assertWithMessage;
@@ -70,7 +71,7 @@ private String extractResourceToFilePath(String resourcePath) {
7071
}
7172

7273
@Test
73-
public void testReadAppEnvironment() throws java.lang.InterruptedException {
74+
public void testReadAppEnvironment() throws InterruptedException {
7475
AppEnvironment java8Config =
7576
KickStart.readAppEnvironment(extractAppResourceToFilePath("warjava8"));
7677
assertThat(java8Config.serviceName).isEqualTo("default");
@@ -170,8 +171,24 @@ private List<String> runWithKickStart(File webInfDir) throws IOException, Interr
170171
KickStart.class.getName(),
171172
"--test_mode",
172173
"com.google.appengine.tools.PrintDefaultCharset",
173-
"--no_java_agent",
174174
webInfDir.getPath());
175+
if (!JAVA_SPECIFICATION_VERSION.value().equals("1.8")) {
176+
args =
177+
ImmutableList.of(
178+
javaBinary,
179+
"-classpath",
180+
classpath,
181+
"--add-opens",
182+
"java.base/java.net=ALL-UNNAMED",
183+
"--add-opens",
184+
"java.base/sun.net.www.protocol.http=ALL-UNNAMED",
185+
"--add-opens",
186+
"java.base/sun.net.www.protocol.https=ALL-UNNAMED",
187+
KickStart.class.getName(),
188+
"--test_mode",
189+
"com.google.appengine.tools.PrintDefaultCharset",
190+
webInfDir.getPath());
191+
}
175192
Process p =
176193
new ProcessBuilder(args)
177194
.redirectErrorStream(true)

0 commit comments

Comments
 (0)