Skip to content

Commit

Permalink
Support for java17 runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Clément Denis authored and meltsufin committed Sep 26, 2023
1 parent 52dd5aa commit a1c92b1
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ public class AppYamlProjectStaging {

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

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

@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 +78,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 +90,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
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import java.util.logging.LogRecord;
import org.junit.Assert;
import org.junit.Before;
import org.junit.ComparisonFailure;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TemporaryFolder;
Expand Down Expand Up @@ -107,9 +108,19 @@ 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");
}

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 +133,16 @@ 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");
}

private void stageArchive_gen2StandardBinaryPath(String runtime)
throws IOException, AppEngineException {
config =
AppYamlProjectStageConfiguration.builder()
.appEngineDirectory(appEngineDirectory)
Expand All @@ -132,7 +153,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 +166,15 @@ 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");
}

private void stageArchive_gen2BinaryWithoutEntrypoint(String runtime) throws IOException {
Path nonJarArtifact = temporaryFolder.newFile("myscript.sh").toPath();
config =
AppYamlProjectStageConfiguration.builder()
Expand All @@ -156,7 +186,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 +196,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

0 comments on commit a1c92b1

Please sign in to comment.