Search in sources :

Example 1 with ProgressLogger

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);
    }
}
Also used : OperationIdentifier(org.gradle.internal.logging.events.OperationIdentifier) ProgressLogger(org.gradle.internal.logging.progress.ProgressLogger)

Example 2 with ProgressLogger

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();
    }
}
Also used : ProgressLogger(org.gradle.internal.logging.progress.ProgressLogger)

Example 3 with ProgressLogger

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);
    }
}
Also used : ConsumerOperationParameters(org.gradle.tooling.internal.consumer.parameters.ConsumerOperationParameters) ProgressLogger(org.gradle.internal.logging.progress.ProgressLogger) ListenerManager(org.gradle.internal.event.ListenerManager)

Example 4 with ProgressLogger

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();
    }
}
Also used : InvalidUserDataException(org.gradle.api.InvalidUserDataException) OutputStream(java.io.OutputStream) ProgressLogger(org.gradle.internal.logging.progress.ProgressLogger) Socket(java.net.Socket) ConnectException(java.net.ConnectException) InvalidUserDataException(org.gradle.api.InvalidUserDataException) ConnectException(java.net.ConnectException) TaskAction(org.gradle.api.tasks.TaskAction)

Example 5 with ProgressLogger

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();
    }
}
Also used : ProgressLogger(org.gradle.internal.logging.progress.ProgressLogger)

Aggregations

ProgressLogger (org.gradle.internal.logging.progress.ProgressLogger)18 TaskAction (org.gradle.api.tasks.TaskAction)3 ProgressLoggerFactory (org.gradle.internal.logging.progress.ProgressLoggerFactory)2 File (java.io.File)1 OutputStream (java.io.OutputStream)1 ConnectException (java.net.ConnectException)1 Socket (java.net.Socket)1 SimpleDateFormat (java.text.SimpleDateFormat)1 Date (java.util.Date)1 LinkedHashMap (java.util.LinkedHashMap)1 GradleException (org.gradle.api.GradleException)1 InvalidUserDataException (org.gradle.api.InvalidUserDataException)1 Logger (org.gradle.api.logging.Logger)1 BuildComparisonResult (org.gradle.api.plugins.buildcomparison.compare.internal.BuildComparisonResult)1 ComparableGradleBuildExecuter (org.gradle.api.plugins.buildcomparison.gradle.internal.ComparableGradleBuildExecuter)1 DefaultGradleBuildInvocationSpec (org.gradle.api.plugins.buildcomparison.gradle.internal.DefaultGradleBuildInvocationSpec)1 GradleBuildComparison (org.gradle.api.plugins.buildcomparison.gradle.internal.GradleBuildComparison)1 GeneratedArchiveBuildOutcomeComparator (org.gradle.api.plugins.buildcomparison.outcome.internal.archive.GeneratedArchiveBuildOutcomeComparator)1 GeneratedArchiveBuildOutcomeComparisonResultHtmlRenderer (org.gradle.api.plugins.buildcomparison.outcome.internal.archive.GeneratedArchiveBuildOutcomeComparisonResultHtmlRenderer)1 GeneratedArchiveBuildOutcomeHtmlRenderer (org.gradle.api.plugins.buildcomparison.outcome.internal.archive.GeneratedArchiveBuildOutcomeHtmlRenderer)1