use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class GccVersionDeterminer method transform.
private GccVersionResult transform(String output, File gccBinary) {
BufferedReader reader = new BufferedReader(new StringReader(output));
String line;
Map<String, String> defines = new HashMap<String, String>();
try {
while ((line = reader.readLine()) != null) {
Matcher matcher = DEFINE_PATTERN.matcher(line);
if (!matcher.matches()) {
return new BrokenResult(String.format("Could not determine %s version: %s produced unexpected output.", getDescription(), gccBinary.getName()));
}
defines.put(matcher.group(1), matcher.group(2));
}
} catch (IOException e) {
// Should not happen reading from a StringReader
throw new UncheckedIOException(e);
}
if (!defines.containsKey("__GNUC__")) {
return new BrokenResult(String.format("Could not determine %s version: %s produced unexpected output.", getDescription(), gccBinary.getName()));
}
int major;
int minor;
int patch;
if (clang) {
if (!defines.containsKey("__clang__")) {
return new BrokenResult(String.format("%s appears to be GCC rather than Clang. Treating it as GCC.", gccBinary.getName()));
}
major = toInt(defines.get("__clang_major__"));
minor = toInt(defines.get("__clang_minor__"));
patch = toInt(defines.get("__clang_patchlevel__"));
} else {
if (defines.containsKey("__clang__")) {
return new BrokenResult(String.format("XCode %s is a wrapper around Clang. Treating it as Clang and not GCC.", gccBinary.getName()));
}
major = toInt(defines.get("__GNUC__"));
minor = toInt(defines.get("__GNUC_MINOR__"));
patch = toInt(defines.get("__GNUC_PATCHLEVEL__"));
}
final ArchitectureInternal architecture = determineArchitecture(defines);
return new DefaultGccVersionResult(new VersionNumber(major, minor, patch, null), architecture, clang);
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class SerializedValueSnapshot method snapshot.
@Override
public ValueSnapshot snapshot(Object value, ValueSnapshotter snapshotter) {
ValueSnapshot snapshot = snapshotter.snapshot(value);
if (snapshot instanceof SerializedValueSnapshot) {
SerializedValueSnapshot newSnapshot = (SerializedValueSnapshot) snapshot;
if (!Objects.equal(implementationHash, newSnapshot.implementationHash)) {
// Different implementation - assume value has changed
return newSnapshot;
}
if (Arrays.equals(serializedValue, newSnapshot.serializedValue)) {
// Same serialized content - value has not changed
return this;
}
// Deserialize the old value and use the equals() implementation. This will be removed at some point
Object oldValue;
try {
oldValue = new ClassLoaderObjectInputStream(new ByteArrayInputStream(serializedValue), value.getClass().getClassLoader()).readObject();
} catch (Exception e) {
throw new UncheckedIOException(e);
}
if (oldValue.equals(value)) {
// Same value
return this;
}
}
return snapshot;
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class ValueSnapshotter method serialize.
private SerializedValueSnapshot serialize(Object value) {
ByteArrayOutputStream outputStream;
try {
outputStream = new ByteArrayOutputStream();
ObjectOutputStream objectStr = new ObjectOutputStream(outputStream);
objectStr.writeObject(value);
objectStr.flush();
} catch (IOException e) {
throw new UncheckedIOException(e);
}
return new SerializedValueSnapshot(classLoaderHasher.getClassLoaderHash(value.getClass().getClassLoader()), outputStream.toByteArray());
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class DefaultModuleRegistry method loadModuleProperties.
private Properties loadModuleProperties(String name, File jarFile) {
try {
ZipFile zipFile = new ZipFile(jarFile);
try {
final String entryName = name + "-classpath.properties";
ZipEntry entry = zipFile.getEntry(entryName);
if (entry == null) {
throw new IllegalStateException("Did not find " + entryName + " in " + jarFile.getAbsolutePath());
}
return GUtil.loadProperties(zipFile.getInputStream(entry));
} finally {
zipFile.close();
}
} catch (IOException e) {
throw new UncheckedIOException(e);
}
}
use of org.gradle.api.UncheckedIOException in project gradle by gradle.
the class DefaultZipCompressor method createArchiveOutputStream.
public ZipOutputStream createArchiveOutputStream(File destination) throws IOException {
ZipOutputStream outStream = new ZipOutputStream(destination);
try {
outStream.setUseZip64(zip64Mode);
outStream.setMethod(entryCompressionMethod);
return outStream;
} catch (Exception e) {
IOUtils.closeQuietly(outStream);
String message = String.format("Unable to create ZIP output stream for file %s.", destination);
throw new UncheckedIOException(message, e);
}
}
Aggregations