Fix #42 mvnd fails if there is no .mvn/ dir in the user home

This commit is contained in:
Peter Palaga
2020-07-30 12:25:56 +02:00
parent 5d46afa55c
commit 6b912897b9
6 changed files with 21 additions and 17 deletions

View File

@@ -255,7 +255,6 @@ public class DaemonConnector {
if (timeout != null) {
args.add(Environment.DAEMON_IDLE_TIMEOUT.asCommandLineProperty(timeout));
}
args.add("\"-Dmaven.multiModuleProjectDirectory=" + layout.multiModuleProjectDirectory().toString() + "\"");
args.add(ServerMain.class.getName());
command = String.join(" ", args);

View File

@@ -116,22 +116,25 @@ public enum Environment {
public static Path findMultiModuleProjectDirectory(Path pwd) {
return MAVEN_MULTIMODULE_PROJECT_DIRECTORY
.systemProperty()
.orDefault(() -> {
Path dir = pwd;
do {
if (Files.isDirectory(dir.resolve(".mvn"))) {
return dir.toString();
}
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.");
})
.orDefault(() -> findDefaultMultimoduleProjectDirectory(pwd))
.asPath()
.toAbsolutePath().normalize();
}
public static String findDefaultMultimoduleProjectDirectory(Path pwd) {
Path dir = pwd;
do {
if (Files.isDirectory(dir.resolve(".mvn"))) {
return dir.toString();
}
dir = dir.getParent();
} while (dir != null);
/* 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();
}
public static Path findLogbackConfigurationPath(Supplier<Properties> mvndProperties, Path mvndPropertiesPath,
Path mvndHome) {
return LOGBACK_CONFIGURATION_FILE

View File

@@ -20,7 +20,6 @@ package org.jboss.fuse.mvnd.plugin;
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;

View File

@@ -28,7 +28,7 @@ import org.junit.jupiter.api.Test;
import org.mockito.ArgumentCaptor;
import org.mockito.Mockito;
@MvndNativeTest(projectDir = "src/test/projects/single-module")
@MvndNativeTest(projectDir = MvndTestExtension.TEMP_EXTERNAL)
public class VersionNativeIT {
@Inject

View File

@@ -18,7 +18,7 @@ package org.jboss.fuse.mvnd.it;
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 {
}

View File

@@ -30,6 +30,7 @@ import org.jboss.fuse.mvnd.client.Client;
import org.jboss.fuse.mvnd.client.DaemonInfo;
import org.jboss.fuse.mvnd.client.DaemonRegistry;
import org.jboss.fuse.mvnd.client.DefaultClient;
import org.jboss.fuse.mvnd.client.Environment;
import org.jboss.fuse.mvnd.client.Layout;
import org.jboss.fuse.mvnd.jpm.ProcessImpl;
import org.junit.jupiter.api.extension.AfterAllCallback;
@@ -167,6 +168,8 @@ public class MvndTestExtension implements BeforeAllCallback, BeforeEachCallback,
});
}
}
final Path multiModuleProjectDirectory = Paths
.get(Environment.findDefaultMultimoduleProjectDirectory(testExecutionDir));
final Path mvndHome = Paths
.get(Objects.requireNonNull(System.getProperty("mvnd.home"), "System property mvnd.home must be set"))
@@ -183,7 +186,7 @@ public class MvndTestExtension implements BeforeAllCallback, BeforeEachCallback,
mvndPropertiesPath,
mvndHome,
testExecutionDir,
testExecutionDir,
multiModuleProjectDirectory,
Paths.get(System.getProperty("java.home")).toAbsolutePath().normalize(),
localMavenRepository, settingsPath,
mvndHome.resolve("conf/logging/logback.xml"));