Skip to content

Commit

Permalink
Fix #42 mvnd fails if there is no .mvn/ dir in the user home
Browse files Browse the repository at this point in the history
  • Loading branch information
ppalaga committed Jul 30, 2020
1 parent 5d46afa commit 428b4d6
Show file tree
Hide file tree
Showing 11 changed files with 31 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,11 @@ private String startDaemon() {
if (timeout != null) {
args.add(Environment.DAEMON_IDLE_TIMEOUT.asCommandLineProperty(timeout));
}
args.add("\"-Dmaven.multiModuleProjectDirectory=" + layout.multiModuleProjectDirectory().toString() + "\"");

final Path multiModuleProjectDirectory = layout.multiModuleProjectDirectory();
if (multiModuleProjectDirectory != null) {
args.add("\"-Dmaven.multiModuleProjectDirectory=" + multiModuleProjectDirectory.toString() + "\"");
}

args.add(ServerMain.class.getName());
command = String.join(" ", args);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,8 +217,7 @@ public ExecutionResult execute(ClientOutput output, List<String> argv) {

daemon.dispatch(new Message.BuildRequest(
args,
layout.userDir().toString(),
layout.multiModuleProjectDirectory().toString()));
layout.userDir().toString()));

while (true) {
Message m = daemon.receive();
Expand Down
15 changes: 10 additions & 5 deletions client/src/main/java/org/jboss/fuse/mvnd/client/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -124,12 +124,12 @@ public static Path findMultiModuleProjectDirectory(Path pwd) {
}
dir = dir.getParent();
} while (dir != null);
throw new IllegalStateException("Could not detect maven.multiModuleProjectDirectory by climbing up from ["
+ pwd
+ "] seeking a .mvn directory. You may want to create a .mvn directory in the root directory of your source tree.");
/* Return pwd if .mvn directory was not found in the hierarchy.
* Maven does the same thing in mvn shell script's find_maven_basedir()
* and find_file_argument_basedir() routines */
return pwd.toString();
})
.asPath()
.toAbsolutePath().normalize();
.asAbsolutePath();
}

