Search in sources :

Example 1 with UncheckedException

use of org.gradle.internal.UncheckedException in project gradle by gradle.

the class StoppableExecutorImpl method stop.

public void stop(int timeoutValue, TimeUnit timeoutUnits) throws IllegalStateException {
    requestStop();
    if (executing.get() != null) {
        throw new IllegalStateException("Cannot stop this executor from an executor thread.");
    }
    try {
        if (!executor.awaitTermination(timeoutValue, timeoutUnits)) {
            executor.shutdownNow();
            throw new IllegalStateException("Timeout waiting for concurrent jobs to complete.");
        }
    } catch (InterruptedException e) {
        throw new UncheckedException(e);
    }
    executorPolicy.onStop();
}
Also used : UncheckedException(org.gradle.internal.UncheckedException)

Example 2 with UncheckedException

use of org.gradle.internal.UncheckedException in project gradle by gradle.

the class AsyncDispatch method dispatch.

public void dispatch(final T message) {
    lock.lock();
    try {
        while (state != State.Stopped && queue.size() >= maxQueueSize) {
            try {
                condition.await();
            } catch (InterruptedException e) {
                throw new UncheckedException(e);
            }
        }
        if (state == State.Stopped) {
            throw new IllegalStateException("Cannot dispatch message, as this message dispatch has been stopped. Message: " + message);
        }
        queue.add(message);
        condition.signalAll();
    } finally {
        lock.unlock();
    }
}
Also used : UncheckedException(org.gradle.internal.UncheckedException)

Example 3 with UncheckedException

use of org.gradle.internal.UncheckedException in project gradle by gradle.

the class AsyncDispatch method dispatchMessages.

private void dispatchMessages(Dispatch<? super T> dispatch) {
    while (true) {
        T message = null;
        lock.lock();
        try {
            while (state != State.Stopped && queue.isEmpty()) {
                try {
                    condition.await();
                } catch (InterruptedException e) {
                    throw new UncheckedException(e);
                }
            }
            if (!queue.isEmpty()) {
                message = queue.remove();
                condition.signalAll();
            }
        } finally {
            lock.unlock();
        }
        if (message == null) {
            // Have been stopped and nothing to deliver
            return;
        }
        dispatch.dispatch(message);
    }
}
Also used : UncheckedException(org.gradle.internal.UncheckedException)

Example 4 with UncheckedException

use of org.gradle.internal.UncheckedException in project gradle by gradle.

the class ManagedExecutorImpl method stop.

public void stop(int timeoutValue, TimeUnit timeoutUnits) throws IllegalStateException {
    requestStop();
    if (executing.get() != null) {
        throw new IllegalStateException("Cannot stop this executor from an executor thread.");
    }
    try {
        if (!executor.awaitTermination(timeoutValue, timeoutUnits)) {
            executor.shutdownNow();
            throw new IllegalStateException("Timeout waiting for concurrent jobs to complete.");
        }
    } catch (InterruptedException e) {
        throw new UncheckedException(e);
    }
    executorPolicy.onStop();
}
Also used : UncheckedException(org.gradle.internal.UncheckedException)

Example 5 with UncheckedException

use of org.gradle.internal.UncheckedException in project gradle by gradle.

the class ExceptionPlaceholder method read.

public Throwable read(Transformer<Class<?>, String> classNameTransformer, Transformer<ExceptionReplacingObjectInputStream, InputStream> objectInputStreamCreator) throws IOException {
    final List<Throwable> causes = recreateExceptions(this.causes, classNameTransformer, objectInputStreamCreator);
    final List<Throwable> suppressed = recreateExceptions(this.suppressed, classNameTransformer, objectInputStreamCreator);
    if (serializedException != null) {
        // try to deserialize the original exception
        final ExceptionReplacingObjectInputStream ois = objectInputStreamCreator.transform(new ByteArrayInputStream(serializedException));
        ois.setObjectTransformer(new Transformer<Object, Object>() {

            @Override
            public Object transform(Object obj) {
                if (obj instanceof NestedExceptionPlaceholder) {
                    NestedExceptionPlaceholder placeholder = (NestedExceptionPlaceholder) obj;
                    int index = placeholder.getIndex();
                    switch(placeholder.getKind()) {
                        case cause:
                            return causes.get(index);
                        case suppressed:
                            return suppressed.get(index);
                    }
                }
                return obj;
            }
        });
        try {
            return (Throwable) ois.readObject();
        } catch (ClassNotFoundException ignored) {
        // Don't log
        } catch (Throwable failure) {
            LOGGER.debug("Ignoring failure to de-serialize throwable.", failure);
        }
    }
    try {
        // try to reconstruct the exception
        Class<?> clazz = classNameTransformer.transform(type);
        if (clazz != null && causes.size() <= 1) {
            Constructor<?> constructor = clazz.getConstructor(String.class);
            Throwable reconstructed = (Throwable) constructor.newInstance(message);
            if (!causes.isEmpty()) {
                reconstructed.initCause(causes.get(0));
            }
            reconstructed.setStackTrace(convertStackTrace(stackTrace));
            registerSuppressedExceptions(suppressed, reconstructed);
            return reconstructed;
        }
    } catch (UncheckedException ignore) {
    // Don't log
    } catch (NoSuchMethodException ignored) {
    // Don't log
    } catch (Throwable ignored) {
        LOGGER.debug("Ignoring failure to recreate throwable.", ignored);
    }
    Throwable placeholder;
    if (causes.size() <= 1) {
        if (contextual) {
            // there are no @Contextual assertion errors in Gradle so we're safe to use this type only
            placeholder = new ContextualPlaceholderException(type, message, getMessageExec, toString, toStringRuntimeExec, causes.isEmpty() ? null : causes.get(0));
        } else {
            if (assertionError) {
                placeholder = new PlaceholderAssertionError(type, message, getMessageExec, toString, toStringRuntimeExec, causes.isEmpty() ? null : causes.get(0));
            } else {
                placeholder = new PlaceholderException(type, message, getMessageExec, toString, toStringRuntimeExec, causes.isEmpty() ? null : causes.get(0));
            }
        }
    } else {
        placeholder = new DefaultMultiCauseException(message, causes);
    }
    placeholder.setStackTrace(convertStackTrace(stackTrace));
    registerSuppressedExceptions(suppressed, placeholder);
    return placeholder;
}
Also used : DefaultMultiCauseException(org.gradle.internal.exceptions.DefaultMultiCauseException) UncheckedException(org.gradle.internal.UncheckedException) ByteArrayInputStream(java.io.ByteArrayInputStream)

Aggregations

UncheckedException (org.gradle.internal.UncheckedException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)1 DefaultMultiCauseException (org.gradle.internal.exceptions.DefaultMultiCauseException)1