Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support for java17 and java21 runtimes #936

Merged
merged 7 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/unit-tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ jobs:
strategy:
fail-fast: false
matrix:
java: [8, 11, 17]
java: [8, 11, 17, 21]
env:
CLOUDSDK_CORE_DISABLE_USAGE_REPORTING: true
CLOUDSDK_CORE_DISABLE_PROMPTS: true
Expand Down
17 changes: 13 additions & 4 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<version>4.4.0</version>
<version>5.5.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -244,7 +244,7 @@
<plugin>
<groupId>org.jacoco</groupId>
<artifactId>jacoco-maven-plugin</artifactId>
<version>0.8.7</version>
<version>0.8.10</version>
<executions>
<execution>
<id>initialize</id>
Expand Down Expand Up @@ -329,12 +329,12 @@
<path>
<groupId>com.google.errorprone</groupId>
<artifactId>error_prone_core</artifactId>
<version>2.11.0</version>
<version>2.22.0</version>
</path>
<path>
<groupId>com.uber.nullaway</groupId>
<artifactId>nullaway</artifactId>
<version>0.7.8</version>
<version>0.10.14</version>
</path>
</annotationProcessorPaths>
<fork>true</fork>
Expand Down Expand Up @@ -420,6 +420,15 @@
<activation>
<jdk>1.8</jdk>
</activation>
<dependencies>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<!-- keep 4.x for JDK 8 tests as 5.x is for JDK 11+ -->
<version>4.11.0</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.google.common.base.Splitter;
import com.google.common.base.Strings;
import com.google.common.collect.ImmutableList;
import com.google.common.collect.ImmutableSet;
import java.io.IOException;
import java.io.InputStream;
import java.nio.file.Files;
Expand All @@ -44,6 +45,9 @@ public class AppYamlProjectStaging {

private static final String APP_YAML = "app.yaml";

private static final ImmutableSet<String> GEN2_RUNTIMES =
ImmutableSet.of("java11", "java17", "java21");

@VisibleForTesting
static final ImmutableList<String> OTHER_YAMLS =
ImmutableList.of("cron.yaml", "dos.yaml", "dispatch.yaml", "index.yaml", "queue.yaml");
Expand Down Expand Up @@ -76,7 +80,7 @@ public void stageArchive(AppYamlProjectStageConfiguration config) throws AppEngi
stageFlexibleArchive(config, runtime);
return;
}
if ("java11".equals(runtime) || "java17".equals(runtime)) {
if (GEN2_RUNTIMES.contains(runtime)) {
boolean isJar = config.getArtifact().getFileName().toString().endsWith(".jar");
if (isJar) {
stageStandardArchive(config);
Expand All @@ -88,7 +92,9 @@ public void stageArchive(AppYamlProjectStageConfiguration config) throws AppEngi
}
// I cannot deploy non-jars without custom entrypoints
throw new AppEngineException(
"Cannot process application with runtime: java11/java17."
"Cannot process application with runtime: "
+ runtime
+ "."
+ " A custom entrypoint must be defined in your app.yaml for non-jar artifact: "
+ config.getArtifact().toString());
}
Expand Down Expand Up @@ -248,10 +254,10 @@ static void copyArtifactJarClasspath(
Iterable<String> classpathEntries = Splitter.onPattern("\\s+").split(jarClassPath.trim());
for (String classpathEntry : classpathEntries) {
// classpath entries are relative to artifact's position and relativeness should be
// preserved
// in the target directory
Path jarSrc = artifact.getParent().resolve(classpathEntry);
if (!Files.isRegularFile(jarSrc)) {
// preserved in the target directory
Path jarSrc =
artifact.getParent() == null ? null : artifact.getParent().resolve(classpathEntry);
if (jarSrc == null || !Files.isRegularFile(jarSrc)) {
log.warning("Could not copy 'Class-Path' jar: " + jarSrc + " referenced in MANIFEST.MF");
continue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,9 +72,11 @@ public void run(
command.add(sdk.getJavaExecutablePath().toAbsolutePath().toString());

command.addAll(jvmArgs);
command.add(
"-Dappengine.sdk.root="
+ sdk.getAppEngineSdkForJavaPath().getParent().toAbsolutePath().toString());
if (sdk.getAppEngineSdkForJavaPath().getParent() != null) {
command.add(
"-Dappengine.sdk.root="
+ sdk.getAppEngineSdkForJavaPath().getParent().toAbsolutePath().toString());
}
command.add("-cp");
command.add(sdk.getAppEngineToolsJar().toAbsolutePath().toString());
command.add("com.google.appengine.tools.development.DevAppServerMain");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,9 +107,24 @@ public void testStageArchive_flexPath() throws IOException, AppEngineException {

@Test
public void testStageArchive_java11StandardPath() throws IOException, AppEngineException {
stageArchive_gen2StandardPath("java11");
}

@Test
public void testStageArchive_java17StandardPath() throws IOException, AppEngineException {
stageArchive_gen2StandardPath("java17");
}

@Test
public void testStageArchive_java21StandardPath() throws IOException, AppEngineException {
stageArchive_gen2StandardPath("java21");
}

private void stageArchive_gen2StandardPath(String runtime)
throws IOException, AppEngineException {
Files.write(
appEngineDirectory.resolve("app.yaml"),
"runtime: java11\n".getBytes(StandardCharsets.UTF_8),
("runtime: " + runtime + "\n").getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE_NEW);

// mock to watch internal calls
Expand All @@ -122,6 +137,21 @@ public void testStageArchive_java11StandardPath() throws IOException, AppEngineE

@Test
public void testStageArchive_java11StandardBinaryPath() throws IOException, AppEngineException {
stageArchive_gen2StandardBinaryPath("java11");
}

@Test
public void testStageArchive_java17StandardBinaryPath() throws IOException, AppEngineException {
stageArchive_gen2StandardBinaryPath("java17");
}

@Test
public void testStageArchive_java21StandardBinaryPath() throws IOException, AppEngineException {
stageArchive_gen2StandardBinaryPath("java21");
}

private void stageArchive_gen2StandardBinaryPath(String runtime)
throws IOException, AppEngineException {
config =
AppYamlProjectStageConfiguration.builder()
.appEngineDirectory(appEngineDirectory)
Expand All @@ -132,7 +162,7 @@ public void testStageArchive_java11StandardBinaryPath() throws IOException, AppE

Files.write(
appEngineDirectory.resolve("app.yaml"),
"runtime: java11\nentrypoint: anything\n".getBytes(StandardCharsets.UTF_8),
("runtime: " + runtime + "\nentrypoint: anything\n").getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE_NEW);

// mock to watch internal calls
Expand All @@ -145,6 +175,20 @@ public void testStageArchive_java11StandardBinaryPath() throws IOException, AppE

@Test
public void testStageArchive_java11BinaryWithoutEntrypoint() throws IOException {
stageArchive_gen2BinaryWithoutEntrypoint("java11");
}

@Test
public void testStageArchive_java17BinaryWithoutEntrypoint() throws IOException {
stageArchive_gen2BinaryWithoutEntrypoint("java17");
}

@Test
public void testStageArchive_java21BinaryWithoutEntrypoint() throws IOException {
stageArchive_gen2BinaryWithoutEntrypoint("java21");
}

private void stageArchive_gen2BinaryWithoutEntrypoint(String runtime) throws IOException {
Path nonJarArtifact = temporaryFolder.newFile("myscript.sh").toPath();
config =
AppYamlProjectStageConfiguration.builder()
Expand All @@ -156,7 +200,7 @@ public void testStageArchive_java11BinaryWithoutEntrypoint() throws IOException

Files.write(
appEngineDirectory.resolve("app.yaml"),
"runtime: java11\n".getBytes(StandardCharsets.UTF_8),
("runtime: " + runtime + "\n").getBytes(StandardCharsets.UTF_8),
StandardOpenOption.CREATE_NEW);

AppYamlProjectStaging testStaging = new AppYamlProjectStaging();
Expand All @@ -166,8 +210,10 @@ public void testStageArchive_java11BinaryWithoutEntrypoint() throws IOException
fail();
} catch (AppEngineException ex) {
assertEquals(
"Cannot process application with runtime: java11/java17. A custom entrypoint must be defined in your app.yaml for non-jar artifact: "
+ nonJarArtifact.toString(),
"Cannot process application with runtime: "
+ runtime
+ ". A custom entrypoint must be defined in your app.yaml for non-jar artifact: "
+ config.getArtifact().toString(),
ex.getMessage());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import org.mockito.junit.MockitoJUnitRunner;

@RunWith(MockitoJUnitRunner.class)
@SuppressWarnings("NullAway")
public class DevServersRunnerTest {

@Rule public TemporaryFolder testFolder = new TemporaryFolder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import org.junit.rules.TemporaryFolder;
import org.mockito.Mockito;

@SuppressWarnings("NullAway")
public class PathResolverTest {

@ClassRule public static TemporaryFolder symlinkTestArea = new TemporaryFolder();
Expand Down