Search in sources :

Example 36 with JibPluginExtensionException

use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException in project jib-extensions by GoogleContainerTools.

the class JibLayerFilterExtensionTest method testExtendContainerBuildPlan_createParentLayers_noProjectDependenciesResolver.

@Test
public void testExtendContainerBuildPlan_createParentLayers_noProjectDependenciesResolver() {
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().build();
    when(config.isCreateParentDependencyLayers()).thenReturn(true);
    try {
        new JibLayerFilterExtension().extendContainerBuildPlan(buildPlan, null, Optional.of(config), mavenData, logger);
        fail();
    } catch (JibPluginExtensionException ex) {
        assertEquals(JibLayerFilterExtension.class, ex.getExtensionClass());
        assertEquals("Try to get parent dependencies, but ProjectDependenciesResolver is null. Please use a " + "more recent Jib plugin version to fix this.", 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 37 with JibPluginExtensionException

use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException in project jib-extensions by GoogleContainerTools.

the class JibLayerFilterExtensionTest method testExtendContainerBuildPlan_noGlobGiven.

@Test
public void testExtendContainerBuildPlan_noGlobGiven() {
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().build();
    Configuration.Filter filter = mockFilter("", "doesn't matter");
    when(config.getFilters()).thenReturn(Arrays.asList(filter));
    try {
        new JibLayerFilterExtension().extendContainerBuildPlan(buildPlan, null, Optional.of(config), null, logger);
        fail();
    } catch (JibPluginExtensionException ex) {
        assertEquals(JibLayerFilterExtension.class, ex.getExtensionClass());
        assertEquals("glob pattern not given in filter 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 38 with JibPluginExtensionException

use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException in project jib-extensions by GoogleContainerTools.

the class JibLayerFilterExtensionTest method testExtendContainerBuildPlan_movingToExistingLayerNotAllowed.

@Test
public void testExtendContainerBuildPlan_movingToExistingLayerNotAllowed() {
    FileEntriesLayer layer = buildLayer("same layer name", Arrays.asList("/foo"));
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().addLayer(layer).build();
    Configuration.Filter filter = mockFilter("", "same layer name");
    when(config.getFilters()).thenReturn(Arrays.asList(filter));
    try {
        new JibLayerFilterExtension().extendContainerBuildPlan(buildPlan, null, Optional.of(config), null, logger);
        fail();
    } catch (JibPluginExtensionException ex) {
        assertEquals(JibLayerFilterExtension.class, ex.getExtensionClass());
        assertEquals("moving files into existing layer 'same layer name' is prohibited; specify a new layer " + "name in '<toLayer>'.", ex.getMessage());
    }
}
Also used : JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Example 39 with JibPluginExtensionException

use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException in project jib-extensions by GoogleContainerTools.

the class JibLayerFilterExtension method extendContainerBuildPlan.

@Override
public ContainerBuildPlan extendContainerBuildPlan(ContainerBuildPlan buildPlan, Map<String, String> properties, Optional<Configuration> config, GradleData gradleData, ExtensionLogger logger) throws JibPluginExtensionException {
    logger.log(LogLevel.LIFECYCLE, "Running Jib Layer Filter Extension");
    if (!config.isPresent()) {
        logger.log(LogLevel.WARN, "Nothing configured for Jib Layer Filter Extension");
        return buildPlan;
    }
    preparePathMatchersAndLayerBuilders(buildPlan, config.get());
    ContainerBuildPlan.Builder newPlanBuilder = buildPlan.toBuilder();
    newPlanBuilder.setLayers(Collections.emptyList());
    @SuppressWarnings("unchecked") List<FileEntriesLayer> originalLayers = (List<FileEntriesLayer>) buildPlan.getLayers();
    // Start filtering original layers.
    for (FileEntriesLayer layer : originalLayers) {
        List<FileEntry> filesToKeep = new ArrayList<>();
        for (FileEntry entry : layer.getEntries()) {
            Optional<String> finalLayerName = determineFinalLayerName(entry, layer.getName());
            // Either keep, move, or delete this FileEntry.
            if (finalLayerName.isPresent()) {
                if (finalLayerName.get().equals(layer.getName())) {
                    filesToKeep.add(entry);
                } else {
                    FileEntriesLayer.Builder targetLayerBuilder = Verify.verifyNotNull(newToLayers.get(finalLayerName.get()));
                    targetLayerBuilder.addEntry(entry);
                }
            }
        }
        if (!filesToKeep.isEmpty()) {
            newPlanBuilder.addLayer(layer.toBuilder().setEntries(filesToKeep).build());
        }
    }
    // Add newly created non-empty to-layers (if any).
    newToLayers.values().stream().map(FileEntriesLayer.Builder::build).filter(layer -> !layer.getEntries().isEmpty()).forEach(newPlanBuilder::addLayer);
    return newPlanBuilder.build();
}
Also used : GradleData(com.google.cloud.tools.jib.gradle.extension.GradleData) Verify(com.google.common.base.Verify) 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) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) List(java.util.List) LayerObject(com.google.cloud.tools.jib.api.buildplan.LayerObject) JibGradlePluginExtension(com.google.cloud.tools.jib.gradle.extension.JibGradlePluginExtension) Paths(java.nio.file.Paths) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) Map(java.util.Map) PathMatcher(java.nio.file.PathMatcher) Optional(java.util.Optional) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) VisibleForTesting(com.google.common.annotations.VisibleForTesting) Path(java.nio.file.Path) Collections(java.util.Collections) FileSystems(java.nio.file.FileSystems) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) ArrayList(java.util.ArrayList) ArrayList(java.util.ArrayList) List(java.util.List) FileEntry(com.google.cloud.tools.jib.api.buildplan.FileEntry) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)

