Search in sources :

Example 31 with FileEntriesLayer

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

the class JibSpringBootExtensionTest method testFilterOutDevtools_differentDependencyLayerName.

@Test
public void testFilterOutDevtools_differentDependencyLayerName() {
    FileEntriesLayer layer = buildLayer("NOT dependencies", Paths.get("lib").resolve("spring-boot-devtools-1.2.3.jar"), Paths.get("archive").resolve("bar.zip"));
    LayerObject newLayer = JibSpringBootExtension.filterOutDevtools(layer);
    assertSame(layer, newLayer);
    assertEquals(layer.getEntries(), ((FileEntriesLayer) newLayer).getEntries());
}
Also used : LayerObject(com.google.cloud.tools.jib.api.buildplan.LayerObject) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) Test(org.junit.Test)

Example 32 with FileEntriesLayer

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

the class JibSpringBootExtension method filterOutDevtools.

@VisibleForTesting
static LayerObject filterOutDevtools(LayerObject layerObject) {
    String dependencyLayerName = JavaContainerBuilder.LayerType.DEPENDENCIES.getName();
    if (!dependencyLayerName.equals(layerObject.getName())) {
        return layerObject;
    }
    FileEntriesLayer layer = (FileEntriesLayer) layerObject;
    Predicate<FileEntry> notDevtoolsJar = fileEntry -> !isDevtoolsJar(fileEntry.getSourceFile().toFile());
    List<FileEntry> newEntries = layer.getEntries().stream().filter(notDevtoolsJar).collect(Collectors.toList());
    return layer.toBuilder().setEntries(newEntries).build();
}
Also used : JibMavenPluginExtension(com.google.cloud.tools.jib.maven.extension.JibMavenPluginExtension) Predicate(java.util.function.Predicate) JavaContainerBuilder(com.google.cloud.tools.jib.api.JavaContainerBuilder) Xpp3Dom(org.codehaus.plexus.util.xml.Xpp3Dom) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) ExtensionLogger(com.google.cloud.tools.jib.plugins.extension.ExtensionLogger) JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) Collectors(java.util.stream.Collectors) LogLevel(com.google.cloud.tools.jib.plugins.extension.ExtensionLogger.LogLevel) File(java.io.File) List(java.util.List) Plugin(org.apache.maven.model.Plugin) LayerObject(com.google.cloud.tools.jib.api.buildplan.LayerObject) MavenProject(org.apache.maven.project.MavenProject) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) Map(java.util.Map) MavenData(com.google.cloud.tools.jib.maven.extension.MavenData) Optional(java.util.Optional) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) VisibleForTesting(com.google.common.annotations.VisibleForTesting) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) VisibleForTesting(com.google.common.annotations.VisibleForTesting)

Example 33 with FileEntriesLayer

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

the class JibLayerFilterExtensionTest method testExtendContainerBuildPlan_sameLayerNameInMultipleFilters.

@Test
public void testExtendContainerBuildPlan_sameLayerNameInMultipleFilters() throws JibPluginExtensionException {
    FileEntriesLayer layer = buildLayer("", Arrays.asList("/filter1", "/filter2", "/filter3", "/filter4", "/filter5"));
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().addLayer(layer).build();
    Configuration.Filter filter1 = mockFilter("/filter1", "foo");
    Configuration.Filter filter2 = mockFilter("/filter2", "same layer name");
    Configuration.Filter filter3 = mockFilter("/filter3", "bar");
    Configuration.Filter filter4 = mockFilter("/filter4", "same layer name");
    Configuration.Filter filter5 = mockFilter("/filter5", "baz");
    when(config.getFilters()).thenReturn(Arrays.asList(filter1, filter2, filter3, filter4, filter5));
    JibLayerFilterExtension extension = new JibLayerFilterExtension();
    ContainerBuildPlan newPlan = extension.extendContainerBuildPlan(buildPlan, null, Optional.of(config), null, logger);
    ArrayList<String> layerNames = new ArrayList<>(extension.newToLayers.keySet());
    assertEquals(Arrays.asList("foo", "same layer name", "bar", "baz"), layerNames);
    assertEquals(4, newPlan.getLayers().size());
    FileEntriesLayer newLayer1 = (FileEntriesLayer) newPlan.getLayers().get(0);
    FileEntriesLayer newLayer2 = (FileEntriesLayer) newPlan.getLayers().get(1);
    FileEntriesLayer newLayer3 = (FileEntriesLayer) newPlan.getLayers().get(2);
    FileEntriesLayer newLayer4 = (FileEntriesLayer) newPlan.getLayers().get(3);
    assertEquals("foo", newLayer1.getName());
    assertEquals("same layer name", newLayer2.getName());
    assertEquals("bar", newLayer3.getName());
    assertEquals("baz", newLayer4.getName());
    assertEquals(Arrays.asList("/filter1"), layerToExtractionPaths(newLayer1));
    assertEquals(Arrays.asList("/filter2", "/filter4"), layerToExtractionPaths(newLayer2));
    assertEquals(Arrays.asList("/filter3"), layerToExtractionPaths(newLayer3));
    assertEquals(Arrays.asList("/filter5"), layerToExtractionPaths(newLayer4));
}
Also used : FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) ArrayList(java.util.ArrayList) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 34 with FileEntriesLayer

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

the class JibLayerFilterExtensionTest method testExtendContainerBuildPlan_lastConfigWins.

@Test
public void testExtendContainerBuildPlan_lastConfigWins() throws JibPluginExtensionException {
    FileEntriesLayer layer = buildLayer("extra files", Arrays.asList("/foo"));
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().addLayer(layer).build();
    Configuration.Filter filter1 = mockFilter("**", "looser");
    Configuration.Filter filter2 = mockFilter("**", "winner");
    when(config.getFilters()).thenReturn(Arrays.asList(filter1, filter2));
    ContainerBuildPlan newPlan = new JibLayerFilterExtension().extendContainerBuildPlan(buildPlan, null, Optional.of(config), null, logger);
    assertEquals(1, newPlan.getLayers().size());
    FileEntriesLayer newLayer = (FileEntriesLayer) newPlan.getLayers().get(0);
    assertEquals("winner", newLayer.getName());
    assertEquals(layer.getEntries(), newLayer.getEntries());
}
Also used : FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 35 with FileEntriesLayer

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

the class JibLayerFilterExtensionTest method testExtendContainerBuildPlan_noMatches.

@Test
public void testExtendContainerBuildPlan_noMatches() throws JibPluginExtensionException {
    FileEntriesLayer layer1 = buildLayer("", Arrays.asList("/foo"));
    FileEntriesLayer layer2 = buildLayer("", Arrays.asList("/foo", "/bar"));
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().addLayer(layer1).addLayer(layer2).build();
    Configuration.Filter filter = mockFilter("nothing/matches", "");
    when(config.getFilters()).thenReturn(Arrays.asList(filter));
    ContainerBuildPlan newPlan = new JibLayerFilterExtension().extendContainerBuildPlan(buildPlan, null, Optional.of(config), null, logger);
    assertEquals(2, newPlan.getLayers().size());
    FileEntriesLayer newLayer1 = (FileEntriesLayer) newPlan.getLayers().get(0);
    FileEntriesLayer newLayer2 = (FileEntriesLayer) newPlan.getLayers().get(1);
    assertEquals("", newLayer1.getName());
    assertEquals("", newLayer2.getName());
    assertEquals(layer1.getEntries(), newLayer1.getEntries());
    assertEquals(layer2.getEntries(), newLayer2.getEntries());
}
Also used : FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) 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