mirror of
https://github.com/apache/maven-mvnd.git
synced 2026-01-20 07:02:45 +08:00
@@ -0,0 +1,64 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.apache.maven.cli.logging;
|
||||
|
||||
import ch.qos.logback.classic.Level;
|
||||
import ch.qos.logback.classic.pattern.ThrowableProxyConverter;
|
||||
import ch.qos.logback.classic.spi.ILoggingEvent;
|
||||
import ch.qos.logback.classic.spi.IThrowableProxy;
|
||||
import ch.qos.logback.core.AppenderBase;
|
||||
import ch.qos.logback.core.CoreConstants;
|
||||
|
||||
import static org.apache.maven.shared.utils.logging.MessageUtils.level;
|
||||
|
||||
public class SimpleAppender extends AppenderBase<ILoggingEvent> {
|
||||
|
||||
@Override
|
||||
protected void append(ILoggingEvent eventObject) {
|
||||
StringBuilder buf = new StringBuilder();
|
||||
buf.append('[');
|
||||
buf.append(renderLevel(eventObject.getLevel()));
|
||||
buf.append(']');
|
||||
buf.append(' ');
|
||||
buf.append(eventObject.getFormattedMessage());
|
||||
buf.append(CoreConstants.LINE_SEPARATOR);
|
||||
IThrowableProxy tp = eventObject.getThrowableProxy();
|
||||
if (tp != null) {
|
||||
buf.append(CoreConstants.LINE_SEPARATOR);
|
||||
buf.append(new ThrowableProxyConverter().convert(eventObject));
|
||||
}
|
||||
System.out.print(buf.toString());
|
||||
}
|
||||
|
||||
private String renderLevel(Level level) {
|
||||
switch (level.toInt()) {
|
||||
case Level.TRACE_INT:
|
||||
return level().debug("TRACE");
|
||||
case Level.DEBUG_INT:
|
||||
return level().debug("DEBUG");
|
||||
case Level.INFO_INT:
|
||||
return level().info("INFO");
|
||||
case Level.WARN_INT:
|
||||
return level().warning("WARNING");
|
||||
case Level.ERROR_INT:
|
||||
return level().error("ERROR");
|
||||
default:
|
||||
throw new IllegalStateException("Level " + level + " is unknown.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
/*
|
||||
* Copyright 2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.jboss.fuse.mvnd.logging.internal;
|
||||
|
||||
import org.apache.maven.cli.logging.Slf4jConfiguration;
|
||||
|
||||
public class MvndSlf4jConfiguration implements Slf4jConfiguration {
|
||||
@Override
|
||||
public void setRootLoggerLevel(Level level) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void activate() {
|
||||
}
|
||||
}
|
||||
@@ -34,7 +34,12 @@ public abstract class AbstractLoggingSpy extends AbstractEventSpy {
|
||||
|
||||
public static AbstractLoggingSpy instance() {
|
||||
if (instance == null) {
|
||||
instance = new MavenLoggingSpy();
|
||||
if ("mvns".equals(System.getProperty("mvnd.logging", "mvn"))) {
|
||||
instance = new MavenLoggingSpy();
|
||||
} else {
|
||||
instance = new AbstractLoggingSpy() {
|
||||
};
|
||||
}
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
@@ -112,32 +117,23 @@ public abstract class AbstractLoggingSpy extends AbstractEventSpy {
|
||||
|
||||
protected void onStartProject(String projectId, String display) {
|
||||
MDC.put(KEY_PROJECT_ID, projectId);
|
||||
update();
|
||||
}
|
||||
|
||||
protected void onStopProject(String projectId, String display) {
|
||||
MDC.put(KEY_PROJECT_ID, projectId);
|
||||
update();
|
||||
MDC.remove(KEY_PROJECT_ID);
|
||||
}
|
||||
|
||||
protected void onStartMojo(String projectId, String display) {
|
||||
Slf4jLogger.setCurrentProject(projectId);
|
||||
MDC.put(KEY_PROJECT_ID, projectId);
|
||||
update();
|
||||
}
|
||||
|
||||
protected void onStopMojo(String projectId, String display) {
|
||||
MDC.put(KEY_PROJECT_ID, projectId);
|
||||
update();
|
||||
}
|
||||
|
||||
protected void onProjectLog(String projectId, String message) {
|
||||
MDC.put(KEY_PROJECT_ID, projectId);
|
||||
update();
|
||||
}
|
||||
|
||||
protected void update() {
|
||||
}
|
||||
|
||||
private String getProjectId(ExecutionEvent event) {
|
||||
|
||||
@@ -15,22 +15,11 @@
|
||||
*/
|
||||
package org.jboss.fuse.mvnd.logging.smart;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import org.jline.terminal.Size;
|
||||
import org.jline.terminal.Terminal;
|
||||
import org.jline.terminal.TerminalBuilder;
|
||||
import org.jline.utils.AttributedString;
|
||||
import org.jline.utils.Display;
|
||||
import org.jboss.fuse.mvnd.common.logging.TerminalOutput;
|
||||
|
||||
public class MavenLoggingSpy extends AbstractLoggingSpy {
|
||||
|
||||
private Map<String, String> projects = new LinkedHashMap<>();
|
||||
private Terminal terminal;
|
||||
private Display display;
|
||||
private TerminalOutput output;
|
||||
|
||||
public MavenLoggingSpy() {
|
||||
}
|
||||
@@ -38,61 +27,43 @@ public class MavenLoggingSpy extends AbstractLoggingSpy {
|
||||
@Override
|
||||
public void init(Context context) throws Exception {
|
||||
super.init(context);
|
||||
terminal = (Terminal) context.getData().get("terminal");
|
||||
if (terminal == null) {
|
||||
terminal = TerminalBuilder.terminal();
|
||||
}
|
||||
display = new Display(terminal, false);
|
||||
output = new TerminalOutput(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void close() throws Exception {
|
||||
display.update(Collections.emptyList(), 0);
|
||||
terminal.flush();
|
||||
terminal.close();
|
||||
terminal = null;
|
||||
display = null;
|
||||
output.close();
|
||||
super.close();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStartProject(String projectId, String display) {
|
||||
projects.put(projectId, display);
|
||||
super.onStartProject(projectId, display);
|
||||
output.projectStateChanged(projectId, display);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStopProject(String projectId, String display) {
|
||||
projects.remove(projectId);
|
||||
output.projectFinished(projectId);
|
||||
super.onStopProject(projectId, display);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStartMojo(String projectId, String display) {
|
||||
projects.put(projectId, display);
|
||||
super.onStartMojo(projectId, display);
|
||||
output.projectStateChanged(projectId, display);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStopMojo(String projectId, String display) {
|
||||
projects.put(projectId, display);
|
||||
output.projectStateChanged(projectId, ":" + projectId);
|
||||
super.onStopMojo(projectId, display);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProjectLog(String projectId, String message) {
|
||||
super.onProjectLog(projectId, message);
|
||||
}
|
||||
|
||||
protected void update() {
|
||||
Size size = terminal.getSize();
|
||||
display.resize(size.getRows(), size.getColumns());
|
||||
List<AttributedString> lines = new ArrayList<>();
|
||||
lines.add(new AttributedString("Building..."));
|
||||
for (String build : projects.values()) {
|
||||
lines.add(new AttributedString(build));
|
||||
}
|
||||
display.update(lines, -1);
|
||||
output.accept(projectId, message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user