Search in sources :

Example 1 with OperationIdentifier

use of org.gradle.internal.logging.events.OperationIdentifier 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 OperationIdentifier

use of org.gradle.internal.logging.events.OperationIdentifier in project gradle by gradle.

the class ProgressCompleteEventSerializer method read.

@Override
public ProgressCompleteEvent read(Decoder decoder) throws Exception {
    OperationIdentifier id = new OperationIdentifier(decoder.readSmallLong());
    long timestamp = decoder.readLong();
    String category = decoder.readString();
    String description = decoder.readString();
    String status = decoder.readString();
    return new ProgressCompleteEvent(id, timestamp, category, description, status);
}
Also used : OperationIdentifier(org.gradle.internal.logging.events.OperationIdentifier) ProgressCompleteEvent(org.gradle.internal.logging.events.ProgressCompleteEvent)

Example 3 with OperationIdentifier

use of org.gradle.internal.logging.events.OperationIdentifier in project gradle by gradle.

the class ProgressEventSerializer method read.

@Override
public ProgressEvent read(Decoder decoder) throws Exception {
    OperationIdentifier id = new OperationIdentifier(decoder.readSmallLong());
    long timestamp = decoder.readLong();
    String category = decoder.readString();
    String status = decoder.readString();
    return new ProgressEvent(id, timestamp, category, status);
}
Also used : OperationIdentifier(org.gradle.internal.logging.events.OperationIdentifier) ProgressEvent(org.gradle.internal.logging.events.ProgressEvent)

Example 4 with OperationIdentifier

use of org.gradle.internal.logging.events.OperationIdentifier in project gradle by gradle.

the class ProgressStartEventSerializer method read.

@Override
public ProgressStartEvent read(Decoder decoder) throws Exception {
    OperationIdentifier id = new OperationIdentifier(decoder.readSmallLong());
    OperationIdentifier parentId = decoder.readBoolean() ? new OperationIdentifier(decoder.readSmallLong()) : null;
    long timestamp = decoder.readLong();
    String category = decoder.readString();
    String description = decoder.readString();
    String shortDescription = decoder.readNullableString();
    String loggingHeader = decoder.readNullableString();
    String status = decoder.readString();
    return new ProgressStartEvent(id, parentId, timestamp, category, description, shortDescription, loggingHeader, status);
}
Also used : ProgressStartEvent(org.gradle.internal.logging.events.ProgressStartEvent) OperationIdentifier(org.gradle.internal.logging.events.OperationIdentifier)

Aggregations

OperationIdentifier (org.gradle.internal.logging.events.OperationIdentifier)4 ProgressCompleteEvent (org.gradle.internal.logging.events.ProgressCompleteEvent)1 ProgressEvent (org.gradle.internal.logging.events.ProgressEvent)1 ProgressStartEvent (org.gradle.internal.logging.events.ProgressStartEvent)1 ProgressLogger (org.gradle.internal.logging.progress.ProgressLogger)1