use of org.gradle.api.file.RelativePath in project gradle by gradle.
the class RelativePathTest method testConstructors.
@Test
public void testConstructors() {
RelativePath path;
path = new RelativePath(true, "one");
assertPathContains(path, true, "one");
path = new RelativePath(false, "one", "two");
assertPathContains(path, false, "one", "two");
}
use of org.gradle.api.file.RelativePath in project gradle by gradle.
the class RelativePathTest method appendNames.
@Test
public void appendNames() {
RelativePath childPath = new RelativePath(false, "one", "two").append(true, "three", "four");
assertPathContains(childPath, true, "one", "two", "three", "four");
childPath = new RelativePath(false, "one", "two").append(true);
assertPathContains(childPath, true, "one", "two");
}
use of org.gradle.api.file.RelativePath in project gradle by gradle.
the class CoffeeScriptCompileDestinationCalculator method transform.
public File transform(RelativePath relativePath) {
String sourceFileName = relativePath.getLastName();
String destinationFileNameBase = sourceFileName;
if (sourceFileName.endsWith(".coffee")) {
destinationFileNameBase = sourceFileName.substring(0, sourceFileName.length() - 7);
}
String destinationFileName = destinationFileNameBase + ".js";
RelativePath destinationRelativePath = relativePath.replaceLastName(destinationFileName);
return new File(destination, destinationRelativePath.getPathString());
}
use of org.gradle.api.file.RelativePath 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);
}
use of org.gradle.api.file.RelativePath 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;
}
Aggregations