use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class DefaultClasspathEntryHasher method hashJar.
private HashCode hashJar(FileDetails fileDetails, Hasher hasher, ClasspathContentHasher classpathContentHasher) {
File jarFilePath = new File(fileDetails.getPath());
ZipInputStream zipInput = null;
try {
zipInput = new ZipInputStream(new FileInputStream(jarFilePath));
ZipEntry zipEntry;
Multimap<String, HashCode> entriesByName = MultimapBuilder.hashKeys().arrayListValues().build();
while ((zipEntry = zipInput.getNextEntry()) != null) {
if (zipEntry.isDirectory()) {
continue;
}
HashCode hash = hashZipEntry(zipInput, zipEntry, classpathContentHasher);
if (hash != null) {
entriesByName.put(zipEntry.getName(), hash);
}
}
Map<String, Collection<HashCode>> map = entriesByName.asMap();
// Ensure we hash the zip entries in a deterministic order
String[] keys = map.keySet().toArray(new String[0]);
Arrays.sort(keys);
for (String key : keys) {
for (HashCode hash : map.get(key)) {
hasher.putBytes(hash.asBytes());
}
}
return hasher.hash();
} catch (ZipException e) {
// ZipExceptions point to a problem with the Zip, we try to be lenient for now.
return hashMalformedZip(fileDetails, hasher, classpathContentHasher);
} catch (IOException e) {
// IOExceptions other than ZipException are failures.
throw new UncheckedIOException("Error snapshotting jar [" + fileDetails.getName() + "]", e);
} catch (Exception e) {
// Other Exceptions can be thrown by invalid zips, too. See https://github.com/gradle/gradle/issues/1581.
return hashMalformedZip(fileDetails, hasher, classpathContentHasher);
} finally {
IOUtils.closeQuietly(zipInput);
}
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class DefaultTemporaryFileProvider method createTemporaryDirectory.
public File createTemporaryDirectory(@Nullable String prefix, @Nullable String suffix, @Nullable String... path) {
File dir = new File(baseDirFactory.create(), CollectionUtils.join("/", path));
GFileUtils.mkdirs(dir);
try {
// TODO: This is not a great paradigm for creating a temporary directory.
// See http://guava-libraries.googlecode.com/svn/tags/release08/javadoc/com/google/common/io/Files.html#createTempDir%28%29 for an alternative.
File tmpDir = File.createTempFile("gradle", "projectDir", dir);
tmpDir.delete();
tmpDir.mkdir();
return tmpDir;
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class FileNormaliser method normalise.
// normalizes a path in similar ways as File.getCanonicalFile(), except that it
// does NOT resolve symlinks (by design)
public File normalise(File file) {
try {
if (!file.isAbsolute()) {
throw new IllegalArgumentException(String.format("Cannot normalize a relative file: '%s'", file));
}
if (isWindowsOs) {
// on Windows, File.getCanonicalFile() doesn't resolve symlinks
return file.getCanonicalFile();
}
File candidate;
String filePath = file.getPath();
List<String> path = null;
if (isNormalisingRequiredForAbsolutePath(filePath)) {
path = splitAndNormalisePath(filePath);
String resolvedPath = CollectionUtils.join(File.separator, path);
boolean needLeadingSeparator = File.listRoots()[0].getPath().startsWith(File.separator);
if (needLeadingSeparator) {
resolvedPath = File.separator + resolvedPath;
}
candidate = new File(resolvedPath);
} else {
candidate = file;
}
// If the file system is case sensitive, we don't have to normalise it further
if (fileSystem.isCaseSensitive()) {
return candidate;
}
// Short-circuit the slower lookup method by using the canonical file
File canonical = candidate.getCanonicalFile();
if (candidate.getPath().equalsIgnoreCase(canonical.getPath())) {
return canonical;
}
// TODO - start resolving only from where the expected and canonical paths are different
if (path == null) {
path = splitAndNormalisePath(filePath);
}
return normaliseUnixPathIgnoringCase(path);
} catch (IOException e) {
throw new UncheckedIOException(String.format("Could not normalize path for file '%s'.", file), e);
}
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class FileTimeStampInspector method updateOnFinishBuild.
protected void updateOnFinishBuild() {
markerFile.getParentFile().mkdirs();
try {
FileOutputStream outputStream = new FileOutputStream(markerFile);
try {
outputStream.write(0);
} finally {
outputStream.close();
}
} catch (IOException e) {
throw new UncheckedIOException("Could not update " + markerFile, e);
}
lastBuildTimestamp = markerFile.lastModified();
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class DefaultTemplateBasedStartScriptGenerator method generateScript.
public void generateScript(JavaAppStartScriptGenerationDetails details, Writer destination) {
try {
Map<String, String> binding = bindingFactory.transform(details);
String scriptContent = generateStartScriptContentFromTemplate(binding);
destination.write(scriptContent);
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
Aggregations