Example 40 with JibPluginExtensionException

use of com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException in project jib-extensions by GoogleContainerTools.

the class JibLayerFilterExtensionTest method testExtendContainerBuildPlan_movingToExistingLayerNotAllowed.

@Test
public void testExtendContainerBuildPlan_movingToExistingLayerNotAllowed() {
    FileEntriesLayer layer = buildLayer("same layer name", Arrays.asList("/foo"));
    ContainerBuildPlan buildPlan = ContainerBuildPlan.builder().addLayer(layer).build();
    Configuration.Filter filter = mockFilter("", "same layer name");
    when(config.getFilters()).thenReturn(Arrays.asList(filter));
    try {
        new JibLayerFilterExtension().extendContainerBuildPlan(buildPlan, null, Optional.of(config), null, logger);
        fail();
    } catch (JibPluginExtensionException ex) {
        assertEquals(JibLayerFilterExtension.class, ex.getExtensionClass());
        assertEquals("moving files into existing layer 'same layer name' is prohibited; specify a new layer " + "name in 'filter.toLayer'.", ex.getMessage());
    }
}
Also used : JibPluginExtensionException(com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException) FileEntriesLayer(com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer) ContainerBuildPlan(com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan) Test(org.junit.Test)

Aggregations

JibPluginExtensionException (com.google.cloud.tools.jib.plugins.extension.JibPluginExtensionException)45 ContainerBuildPlan (com.google.cloud.tools.jib.api.buildplan.ContainerBuildPlan)22 Optional (java.util.Optional)20 Test (org.junit.Test)18 InvalidImageReferenceException (com.google.cloud.tools.jib.api.InvalidImageReferenceException)16 IOException (java.io.IOException)14 CacheDirectoryCreationException (com.google.cloud.tools.jib.api.CacheDirectoryCreationException)12 TempDirectoryProvider (com.google.cloud.tools.jib.filesystem.TempDirectoryProvider)12 BuildStepsExecutionException (com.google.cloud.tools.jib.plugins.common.BuildStepsExecutionException)12 ExtraDirectoryNotFoundException (com.google.cloud.tools.jib.plugins.common.ExtraDirectoryNotFoundException)12 IncompatibleBaseImageJavaVersionException (com.google.cloud.tools.jib.plugins.common.IncompatibleBaseImageJavaVersionException)12 InvalidAppRootException (com.google.cloud.tools.jib.plugins.common.InvalidAppRootException)12 InvalidContainerVolumeException (com.google.cloud.tools.jib.plugins.common.InvalidContainerVolumeException)12 InvalidContainerizingModeException (com.google.cloud.tools.jib.plugins.common.InvalidContainerizingModeException)12 InvalidCreationTimeException (com.google.cloud.tools.jib.plugins.common.InvalidCreationTimeException)12 InvalidFilesModificationTimeException (com.google.cloud.tools.jib.plugins.common.InvalidFilesModificationTimeException)12 InvalidPlatformException (com.google.cloud.tools.jib.plugins.common.InvalidPlatformException)12 InvalidWorkingDirectoryException (com.google.cloud.tools.jib.plugins.common.InvalidWorkingDirectoryException)12 MainClassInferenceException (com.google.cloud.tools.jib.plugins.common.MainClassInferenceException)12 GlobalConfig (com.google.cloud.tools.jib.plugins.common.globalconfig.GlobalConfig)12