Search in sources :

Example 66 with FileEntriesLayer

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

the class StandardExplodedProcessorTest method testCreateLayers_withoutClassPathInManifest.

@Test
public void testCreateLayers_withoutClassPathInManifest() throws IOException, URISyntaxException {
    Path standardJar = Paths.get(Resources.getResource(STANDARD_JAR_WITHOUT_CLASS_PATH_MANIFEST).toURI());
    Path destDir = temporaryFolder.newFolder().toPath();
    StandardExplodedProcessor standardExplodedModeProcessor = new StandardExplodedProcessor(standardJar, destDir, JAR_JAVA_VERSION);
    List<FileEntriesLayer> layers = standardExplodedModeProcessor.createLayers();
    assertThat(layers.size()).isEqualTo(2);
    FileEntriesLayer resourcesLayer = layers.get(0);
    FileEntriesLayer classesLayer = layers.get(1);
    // Validate resources layer.
    assertThat(resourcesLayer.getName()).isEqualTo("resources");
    List<AbsoluteUnixPath> actualResourcesPaths = resourcesLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList());
    assertThat(actualResourcesPaths).containsExactly(AbsoluteUnixPath.get("/app/explodedJar/META-INF/MANIFEST.MF"), AbsoluteUnixPath.get("/app/explodedJar/directory1/resource1.txt"), AbsoluteUnixPath.get("/app/explodedJar/directory2/directory3/resource2.sql"), AbsoluteUnixPath.get("/app/explodedJar/directory4/resource3.txt"), AbsoluteUnixPath.get("/app/explodedJar/resource4.sql"));
    // Validate classes layer.
    assertThat(classesLayer.getName()).isEqualTo("classes");
    List<AbsoluteUnixPath> actualClassesPaths = classesLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList());
    assertThat(actualClassesPaths).containsExactly(AbsoluteUnixPath.get("/app/explodedJar/class5.class"), AbsoluteUnixPath.get("/app/explodedJar/directory1/class1.class"), AbsoluteUnixPath.get("/app/explodedJar/directory1/class2.class"), AbsoluteUnixPath.get("/app/explodedJar/directory2/class4.class"), AbsoluteUnixPath.get("/app/explodedJar/directory2/directory3/class3.class"));
}
Also used : AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) 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 67 with FileEntriesLayer

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

the class StandardPackagedProcessorTest method testCreateLayers_withClassPathInManifest.

@Test
public void testCreateLayers_withClassPathInManifest() throws IOException, URISyntaxException {
    Path standardJar = Paths.get(Resources.getResource(STANDARD_JAR_WITH_CLASS_PATH_MANIFEST).toURI());
    StandardPackagedProcessor standardPackagedModeProcessor = new StandardPackagedProcessor(standardJar, JAR_JAVA_VERSION);
    List<FileEntriesLayer> layers = standardPackagedModeProcessor.createLayers();
    assertThat(layers.size()).isEqualTo(3);
    FileEntriesLayer nonSnapshotLayer = layers.get(0);
    FileEntriesLayer snapshotLayer = layers.get(1);
    FileEntriesLayer jarLayer = layers.get(2);
    // Validate dependencies layers.
    assertThat(nonSnapshotLayer.getName()).isEqualTo("dependencies");
    assertThat(nonSnapshotLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList())).isEqualTo(ImmutableList.of(AbsoluteUnixPath.get("/app/dependency1"), AbsoluteUnixPath.get("/app/dependency2"), AbsoluteUnixPath.get("/app/directory/dependency4")));
    assertThat(snapshotLayer.getName()).isEqualTo("snapshot dependencies");
    assertThat(snapshotLayer.getEntries().stream().map(FileEntry::getExtractionPath).collect(Collectors.toList())).isEqualTo(ImmutableList.of(AbsoluteUnixPath.get("/app/dependency3-SNAPSHOT-1.jar")));
    // Validate jar layer.
    assertThat(jarLayer.getName()).isEqualTo("jar");
    assertThat(jarLayer.getEntries().size()).isEqualTo(1);
    assertThat(jarLayer.getEntries().get(0).getExtractionPath()).isEqualTo(AbsoluteUnixPath.get("/app/standardJarWithClassPath.jar"));
}
Also used : AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Path(java.nio.file.Path) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Test(org.junit.Test)

Example 68 with FileEntriesLayer

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

the class StandardPackagedProcessorTest method testCreateLayers_emptyJar.

