Search in sources :

Example 46 with ContainerBuildPlan

use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib-extensions by GoogleContainerTools.

the class JibOwnershipExtensionTest method testExtendContainerBuildPlan_noGlobGiven.

@Test
public void testExtendContainerBuildPlan_noGlobGiven() {
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().build();
    Configuration.Rule rule = mockRule("", "doesn't matter");
    when(config.getRules()).thenReturn(Arrays.asList(rule));
    try {
        new JibOwnershipExtension().extendContainerBuildPlan(buildPlan, null, Optional.of(config), null, logger);
        fail();
    } catch (JibPluginExtensionException ex) {
        assertEquals(JibOwnershipExtension.class, ex.getExtensionClass());
        assertEquals("glob pattern not given in ownership configuration", ex.getMessage());
    }
}
Also used : JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 47 with ContainerBuildPlan

use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib-extensions by GoogleContainerTools.

the class JibSpringBootExtensionTest method testExtendContainerBuildPlan_noFiltering.

@Test
public void testExtendContainerBuildPlan_noFiltering() throws JibPluginExtensionException {
    // set up <excludeDevtools>false (no filtering required)
    Xpp3Dom configuration = new Xpp3Dom("configuration");
    Xpp3Dom excludeDevtools = new Xpp3Dom("excludeDevtools");
    excludeDevtools.setValue("false");
    configuration.addChild(excludeDevtools);
    when(project.getPlugin("org.springframework.boot:spring-boot-maven-plugin")).thenReturn(bootPlugin);
    when(bootPlugin.getConfiguration()).thenReturn(configuration);
    FileEntriesLayer layer1 = buildLayer("dependencies", Paths.get("spring-boot-devtools-1.2.3.jar"), Paths.get("archive").resolve("bar.zip"));
    FileEntriesLayer layer2 = buildLayer("NOT dependencies", Paths.get("spring-boot-devtools-1.2.3.jar"));
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().addLayer(layer1).addLayer(layer2).build();
    ContainerBuildPlan newPlan = new JibSpringBootExtension().extendContainerBuildPlan(buildPlan, null, Optional.empty(), mavenData, logger);
    assertSame(buildPlan, newPlan);
    verify(logger).log(LogLevel.INFO, "Keeping spring-boot-devtools (if any)");
}
Also used : Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 48 with ContainerBuildPlan

use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib by google.

the class PluginConfigurationProcessorTest method testEntrypoint_defaultNonWarPackaging.

