Search in sources :

Example 86 with FileEntriesLayer

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

the class JavaContainerBuilderHelperTest method testExtraDirectoryLayerConfiguration_includes.

@Test
public void testExtraDirectoryLayerConfiguration_includes() throws URISyntaxException, IOException {
    Path extraFilesDirectory = Paths.get(Resources.getResource("core/layer").toURI());
    FileEntriesLayer layerConfiguration = JavaContainerBuilderHelper.extraDirectoryLayerConfiguration(extraFilesDirectory, AbsoluteUnixPath.get("/"), Arrays.asList("**/bar", "**/*a*"), Collections.emptyList(), Collections.emptyMap(), (ignored1, ignored2) -> Instant.EPOCH);
    assertThat(layerConfiguration.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(extraFilesDirectory.resolve("a/b/bar"), extraFilesDirectory.resolve("c/cat"));
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Test(org.junit.Test)

Example 87 with FileEntriesLayer

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

the class JavaContainerBuilderHelperTest method testExtraDirectoryLayerConfiguration_globPermissions.

@Test
public void testExtraDirectoryLayerConfiguration_globPermissions() throws URISyntaxException, IOException {
    Path extraFilesDirectory = Paths.get(Resources.getResource("core/layer").toURI());
    Map<String, FilePermissions> permissionsMap = ImmutableMap.of("/a", FilePermissions.fromOctalString("123"), "/a/*", FilePermissions.fromOctalString("456"), "**/bar", FilePermissions.fromOctalString("765"));
    FileEntriesLayer fileEntriesLayer = JavaContainerBuilderHelper.extraDirectoryLayerConfiguration(extraFilesDirectory, AbsoluteUnixPath.get("/"), Collections.emptyList(), Collections.emptyList(), permissionsMap, (ignored1, ignored2) -> Instant.EPOCH);
    assertThat(fileEntriesLayer.getEntries()).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/a", "/a/b", "/a/b/bar", "/c", "/c/cat", "/foo");
    Map<AbsoluteUnixPath, FilePermissions> expectedPermissions = ImmutableMap.<AbsoluteUnixPath, FilePermissions>builder().put(AbsoluteUnixPath.get("/a"), FilePermissions.fromOctalString("123")).put(AbsoluteUnixPath.get("/a/b"), FilePermissions.fromOctalString("456")).put(AbsoluteUnixPath.get("/a/b/bar"), FilePermissions.fromOctalString("765")).put(AbsoluteUnixPath.get("/c"), FilePermissions.DEFAULT_FOLDER_PERMISSIONS).put(AbsoluteUnixPath.get("/c/cat"), FilePermissions.DEFAULT_FILE_PERMISSIONS).put(AbsoluteUnixPath.get("/foo"), FilePermissions.DEFAULT_FILE_PERMISSIONS).build();
    for (FileEntry entry : fileEntriesLayer.getEntries()) {
        assertThat(entry.getPermissions()).isEqualTo(expectedPermissions.get(entry.getExtractionPath()));
    }
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) FilePermissions(com.google.cloud.tools.jib.api.buildplan.FilePermissions) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) Test(org.junit.Test)

Example 88 with FileEntriesLayer

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

the class JavaContainerBuilderHelperTest method testFromExplodedWar.

@Test
public void testFromExplodedWar() throws URISyntaxException, IOException, InvalidImageReferenceException, CacheDirectoryCreationException {
    // Copy test files to a temporary directory that we can safely operate on
    Path resourceExplodedWar = Paths.get(Resources.getResource("plugins-common/exploded-war").toURI());
    FileOperations.copy(ImmutableList.of(resourceExplodedWar), temporaryFolder.getRoot().toPath());
    Path temporaryExplodedWar = temporaryFolder.getRoot().toPath().resolve("exploded-war");
    Files.createDirectories(temporaryExplodedWar.resolve("WEB-INF/classes/empty_dir"));
    Files.createFile(temporaryExplodedWar.resolve("WEB-INF/lib/project-dependency-1.0.0.jar"));
    Set<String> projectArtifacts = ImmutableSet.of("project-dependency-1.0.0.jar");
    JavaContainerBuilder javaContainerBuilder = JavaContainerBuilder.from(RegistryImage.named("base")).setAppRoot(AbsoluteUnixPath.get("/my/app"));
    JibContainerBuilder jibContainerBuilder = JavaContainerBuilderHelper.fromExplodedWar(javaContainerBuilder, temporaryExplodedWar, projectArtifacts);
    BuildContext buildContext = JibContainerBuilderTestHelper.toBuildContext(jibContainerBuilder, Containerizer.to(RegistryImage.named("target")).setExecutorService(MoreExecutors.newDirectExecutorService()));
    FileEntriesLayer resourcesLayerConfigurations = getLayerConfigurationByName(buildContext, LayerType.RESOURCES.getName());
    FileEntriesLayer classesLayerConfigurations = getLayerConfigurationByName(buildContext, LayerType.CLASSES.getName());
    FileEntriesLayer dependenciesLayerConfigurations = getLayerConfigurationByName(buildContext, LayerType.DEPENDENCIES.getName());
    FileEntriesLayer snapshotsLayerConfigurations = getLayerConfigurationByName(buildContext, LayerType.SNAPSHOT_DEPENDENCIES.getName());
    FileEntriesLayer projectDependenciesLayerConfigurations = getLayerConfigurationByName(buildContext, LayerType.PROJECT_DEPENDENCIES.getName());
    assertThat(projectDependenciesLayerConfigurations.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(temporaryExplodedWar.resolve("WEB-INF/lib/project-dependency-1.0.0.jar"));
    assertThat(dependenciesLayerConfigurations.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(temporaryExplodedWar.resolve("WEB-INF/lib/dependency-1.0.0.jar"));
    assertThat(snapshotsLayerConfigurations.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(temporaryExplodedWar.resolve("WEB-INF/lib/dependencyX-1.0.0-SNAPSHOT.jar"));
    assertThat(resourcesLayerConfigurations.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(temporaryExplodedWar.resolve("META-INF"), temporaryExplodedWar.resolve("META-INF/context.xml"), temporaryExplodedWar.resolve("Test.jsp"), temporaryExplodedWar.resolve("WEB-INF"), temporaryExplodedWar.resolve("WEB-INF/classes"), temporaryExplodedWar.resolve("WEB-INF/classes/empty_dir"), temporaryExplodedWar.resolve("WEB-INF/classes/package"), temporaryExplodedWar.resolve("WEB-INF/classes/package/test.properties"), temporaryExplodedWar.resolve("WEB-INF/lib"), temporaryExplodedWar.resolve("WEB-INF/web.xml"));
    assertThat(classesLayerConfigurations.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(temporaryExplodedWar.resolve("WEB-INF/classes/HelloWorld.class"), temporaryExplodedWar.resolve("WEB-INF/classes/empty_dir"), temporaryExplodedWar.resolve("WEB-INF/classes/package"), temporaryExplodedWar.resolve("WEB-INF/classes/package/Other.class"));
    assertThat(dependenciesLayerConfigurations.getEntries()).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/my/app/WEB-INF/lib/dependency-1.0.0.jar");
    assertThat(snapshotsLayerConfigurations.getEntries()).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/my/app/WEB-INF/lib/dependencyX-1.0.0-SNAPSHOT.jar");
    assertThat(resourcesLayerConfigurations.getEntries()).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/my/app/META-INF", "/my/app/META-INF/context.xml", "/my/app/Test.jsp", "/my/app/WEB-INF", "/my/app/WEB-INF/classes", "/my/app/WEB-INF/classes/empty_dir", "/my/app/WEB-INF/classes/package", "/my/app/WEB-INF/classes/package/test.properties", "/my/app/WEB-INF/lib", "/my/app/WEB-INF/web.xml");
    assertThat(classesLayerConfigurations.getEntries()).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/my/app/WEB-INF/classes/HelloWorld.class", "/my/app/WEB-INF/classes/empty_dir", "/my/app/WEB-INF/classes/package", "/my/app/WEB-INF/classes/package/Other.class");
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) BuildContext(com.google.cloud.tools.jib.configuration.BuildContext) JavaContainerBuilder(com.google.cloud.tools.jib.api.JavaContainerBuilder) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) JibContainerBuilder(com.google.cloud.tools.jib.api.JibContainerBuilder) Test(org.junit.Test)

Example 89 with FileEntriesLayer

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

the class JavaContainerBuilderHelperTest method testExtraDirectoryLayerConfiguration_excludes.

@Test
public void testExtraDirectoryLayerConfiguration_excludes() throws URISyntaxException, IOException {
    Path extraFilesDirectory = Paths.get(Resources.getResource("core/layer").toURI());
    FileEntriesLayer layerConfiguration = JavaContainerBuilderHelper.extraDirectoryLayerConfiguration(extraFilesDirectory, AbsoluteUnixPath.get("/"), Collections.emptyList(), Arrays.asList("**/bar", "**/*a*"), Collections.emptyMap(), (ignored1, ignored2) -> Instant.EPOCH);
    assertThat(layerConfiguration.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(extraFilesDirectory.resolve("a"), extraFilesDirectory.resolve("a/b"), extraFilesDirectory.resolve("c"), extraFilesDirectory.resolve("foo"));
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Test(org.junit.Test)

Example 90 with FileEntriesLayer

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

the class JavaContainerBuilderHelperTest method testExtraDirectoryLayerConfiguration_includesAndExcludes.

@Test
public void testExtraDirectoryLayerConfiguration_includesAndExcludes() throws URISyntaxException, IOException {
    Path extraFilesDirectory = Paths.get(Resources.getResource("core/layer").toURI());
    FileEntriesLayer layerConfiguration = JavaContainerBuilderHelper.extraDirectoryLayerConfiguration(extraFilesDirectory, AbsoluteUnixPath.get("/"), Arrays.asList("**/*a*", "a"), Arrays.asList("**/*c*"), Collections.emptyMap(), (ignored1, ignored2) -> Instant.EPOCH);
    assertThat(layerConfiguration.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(extraFilesDirectory.resolve("a"), extraFilesDirectory.resolve("a/b/bar"));
}
Also used : Path(java.nio.file.Path) AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Test(org.junit.Test)

Aggregations

FileEntriesLayer (com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer)154 Test (org.junit.Test)111 Path (java.nio.file.Path)92 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)85 ContainerBuildPlan (com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)55 List (java.util.List)29 IOException (java.io.IOException)26 ArrayList (java.util.ArrayList)26 JibContainerBuilder (com.google.cloud.tools.jib.api.JibContainerBuilder)24 FileEntry (com.google.cloud.tools.jib.api.buildplan.FileEntry)23 Map (java.util.Map)23 Files (java.nio.file.Files)21 Predicate (java.util.function.Predicate)20 Platform (com.google.cloud.tools.jib.api.buildplan.Platform)16 Collectors (java.util.stream.Collectors)16 FilePermissions (com.google.cloud.tools.jib.api.buildplan.FilePermissions)13 Paths (java.nio.file.Paths)13 Optional (java.util.Optional)13 JavaContainerBuilder (com.google.cloud.tools.jib.api.JavaContainerBuilder)12 JibPluginExtensionException (com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException)12