mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-11 05:30:08 +00:00
Separate BuildStarted message to avoid serializing via Propertries.[load|write]()
This commit is contained in:
@@ -15,7 +15,6 @@
|
||||
*/
|
||||
package org.jboss.fuse.mvnd.client;
|
||||
|
||||
import java.io.StringReader;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.time.Instant;
|
||||
@@ -23,7 +22,6 @@ import java.time.LocalDateTime;
|
||||
import java.time.ZoneId;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.function.Supplier;
|
||||
import org.fusesource.jansi.Ansi;
|
||||
import org.jboss.fuse.mvnd.common.BuildProperties;
|
||||
@@ -35,6 +33,7 @@ import org.jboss.fuse.mvnd.common.Message;
|
||||
import org.jboss.fuse.mvnd.common.Message.BuildEvent;
|
||||
import org.jboss.fuse.mvnd.common.Message.BuildException;
|
||||
import org.jboss.fuse.mvnd.common.Message.BuildMessage;
|
||||
import org.jboss.fuse.mvnd.common.Message.BuildStarted;
|
||||
import org.jboss.fuse.mvnd.common.OsUtils;
|
||||
import org.jboss.fuse.mvnd.common.logging.ClientOutput;
|
||||
import org.jboss.fuse.mvnd.common.logging.TerminalOutput;
|
||||
@@ -219,22 +218,12 @@ public class DefaultClient implements Client {
|
||||
output.error(e.getMessage(), e.getClassName(), e.getStackTrace());
|
||||
return new DefaultResult(argv,
|
||||
new Exception(e.getClassName() + ": " + e.getMessage() + "\n" + e.getStackTrace()));
|
||||
} else if (m instanceof BuildStarted) {
|
||||
final BuildStarted bs = (BuildStarted) m;
|
||||
output.startBuild(bs.getProjectId(), bs.getProjectCount(), bs.getMaxThreads());
|
||||
} else if (m instanceof BuildEvent) {
|
||||
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);
|
||||
case ProjectStarted:
|
||||
@@ -254,7 +243,6 @@ public class DefaultClient implements Client {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
static void setDefaultArgs(List<String> args, ClientLayout layout) {
|
||||
|
@@ -34,6 +34,7 @@ public abstract class Message {
|
||||
static final int BUILD_EXCEPTION = 3;
|
||||
static final int KEEP_ALIVE = 4;
|
||||
static final int STOP = 5;
|
||||
static final int BUILD_STARTED = 6;
|
||||
|
||||
public static final SimpleMessage KEEP_ALIVE_SINGLETON = new SimpleMessage(Message.KEEP_ALIVE, "KEEP_ALIVE");
|
||||
public static final SimpleMessage STOP_SINGLETON = new SimpleMessage(Message.STOP, "STOP");
|
||||
@@ -46,6 +47,8 @@ public abstract class Message {
|
||||
switch (type) {
|
||||
case BUILD_REQUEST:
|
||||
return BuildRequest.read(input);
|
||||
case BUILD_STARTED:
|
||||
return BuildStarted.read(input);
|
||||
case BUILD_EVENT:
|
||||
return BuildEvent.read(input);
|
||||
case BUILD_MESSAGE:
|
||||
@@ -315,7 +318,7 @@ public abstract class Message {
|
||||
|
||||
public static class BuildEvent extends Message {
|
||||
public enum Type {
|
||||
BuildStarted, BuildStopped, ProjectStarted, ProjectStopped, MojoStarted, MojoStopped
|
||||
BuildStopped, ProjectStarted, ProjectStopped, MojoStarted
|
||||
}
|
||||
|
||||
final Type type;
|
||||
@@ -365,6 +368,55 @@ public abstract class Message {
|
||||
}
|
||||
}
|
||||
|
||||
public static class BuildStarted extends Message {
|
||||
|
||||
final String projectId;
|
||||
final int projectCount;
|
||||
final int maxThreads;
|
||||
|
||||
public static BuildStarted read(DataInputStream input) throws IOException {
|
||||
final String projectId = readUTF(input);
|
||||
final int projectCount = input.readInt();
|
||||
final int maxThreads = input.readInt();
|
||||
return new BuildStarted(projectId, projectCount, maxThreads);
|
||||
}
|
||||
|
||||
public BuildStarted(String projectId, int projectCount, int maxThreads) {
|
||||
this.projectId = projectId;
|
||||
this.projectCount = projectCount;
|
||||
this.maxThreads = maxThreads;
|
||||
}
|
||||
|
||||
public String getProjectId() {
|
||||
return projectId;
|
||||
}
|
||||
|
||||
public int getProjectCount() {
|
||||
return projectCount;
|
||||
}
|
||||
|
||||
public int getMaxThreads() {
|
||||
return maxThreads;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return "BuildEvent{" +
|
||||
"projectId='" + projectId + '\'' +
|
||||
", projectCount=" + projectCount +
|
||||
", maxThreads='" + maxThreads + '\'' +
|
||||
'}';
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream output) throws IOException {
|
||||
output.write(BUILD_STARTED);
|
||||
writeUTF(output, projectId);
|
||||
output.writeInt(projectCount);
|
||||
output.writeInt(maxThreads);
|
||||
}
|
||||
}
|
||||
|
||||
public static class BuildMessage extends Message {
|
||||
final String projectId;
|
||||
final String message;
|
||||
|
@@ -16,7 +16,6 @@
|
||||
package org.jboss.fuse.mvnd.daemon;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.lang.reflect.Field;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
@@ -29,7 +28,6 @@ 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;
|
||||
@@ -57,6 +55,7 @@ import org.jboss.fuse.mvnd.common.Message.BuildEvent.Type;
|
||||
import org.jboss.fuse.mvnd.common.Message.BuildException;
|
||||
import org.jboss.fuse.mvnd.common.Message.BuildMessage;
|
||||
import org.jboss.fuse.mvnd.common.Message.BuildRequest;
|
||||
import org.jboss.fuse.mvnd.common.Message.BuildStarted;
|
||||
import org.jboss.fuse.mvnd.daemon.DaemonExpiration.DaemonExpirationResult;
|
||||
import org.jboss.fuse.mvnd.daemon.DaemonExpiration.DaemonExpirationStrategy;
|
||||
import org.jboss.fuse.mvnd.logging.smart.AbstractLoggingSpy;
|
||||
@@ -452,7 +451,7 @@ public class Server implements AutoCloseable, Runnable {
|
||||
int getClassOrder(Message m) {
|
||||
if (m instanceof BuildRequest) {
|
||||
return 0;
|
||||
} else if (m instanceof BuildEvent && ((BuildEvent) m).getType() == Type.BuildStarted) {
|
||||
} else if (m instanceof BuildStarted) {
|
||||
return 1;
|
||||
} else if (m instanceof BuildEvent && ((BuildEvent) m).getType() == Type.ProjectStarted) {
|
||||
return 2;
|
||||
@@ -460,8 +459,6 @@ public class Server implements AutoCloseable, Runnable {
|
||||
return 3;
|
||||
} else if (m instanceof BuildMessage) {
|
||||
return 50;
|
||||
} else if (m instanceof BuildEvent && ((BuildEvent) m).getType() == Type.MojoStopped) {
|
||||
return 94;
|
||||
} else if (m instanceof BuildEvent && ((BuildEvent) m).getType() == Type.ProjectStopped) {
|
||||
return 95;
|
||||
} else if (m instanceof BuildEvent && ((BuildEvent) m).getType() == Type.BuildStopped) {
|
||||
@@ -542,16 +539,8 @@ public class Server implements AutoCloseable, Runnable {
|
||||
|
||||
@Override
|
||||
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()));
|
||||
queue.add(new BuildStarted(session.getTopLevelProject().getName(), session.getAllProjects().size(),
|
||||
session.getRequest().getDegreeOfConcurrency()));
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -569,11 +558,6 @@ public class Server implements AutoCloseable, Runnable {
|
||||
sendEvent(Type.MojoStarted, projectId, display);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onStopMojo(String projectId, String display) {
|
||||
sendEvent(Type.MojoStopped, projectId, display);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onProjectLog(String projectId, String message) {
|
||||
queue.add(new BuildMessage(projectId, message));
|
||||
|
Reference in New Issue
Block a user