use of org.gradle.wrapper.Download in project gradle by gradle.
the class DistributionInstaller method withAsyncDownload.
private void withAsyncDownload(final URI address, final File destination, final OperationDescriptor operationDescriptor) throws Throwable {
currentListener.set(buildProgressListener);
try {
// Start the download in another thread and wait for the result
Thread thread = new Thread("Distribution download") {
@Override
public void run() {
try {
new Download(new Logger(false), new ForwardingDownloadProgressListener(operationDescriptor), APP_NAME, GradleVersion.current().getVersion()).download(address, destination);
} catch (Throwable t) {
synchronized (lock) {
failure = t;
}
} finally {
synchronized (lock) {
completed = true;
lock.notifyAll();
}
}
}
};
thread.setDaemon(true);
thread.start();
synchronized (lock) {
while (!completed && !cancelled) {
try {
lock.wait();
} catch (InterruptedException e) {
throw UncheckedException.throwAsUncheckedException(e);
}
}
if (failure != null) {
throw failure;
}
if (cancelled) {
// When cancelled, try to stop the download thread but don't attempt to wait for it to complete
// Could possibly loop here for a while trying to force the thread to exit
thread.interrupt();
throw new CancellationException();
}
}
} finally {
// The download thread may still be running. Ignore any further status events from it
currentListener.set(NO_OP);
}
}
Aggregations