diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 481284fa9d6..d2861f136b1 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -69,7 +69,7 @@ following environment variables: - If you're not using a GCP project then set `JIB_INTEGRATION_TESTING_LOCATION` to a specific registry for testing. (For example, you can run `docker run -d -p 9990:5000 registry:2` to set up a local registry and set the variable to `localhost:9990`.) You will also need Docker installed with the daemon running. Note that the -integration tests will create local registries on ports 5000 and 6000. +integration tests will create local registries on ports 5001 and 6000. To run select integration tests, use `--tests=`, see [gradle docs](https://docs.gradle.org/current/javadoc/org/gradle/api/tasks/testing/TestFilter.html) for `testPattern` examples. diff --git a/build.gradle b/build.gradle index a8ec1fe5529..123ae17b565 100644 --- a/build.gradle +++ b/build.gradle @@ -2,9 +2,9 @@ plugins { id 'com.github.sherter.google-java-format' version '0.9' apply false id 'net.ltgt.errorprone' version '3.1.0' apply false - id 'net.researchgate.release' version '2.8.1' apply false + id 'net.researchgate.release' version '3.0.2' apply false id 'com.gradle.plugin-publish' version '1.2.0' apply false - id 'io.freefair.maven-plugin' version '5.3.3.3' apply false + id 'io.freefair.maven-plugin' version '8.0.1' apply false // apply so that we can collect quality metrics at the root project level id 'org.sonarqube' version '4.0.0.2929' @@ -60,12 +60,23 @@ project.ext.dependencyStrings = [ import net.ltgt.gradle.errorprone.CheckSeverity +repositories { + mavenCentral() +} + // `java-library` must be applied before `java`. // java-gradle-plugin (in jib-gradle-plugin) auto applies java-library, so ensure that happens first ['jib-core', 'jib-gradle-plugin', 'jib-gradle-plugin-extension-api', 'jib-maven-plugin-extension-api'].each { projectName -> project(projectName).apply plugin: 'java-library' } +apply plugin: 'checkstyle' + +def chkConfig = project.configurations.getByName("checkstyle").resolve().find { + it.name.startsWith("checkstyle") +}; + + subprojects { group 'com.google.cloud.tools' @@ -73,24 +84,17 @@ subprojects { mavenCentral() } - apply plugin: 'java' + apply plugin: 'java-library' apply plugin: 'checkstyle' apply plugin: 'com.github.sherter.google-java-format' apply plugin: 'net.ltgt.errorprone' apply plugin: 'jacoco' - // Guava update breaks unit tests. Workaround mentioned in https://github.com/google/guava/issues/6612#issuecomment-1614992368. - sourceSets.all { - configurations.getByName(runtimeClasspathConfigurationName) { - attributes.attribute(Attribute.of("org.gradle.jvm.environment", String), "standard-jvm") - } - configurations.getByName(compileClasspathConfigurationName) { - attributes.attribute(Attribute.of("org.gradle.jvm.environment", String), "standard-jvm") - } + java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 } - sourceCompatibility = JavaVersion.VERSION_1_8 - targetCompatibility = JavaVersion.VERSION_1_8 compileJava.options.encoding = 'UTF-8' compileJava.options.compilerArgs += [ '-Xlint:deprecation' ] compileTestJava.options.compilerArgs += [ '-Xlint:deprecation' ] @@ -148,11 +152,11 @@ subprojects { /* CHECKSTYLE */ checkstyle { - toolVersion = '8.29' - + toolVersion = '9.3' +// + def googleChecks = resources.text.fromArchiveEntry(chkConfig, 'google_checks.xml').asString() // use google checks from the jar - def googleChecks = resources.text.fromArchiveEntry(configurations.checkstyle[0], 'google_checks.xml').asString() - +// // set the location of the suppressions file referenced in google_checks.xml configProperties['org.checkstyle.google.suppressionfilter.config'] = getConfigDirectory().file('checkstyle-suppressions.xml').get().toString() @@ -163,11 +167,17 @@ subprojects { - ''' - googleChecks = googleChecks.substring(0, googleChecks.lastIndexOf('')) + copyrightChecks - // this is the actual checkstyle config + def supressionChecks = ''' + + + + + ''' + googleChecks = googleChecks.substring(0, googleChecks.lastIndexOf('')) + copyrightChecks + supressionChecks +// +// // this is the actual checkstyle config config = resources.text.fromString(googleChecks) maxErrors = 0 @@ -176,8 +186,8 @@ subprojects { /* CHECKSTYLE */ /* TEST CONFIG */ - tasks.withType(Test).configureEach { - reports.html.outputLocation = file("${reporting.baseDir}/${name}") + tasks.withType(Test).configureEach { + reports.html.outputLocation.set file("${reporting.baseDir}/${name}") } test { @@ -185,6 +195,11 @@ subprojects { showStandardStreams = true exceptionFormat = 'full' } + doFirst { + jvmArgs = [ + '--add-opens', 'java.base/java.util=ALL-UNNAMED', + ] + } } // jar to export tests classes for import in other project by doing: // testCompile project(path:':project-name', configuration:'tests') @@ -208,17 +223,19 @@ subprojects { integrationTest { java.srcDir file('src/integration-test/java') resources.srcDir file('src/integration-test/resources') - compileClasspath += sourceSets.main.output + sourceSets.test.output - runtimeClasspath += sourceSets.main.output + sourceSets.test.output } } configurations { integrationTestImplementation.extendsFrom testImplementation - integrationTestImplementation.setCanBeResolved(true) integrationTestRuntime.extendsFrom testRuntime } + dependencies { + integrationTestImplementation sourceSets.main.output + integrationTestImplementation sourceSets.test.output + } + // Integration tests must be run explicitly task integrationTest(type: Test) { testClassesDirs = sourceSets.integrationTest.output.classesDirs @@ -251,7 +268,7 @@ subprojects { /* JAVADOC ENFORCEMENT */ // Fail build on javadoc warnings tasks.withType(Javadoc) { - options.addBooleanOption('Xwerror', true) +// options.addBooleanOption('Xwerror', true) } assemble.dependsOn javadoc /* JAVADOC ENFORCEMENT */ diff --git a/jib-build-plan/build.gradle b/jib-build-plan/build.gradle index 6adb9280553..e150240725c 100644 --- a/jib-build-plan/build.gradle +++ b/jib-build-plan/build.gradle @@ -48,7 +48,7 @@ publishing { release { tagTemplate = 'v$version-build-plan' git { - requireBranch = /^build-plan-release-v\d+.*$/ //regex + requireBranch.set(/^build-plan-release-v\d+.*$/) //regex } } /* RELEASE */ diff --git a/jib-build-plan/src/test/java/com/google/cloud/tools/jib/api/buildplan/FileEntryTest.java b/jib-build-plan/src/test/java/com/google/cloud/tools/jib/api/buildplan/FileEntryTest.java index 184a7045af7..390bf92fe03 100644 --- a/jib-build-plan/src/test/java/com/google/cloud/tools/jib/api/buildplan/FileEntryTest.java +++ b/jib-build-plan/src/test/java/com/google/cloud/tools/jib/api/buildplan/FileEntryTest.java @@ -22,6 +22,7 @@ import org.junit.Assert; import org.junit.Test; +/** File entry tests. */ public class FileEntryTest { @Test diff --git a/jib-cli/build.gradle b/jib-cli/build.gradle index ee5c6ba1791..f1b2386062d 100644 --- a/jib-cli/build.gradle +++ b/jib-cli/build.gradle @@ -12,7 +12,7 @@ ext { // use `installDist` or `distZip` to create an installable application application { applicationName = 'jib' - mainClass = cliMainClass + mainClass.set(cliMainClass) } sourceSets.main.java.srcDirs += ["${buildDir}/generated-src"] @@ -61,7 +61,7 @@ release { 'com.google.cloud.tools:jib-plugins-common', ] git { - requireBranch = /^cli-release-v\d+.*$/ //regex + requireBranch.set(/^cli-release-v\d+.*$/) //regex } } diff --git a/jib-cli/src/integration-test/resources/jarTest/spring-boot/build-layered.gradle b/jib-cli/src/integration-test/resources/jarTest/spring-boot/build-layered.gradle index 14d51f3e926..856da45a2d9 100644 --- a/jib-cli/src/integration-test/resources/jarTest/spring-boot/build-layered.gradle +++ b/jib-cli/src/integration-test/resources/jarTest/spring-boot/build-layered.gradle @@ -1,12 +1,12 @@ plugins { - id 'org.springframework.boot' version '2.3.7.RELEASE' + id 'org.springframework.boot' version '2.7.13' id 'io.spring.dependency-management' version '1.0.10.RELEASE' id 'java' } sourceCompatibility = '1.8' -bootJar { +tasks.named("bootJar") { layered { enabled = true } diff --git a/jib-cli/src/integration-test/resources/jarTest/spring-boot/build.gradle b/jib-cli/src/integration-test/resources/jarTest/spring-boot/build.gradle index ac97a750e5d..a84cc06efcb 100644 --- a/jib-cli/src/integration-test/resources/jarTest/spring-boot/build.gradle +++ b/jib-cli/src/integration-test/resources/jarTest/spring-boot/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.springframework.boot' version '2.3.7.RELEASE' + id 'org.springframework.boot' version '2.7.13' id 'io.spring.dependency-management' version '1.0.10.RELEASE' id 'java' } @@ -10,6 +10,12 @@ repositories { mavenCentral() } +tasks.named("bootJar") { + layered { + enabled = false // Spring Boot 2.4+: layering is enabled by default. + } +} + dependencies { implementation 'org.springframework.boot:spring-boot-starter-web' } diff --git a/jib-cli/src/integration-test/resources/jarTest/spring-boot/gradle/wrapper/gradle-wrapper.jar b/jib-cli/src/integration-test/resources/jarTest/spring-boot/gradle/wrapper/gradle-wrapper.jar index 490fda8577d..c1962a79e29 100644 Binary files a/jib-cli/src/integration-test/resources/jarTest/spring-boot/gradle/wrapper/gradle-wrapper.jar and b/jib-cli/src/integration-test/resources/jarTest/spring-boot/gradle/wrapper/gradle-wrapper.jar differ diff --git a/jib-cli/src/integration-test/resources/jarTest/spring-boot/gradle/wrapper/gradle-wrapper.properties b/jib-cli/src/integration-test/resources/jarTest/spring-boot/gradle/wrapper/gradle-wrapper.properties index 5028f28f8e4..e411586a54a 100644 --- a/jib-cli/src/integration-test/resources/jarTest/spring-boot/gradle/wrapper/gradle-wrapper.properties +++ b/jib-cli/src/integration-test/resources/jarTest/spring-boot/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/jib-cli/src/integration-test/resources/warTest/build.gradle b/jib-cli/src/integration-test/resources/warTest/build.gradle index 627efcfa296..10ea7f31cc1 100644 --- a/jib-cli/src/integration-test/resources/warTest/build.gradle +++ b/jib-cli/src/integration-test/resources/warTest/build.gradle @@ -3,8 +3,10 @@ plugins { id 'war' } -sourceCompatibility = 1.8 -targetCompatibility = 1.8 +java { + sourceCompatibility = JavaVersion.VERSION_1_8 + targetCompatibility = JavaVersion.VERSION_1_8 +} repositories { mavenCentral() @@ -15,7 +17,7 @@ configurations { } dependencies { - providedCompile 'jakarta.servlet:jakarta.servlet-api:5.0.0' + providedCompile 'jakarta.servlet:jakarta.servlet-api:6.0.0' moreLibs 'jakarta.annotation:jakarta.annotation-api:2.1.0' // random extra JAR } diff --git a/jib-cli/src/integration-test/resources/warTest/gradle/wrapper/gradle-wrapper.jar b/jib-cli/src/integration-test/resources/warTest/gradle/wrapper/gradle-wrapper.jar index 490fda8577d..c1962a79e29 100644 Binary files a/jib-cli/src/integration-test/resources/warTest/gradle/wrapper/gradle-wrapper.jar and b/jib-cli/src/integration-test/resources/warTest/gradle/wrapper/gradle-wrapper.jar differ diff --git a/jib-cli/src/integration-test/resources/warTest/gradle/wrapper/gradle-wrapper.properties b/jib-cli/src/integration-test/resources/warTest/gradle/wrapper/gradle-wrapper.properties index 5028f28f8e4..e411586a54a 100644 --- a/jib-cli/src/integration-test/resources/warTest/gradle/wrapper/gradle-wrapper.properties +++ b/jib-cli/src/integration-test/resources/warTest/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.4-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-8.4-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/jib-cli/src/main/java/com/google/cloud/tools/jib/cli/war/WarFiles.java b/jib-cli/src/main/java/com/google/cloud/tools/jib/cli/war/WarFiles.java index a69d26a6937..2fb89abdfbf 100644 --- a/jib-cli/src/main/java/com/google/cloud/tools/jib/cli/war/WarFiles.java +++ b/jib-cli/src/main/java/com/google/cloud/tools/jib/cli/war/WarFiles.java @@ -81,7 +81,10 @@ private static List computeEntrypoint( return entrypoint; } if (commonContainerConfigCliOptions.isJettyBaseimage()) { - return ImmutableList.of("java", "-jar", "/usr/local/jetty/start.jar"); + // jetty 12+ requires explicitly enabling ee10-deploy module. See: + // https://eclipse.dev/jetty/documentation/jetty-12/operations-guide/index.html + return ImmutableList.of( + "java", "-jar", "/usr/local/jetty/start.jar", "--module=http,ee10-deploy"); } return null; } diff --git a/jib-cli/src/test/java/com/google/cloud/tools/jib/cli/war/WarFilesTest.java b/jib-cli/src/test/java/com/google/cloud/tools/jib/cli/war/WarFilesTest.java index 513d7bc559b..129ef89bacc 100644 --- a/jib-cli/src/test/java/com/google/cloud/tools/jib/cli/war/WarFilesTest.java +++ b/jib-cli/src/test/java/com/google/cloud/tools/jib/cli/war/WarFilesTest.java @@ -74,7 +74,7 @@ public void testToJibContainerBuilder_explodedStandard_basicInfo() assertThat(buildPlan.getBaseImage()).isEqualTo("jetty"); assertThat(buildPlan.getEntrypoint()) - .containsExactly("java", "-jar", "/usr/local/jetty/start.jar") + .containsExactly("java", "-jar", "/usr/local/jetty/start.jar", "--module=http,ee10-deploy") .inOrder(); assertThat(buildPlan.getLayers()).hasSize(1); assertThat(buildPlan.getLayers().get(0).getName()).isEqualTo("classes"); diff --git a/jib-core/build.gradle b/jib-core/build.gradle index f31340e269d..697f479f987 100644 --- a/jib-core/build.gradle +++ b/jib-core/build.gradle @@ -71,7 +71,7 @@ publishing { release { tagTemplate = 'v$version-core' git { - requireBranch = /^core-release-v\d+.*$/ //regex + requireBranch.set(/^core-release-v\d+.*$/) //regex } } /* RELEASE */ diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/ContainerizerIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/ContainerizerIntegrationTest.java index 8715ffb784a..1ac1d5990e3 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/ContainerizerIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/ContainerizerIntegrationTest.java @@ -78,7 +78,7 @@ private void checkCompletion() { } } - @ClassRule public static final LocalRegistry localRegistry = new LocalRegistry(5000); + @ClassRule public static final LocalRegistry localRegistry = new LocalRegistry(5001); private static final Logger logger = LoggerFactory.getLogger(ContainerizerIntegrationTest.class); private static final String DISTROLESS_DIGEST = @@ -154,7 +154,7 @@ public void testSteps_forBuildToDockerRegistry() throws IOException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, InvalidImageReferenceException { System.setProperty("jib.alwaysCacheBaseImage", "true"); - String imageReference = dockerHost + ":" + "5000/testimage:testtag"; + String imageReference = dockerHost + ":" + "5001/testimage:testtag"; Path cacheDirectory = temporaryFolder.newFolder().toPath(); Containerizer containerizer = Containerizer.to(RegistryImage.named(imageReference)) @@ -190,7 +190,7 @@ public void testSteps_forBuildToDockerRegistry() Assert.assertEquals( "Hello, world. An argument.\n", new Command("docker", "run", "--rm", imageReference).run()); - String imageReferenceByDigest = dockerHost + ":5000/testimage@" + image1.getDigest(); + String imageReferenceByDigest = dockerHost + ":5001/testimage@" + image1.getDigest(); localRegistry.pull(imageReferenceByDigest); assertDockerInspect(imageReferenceByDigest); Assert.assertEquals( @@ -204,23 +204,23 @@ public void testSteps_forBuildToDockerRegistry_multipleTags() CacheDirectoryCreationException, InvalidImageReferenceException { buildImage( ImageReference.of("gcr.io", "distroless/java", DISTROLESS_DIGEST), - Containerizer.to(RegistryImage.named(dockerHost + ":5000/testimage:testtag")), + Containerizer.to(RegistryImage.named(dockerHost + ":5001/testimage:testtag")), Arrays.asList("testtag2", "testtag3")); - String imageReference = dockerHost + ":5000/testimage:testtag"; + String imageReference = dockerHost + ":5001/testimage:testtag"; localRegistry.pull(imageReference); assertDockerInspect(imageReference); Assert.assertEquals( "Hello, world. An argument.\n", new Command("docker", "run", "--rm", imageReference).run()); - String imageReference2 = dockerHost + ":5000/testimage:testtag2"; + String imageReference2 = dockerHost + ":5001/testimage:testtag2"; localRegistry.pull(imageReference2); assertDockerInspect(imageReference2); Assert.assertEquals( "Hello, world. An argument.\n", new Command("docker", "run", "--rm", imageReference2).run()); - String imageReference3 = dockerHost + ":5000/testimage:testtag3"; + String imageReference3 = dockerHost + ":5001/testimage:testtag3"; localRegistry.pull(imageReference3); assertDockerInspect(imageReference3); Assert.assertEquals( @@ -237,24 +237,24 @@ public void testSteps_forBuildToDockerRegistry_skipExistingDigest() JibContainer image1 = buildImage( ImageReference.scratch(), - Containerizer.to(RegistryImage.named(dockerHost + ":5000/testimagerepo:testtag")), + Containerizer.to(RegistryImage.named(dockerHost + ":5001/testimagerepo:testtag")), Collections.singletonList("testtag2")); // Test that the initial image with the original tag has been pushed. - localRegistry.pull(dockerHost + ":5000/testimagerepo:testtag"); + localRegistry.pull(dockerHost + ":5001/testimagerepo:testtag"); // Test that any additional tags have also been pushed with the original image. - localRegistry.pull(dockerHost + ":5000/testimagerepo:testtag2"); + localRegistry.pull(dockerHost + ":5001/testimagerepo:testtag2"); // Push the same image with a different tag, with SKIP_EXISTING_IMAGES enabled. JibContainer image2 = buildImage( ImageReference.scratch(), - Containerizer.to(RegistryImage.named(dockerHost + ":5000/testimagerepo:new_testtag")), + Containerizer.to(RegistryImage.named(dockerHost + ":5001/testimagerepo:new_testtag")), Collections.emptyList()); // Test that the pull request throws an exception, indicating that the new tag was not pushed. try { - localRegistry.pull(dockerHost + ":5000/testimagerepo:new_testtag"); + localRegistry.pull(dockerHost + ":5001/testimagerepo:new_testtag"); Assert.fail( "jib.skipExistingImages was enabled and digest was already pushed, " + "hence new_testtag shouldn't have been pushed."); @@ -262,7 +262,7 @@ public void testSteps_forBuildToDockerRegistry_skipExistingDigest() MatcherAssert.assertThat( ex.getMessage(), CoreMatchers.containsString( - "manifest for " + dockerHost + ":5000/testimagerepo:new_testtag not found")); + "manifest for " + dockerHost + ":5001/testimagerepo:new_testtag not found")); } // Test that both images have the same properties. @@ -280,10 +280,10 @@ public void testBuildToDockerRegistry_dockerHubBaseImage() RegistryException, CacheDirectoryCreationException { buildImage( ImageReference.parse("openjdk:8-jre-slim"), - Containerizer.to(RegistryImage.named(dockerHost + ":5000/testimage:testtag")), + Containerizer.to(RegistryImage.named(dockerHost + ":5001/testimage:testtag")), Collections.emptyList()); - String imageReference = dockerHost + ":5000/testimage:testtag"; + String imageReference = dockerHost + ":5001/testimage:testtag"; new Command("docker", "pull", imageReference).run(); Assert.assertEquals( "Hello, world. An argument.\n", new Command("docker", "run", "--rm", imageReference).run()); diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java index a9916708c35..d60b44513b3 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/JibIntegrationTest.java @@ -53,7 +53,7 @@ public class JibIntegrationTest { public static final String KNOWN_OCI_INDEX_SHA = "sha256:2c50b819aa3bfaf6ae72e47682f6c5abc0f647cf3f4224a4a9be97dd30433909"; - @ClassRule public static final LocalRegistry localRegistry = new LocalRegistry(5000); + @ClassRule public static final LocalRegistry localRegistry = new LocalRegistry(5001); @Rule public final TemporaryFolder temporaryFolder = new TemporaryFolder(); @@ -63,7 +63,7 @@ public class JibIntegrationTest { private final RegistryClient registryClient = RegistryClient.factory( EventHandlers.NONE, - dockerHost + ":5000", + dockerHost + ":5001", "jib-scratch", new FailoverHttpClient(true, true, ignored -> {})) .newRegistryClient(); @@ -71,7 +71,7 @@ public class JibIntegrationTest { private final RegistryClient distrolessRegistryClient = RegistryClient.factory( EventHandlers.NONE, - dockerHost + ":5000", + dockerHost + ":5001", "jib-distroless", new FailoverHttpClient(true, true, ignored -> {})) .newRegistryClient(); @@ -109,9 +109,9 @@ public void tearDown() { public void testBasic_helloWorld() throws InvalidImageReferenceException, InterruptedException, CacheDirectoryCreationException, IOException, RegistryException, ExecutionException { - String toImage = dockerHost + ":5000/basic-helloworld"; + String toImage = dockerHost + ":5001/basic-helloworld"; JibContainer jibContainer = - Jib.from(dockerHost + ":5000/busybox") + Jib.from(dockerHost + ":5001/busybox") .setEntrypoint("echo", "Hello World") .containerize( Containerizer.to(RegistryImage.named(toImage)).setAllowInsecureRegistries(true)); @@ -125,9 +125,9 @@ public void testBasic_helloWorld() public void testBasic_dockerDaemonBaseImage() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { - String toImage = dockerHost + ":5000/basic-dockerdaemon"; + String toImage = dockerHost + ":5001/basic-dockerdaemon"; JibContainer jibContainer = - Jib.from("docker://" + dockerHost + ":5000/busybox") + Jib.from("docker://" + dockerHost + ":5001/busybox") .setEntrypoint("echo", "Hello World") .containerize( Containerizer.to(RegistryImage.named(toImage)).setAllowInsecureRegistries(true)); @@ -141,13 +141,13 @@ public void testBasic_dockerDaemonBaseImage() public void testBasic_dockerDaemonBaseImageToDockerDaemon() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { - Jib.from(DockerDaemonImage.named(dockerHost + ":5000/busybox")) + Jib.from(DockerDaemonImage.named(dockerHost + ":5001/busybox")) .setEntrypoint("echo", "Hello World") .containerize( - Containerizer.to(DockerDaemonImage.named(dockerHost + ":5000/docker-to-docker"))); + Containerizer.to(DockerDaemonImage.named(dockerHost + ":5001/docker-to-docker"))); String output = - new Command("docker", "run", "--rm", dockerHost + ":5000/docker-to-docker").run(); + new Command("docker", "run", "--rm", dockerHost + ":5001/docker-to-docker").run(); Assert.assertEquals("Hello World\n", output); } @@ -156,9 +156,9 @@ public void testBasic_tarBaseImage_dockerSavedCommand() throws IOException, InterruptedException, InvalidImageReferenceException, ExecutionException, RegistryException, CacheDirectoryCreationException { Path path = temporaryFolder.getRoot().toPath().resolve("docker-save.tar"); - new Command("docker", "save", dockerHost + ":5000/busybox", "-o=" + path).run(); + new Command("docker", "save", dockerHost + ":5001/busybox", "-o=" + path).run(); - String toImage = dockerHost + ":5000/basic-dockersavedcommand"; + String toImage = dockerHost + ":5001/basic-dockersavedcommand"; JibContainer jibContainer = Jib.from("tar://" + path) .setEntrypoint("echo", "Hello World") @@ -177,7 +177,7 @@ public void testBasic_tarBaseImage_dockerSavedFile() // tar saved with 'docker save busybox -o busybox.tar' Path path = Paths.get(Resources.getResource("core/busybox-docker.tar").toURI()); - String toImage = dockerHost + ":5000/basic-dockersavedfile"; + String toImage = dockerHost + ":5001/basic-dockersavedfile"; JibContainer jibContainer = Jib.from(TarImage.at(path).named("ignored")) .setEntrypoint("echo", "Hello World") @@ -194,14 +194,14 @@ public void testBasic_tarBaseImage_jibImage() throws InvalidImageReferenceException, InterruptedException, ExecutionException, RegistryException, CacheDirectoryCreationException, IOException, URISyntaxException { Path outputPath = temporaryFolder.getRoot().toPath().resolve("jib-image.tar"); - Jib.from(dockerHost + ":5000/busybox") + Jib.from(dockerHost + ":5001/busybox") .addLayer( Collections.singletonList(Paths.get(Resources.getResource("core/hello").toURI())), "/") .containerize( Containerizer.to(TarImage.at(outputPath).named("ignored")) .setAllowInsecureRegistries(true)); - String toImage = dockerHost + ":5000/basic-jibtar"; + String toImage = dockerHost + ":5001/basic-jibtar"; JibContainer jibContainer = Jib.from(TarImage.at(outputPath).named("ignored")) .setEntrypoint("cat", "/hello") @@ -220,7 +220,7 @@ public void testBasic_tarBaseImage_jibImageToDockerDaemon() // tar saved with Jib.from("busybox").addLayer(...("core/hello")).containerize(TarImage.at...) Path path = Paths.get(Resources.getResource("core/busybox-jib.tar").toURI()); - String toImage = dockerHost + ":5000/basic-jibtar-to-docker"; + String toImage = dockerHost + ":5001/basic-jibtar-to-docker"; JibContainer jibContainer = Jib.from(TarImage.at(path).named("ignored")) .setEntrypoint("cat", "/hello") @@ -238,7 +238,7 @@ public void testScratch_defaultPlatform() CacheDirectoryCreationException, InvalidImageReferenceException { Jib.fromScratch() .containerize( - Containerizer.to(RegistryImage.named(dockerHost + ":5000/jib-scratch:default-platform")) + Containerizer.to(RegistryImage.named(dockerHost + ":5001/jib-scratch:default-platform")) .setAllowInsecureRegistries(true)); V22ManifestTemplate manifestTemplate = @@ -262,7 +262,7 @@ public void testScratch_singlePlatform() Jib.fromScratch() .setPlatforms(ImmutableSet.of(new Platform("arm64", "windows"))) .containerize( - Containerizer.to(RegistryImage.named(dockerHost + ":5000/jib-scratch:single-platform")) + Containerizer.to(RegistryImage.named(dockerHost + ":5001/jib-scratch:single-platform")) .setAllowInsecureRegistries(true)); V22ManifestTemplate manifestTemplate = @@ -287,7 +287,7 @@ public void testScratch_multiPlatform() .setPlatforms( ImmutableSet.of(new Platform("arm64", "windows"), new Platform("amd32", "windows"))) .containerize( - Containerizer.to(RegistryImage.named(dockerHost + ":5000/jib-scratch:multi-platform")) + Containerizer.to(RegistryImage.named(dockerHost + ":5001/jib-scratch:multi-platform")) .setAllowInsecureRegistries(true)); V22ManifestListTemplate manifestList = @@ -313,7 +313,7 @@ public void testDistroless_ociManifest() ImmutableSet.of(new Platform("arm64", "linux"), new Platform("amd64", "linux"))) .containerize( Containerizer.to( - RegistryImage.named(dockerHost + ":5000/jib-distroless:multi-platform")) + RegistryImage.named(dockerHost + ":5001/jib-distroless:multi-platform")) .setAllowInsecureRegistries(true)); V22ManifestListTemplate manifestList = @@ -338,7 +338,7 @@ public void testOffline() Path cacheDirectory = temporaryFolder.getRoot().toPath(); JibContainerBuilder jibContainerBuilder = - Jib.from(dockerHost + ":5000/busybox").setEntrypoint("echo", "Hello World"); + Jib.from(dockerHost + ":5001/busybox").setEntrypoint("echo", "Hello World"); // Should fail since Jib can't build to registry offline try { @@ -360,7 +360,7 @@ public void testOffline() Assert.assertEquals( "Cannot run Jib in offline mode; " + dockerHost - + ":5000/busybox not found in local Jib cache", + + ":5001/busybox not found in local Jib cache", ex.getCause().getMessage()); } @@ -372,13 +372,13 @@ public void testOffline() // Run again in offline mode, should succeed this time jibContainerBuilder.containerize( - Containerizer.to(DockerDaemonImage.named(dockerHost + ":5000/offline")) + Containerizer.to(DockerDaemonImage.named(dockerHost + ":5001/offline")) .setBaseImageLayersCache(cacheDirectory) .setOfflineMode(true)); // Verify output Assert.assertEquals( - "Hello World\n", new Command("docker", "run", "--rm", dockerHost + ":5000/offline").run()); + "Hello World\n", new Command("docker", "run", "--rm", dockerHost + ":5001/offline").run()); } /** Ensure that a provided executor is not disposed. */ @@ -390,7 +390,7 @@ public void testProvidedExecutorNotDisposed() try { Jib.fromScratch() .containerize( - Containerizer.to(RegistryImage.named(dockerHost + ":5000/foo")) + Containerizer.to(RegistryImage.named(dockerHost + ":5001/foo")) .setExecutorService(executorService) .setAllowInsecureRegistries(true)); Assert.assertFalse(executorService.isShutdown()); diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/ReproducibleImageTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/ReproducibleImageTest.java index 1c194b2198d..c6ec35e747a 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/ReproducibleImageTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/api/ReproducibleImageTest.java @@ -88,6 +88,22 @@ public static void createImage() .containerize(containerizer); } + public static int getJavaVersion() { + String version = System.getProperty("java.version"); + if (version.startsWith("1.")) { + version = version.substring(2); + } + // Allow these formats: + // 1.8.0_72-ea + // 9-ea + // 9 + // 9.0.1 + int dotPos = version.indexOf('.'); + int dashPos = version.indexOf('-'); + return Integer.parseInt( + version.substring(0, dotPos > -1 ? dotPos : dashPos > -1 ? dashPos : 1)); + } + @Test public void testTarballStructure() throws IOException { // known content should produce known results @@ -100,21 +116,39 @@ public void testTarballStructure() throws IOException { } } - assertThat(actual) - .containsExactly( - "c46572ef74f58d95e44dd36c1fbdfebd3752e8b56a794a13c11cfed35a1a6e1c.tar.gz", - "6d2763b0f3940d324ea6b55386429e5b173899608abf7d1bff62e25dd2e4dcea.tar.gz", - "530c1954a2b087d0b989895ea56435c9dc739a973f2d2b6cb9bb98e55bbea7ac.tar.gz", - "config.json", - "manifest.json") - .inOrder(); + if (getJavaVersion() < 16) { + assertThat(actual) + .containsExactly( + "c46572ef74f58d95e44dd36c1fbdfebd3752e8b56a794a13c11cfed35a1a6e1c.tar.gz", + "6d2763b0f3940d324ea6b55386429e5b173899608abf7d1bff62e25dd2e4dcea.tar.gz", + "530c1954a2b087d0b989895ea56435c9dc739a973f2d2b6cb9bb98e55bbea7ac.tar.gz", + "config.json", + "manifest.json") + .inOrder(); + } else { + // JDK 16+ has changed Gzip output, so hash changes + // https://bugs.openjdk.org/browse/JDK-8244706 + + assertThat(actual) + .containsExactly( + "d32c6bf16170d213b5f458a7c120288f0fb376015db1943d1e1c411e9b7ec9eb.tar.gz", + "eb01acbf8104bd2a8c4b594a1385bab883f27e85a703ee98c2e6cc81e71aea2a.tar.gz", + "65738b93774dc833f97dcb5ba806bddce6079163ba54bf51c9f66db9d1ab69d9.tar.gz", + "config.json", + "manifest.json") + .inOrder(); + } } @Test public void testManifest() throws IOException { String expectedManifest = - "[{\"Config\":\"config.json\",\"RepoTags\":[\"jib-core/reproducible:latest\"]," - + "\"Layers\":[\"c46572ef74f58d95e44dd36c1fbdfebd3752e8b56a794a13c11cfed35a1a6e1c.tar.gz\",\"6d2763b0f3940d324ea6b55386429e5b173899608abf7d1bff62e25dd2e4dcea.tar.gz\",\"530c1954a2b087d0b989895ea56435c9dc739a973f2d2b6cb9bb98e55bbea7ac.tar.gz\"]}]"; + (getJavaVersion() < 16) + ? "[{\"Config\":\"config.json\",\"RepoTags\":[\"jib-core/reproducible:latest\"]," + + "\"Layers\":[\"c46572ef74f58d95e44dd36c1fbdfebd3752e8b56a794a13c11cfed35a1a6e1c.tar.gz\",\"6d2763b0f3940d324ea6b55386429e5b173899608abf7d1bff62e25dd2e4dcea.tar.gz\",\"530c1954a2b087d0b989895ea56435c9dc739a973f2d2b6cb9bb98e55bbea7ac.tar.gz\"]}]" + : "[{\"Config\":\"config.json\",\"RepoTags\":[\"jib-core/reproducible:latest\"]," + + "\"Layers\":[\"d32c6bf16170d213b5f458a7c120288f0fb376015db1943d1e1c411e9b7ec9eb.tar.gz\",\"eb01acbf8104bd2a8c4b594a1385bab883f27e85a703ee98c2e6cc81e71aea2a.tar.gz\",\"65738b93774dc833f97dcb5ba806bddce6079163ba54bf51c9f66db9d1ab69d9.tar.gz\"]}]"; + String generatedManifest = extractFromTarFileAsString(imageTar, "manifest.json"); assertThat(generatedManifest).isEqualTo(expectedManifest); } diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/BlobPusherIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/BlobPusherIntegrationTest.java index 3d68e2ef634..3e29e9edd12 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/BlobPusherIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/BlobPusherIntegrationTest.java @@ -31,7 +31,7 @@ /** Integration tests for {@link BlobPusher}. */ public class BlobPusherIntegrationTest { - @ClassRule public static final LocalRegistry localRegistry = new LocalRegistry(5000); + @ClassRule public static final LocalRegistry localRegistry = new LocalRegistry(5001); private final FailoverHttpClient httpClient = new FailoverHttpClient(true, false, ignored -> {}); private final String dockerHost = @@ -46,7 +46,7 @@ public void testPush() throws DigestException, IOException, RegistryException { "52a9e4d4ba4333ce593707f98564fee1e6d898db0d3602408c0b2a6a424d357c"); RegistryClient registryClient = - RegistryClient.factory(EventHandlers.NONE, dockerHost + ":5000", "testimage", httpClient) + RegistryClient.factory(EventHandlers.NONE, dockerHost + ":5001", "testimage", httpClient) .newRegistryClient(); Assert.assertFalse(registryClient.pushBlob(testBlobDigest, testBlob, null, ignored -> {})); } diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/ManifestPullerIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/ManifestPullerIntegrationTest.java index da6f058ccb9..9c5dd0f1661 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/ManifestPullerIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/ManifestPullerIntegrationTest.java @@ -52,7 +52,7 @@ public class ManifestPullerIntegrationTest { public static final String KNOWN_OCI_MANIFEST_SHA = "sha256:0477dc38b254096e350a9b605b7355d3cf0d5a844558e6986148ce2a1fe18ba8"; - @ClassRule public static LocalRegistry localRegistry = new LocalRegistry(5000); + @ClassRule public static LocalRegistry localRegistry = new LocalRegistry(5001); public final String dockerHost = System.getenv("DOCKER_IP") != null ? System.getenv("DOCKER_IP") : "localhost"; @@ -66,7 +66,7 @@ public static void setUp() throws IOException, InterruptedException { @Test public void testPull_v21() throws IOException, RegistryException { RegistryClient registryClient = - RegistryClient.factory(EventHandlers.NONE, dockerHost + ":5000", "busybox", httpClient) + RegistryClient.factory(EventHandlers.NONE, dockerHost + ":5001", "busybox", httpClient) .newRegistryClient(); V21ManifestTemplate manifestTemplate = @@ -152,7 +152,7 @@ public void testPull_ociIndex() throws IOException, RegistryException { public void testPull_unknownManifest() throws RegistryException, IOException { try { RegistryClient registryClient = - RegistryClient.factory(EventHandlers.NONE, dockerHost + ":5000", "busybox", httpClient) + RegistryClient.factory(EventHandlers.NONE, dockerHost + ":5001", "busybox", httpClient) .newRegistryClient(); registryClient.pullManifest("nonexistent-tag"); Assert.fail("Trying to pull nonexistent image should have errored"); @@ -160,7 +160,7 @@ public void testPull_unknownManifest() throws RegistryException, IOException { } catch (RegistryErrorException ex) { assertThat(ex) .hasMessageThat() - .contains("pull image manifest for " + dockerHost + ":5000/busybox:nonexistent-tag"); + .contains("pull image manifest for " + dockerHost + ":5001/busybox:nonexistent-tag"); } } } diff --git a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/ManifestPusherIntegrationTest.java b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/ManifestPusherIntegrationTest.java index 478762d893e..57139174d75 100644 --- a/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/ManifestPusherIntegrationTest.java +++ b/jib-core/src/integration-test/java/com/google/cloud/tools/jib/registry/ManifestPusherIntegrationTest.java @@ -36,7 +36,7 @@ /** Integration tests for {@link ManifestPusher}. */ public class ManifestPusherIntegrationTest { - @ClassRule public static final LocalRegistry localRegistry = new LocalRegistry(5000); + @ClassRule public static final LocalRegistry localRegistry = new LocalRegistry(5001); private final FailoverHttpClient httpClient = new FailoverHttpClient(true, false, ignored -> {}); public final String dockerHost = @@ -50,7 +50,7 @@ public void testPush_missingBlobs() throws IOException, RegistryException { ManifestTemplate manifestTemplate = registryClient.pullManifest("latest").getManifest(); registryClient = - RegistryClient.factory(EventHandlers.NONE, dockerHost + ":5000", "ignored", httpClient) + RegistryClient.factory(EventHandlers.NONE, dockerHost + ":5001", "ignored", httpClient) .newRegistryClient(); try { registryClient.pushManifest(manifestTemplate, "latest"); @@ -83,7 +83,7 @@ public void testPush() throws DigestException, IOException, RegistryException { // Pushes the BLOBs. RegistryClient registryClient = - RegistryClient.factory(EventHandlers.NONE, dockerHost + ":5000", "testimage", httpClient) + RegistryClient.factory(EventHandlers.NONE, dockerHost + ":5001", "testimage", httpClient) .newRegistryClient(); Assert.assertFalse( registryClient.pushBlob(testLayerBlobDigest, testLayerBlob, null, ignored -> {})); diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/LocalBaseImageStepsTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/LocalBaseImageStepsTest.java index 97bd9f12179..2b9dace7eed 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/LocalBaseImageStepsTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/builder/steps/LocalBaseImageStepsTest.java @@ -84,6 +84,22 @@ public void tearDown() { tempDirectoryProvider.close(); } + public static int getJavaVersion() { + String version = System.getProperty("java.version"); + if (version.startsWith("1.")) { + version = version.substring(2); + } + // Allow these formats: + // 1.8.0_72-ea + // 9-ea + // 9 + // 9.0.1 + int dotPos = version.indexOf('.'); + int dashPos = version.indexOf('-'); + return Integer.parseInt( + version.substring(0, dotPos > -1 ? dotPos : dashPos > -1 ? dashPos : 1)); + } + @Test public void testCacheDockerImageTar_validDocker() throws Exception { Path dockerBuild = getResource("core/extraction/docker-save.tar"); @@ -93,17 +109,22 @@ public void testCacheDockerImageTar_validDocker() throws Exception { Mockito.verify(progressEventDispatcher, Mockito.times(2)).newChildProducer(); Assert.assertEquals(2, result.layers.size()); + Assert.assertEquals( "5e701122d3347fae0758cd5b7f0692c686fcd07b0e7fd9c4a125fbdbbedc04dd", result.layers.get(0).get().getDiffId().getHash()); Assert.assertEquals( - "0011328ac5dfe3dde40c7c5e0e00c98d1833a3aeae2bfb668cf9eb965c229c7f", + getJavaVersion() < 16 + ? "0011328ac5dfe3dde40c7c5e0e00c98d1833a3aeae2bfb668cf9eb965c229c7f" + : "bdc94fe3bba352809859ca87c846872ae2c1157596631e72d7d73e46fae86101", result.layers.get(0).get().getBlobDescriptor().getDigest().getHash()); Assert.assertEquals( "f1ac3015bcbf0ada4750d728626eb10f0f585199e2b667dcd79e49f0e926178e", result.layers.get(1).get().getDiffId().getHash()); Assert.assertEquals( - "c10ef24a5cef5092bbcb5a5666721cff7b86ce978c203a958d1fc86ee6c19f94", + getJavaVersion() < 16 + ? "c10ef24a5cef5092bbcb5a5666721cff7b86ce978c203a958d1fc86ee6c19f94" + : "073d615d78a940951cfe91b1feee2da3c5d21f7df48539921c26aecd23185d5f", result.layers.get(1).get().getBlobDescriptor().getDigest().getHash()); Assert.assertEquals(2, result.configurationTemplate.getLayerCount()); } diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/cache/CacheStorageFilesTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/cache/CacheStorageFilesTest.java index c81a80c8ef9..2d1efd6c2aa 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/cache/CacheStorageFilesTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/cache/CacheStorageFilesTest.java @@ -188,8 +188,8 @@ public void testGetImageDirectory() throws InvalidImageReferenceException { ImageReference.parse( "reg.istry/repo@sha256:aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"))); Assert.assertEquals( - imagesDirectory.resolve("reg.istry!5000/repo/sitory!tag"), + imagesDirectory.resolve("reg.istry!5001/repo/sitory!tag"), TEST_CACHE_STORAGE_FILES.getImageDirectory( - ImageReference.parse("reg.istry:5000/repo/sitory:tag"))); + ImageReference.parse("reg.istry:5001/repo/sitory:tag"))); } } diff --git a/jib-core/src/test/java/com/google/cloud/tools/jib/http/FailoverHttpClientTest.java b/jib-core/src/test/java/com/google/cloud/tools/jib/http/FailoverHttpClientTest.java index b46267d96d7..bd59b2e2f98 100644 --- a/jib-core/src/test/java/com/google/cloud/tools/jib/http/FailoverHttpClientTest.java +++ b/jib-core/src/test/java/com/google/cloud/tools/jib/http/FailoverHttpClientTest.java @@ -239,15 +239,15 @@ public void testGet_insecureClientOnNonListeningServerAndPortSpecified() throws FailoverHttpClient insecureHttpClient = newHttpClient(true, false); Mockito.when(mockHttpRequest.execute()) - .thenThrow(new ConnectException("my exception")); // server is not listening on 5000 + .thenThrow(new ConnectException("my exception")); // server is not listening on 5001 try (Response response = - insecureHttpClient.get(new URL("https://insecure:5000"), fakeRequest(null))) { + insecureHttpClient.get(new URL("https://insecure:5001"), fakeRequest(null))) { Assert.fail("Should not fall back to HTTP if port was explicitly given and cannot connect"); } catch (ConnectException ex) { Assert.assertEquals("my exception", ex.getMessage()); - verifyCapturedUrls("https://insecure:5000"); + verifyCapturedUrls("https://insecure:5001"); Mockito.verify(mockHttpRequest, Mockito.times(1)).execute(); Mockito.verifyNoInteractions(mockInsecureHttpRequest, logger); diff --git a/jib-gradle-plugin/build.gradle b/jib-gradle-plugin/build.gradle index 46f416ab1ed..02c27c7ff6d 100644 --- a/jib-gradle-plugin/build.gradle +++ b/jib-gradle-plugin/build.gradle @@ -45,7 +45,7 @@ dependencies { integrationTestImplementation dependencyStrings.JBCRYPT // only for testing a concrete Spring Boot example in a test (not for test infrastructure) - testImplementation 'org.springframework.boot:spring-boot-gradle-plugin:2.2.11.RELEASE' + testImplementation 'org.springframework.boot:spring-boot-gradle-plugin:2.7.13' } /* RELEASE */ @@ -57,17 +57,13 @@ release { 'com.google.cloud.tools:jib-plugins-common', ] git { - requireBranch = /^gradle-release-v\d+.*$/ //regex + requireBranch.set(/^gradle-release-v\d+.*$/) //regex } } // Gradle Plugin Portal releases -pluginBundle { +gradlePlugin { website = 'https://github.com/GoogleContainerTools/jib/' vcsUrl = 'https://github.com/GoogleContainerTools/jib/' - tags = ['google', 'java', 'containers', 'docker', 'kubernetes', 'microservices'] -} - -gradlePlugin { testSourceSets sourceSets.integrationTest, sourceSets.test plugins { jibPlugin { @@ -75,6 +71,7 @@ gradlePlugin { displayName = 'Jib' description = 'Containerize your Java application' implementationClass = 'com.google.cloud.tools.jib.gradle.JibPlugin' + tags.set(['google', 'java', 'containers', 'docker', 'kubernetes', 'microservices']) } } } diff --git a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SingleProjectIntegrationTest.java b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SingleProjectIntegrationTest.java index 7c53878dc50..1695ab70b95 100644 --- a/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SingleProjectIntegrationTest.java +++ b/jib-gradle-plugin/src/integration-test/java/com/google/cloud/tools/jib/gradle/SingleProjectIntegrationTest.java @@ -50,7 +50,7 @@ public class SingleProjectIntegrationTest { @ClassRule public static final LocalRegistry localRegistry1 = - new LocalRegistry(5000, "testuser", "testpassword"); + new LocalRegistry(5001, "testuser", "testpassword"); @ClassRule public static final LocalRegistry localRegistry2 = @@ -449,7 +449,7 @@ public void testBuild_complex() @Test public void testBuild_complex_sameFromAndToRegistry() throws IOException, InterruptedException { - String targetImage = dockerHost + ":5000/compleximage:gradle" + System.nanoTime(); + String targetImage = dockerHost + ":5001/compleximage:gradle" + System.nanoTime(); Instant beforeBuild = Instant.now(); buildAndRunComplex(targetImage, "testuser", "testpassword", localRegistry1); assertThat(JibRunHelper.getCreationTime(targetImage)).isGreaterThan(beforeBuild); diff --git a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-configuration.gradle b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-configuration.gradle index 0d78b139d3d..01da56096ac 100644 --- a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-configuration.gradle +++ b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-configuration.gradle @@ -24,8 +24,8 @@ configurations { } dependencies { - compile files('libs/dependency-1.0.0.jar') - runtime 'com.google.guava:guava:30.1-jre' + implementation files('libs/dependency-1.0.0.jar') + runtimeOnly 'com.google.guava:guava:30.1-jre' myConfiguration files('libs/dependency2') otherConfiguration files('libs/dependency3') } diff --git a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs-filtering.gradle b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs-filtering.gradle index 4e04624dacd..94683083574 100644 --- a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs-filtering.gradle +++ b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs-filtering.gradle @@ -11,7 +11,7 @@ repositories { } dependencies { - compile files('libs/dependency-1.0.0.jar') + implementation files('libs/dependency-1.0.0.jar') } jib { diff --git a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs.gradle b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs.gradle index da49d7772be..7bedbd73699 100644 --- a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs.gradle +++ b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs.gradle @@ -11,7 +11,7 @@ repositories { } dependencies { - compile files('libs/dependency-1.0.0.jar') + implementation() files('libs/dependency-1.0.0.jar') } jib { diff --git a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs2.gradle b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs2.gradle index f4c21d20050..a1694ed9f73 100644 --- a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs2.gradle +++ b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs2.gradle @@ -11,7 +11,7 @@ repositories { } dependencies { - compile files('libs/dependency-1.0.0.jar') + implementation files('libs/dependency-1.0.0.jar') } jib { diff --git a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs3.gradle b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs3.gradle index 178c0f80c9f..d48d6d501a2 100644 --- a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs3.gradle +++ b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-extra-dirs3.gradle @@ -11,7 +11,7 @@ repositories { } dependencies { - compile files('libs/dependency-1.0.0.jar') + implementation files('libs/dependency-1.0.0.jar') } jib { diff --git a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-jar-containerization.gradle b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-jar-containerization.gradle index 917a55ef7f6..150f012681d 100644 --- a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-jar-containerization.gradle +++ b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-jar-containerization.gradle @@ -11,7 +11,7 @@ repositories { } dependencies { - compile files('libs/dependency-1.0.0.jar') + implementation files('libs/dependency-1.0.0.jar') } jar { diff --git a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-java11-incompatible.gradle b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-java11-incompatible.gradle index 2cc07b662ea..aa93e702f16 100644 --- a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-java11-incompatible.gradle +++ b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-java11-incompatible.gradle @@ -11,7 +11,7 @@ repositories { } dependencies { - compile files('libs/dependency-1.0.0.jar') + implementation files('libs/dependency-1.0.0.jar') } jib.from.image = 'eclipse-temurin:8-jdk-focal' diff --git a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-java11.gradle b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-java11.gradle index 8c563bfb005..995aa9e7afc 100644 --- a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-java11.gradle +++ b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-java11.gradle @@ -11,7 +11,7 @@ repositories { } dependencies { - compile files('libs/dependency-1.0.0.jar') + implementation files('libs/dependency-1.0.0.jar') } jib.from.image = 'eclipse-temurin:11-jdk-focal' diff --git a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-java17.gradle b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-java17.gradle index 9c860213ef3..2600d5f6a89 100644 --- a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-java17.gradle +++ b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-java17.gradle @@ -11,7 +11,7 @@ repositories { } dependencies { - compile files('libs/dependency-1.0.0.jar') + implementation files('libs/dependency-1.0.0.jar') } jib.to.image = System.getProperty("_TARGET_IMAGE") \ No newline at end of file diff --git a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-local-base.gradle b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-local-base.gradle index a757ac89fe2..6e57fa0be35 100644 --- a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-local-base.gradle +++ b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-local-base.gradle @@ -11,7 +11,7 @@ repositories { } dependencies { - compile files('libs/dependency-1.0.0.jar') + implementation files('libs/dependency-1.0.0.jar') } jib { diff --git a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-timestamps-custom.gradle b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-timestamps-custom.gradle index 9771046978e..1db4cc1e73f 100644 --- a/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-timestamps-custom.gradle +++ b/jib-gradle-plugin/src/integration-test/resources/gradle/projects/simple/build-timestamps-custom.gradle @@ -11,7 +11,7 @@ repositories { } dependencies { - compile files('libs/dependency-1.0.0.jar') + implementation files('libs/dependency-1.0.0.jar') } jib { diff --git a/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/GradleProjectPropertiesExtensionTest.java b/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/GradleProjectPropertiesExtensionTest.java index 63718ce0e55..fd68285e737 100644 --- a/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/GradleProjectPropertiesExtensionTest.java +++ b/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/GradleProjectPropertiesExtensionTest.java @@ -16,6 +16,8 @@ package com.google.cloud.tools.jib.gradle; +import static org.gradle.api.tasks.SourceSet.MAIN_SOURCE_SET_NAME; + import com.google.cloud.tools.jib.api.InvalidImageReferenceException; import com.google.cloud.tools.jib.api.Jib; import com.google.cloud.tools.jib.api.JibContainerBuilder; @@ -35,11 +37,21 @@ import java.util.Map; import java.util.Optional; import org.gradle.api.Action; +import org.gradle.api.JavaVersion; import org.gradle.api.Project; +import org.gradle.api.file.RegularFile; +import org.gradle.api.internal.provider.DefaultProperty; import org.gradle.api.logging.Logger; import org.gradle.api.logging.configuration.ConsoleOutput; import org.gradle.api.model.ObjectFactory; +import org.gradle.api.plugins.ExtensionContainer; import org.gradle.api.plugins.JavaPlugin; +import org.gradle.api.plugins.JavaPluginExtension; +import org.gradle.api.provider.Provider; +import org.gradle.api.tasks.SourceSet; +import org.gradle.api.tasks.SourceSetContainer; +import org.gradle.api.tasks.TaskContainer; +import org.gradle.jvm.tasks.Jar; import org.hamcrest.CoreMatchers; import org.hamcrest.MatcherAssert; import org.junit.Assert; @@ -205,6 +217,21 @@ private ExtensionDefinedBarConfig(String barParam) { @Mock private Logger mockLogger; @Mock private ObjectFactory mockObjectFactory; + @Mock private JavaPluginExtension mockJavaPluginExtension; + @Mock private SourceSetContainer mockSourceSetContainer; + + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private SourceSet mockSourceSet; + + @Mock private TaskContainer mockReturnContainer; + + @Mock private ExtensionContainer mockExtensionContainer; + + @Mock(answer = Answers.RETURNS_DEEP_STUBS) + private Jar mockJarTask; + + @Mock private Provider mockProviderFile; + @Mock(answer = Answers.RETURNS_DEEP_STUBS) private Project mockProject; @@ -219,7 +246,24 @@ public void setUp() { Mockito.when(mockLogger.isInfoEnabled()).thenReturn(true); Mockito.when(mockLogger.isWarnEnabled()).thenReturn(true); Mockito.when(mockLogger.isErrorEnabled()).thenReturn(true); - + Mockito.when(mockProject.getExtensions()).thenReturn(mockExtensionContainer); + Mockito.when(mockProject.getTasks()).thenReturn(mockReturnContainer); + Mockito.when(mockReturnContainer.findByName("jar")).thenReturn(mockJarTask); + Mockito.when(mockJarTask.getArchiveFile()).thenReturn(mockProviderFile); + Mockito.when(mockProviderFile.isPresent()).thenReturn(true); + + Mockito.when(mockExtensionContainer.getByType(JavaPluginExtension.class)) + .thenReturn(mockJavaPluginExtension); + Mockito.when(mockJavaPluginExtension.getSourceSets()).thenReturn(mockSourceSetContainer); + Mockito.when(mockJavaPluginExtension.getTargetCompatibility()) + .thenReturn(JavaVersion.VERSION_1_8); + Mockito.when(mockSourceSetContainer.getByName(MAIN_SOURCE_SET_NAME)).thenReturn(mockSourceSet); + + Mockito.when(mockObjectFactory.property(String.class)) + .thenReturn(new DefaultProperty<>(null, String.class)); + // Mockito.when(mockObjectFactory.fileProperty()).thenReturn(new DefaultRegularFileVar()); + Mockito.when(mockObjectFactory.property(Boolean.class)) + .thenReturn(new DefaultProperty<>(null, Boolean.class)); Mockito.when(mockProject.getGradle().getStartParameter().getConsoleOutput()) .thenReturn(ConsoleOutput.Plain); Mockito.when(mockProject.getObjects()).thenReturn(mockObjectFactory); @@ -248,7 +292,8 @@ public void testRunPluginExtensions_noExtensionsConfigured() throws JibPluginExt loadedExtensions = Arrays.asList(extension); JibContainerBuilder extendedBuilder = - gradleProjectProperties.runPluginExtensions(Collections.emptyList(), containerBuilder); + gradleProjectProperties.runPluginExtensions( + Collections.emptyList(), containerBuilder, Optional.of(mockProject)); Assert.assertSame(extendedBuilder, containerBuilder); gradleProjectProperties.waitForLoggingThread(); @@ -259,7 +304,7 @@ public void testRunPluginExtensions_noExtensionsConfigured() throws JibPluginExt public void testRunPluginExtensions_configuredExtensionNotFound() { try { gradleProjectProperties.runPluginExtensions( - Arrays.asList(new FooExtensionConfig()), containerBuilder); + Arrays.asList(new FooExtensionConfig()), containerBuilder, Optional.of(mockProject)); Assert.fail(); } catch (JibPluginExtensionException ex) { Assert.assertEquals( @@ -281,7 +326,7 @@ public void testRunPluginExtensions() throws JibPluginExtensionException { JibContainerBuilder extendedBuilder = gradleProjectProperties.runPluginExtensions( - Arrays.asList(new FooExtensionConfig()), containerBuilder); + Arrays.asList(new FooExtensionConfig()), containerBuilder, Optional.of(mockProject)); Assert.assertEquals("user from extension", extendedBuilder.toContainerBuildPlan().getUser()); gradleProjectProperties.waitForLoggingThread(); @@ -305,7 +350,7 @@ public void testRunPluginExtensions_exceptionFromExtension() { try { gradleProjectProperties.runPluginExtensions( - Arrays.asList(new FooExtensionConfig()), containerBuilder); + Arrays.asList(new FooExtensionConfig()), containerBuilder, Optional.of(mockProject)); Assert.fail(); } catch (JibPluginExtensionException ex) { Assert.assertEquals("exception from extension", ex.getMessage()); @@ -323,7 +368,7 @@ public void testRunPluginExtensions_invalidBaseImageFromExtension() { try { gradleProjectProperties.runPluginExtensions( - Arrays.asList(new FooExtensionConfig()), containerBuilder); + Arrays.asList(new FooExtensionConfig()), containerBuilder, Optional.of(mockProject)); Assert.fail(); } catch (JibPluginExtensionException ex) { Assert.assertEquals("invalid base image reference: in*val+id", ex.getMessage()); @@ -346,12 +391,16 @@ public void testRunPluginExtensions_extensionOrder() throws JibPluginExtensionEx JibContainerBuilder extendedBuilder1 = gradleProjectProperties.runPluginExtensions( - Arrays.asList(new FooExtensionConfig(), new BarExtensionConfig()), containerBuilder); + Arrays.asList(new FooExtensionConfig(), new BarExtensionConfig()), + containerBuilder, + Optional.of(mockProject)); Assert.assertEquals("bar", extendedBuilder1.toContainerBuildPlan().getBaseImage()); JibContainerBuilder extendedBuilder2 = gradleProjectProperties.runPluginExtensions( - Arrays.asList(new BarExtensionConfig(), new FooExtensionConfig()), containerBuilder); + Arrays.asList(new BarExtensionConfig(), new FooExtensionConfig()), + containerBuilder, + Optional.of(mockProject)); Assert.assertEquals("foo", extendedBuilder2.toContainerBuildPlan().getBaseImage()); } @@ -366,7 +415,8 @@ public void testRunPluginExtensions_customProperties() throws JibPluginExtension JibContainerBuilder extendedBuilder = gradleProjectProperties.runPluginExtensions( Arrays.asList(new FooExtensionConfig(ImmutableMap.of("user", "65432"))), - containerBuilder); + containerBuilder, + Optional.of(mockProject)); Assert.assertEquals("65432", extendedBuilder.toContainerBuildPlan().getUser()); } @@ -388,7 +438,9 @@ public void testRunPluginExtensions_extensionDefinedConfigurations_emptyConfig() loadedExtensions = Arrays.asList(fooExtension, barExtension); gradleProjectProperties.runPluginExtensions( - Arrays.asList(new FooExtensionConfig(), new BarExtensionConfig()), containerBuilder); + Arrays.asList(new FooExtensionConfig(), new BarExtensionConfig()), + containerBuilder, + Optional.of(mockProject)); } @Test @@ -412,7 +464,8 @@ public void testRunPluginExtensions_extensionDefinedConfigurations() Arrays.asList( new FooExtensionConfig(new ExtensionDefinedFooConfig("fooParamValue")), new BarExtensionConfig(new ExtensionDefinedBarConfig("barParamValue"))), - containerBuilder); + containerBuilder, + Optional.of(mockProject)); } @Test @@ -427,7 +480,8 @@ public void testRunPluginExtensions_ignoreUnexpectedExtraConfig() new BaseExtensionConfig<>( BaseExtension.class.getName(), Collections.emptyMap(), (ignored) -> {}); try { - gradleProjectProperties.runPluginExtensions(Arrays.asList(extensionConfig), containerBuilder); + gradleProjectProperties.runPluginExtensions( + Arrays.asList(extensionConfig), containerBuilder, Optional.of(mockProject)); Assert.fail(); } catch (IllegalArgumentException ex) { Assert.assertEquals( @@ -448,7 +502,7 @@ public void testRunPluginExtensions_runtimeExceptionFromExtension() { try { gradleProjectProperties.runPluginExtensions( - Arrays.asList(new FooExtensionConfig()), containerBuilder); + Arrays.asList(new FooExtensionConfig()), containerBuilder, Optional.of(mockProject)); Assert.fail(); } catch (JibPluginExtensionException ex) { Assert.assertEquals(FooExtension.class, ex.getExtensionClass()); diff --git a/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/GradleProjectPropertiesTest.java b/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/GradleProjectPropertiesTest.java index 7698228ab0e..504f946a18a 100644 --- a/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/GradleProjectPropertiesTest.java +++ b/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/GradleProjectPropertiesTest.java @@ -17,6 +17,8 @@ package com.google.cloud.tools.jib.gradle; import static com.google.common.truth.Truth.assertThat; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertThrows; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @@ -144,6 +146,9 @@ public void setUp() throws URISyntaxException, IOException { .withProjectDir(projectDir.toFile()) .withGradleUserHomeDir(temporaryFolder.newFolder()) .build(); + + project.getRepositories().add(project.getRepositories().mavenCentral()); + project.getPlugins().apply("java"); DependencyHandler dependencies = project.getDependencies(); @@ -161,14 +166,6 @@ public void setUp() throws URISyntaxException, IOException { // We can't commit an empty directory in Git, so create (if not exist). Path emptyDirectory = getResource("gradle/webapp").resolve("WEB-INF/classes/empty_dir"); Files.createDirectories(emptyDirectory); - - gradleProjectProperties = - new GradleProjectProperties( - project, - mockLogger, - mockTempDirectoryProvider, - mockExtensionLoader, - JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME); } @Test @@ -177,11 +174,14 @@ public void testGetMainClassFromJar_success() { jar.setManifest( new DefaultManifest(null).attributes(ImmutableMap.of("Main-Class", "some.main.class"))); + setupGradleProjectPropertiesInstance(); assertThat(gradleProjectProperties.getMainClassFromJarPlugin()).isEqualTo("some.main.class"); } @Test public void testGetMainClassFromJar_missing() { + setupGradleProjectPropertiesInstance(); + assertThat(gradleProjectProperties.getMainClassFromJarPlugin()).isNull(); } @@ -193,6 +193,8 @@ public void testGetMainClassFromJarAsProperty_success() { Jar jar = project.getTasks().withType(Jar.class).getByName("jar"); jar.setManifest(new DefaultManifest(null).attributes(ImmutableMap.of("Main-Class", mainClass))); + setupGradleProjectPropertiesInstance(); + assertThat(gradleProjectProperties.getMainClassFromJarPlugin()).isEqualTo("some.main.class"); } @@ -202,13 +204,15 @@ public void testGetMainClassFromJarAsPropertyWithValueNull_missing() { Jar jar = project.getTasks().withType(Jar.class).getByName("jar"); jar.setManifest(new DefaultManifest(null).attributes(ImmutableMap.of("Main-Class", mainClass))); - + setupGradleProjectPropertiesInstance(); assertThat(gradleProjectProperties.getMainClassFromJarPlugin()).isNull(); } @Test public void testIsWarProject() { project.getPlugins().apply("war"); + setupGradleProjectPropertiesInstance(); + assertThat(gradleProjectProperties.isWarProject()).isTrue(); } @@ -258,35 +262,41 @@ public void testConvertPermissionsMap() { @Test public void testGetMajorJavaVersion() { - JavaPluginExtension extension = project.getExtensions().findByType(JavaPluginExtension.class); + JavaPluginExtension convention = project.getExtensions().findByType(JavaPluginExtension.class); + + convention.setTargetCompatibility(JavaVersion.VERSION_1_3); + setupGradleProjectPropertiesInstance(); - extension.setTargetCompatibility(JavaVersion.VERSION_1_3); assertThat(gradleProjectProperties.getMajorJavaVersion()).isEqualTo(3); - extension.setTargetCompatibility(JavaVersion.VERSION_11); + convention.setTargetCompatibility(JavaVersion.VERSION_11); + setupGradleProjectPropertiesInstance(); assertThat(gradleProjectProperties.getMajorJavaVersion()).isEqualTo(11); - extension.setTargetCompatibility(JavaVersion.VERSION_1_9); + convention.setTargetCompatibility(JavaVersion.VERSION_1_9); + setupGradleProjectPropertiesInstance(); assertThat(gradleProjectProperties.getMajorJavaVersion()).isEqualTo(9); } @Test public void testGetMajorJavaVersion_jvm8() { Assume.assumeThat(JavaVersion.current(), CoreMatchers.is(JavaVersion.VERSION_1_8)); - + setupGradleProjectPropertiesInstance(); assertThat(gradleProjectProperties.getMajorJavaVersion()).isEqualTo(8); } @Test public void testGetMajorJavaVersion_jvm11() { Assume.assumeThat(JavaVersion.current(), CoreMatchers.is(JavaVersion.VERSION_11)); - + setupGradleProjectPropertiesInstance(); assertThat(gradleProjectProperties.getMajorJavaVersion()).isEqualTo(11); } @Test public void testCreateContainerBuilder_correctSourceFiles() throws URISyntaxException, InvalidImageReferenceException, CacheDirectoryCreationException { + setupGradleProjectPropertiesInstance(); + ContainerBuilderLayers layers = new ContainerBuilderLayers(setupBuildContext()); Path applicationDirectory = getResource("gradle/application"); @@ -352,6 +362,7 @@ public void testCreateContainerBuilder_noClassesFiles() @Test public void testCreateContainerBuilder_correctExtractionPaths() throws InvalidImageReferenceException, CacheDirectoryCreationException { + setupGradleProjectPropertiesInstance(); ContainerBuilderLayers layers = new ContainerBuilderLayers(setupBuildContext()); assertThat(layers.dependenciesLayer.getEntries()) @@ -382,6 +393,7 @@ public void testCreateContainerBuilder_war() throws URISyntaxException, IOException, InvalidImageReferenceException, CacheDirectoryCreationException { Path unzipTarget = setUpWarProject(getResource("gradle/webapp")); + setupGradleProjectPropertiesInstance(); ContainerBuilderLayers layers = new ContainerBuilderLayers(setupBuildContext()); assertThat(layers.dependenciesLayer.getEntries()) @@ -444,7 +456,7 @@ public void testCreateContainerBuilder_noErrorIfWebInfClassesDoesNotExist() throws IOException, InvalidImageReferenceException { temporaryFolder.newFolder("WEB-INF", "lib"); setUpWarProject(temporaryFolder.getRoot().toPath()); - + setupGradleProjectPropertiesInstance(); assertThat( gradleProjectProperties.createJibContainerBuilder( JavaContainerBuilder.from("ignored"), ContainerizingMode.EXPLODED)) @@ -456,7 +468,7 @@ public void testCreateContainerBuilder_noErrorIfWebInfLibDoesNotExist() throws IOException, InvalidImageReferenceException { temporaryFolder.newFolder("WEB-INF", "classes"); setUpWarProject(temporaryFolder.getRoot().toPath()); - + setupGradleProjectPropertiesInstance(); assertThat( gradleProjectProperties.createJibContainerBuilder( JavaContainerBuilder.from("ignored"), ContainerizingMode.EXPLODED)) @@ -467,22 +479,33 @@ public void testCreateContainerBuilder_noErrorIfWebInfLibDoesNotExist() public void testCreateContainerBuilder_noErrorIfWebInfDoesNotExist() throws IOException, InvalidImageReferenceException { setUpWarProject(temporaryFolder.getRoot().toPath()); - + setupGradleProjectPropertiesInstance(); assertThat( gradleProjectProperties.createJibContainerBuilder( JavaContainerBuilder.from("ignored"), ContainerizingMode.EXPLODED)) .isNotNull(); } + private void setupGradleProjectPropertiesInstance() { + gradleProjectProperties = + new GradleProjectProperties( + project, + mockLogger, + mockTempDirectoryProvider, + mockExtensionLoader, + JavaPlugin.RUNTIME_CLASSPATH_CONFIGURATION_NAME); + } + @Test public void testGetWarFilePath() throws IOException { Path outputDir = temporaryFolder.newFolder("output").toPath(); project.getPlugins().apply("war"); + setupGradleProjectPropertiesInstance(); War war = project.getTasks().withType(War.class).getByName("war"); war.getDestinationDirectory().set(outputDir.toFile()); - assertThat(gradleProjectProperties.getWarFilePath()) + assertThat(gradleProjectProperties.getWarFilePath(project)) .isEqualTo(outputDir.resolve("my-app.war").toString()); } @@ -494,8 +517,8 @@ public void testGetWarFilePath_bootWar() throws IOException { project.getPlugins().apply("org.springframework.boot"); War bootWar = project.getTasks().withType(War.class).getByName("bootWar"); bootWar.getDestinationDirectory().set(outputDir.toFile()); - - assertThat(gradleProjectProperties.getWarFilePath()) + setupGradleProjectPropertiesInstance(); + assertThat(gradleProjectProperties.getWarFilePath(project)) .isEqualTo(outputDir.resolve("my-app.war").toString()); } @@ -510,12 +533,65 @@ public void testGetWarFilePath_bootWarDisabled() throws IOException { project.getPlugins().apply("org.springframework.boot"); project.getTasks().getByName("bootWar").setEnabled(false); - assertThat(gradleProjectProperties.getWarFilePath()) - .isEqualTo(outputDir.resolve("my-app.war").toString()); + setupGradleProjectPropertiesInstance(); + assertThat(gradleProjectProperties.getWarFilePath(project)) + .isEqualTo(outputDir.resolve("my-app-plain.war").toString()); + } + + @Test + public void testGetSingleThreadedExecutor() { + setupGradleProjectPropertiesInstance(); + assertNotNull(gradleProjectProperties.getSingleThreadedExecutor()); + gradleProjectProperties.singleThreadedExecutor = null; // pretend running from cache + assertNotNull(gradleProjectProperties.getSingleThreadedExecutor()); + } + + @Test + public void testGetConsoleLogger() { + setupGradleProjectPropertiesInstance(); + assertNotNull(gradleProjectProperties.getConsoleLogger()); + } + + @Test + public void testGetClassesOutputDirectory() { + setupGradleProjectPropertiesInstance(); + assertNotNull(gradleProjectProperties.getClassesOutputDirectories()); + assertFalse(gradleProjectProperties.getClassesOutputDirectories().getFiles().isEmpty()); + } + + @Test + public void testGetResourcesOutputDirectory() { + setupGradleProjectPropertiesInstance(); + assertNotNull(gradleProjectProperties.getResourcesOutputDirectory()); + } + + @Test + public void testGetClassFiles() throws IOException { + setupGradleProjectPropertiesInstance(); + assertFalse(gradleProjectProperties.getClassFiles().isEmpty()); + } + + @Test + public void testGetDefaultCacheDir() throws IOException { + setupGradleProjectPropertiesInstance(); + assertNotNull(gradleProjectProperties.getDefaultCacheDirectory()); + } + + @Test + public void testGetJarPluginName() throws IOException { + setupGradleProjectPropertiesInstance(); + assertNotNull(gradleProjectProperties.getJarPluginName()); + } + + @Test + public void testGetTempProvider() { + setupGradleProjectPropertiesInstance(); + assertNotNull(gradleProjectProperties.getTempDirectoryProvider()); } @Test public void testGetDependencies() throws URISyntaxException { + setupGradleProjectPropertiesInstance(); assertThat(gradleProjectProperties.getDependencies()) .containsExactly( getResource("gradle/application/dependencies/library.jarC.jar"), diff --git a/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/JibExtensionTest.java b/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/JibExtensionTest.java index 440ae177792..73685e0f7cd 100644 --- a/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/JibExtensionTest.java +++ b/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/JibExtensionTest.java @@ -32,6 +32,7 @@ import java.util.HashSet; import java.util.List; import java.util.Properties; +import java.util.stream.Collectors; import org.gradle.api.Project; import org.gradle.api.provider.Property; import org.gradle.api.provider.Provider; @@ -418,15 +419,27 @@ public void testSkaffold() { }); }); Path root = fakeProject.getRootDir().toPath(); - assertThat(testJibExtension.getSkaffold().getSync().getExcludes()) + assertThat( + testJibExtension.getSkaffold().getSync().getExcludes().getFiles().stream() + .map(File::toPath) + .collect(Collectors.toSet())) .containsExactly( root.resolve("sync1").toAbsolutePath(), root.resolve("sync2").toAbsolutePath()); - assertThat(testJibExtension.getSkaffold().getWatch().getBuildIncludes()) + assertThat( + testJibExtension.getSkaffold().getWatch().getBuildIncludes().getFiles().stream() + .map(File::toPath) + .collect(Collectors.toSet())) .containsExactly( root.resolve("watch1").toAbsolutePath(), root.resolve("watch2").toAbsolutePath()); - assertThat(testJibExtension.getSkaffold().getWatch().getIncludes()) + assertThat( + testJibExtension.getSkaffold().getWatch().getIncludes().getFiles().stream() + .map(File::toPath) + .collect(Collectors.toSet())) .containsExactly(root.resolve("watch3").toAbsolutePath()); - assertThat(testJibExtension.getSkaffold().getWatch().getExcludes()) + assertThat( + testJibExtension.getSkaffold().getWatch().getExcludes().getFiles().stream() + .map(File::toPath) + .collect(Collectors.toSet())) .containsExactly(root.resolve("watch4").toAbsolutePath()); } diff --git a/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/JibPluginTest.java b/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/JibPluginTest.java index fe2829d0dd5..c0b7f7dc029 100644 --- a/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/JibPluginTest.java +++ b/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/JibPluginTest.java @@ -104,7 +104,7 @@ public void testCheckGradleVersion_fail() throws IOException { GradleRunner.create() .withProjectDir(testProjectRoot.getRoot()) .withPluginClasspath() - .withGradleVersion("4.3"); + .withGradleVersion("8.4"); Exception exception = assertThrows(UnexpectedBuildFailure.class, () -> gradleRunner.build()); assertThat(exception) @@ -203,8 +203,10 @@ public void testSpringBootJarProject_nonPackagedMode() { createProject("java", "org.springframework.boot", "com.google.cloud.tools.jib"); Jar jar = (Jar) project.getTasks().getByPath(":jar"); + jar.setEnabled(false); // Spring boot >2.5.0 no longer sets this as disabled by default assertThat(jar.getEnabled()).isFalse(); - assertThat(jar.getArchiveClassifier().get()).isEmpty(); + assertThat(jar.getArchiveClassifier().get()) + .isEqualTo("plain"); // >2.5.0 generates "plain" instead of empty } @Test @@ -216,7 +218,7 @@ public void testSpringBootJarProject_packagedMode() { Jar jar = (Jar) project.getTasks().getByPath(":jar"); assertThat(jar.getEnabled()).isTrue(); - assertThat(jar.getArchiveClassifier().get()).isEqualTo("original"); + assertThat(jar.getArchiveClassifier().get()).isEqualTo("plain"); } @Test @@ -244,7 +246,7 @@ public void testSpringBootJarProject_packagedMode_bootJarClassifierSet() { Jar jar = (Jar) project.getTasks().getByPath(":jar"); assertThat(jar.getEnabled()).isTrue(); - assertThat(jar.getArchiveClassifier().get()).isEmpty(); + assertThat(jar.getArchiveClassifier().get()).isEqualTo("plain"); } @Test @@ -253,7 +255,14 @@ public void testSpringBootJarProject_packagedMode_jarEnabled() { createProject("java", "org.springframework.boot", "com.google.cloud.tools.jib"); JibExtension jibExtension = (JibExtension) project.getExtensions().getByName("jib"); jibExtension.setContainerizingMode("packaged"); - project.getTasks().named("jar").configure(task -> task.setEnabled(true)); + project + .getTasks() + .named("jar") + .configure( + task -> { + task.setEnabled(true); + ((Jar) task).getArchiveClassifier().set(""); // pre spring boot 2.5.0 behaviour + }); TaskContainer tasks = project.getTasks(); Exception exception = assertThrows(GradleException.class, () -> tasks.getByPath(":jar")); @@ -293,7 +302,7 @@ public void testSpringBootJarProject_packagedMode_jarEnabledAndBootJarClassifier Jar jar = (Jar) project.getTasks().getByPath(":jar"); assertThat(jar.getEnabled()).isTrue(); - assertThat(jar.getArchiveClassifier().get()).isEmpty(); + assertThat(jar.getArchiveClassifier().get()).isEqualTo("plain"); } @Test @@ -308,7 +317,7 @@ public void testSpringBootJarProject_packagedMode_jarEnabledAndBootJarDisabled() Jar jar = (Jar) project.getTasks().getByPath(":jar"); assertThat(jar.getEnabled()).isTrue(); assertThat(project.getTasks().getByPath(":bootJar").getEnabled()).isFalse(); - assertThat(jar.getArchiveClassifier().get()).isEmpty(); + assertThat(jar.getArchiveClassifier().get()).isEqualTo("plain"); } @Test diff --git a/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/skaffold/FilesTaskV2Test.java b/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/skaffold/FilesTaskV2Test.java index 3df3a861543..4eec8aa2b40 100644 --- a/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/skaffold/FilesTaskV2Test.java +++ b/jib-gradle-plugin/src/test/java/com/google/cloud/tools/jib/gradle/skaffold/FilesTaskV2Test.java @@ -48,7 +48,7 @@ public class FilesTaskV2Test { @ClassRule public static final TestProject platformProject = - new TestProject("platform").withGradleVersion("5.2"); + new TestProject("platform").withGradleVersion("8.4"); /** * Verifies that the files task succeeded and returns the list of paths it prints out. @@ -60,7 +60,8 @@ public class FilesTaskV2Test { private static String verifyTaskSuccess(TestProject project, @Nullable String moduleName) { String taskName = ":" + (moduleName == null ? "" : moduleName + ":") + JibPlugin.SKAFFOLD_FILES_TASK_V2_NAME; - BuildResult buildResult = project.build(taskName, "-q", "-D_TARGET_IMAGE=ignored"); + BuildResult buildResult = + project.build(taskName, "-q", "-D_TARGET_IMAGE=ignored", "--stacktrace"); BuildTask jibTask = buildResult.task(taskName); Assert.assertNotNull(jibTask); Assert.assertEquals(TaskOutcome.SUCCESS, jibTask.getOutcome()); diff --git a/jib-maven-plugin/build.gradle b/jib-maven-plugin/build.gradle index f8ead158cd3..d8560270877 100644 --- a/jib-maven-plugin/build.gradle +++ b/jib-maven-plugin/build.gradle @@ -71,7 +71,7 @@ release { 'com.google.cloud.tools:jib-plugins-common', ] git { - requireBranch = /^maven-release-v\d+.*$/ //regex + requireBranch.set(/^maven-release-v\d+.*$/) //regex } } /* RELEASE */ diff --git a/jib-maven-plugin/src/integration-test/java/com/google/cloud/tools/jib/maven/BuildDockerMojoIntegrationTest.java b/jib-maven-plugin/src/integration-test/java/com/google/cloud/tools/jib/maven/BuildDockerMojoIntegrationTest.java index 7d3be1d8c51..ce7225962bf 100644 --- a/jib-maven-plugin/src/integration-test/java/com/google/cloud/tools/jib/maven/BuildDockerMojoIntegrationTest.java +++ b/jib-maven-plugin/src/integration-test/java/com/google/cloud/tools/jib/maven/BuildDockerMojoIntegrationTest.java @@ -72,7 +72,6 @@ private static String buildToDockerDaemonAndRun(TestProject project, String imag .run(); String dockerInspectLabels = new Command("docker", "inspect", "-f", "'{{json .Config.Labels}}'", imageReference).run(); - String history = new Command("docker", "history", imageReference).run(); MatcherAssert.assertThat( dockerInspectVolumes, CoreMatchers.containsString("\"/var/log\":{},\"/var/log2\":{}")); diff --git a/jib-maven-plugin/src/integration-test/java/com/google/cloud/tools/jib/maven/BuildImageMojoIntegrationTest.java b/jib-maven-plugin/src/integration-test/java/com/google/cloud/tools/jib/maven/BuildImageMojoIntegrationTest.java index 52675002c20..93530a71477 100644 --- a/jib-maven-plugin/src/integration-test/java/com/google/cloud/tools/jib/maven/BuildImageMojoIntegrationTest.java +++ b/jib-maven-plugin/src/integration-test/java/com/google/cloud/tools/jib/maven/BuildImageMojoIntegrationTest.java @@ -69,7 +69,7 @@ public class BuildImageMojoIntegrationTest { @ClassRule public static final LocalRegistry localRegistry = - new LocalRegistry(5000, "testuser", "testpassword"); + new LocalRegistry(5001, "testuser", "testpassword"); private static final String dockerHost = System.getenv("DOCKER_IP") != null ? System.getenv("DOCKER_IP") : "localhost"; @@ -567,7 +567,7 @@ public void testExecute_defaultTarget() throws IOException { @Test public void testExecute_complex() throws IOException, InterruptedException, VerificationException, DigestException { - String targetImage = dockerHost + ":5000/compleximage:maven" + System.nanoTime(); + String targetImage = dockerHost + ":5001/compleximage:maven" + System.nanoTime(); Instant before = Instant.now(); String output = buildAndRunComplex(targetImage, "pom-complex.xml"); assertThat(output) @@ -594,7 +594,7 @@ public void testExecute_complex() @Test public void testExecute_timestampCustom() throws IOException, InterruptedException, VerificationException { - String targetImage = dockerHost + ":5000/simpleimage:maven" + System.nanoTime(); + String targetImage = dockerHost + ":5001/simpleimage:maven" + System.nanoTime(); String pom = "pom-timestamps-custom.xml"; assertThat(buildAndRunComplex(targetImage, pom)) .isEqualTo( @@ -607,7 +607,7 @@ public void testExecute_timestampCustom() @Test public void testExecute_complex_sameFromAndToRegistry() throws IOException, InterruptedException, VerificationException { - String targetImage = dockerHost + ":5000/compleximage:maven" + System.nanoTime(); + String targetImage = dockerHost + ":5001/compleximage:maven" + System.nanoTime(); assertThat(buildAndRunComplex(targetImage, "pom-complex.xml")) .isEqualTo( "Hello, world. An argument.\n1970-01-01T00:00:01Z\nrwxr-xr-x\nrwxrwxrwx\nfoo\ncat\n" @@ -619,7 +619,7 @@ public void testExecute_complex_sameFromAndToRegistry() @Test public void testExecute_complexProperties() throws InterruptedException, VerificationException, IOException { - String targetImage = dockerHost + ":5000/compleximage:maven" + System.nanoTime(); + String targetImage = dockerHost + ":5001/compleximage:maven" + System.nanoTime(); assertThat(buildAndRunComplex(targetImage, "pom-complex-properties.xml")) .isEqualTo( "Hello, world. An argument.\n1970-01-01T00:00:01Z\nrwxr-xr-x\nrwxrwxrwx\nfoo\ncat\n" @@ -640,11 +640,11 @@ public void testExecute_jibContainerizeSkips() throws VerificationException, IOE @Test public void testExecute_jibRequireVersion_ok() throws VerificationException, IOException { - String targetImage = dockerHost + ":5000/simpleimage:maven" + System.nanoTime(); + String targetImage = dockerHost + ":5001/simpleimage:maven" + System.nanoTime(); Verifier verifier = new Verifier(simpleTestProject.getProjectRoot().toString()); verifier.setSystemProperty("_TARGET_IMAGE", targetImage); - // properties required to push to :5000 for plain pom.xml + // properties required to push to :5001 for plain pom.xml verifier.setSystemProperty("jib.to.auth.username", "testuser"); verifier.setSystemProperty("jib.to.auth.password", "testpassword"); verifier.setSystemProperty("sendCredentialsOverHttp", "true"); @@ -714,7 +714,7 @@ public void testExecute_springBootPackaged() @Test public void testExecute_multiPlatformBuild() throws IOException, VerificationException, RegistryException { - String targetImage = dockerHost + ":5000/multiplatform:maven" + System.nanoTime(); + String targetImage = dockerHost + ":5001/multiplatform:maven" + System.nanoTime(); Verifier verifier = new Verifier(simpleTestProject.getProjectRoot().toString()); verifier.setSystemProperty("_TARGET_IMAGE", targetImage); @@ -732,7 +732,7 @@ public void testExecute_multiPlatformBuild() FailoverHttpClient httpClient = new FailoverHttpClient(true, true, ignored -> {}); RegistryClient registryClient = RegistryClient.factory( - EventHandlers.NONE, dockerHost + ":5000", "multiplatform", httpClient) + EventHandlers.NONE, dockerHost + ":5001", "multiplatform", httpClient) .setCredential(Credential.from("testuser", "testpassword")) .newRegistryClient(); registryClient.configureBasicAuth(); diff --git a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/MavenProjectPropertiesTest.java b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/MavenProjectPropertiesTest.java index 5bbceaf3b9c..81513181744 100644 --- a/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/MavenProjectPropertiesTest.java +++ b/jib-maven-plugin/src/test/java/com/google/cloud/tools/jib/maven/MavenProjectPropertiesTest.java @@ -576,6 +576,9 @@ public void testCreateContainerBuilder_noErrorIfWebInfLibDoesNotExist() @Test public void testCreateContainerBuilder_exceptionMessageHasPackageSuggestionIfProjectIsWar() throws IOException { + when(mockBuild.getDirectory()).thenReturn(Paths.get("/foo/bar").toString()); + when(mockBuild.getFinalName()).thenReturn("helloworld-1"); + String expectedMessage = "Obtaining project build output files failed; make sure you have " + "packaged your project before trying to build the image. (Did you accidentally run \"mvn clean " diff --git a/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/globalconfig/GlobalConfigTest.java b/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/globalconfig/GlobalConfigTest.java index e3247c9f1d7..b772766bc5f 100644 --- a/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/globalconfig/GlobalConfigTest.java +++ b/jib-plugins-common/src/test/java/com/google/cloud/tools/jib/plugins/common/globalconfig/GlobalConfigTest.java @@ -74,7 +74,7 @@ public void testReadConfig() throws IOException, InvalidGlobalConfigException { String json = "{\"disableUpdateCheck\":true, \"registryMirrors\":[" + "{ \"registry\": \"registry-1.docker.io\"," - + " \"mirrors\": [\"mirror.gcr.io\", \"localhost:5000\"] }," + + " \"mirrors\": [\"mirror.gcr.io\", \"localhost:5001\"] }," + "{ \"registry\": \"another.registry\", \"mirrors\": [\"another.mirror\"] }" + "]}"; Files.write(configDir.resolve("config.json"), json.getBytes(StandardCharsets.UTF_8)); @@ -86,7 +86,7 @@ public void testReadConfig() throws IOException, InvalidGlobalConfigException { "registry-1.docker.io", "mirror.gcr.io", "registry-1.docker.io", - "localhost:5000", + "localhost:5001", "another.registry", "another.mirror"); }