Search in sources :

Example 6 with UncheckedIOException

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

the class ClientProcess method start.

/**
     * Call this to attempt to connect to the server.
     *
     * @param port where the server is listening. Since it launched this client, it should have either been passed to it on the command line or via a system property (-D).
     */
public void start(int port) {
    Socket clientSocket;
    try {
        clientSocket = new Socket((String) null, port);
        socketWrapper = new ObjectSocketWrapper(clientSocket);
        if (protocol.serverConnected(clientSocket)) {
            return;
        }
    } catch (IOException e) {
        throw new UncheckedIOException(String.format("Could not connect to GUI server at port %s.", port), e);
    }
    try {
        clientSocket.close();
        socketWrapper = null;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    throw new UncheckedIOException("GUI protocol failed to connect.");
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) Socket(java.net.Socket)

Example 7 with UncheckedIOException

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

the class AbstractGradleServerProtocol method extractInitScriptFile.

/**
     * If you do have an init script that's a resource, this will extract it based on the name and write it to a temporary file and delete it on exit.
     *
     * @param resourceClass the class associated with the resource
     * @param resourceName the name (minus extension or '.') of the resource
     */
protected File extractInitScriptFile(Class resourceClass, String resourceName) {
    File file = null;
    try {
        file = temporaryFileProvider.createTemporaryFile(resourceName, INIT_SCRIPT_EXTENSION);
    } catch (UncheckedIOException e) {
        logger.error("Creating init script file temp file", e);
        return null;
    }
    file.deleteOnExit();
    if (extractResourceAsFile(resourceClass, resourceName + INIT_SCRIPT_EXTENSION, file)) {
        return file;
    }
    logger.error("Internal error! Failed to extract init script for executing commands!");
    return null;
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) File(java.io.File)

Example 8 with UncheckedIOException

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

the class AbstractNamedFileSnapshotTaskStateChanges method buildSnapshots.

protected static ImmutableSortedMap<String, FileCollectionSnapshot> buildSnapshots(String taskName, FileCollectionSnapshotterRegistry snapshotterRegistry, String title, SortedSet<? extends TaskFilePropertySpec> fileProperties) {
    ImmutableSortedMap.Builder<String, FileCollectionSnapshot> builder = ImmutableSortedMap.naturalOrder();
    for (TaskFilePropertySpec propertySpec : fileProperties) {
        FileCollectionSnapshot result;
        try {
            FileCollectionSnapshotter snapshotter = snapshotterRegistry.getSnapshotter(propertySpec.getSnapshotter());
            result = snapshotter.snapshot(propertySpec.getPropertyFiles(), propertySpec.getCompareStrategy(), propertySpec.getSnapshotNormalizationStrategy());
        } catch (UncheckedIOException e) {
            throw new UncheckedIOException(String.format("Failed to capture snapshot of %s files for task '%s' property '%s' during up-to-date check.", title.toLowerCase(), taskName, propertySpec.getPropertyName()), e);
        }
        builder.put(propertySpec.getPropertyName(), result);
    }
    return builder.build();
}
Also used : FileCollectionSnapshot(org.gradle.api.internal.changedetection.state.FileCollectionSnapshot) TaskFilePropertySpec(org.gradle.api.internal.tasks.TaskFilePropertySpec) ImmutableSortedMap(com.google.common.collect.ImmutableSortedMap) UncheckedIOException(org.gradle.api.UncheckedIOException) FileCollectionSnapshotter(org.gradle.api.internal.changedetection.state.FileCollectionSnapshotter)

Example 9 with UncheckedIOException

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

the class FileToArchiveEntrySetTransformer method walk.

private ImmutableSet<ArchiveEntry> walk(InputStream archiveInputStream, ImmutableSet.Builder<ArchiveEntry> allEntries, ImmutableList<String> parentPaths) {
    ImmutableSet.Builder<ArchiveEntry> entries = ImmutableSet.builder();
    ZipInputStream zipStream = new ZipInputStream(archiveInputStream);
    try {
        ZipEntry entry = zipStream.getNextEntry();
        while (entry != null) {
            ArchiveEntry.Builder builder = new ArchiveEntry.Builder();
            builder.setParentPaths(parentPaths);
            builder.setPath(entry.getName());
            builder.setCrc(entry.getCrc());
            builder.setDirectory(entry.isDirectory());
            builder.setSize(entry.getSize());
            if (!builder.isDirectory() && (zipStream.available() == 1)) {
                boolean zipEntry;
                final BufferedInputStream bis = new BufferedInputStream(zipStream) {

                    @Override
                    public void close() throws IOException {
                    }
                };
                bis.mark(Integer.MAX_VALUE);
                zipEntry = new ZipInputStream(bis).getNextEntry() != null;
                bis.reset();
                if (zipEntry) {
                    ImmutableList<String> nextParentPaths = ImmutableList.<String>builder().addAll(parentPaths).add(entry.getName()).build();
                    ImmutableSet<ArchiveEntry> subEntries = walk(bis, allEntries, nextParentPaths);
                    builder.setSubEntries(subEntries);
                }
            }
            ArchiveEntry archiveEntry = builder.build();
            entries.add(archiveEntry);
            allEntries.add(archiveEntry);
            zipStream.closeEntry();
            entry = zipStream.getNextEntry();
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    } finally {
        IOUtils.closeQuietly(zipStream);
    }
    return entries.build();
}
Also used : ZipEntry(java.util.zip.ZipEntry) UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException) ZipInputStream(java.util.zip.ZipInputStream) ImmutableSet(com.google.common.collect.ImmutableSet)

Example 10 with UncheckedIOException

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

the class GUtil method loadProperties.

public static Properties loadProperties(URL url) {
    try {
        URLConnection uc = url.openConnection();
        uc.setUseCaches(false);
        return loadProperties(uc.getInputStream());
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException) URLConnection(java.net.URLConnection)

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