org.gradle.internal.UncheckedException Java Examples
The following examples show how to use
org.gradle.internal.UncheckedException.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: DefaultCacheAccess.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
private void takeOwnership(String operationDisplayName) { lock.lock(); try { while (owner != null && owner != Thread.currentThread()) { try { condition.await(); } catch (InterruptedException e) { throw UncheckedException.throwAsUncheckedException(e); } } owner = Thread.currentThread(); operations.pushCacheAction(operationDisplayName); } finally { lock.unlock(); } }
Example #2
Source File: ServiceLifecycle.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public void stop() { lock.lock(); try { if (usages.containsKey(Thread.currentThread())) { throw new IllegalStateException(String.format("Cannot stop %s from a thread that is using it.", displayName)); } if (state == State.RUNNING) { state = State.STOPPING; } while (!usages.isEmpty()) { try { condition.await(); } catch (InterruptedException e) { throw UncheckedException.throwAsUncheckedException(e); } } if (state != State.STOPPED) { state = State.STOPPED; } } finally { lock.unlock(); } }
Example #3
Source File: AsyncDispatch.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
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(); } }
Example #4
Source File: DefaultExecutorFactory.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
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 { 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); } if (failure.get() != null) { throw UncheckedException.throwAsUncheckedException(failure.get()); } } finally { executors.remove(this); } }
Example #5
Source File: DefaultClassLoaderFactory.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
private ClassLoader doCreateIsolatedClassLoader(Collection<URL> classpath) { // This piece of ugliness copies the JAXP (ie XML API) provider, if any, from the system ClassLoader. Here's why: // // 1. When looking for a provider, JAXP looks for a service resource in the context ClassLoader, which is our isolated ClassLoader. If our classpath above does not contain a // provider, this returns null. If it does contain a provider, JAXP extracts the classname from the service resource. // 2. If not found, JAXP looks for a service resource in the system ClassLoader. This happens to include all the application classes specified on the classpath. If the application // classpath does not contain a provider, this returns null. If it does contain a provider, JAXP extracts the implementation classname from the service resource. // 3. If not found, JAXP uses a default classname // 4. JAXP attempts to load the provider using the context ClassLoader. which is our isolated ClassLoader. This is fine if the classname came from step 1 or 3. It blows up if the // classname came from step 2. // // So, as a workaround, locate and include the JAXP provider jar in the classpath for our isolated ClassLoader. // // Note that in practise, this is only triggered when running in our tests if (needJaxpImpl()) { try { classpath.add(ClasspathUtil.getClasspathForResource(ClassLoader.getSystemClassLoader(), "META-INF/services/javax.xml.parsers.SAXParserFactory").toURI().toURL()); } catch (MalformedURLException e) { throw UncheckedException.throwAsUncheckedException(e); } } return new URLClassLoader(classpath.toArray(new URL[classpath.size()]), ClassLoader.getSystemClassLoader().getParent()); }
Example #6
Source File: DefaultScriptCompilationHandler.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
private void wrapCompilationFailure(ScriptSource source, MultipleCompilationErrorsException e) { // Fix the source file name displayed in the error messages for (Object message : e.getErrorCollector().getErrors()) { if (message instanceof SyntaxErrorMessage) { try { SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage) message; Field sourceField = SyntaxErrorMessage.class.getDeclaredField("source"); sourceField.setAccessible(true); SourceUnit sourceUnit = (SourceUnit) sourceField.get(syntaxErrorMessage); Field nameField = SourceUnit.class.getDeclaredField("name"); nameField.setAccessible(true); nameField.set(sourceUnit, source.getDisplayName()); } catch (Exception failure) { throw UncheckedException.throwAsUncheckedException(failure); } } } SyntaxException syntaxError = e.getErrorCollector().getSyntaxError(0); Integer lineNumber = syntaxError == null ? null : syntaxError.getLine(); throw new ScriptCompilationException(String.format("Could not compile %s.", source.getDisplayName()), e, source, lineNumber); }
Example #7
Source File: AsyncDispatch.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
/** * Stops accepting new messages, and blocks until all queued messages have been dispatched. */ public void stop() { lock.lock(); try { setState(State.Stopped); while (dispatchers > 0) { condition.await(); } if (!queue.isEmpty()) { throw new IllegalStateException( "Cannot wait for messages to be dispatched, as there are no dispatch threads running."); } } catch (InterruptedException e) { throw new UncheckedException(e); } finally { lock.unlock(); } }
Example #8
Source File: TestResultSerializer.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public void read(Action<? super TestClassResult> visitor) { if (!isHasResults()) { return; } try { InputStream inputStream = new FileInputStream(resultsFile); try { Decoder decoder = new KryoBackedDecoder(inputStream); int version = decoder.readSmallInt(); if (version != RESULT_VERSION) { throw new IllegalArgumentException(String.format("Unexpected result file version %d found in %s.", version, resultsFile)); } readResults(decoder, visitor); } finally { inputStream.close(); } } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } }
Example #9
Source File: BlockingResultHandler.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public T getResult() { Object result; try { result = queue.take(); } catch (InterruptedException e) { throw UncheckedException.throwAsUncheckedException(e); } if (result instanceof Throwable) { throw UncheckedException.throwAsUncheckedException(attachCallerThreadStackTrace((Throwable) result)); } if (result == NULL) { return null; } return resultType.cast(result); }
Example #10
Source File: DefaultScriptCompilationHandler.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
private void wrapCompilationFailure(ScriptSource source, MultipleCompilationErrorsException e) { // Fix the source file name displayed in the error messages for (Object message : e.getErrorCollector().getErrors()) { if (message instanceof SyntaxErrorMessage) { try { SyntaxErrorMessage syntaxErrorMessage = (SyntaxErrorMessage) message; Field sourceField = SyntaxErrorMessage.class.getDeclaredField("source"); sourceField.setAccessible(true); SourceUnit sourceUnit = (SourceUnit) sourceField.get(syntaxErrorMessage); Field nameField = SourceUnit.class.getDeclaredField("name"); nameField.setAccessible(true); nameField.set(sourceUnit, source.getDisplayName()); } catch (Exception failure) { throw UncheckedException.throwAsUncheckedException(failure); } } } SyntaxException syntaxError = e.getErrorCollector().getSyntaxError(0); Integer lineNumber = syntaxError == null ? null : syntaxError.getLine(); throw new ScriptCompilationException(String.format("Could not compile %s.", source.getDisplayName()), e, source, lineNumber); }
Example #11
Source File: DefaultTaskInputs.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
private Object unwrap(Object value) { while (true) { if (value instanceof Callable) { Callable callable = (Callable) value; try { value = callable.call(); } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } } else if (value instanceof Closure) { Closure closure = (Closure) value; value = closure.call(); } else if (value instanceof FileCollection) { FileCollection fileCollection = (FileCollection) value; return fileCollection.getFiles(); } else { return value; } } }
Example #12
Source File: ServiceLifecycle.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public void stop() { lock.lock(); try { if (usages.containsKey(Thread.currentThread())) { throw new IllegalStateException(String.format("Cannot stop %s from a thread that is using it.", displayName)); } if (state == State.RUNNING) { state = State.STOPPING; } while (!usages.isEmpty()) { try { condition.await(); } catch (InterruptedException e) { throw UncheckedException.throwAsUncheckedException(e); } } if (state != State.STOPPED) { state = State.STOPPED; } } finally { lock.unlock(); } }
Example #13
Source File: InputForwarder.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public void stop() { lifecycleLock.lock(); try { if (!stopped) { try { disconnectableInput.close(); } catch (IOException e) { throw UncheckedException.throwAsUncheckedException(e); } forwardingExecuter.stop(); stopped = true; } } finally { lifecycleLock.unlock(); } }
Example #14
Source File: BlockingResultHandler.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public T getResult() { Object result; try { result = queue.take(); } catch (InterruptedException e) { throw UncheckedException.throwAsUncheckedException(e); } if (result instanceof Throwable) { throw UncheckedException.throwAsUncheckedException(attachCallerThreadStackTrace((Throwable) result)); } if (result == NULL) { return null; } return resultType.cast(result); }
Example #15
Source File: AsyncReceive.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
/** * Stops receiving new messages. Blocks until all queued messages have been delivered. */ public void stop() { lock.lock(); try { doRequestStop(); while (receivers > 0) { condition.await(); } setState(State.Stopped); } catch (InterruptedException e) { throw new UncheckedException(e); } finally { lock.unlock(); } }
Example #16
Source File: Jvm.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
/** * @param os the OS * @param suppliedJavaBase initial location to discover from. May be jdk or jre. */ Jvm(OperatingSystem os, File suppliedJavaBase) { this.os = os; if (suppliedJavaBase == null) { //discover based on what's in the sys. property try { this.javaBase = new File(System.getProperty("java.home")).getCanonicalFile(); } catch (IOException e) { throw new UncheckedException(e); } this.javaHome = findJavaHome(javaBase); this.javaVersion = JavaVersion.current(); this.userSupplied = false; } else { //precisely use what the user wants and validate strictly further on this.javaBase = suppliedJavaBase; this.javaHome = suppliedJavaBase; this.userSupplied = true; this.javaVersion = null; } }
Example #17
Source File: SocketConnection.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public SocketConnection(SocketChannel socket, MessageSerializer<T> serializer) { this.socket = socket; try { // NOTE: we use non-blocking IO as there is no reliable way when using blocking IO to shutdown reads while // keeping writes active. For example, Socket.shutdownInput() does not work on Windows. socket.configureBlocking(false); outstr = new SocketOutputStream(socket); instr = new SocketInputStream(socket); } catch (IOException e) { throw UncheckedException.throwAsUncheckedException(e); } InetSocketAddress localSocketAddress = (InetSocketAddress) socket.socket().getLocalSocketAddress(); localAddress = new SocketInetAddress(localSocketAddress.getAddress(), localSocketAddress.getPort()); InetSocketAddress remoteSocketAddress = (InetSocketAddress) socket.socket().getRemoteSocketAddress(); remoteAddress = new SocketInetAddress(remoteSocketAddress.getAddress(), remoteSocketAddress.getPort()); objectReader = serializer.newReader(instr, localAddress, remoteAddress); objectWriter = serializer.newWriter(outstr); }
Example #18
Source File: InProcessCompilerDaemonFactory.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public CompilerDaemon getDaemon(File workingDir, final DaemonForkOptions forkOptions) { return new CompilerDaemon() { public <T extends CompileSpec> CompileResult execute(Compiler<T> compiler, T spec) { ClassLoader groovyClassLoader = classLoaderFactory.createIsolatedClassLoader(new DefaultClassPath(forkOptions.getClasspath())); FilteringClassLoader filteredGroovy = classLoaderFactory.createFilteringClassLoader(groovyClassLoader); for (String packageName : forkOptions.getSharedPackages()) { filteredGroovy.allowPackage(packageName); } ClassLoader workerClassLoader = new MutableURLClassLoader(filteredGroovy, ClasspathUtil.getClasspath(compiler.getClass().getClassLoader())); try { byte[] serializedWorker = GUtil.serialize(new Worker<T>(compiler, spec)); ClassLoaderObjectInputStream inputStream = new ClassLoaderObjectInputStream(new ByteArrayInputStream(serializedWorker), workerClassLoader); Callable<?> worker = (Callable<?>) inputStream.readObject(); Object result = worker.call(); byte[] serializedResult = GUtil.serialize(result); inputStream = new ClassLoaderObjectInputStream(new ByteArrayInputStream(serializedResult), getClass().getClassLoader()); return (CompileResult) inputStream.readObject(); } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } } }; }
Example #19
Source File: AsyncDispatch.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
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(); } }
Example #20
Source File: XmlTransformer.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
private void doWriteTo(Writer writer, String encoding) { writeXmlDeclaration(writer, encoding); try { if (node != null) { printNode(node, writer); } else if (element != null) { printDomNode(element, writer); } else if (builder != null) { writer.append(TextUtil.toPlatformLineSeparators(stripXmlDeclaration(builder))); } else { writer.append(TextUtil.toPlatformLineSeparators(stripXmlDeclaration(stringValue))); } } catch (IOException e) { throw UncheckedException.throwAsUncheckedException(e); } }
Example #21
Source File: LazyConsumerActionExecutor.java From pushfish-android with BSD 2-Clause "Simplified" License | 6 votes |
public void stop() { ConsumerConnection connection = null; lock.lock(); try { stopped = true; while (!executing.isEmpty()) { try { condition.await(); } catch (InterruptedException e) { throw UncheckedException.throwAsUncheckedException(e); } } connection = this.connection; this.connection = null; } finally { lock.unlock(); } if (connection != null) { connection.stop(); } }
Example #22
Source File: XmlTransformer.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private void writeXmlDeclaration(Writer writer, String encoding) { try { writer.write("<?xml version=\"1.0\""); if (encoding != null) { writer.write(" encoding=\""); writer.write(encoding); writer.write("\""); } writer.write("?>"); writer.write(SystemProperties.getLineSeparator()); } catch (IOException e) { throw UncheckedException.throwAsUncheckedException(e); } }
Example #23
Source File: QueuingDispatch.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public void stop() { lock.lock(); try { while (queue != null && !queue.isEmpty()) { try { condition.await(); } catch (InterruptedException e) { throw UncheckedException.throwAsUncheckedException(e); } } } finally { lock.unlock(); } }
Example #24
Source File: DelayedReceive.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public T receive() { lock.lock(); try { while (true) { DelayedMessage message = queue.peek(); if (message == null && stopping) { return null; } if (message == null) { condition.await(); continue; } long now = timeProvider.getCurrentTime(); if (message.dispatchTime > now) { condition.awaitUntil(new Date(message.dispatchTime)); } else { queue.poll(); if (queue.isEmpty()) { condition.signalAll(); } return message.message; } } } catch (InterruptedException e) { throw UncheckedException.throwAsUncheckedException(e); } finally { lock.unlock(); } }
Example #25
Source File: AsyncDispatch.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
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); } }
Example #26
Source File: QueuingDispatch.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
public void stop() { lock.lock(); try { while (queue != null && !queue.isEmpty()) { try { condition.await(); } catch (InterruptedException e) { throw UncheckedException.throwAsUncheckedException(e); } } } finally { lock.unlock(); } }
Example #27
Source File: AsyncReceive.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private void receiveMessages(Receive<? extends T> receive) { while (true) { Dispatch<? super T> dispatch; lock.lock(); try { while (dispatches.isEmpty() && state == State.Init) { try { condition.await(); } catch (InterruptedException e) { throw UncheckedException.throwAsUncheckedException(e); } } if (state != State.Init) { return; } dispatch = dispatches.remove(0); } finally { lock.unlock(); } try { T message = receive.receive(); if (message == null) { return; } dispatch.dispatch(message); } finally { lock.lock(); try { dispatches.add(dispatch); condition.signalAll(); } finally { lock.unlock(); } } } }
Example #28
Source File: PlayWorkerServer.java From playframework with Apache License 2.0 | 5 votes |
@Override public void stop() { lock.lock(); try { stopRequested = true; events.put(PlayAppLifecycleUpdate.stopped()); } catch (InterruptedException e) { throw UncheckedException.throwAsUncheckedException(e); } finally { lock.unlock(); } }
Example #29
Source File: DefaultTaskExecutionPlan.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
private void rethrowFailures() { if (failures.isEmpty()) { return; } if (failures.size() > 1) { throw new MultipleBuildFailures(failures); } throw UncheckedException.throwAsUncheckedException(failures.get(0)); }
Example #30
Source File: ModuleVersionResolveException.java From pushfish-android with BSD 2-Clause "Simplified" License | 5 votes |
protected ModuleVersionResolveException createCopy() { try { return getClass().getConstructor(ModuleVersionSelector.class, String.class).newInstance(selector, messageFormat); } catch (Exception e) { throw UncheckedException.throwAsUncheckedException(e); } }