public static Path findLogbackConfigurationPath(Supplier<Properties> mvndProperties, Path mvndPropertiesPath,
Expand Down Expand Up @@ -269,6 +269,11 @@ public Path asPath() {
return result == null ? null : Paths.get(result);
}

public Path asAbsolutePath() {
final String result = get();
return result == null ? null : Paths.get(result).toAbsolutePath().normalize();
}

public boolean asBoolean() {
return Boolean.parseBoolean(get());
}
Expand Down
13 changes: 2 additions & 11 deletions client/src/main/java/org/jboss/fuse/mvnd/client/Message.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,10 @@ public long timestamp() {
public static class BuildRequest extends Message {
final List<String> args;
final String workingDir;
final String projectDir;

public BuildRequest(List<String> args, String workingDir, String projectDir) {
public BuildRequest(List<String> args, String workingDir) {
this.args = args;
this.workingDir = workingDir;
this.projectDir = projectDir;
}

public List<String> getArgs() {
Expand All @@ -52,16 +50,11 @@ public String getWorkingDir() {
return workingDir;
}

public String getProjectDir() {
return projectDir;
}

@Override
public String toString() {
return "BuildRequest{" +
"args=" + args +
", workingDir='" + workingDir + '\'' +
", projectDir='" + projectDir + '\'' +
'}';
}
}
Expand Down Expand Up @@ -212,14 +205,12 @@ public void write(DataOutputStream output, Message value) throws Exception {
private BuildRequest readBuildRequest(DataInputStream input) throws IOException {
List<String> args = readStringList(input);
String workingDir = readUTF(input);
String projectDir = readUTF(input);
return new BuildRequest(args, workingDir, projectDir);
return new BuildRequest(args, workingDir);
}

private void writeBuildRequest(DataOutputStream output, BuildRequest value) throws IOException {
writeStringList(output, value.args);
writeUTF(output, value.workingDir);
writeUTF(output, value.projectDir);
}

private BuildEvent readBuildEvent(DataInputStream input) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ public CliRequestBuilder workingDirectory(Path workingDirectory) {
}

public CliRequestBuilder projectDirectory(Path projectDirectory) {
request.multiModuleProjectDirectory = projectDirectory.toAbsolutePath().toFile();
if (projectDirectory != null) {
request.multiModuleProjectDirectory = projectDirectory.toAbsolutePath().toFile();
}
return this;
}

Expand Down
2 changes: 2 additions & 0 deletions daemon/src/main/java/org/apache/maven/cli/DaemonMavenCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,8 @@ public DaemonMavenCli() throws Exception {

// TODO need to externalize CliRequest
public int doMain(CliRequest cliRequest) throws Exception {
LoggerFactory.getLogger(DaemonMavenCli.class).warn("doMain");

Properties props = (Properties) System.getProperties().clone();
try {
initialize(cliRequest);
Expand Down
3 changes: 2 additions & 1 deletion daemon/src/main/java/org/jboss/fuse/mvnd/daemon/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ private void handle(DaemonConnection<Message> connection, BuildRequest buildRequ
CliRequest req = new CliRequestBuilder()
.arguments(buildRequest.getArgs())
.workingDirectory(Paths.get(buildRequest.getWorkingDir()))
.projectDirectory(Paths.get(buildRequest.getProjectDir()))
.projectDirectory(layout.multiModuleProjectDirectory())
.build();

PriorityBlockingQueue<Message> queue = new PriorityBlockingQueue<Message>(64,
Expand Down Expand Up @@ -417,6 +417,7 @@ private void handle(DaemonConnection<Message> connection, BuildRequest buildRequ
});
pumper.start();
try {
LOGGER.info("before doMain");
cli.doMain(req);
LOGGER.info("Build finished, finishing message dispatch");
loggingSpy.finish();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@

import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.file.FileSystems;
import java.nio.file.Files;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;

@MvndNativeTest(projectDir = "src/test/projects/single-module")
@MvndNativeTest(projectDir = MvndTestExtension.TEMP_EXTERNAL)
public class VersionNativeIT {

@Inject
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
import org.jboss.fuse.mvnd.junit.MvndTest;
import org.jboss.fuse.mvnd.junit.MvndTestExtension;

@MvndTest(projectDir = "src/test/projects/single-module")
@MvndTest(projectDir = MvndTestExtension.TEMP_EXTERNAL)
public class VersionTest extends VersionNativeIT {

}
Original file line number Diff line number Diff line change
Expand Up @@ -138,19 +138,22 @@ public static MvndResource create(String className, String rawProjectDir, boolea
final Path testDir = Paths.get("target/mvnd-tests/" + className).toAbsolutePath();
Files.createDirectories(testDir);
final Path testExecutionDir;
final Path multiModuleProjectDirectory;
if (TEMP_EXTERNAL.equals(rawProjectDir)) {
try {
testExecutionDir = Files.createTempDirectory(MvndTestExtension.class.getSimpleName());
} catch (IOException e) {
throw new RuntimeException("Could not create temporary directory", e);
}
multiModuleProjectDirectory = null;
} else {
final Path mvndTestSrcDir = Paths.get(rawProjectDir).toAbsolutePath().normalize();
if (!Files.exists(mvndTestSrcDir)) {
throw new IllegalStateException("@MvndTest(projectDir = \"" + mvndTestSrcDir
+ "\") points at a path that does not exist: " + mvndTestSrcDir);
}
testExecutionDir = testDir.resolve("project");
multiModuleProjectDirectory = testExecutionDir;
try (Stream<Path> files = Files.walk(mvndTestSrcDir)) {
files.forEach(source -> {
final Path dest = testExecutionDir.resolve(mvndTestSrcDir.relativize(source));
Expand Down Expand Up @@ -183,7 +186,7 @@ public static MvndResource create(String className, String rawProjectDir, boolea
mvndPropertiesPath,
mvndHome,
testExecutionDir,
testExecutionDir,
multiModuleProjectDirectory,
Paths.get(System.getProperty("java.home")).toAbsolutePath().normalize(),
localMavenRepository, settingsPath,
mvndHome.resolve("conf/logging/logback.xml"));
Expand Down

0 comments on commit 428b4d6

Please sign in to comment.