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 6b91289
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,6 @@ private String startDaemon() {
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);
Expand Down
27 changes: 15 additions & 12 deletions client/src/main/java/org/jboss/fuse/mvnd/client/Environment.java
Original file line number Diff line number Diff line change
Expand Up @@ -116,22 +116,25 @@ public static EnvValue findBasicMavenHome() {
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
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 @@ -30,6 +30,7 @@
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;
Expand Down Expand Up @@ -167,6 +168,8 @@ public static MvndResource create(String className, String rawProjectDir, boolea
});
}
}
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"))
Expand All @@ -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 6b91289

Please sign in to comment.