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);
}
}
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());
}
});
}
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;
}
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);
}
}
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);
}
}
Aggregations