Skip to content

Commit

Permalink
Support Java 11 WAR projects (#1516)
Browse files Browse the repository at this point in the history
  • Loading branch information
chanseokoh authored Feb 28, 2019
1 parent b0174eb commit 083c255
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 9 deletions.
4 changes: 3 additions & 1 deletion jib-gradle-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.

### Added

- Java 9+ WAR projects are now supported and run on the distroless Jetty Java 11 image (https://github.com/GoogleContainerTools/distroless) by default. Java 8 projects remain on the distroless Jetty Java 8 image. ([#1510](https://github.com/GoogleContainerTools/jib/issues/1510))

### Changed

### Fixed
Expand All @@ -13,7 +15,7 @@ All notable changes to this project will be documented in this file.

### Added

- Java 9+ projects are now supported and run on the distroless Java 11 image by default. Java 8 projects remain on the distroless Java 8 image. ([#1279](https://github.com/GoogleContainerTools/jib/issues/1279))
- Java 9+ projects are now supported and run on the distroless Java 11 image (https://github.com/GoogleContainerTools/distroless) by default. Java 8 projects remain on the distroless Java 8 image. ([#1279](https://github.com/GoogleContainerTools/jib/issues/1279))

### Fixed

Expand Down
4 changes: 3 additions & 1 deletion jib-maven-plugin/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ All notable changes to this project will be documented in this file.

### Added

- Java 9+ WAR projects are now supported and run on the distroless Jetty Java 11 image (https://github.com/GoogleContainerTools/distroless) by default. Java 8 projects remain on the distroless Jetty Java 8 image. ([#1510](https://github.com/GoogleContainerTools/jib/issues/1510))

### Changed

### Fixed
Expand All @@ -13,7 +15,7 @@ All notable changes to this project will be documented in this file.

### Added

- Java 9+ projects are now supported and run on the distroless Java 11 image by default. Java 8 projects remain on the distroless Java 8 image. ([#1279](https://github.com/GoogleContainerTools/jib/issues/1279))
- Java 9+ projects are now supported and run on the distroless Java 11 image (https://github.com/GoogleContainerTools/distroless) by default. Java 8 projects remain on the distroless Java 8 image. ([#1279](https://github.com/GoogleContainerTools/jib/issues/1279))

### Fixed

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -295,14 +295,15 @@ static String getBaseImage(RawConfiguration rawConfiguration, ProjectProperties
}

// Base image not configured; auto-pick Distroless.
if (projectProperties.isWarProject()) {
return "gcr.io/distroless/java/jetty";
}
if (javaVersion <= 8) {
return "gcr.io/distroless/java:8";
return projectProperties.isWarProject()
? "gcr.io/distroless/java/jetty:java8"
: "gcr.io/distroless/java:8";
}
if (javaVersion <= 11) {
return "gcr.io/distroless/java:11";
return projectProperties.isWarProject()
? "gcr.io/distroless/java/jetty:java11"
: "gcr.io/distroless/java:11";
}
throw new IncompatibleBaseImageJavaVersionException(11, javaVersion);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ public void testPluginConfigurationProcessor_warProjectBaseImage()
PluginConfigurationProcessor processor = createPluginConfigurationProcessor();

Assert.assertEquals(
ImageReference.parse("gcr.io/distroless/java/jetty").toString(),
ImageReference.parse("gcr.io/distroless/java/jetty:java8").toString(),
processor.getBaseImageReference().toString());
Mockito.verifyNoMoreInteractions(logger);
}
Expand Down Expand Up @@ -469,6 +469,46 @@ public void testGetBaseImage_chooseJava11Distroless()
PluginConfigurationProcessor.getBaseImage(rawConfiguration, projectProperties));
}

@Test
public void testGetBaseImage_chooseJava8JettyDistroless()
throws IncompatibleBaseImageJavaVersionException {
Mockito.when(projectProperties.getMajorJavaVersion()).thenReturn(6);
Mockito.when(projectProperties.isWarProject()).thenReturn(true);
Assert.assertEquals(
"gcr.io/distroless/java/jetty:java8",
PluginConfigurationProcessor.getBaseImage(rawConfiguration, projectProperties));

Mockito.when(projectProperties.getMajorJavaVersion()).thenReturn(7);
Assert.assertEquals(
"gcr.io/distroless/java/jetty:java8",
PluginConfigurationProcessor.getBaseImage(rawConfiguration, projectProperties));

Mockito.when(projectProperties.getMajorJavaVersion()).thenReturn(8);
Assert.assertEquals(
"gcr.io/distroless/java/jetty:java8",
PluginConfigurationProcessor.getBaseImage(rawConfiguration, projectProperties));
}

@Test
public void testGetBaseImage_chooseJava11JettyDistroless()
throws IncompatibleBaseImageJavaVersionException {
Mockito.when(projectProperties.getMajorJavaVersion()).thenReturn(9);
Mockito.when(projectProperties.isWarProject()).thenReturn(true);
Assert.assertEquals(
"gcr.io/distroless/java/jetty:java11",
PluginConfigurationProcessor.getBaseImage(rawConfiguration, projectProperties));

Mockito.when(projectProperties.getMajorJavaVersion()).thenReturn(10);
Assert.assertEquals(
"gcr.io/distroless/java/jetty:java11",
PluginConfigurationProcessor.getBaseImage(rawConfiguration, projectProperties));

Mockito.when(projectProperties.getMajorJavaVersion()).thenReturn(11);
Assert.assertEquals(
"gcr.io/distroless/java/jetty:java11",
PluginConfigurationProcessor.getBaseImage(rawConfiguration, projectProperties));
}

@Test
public void testGetBaseImage_projectHigherThanJava11() {
Mockito.when(projectProperties.getMajorJavaVersion()).thenReturn(12);
Expand Down Expand Up @@ -522,6 +562,36 @@ public void testGetBaseImage_incompatibleJava11BaseImage() {
}
}

@Test
public void testGetBaseImage_incompatibleJava8JettyBaseImage() {
Mockito.when(projectProperties.getMajorJavaVersion()).thenReturn(11);

Mockito.when(rawConfiguration.getFromImage())
.thenReturn(Optional.of("gcr.io/distroless/java/jetty:java8"));
try {
PluginConfigurationProcessor.getBaseImage(rawConfiguration, projectProperties);
Assert.fail();
} catch (IncompatibleBaseImageJavaVersionException ex) {
Assert.assertEquals(8, ex.getBaseImageMajorJavaVersion());
Assert.assertEquals(11, ex.getProjectMajorJavaVersion());
}
}

@Test
public void testGetBaseImage_incompatibleJava11JettyBaseImage() {
Mockito.when(projectProperties.getMajorJavaVersion()).thenReturn(15);

Mockito.when(rawConfiguration.getFromImage())
.thenReturn(Optional.of("gcr.io/distroless/java/jetty:java11"));
try {
PluginConfigurationProcessor.getBaseImage(rawConfiguration, projectProperties);
Assert.fail();
} catch (IncompatibleBaseImageJavaVersionException ex) {
Assert.assertEquals(11, ex.getBaseImageMajorJavaVersion());
Assert.assertEquals(15, ex.getProjectMajorJavaVersion());
}
}

@Test
public void testGetBaseImage_defaultNonWarPackaging()
throws IncompatibleBaseImageJavaVersionException {
Expand All @@ -538,7 +608,7 @@ public void testGetBaseImage_defaultWarProject()
Mockito.when(projectProperties.isWarProject()).thenReturn(true);

Assert.assertEquals(
"gcr.io/distroless/java/jetty",
"gcr.io/distroless/java/jetty:java8",
PluginConfigurationProcessor.getBaseImage(rawConfiguration, projectProperties));
}

Expand Down

0 comments on commit 083c255

Please sign in to comment.