diff --git a/daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java b/daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java index f140b3730..3281f28b8 100644 --- a/daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java +++ b/daemon/src/main/java/org/mvndaemon/mvnd/daemon/Server.java @@ -42,6 +42,7 @@ import java.util.stream.Collectors; import org.apache.maven.cli.DaemonMavenCli; import org.apache.maven.execution.MavenSession; +import org.apache.maven.project.MavenProject; import org.mvndaemon.mvnd.builder.SmartBuilder; import org.mvndaemon.mvnd.common.DaemonConnection; import org.mvndaemon.mvnd.common.DaemonException; @@ -651,10 +652,22 @@ public void fail(Throwable t) throws Exception { @Override protected void onStartSession(MavenSession session) { - queue.add(new BuildStarted(session.getCurrentProject().getName(), session.getProjects().size(), + queue.add(new BuildStarted(getCurrentProject(session).getName(), session.getProjects().size(), session.getRequest().getDegreeOfConcurrency())); } + private MavenProject getCurrentProject(MavenSession mavenSession) { + // MavenSession.getCurrentProject() does not return the correct value in some cases + String executionRootDirectory = mavenSession.getExecutionRootDirectory(); + if (executionRootDirectory == null) { + return mavenSession.getCurrentProject(); + } + return mavenSession.getProjects().stream() + .filter(p -> (p.getFile() != null && executionRootDirectory.equals(p.getFile().getParent()))) + .findFirst() + .orElse(mavenSession.getCurrentProject()); + } + @Override protected void onStartProject(String projectId, String display) { queue.add(Message.projectStarted(projectId, display));