use of org.gradle.internal.logging.progress.ProgressLogger in project gradle by gradle.
the class DefaultBuildOperationExecutor method run.
@Override
public <T> T run(BuildOperationDetails operationDetails, Transformer<T, ? super BuildOperationContext> factory) {
OperationDetails operationBefore = currentOperation.get();
OperationDetails parent = operationDetails.getParent() != null ? (OperationDetails) operationDetails.getParent() : operationBefore;
OperationIdentifier parentId;
if (parent == null) {
parentId = null;
} else {
if (!parent.running.get()) {
throw new IllegalStateException(String.format("Cannot start operation (%s) as parent operation (%s) has already completed.", operationDetails.getDisplayName(), parent.operationDetails.getDisplayName()));
}
parentId = parent.id;
}
OperationIdentifier id = new OperationIdentifier(nextId.getAndIncrement());
OperationDetails currentOperation = new OperationDetails(parent, id, operationDetails);
currentOperation.running.set(true);
this.currentOperation.set(currentOperation);
try {
long startTime = timeProvider.getCurrentTime();
BuildOperationInternal operation = new BuildOperationInternal(id, parentId, operationDetails.getName(), operationDetails.getDisplayName(), operationDetails.getOperationDescriptor());
listener.started(operation, new OperationStartEvent(startTime));
T result = null;
Throwable failure = null;
BuildOperationContextImpl context = new BuildOperationContextImpl();
try {
ProgressLogger progressLogger;
if (operationDetails.getProgressDisplayName() != null) {
progressLogger = progressLoggerFactory.newOperation(DefaultBuildOperationExecutor.class);
progressLogger.setDescription(operationDetails.getDisplayName());
progressLogger.setShortDescription(operationDetails.getProgressDisplayName());
progressLogger.started();
} else {
progressLogger = null;
}
LOGGER.debug("Build operation '{}' started", operation.getDisplayName());
try {
result = factory.transform(context);
} finally {
if (progressLogger != null) {
progressLogger.completed();
}
}
if (parent != null && !parent.running.get()) {
throw new IllegalStateException(String.format("Parent operation (%s) completed before this operation (%s).", parent.operationDetails.getDisplayName(), operationDetails.getDisplayName()));
}
} catch (Throwable t) {
context.failed(t);
failure = t;
}
long endTime = timeProvider.getCurrentTime();
listener.finished(operation, new OperationResult(startTime, endTime, context.failure));
if (failure != null) {
throw UncheckedException.throwAsUncheckedException(failure);
}
LOGGER.debug("Build operation '{}' completed", operation.getDisplayName());
return result;
} finally {
this.currentOperation.set(operationBefore);
currentOperation.running.set(false);
}
}
use of org.gradle.internal.logging.progress.ProgressLogger in project gradle by gradle.
the class DistributionInstaller method withProgressLogging.
private void withProgressLogging(URI address, File destination, OperationDescriptor operationDescriptor) throws Throwable {
ProgressLogger progressLogger = progressLoggerFactory.newOperation(DistributionInstaller.class);
progressLogger.setDescription("Download " + address);
progressLogger.started();
try {
withAsyncDownload(address, destination, operationDescriptor);
} finally {
progressLogger.completed();
}
}
use of org.gradle.internal.logging.progress.ProgressLogger in project gradle by gradle.
the class ProgressLoggingConsumerActionExecutor method run.
public <T> T run(ConsumerAction<T> action) throws UnsupportedOperationException, IllegalStateException {
ConsumerOperationParameters parameters = action.getParameters();
ProgressListenerAdapter listener = new ProgressListenerAdapter(parameters.getProgressListener());
ListenerManager listenerManager = loggingProvider.getListenerManager();
listenerManager.addListener(listener);
try {
ProgressLogger progressLogger = loggingProvider.getProgressLoggerFactory().newOperation(ProgressLoggingConsumerActionExecutor.class);
progressLogger.setDescription("Build");
progressLogger.started();
try {
return actionExecutor.run(action);
} finally {
progressLogger.completed();
}
} finally {
listenerManager.removeListener(listener);
}
}
use of org.gradle.internal.logging.progress.ProgressLogger in project gradle by gradle.
the class JettyStop method stop.
@TaskAction
public void stop() {
if (getStopPort() == null) {
throw new InvalidUserDataException("Please specify a valid port");
}
if (getStopKey() == null) {
throw new InvalidUserDataException("Please specify a valid stopKey");
}
ProgressLogger progressLogger = getServices().get(ProgressLoggerFactory.class).newOperation(JettyStop.class).start("Stop Jetty server", "Stopping Jetty");
try {
Socket s = new Socket(InetAddress.getByName("127.0.0.1"), getStopPort());
s.setSoLinger(false, 0);
OutputStream out = s.getOutputStream();
out.write((getStopKey() + "\r\nstop\r\n").getBytes());
out.flush();
s.close();
} catch (ConnectException e) {
LOGGER.info("Jetty not running!");
} catch (Exception e) {
LOGGER.error("Exception during stopping", e);
} finally {
progressLogger.completed();
}
}
use of org.gradle.internal.logging.progress.ProgressLogger in project gradle by gradle.
the class DependencyResolutionLogger method afterResolve.
public void afterResolve(ResolvableDependencies dependencies) {
LinkedList<ProgressLogger> loggers = progressLoggers.get();
if (loggers.isEmpty()) {
throw new IllegalStateException("Logging operation was not started or it has already completed.");
}
ProgressLogger logger = loggers.removeLast();
logger.completed();
if (loggers.isEmpty()) {
progressLoggers.remove();
}
}
Aggregations