Search in sources :

Example 1 with FileContentSnapshot

use of org.gradle.api.internal.changedetection.state.FileContentSnapshot in project gradle by gradle.

the class TarTaskOutputPacker method pack.

private long pack(Collection<ResolvedTaskOutputFilePropertySpec> propertySpecs, Map<String, Map<String, FileContentSnapshot>> outputSnapshots, TarArchiveOutputStream tarOutput) {
    long entries = 0;
    for (ResolvedTaskOutputFilePropertySpec propertySpec : propertySpecs) {
        String propertyName = propertySpec.getPropertyName();
        Map<String, FileContentSnapshot> outputs = outputSnapshots.get(propertyName);
        try {
            entries += packProperty(propertySpec, outputs, tarOutput);
        } catch (Exception ex) {
            throw new GradleException(String.format("Could not pack property '%s': %s", propertyName, ex.getMessage()), ex);
        }
    }
    return entries;
}
Also used : FileContentSnapshot(org.gradle.api.internal.changedetection.state.FileContentSnapshot) GradleException(org.gradle.api.GradleException) ResolvedTaskOutputFilePropertySpec(org.gradle.api.internal.tasks.ResolvedTaskOutputFilePropertySpec) UnsupportedEncodingException(java.io.UnsupportedEncodingException) IOException(java.io.IOException) GradleException(org.gradle.api.GradleException)

Example 2 with FileContentSnapshot

use of org.gradle.api.internal.changedetection.state.FileContentSnapshot in project gradle by gradle.

the class TarTaskOutputPacker method storeDirectoryProperty.

private long storeDirectoryProperty(String propertyPath, File directory, Map<String, FileContentSnapshot> outputSnapshots, final TarArchiveOutputStream tarOutput) throws IOException {
    if (!directory.isDirectory()) {
        throw new IllegalArgumentException(String.format("Expected '%s' to be a directory", directory));
    }
    long entries = 0;
    final String propertyRoot = propertyPath + "/";
    createTarEntry(propertyRoot, 0, UnixStat.DIR_FLAG | UnixStat.DEFAULT_DIR_PERM, tarOutput);
    tarOutput.closeArchiveEntry();
    entries++;
    String rootAbsolutePath = directory.getAbsolutePath();
    Path rootPath = directory.toPath();
    for (Map.Entry<String, FileContentSnapshot> entry : outputSnapshots.entrySet()) {
        String absolutePath = entry.getKey();
        // We've already created the directory for the property
        if (absolutePath.equals(rootAbsolutePath)) {
            continue;
        }
        File file = new File(absolutePath);
        String relativePath = rootPath.relativize(file.toPath()).toString();
        String targetPath = propertyRoot + relativePath;
        int mode = fileSystem.getUnixMode(file);
        switch(entry.getValue().getType()) {
            case RegularFile:
                storeFileEntry(file, targetPath, file.length(), mode, tarOutput);
                break;
            case Directory:
                storeDirectoryEntry(targetPath, mode, tarOutput);
                break;
            case Missing:
                throw new IllegalStateException("File should not be missing: " + file);
            default:
                throw new AssertionError();
        }
        entries++;
    }
    return entries;
}
Also used : Path(java.nio.file.Path) RelativePath(org.gradle.api.file.RelativePath) FileContentSnapshot(org.gradle.api.internal.changedetection.state.FileContentSnapshot) Map(java.util.Map) File(java.io.File)

Aggregations

FileContentSnapshot (org.gradle.api.internal.changedetection.state.FileContentSnapshot)2 File (java.io.File)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 Path (java.nio.file.Path)1 Map (java.util.Map)1 GradleException (org.gradle.api.GradleException)1 RelativePath (org.gradle.api.file.RelativePath)1 ResolvedTaskOutputFilePropertySpec (org.gradle.api.internal.tasks.ResolvedTaskOutputFilePropertySpec)1