Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The maven.multiModuleProjectDirectory is badly set when using -f [pat… #494

Merged
merged 1 commit into from
Oct 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -31,6 +31,7 @@
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 Path daemonOutLog(String daemon) {
}

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 Path settings() {
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 boolean serial() {
* @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() {
Original file line number Diff line number Diff line change
@@ -251,6 +251,17 @@ public ExecutionResult execute(ClientOutput output, List<String> argv) {
}
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 ExecutionResult execute(ClientOutput output, List<String> argv) {
daemon.dispatch(new Message.BuildRequest(
args,
parameters.userDir().toString(),
parameters.multiModuleProjectDirectory().toString(),
parameters.multiModuleProjectDirectory(dir).toString(),
System.getenv()));

output.accept(Message
Original file line number Diff line number Diff line change
@@ -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 */
Original file line number Diff line number Diff line change
@@ -32,8 +32,7 @@ void testMessageOrdering() {
Message.projectStopped("projectId"),
Message.projectStarted("projectId"),
Message.log("projectId", "message"),
Message.executionFailure("projectId", true, "error")
));
Message.executionFailure("projectId", true, "error")));

assertEquals(Message.PROJECT_STARTED, messages.remove().getType());
assertEquals(Message.EXECUTION_FAILURE, messages.remove().getType());
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}

}
Original file line number Diff line number Diff line change
@@ -43,7 +43,10 @@ public TestParameters(Path testDir, Path mvndPropertiesPath, Path mavenHome, Pat
.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() {
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-Dmaven.wagon.httpconnectionManager.ttlSeconds=120
-Dmaven.wagon.http.retryHandler.requestSentEnabled=true
-Dmaven.wagon.http.retryHandler.count=10
27 changes: 27 additions & 0 deletions integration-tests/src/test/projects/specific-file/prj1/pom.xml
Original file line number Diff line number Diff line change
@@ -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>
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
-Dmaven.wagon.httpconnectionManager.ttlSeconds=120
-Dmaven.wagon.http.retryHandler.requestSentEnabled=true
-Dmaven.wagon.http.retryHandler.count=10
27 changes: 27 additions & 0 deletions integration-tests/src/test/projects/specific-file/prj2/pom.xml
Original file line number Diff line number Diff line change
@@ -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>