mirror of
https://github.com/apache/maven-mvnd.git
synced 2025-09-26 23:45:47 +00:00
The maven.multiModuleProjectDirectory is badly set when using -f [path-to-pom], fixes #484
This commit is contained in:
@@ -31,6 +31,7 @@ import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.Properties;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.function.Consumer;
|
||||
import java.util.function.Function;
|
||||
import java.util.function.IntUnaryOperator;
|
||||
import java.util.function.Supplier;
|
||||
@@ -204,9 +205,13 @@ public class DaemonParameters {
|
||||
}
|
||||
|
||||
public Path multiModuleProjectDirectory() {
|
||||
return multiModuleProjectDirectory(userDir());
|
||||
}
|
||||
|
||||
public Path multiModuleProjectDirectory(Path projectDir) {
|
||||
return value(Environment.MAVEN_MULTIMODULE_PROJECT_DIRECTORY)
|
||||
.orSystemProperty()
|
||||
.orDefault(() -> findDefaultMultimoduleProjectDirectory(userDir()))
|
||||
.orDefault(() -> findDefaultMultimoduleProjectDirectory(projectDir))
|
||||
.asPath()
|
||||
.toAbsolutePath().normalize();
|
||||
}
|
||||
@@ -257,6 +262,13 @@ public class DaemonParameters {
|
||||
return property(Environment.MAVEN_SETTINGS).asPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return path to {@code pom.xml} or {@code null}
|
||||
*/
|
||||
public Path file() {
|
||||
return value(Environment.MAVEN_FILE).asPath();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return absolute normalized path to local Maven repository or {@code null} if the server is supposed to use the
|
||||
* default
|
||||
@@ -292,16 +304,18 @@ public class DaemonParameters {
|
||||
* @return a new {@link DaemonParameters} with {@code userDir} set to the given {@code newUserDir}
|
||||
*/
|
||||
public DaemonParameters cd(Path newUserDir) {
|
||||
return new DaemonParameters(new PropertiesBuilder()
|
||||
.putAll(this.properties)
|
||||
.put(Environment.USER_DIR, newUserDir));
|
||||
return derive(b -> b.put(Environment.USER_DIR, newUserDir));
|
||||
}
|
||||
|
||||
public DaemonParameters withJdkJavaOpts(String opts) {
|
||||
String org = this.properties.getOrDefault(Environment.JDK_JAVA_OPTIONS.getProperty(), "");
|
||||
return new DaemonParameters(new PropertiesBuilder()
|
||||
.putAll(this.properties)
|
||||
.put(Environment.JDK_JAVA_OPTIONS, org + opts));
|
||||
return derive(b -> b.put(Environment.JDK_JAVA_OPTIONS, org + opts));
|
||||
}
|
||||
|
||||
protected DaemonParameters derive(Consumer<PropertiesBuilder> customizer) {
|
||||
PropertiesBuilder builder = new PropertiesBuilder().putAll(this.properties);
|
||||
customizer.accept(builder);
|
||||
return new DaemonParameters(builder);
|
||||
}
|
||||
|
||||
public Duration keepAlive() {
|
||||
|
@@ -251,6 +251,17 @@ public class DefaultClient implements Client {
|
||||
}
|
||||
Environment.MVND_TERMINAL_WIDTH.addCommandLineOption(args, Integer.toString(output.getTerminalWidth()));
|
||||
|
||||
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());
|
||||
@@ -260,7 +271,7 @@ public class DefaultClient implements Client {
|
||||
daemon.dispatch(new Message.BuildRequest(
|
||||
args,
|
||||
parameters.userDir().toString(),
|
||||
parameters.multiModuleProjectDirectory().toString(),
|
||||
parameters.multiModuleProjectDirectory(dir).toString(),
|
||||
System.getenv()));
|
||||
|
||||
output.accept(Message
|
||||
|
@@ -96,6 +96,8 @@ public enum Environment {
|
||||
MAVEN_REPO_LOCAL("maven.repo.local", null, null, OptionType.PATH, Flags.NONE),
|
||||
/** The location of the maven settings file */
|
||||
MAVEN_SETTINGS("maven.settings", null, null, OptionType.PATH, Flags.NONE, "mvn:-s", "mvn:--settings"),
|
||||
/** The pom or directory to build */
|
||||
MAVEN_FILE(null, null, null, OptionType.PATH, Flags.NONE, "mvn:-f", "mvn:--file"),
|
||||
/** The root directory of the current multi module Maven project */
|
||||
MAVEN_MULTIMODULE_PROJECT_DIRECTORY("maven.multiModuleProjectDirectory", null, null, OptionType.PATH, Flags.NONE),
|
||||
/** Log file */
|
||||
|
@@ -0,0 +1,58 @@
|
||||
/*
|
||||
* 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 java.io.IOException;
|
||||
import java.nio.file.Path;
|
||||
import javax.inject.Inject;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mvndaemon.mvnd.assertj.TestClientOutput;
|
||||
import org.mvndaemon.mvnd.client.Client;
|
||||
import org.mvndaemon.mvnd.junit.ClientFactory;
|
||||
import org.mvndaemon.mvnd.junit.MvndNativeTest;
|
||||
import org.mvndaemon.mvnd.junit.TestParameters;
|
||||
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
@MvndNativeTest(projectDir = "src/test/projects/specific-file")
|
||||
public class SpecificFileNativeIT {
|
||||
|
||||
@Inject
|
||||
ClientFactory clientFactory;
|
||||
|
||||
@Inject
|
||||
TestParameters parameters;
|
||||
|
||||
@Test
|
||||
void version() throws IOException, InterruptedException {
|
||||
TestClientOutput output = new TestClientOutput();
|
||||
|
||||
|
||||
Path prj1 = parameters.getTestDir().resolve("project/prj1").toAbsolutePath();
|
||||
Path prj2 = parameters.getTestDir().resolve("project/prj2").toAbsolutePath();
|
||||
|
||||
Client cl = clientFactory.newClient(parameters.clearMavenMultiModuleProjectDirectory().cd(prj1));
|
||||
|
||||
cl.execute(output, "org.apache.maven.plugins:maven-help-plugin:3.2.0:evaluate",
|
||||
"-Dexpression=maven.multiModuleProjectDirectory", "-f", "../prj2/pom.xml", "-e").assertSuccess();
|
||||
assertTrue(output.getMessages().stream()
|
||||
.anyMatch(m -> m.toString().contains(prj2.toString())), "Output should contain " + prj2);
|
||||
}
|
||||
|
||||
protected boolean isNative() {
|
||||
return true;
|
||||
}
|
||||
}
|
@@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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;
|
||||
}
|
||||
|
||||
}
|
@@ -43,7 +43,10 @@ public class TestParameters extends DaemonParameters {
|
||||
.put(Environment.MVND_MAX_LOST_KEEP_ALIVE, maxLostKeepAlive)
|
||||
.put(Environment.MVND_MIN_THREADS, TEST_MIN_THREADS));
|
||||
this.testDir = testDir;
|
||||
}
|
||||
|
||||
public DaemonParameters clearMavenMultiModuleProjectDirectory() {
|
||||
return derive(b -> b.put(Environment.MAVEN_MULTIMODULE_PROJECT_DIRECTORY, null));
|
||||
}
|
||||
|
||||
public Path getTestDir() {
|
||||
|
@@ -0,0 +1,3 @@
|
||||
-Dmaven.wagon.httpconnectionManager.ttlSeconds=120
|
||||
-Dmaven.wagon.http.retryHandler.requestSentEnabled=true
|
||||
-Dmaven.wagon.http.retryHandler.count=10
|
@@ -0,0 +1,27 @@
|
||||
<!--
|
||||
|
||||
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.
|
||||
|
||||
-->
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.mvndaemon.mvnd.test.specific-file</groupId>
|
||||
<artifactId>specific-file-prj1</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
</project>
|
@@ -0,0 +1,3 @@
|
||||
-Dmaven.wagon.httpconnectionManager.ttlSeconds=120
|
||||
-Dmaven.wagon.http.retryHandler.requestSentEnabled=true
|
||||
-Dmaven.wagon.http.retryHandler.count=10
|
@@ -0,0 +1,27 @@
|
||||
<!--
|
||||
|
||||
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.
|
||||
|
||||
-->
|
||||
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
|
||||
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
<groupId>org.mvndaemon.mvnd.test.specific-file</groupId>
|
||||
<artifactId>specific-file-prj2</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
</project>
|
Reference in New Issue
Block a user