use of org.gradle.api.internal.changedetection.state.RegularFileSnapshot in project gradle by gradle.
the class TarTaskOutputPacker method unpackPropertyEntry.
private void unpackPropertyEntry(ResolvedTaskOutputFilePropertySpec propertySpec, InputStream input, TarArchiveEntry entry, String childPath, boolean missing, ImmutableMultimap.Builder<String, FileSnapshot> fileSnapshots) throws IOException {
File propertyRoot = propertySpec.getOutputFile();
String propertyName = propertySpec.getPropertyName();
if (propertyRoot == null) {
throw new IllegalStateException("Optional property should have a value: " + propertyName);
}
File outputFile;
boolean isDirEntry = entry.isDirectory();
boolean root = Strings.isNullOrEmpty(childPath);
if (root) {
// We are handling the root of the property here
if (missing) {
if (!makeDirectory(propertyRoot.getParentFile())) {
// Make sure output is removed if it exists already
if (propertyRoot.exists()) {
FileUtils.forceDelete(propertyRoot);
}
}
return;
}
OutputType outputType = propertySpec.getOutputType();
if (isDirEntry) {
if (outputType != OutputType.DIRECTORY) {
throw new IllegalStateException("Property should be an output directory property: " + propertyName);
}
} else {
if (outputType == OutputType.DIRECTORY) {
throw new IllegalStateException("Property should be an output file property: " + propertyName);
}
}
ensureDirectoryForProperty(outputType, propertyRoot);
outputFile = propertyRoot;
} else {
outputFile = new File(propertyRoot, childPath);
}
String internedPath = stringInterner.intern(outputFile.getAbsolutePath());
RelativePath relativePath = root ? RelativePath.parse(!isDirEntry, outputFile.getName()) : RelativePath.parse(!isDirEntry, childPath);
if (isDirEntry) {
FileUtils.forceMkdir(outputFile);
fileSnapshots.put(propertyName, new DirectoryFileSnapshot(internedPath, relativePath, root));
} else {
OutputStream output = new FileOutputStream(outputFile);
HashCode hash;
try {
hash = streamHasher.hashCopy(input, output);
} finally {
IOUtils.closeQuietly(output);
}
FileHashSnapshot contentSnapshot = new FileHashSnapshot(hash, outputFile.lastModified());
fileSnapshots.put(propertyName, new RegularFileSnapshot(internedPath, relativePath, root, contentSnapshot));
}
fileSystem.chmod(outputFile, entry.getMode() & FILE_PERMISSION_MASK);
}
Aggregations