Skip to content

Commit 94fa546

Browse files
committed
Resolve the local repository path relative to the multi module directory
If a user specify a relative path in the settings.xml this currently leads a bit to unspecified behavior. Java would then resolve it to the current working directory what might give desired results on the commandline (but sometimes also unexpected ones) but in the IDE it is not really controllable. This now resolves the local repository path against the multi module directory what is the only user controllable constant directory we can offer here at the moment.
1 parent 4568238 commit 94fa546

File tree

2 files changed

+13
-10
lines changed

2 files changed

+13
-10
lines changed

org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/MavenExecutionContext.java

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -165,20 +165,21 @@ protected MavenExecutionRequest newExecutionRequest() throws CoreException {
165165
.orElseGet(workspaceConfiguration::getSettingsLocations);
166166
if(request == null) {
167167
//create a fresh one ....
168-
request = createExecutionRequest(workspaceConfiguration, containerLookup, mavenSettingsLocations);
168+
request = createExecutionRequest(workspaceConfiguration, containerLookup, mavenSettingsLocations,
169+
multiModuleProjectDirectory);
169170
request.setBaseDirectory(basedir);
170171
} else {
171172
//update existing configuration, we might have copied from an outer context here, but if the multi-module directory is different, we need to update some things...
172173
Settings settings = MavenPlugin.getMaven().getSettings(mavenSettingsLocations);
173174
File requestLocalRepositoryPath = request.getLocalRepositoryPath();
174-
File settingsLocalRepositoryPath = getLocalRepositoryPath(settings);
175+
File settingsLocalRepositoryPath = getLocalRepositoryPath(settings, multiModuleProjectDirectory);
175176
if(!pathEquals(requestLocalRepositoryPath, settingsLocalRepositoryPath)) {
176177
updateLocalRepository(request, settingsLocalRepositoryPath, containerLookup);
177178
}
178179
//TODO maybe also need to update user properties?!?
179180
updateSettingsFiles(request, mavenSettingsLocations);
181+
request.setMultiModuleProjectDirectory(multiModuleProjectDirectory);
180182
}
181-
request.setMultiModuleProjectDirectory(multiModuleProjectDirectory);
182183
}
183184
return request;
184185
}
@@ -198,16 +199,14 @@ private boolean pathEquals(File file1, File file2) {
198199
}
199200

200201
static MavenExecutionRequest createExecutionRequest(IMavenConfiguration mavenConfiguration, IComponentLookup lookup,
201-
MavenSettingsLocations settingsLocations) throws CoreException {
202+
MavenSettingsLocations settingsLocations, File multiModuleProjectDirectory) throws CoreException {
202203
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
203204
// this causes problems with unexpected "stale project configuration" error markers
204205
// need to think how to manage ${maven.build.timestamp} properly inside workspace
205206
//request.setStartTime( new Date() );
206207
Settings settings = MavenPlugin.getMaven().getSettings(settingsLocations);
207208
updateSettingsFiles(request, settingsLocations);
208-
209209
//and settings are actually derived from IMavenConfiguration
210-
211210
File userToolchainsFile = MavenCli.DEFAULT_USER_TOOLCHAINS_FILE;
212211
if(mavenConfiguration.getUserToolchainsFile() != null) {
213212
userToolchainsFile = new File(mavenConfiguration.getUserToolchainsFile());
@@ -219,7 +218,7 @@ static MavenExecutionRequest createExecutionRequest(IMavenConfiguration mavenCon
219218
throw new CoreException(Status.error(Messages.MavenImpl_error_no_exec_req, ex));
220219
}
221220

222-
updateLocalRepository(request, getLocalRepositoryPath(settings), lookup);
221+
updateLocalRepository(request, getLocalRepositoryPath(settings, multiModuleProjectDirectory), lookup);
223222
request.setOffline(mavenConfiguration.isOffline());
224223

225224
request.getUserProperties().put("m2e.version", MavenPluginActivator.getVersion()); //$NON-NLS-1$
@@ -231,6 +230,7 @@ static MavenExecutionRequest createExecutionRequest(IMavenConfiguration mavenCon
231230
request.setCacheTransferError(true);
232231

233232
request.setGlobalChecksumPolicy(mavenConfiguration.getGlobalChecksumPolicy());
233+
request.setMultiModuleProjectDirectory(multiModuleProjectDirectory);
234234
return request;
235235
}
236236

@@ -259,12 +259,14 @@ private static void updateLocalRepository(MavenExecutionRequest request, File lo
259259
request.setLocalRepositoryPath(localRepository.getBasedir());
260260
}
261261

262-
private static File getLocalRepositoryPath(Settings settings) {
262+
private static File getLocalRepositoryPath(Settings settings, File multiModuleProjectDirectory) {
263263
String localRepositoryPath = settings.getLocalRepository();
264264
if(localRepositoryPath == null) {
265265
return RepositorySystem.defaultUserLocalRepository;
266266
}
267-
return new File(localRepositoryPath);
267+
//Actually maven would resolve these against the current working directory,
268+
//as we have no such thing available the best we can use here is the root folder of the multimodule directory
269+
return new File(multiModuleProjectDirectory, localRepositoryPath).getAbsoluteFile();
268270
}
269271

270272
@Override

org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/embedder/PlexusContainerManager.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ protected void configure() {
346346
IMavenConfiguration workspaceConfiguration = IMavenConfiguration.getWorkspaceConfiguration();
347347
MavenExecutionRequest request = MavenExecutionContext.createExecutionRequest(mavenConfiguration,
348348
wrap(container), mavenProperties.map(mavenCfg -> mavenCfg.getSettingsLocations(workspaceConfiguration))
349-
.orElseGet(workspaceConfiguration::getSettingsLocations));
349+
.orElseGet(workspaceConfiguration::getSettingsLocations),
350+
multiModuleProjectDirectory);
350351
container.lookup(MavenExecutionRequestPopulator.class).populateDefaults(request);
351352
request.setBaseDirectory(multiModuleProjectDirectory);
352353
request.setMultiModuleProjectDirectory(multiModuleProjectDirectory);

0 commit comments

Comments
 (0)