Skip to content

Commit 5249bdb

Browse files
committed
Merge remote-tracking branch 'origin/master' into
Maven_global_settings_and_toolchains_UI_cleanup
2 parents f6fb6a2 + 044cb60 commit 5249bdb

File tree

22 files changed

+410
-159
lines changed

22 files changed

+410
-159
lines changed

.github/workflows/junit.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ jobs:
4545
done
4646
4747
- name: Publish Test Results
48-
uses: EnricoMi/publish-unit-test-result-action@4e121453199042300b654ee3b4b52720bc645dc6 # v2.13.0
48+
uses: EnricoMi/publish-unit-test-result-action@8885e273a4343cd7b48eaa72428dea0c3067ea98 # v2.14.0
4949
with:
5050
commit: ${{ github.event.workflow_run.head_sha }}
5151
event_file: artifacts/Event File/event.json

RELEASE_NOTES.md

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
# Eclipse m2e - Release notes
22

3-
## 2.5.1
3+
## 2.6.0
44

55
* 📅 Release Date: _expected_ end February 2024
66

77
### Embedded and use Maven 3.9.6
88

99
Updated the embedded Maven from version 3.9.5 to 3.9.6; [Maven 3.9.6 Release Notes](https://maven.apache.org/docs/3.9.6/release-notes.html).
1010

11-
### New project preference for automated Maven project configuration updates
11+
### Improved toolchain.xml handling
12+
13+
In the Preferences under `Maven -> User Settings` the user `toolchain.xml` used in workspace builds can now be specified explicitly.
14+
At the same time the `maven-toolchains-plugin` is now disabled by default for workspace builds.
15+
16+
### Improved resource linking
17+
18+
Source or resource folders of Maven-projects outside of the project's base directory are now considered in the workspace and are added to the project as linked resources.
19+
20+
### Project preference for automated Maven project configuration updates
1221

1322
Automatic configuration updates for Maven projects can now be disabled the in the project preferences.
1423
This allows to disable these updates individually per project and to store the setting in a preference-file under version control,

org.eclipse.m2e.core.ui/META-INF/MANIFEST.MF

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -56,9 +56,4 @@ Service-Component: OSGI-INF/component.xml,
5656
OSGI-INF/org.eclipse.m2e.core.ui.internal.archetype.ArchetypeGenerator.xml,
5757
OSGI-INF/org.eclipse.m2e.core.ui.internal.archetype.ArchetypePlugin.xml
5858
Automatic-Module-Name: org.eclipse.m2e.core.ui
59-
Service-Component: OSGI-INF/org.eclipse.m2e.core.ui.internal.archetype.ArchetypeGenerator.xml,
60-
OSGI-INF/org.eclipse.m2e.core.ui.internal.archetype.ArchetypePlugin.xml
61-
Bundle-ActivationPolicy: lazy
62-
Service-Component: OSGI-INF/org.eclipse.m2e.core.ui.internal.archetype.ArchetypeGenerator.xml,
63-
OSGI-INF/org.eclipse.m2e.core.ui.internal.archetype.ArchetypePlugin.xml
64-
Bundle-ActivationPolicy: lazy
59+

org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/actions/MavenPropertyTester.java

Lines changed: 5 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,18 +18,18 @@
1818
import org.eclipse.core.resources.IFolder;
1919
import org.eclipse.core.resources.IProject;
2020
import org.eclipse.core.resources.IResource;
21+
import org.eclipse.core.runtime.Adapters;
2122
import org.eclipse.core.runtime.CoreException;
22-
import org.eclipse.core.runtime.IAdaptable;
2323
import org.eclipse.core.runtime.IPath;
2424
import org.eclipse.core.runtime.NullProgressMonitor;
2525
import org.eclipse.ui.IFileEditorInput;
2626

2727
import org.eclipse.m2e.core.MavenPlugin;
2828
import org.eclipse.m2e.core.embedder.ArtifactKey;
2929
import org.eclipse.m2e.core.internal.IMavenConstants;
30+
import org.eclipse.m2e.core.internal.project.ResolverConfigurationIO;
3031
import org.eclipse.m2e.core.project.IMavenProjectFacade;
3132
import org.eclipse.m2e.core.project.IMavenProjectRegistry;
32-
import org.eclipse.m2e.core.project.IProjectConfiguration;
3333
import org.eclipse.m2e.core.project.MavenProjectUtils;
3434

3535

@@ -60,19 +60,11 @@ public class MavenPropertyTester extends PropertyTester {
6060
@Override
6161
public boolean test(Object receiver, String property, Object[] args, Object expectedValue) {
6262
if(WORKSPACE_RESULUTION_ENABLE.equals(property)) {
63-
boolean enableWorkspaceResolution = true;
64-
IAdaptable adaptable = (IAdaptable) receiver;
65-
66-
IProject projectAdapter = adaptable.getAdapter(IProject.class);
63+
IProject projectAdapter = Adapters.adapt(receiver, IProject.class);
6764
if(projectAdapter != null) {
68-
IMavenProjectRegistry projectManager = MavenPlugin.getMavenProjectRegistry();
69-
IMavenProjectFacade projectFacade = projectManager.create(projectAdapter, new NullProgressMonitor());
70-
if(projectFacade != null) {
71-
IProjectConfiguration configuration = projectFacade.getConfiguration();
72-
return !configuration.isResolveWorkspaceProjects();
73-
}
65+
return !ResolverConfigurationIO.isResolveWorkspaceProjects(projectAdapter);
7466
}
75-
return enableWorkspaceResolution;
67+
return true;
7668
}
7769

7870
if(HAS_ARTIFACT_KEY.equals(property)) {

org.eclipse.m2e.core/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ Manifest-Version: 1.0
22
Bundle-ManifestVersion: 2
33
Bundle-Name: %Bundle-Name
44
Bundle-SymbolicName: org.eclipse.m2e.core;singleton:=true
5-
Bundle-Version: 2.4.2.qualifier
5+
Bundle-Version: 2.6.0.qualifier
66
Bundle-Activator: org.eclipse.m2e.core.internal.MavenPluginActivator
77
Bundle-Vendor: %Bundle-Vendor
88
Bundle-Localization: plugin

org.eclipse.m2e.core/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
</parent>
2020

2121
<artifactId>org.eclipse.m2e.core</artifactId>
22-
<version>2.4.2-SNAPSHOT</version>
22+
<version>2.6.0-SNAPSHOT</version>
2323
<packaging>eclipse-plugin</packaging>
2424

2525
<name>Maven Integration for Eclipse Core Plug-in</name>

org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMaven.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,8 @@ <T> T getMojoParameterValue(MavenProject project, String parameter, Class<T> typ
187187
*/
188188
Settings getSettings() throws CoreException;
189189

190+
Settings getSettings(MavenSettingsLocations locations) throws CoreException;
191+
190192
String getLocalRepositoryPath();
191193

192194
ArtifactRepository getLocalRepository() throws CoreException;
@@ -209,6 +211,10 @@ <T> T getMojoParameterValue(MavenProject project, String parameter, Class<T> typ
209211

210212
List<ArtifactRepository> getPluginArtifactRepositories(boolean injectSettings) throws CoreException;
211213

214+
/**
215+
* @deprecated use {@link #getSettings(MavenSettingsLocations)} instead
216+
*/
217+
@Deprecated(forRemoval = true)
212218
Settings buildSettings(String globalSettings, String userSettings) throws CoreException;
213219

214220
void writeSettings(Settings settings, OutputStream out) throws CoreException;

org.eclipse.m2e.core/src/org/eclipse/m2e/core/embedder/IMavenConfiguration.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,8 @@ public interface IMavenConfiguration {
138138
*/
139139
boolean buildWithNullSchedulingRule();
140140

141+
MavenSettingsLocations getSettingsLocations();
142+
141143
static IMavenConfiguration getWorkspaceConfiguration() {
142144
MavenPluginActivator activator = MavenPluginActivator.getDefault();
143145
if(activator == null) {
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/********************************************************************************
2+
* Copyright (c) 2024 Christoph Läubrich and others
3+
*
4+
* This program and the accompanying materials are made available under the
5+
* terms of the Eclipse Public License 2.0 which is available at
6+
* http://www.eclipse.org/legal/epl-2.0.
7+
*
8+
* SPDX-License-Identifier: EPL-2.0
9+
*
10+
* Contributors:
11+
* Christoph Läubrich - initial API and implementation
12+
********************************************************************************/
13+
14+
package org.eclipse.m2e.core.embedder;
15+
16+
import java.io.File;
17+
18+
19+
/**
20+
* This recored encapsulates the combination of a global and a user settings files as defined in
21+
* https://maven.apache.org/settings.html
22+
*/
23+
public record MavenSettingsLocations(File globalSettings, File userSettings) {
24+
25+
}

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

Lines changed: 85 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
import static org.eclipse.m2e.core.internal.M2EUtils.copyProperties;
1818

1919
import java.io.File;
20+
import java.io.IOException;
2021
import java.util.ArrayDeque;
2122
import java.util.Collections;
2223
import java.util.Deque;
@@ -25,6 +26,7 @@
2526
import java.util.List;
2627
import java.util.Map;
2728
import java.util.Objects;
29+
import java.util.Optional;
2830
import java.util.Properties;
2931
import java.util.Set;
3032
import java.util.function.Function;
@@ -73,6 +75,7 @@
7375
import org.eclipse.m2e.core.embedder.IComponentLookup;
7476
import org.eclipse.m2e.core.embedder.IMavenConfiguration;
7577
import org.eclipse.m2e.core.embedder.IMavenExecutionContext;
78+
import org.eclipse.m2e.core.embedder.MavenSettingsLocations;
7679
import org.eclipse.m2e.core.internal.MavenPluginActivator;
7780
import org.eclipse.m2e.core.internal.Messages;
7881

@@ -149,60 +152,73 @@ protected MavenExecutionRequest newExecutionRequest() throws CoreException {
149152
}
150153
request = DefaultMavenExecutionRequest.copy(parent);
151154
}
152-
if(request == null) {
153-
request = createExecutionRequest(IMavenConfiguration.getWorkspaceConfiguration(),
154-
containerLookup, MavenPlugin.getMaven().getSettings());
155-
request.setBaseDirectory(basedir);
155+
if(request == null || !Objects.equals(request.getMultiModuleProjectDirectory(), multiModuleProjectDirectory)) {
156+
IMavenConfiguration workspaceConfiguration = IMavenConfiguration.getWorkspaceConfiguration();
157+
Optional<MavenProperties> mavenArgs;
158+
try {
159+
mavenArgs = MavenProperties.getMavenArgs(multiModuleProjectDirectory);
160+
} catch(IOException ex) {
161+
throw new CoreException(Status.error("Loading maven.config failed!", ex));
162+
}
163+
MavenSettingsLocations mavenSettingsLocations = mavenArgs
164+
.map(mavenCfg -> mavenCfg.getSettingsLocations(workspaceConfiguration))
165+
.orElseGet(workspaceConfiguration::getSettingsLocations);
166+
if(request == null) {
167+
//create a fresh one ....
168+
request = createExecutionRequest(workspaceConfiguration, containerLookup, mavenSettingsLocations,
169+
multiModuleProjectDirectory);
170+
request.setBaseDirectory(basedir);
171+
} else {
172+
//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...
173+
Settings settings = MavenPlugin.getMaven().getSettings(mavenSettingsLocations);
174+
File requestLocalRepositoryPath = request.getLocalRepositoryPath();
175+
File settingsLocalRepositoryPath = getLocalRepositoryPath(settings, multiModuleProjectDirectory);
176+
if(!pathEquals(requestLocalRepositoryPath, settingsLocalRepositoryPath)) {
177+
updateLocalRepository(request, settingsLocalRepositoryPath, containerLookup);
178+
}
179+
//TODO maybe also need to update user properties?!?
180+
updateSettingsFiles(request, mavenSettingsLocations);
181+
request.setMultiModuleProjectDirectory(multiModuleProjectDirectory);
182+
}
156183
}
157-
request.setMultiModuleProjectDirectory(multiModuleProjectDirectory);
158-
159184
return request;
160185
}
161186

187+
private boolean pathEquals(File file1, File file2) {
188+
if(Objects.equals(file1, file2)) {
189+
return true;
190+
}
191+
if(file1 != null && file2 != null) {
192+
try {
193+
return Objects.equals(file1.getCanonicalFile(), file2.getCanonicalFile());
194+
} catch(IOException ex) {
195+
//can't compare then...
196+
}
197+
}
198+
return false;
199+
}
200+
162201
static MavenExecutionRequest createExecutionRequest(IMavenConfiguration mavenConfiguration, IComponentLookup lookup,
163-
Settings settings) throws CoreException {
202+
MavenSettingsLocations settingsLocations, File multiModuleProjectDirectory) throws CoreException {
164203
MavenExecutionRequest request = new DefaultMavenExecutionRequest();
165-
166204
// this causes problems with unexpected "stale project configuration" error markers
167205
// need to think how to manage ${maven.build.timestamp} properly inside workspace
168206
//request.setStartTime( new Date() );
169-
170-
if(mavenConfiguration.getGlobalSettingsFile() != null) {
171-
request.setGlobalSettingsFile(new File(mavenConfiguration.getGlobalSettingsFile()));
172-
}
173-
File userSettingsFile = SettingsXmlConfigurationProcessor.DEFAULT_USER_SETTINGS_FILE;
174-
if(mavenConfiguration.getUserSettingsFile() != null) {
175-
userSettingsFile = new File(mavenConfiguration.getUserSettingsFile());
176-
}
177-
request.setUserSettingsFile(userSettingsFile);
178-
207+
Settings settings = MavenPlugin.getMaven().getSettings(settingsLocations);
208+
updateSettingsFiles(request, settingsLocations);
179209
//and settings are actually derived from IMavenConfiguration
180-
181210
File userToolchainsFile = MavenCli.DEFAULT_USER_TOOLCHAINS_FILE;
182211
if(mavenConfiguration.getUserToolchainsFile() != null) {
183212
userToolchainsFile = new File(mavenConfiguration.getUserToolchainsFile());
184213
}
185214
request.setUserToolchainsFile(userToolchainsFile);
186-
187215
try {
188216
request = lookup.lookup(MavenExecutionRequestPopulator.class).populateFromSettings(request, settings);
189217
} catch(MavenExecutionRequestPopulationException ex) {
190218
throw new CoreException(Status.error(Messages.MavenImpl_error_no_exec_req, ex));
191219
}
192220

193-
String localRepositoryPath = settings.getLocalRepository();
194-
if(localRepositoryPath == null) {
195-
localRepositoryPath = RepositorySystem.defaultUserLocalRepository.getAbsolutePath();
196-
}
197-
198-
ArtifactRepository localRepository;
199-
try {
200-
localRepository = lookup.lookup(RepositorySystem.class).createLocalRepository(new File(localRepositoryPath));
201-
} catch(InvalidRepositoryException ex) {
202-
throw new AssertionError("Should never happen!", ex);
203-
}
204-
request.setLocalRepository(localRepository);
205-
request.setLocalRepositoryPath(localRepository.getBasedir());
221+
updateLocalRepository(request, getLocalRepositoryPath(settings, multiModuleProjectDirectory), lookup);
206222
request.setOffline(mavenConfiguration.isOffline());
207223

208224
request.getUserProperties().put("m2e.version", MavenPluginActivator.getVersion()); //$NON-NLS-1$
@@ -214,9 +230,45 @@ static MavenExecutionRequest createExecutionRequest(IMavenConfiguration mavenCon
214230
request.setCacheTransferError(true);
215231

216232
request.setGlobalChecksumPolicy(mavenConfiguration.getGlobalChecksumPolicy());
233+
request.setMultiModuleProjectDirectory(multiModuleProjectDirectory);
217234
return request;
218235
}
219236

237+
private static void updateSettingsFiles(MavenExecutionRequest request, MavenSettingsLocations settingsLocations) {
238+
File global = settingsLocations.globalSettings();
239+
if(global != null) {
240+
request.setGlobalSettingsFile(global);
241+
}
242+
File userSettingsFile = settingsLocations.userSettings();
243+
if(userSettingsFile == null) {
244+
request.setUserSettingsFile(SettingsXmlConfigurationProcessor.DEFAULT_USER_SETTINGS_FILE);
245+
} else {
246+
request.setUserSettingsFile(userSettingsFile);
247+
}
248+
}
249+
250+
private static void updateLocalRepository(MavenExecutionRequest request, File localRepositoryPath,
251+
IComponentLookup lookup) throws CoreException, AssertionError {
252+
ArtifactRepository localRepository;
253+
try {
254+
localRepository = lookup.lookup(RepositorySystem.class).createLocalRepository(localRepositoryPath);
255+
} catch(InvalidRepositoryException ex) {
256+
throw new AssertionError("Should never happen!", ex);
257+
}
258+
request.setLocalRepository(localRepository);
259+
request.setLocalRepositoryPath(localRepository.getBasedir());
260+
}
261+
262+
private static File getLocalRepositoryPath(Settings settings, File multiModuleProjectDirectory) {
263+
String localRepositoryPath = settings.getLocalRepository();
264+
if(localRepositoryPath == null) {
265+
return RepositorySystem.defaultUserLocalRepository;
266+
}
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();
270+
}
271+
220272
@Override
221273
public <V> V execute(ICallable<V> callable, IProgressMonitor monitor) throws CoreException {
222274
return execute(null, callable, monitor);

0 commit comments

Comments
 (0)