Search in sources :

Example 11 with ContainerBuildPlan

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

the class PluginConfigurationProcessorTest method testEntrypoint_warningOnExpandClasspathDependenciesForWar.

@Test
public void testEntrypoint_warningOnExpandClasspathDependenciesForWar() throws IOException, InvalidCreationTimeException, InvalidImageReferenceException, IncompatibleBaseImageJavaVersionException, InvalidPlatformException, InvalidContainerVolumeException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidFilesModificationTimeException, InvalidContainerizingModeException, ExtraDirectoryNotFoundException {
    when(rawConfiguration.getExpandClasspathDependencies()).thenReturn(true);
    when(projectProperties.isWarProject()).thenReturn(true);
    ContainerBuildPlan buildPlan = processCommonConfiguration();
    assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-jar", "/usr/local/jetty/start.jar").inOrder();
    verify(projectProperties).log(LogEvent.warn("mainClass, extraClasspath, jvmFlags, and expandClasspathDependencies " + "are ignored for WAR projects"));
}
Also used : ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 12 with ContainerBuildPlan

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

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)

Example 13 with ContainerBuildPlan

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

the class PluginConfigurationProcessorTest method testEntrypoint_warningOnJvmFlags.

@Test
public void testEntrypoint_warningOnJvmFlags() 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.getJvmFlags()).thenReturn(Collections.singletonList("jvmFlag"));
    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 14 with ContainerBuildPlan

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

the class PluginConfigurationProcessorTest method testEntrypoint_warningOnMainclassForWar.

@Test
public void testEntrypoint_warningOnMainclassForWar() throws IOException, InvalidCreationTimeException, InvalidImageReferenceException, IncompatibleBaseImageJavaVersionException, InvalidPlatformException, InvalidContainerVolumeException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidFilesModificationTimeException, InvalidContainerizingModeException, ExtraDirectoryNotFoundException {
    when(rawConfiguration.getMainClass()).thenReturn(Optional.of("java.util.Object"));
    when(projectProperties.isWarProject()).thenReturn(true);
    ContainerBuildPlan buildPlan = processCommonConfiguration();
    assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-jar", "/usr/local/jetty/start.jar").inOrder();
    verify(projectProperties).log(LogEvent.warn("mainClass, extraClasspath, jvmFlags, and expandClasspathDependencies " + "are ignored for WAR projects"));
}
Also used : ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 15 with ContainerBuildPlan

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

the class PluginConfigurationProcessorTest method testEntrypointClasspath_nonDefaultAppRoot.

@Test
public void testEntrypointClasspath_nonDefaultAppRoot() throws InvalidImageReferenceException, IOException, MainClassInferenceException, InvalidAppRootException, InvalidWorkingDirectoryException, InvalidPlatformException, InvalidContainerVolumeException, IncompatibleBaseImageJavaVersionException, NumberFormatException, InvalidContainerizingModeException, InvalidFilesModificationTimeException, InvalidCreationTimeException, ExtraDirectoryNotFoundException {
    when(rawConfiguration.getAppRoot()).thenReturn("/my/app");
    ContainerBuildPlan buildPlan = processCommonConfiguration();
    assertThat(buildPlan.getEntrypoint()).containsExactly("java", "-cp", "/my/app/resources:/my/app/classes:/my/app/libs/*", "java.lang.Object").inOrder();
}
Also used : 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