Skip to content
Merged
Show file tree
Hide file tree
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
Expand Up @@ -31,6 +31,7 @@
import org.apache.maven.artifact.repository.ArtifactRepository;
import org.apache.maven.eventspy.internal.EventSpyDispatcher;
import org.apache.maven.model.Profile;
import org.apache.maven.model.root.RootLocator;
import org.apache.maven.project.DefaultProjectBuildingRequest;
import org.apache.maven.project.ProjectBuildingRequest;
import org.apache.maven.properties.internal.SystemProperties;
Expand Down Expand Up @@ -211,7 +212,11 @@ public static MavenExecutionRequest copy(MavenExecutionRequest original) {
copy.setBuilderId(original.getBuilderId());

copy.setTopDirectory(original.getTopDirectory());
copy.setRootDirectory(original.getRootDirectory());
try {
copy.setRootDirectory(original.getRootDirectory());
} catch (IllegalStateException e) {
// ignore during copy
}

return copy;
}
Expand Down Expand Up @@ -1120,6 +1125,9 @@ public MavenExecutionRequest setTopDirectory(Path topDirectory) {

@Override
public Path getRootDirectory() {
if (rootDirectory == null) {
throw new IllegalStateException(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE);
}
return rootDirectory;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
package org.apache.maven.execution;

import java.io.File;
import java.nio.file.Path;
import java.util.Arrays;
import java.util.Date;
import java.util.List;
Expand Down Expand Up @@ -170,20 +171,22 @@ public MavenExecutionResult getResult() {
*
* @since 3.10.0
*/
public File getTopDirectory() {
return request.getTopDirectory() != null ? request.getTopDirectory().toFile() : null;
public Path getTopDirectory() {
return request.getTopDirectory();
}

/**
* Returns root directory if discovered or {@code null}.
* Returns root directory if discovered or throws {@link IllegalStateException} if it could not be found.
* Root directory is detected, usually by the presence of {@code .mvn} directory, and is used to discover
* extensions and other configuration files. It usually represents the "project root" or "checkout root".
* Root directory may be equal to top directory or some parent of it (first directory where {@code .mvn} is found).
*
* @throws IllegalStateException if the root directory could not be found
*
* @since 3.10.0
*/
public File getRootDirectory() {
return request.getRootDirectory() != null ? request.getRootDirectory().toFile() : null;
public Path getRootDirectory() {
return request.getRootDirectory();
}

// Backward compat
Expand Down
11 changes: 6 additions & 5 deletions maven-embedder/src/main/java/org/apache/maven/cli/MavenCli.java
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,9 @@ void properties(CliRequest cliRequest) throws ExitException {
} catch (IllegalUseOfUndefinedProperty e) {
String message = "ERROR: Illegal use of undefined property: " + e.property;
System.err.println(message);
if (cliRequest.request.getRootDirectory() == null) {
try {
cliRequest.request.getRootDirectory();
} catch (IllegalStateException ex) {
System.err.println();
System.err.println(RootLocator.UNABLE_TO_FIND_ROOT_PROJECT_MESSAGE);
}
Expand Down Expand Up @@ -1652,10 +1654,9 @@ public Object getValue(String expression) {
throw new IllegalUseOfUndefinedProperty(expression);
}
} else if ("session.rootDirectory".equals(expression)) {
Path rootDirectory = cliRequest.request.getRootDirectory();
if (rootDirectory != null) {
return rootDirectory.toString();
} else {
try {
return cliRequest.request.getRootDirectory();
} catch (IllegalStateException e) {
throw new IllegalUseOfUndefinedProperty(expression);
}
}
Expand Down