mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-11 13:39:32 +00:00
Improve progress display, fixes #112
This commit is contained in:
@@ -15,6 +15,7 @@
|
||||
*/
|
||||
package org.jboss.fuse.mvnd.client;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Instant;
|
||||
@@ -200,6 +201,17 @@ public class DefaultClient implements Client {
|
||||
BuildEvent be = (BuildEvent) m;
|
||||
switch (be.getType()) {
|
||||
case BuildStarted:
|
||||
int projects = 0;
|
||||
int cores = 0;
|
||||
Properties props = new Properties();
|
||||
try {
|
||||
props.load(new StringReader(be.getDisplay()));
|
||||
projects = Integer.parseInt(props.getProperty("projects"));
|
||||
cores = Integer.parseInt(props.getProperty("cores"));
|
||||
} catch (Exception e) {
|
||||
// Ignore
|
||||
}
|
||||
output.startBuild(be.getProjectId(), projects, cores);
|
||||
break;
|
||||
case BuildStopped:
|
||||
return new DefaultResult(argv, null);
|
||||
|
@@ -20,6 +20,8 @@ package org.jboss.fuse.mvnd.common.logging;
|
||||
*/
|
||||
public interface ClientOutput extends AutoCloseable {
|
||||
|
||||
void startBuild(String name, int projects, int cores);
|
||||
|
||||
void projectStateChanged(String projectId, String display);
|
||||
|
||||
void projectFinished(String projectId);
|
||||
|
@@ -63,7 +63,14 @@ public class TerminalOutput implements ClientOutput {
|
||||
private int linesPerProject = 0;
|
||||
private boolean displayDone = false;
|
||||
|
||||
private long start;
|
||||
private String name;
|
||||
private int totalProjects;
|
||||
private int doneProjects;
|
||||
private int usedCores;
|
||||
|
||||
enum EventType {
|
||||
BUILD,
|
||||
PROJECT_STATE,
|
||||
PROJECT_FINISHED,
|
||||
LOG,
|
||||
@@ -108,6 +115,14 @@ public class TerminalOutput implements ClientOutput {
|
||||
this.reader = r;
|
||||
}
|
||||
|
||||
public void startBuild(String name, int projects, int cores) {
|
||||
this.name = name;
|
||||
this.start = System.currentTimeMillis();
|
||||
this.totalProjects = projects;
|
||||
this.doneProjects = 0;
|
||||
this.usedCores = cores;
|
||||
}
|
||||
|
||||
public void projectStateChanged(String projectId, String task) {
|
||||
try {
|
||||
queue.put(new Event(EventType.PROJECT_STATE, projectId, task));
|
||||
@@ -215,6 +230,7 @@ public class TerminalOutput implements ClientOutput {
|
||||
if (prj != null) {
|
||||
prj.log.forEach(log);
|
||||
}
|
||||
doneProjects++;
|
||||
displayDone();
|
||||
break;
|
||||
}
|
||||
@@ -285,7 +301,22 @@ public class TerminalOutput implements ClientOutput {
|
||||
int dispLines = rows - 1; // for the "Building..." line
|
||||
dispLines--; // there's a bug which sometimes make the cursor goes one line below, so keep one more line empty at the end
|
||||
if (projects.size() <= dispLines) {
|
||||
lines.add(new AttributedString("Building..."));
|
||||
String dstr = "";
|
||||
if (start > 0) {
|
||||
long sec = (System.currentTimeMillis() - this.start) / 1000;
|
||||
if (sec > 60) {
|
||||
dstr = "(time: " + (sec / 60) + "m" + (sec % 60) + "s)";
|
||||
} else {
|
||||
dstr = "(time: " + sec + "s)";
|
||||
}
|
||||
}
|
||||
String pstr = "";
|
||||
if (totalProjects > 0) {
|
||||
pstr = "(progress: " + ((doneProjects * 100) / totalProjects) + "% - " + doneProjects + " out of "
|
||||
+ totalProjects + " projects)";
|
||||
}
|
||||
lines.add(new AttributedString(
|
||||
"Building " + name + "... (cores: " + usedCores + ")" + dstr + pstr));
|
||||
int remLogLines = dispLines - projects.size();
|
||||
for (Project prj : projects.values()) {
|
||||
lines.add(AttributedString.fromAnsi(prj.status != null ? prj.status : prj.id + ":<unknown>"));
|
||||
|
@@ -16,6 +16,7 @@
|
||||
package org.jboss.fuse.mvnd.daemon;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.nio.channels.ServerSocketChannel;
|
||||
@@ -27,6 +28,7 @@ import java.util.Comparator;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.BlockingQueue;
|
||||
import java.util.concurrent.Executors;
|
||||
import java.util.concurrent.PriorityBlockingQueue;
|
||||
@@ -38,6 +40,7 @@ import java.util.concurrent.locks.ReentrantLock;
|
||||
import org.apache.maven.cli.CliRequest;
|
||||
import org.apache.maven.cli.CliRequestBuilder;
|
||||
import org.apache.maven.cli.DaemonMavenCli;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.jboss.fuse.mvnd.common.DaemonConnection;
|
||||
import org.jboss.fuse.mvnd.common.DaemonException;
|
||||
import org.jboss.fuse.mvnd.common.DaemonExpirationStatus;
|
||||
@@ -527,8 +530,17 @@ public class Server implements AutoCloseable, Runnable {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStartSession() {
|
||||
queue.add(new BuildEvent(Type.BuildStarted, "", ""));
|
||||
protected void onStartSession(MavenSession session) {
|
||||
Properties props = new Properties();
|
||||
props.setProperty("projects", Integer.toString(session.getAllProjects().size()));
|
||||
props.setProperty("cores", Integer.toString(session.getRequest().getDegreeOfConcurrency()));
|
||||
StringWriter sw = new StringWriter();
|
||||
try {
|
||||
props.store(sw, null);
|
||||
} catch (IOException e) {
|
||||
throw new IllegalStateException(e);
|
||||
}
|
||||
queue.add(new BuildEvent(Type.BuildStarted, session.getTopLevelProject().getName(), sw.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@@ -16,6 +16,7 @@
|
||||
package org.jboss.fuse.mvnd.logging.smart;
|
||||
|
||||
import org.apache.maven.execution.ExecutionEvent;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
|
||||
public abstract class AbstractLoggingSpy {
|
||||
|
||||
@@ -43,7 +44,7 @@ public abstract class AbstractLoggingSpy {
|
||||
}
|
||||
|
||||
protected void notifySessionStart(ExecutionEvent event) {
|
||||
onStartSession();
|
||||
onStartSession(event.getSession());
|
||||
}
|
||||
|
||||
protected void notifySessionFinish(ExecutionEvent event) {
|
||||
@@ -66,7 +67,7 @@ public abstract class AbstractLoggingSpy {
|
||||
onStopMojo(getProjectId(event), getProjectDisplay(event));
|
||||
}
|
||||
|
||||
protected void onStartSession() {
|
||||
protected void onStartSession(MavenSession session) {
|
||||
}
|
||||
|
||||
protected void onFinishSession() {
|
||||
|
@@ -16,6 +16,7 @@
|
||||
package org.jboss.fuse.mvnd.logging.smart;
|
||||
|
||||
import java.io.IOError;
|
||||
import org.apache.maven.execution.MavenSession;
|
||||
import org.jboss.fuse.mvnd.common.logging.TerminalOutput;
|
||||
|
||||
public class MavenLoggingSpy extends AbstractLoggingSpy {
|
||||
@@ -26,9 +27,13 @@ public class MavenLoggingSpy extends AbstractLoggingSpy {
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStartSession() {
|
||||
protected void onStartSession(MavenSession session) {
|
||||
try {
|
||||
output = new TerminalOutput(null);
|
||||
output.startBuild(
|
||||
session.getTopLevelProject().getName(),
|
||||
session.getAllProjects().size(),
|
||||
session.getRequest().getDegreeOfConcurrency());
|
||||
} catch (Exception e) {
|
||||
throw new IOError(e);
|
||||
}
|
||||
|
Reference in New Issue
Block a user