Search in sources :

Example 66 with UncheckedIOException

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

the class ClasspathVersionSource method create.

public Properties create() {
    URL resource = classLoader.getResource(resourceName);
    if (resource == null) {
        throw new RuntimeException("Unable to find the released versions information.\n" + "The resource '" + resourceName + "' was not found.\n" + "Most likely, you haven't run the 'prepareVersionsInfo' task.\n" + "If you have trouble running tests from your IDE, please run gradlew idea|eclipse first.");
    }
    try {
        Properties properties = new Properties();
        InputStream stream = resource.openStream();
        try {
            properties.load(stream);
        } finally {
            stream.close();
        }
        return properties;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : InputStream(java.io.InputStream) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) Properties(java.util.Properties) URL(java.net.URL)

Example 67 with UncheckedIOException

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

the class CyclicBarrierHttpServer method start.

void start() {
    // Note: this is implemented using raw sockets. Originally implemented using Jetty, but some concurrency problems there caused Jetty to hang
    try {
        serverSocket = ServerSocketChannel.open();
        serverSocket.socket().bind(new InetSocketAddress(0));
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    executor = Executors.newCachedThreadPool();
    executor.execute(new Runnable() {

        public void run() {
            int i = 0;
            while (true) {
                try {
                    SocketChannel connection;
                    try {
                        connection = serverSocket.accept();
                    } catch (AsynchronousCloseException e) {
                        // Socket has been closed, so we're stopping
                        return;
                    } catch (ClosedChannelException e) {
                        // Socket has been closed, so we're stopping
                        return;
                    }
                    try {
                        OutputStream outputStream = Channels.newOutputStream(connection);
                        System.out.println("Handle connection request no." + (++i));
                        handleConnection(outputStream);
                        outputStream.flush();
                    } finally {
                        connection.close();
                    }
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }

        private void handleConnection(OutputStream outputStream) throws IOException {
            System.out.println("Handling HTTP request");
            synchronized (lock) {
                if (connected) {
                    System.out.println("Received unexpected connection.");
                    outputStream.write("HTTP/1.1 500 Received an unexpected connection.\r\nConnection: close\r\nContent-length: 0\r\n\r\n".getBytes());
                    return;
                }
                System.out.println("Connection received");
                connected = true;
                lock.notifyAll();
                long expiry = monotonicClockMillis() + 30000;
                while (!released && !stopped) {
                    long delay = expiry - monotonicClockMillis();
                    if (delay <= 0) {
                        System.out.println("Timeout waiting for client to be released.");
                        outputStream.write("HTTP/1.1 500 Timeout waiting for client to be released.\r\nConnection: close\r\nContent-length: 0\r\n\r\n".getBytes());
                        return;
                    }
                    try {
                        lock.wait(delay);
                    } catch (InterruptedException e) {
                        throw new RuntimeException(e);
                    }
                }
                if (stopped) {
                    System.out.println("Releasing client on stop.");
                    outputStream.write("HTTP/1.1 500 Server stopped.\r\nConnection: close\r\nContent-length: 0\r\n\r\n".getBytes());
                    return;
                }
                connected = false;
                released = false;
                lock.notifyAll();
            }
            System.out.println("Sending response to client");
            outputStream.write("HTTP/1.1 200 Ok.\r\nConnection: close\r\nContent-length: 0\r\n\r\n".getBytes());
        }
    });
}
Also used : ServerSocketChannel(java.nio.channels.ServerSocketChannel) SocketChannel(java.nio.channels.SocketChannel) ClosedChannelException(java.nio.channels.ClosedChannelException) AsynchronousCloseException(java.nio.channels.AsynchronousCloseException) InetSocketAddress(java.net.InetSocketAddress) OutputStream(java.io.OutputStream) UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Example 68 with UncheckedIOException

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

the class ToolSearchPath method findExecutable.

private File findExecutable(OperatingSystem operatingSystem, String name) {
    List<File> path = pathEntries.isEmpty() ? operatingSystem.getPath() : pathEntries;
    String exeName = operatingSystem.getExecutableName(name);
    try {
        if (name.contains(File.separator)) {
            return maybeResolveFile(operatingSystem, new File(name), new File(exeName));
        }
        for (File pathEntry : path) {
            File resolved = maybeResolveFile(operatingSystem, new File(pathEntry, name), new File(pathEntry, exeName));
            if (resolved != null) {
                return resolved;
            }
        }
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
    return null;
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) UncheckedIOException(org.gradle.api.UncheckedIOException)

Example 69 with UncheckedIOException

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

the class PCHUtils method generatePCHSourceFile.

public static <T extends NativeCompileSpec> File generatePCHSourceFile(T original, File sourceFile) {
    File generatedSourceDir = new File(original.getTempDir(), "pchGenerated");
    generatedSourceDir.mkdirs();
    File generatedSource = new File(generatedSourceDir, FilenameUtils.removeExtension(sourceFile.getName()).concat(getSourceFileExtension(original.getClass())));
    File headerFileCopy = new File(generatedSourceDir, sourceFile.getName());
    try {
        FileUtils.copyFile(sourceFile, headerFileCopy);
        FileUtils.writeStringToFile(generatedSource, "#include \"".concat(headerFileCopy.getName()).concat("\""));
        return generatedSource;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) File(java.io.File)

Example 70 with UncheckedIOException

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

the class PCHUtils method generatePCHObjectDirectory.

public static File generatePCHObjectDirectory(File tempDir, File prefixHeaderFile, File preCompiledHeaderObjectFile) {
    File generatedDir = new File(tempDir, "preCompiledHeaders");
    generatedDir.mkdirs();
    File generatedHeader = new File(generatedDir, prefixHeaderFile.getName());
    File generatedPCH = new File(generatedDir, preCompiledHeaderObjectFile.getName());
    try {
        FileUtils.copyFile(prefixHeaderFile, generatedHeader);
        FileUtils.copyFile(preCompiledHeaderObjectFile, generatedPCH);
        return generatedDir;
    } catch (IOException e) {
        throw new UncheckedIOException(e);
    }
}
Also used : UncheckedIOException(org.gradle.api.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(org.gradle.api.UncheckedIOException) File(java.io.File)

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