Skip to content

Commit 5287c77

Browse files
committed
Provide public rootdir / topdir and deprecate others
1 parent c93458a commit 5287c77

17 files changed

Lines changed: 179 additions & 33 deletions

File tree

apache-maven/src/assembly/shared/run

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ exec "$JAVACMD" \
1616
"-Dmaven.home=$MAVEN_HOME" \
1717
"-Dlibrary.jansi.path=${MAVEN_HOME}/lib/jansi-native" \
1818
"-Dmaven.multiModuleProjectDirectory=$MAVEN_PROJECTBASEDIR" \
19-
"-Dproject.topdir=$MAVEN_PROJECTBASEDIR" \
19+
"-Dmaven.rootdir=$MAVEN_PROJECTBASEDIR" \
2020
$LAUNCHER_CLASS \
2121
$MAVEN_ARGS \
2222
"$@"

apache-maven/src/assembly/shared/run.cmd

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"-Dmaven.home=%MAVEN_HOME%" ^
77
"-Dlibrary.jansi.path=%MAVEN_HOME%\lib\jansi-native" ^
88
"-Dmaven.multiModuleProjectDirectory=%MAVEN_PROJECTBASEDIR%" ^
9-
"-Dproject.topdir=%MAVEN_PROJECTBASEDIR%" ^
9+
"-Dmaven.rootdir=%MAVEN_PROJECTBASEDIR%" ^
1010
%LAUNCHER_CLASS% ^
1111
%MAVEN_ARGS% ^
1212
%*

api/maven-api-core/src/main/java/org/apache/maven/api/Project.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,34 @@ default String getId() {
8686
return getModel().getId();
8787
}
8888

89+
/**
90+
* @deprecated use {@link #isTopdirProject()} instead
91+
*/
92+
@Deprecated
8993
boolean isExecutionRoot();
9094

95+
/**
96+
* Returns a boolean indicating if the project is the top leve project for
97+
* this reactor build. The top level project may be different from the
98+
* {@code rootDirProject}, especially if a subtree of the project is being
99+
* built, either because maven has been launched in a subdirectory or using
100+
* a {@code -f} option.
101+
*
102+
* @return {@code true} if the project is the top level project for this build
103+
*/
104+
boolean isTopdirProject();
105+
106+
/**
107+
* Returns a boolean indicating if the project is the project from the root
108+
* directory of this reactor. The root project is the top-most project containing
109+
* the {@code .mvn} directory. If only a subtree of the reactor is build (because
110+
* the current directory is in a subtree or because the {@code -f} option has been
111+
* specified, then there may be no rootDirProject in this reactor.
112+
*
113+
* @return {@code true} if the project is the root dir project
114+
*/
115+
boolean isRootdirProject();
116+
91117
@Nonnull
92118
Optional<Project> getParent();
93119