@Test
public void testCreateLayers_emptyJar() throws IOException, URISyntaxException {
    Path standardJar = Paths.get(Resources.getResource(STANDARD_JAR_EMPTY).toURI());
    StandardPackagedProcessor standardPackagedModeProcessor = new StandardPackagedProcessor(standardJar, JAR_JAVA_VERSION);
    List<FileEntriesLayer> layers = standardPackagedModeProcessor.createLayers();
    assertThat(layers.size()).isEqualTo(1);
    FileEntriesLayer jarLayer = layers.get(0);
    assertThat(jarLayer.getName()).isEqualTo("jar");
    assertThat(jarLayer.getEntries().size()).isEqualTo(1);
    assertThat(jarLayer.getEntries().get(0).getExtractionPath()).isEqualTo(AbsoluteUnixPath.get("/app/emptyStandardJar.jar"));
}
Also used : AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Path(java.nio.file.Path) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Test(org.junit.Test)

Example 69 with FileEntriesLayer

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

the class StandardWarExplodedProcessorTest method testCreateLayers_allLayers_correctExtractionPaths.

@Test
public void testCreateLayers_allLayers_correctExtractionPaths() throws IOException, URISyntaxException {
    // Prepare war file for test
    Path tempDirectory = temporaryFolder.getRoot().toPath();
    Path warContents = Paths.get(Resources.getResource("war/standard/allLayers").toURI());
    Path standardWar = zipUpDirectory(warContents, tempDirectory.resolve("standardWar.war"));
    Path explodedWarDestination = temporaryFolder.newFolder("exploded-war").toPath();
    StandardWarExplodedProcessor processor = new StandardWarExplodedProcessor(standardWar, explodedWarDestination, APP_ROOT);
    List<FileEntriesLayer> layers = processor.createLayers();
    assertThat(layers.size()).isEqualTo(4);
    FileEntriesLayer nonSnapshotLayer = layers.get(0);
    FileEntriesLayer snapshotLayer = layers.get(1);
    FileEntriesLayer resourcesLayer = layers.get(2);
    FileEntriesLayer classesLayer = layers.get(3);
    assertThat(nonSnapshotLayer.getEntries()).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/my/app/WEB-INF/lib/dependency-1.0.0.jar");
    assertThat(snapshotLayer.getEntries()).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/my/app/WEB-INF/lib/dependencyX-1.0.0-SNAPSHOT.jar");
    assertThat(resourcesLayer.getEntries()).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/my/app/META-INF/context.xml", "/my/app/Test.jsp", "/my/app/WEB-INF/web.xml", "/my/app/WEB-INF/classes/package/test.properties");
    assertThat(classesLayer.getEntries()).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/my/app/WEB-INF/classes/MyClass2.class", "/my/app/WEB-INF/classes/package/MyClass.class");
}
Also used : AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Path(java.nio.file.Path) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Test(org.junit.Test)

Example 70 with FileEntriesLayer

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

the class StandardWarExplodedProcessorTest method testCreateLayers_webInfLibDoesNotExist_correctExtractionPaths.

@Test
public void testCreateLayers_webInfLibDoesNotExist_correctExtractionPaths() throws IOException, URISyntaxException {
    // Prepare war file for test
    Path tempDirectory = temporaryFolder.getRoot().toPath();
    Path warContents = Paths.get(Resources.getResource("war/standard/noWebInfLib").toURI());
    Path standardWar = zipUpDirectory(warContents, tempDirectory.resolve("noDependenciesWar.war"));
    Path explodedWarDestination = temporaryFolder.newFolder("exploded-war").toPath();
    StandardWarExplodedProcessor processor = new StandardWarExplodedProcessor(standardWar, explodedWarDestination, APP_ROOT);
    List<FileEntriesLayer> layers = processor.createLayers();
    assertThat(layers.size()).isEqualTo(2);
    FileEntriesLayer resourcesLayer = layers.get(0);
    FileEntriesLayer classesLayer = layers.get(1);
    assertThat(resourcesLayer.getEntries()).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/my/app/META-INF/context.xml");
    assertThat(classesLayer.getEntries()).comparingElementsUsing(EXTRACTION_PATH_OF).containsExactly("/my/app/WEB-INF/classes/MyClass2.class", "/my/app/WEB-INF/classes/package/MyClass.class");
}
Also used : AbsoluteUnixPath(com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath) Path(java.nio.file.Path) 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