@Test
public void testEntrypoint_defaultNonWarPackaging() throws IOException, InvalidImageReferenceException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
    when(projectProperties.isWarProject()).thenReturn(false);
    ContainerBuildPlan buildPlan = processCommonConfiguration();
    assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-cp", "/app/resources:/app/classes:/app/libs/*", "java.lang.Object").inOrder();
    ArgumentMatcher<LogEvent> isLogWarn = logEvent -> logEvent.getLevel() == LogEvent.Level.WARN;
    verify(logger, never()).accept(argThat(isLogWarn));
}
Also used : CredHelperConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.CredHelperConfiguration) Arrays(java.util.Arrays) ArgumentMatchers.argThat(org.mockito.ArgumentMatchers.argThat) URISyntaxException(java.net.URISyntaxException) FileTime(java.nio.file.attribute.FileTime) PlatformConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.PlatformConfiguration) JavaContainerBuilder(com.google.cloud.tools.jib.api.JavaContainerBuilder) ExtraDirectoriesConfiguration(com.google.cloud.tools.jib.plugins.common.RawConfiguration.ExtraDirectoriesConfiguration) Mockito.verifyNoInteractions(org.mockito.Mockito.verifyNoInteractions) ArgumentMatcher(org.mockito.ArgumentMatcher) JUnitParamsRunner(junitparams.JUnitParamsRunner) Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) JibContainerBuilderTestHelper(com.google.cloud.tools.jib.api.JibContainerBuilderTestHelper) FilePermissions(com.google.cloud.tools.jib.api.buildplan.FilePermissions) InvalidImageReferenceException(com.google.cloud.tools.jib.api.InvalidImageReferenceException) Instant(java.time.Instant) StandardCharsets(java.nio.charset.StandardCharsets) List(java.util.List) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) Optional(java.util.Optional) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Platform(com.google.cloud.tools.jib.api.buildplan.Platform) Parameters(junitparams.Parameters) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) ImageConfiguration(com.google.cloud.tools.jib.configuration.ImageConfiguration) Mock(org.mockito.Mock) Assert.assertThrows(org.junit.Assert.assertThrows) RegistryImage(com.google.cloud.tools.jib.api.RegistryImage) RunWith(org.junit.runner.RunWith) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Jib(com.google.cloud.tools.jib.api.Jib) CacheDirectoryCreationException(com.google.cloud.tools.jib.api.CacheDirectoryCreationException) ImmutableList(com.google.common.collect.ImmutableList) MockitoJUnit(org.mockito.junit.MockitoJUnit) Truth8.assertThat(com.google.common.truth.Truth8.assertThat) Nullable(javax.annotation.Nullable) Before(org.junit.Before) Answers(org.mockito.Answers) Resources(com.google.common.io.Resources) Files(java.nio.file.Files) IOException(java.io.IOException) Test(org.junit.Test) Mockito.when(org.mockito.Mockito.when) Truth.assertThat(com.google.common.truth.Truth.assertThat) ModificationTimeProvider(com.google.cloud.tools.jib.api.buildplan.ModificationTimeProvider) File(java.io.File) Mockito.verify(org.mockito.Mockito.verify) Correspondence(com.google.common.truth.Correspondence) Consumer(java.util.function.Consumer) LogEvent(com.google.cloud.tools.jib.api.LogEvent) Mockito(org.mockito.Mockito) Mockito.never(org.mockito.Mockito.never) Rule(org.junit.Rule) Containerizer(com.google.cloud.tools.jib.api.Containerizer) Paths(java.nio.file.Paths) DateTimeFormatter(java.time.format.DateTimeFormatter) RestoreSystemProperties(org.junit.contrib.java.lang.system.RestoreSystemProperties) MockitoRule(org.mockito.junit.MockitoRule) Collections(java.util.Collections) TemporaryFolder(org.junit.rules.TemporaryFolder) LogEvent(com.google.cloud.tools.jib.api.LogEvent) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 49 with ContainerBuildPlan

use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib by google.

the class PluginConfigurationProcessorTest method testEntrypoint_warningOnMainclass.

@Test
public void testEntrypoint_warningOnMainclass() throws InvalidImageReferenceException, IOException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
    when(rawConfiguration.getEntrypoint()).thenReturn(Optional.of(Arrays.asList("custom", "entrypoint")));
    when(rawConfiguration.getMainClass()).thenReturn(Optional.of("java.util.Object"));
    ContainerBuildPlan buildPlan = processCommonConfiguration();
    assertThat(buildPlan.getEntrypoint()).containsExactly("custom", "entrypoint").inOrder();
    verify(projectProperties).log(LogEvent.warn("mainClass, extraClasspath, jvmFlags, and expandClasspathDependencies are ignored " + "when entrypoint is specified"));
}
Also used : ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 50 with ContainerBuildPlan

use of com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan in project jib by google.

the class PluginConfigurationProcessorTest method testClasspathArgumentFile.

@Test
public void testClasspathArgumentFile() throws NumberFormatException, InvalidImageReferenceException, MainClassInferenceException, InvalidAppRootException, IOException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
    when(rawConfiguration.getExtraClasspath()).thenReturn(Collections.singletonList("/foo"));
    when(projectProperties.getMajorJavaVersion()).thenReturn(9);
    ContainerBuildPlan buildPlan = processCommonConfiguration();
    assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-cp", "@/app/jib-classpath-file", "java.lang.Object").inOrder();
    List<FileEntry> jvmArgFiles = getLayerEntries(buildPlan, "jvm arg files");
    assertThat(jvmArgFiles).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(appCacheDirectory.resolve("jib-classpath-file"), appCacheDirectory.resolve("jib-main-class-file"));
    assertThat(jvmArgFiles).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/app/jib-classpath-file", "/app/jib-main-class-file");
    String classpath = new String(Files.readAllBytes(appCacheDirectory.resolve("jib-classpath-file")), StandardCharsets.UTF_8);
    assertThat(classpath).isEqualTo("/foo:/app/resources:/app/classes:/app/libs/foo-1.jar:/app/libs/bar-2.jar");
    String mainClass = new String(Files.readAllBytes(appCacheDirectory.resolve("jib-main-class-file")), StandardCharsets.UTF_8);
    assertThat(mainClass).isEqualTo("java.lang.Object");
}
Also used : FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Aggregations

ContainerBuildPlan (com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)130 Test (org.junit.Test)120 FileEntriesLayer (com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer)61 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)38 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)26 Path (java.nio.file.Path)24 JibPluginExtensionException (com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException)22 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)21 FileEntry (com.google.cloud.tools.jib.api.buildplan.FileEntry)20 ImageConfiguration (com.google.cloud.tools.jib.configuration.ImageConfiguration)14 Collections (java.util.Collections)14 Optional (java.util.Optional)14 Paths (java.nio.file.Paths)13 List (java.util.List)13 InvalidImageReferenceException (com.google.cloud.tools.jib.api.InvalidImageReferenceException)12 JavaContainerBuilder (com.google.cloud.tools.jib.api.JavaContainerBuilder)11 Files (java.nio.file.Files)11 File (java.io.File)10 IOException (java.io.IOException)10 Parameters (junitparams.Parameters)10