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