diff --git a/client/src/main/java/org/mvndaemon/mvnd/client/DefaultClient.java b/client/src/main/java/org/mvndaemon/mvnd/client/DefaultClient.java index 14197c36..58f91db6 100644 --- a/client/src/main/java/org/mvndaemon/mvnd/client/DefaultClient.java +++ b/client/src/main/java/org/mvndaemon/mvnd/client/DefaultClient.java @@ -116,6 +116,19 @@ public class DefaultClient implements Client { System.setProperty(Environment.MVND_HOME.getProperty(), parameters.mvndHome().toString()); + Path dir; + if (Environment.MAVEN_FILE.hasCommandLineOption(args)) { + dir = parameters.userDir().resolve(Environment.MAVEN_FILE.getCommandLineOption(args)); + if (Files.isRegularFile(dir)) { + dir = dir.getParent(); + } + dir = dir.normalize(); + } else { + dir = parameters.userDir(); + } + System.setProperty(Environment.MAVEN_MULTIMODULE_PROJECT_DIRECTORY.getProperty(), + parameters.multiModuleProjectDirectory(dir).toString()); + // .mvn/jvm.config if (Files.isRegularFile(parameters.jvmConfigPath())) { try (Stream jvmArgs = Files.lines(parameters.jvmConfigPath())) { @@ -293,17 +306,6 @@ public class DefaultClient implements Client { }); Environment.MVND_TERMINAL_WIDTH.addCommandLineOption(args, width); - Path dir; - if (Environment.MAVEN_FILE.hasCommandLineOption(args)) { - dir = parameters.userDir().resolve(Environment.MAVEN_FILE.getCommandLineOption(args)); - if (Files.isRegularFile(dir)) { - dir = dir.getParent(); - } - dir = dir.normalize(); - } else { - dir = parameters.userDir(); - } - final DaemonConnector connector = new DaemonConnector(parameters, registry); try (DaemonClientConnection daemon = connector.connect(output)) { output.setDaemonId(daemon.getDaemon().getId()); @@ -313,7 +315,7 @@ public class DefaultClient implements Client { daemon.dispatch(new Message.BuildRequest( args, parameters.userDir().toString(), - parameters.multiModuleProjectDirectory(dir).toString(), + parameters.multiModuleProjectDirectory().toString(), System.getenv())); output.accept(Message diff --git a/dist/src/main/distro/bin/mvnd.cmd b/dist/src/main/distro/bin/mvnd.cmd index 53507e4b..c988ac0a 100644 --- a/dist/src/main/distro/bin/mvnd.cmd +++ b/dist/src/main/distro/bin/mvnd.cmd @@ -78,88 +78,6 @@ goto error set MAVEN_CMD_LINE_ARGS=%* -@REM Find the project basedir, i.e., the directory that contains the folder ".mvn". -@REM Fallback to current working directory if not found. - -set "MAVEN_PROJECTBASEDIR=%MAVEN_BASEDIR%" -if not "%MAVEN_PROJECTBASEDIR%"=="" goto endDetectBaseDir - -set "EXEC_DIR=%CD%" -set "WDIR=%EXEC_DIR%" - -@REM Look for the --file switch and start the search for the .mvn directory from the specified -@REM POM location, if supplied. - -set FILE_ARG= -:arg_loop -if "%~1" == "-f" ( - set "FILE_ARG=%~2" - shift - goto process_file_arg -) -if "%~1" == "--file" ( - set "FILE_ARG=%~2" - shift - goto process_file_arg -) -@REM If none of the above, skip the argument -shift -if not "%~1" == "" ( - goto arg_loop -) else ( - goto findBaseDir -) - -:process_file_arg -if "%FILE_ARG%" == "" ( - goto findBaseDir -) -if not exist "%FILE_ARG%" ( - echo POM file "%FILE_ARG%" specified the -f/--file command-line argument does not exist >&2 - goto error -) -if exist "%FILE_ARG%\*" ( - set "POM_DIR=%FILE_ARG%" -) else ( - call :get_directory_from_file "%FILE_ARG%" -) -if not exist "%POM_DIR%" ( - echo Directory "%POM_DIR%" extracted from the -f/--file command-line argument "%FILE_ARG%" does not exist >&2 - goto error -) -set "WDIR=%POM_DIR%" -goto findBaseDir - -:get_directory_from_file -set "POM_DIR=%~dp1" -:stripPomDir -if not "_%POM_DIR:~-1%"=="_\" goto pomDirStripped -set "POM_DIR=%POM_DIR:~0,-1%" -goto stripPomDir -:pomDirStripped -exit /b - -:findBaseDir -cd /d "%WDIR%" -:findBaseDirLoop -if exist "%WDIR%\.mvn" goto baseDirFound -cd .. -IF "%WDIR%"=="%CD%" goto baseDirNotFound -set "WDIR=%CD%" -goto findBaseDirLoop - -:baseDirFound -set "MAVEN_PROJECTBASEDIR=%WDIR%" -cd /d "%EXEC_DIR%" -goto endDetectBaseDir - -:baseDirNotFound -if "_%EXEC_DIR:~-1%"=="_\" set "EXEC_DIR=%EXEC_DIR:~0,-1%" -set "MAVEN_PROJECTBASEDIR=%EXEC_DIR%" -cd "%EXEC_DIR%" - -:endDetectBaseDir - @setlocal EnableExtensions EnableDelayedExpansion for %%i in ("%MVND_HOME%"\mvn\boot\*.jar "%MVND_HOME%"\mvn\lib\ext\*.jar "%MVND_HOME%"\mvn\lib\*.jar) do set DAEMON_JAR=!DAEMON_JAR!;%%i @endlocal & set DAEMON_JAR="%DAEMON_JAR%" diff --git a/dist/src/main/distro/bin/mvnd.sh b/dist/src/main/distro/bin/mvnd.sh index aab3f4bd..c1c3d41d 100755 --- a/dist/src/main/distro/bin/mvnd.sh +++ b/dist/src/main/distro/bin/mvnd.sh @@ -118,23 +118,6 @@ if $cygwin ; then DAEMON_JAR=`cygpath --path --windows "$DAEMON_JAR"` fi -# traverses directory structure from process work directory to filesystem root -# first directory with .mvn subdirectory is considered project base directory -find_maven_basedir() { -( - basedir=`find_file_argument_basedir "$@"` - wdir="${basedir}" - while [ "$wdir" != '/' ] ; do - if [ -d "$wdir"/.mvn ] ; then - basedir=$wdir - break - fi - wdir=`cd "$wdir/.."; pwd` - done - echo "${basedir}" -) -} - find_file_argument_basedir() { ( basedir=`pwd` @@ -172,17 +155,6 @@ concat_lines() { fi } -MAVEN_PROJECTBASEDIR="${MAVEN_BASEDIR:-`find_maven_basedir "$@"`}" - -# For Cygwin, switch project base directory path to Windows format before -# executing Maven otherwise this will cause Maven not to consider it. -if $cygwin ; then - [ -n "$MAVEN_PROJECTBASEDIR" ] && - MAVEN_PROJECTBASEDIR=`cygpath --path --windows "$MAVEN_PROJECTBASEDIR"` -fi - -export MAVEN_PROJECTBASEDIR - # Provide a "standardized" way to retrieve the CLI args that will # work with both Windows and non-Windows executions. MAVEN_CMD_LINE_ARGS="$MAVEN_CONFIG $@" @@ -196,5 +168,4 @@ exec "$JAVACMD" \ "-Dmvnd.home=${MVND_HOME}" \ "-Dmaven.home=${MVND_HOME}/mvn" \ "-Dlibrary.jansi.path=${MVND_HOME}/mvn/lib/jansi-native" \ - "-Dmaven.multiModuleProjectDirectory=${MAVEN_PROJECTBASEDIR}" \ ${DAEMON_LAUNCHER} "$@" diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/SpecificFileNativeIT.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/SpecificFileNativeIT.java index 5fd6f895..6f90936d 100644 --- a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/SpecificFileNativeIT.java +++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/SpecificFileNativeIT.java @@ -27,6 +27,13 @@ import org.mvndaemon.mvnd.junit.TestParameters; import static org.junit.jupiter.api.Assertions.assertTrue; +/** + * NOTE: there is no related JVM test because the support for the maven + * multiModuleProjectDiscovery is done very early in the client in order + * to be able to load the JVM parameters from the .mvn/jvm.config file. + * Thus, there's point in setting because it would have to be done + * in the test iself. + */ @MvndNativeTest(projectDir = "src/test/projects/specific-file") public class SpecificFileNativeIT { @@ -49,6 +56,12 @@ public class SpecificFileNativeIT { "-Dexpression=maven.multiModuleProjectDirectory", "-f", "../prj2/pom.xml", "-e").assertSuccess(); assertTrue(output.getMessages().stream() .anyMatch(m -> m.toString().contains(prj2.toString())), "Output should contain " + prj2); + + output.getMessages().clear(); + cl.execute(output, "org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate", + "-Dexpression=foo-bar", "-f", "../prj2/pom.xml", "-e").assertSuccess(); + assertTrue(output.getMessages().stream() + .anyMatch(m -> m.toString().contains("xx-prj2-xx")), "Output should contain " + prj2); } protected boolean isNative() { diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/SpecificFileTest.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/it/SpecificFileTest.java deleted file mode 100644 index 46a0fa52..00000000 --- a/integration-tests/src/test/java/org/mvndaemon/mvnd/it/SpecificFileTest.java +++ /dev/null @@ -1,26 +0,0 @@ -/* - * Copyright 2021 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.mvndaemon.mvnd.it; - -import org.mvndaemon.mvnd.junit.MvndTest; - -@MvndTest(projectDir = "src/test/projects/specific-file") -public class SpecificFileTest extends SpecificFileNativeIT { - protected boolean isNative() { - return false; - } - -} diff --git a/integration-tests/src/test/java/org/mvndaemon/mvnd/junit/JvmTestClient.java b/integration-tests/src/test/java/org/mvndaemon/mvnd/junit/JvmTestClient.java index 283edfc3..42f310cf 100644 --- a/integration-tests/src/test/java/org/mvndaemon/mvnd/junit/JvmTestClient.java +++ b/integration-tests/src/test/java/org/mvndaemon/mvnd/junit/JvmTestClient.java @@ -15,21 +15,28 @@ */ package org.mvndaemon.mvnd.junit; +import java.nio.file.Files; +import java.nio.file.Path; import java.util.List; import org.mvndaemon.mvnd.assertj.TestClientOutput; import org.mvndaemon.mvnd.client.DaemonParameters; import org.mvndaemon.mvnd.client.DefaultClient; import org.mvndaemon.mvnd.client.ExecutionResult; +import org.mvndaemon.mvnd.common.Environment; import org.mvndaemon.mvnd.common.logging.ClientOutput; public class JvmTestClient extends DefaultClient { + private DaemonParameters parameters; + public JvmTestClient(DaemonParameters parameters) { super(parameters); + this.parameters = parameters; } @Override public ExecutionResult execute(ClientOutput output, List argv) { + setMultiModuleProjectDirectory(argv); setSystemPropertiesFromCommandLine(argv); final ExecutionResult delegate = super.execute(output, argv); if (output instanceof TestClientOutput) { @@ -38,6 +45,22 @@ public class JvmTestClient extends DefaultClient { return delegate; } + private void setMultiModuleProjectDirectory(List args) { + // Specific parameters + Path dir; + if (Environment.MAVEN_FILE.hasCommandLineOption(args)) { + dir = parameters.userDir().resolve(Environment.MAVEN_FILE.getCommandLineOption(args)); + if (Files.isRegularFile(dir)) { + dir = dir.getParent(); + } + dir = dir.normalize(); + } else { + dir = parameters.userDir(); + } + System.setProperty(Environment.MAVEN_MULTIMODULE_PROJECT_DIRECTORY.getProperty(), + parameters.multiModuleProjectDirectory(dir).toString()); + } + public static class JvmTestResult implements ExecutionResult { private final ExecutionResult delegate; diff --git a/integration-tests/src/test/projects/specific-file/prj1/.mvn/jvm.config b/integration-tests/src/test/projects/specific-file/prj1/.mvn/jvm.config new file mode 100644 index 00000000..c74101c4 --- /dev/null +++ b/integration-tests/src/test/projects/specific-file/prj1/.mvn/jvm.config @@ -0,0 +1 @@ +-Dfoo-bar=xx-prj1-xx diff --git a/integration-tests/src/test/projects/specific-file/prj2/.mvn/jvm.config b/integration-tests/src/test/projects/specific-file/prj2/.mvn/jvm.config new file mode 100644 index 00000000..51636631 --- /dev/null +++ b/integration-tests/src/test/projects/specific-file/prj2/.mvn/jvm.config @@ -0,0 +1 @@ +-Dfoo-bar=xx-prj2-xx