Search in sources :

Example 1 with Logger

use of org.gradle.wrapper.Logger 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);
    }
}
Also used : CancellationException(java.util.concurrent.CancellationException) Logger(org.gradle.wrapper.Logger) ProgressLogger(org.gradle.internal.logging.progress.ProgressLogger) IDownload(org.gradle.wrapper.IDownload) Download(org.gradle.wrapper.Download)

Aggregations

CancellationException (java.util.concurrent.CancellationException)1 ProgressLogger (org.gradle.internal.logging.progress.ProgressLogger)1 Download (org.gradle.wrapper.Download)1 IDownload (org.gradle.wrapper.IDownload)1 Logger (org.gradle.wrapper.Logger)1