api/maven-api-core/src/main/java/org/apache/maven/api/Session.java

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,15 +85,22 @@ public interface Session {
8585
Instant getStartTime();
8686

8787
/**
88-
* @deprecated use {@link #getTopdir()} instead
88+
* @deprecated use {@link #getRootdir()} instead
8989
*/
9090
@Nonnull
9191
@Deprecated
9292
Path getMultiModuleProjectDirectory();
9393

94+
@Nonnull
95+
Path getRootdir();
96+
9497
@Nonnull
9598
Path getTopdir();
9699

100+
/**
101+
* @deprecated use {@link #getTopdir()} instead
102+
*/
103+
@Deprecated
97104
@Nonnull
98105
Path getExecutionRootDirectory();
99106

maven-core/src/main/java/org/apache/maven/execution/DefaultMavenExecutionRequest.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,12 @@ public class DefaultMavenExecutionRequest implements MavenExecutionRequest {
101101

102102
private File multiModuleProjectDirectory;
103103

104-
private Path topdir;
105-
106104
private File basedir;
107105

106+
private Path rootdir;
107+
108+
private Path topdir;
109+
108110
private List<String> goals;
109111

110112
private boolean useReactor = false;
@@ -1054,24 +1056,38 @@ public MavenExecutionRequest setToolchains(Map<String, List<ToolchainModel>> too
10541056
return this;
10551057
}
10561058

1059+
@Deprecated
10571060
@Override
10581061
public void setMultiModuleProjectDirectory(File directory) {
10591062
this.multiModuleProjectDirectory = directory;
10601063
}
10611064

1065+
@Deprecated
10621066
@Override
10631067
public File getMultiModuleProjectDirectory() {
10641068
return multiModuleProjectDirectory;
10651069
}
10661070

1071+
@Override
1072+
public Path getRootdir() {
1073+
return rootdir;
1074+
}
1075+
1076+
@Override
1077+
public MavenExecutionRequest setRootdir(Path rootdir) {
1078+
this.rootdir = rootdir;
1079+
return this;
1080+
}
1081+
10671082
@Override
10681083
public Path getTopdir() {
10691084
return topdir;
10701085
}
10711086

10721087
@Override
1073-
public void setTopdir(Path topdir) {
1088+
public MavenExecutionRequest setTopdir(Path topdir) {
10741089
this.topdir = topdir;
1090+
return this;
10751091
}
10761092

10771093
@Override

maven-core/src/main/java/org/apache/maven/execution/MavenExecutionRequest.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,17 @@ public interface MavenExecutionRequest {
9292
// ----------------------------------------------------------------------
9393

9494
// Base directory
95+
96+
/**
97+
* @deprecated use {@link #getTopdir()} instead
98+
*/
99+
@Deprecated
95100
MavenExecutionRequest setBaseDirectory(File basedir);
96101

102+
/**
103+
* @deprecated use {@link #getTopdir()} instead
104+
*/
105+
@Deprecated
97106
String getBaseDirectory();
98107

99108
// Timing (remove this)
@@ -495,18 +504,32 @@ public interface MavenExecutionRequest {
495504

496505
/**
497506
* @since 3.3.0
507+
* @deprecated use {@link #setRootdir(Path)} instead
498508
*/
509+
@Deprecated
499510
void setMultiModuleProjectDirectory(File file);
500511

501512
/**
502513
* @since 3.3.0
514+
* @deprecated use {@link #getRootdir()} instead
503515
*/
516+
@Deprecated
504517
File getMultiModuleProjectDirectory();
505518

506519
/**
507520
* @since 4.0.0
508521
*/
509-
void setTopdir(Path topdir);
522+
MavenExecutionRequest setRootdir(Path rootdir);
523+
524+
/**
525+
* @since 4.0.0
526+
*/
527+
Path getRootdir();
528+
529+
/**
530+
* @since 4.0.0
531+
*/
532+
MavenExecutionRequest setTopdir(Path topdir);
510533

511534
/**
512535
* @since 4.0.0

maven-core/src/main/java/org/apache/maven/execution/MavenSession.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,10 @@ public List<MavenProject> getProjects() {
142142
return projects;
143143
}
144144

145+
/**
146+
* @deprecated use {@link #getTopdir()}
147+
*/
148+
@Deprecated
145149
public String getExecutionRootDirectory() {
146150
return request.getBaseDirectory();
147151
}
@@ -153,6 +157,13 @@ public Path getTopdir() {
153157
return request.getTopdir();
154158
}
155159

160+
/**
161+
* @since 4.0
162+
*/
163+
public Path getRootdir() {
164+
return request.getRootdir();
165+
}
166+
156167
public MavenExecutionRequest getRequest() {
157168
return request;
158169
}

maven-core/src/main/java/org/apache/maven/internal/impl/DefaultProject.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,18 @@ public boolean isExecutionRoot() {
129129
return project.isExecutionRoot();
130130
}
131131

132+
@Override
133+
public boolean isTopdirProject() {
134+
return getBasedir().isPresent()
135+
&& getBasedir().get().equals(getSession().getTopdir());
136+
}
137+
138+
@Override
139+
public boolean isRootdirProject() {
140+
return getBasedir().isPresent()
141+
&& getBasedir().get().equals(getSession().getRootdir());
142+
}
143+
132144
@Override
133145
public Optional<Project> getParent() {
134146
MavenProject parent = project.getParent();

maven-core/src/main/java/org/apache/maven/internal/impl/DefaultSession.java

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
package org.apache.maven.internal.impl;
2020

2121
import java.nio.file.Path;
22-
import java.nio.file.Paths;
2322
import java.time.Instant;
2423
import java.util.Collections;
2524
import java.util.HashMap;
@@ -144,18 +143,23 @@ public Instant getStartTime() {
144143
@Nonnull
145144
@Override
146145
public Path getMultiModuleProjectDirectory() {
147-
return mavenSession.getRequest().getMultiModuleProjectDirectory().toPath();
146+
return getRootdir();
148147
}
149148

149+
@Nonnull
150150
@Override
151-
public Path getTopdir() {
152-
return mavenSession.getRequest().getTopdir();
151+
public Path getExecutionRootDirectory() {
152+
return getTopdir();
153153
}
154154

155-
@Nonnull
156155
@Override
157-
public Path getExecutionRootDirectory() {
158-
return Paths.get(mavenSession.getRequest().getBaseDirectory());
156+
public Path getRootdir() {
157+
return mavenSession.getRequest().getRootdir();
158+
}
159+
160+
@Override
161+
public Path getTopdir() {
162+
return mavenSession.getRequest().getTopdir();
159163
}
160164

161165
@Nonnull

maven-core/src/main/java/org/apache/maven/lifecycle/internal/LifecycleStarter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ public void execute(MavenSession session) {
9191
try {
9292
if (buildExecutionRequiresProject(session) && projectIsNotPresent(session)) {
9393
throw new MissingProjectException("The goal you specified requires a project to execute"
94-
+ " but there is no POM in this directory (" + session.getExecutionRootDirectory() + ")."
94+
+ " but there is no POM in this directory (" + session.getTopdir() + ")."
9595
+ " Please verify you invoked Maven from the correct directory.");
9696
}
9797

0 commit comments

Comments
 (0)