use of org.gradle.internal.logging.events.RenderableOutputEvent in project gradle by gradle.
the class LoggingBuildOperationProgressBroadcaster method onOutput.
@Override
public void onOutput(OutputEvent event) {
if (event instanceof RenderableOutputEvent) {
RenderableOutputEvent renderableOutputEvent = (RenderableOutputEvent) event;
OperationIdentifier operationIdentifier = renderableOutputEvent.getBuildOperationId();
if (operationIdentifier == null) {
if (rootBuildOperation == null) {
return;
}
operationIdentifier = rootBuildOperation;
}
if (renderableOutputEvent instanceof StyledTextOutputEvent || renderableOutputEvent instanceof LogEvent) {
emit(renderableOutputEvent, operationIdentifier);
}
} else if (event instanceof ProgressStartEvent) {
ProgressStartEvent progressStartEvent = (ProgressStartEvent) event;
if (progressStartEvent.getLoggingHeader() == null) {
// If the event has no logging header, it doesn't manifest as console output.
return;
}
OperationIdentifier operationIdentifier = progressStartEvent.getBuildOperationId();
if (operationIdentifier == null && rootBuildOperation != null) {
operationIdentifier = rootBuildOperation;
}
emit(progressStartEvent, operationIdentifier);
}
}
use of org.gradle.internal.logging.events.RenderableOutputEvent in project gradle by gradle.
the class OutputEventTransformer method onOutput.
@Override
public void onOutput(OutputEvent event) {
if (event instanceof ProgressStartEvent) {
ProgressStartEvent startEvent = (ProgressStartEvent) event;
if (!startEvent.isBuildOperationStart()) {
forwarded.add(startEvent.getProgressOperationId());
OperationIdentifier parentProgressOperationId = startEvent.getParentProgressOperationId();
if (parentProgressOperationId != null) {
OperationIdentifier mappedId = effectiveProgressOperation.get(parentProgressOperationId);
if (mappedId != null) {
startEvent = startEvent.withParentProgressOperation(mappedId);
}
}
listener.onOutput(startEvent);
return;
}
if (startEvent.getParentProgressOperationId() == null || GUtil.isTrue(startEvent.getLoggingHeader()) || GUtil.isTrue(startEvent.getStatus()) || startEvent.getBuildOperationCategory() != BuildOperationCategory.UNCATEGORIZED) {
forwarded.add(startEvent.getProgressOperationId());
OperationIdentifier parentProgressOperationId = startEvent.getParentProgressOperationId();
if (parentProgressOperationId != null) {
OperationIdentifier mappedId = effectiveProgressOperation.get(parentProgressOperationId);
if (mappedId != null) {
startEvent = startEvent.withParentProgressOperation(mappedId);
}
}
listener.onOutput(startEvent);
} else {
// Ignore this progress operation, and map any reference to it to its parent (or whatever its parent is mapped to)
OperationIdentifier mappedParent = effectiveProgressOperation.get(startEvent.getParentProgressOperationId());
if (mappedParent == null) {
mappedParent = startEvent.getParentProgressOperationId();
}
effectiveProgressOperation.put(startEvent.getProgressOperationId(), mappedParent);
}
} else if (event instanceof ProgressCompleteEvent) {
ProgressCompleteEvent completeEvent = (ProgressCompleteEvent) event;
OperationIdentifier mappedEvent = effectiveProgressOperation.remove(completeEvent.getProgressOperationId());
if (mappedEvent == null && forwarded.remove(completeEvent.getProgressOperationId())) {
listener.onOutput(event);
}
} else if (event instanceof ProgressEvent) {
ProgressEvent progressEvent = (ProgressEvent) event;
if (forwarded.contains(progressEvent.getProgressOperationId())) {
listener.onOutput(event);
}
} else if (event instanceof RenderableOutputEvent) {
RenderableOutputEvent outputEvent = (RenderableOutputEvent) event;
OperationIdentifier operationId = outputEvent.getBuildOperationId();
if (operationId != null) {
OperationIdentifier mappedId = effectiveProgressOperation.get(operationId);
if (mappedId != null) {
outputEvent = outputEvent.withBuildOperationId(mappedId);
}
}
listener.onOutput(outputEvent);
} else {
listener.onOutput(event);
}
}
use of org.gradle.internal.logging.events.RenderableOutputEvent in project gradle by gradle.
the class OutputEventRenderer method enableUserStandardOutputListeners.
@Override
public void enableUserStandardOutputListeners() {
// Then, a pipeline can be added for each listener as required
synchronized (lock) {
if (userStdoutListeners == null) {
userStdoutListeners = new ListenerBroadcast<StandardOutputListener>(StandardOutputListener.class);
userStderrListeners = new ListenerBroadcast<StandardOutputListener>(StandardOutputListener.class);
final OutputEventListener stdOutChain = new StyledTextOutputBackedRenderer(new StreamingStyledTextOutput(userStdoutListeners.getSource()));
final OutputEventListener stdErrChain = new StyledTextOutputBackedRenderer(new StreamingStyledTextOutput(userStderrListeners.getSource()));
userListenerChain = new BuildLogLevelFilterRenderer(new ProgressLogEventGenerator(new OutputEventListener() {
@Override
public void onOutput(OutputEvent event) {
// Do not forward events for rendering when there are no listeners to receive
if (event instanceof LogLevelChangeEvent) {
stdOutChain.onOutput(event);
stdErrChain.onOutput(event);
} else if (event.getLogLevel() == LogLevel.ERROR && !userStderrListeners.isEmpty() && event instanceof RenderableOutputEvent) {
stdErrChain.onOutput(event);
} else if (event.getLogLevel() != LogLevel.ERROR && !userStdoutListeners.isEmpty() && event instanceof RenderableOutputEvent) {
stdOutChain.onOutput(event);
}
}
}));
addChain(userListenerChain);
}
}
}
use of org.gradle.internal.logging.events.RenderableOutputEvent in project gradle by gradle.
the class StyledTextOutputBackedRenderer method onOutput.
@Override
public void onOutput(OutputEvent event) {
if (event instanceof LogLevelChangeEvent) {
LogLevelChangeEvent changeEvent = (LogLevelChangeEvent) event;
boolean newLogLevelIsDebug = changeEvent.getNewLogLevel() == LogLevel.DEBUG;
if (newLogLevelIsDebug && dateFormat == null) {
dateFormat = new SimpleDateFormat(ISO_8601_DATE_TIME_FORMAT);
}
debugOutput = newLogLevelIsDebug;
}
if (event instanceof RenderableOutputEvent) {
RenderableOutputEvent outputEvent = (RenderableOutputEvent) event;
textOutput.style(outputEvent.getLogLevel() == LogLevel.ERROR ? Error : Normal);
if (debugOutput && (textOutput.atEndOfLine || lastEvent == null || !lastEvent.getCategory().equals(outputEvent.getCategory()))) {
if (!textOutput.atEndOfLine) {
textOutput.println();
}
textOutput.text(dateFormat.format(new Date(outputEvent.getTimestamp())));
textOutput.text(" [");
textOutput.text(outputEvent.getLogLevel());
textOutput.text("] [");
textOutput.text(outputEvent.getCategory());
textOutput.text("] ");
}
outputEvent.render(textOutput);
lastEvent = outputEvent;
textOutput.style(Normal);
}
}
Aggregations