Search in sources :

Example 21 with UncheckedIOException

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);
}
Also used : HashMap(java.util.HashMap) Matcher(java.util.regex.Matcher) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException) VersionNumber(org.gradle.util.VersionNumber) ArchitectureInternal(org.gradle.nativeplatform.platform.internal.ArchitectureInternal)

Example 22 with UncheckedIOException

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;
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) UncheckedIOException(org.gradle.api.UncheckedIOException) ClassLoaderObjectInputStream(org.gradle.internal.io.ClassLoaderObjectInputStream) UncheckedIOException(org.gradle.api.UncheckedIOException)

Example 23 with UncheckedIOException

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());
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 24 with UncheckedIOException

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);
    }
}
Also used : ZipFile(java.util.zip.ZipFile) ZipEntry(java.util.zip.ZipEntry) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Example 25 with UncheckedIOException

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);
    }
}
Also used : ZipOutputStream(org.apache.tools.zip.ZipOutputStream) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Aggregations

UncheckedIOException (org.gradle.api.UncheckedIOException)82 IOException (java.io.IOException)60 File (java.io.File)25 InputStream (java.io.InputStream)7 OutputStream (java.io.OutputStream)6 FileOutputStream (java.io.FileOutputStream)5 FileInputStream (java.io.FileInputStream)4 URI (java.net.URI)4 URL (java.net.URL)4 ArrayList (java.util.ArrayList)4 Manifest (java.util.jar.Manifest)4 ZipInputStream (java.util.zip.ZipInputStream)4 FileVisitDetails (org.gradle.api.file.FileVisitDetails)4 FileVisitor (org.gradle.api.file.FileVisitor)4 ByteArrayInputStream (java.io.ByteArrayInputStream)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 FileReader (java.io.FileReader)3 URISyntaxException (java.net.URISyntaxException)3 Matcher (java.util.regex.Matcher)3 ZipEntry (java.util.zip.ZipEntry)3