Search in sources :

Example 51 with DirectoryWalker

use of com.google.cloud.tools.jib.filesystem.DirectoryWalker in project jib by GoogleContainerTools.

the class ZipUtil method preserveModificationTimes.

/**
 * Preserve modification time of files and directories in a zip file. If a directory is not an
 * entry in the zip file and reproducible timestamps are enabled then its modification timestamp
 * is set to a constant value.
 *
 * @param destination target root for unzipping
 * @param entries list of entries in zip file
 * @param enableReproducibleTimestamps whether or not reproducible timestamps should be used
 * @throws IOException when I/O error occurs
 */
private static void preserveModificationTimes(Path destination, List<ZipEntry> entries, boolean enableReproducibleTimestamps) throws IOException {
    if (enableReproducibleTimestamps) {
        FileTime epochPlusOne = FileTime.fromMillis(1000L);
        new DirectoryWalker(destination).filter(Files::isDirectory).walk(path -> Files.setLastModifiedTime(path, epochPlusOne));
    }
    for (ZipEntry entry : entries) {
        Files.setLastModifiedTime(destination.resolve(entry.getName()), entry.getLastModifiedTime());
    }
}
Also used : ZipEntry(java.util.zip.ZipEntry) DirectoryWalker(com.google.cloud.tools.jib.filesystem.DirectoryWalker) FileTime(java.nio.file.attribute.FileTime)

Example 52 with DirectoryWalker

use of com.google.cloud.tools.jib.filesystem.DirectoryWalker in project jib by GoogleContainerTools.

the class GradleProjectProperties method getClassFiles.

@Override
public List<Path> getClassFiles() throws IOException {
    // TODO: Consolidate with createJibContainerBuilder
    FileCollection classesOutputDirectories = getMainSourceSet().getOutput().getClassesDirs().filter(File::exists);
    List<Path> classFiles = new ArrayList<>();
    for (File classesOutputDirectory : classesOutputDirectories) {
        classFiles.addAll(new DirectoryWalker(classesOutputDirectory.toPath()).walk());
    }
    return classFiles;
}
Also used : Path(java.nio.file.Path) ArrayList(java.util.ArrayList) DirectoryWalker(com.google.cloud.tools.jib.filesystem.DirectoryWalker) FileCollection(org.gradle.api.file.FileCollection) File(java.io.File)

Aggregations

DirectoryWalker (com.google.cloud.tools.jib.filesystem.DirectoryWalker)52 Path (java.nio.file.Path)48 Test (org.junit.Test)23 Result (com.google.cloud.tools.jib.api.MainClassFinder.Result)20 AbsoluteUnixPath (com.google.cloud.tools.jib.api.buildplan.AbsoluteUnixPath)15 IOException (java.io.IOException)11 FileEntriesLayer (com.google.cloud.tools.jib.api.buildplan.FileEntriesLayer)9 Files (java.nio.file.Files)9 FileTime (java.nio.file.attribute.FileTime)8 List (java.util.List)8 Predicate (java.util.function.Predicate)8 Instant (java.time.Instant)7 Map (java.util.Map)7 ModificationTimeProvider (com.google.cloud.tools.jib.api.buildplan.ModificationTimeProvider)6 RelativeUnixPath (com.google.cloud.tools.jib.api.buildplan.RelativeUnixPath)6 InputStream (java.io.InputStream)6 Paths (java.nio.file.Paths)6 ArrayList (java.util.ArrayList)6 StringJoiner (java.util.StringJoiner)6 FilePermissions (com.google.cloud.tools.jib.api.buildplan.FilePermissions)5