mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-27 16:08:21 +00:00
Fix #42 mvnd fails if there is no .mvn/ dir in the user home
This commit is contained in:
@@ -255,7 +255,6 @@ public class DaemonConnector {
|
|||||||
if (timeout != null) {
|
if (timeout != null) {
|
||||||
args.add(Environment.DAEMON_IDLE_TIMEOUT.asCommandLineProperty(timeout));
|
args.add(Environment.DAEMON_IDLE_TIMEOUT.asCommandLineProperty(timeout));
|
||||||
}
|
}
|
||||||
args.add("\"-Dmaven.multiModuleProjectDirectory=" + layout.multiModuleProjectDirectory().toString() + "\"");
|
|
||||||
|
|
||||||
args.add(ServerMain.class.getName());
|
args.add(ServerMain.class.getName());
|
||||||
command = String.join(" ", args);
|
command = String.join(" ", args);
|
||||||
|
@@ -116,22 +116,25 @@ public enum Environment {
|
|||||||
public static Path findMultiModuleProjectDirectory(Path pwd) {
|
public static Path findMultiModuleProjectDirectory(Path pwd) {
|
||||||
return MAVEN_MULTIMODULE_PROJECT_DIRECTORY
|
return MAVEN_MULTIMODULE_PROJECT_DIRECTORY
|
||||||
.systemProperty()
|
.systemProperty()
|
||||||
.orDefault(() -> {
|
.orDefault(() -> findDefaultMultimoduleProjectDirectory(pwd))
|
||||||
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.");
|
|
||||||
})
|
|
||||||
.asPath()
|
.asPath()
|
||||||
.toAbsolutePath().normalize();
|
.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,
|
public static Path findLogbackConfigurationPath(Supplier<Properties> mvndProperties, Path mvndPropertiesPath,
|
||||||
Path mvndHome) {
|
Path mvndHome) {
|
||||||
return LOGBACK_CONFIGURATION_FILE
|
return LOGBACK_CONFIGURATION_FILE
|
||||||
|
@@ -20,7 +20,6 @@ package org.jboss.fuse.mvnd.plugin;
|
|||||||
|
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.URISyntaxException;
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.nio.file.FileSystems;
|
import java.nio.file.FileSystems;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
|
@@ -28,7 +28,7 @@ import org.junit.jupiter.api.Test;
|
|||||||
import org.mockito.ArgumentCaptor;
|
import org.mockito.ArgumentCaptor;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
@MvndNativeTest(projectDir = "src/test/projects/single-module")
|
@MvndNativeTest(projectDir = MvndTestExtension.TEMP_EXTERNAL)
|
||||||
public class VersionNativeIT {
|
public class VersionNativeIT {
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
|
@@ -18,7 +18,7 @@ package org.jboss.fuse.mvnd.it;
|
|||||||
import org.jboss.fuse.mvnd.junit.MvndTest;
|
import org.jboss.fuse.mvnd.junit.MvndTest;
|
||||||
import org.jboss.fuse.mvnd.junit.MvndTestExtension;
|
import org.jboss.fuse.mvnd.junit.MvndTestExtension;
|
||||||
|
|
||||||
@MvndTest(projectDir = "src/test/projects/single-module")
|
@MvndTest(projectDir = MvndTestExtension.TEMP_EXTERNAL)
|
||||||
public class VersionTest extends VersionNativeIT {
|
public class VersionTest extends VersionNativeIT {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@@ -30,6 +30,7 @@ import org.jboss.fuse.mvnd.client.Client;
|
|||||||
import org.jboss.fuse.mvnd.client.DaemonInfo;
|
import org.jboss.fuse.mvnd.client.DaemonInfo;
|
||||||
import org.jboss.fuse.mvnd.client.DaemonRegistry;
|
import org.jboss.fuse.mvnd.client.DaemonRegistry;
|
||||||
import org.jboss.fuse.mvnd.client.DefaultClient;
|
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.client.Layout;
|
||||||
import org.jboss.fuse.mvnd.jpm.ProcessImpl;
|
import org.jboss.fuse.mvnd.jpm.ProcessImpl;
|
||||||
import org.junit.jupiter.api.extension.AfterAllCallback;
|
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
|
final Path mvndHome = Paths
|
||||||
.get(Objects.requireNonNull(System.getProperty("mvnd.home"), "System property mvnd.home must be set"))
|
.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,
|
mvndPropertiesPath,
|
||||||
mvndHome,
|
mvndHome,
|
||||||
testExecutionDir,
|
testExecutionDir,
|
||||||
testExecutionDir,
|
multiModuleProjectDirectory,
|
||||||
Paths.get(System.getProperty("java.home")).toAbsolutePath().normalize(),
|
Paths.get(System.getProperty("java.home")).toAbsolutePath().normalize(),
|
||||||
localMavenRepository, settingsPath,
|
localMavenRepository, settingsPath,
|
||||||
mvndHome.resolve("conf/logging/logback.xml"));
|
mvndHome.resolve("conf/logging/logback.xml"));
|
||||||
|
Reference in New Issue
Block a user