Search in sources :

Example 31 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class SimpleVersionControlSystem method populate.

@Override
public File populate(File versionDir, VersionRef ref, VersionControlSpec spec) {
    File sourceDir = ((DirectoryRepositorySpec) spec).getSourceDir();
    File workingDir = new File(versionDir, sourceDir.getName());
    File checkoutFlag = new File(workingDir, "checkedout");
    try {
        if (!checkoutFlag.exists()) {
            GFileUtils.copyDirectory(sourceDir, workingDir);
            checkoutFlag.createNewFile();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return workingDir;
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) File(java.io.File) DirectoryRepositorySpec(org.gradle.vcs.internal.spec.DirectoryRepositorySpec)

Example 32 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class DefaultTaskExecutionPlan method canonicalizedPaths.

private static ImmutableSet<String> canonicalizedPaths(final Map<File, String> cache, Iterable<File> files) {
    ImmutableSet.Builder<String> builder = ImmutableSet.builder();
    for (File file : files) {
        String path;
        try {
            path = cache.get(file);
            if (path == null) {
                path = file.getCanonicalPath();
                cache.put(file, path);
            }
            builder.add(path);
        } catch (IOException e) {
            throw new UncheckedIOException(e);
        }
    }
    return builder.build();
}
Also used : ImmutableSet(com.google.common.collect.ImmutableSet) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) File(java.io.File)

Example 33 with UncheckedIOException

use of org.gradle.api.UncheckedIOException in project gradle by gradle.

the class DefaultScriptSourceHasher method hash.

@Override
public HashCode hash(ScriptSource scriptSource) {
    TextResource resource = scriptSource.getResource();
    File file = resource.getFile();
    if (file != null) {
        try {
            return fileHasher.hash(file);
        } catch (UncheckedIOException e) {
            if (e.getCause() instanceof FileNotFoundException) {
                throw new UncheckedIOException("Could not read " + scriptSource.getDisplayName() + " as it does not exist.", e.getCause());
            }
            throw e;
        }
    }
    Hasher hasher = contentHasherFactory.create();
    hasher.putString(resource.getText());
    return hasher.hash();
}
Also used : TextResource(org.gradle.internal.resource.TextResource) FileHasher(org.gradle.internal.hash.FileHasher) Hasher(org.gradle.internal.hash.Hasher) FileNotFoundException(java.io.FileNotFoundException) UncheckedIOException(org.gradle.api.UncheckedIOException) File(java.io.File)

Example 34 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 : IsolatableSerializedValueSnapshot(org.gradle.api.internal.changedetection.state.isolation.IsolatableSerializedValueSnapshot) UncheckedIOException(org.gradle.api.UncheckedIOException) ByteArrayOutputStream(java.io.ByteArrayOutputStream) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) ObjectOutputStream(java.io.ObjectOutputStream)

Example 35 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(String.format("Could not load properties for module '%s' from %s", name, jarFile), 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)

Aggregations

UncheckedIOException (org.gradle.api.UncheckedIOException)101 IOException (java.io.IOException)79 File (java.io.File)32 InputStream (java.io.InputStream)9 FileOutputStream (java.io.FileOutputStream)7 OutputStream (java.io.OutputStream)7 BufferedReader (java.io.BufferedReader)6 StringReader (java.io.StringReader)6 FileInputStream (java.io.FileInputStream)5 Matcher (java.util.regex.Matcher)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)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 ImmutableSortedMap (com.google.common.collect.ImmutableSortedMap)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 FileReader (java.io.FileReader)3