Skip to content

Commit 4847911

Browse files
ludochgae-java-bot
authored andcommitted
Remove Java 8 specific classpath setup from ClassPathUtils.
PiperOrigin-RevId: 807265751 Change-Id: I67c62f3b120ff318b2ae0ad851e5ae7efa2278fb
1 parent 9d63cbc commit 4847911

5 files changed

Lines changed: 18 additions & 166 deletions

File tree

runtime/impl/src/main/java/com/google/apphosting/runtime/AppVersionFactory.java

Lines changed: 7 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -422,36 +422,13 @@ private ClassLoader createClassLoader(
422422
if (classPathUtils == null) {
423423
logger.atInfo().log("Ignoring API version setting %s", apiVersion);
424424
} else {
425-
File apiJar = classPathUtils.getFrozenApiJar();
426-
if (apiJar != null) {
427-
logger.atInfo().log("Adding API jar %s for version %s", apiJar, apiVersion);
428-
try {
429-
classPathBuilder.addAppengineJar(new URL("file", "", apiJar.getAbsolutePath()));
430-
} catch (MalformedURLException ex) {
431-
logger.atWarning().withCause(ex).log("Could not parse URL for %s, ignoring.", apiJar);
432-
}
433-
434-
File appengineApiLegacyJar = classPathUtils.getAppengineApiLegacyJar();
435-
if (appengineApiLegacyJar != null) {
436-
logger.atInfo().log("Adding appengine-api-legacy jar %s", appengineApiLegacyJar);
437-
try {
438-
// Add appengine-api-legacy jar with appengine-api-jar priority.
439-
classPathBuilder.addAppengineJar(
440-
new URL("file", "", appengineApiLegacyJar.getAbsolutePath()));
441-
} catch (MalformedURLException ex) {
442-
logger.atWarning().withCause(ex).log(
443-
"Could not parse URL for %s, ignoring.", appengineApiLegacyJar);
444-
}
445-
}
446-
} else {
447-
// TODO: We should probably return an
448-
// UPResponse::UNKNOWN_API_VERSION here, but I'd like to be
449-
// lenient until API versions are well established.
450-
logger.atWarning().log(
451-
"The Java runtime is not adding an API jar for this application, as the "
452-
+ "Java api_version defined in app.yaml or appinfo is unknown: %s",
453-
apiVersion);
454-
}
425+
// TODO: We should probably return an
426+
// UPResponse::UNKNOWN_API_VERSION here, but I'd like to be
427+
// lenient until API versions are well established.
428+
logger.atWarning().log(
429+
"The Java runtime is not adding an API jar for this application, as the "
430+
+ "Java api_version defined in app.yaml or appinfo is unknown: %s",
431+
apiVersion);
455432
}
456433
}
457434
if (!appInfo.getFileList().isEmpty()) {

runtime/impl/src/test/java/com/google/apphosting/runtime/ClassPathUtilsTest.java

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

1919
import static com.google.common.truth.Truth.assertThat;
2020

21-
import java.io.File;
2221
import org.junit.Before;
2322
import org.junit.Rule;
2423
import org.junit.Test;
@@ -40,15 +39,8 @@ public void setUp() throws Exception {
4039
System.setProperty("classpath.runtimebase", runtimeLocation);
4140
}
4241

43-
private void createJava8Environment() throws Exception {
44-
// Only Java8 runtime has the native launcher. This file is used to determine which env
45-
// must be used.
46-
temporaryFolder.newFile("java_runtime_launcher");
47-
}
48-
4942
@Test
5043
public void verifyJava11PropertiesAreConfigured() throws Exception {
51-
// we do not call createJava8Environment() so expect java11+
5244
ClassPathUtils cpu = new ClassPathUtils();
5345
assertThat(cpu.getConnectorJUrls()).hasLength(0);
5446
if (Boolean.getBoolean("appengine.use.EE8")|| Boolean.getBoolean("appengine.use.EE10")) {
@@ -63,33 +55,5 @@ public void verifyJava11PropertiesAreConfigured() throws Exception {
6355
.isEqualTo(runtimeLocation + "/runtime-shared-jetty9.jar");
6456
}
6557
assertThat(System.getProperty("classpath.connector-j")).isNull();
66-
67-
assertThat(cpu.getFrozenApiJar().getCanonicalPath())
68-
.isEqualTo(new File(runtimeLocation + "/appengine-api-1.0-sdk.jar").getCanonicalPath());
69-
}
70-
71-
@Test
72-
public void verifyMavenJarsPropertiesAreConfigured() throws Exception {
73-
createJava8Environment();
74-
75-
ClassPathUtils cpu = new ClassPathUtils(new File("/my_app_root"));
76-
assertThat(cpu.getConnectorJUrls()).hasLength(1);
77-
assertThat(System.getProperty("classpath.runtime-impl"))
78-
.isEqualTo(
79-
runtimeLocation
80-
+ "/jars/runtime-impl-jetty9.jar");
81-
82-
assertThat(System.getProperty("classpath.runtime-shared"))
83-
.isEqualTo(runtimeLocation + "/jars/runtime-shared-jetty9.jar");
84-
assertThat(System.getProperty("classpath.connector-j"))
85-
.isEqualTo(runtimeLocation + "/jdbc-mysql-connector.jar");
86-
87-
assertThat(cpu.getFrozenApiJar().getAbsolutePath())
88-
.isEqualTo("/my_app_root" + runtimeLocation + "/appengine-api.jar");
89-
assertThat(System.getProperty("classpath.appengine-api-legacy"))
90-
.isEqualTo(runtimeLocation + "/jars/appengine-api-legacy.jar");
91-
92-
assertThat(cpu.getAppengineApiLegacyJar().getAbsolutePath())
93-
.isEqualTo("/my_app_root" + runtimeLocation + "/jars/appengine-api-legacy.jar");
9458
}
9559
}

runtime/util/src/main/java/com/google/apphosting/runtime/ApplicationClassLoader.java

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -60,17 +60,14 @@ class ApplicationClassLoader extends URLClassLoader {
6060
static final String COMPAT_PROPERTY = "appengine.api.legacy.repackaging";
6161

6262
private final URL[] originalUrls;
63-
private final URL[] legacyUrls;
6463
private final URLClassLoader resourceLoader;
65-
boolean addedLegacyUrls;
6664

6765
ApplicationClassLoader(
68-
URL[] urls, URL[] legacyUrls, ClassLoader parent, boolean alwaysScanClassDirs) {
66+
URL[] urls, ClassLoader parent, boolean alwaysScanClassDirs) {
6967
super(
7068
alwaysScanClassDirs ? urls : excludeClasslessDirectories(urls),
7169
parent);
7270
this.originalUrls = urls;
73-
this.legacyUrls = legacyUrls;
7471
if (Arrays.equals(urls, super.getURLs())) {
7572
resourceLoader = null;
7673
} else {
@@ -149,13 +146,6 @@ protected Class<?> findClass(String name) throws ClassNotFoundException {
149146
try {
150147
return super.findClass(name);
151148
} catch (ClassNotFoundException e) {
152-
if (!addedLegacyUrls && Boolean.getBoolean(COMPAT_PROPERTY)) {
153-
for (URL url : legacyUrls) {
154-
addURL(url);
155-
}
156-
addedLegacyUrls = true;
157-
return super.findClass(name);
158-
}
159149
throw e;
160150
}
161151
}

runtime/util/src/main/java/com/google/apphosting/runtime/ClassPathUtils.java

Lines changed: 9 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
import java.net.MalformedURLException;
2323
import java.net.URL;
2424
import java.util.ArrayList;
25-
import java.util.Arrays;
2625
import java.util.List;
2726
import java.util.StringTokenizer;
2827
import java.util.logging.Level;
@@ -40,70 +39,16 @@ public class ClassPathUtils {
4039
private static final String RUNTIME_IMPL_PROPERTY = "classpath.runtime-impl";
4140
private static final String RUNTIME_SHARED_PROPERTY = "classpath.runtime-shared";
4241
private static final String PREBUNDLED_PROPERTY = "classpath.prebundled";
43-
private static final String API_PROPERTY = "classpath.api-map";
4442
private static final String CONNECTOR_J_PROPERTY = "classpath.connector-j";
45-
private static final String APPENGINE_API_LEGACY_PROPERTY = "classpath.appengine-api-legacy";
46-
private static final String LEGACY_PROPERTY = "classpath.legacy";
4743
// Cannot use Guava library in this classloader.
4844
private static final String PATH_SEPARATOR = System.getProperty("path.separator");
4945

5046
private final File root;
51-
private File frozenApiJarFile;
5247

5348
public ClassPathUtils() {
5449
this(null);
5550
}
56-
57-
public ClassPathUtils(File root) {
58-
59-
String runtimeBase = System.getProperty(RUNTIME_BASE_PROPERTY);
60-
if (runtimeBase == null) {
61-
throw new RuntimeException("System property not defined: " + RUNTIME_BASE_PROPERTY);
62-
}
63-
this.root = root;
64-
65-
if (!new File(runtimeBase, "java_runtime_launcher").exists()) {
66-
initForJava11OrAbove(runtimeBase);
67-
return;
68-
}
69-
70-
String profilerJar = null;
71-
if (System.getenv("GAE_PROFILER_MODE") != null) {
72-
profilerJar = "profiler.jar"; // Close source, not in Maven.;
73-
logger.log(Level.INFO, "AppEngine profiler enabled.");
74-
}
75-
List<String> runtimeClasspathEntries =
76-
Arrays.asList("jars/runtime-impl-jetty9.jar", profilerJar);
77-
78-
String runtimeClasspath =
79-
runtimeClasspathEntries.stream()
80-
.filter(t -> t != null)
81-
.map(s -> runtimeBase + "/" + s)
82-
.collect(joining(PATH_SEPARATOR));
83-
84-
if (System.getProperty(RUNTIME_IMPL_PROPERTY) != null) {
85-
// Prepend existing value, only used in our tests.
86-
runtimeClasspath =
87-
System.getProperty(RUNTIME_IMPL_PROPERTY) + PATH_SEPARATOR + runtimeClasspath;
88-
}
89-
// Keep old properties for absolute compatibility if ever some public apps depend on them:
90-
System.setProperty(RUNTIME_IMPL_PROPERTY, runtimeClasspath);
91-
logger.log(Level.INFO, "Using runtime classpath: " + runtimeClasspath);
92-
93-
// The frozen API jar we must use for ancient customers still relying on the obsolete feature
94-
// that when deploying with api_version: 1.0 in generated app.yaml
95-
// we need to add our own legacy jar.
96-
frozenApiJarFile = new File(new File(root, runtimeBase), "/appengine-api.jar");
97-
System.setProperty(RUNTIME_SHARED_PROPERTY, runtimeBase + "/jars/runtime-shared-jetty9.jar");
98-
System.setProperty(API_PROPERTY, "1.0=" + runtimeBase + "/jars/appengine-api-1.0-sdk.jar");
99-
System.setProperty(
100-
APPENGINE_API_LEGACY_PROPERTY, runtimeBase + "/jars/appengine-api-legacy.jar");
101-
System.setProperty(CONNECTOR_J_PROPERTY, runtimeBase + "/jdbc-mysql-connector.jar");
102-
System.setProperty(PREBUNDLED_PROPERTY, runtimeBase + "/conscrypt.jar");
103-
System.setProperty(LEGACY_PROPERTY, runtimeBase + "/legacy.jar");
104-
}
105-
106-
/**
51+
/**
10752
* Initializes runtime classpath properties for Java 11 and newer runtimes based on system
10853
* properties that indicate which Jakarta EE version and Jetty version to use.
10954
*
@@ -128,9 +73,15 @@ public ClassPathUtils(File root) {
12873
* <li>If EE6 is active (default), Jetty 9.4 is used with {@code runtime-shared-jetty9.jar}.
12974
* </ul>
13075
*
131-
* @param runtimeBase The base directory for runtime jars.
13276
*/
133-
private void initForJava11OrAbove(String runtimeBase) {
77+
78+
public ClassPathUtils(File root) {
79+
80+
String runtimeBase = System.getProperty(RUNTIME_BASE_PROPERTY);
81+
if (runtimeBase == null) {
82+
throw new RuntimeException("System property not defined: " + RUNTIME_BASE_PROPERTY);
83+
}
84+
this.root = root;
13485
/*
13586
New content is very simple now (from maven jars):
13687
ls blaze-bin/java/com/google/apphosting/runtime_java11/deployment_java11
@@ -223,7 +174,6 @@ New content is very simple now (from maven jars):
223174
System.setProperty(RUNTIME_IMPL_PROPERTY, runtimeClasspath);
224175
logger.log(Level.INFO, "Using runtime classpath: " + runtimeClasspath);
225176

226-
frozenApiJarFile = new File(runtimeBase, "/appengine-api-1.0-sdk.jar");
227177
}
228178

229179
public URL[] getRuntimeImplUrls() {
@@ -252,34 +202,6 @@ public URL[] getConnectorJUrls() {
252202
}
253203
}
254204

255-
/**
256-
* Returns the URLs for legacy jars. This may be empty or it may be one or more jars that contain
257-
* classes like {@code com.google.appengine.repackaged.org.joda.Instant}, the old form of
258-
* repackaging. We've switched to classes like {@code
259-
* com.google.appengine.repackaged.org.joda.$Instant}, with a {@code $}, but this jar can
260-
* optionally be added to an app's classpath if it is referencing the old names. Other legacy
261-
* classes, unrelated to repackaging, may also appear in these jars.
262-
*/
263-
public URL[] getLegacyJarUrls() {
264-
String path = System.getProperty(LEGACY_PROPERTY);
265-
if (path == null) {
266-
return new URL[0];
267-
} else {
268-
return parseClasspath(path);
269-
}
270-
}
271-
272-
/** Returns a {@link File} for the frozen old API jar, */
273-
public File getFrozenApiJar() {
274-
return frozenApiJarFile;
275-
}
276-
277-
@Nullable
278-
public File getAppengineApiLegacyJar() {
279-
String filename = System.getProperty(APPENGINE_API_LEGACY_PROPERTY);
280-
return filename == null ? null : new File(root, filename);
281-
}
282-
283205
/**
284206
* Parse the specified string into individual files (using the machine's path separator) and
285207
* return an array containing a {@link URL} object representing each file.

runtime/util/src/main/java/com/google/apphosting/runtime/NullSandboxPlugin.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,11 +138,10 @@ protected ClassLoader doCreateApplicationClassLoader(
138138
URL[] urls = getClassPathUtils().getConnectorJUrls();
139139
userUrls = append(urls, userUrls);
140140
}
141-
URL[] legacyUrls = getClassPathUtils().getLegacyJarUrls();
142141
boolean alwaysScanClassDirs = "true".equalsIgnoreCase(
143142
environment.getSystemProperties().get(ALWAYS_SCAN_CLASS_DIRS_PROPERTY));
144143
return new ApplicationClassLoader(
145-
userUrls, legacyUrls, sharedClassLoader, alwaysScanClassDirs);
144+
userUrls, sharedClassLoader, alwaysScanClassDirs);
146145
}
147146

148147
/**

0 commit comments

Comments
 (0)