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());
}
}
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());
}
}
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());
}
}
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();
}
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());
}
}
Aggregations