use of com.google.cloud.tools.jib.api.buildplan.FileEntry in project jib by GoogleContainerTools.
the class MavenProjectPropertiesTest method testCreateContainerBuilder_correctFiles.
@Test
public void testCreateContainerBuilder_correctFiles() throws URISyntaxException, IOException, InvalidImageReferenceException, CacheDirectoryCreationException {
ContainerBuilderLayers layers = new ContainerBuilderLayers(setUpBuildContext());
Path dependenciesPath = getResource("maven/application/dependencies");
Path applicationDirectory = getResource("maven/application");
assertThat(layers.dependenciesLayer.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(testRepository.artifactPathOnDisk("com.test", "dependency", "1.0.0"), dependenciesPath.resolve("more/dependency-1.0.0.jar"), dependenciesPath.resolve("another/one/dependency-1.0.0.jar"), dependenciesPath.resolve("libraryA.jar"), dependenciesPath.resolve("libraryB.jar"), dependenciesPath.resolve("library.jarC.jar"));
assertThat(layers.snapshotsLayer.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(testRepository.artifactPathOnDisk("com.test", "dependencyX", "1.0.0-SNAPSHOT"));
assertThat(layers.resourcesLayer.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(applicationDirectory.resolve("output/directory"), applicationDirectory.resolve("output/directory/somefile"), applicationDirectory.resolve("output/package"), applicationDirectory.resolve("output/resourceA"), applicationDirectory.resolve("output/resourceB"), applicationDirectory.resolve("output/world"));
assertThat(layers.classesLayer.getEntries()).comparingElementsUsing(SOURCE_FILE_OF).containsExactly(applicationDirectory.resolve("output/HelloWorld.class"), applicationDirectory.resolve("output/directory"), applicationDirectory.resolve("output/package"), applicationDirectory.resolve("output/package/some.class"), applicationDirectory.resolve("output/some.class"));
List<FileEntry> allFileEntries = new ArrayList<>();
allFileEntries.addAll(layers.dependenciesLayer.getEntries());
allFileEntries.addAll(layers.snapshotsLayer.getEntries());
allFileEntries.addAll(layers.resourcesLayer.getEntries());
allFileEntries.addAll(layers.classesLayer.getEntries());
Set<Instant> modificationTimes = allFileEntries.stream().map(FileEntry::getModificationTime).collect(Collectors.toSet());
assertThat(modificationTimes).containsExactly(EPOCH_PLUS_32);
}
use of com.google.cloud.tools.jib.api.buildplan.FileEntry 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();
}
use of com.google.cloud.tools.jib.api.buildplan.FileEntry 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();
}
use of com.google.cloud.tools.jib.api.buildplan.FileEntry in project jib-extensions by GoogleContainerTools.
the class JibLayerFilterExtension method extendContainerBuildPlan.
@Override
public ContainerBuildPlan extendContainerBuildPlan(ContainerBuildPlan buildPlan, Map<String, String> properties, Optional<Configuration> config, MavenData mavenData, 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);
ContainerBuildPlan newPlan = newPlanBuilder.build();
return config.get().isCreateParentDependencyLayers() ? moveParentDepsToNewLayers(newPlan, mavenData, logger) : newPlan;
}
use of com.google.cloud.tools.jib.api.buildplan.FileEntry in project jib-extensions by GoogleContainerTools.
the class JibOwnershipExtension method applyRulesToFileEntry.
private FileEntry applyRulesToFileEntry(FileEntry entry) {
String newOwnership = null;
for (Entry<PathMatcher, String> mapEntry : pathMatchers.entrySet()) {
PathMatcher matcher = mapEntry.getKey();
Path pathInContainer = Paths.get(entry.getExtractionPath().toString());
if (matcher.matches(pathInContainer)) {
newOwnership = mapEntry.getValue();
}
}
return newOwnership == null ? entry : new FileEntry(entry.getSourceFile(), entry.getExtractionPath(), entry.getPermissions(), entry.getModificationTime(), newOwnership);
}
Aggregations