Skip to content

Commit 40eeb6e

Browse files
committed
Use a MavenCLICompat for constants
1 parent b876dfe commit 40eeb6e

File tree

6 files changed

+128
-92
lines changed

6 files changed

+128
-92
lines changed

org.eclipse.m2e.core.ui/src/org/eclipse/m2e/core/ui/internal/preferences/MavenSettingsPreferencePage.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import org.eclipse.jface.dialogs.IMessageProvider;
3535
import org.eclipse.jface.dialogs.MessageDialog;
3636
import org.eclipse.jface.preference.PreferencePage;
37+
import org.eclipse.osgi.container.Module.Settings;
3738
import org.eclipse.osgi.util.NLS;
3839
import org.eclipse.swt.SWT;
3940
import org.eclipse.swt.events.SelectionListener;
@@ -59,16 +60,15 @@
5960
import org.eclipse.ui.ide.IDE;
6061

6162
import org.apache.maven.building.Problem;
62-
import org.apache.maven.cli.MavenCli;
6363
import org.apache.maven.cli.configuration.SettingsXmlConfigurationProcessor;
6464
import org.apache.maven.repository.RepositorySystem;
65-
import org.apache.maven.settings.Settings;
6665
import org.apache.maven.settings.building.SettingsProblem;
6766

6867
import org.eclipse.m2e.core.MavenPlugin;
6968
import org.eclipse.m2e.core.embedder.IMaven;
7069
import org.eclipse.m2e.core.embedder.IMavenConfiguration;
7170
import org.eclipse.m2e.core.internal.IMavenToolbox;
71+
import org.eclipse.m2e.core.internal.embedder.MavenCLICompat;
7272
import org.eclipse.m2e.core.project.IMavenProjectFacade;
7373
import org.eclipse.m2e.core.project.MavenUpdateRequest;
7474
import org.eclipse.m2e.core.ui.internal.Messages;
@@ -210,9 +210,9 @@ protected Control createContents(Composite parent) {
210210

211211
userToolchainsLink = createLink(composite, Messages.MavenSettingsPreferencePage_userToolchainslink2,
212212
Messages.MavenSettingsPreferencePage_userToolchainslink_tooltip, this::getUserToolchains,
213-
MavenCli.DEFAULT_USER_TOOLCHAINS_FILE);
213+
MavenCLICompat.DEFAULT_USER_TOOLCHAINS_FILE);
214214
userToolchainsText = createFileSelectionWidgets(composite, mavenConfiguration.getUserToolchainsFile(),
215-
MavenCli.DEFAULT_USER_TOOLCHAINS_FILE);
215+
MavenCLICompat.DEFAULT_USER_TOOLCHAINS_FILE);
216216

217217
Button updateSettings = new Button(composite, SWT.NONE);
218218
updateSettings.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1));
@@ -310,7 +310,7 @@ protected void checkSettings() {
310310
Messages.MavenSettingsPreferencePage_userSettingslink2, Messages.MavenSettingsPreferencePage_userSettingslink1);
311311

312312
String userToolchains = getUserToolchains();
313-
updateLink(userToolchainsLink, userToolchains, MavenCli.DEFAULT_USER_TOOLCHAINS_FILE,
313+
updateLink(userToolchainsLink, userToolchains, MavenCLICompat.DEFAULT_USER_TOOLCHAINS_FILE,
314314
Messages.MavenSettingsPreferencePage_userToolchainslink2,
315315
Messages.MavenSettingsPreferencePage_userToolchainslink1);
316316

org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/MavenPluginActivator.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,6 @@
3232

3333
import org.codehaus.plexus.PlexusContainer;
3434

35-
import org.apache.maven.project.DefaultProjectBuilder;
36-
3735
import org.eclipse.m2e.core.embedder.IMaven;
3836
import org.eclipse.m2e.core.embedder.IMavenConfiguration;
3937
import org.eclipse.m2e.core.embedder.MavenModelManager;
@@ -101,7 +99,8 @@ public void start(final BundleContext context) throws Exception {
10199
}
102100

103101
// Workaround MNG-6530
104-
System.setProperty(DefaultProjectBuilder.DISABLE_GLOBAL_MODEL_CACHE_SYSTEM_PROPERTY, Boolean.toString(true));
102+
//TODO is this still working for maven4?
103+
System.setProperty("maven.defaultProjectBuilder.disableGlobalModelCache", Boolean.toString(true));
105104
URLConnectionCaches.disable();
106105
// For static access, this also enables any of the services and keep them running forever...
107106
this.bundleContext = context;
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one
3+
* or more contributor license agreements. See the NOTICE file
4+
* distributed with this work for additional information
5+
* regarding copyright ownership. The ASF licenses this file
6+
* to you under the Apache License, Version 2.0 (the
7+
* "License"); you may not use this file except in compliance
8+
* with the License. You may obtain a copy of the License at
9+
*
10+
* http://www.apache.org/licenses/LICENSE-2.0
11+
*
12+
* Unless required by applicable law or agreed to in writing,
13+
* software distributed under the License is distributed on an
14+
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15+
* KIND, either express or implied. See the License for the
16+
* specific language governing permissions and limitations
17+
* under the License.
18+
*/
19+
20+
package org.eclipse.m2e.core.internal.embedder;
21+
22+
import java.io.File;
23+
24+
25+
/**
26+
* Some constants copied here for backward compatibility
27+
*/
28+
public class MavenCLICompat {
29+
public static final String LOCAL_REPO_PROPERTY = "maven.repo.local";
30+
31+
public static final String MULTIMODULE_PROJECT_DIRECTORY = "maven.multiModuleProjectDirectory";
32+
33+
public static final String USER_HOME = System.getProperty("user.home");
34+
35+
public static final File USER_MAVEN_CONFIGURATION_HOME = new File(USER_HOME, ".m2");
36+
37+
public static final File DEFAULT_USER_TOOLCHAINS_FILE = new File(USER_MAVEN_CONFIGURATION_HOME, "toolchains.xml");
38+
39+
public static final File DEFAULT_GLOBAL_TOOLCHAINS_FILE = new File(System.getProperty("maven.conf"),
40+
"toolchains.xml");
41+
}

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

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,6 @@
4646
import org.apache.maven.artifact.Artifact;
4747
import org.apache.maven.artifact.InvalidRepositoryException;
4848
import org.apache.maven.artifact.repository.ArtifactRepository;
49-
import org.apache.maven.cli.MavenCli;
5049
import org.apache.maven.cli.configuration.SettingsXmlConfigurationProcessor;
5150
import org.apache.maven.eventspy.internal.EventSpyDispatcher;
5251
import org.apache.maven.execution.DefaultMavenExecutionRequest;
@@ -210,7 +209,7 @@ static MavenExecutionRequest createExecutionRequest(IMavenConfiguration mavenCon
210209
Settings settings = MavenPlugin.getMaven().getSettings(settingsLocations);
211210
updateSettingsFiles(request, settingsLocations);
212211
//and settings are actually derived from IMavenConfiguration
213-
File userToolchainsFile = MavenCli.DEFAULT_USER_TOOLCHAINS_FILE;
212+
File userToolchainsFile = MavenCLICompat.DEFAULT_USER_TOOLCHAINS_FILE;
214213
if(mavenConfiguration.getUserToolchainsFile() != null) {
215214
userToolchainsFile = new File(mavenConfiguration.getUserToolchainsFile());
216215
}

org.eclipse.m2e.jdt/src/org/eclipse/m2e/jdt/LookupJDKToolchainsJob.java

Lines changed: 79 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
*
88
* SPDX-License-Identifier: EPL-2.0
99
********************************************************************************/
10+
1011
package org.eclipse.m2e.jdt;
1112

1213
import java.io.File;
@@ -17,13 +18,6 @@
1718
import java.util.Optional;
1819
import java.util.stream.Stream;
1920

20-
import org.apache.maven.cli.MavenCli;
21-
import org.apache.maven.toolchain.io.DefaultToolchainsReader;
22-
import org.apache.maven.toolchain.io.ToolchainsReader;
23-
import org.apache.maven.toolchain.java.JavaToolchainImpl;
24-
import org.apache.maven.toolchain.model.PersistedToolchains;
25-
import org.apache.maven.toolchain.model.ToolchainModel;
26-
import org.codehaus.plexus.util.xml.Xpp3Dom;
2721
import org.eclipse.core.runtime.IProgressMonitor;
2822
import org.eclipse.core.runtime.IStatus;
2923
import org.eclipse.core.runtime.Status;
@@ -35,86 +29,90 @@
3529
import org.eclipse.jdt.launching.JavaRuntime;
3630
import org.eclipse.jdt.launching.VMStandin;
3731

32+
import org.codehaus.plexus.util.xml.Xpp3Dom;
33+
34+
import org.apache.maven.toolchain.io.DefaultToolchainsReader;
35+
import org.apache.maven.toolchain.io.ToolchainsReader;
36+
import org.apache.maven.toolchain.java.JavaToolchainImpl;
37+
import org.apache.maven.toolchain.model.PersistedToolchains;
38+
import org.apache.maven.toolchain.model.ToolchainModel;
39+
40+
import org.eclipse.m2e.core.internal.embedder.MavenCLICompat;
41+
42+
3843
public class LookupJDKToolchainsJob extends Job {
3944

40-
private final IVMInstallType standardType;
45+
private final IVMInstallType standardType;
4146

42-
public LookupJDKToolchainsJob() {
43-
super(LookupJDKToolchainsJob.class.getSimpleName());
44-
this.standardType = JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
45-
}
47+
public LookupJDKToolchainsJob() {
48+
super(LookupJDKToolchainsJob.class.getSimpleName());
49+
this.standardType = JavaRuntime.getVMInstallType(StandardVMType.ID_STANDARD_VM_TYPE);
50+
}
4651

47-
@Override
48-
protected IStatus run(IProgressMonitor monitor) {
49-
List<File> toolchainFiles = List.of(MavenCli.DEFAULT_GLOBAL_TOOLCHAINS_FILE, MavenCli.DEFAULT_USER_TOOLCHAINS_FILE);
50-
ToolchainsReader reader = new DefaultToolchainsReader();
51-
for (File toolchainsFile : toolchainFiles) {
52-
if (toolchainsFile.isFile() && toolchainsFile.canRead()) {
53-
try {
54-
PersistedToolchains toolchains = reader.read(toolchainsFile, null);
55-
for (ToolchainModel toolchain : toolchains.getToolchains()) {
56-
if (monitor.isCanceled()) {
57-
return Status.CANCEL_STATUS;
58-
}
59-
addToolchain(toolchain);
60-
}
61-
} catch(Exception e) {
62-
return Status.error(e.getMessage(), e);
63-
}
64-
}
65-
}
66-
return Status.OK_STATUS;
67-
}
52+
@Override
53+
protected IStatus run(IProgressMonitor monitor) {
54+
List<File> toolchainFiles = List.of(MavenCLICompat.DEFAULT_GLOBAL_TOOLCHAINS_FILE,
55+
MavenCLICompat.DEFAULT_USER_TOOLCHAINS_FILE);
56+
ToolchainsReader reader = new DefaultToolchainsReader();
57+
for(File toolchainsFile : toolchainFiles) {
58+
if(toolchainsFile.isFile() && toolchainsFile.canRead()) {
59+
try {
60+
PersistedToolchains toolchains = reader.read(toolchainsFile, null);
61+
for(ToolchainModel toolchain : toolchains.getToolchains()) {
62+
if(monitor.isCanceled()) {
63+
return Status.CANCEL_STATUS;
64+
}
65+
addToolchain(toolchain);
66+
}
67+
} catch(Exception e) {
68+
return Status.error(e.getMessage(), e);
69+
}
70+
}
71+
}
72+
return Status.OK_STATUS;
73+
}
6874

69-
private Optional<File> getVMInstallation(ToolchainModel toolchain) {
70-
return Optional.ofNullable(toolchain)
71-
.filter(t -> "jdk".equals(t.getType()))
72-
.map(ToolchainModel::getConfiguration)
73-
.filter(Xpp3Dom.class::isInstance)
74-
.map(Xpp3Dom.class::cast)
75-
.map(dom -> dom.getChild(JavaToolchainImpl.KEY_JAVAHOME))
76-
.map(Xpp3Dom::getValue)
77-
.map(File::new)
78-
.filter(File::isDirectory);
79-
}
75+
private Optional<File> getVMInstallation(ToolchainModel toolchain) {
76+
return Optional.ofNullable(toolchain).filter(t -> "jdk".equals(t.getType())).map(ToolchainModel::getConfiguration)
77+
.filter(Xpp3Dom.class::isInstance).map(Xpp3Dom.class::cast)
78+
.map(dom -> dom.getChild(JavaToolchainImpl.KEY_JAVAHOME)).map(Xpp3Dom::getValue).map(File::new)
79+
.filter(File::isDirectory);
80+
}
8081

81-
private void addToolchain(ToolchainModel toolchain) {
82-
getVMInstallation(toolchain)
83-
.filter(f -> standardType.validateInstallLocation(f).isOK())
84-
.ifPresent(candidate -> {
85-
if (Arrays.stream(standardType.getVMInstalls()) //
86-
.map(IVMInstall::getInstallLocation) //
87-
.filter(Objects::nonNull)
88-
.noneMatch(install -> isSameCanonicalFile(candidate, install))) {
89-
VMStandin workingCopy = new VMStandin(standardType, candidate.getAbsolutePath());
90-
workingCopy.setInstallLocation(candidate);
91-
String name = candidate.getName();
92-
int i = 1;
93-
while (isDuplicateName(name)) {
94-
name = candidate.getName() + '(' + i++ + ')';
95-
}
96-
workingCopy.setName(name);
97-
IVMInstall newVM = workingCopy.convertToRealVM();
98-
// next lines workaround https://github.com/eclipse-jdt/eclipse.jdt.debug/issues/248
99-
if (!(newVM instanceof IVMInstall2 newVM2 && newVM2.getJavaVersion() != null)) {
100-
standardType.disposeVMInstall(newVM.getId());
101-
}
102-
}
103-
});
104-
}
82+
private void addToolchain(ToolchainModel toolchain) {
83+
getVMInstallation(toolchain).filter(f -> standardType.validateInstallLocation(f).isOK()).ifPresent(candidate -> {
84+
if(Arrays.stream(standardType.getVMInstalls()) //
85+
.map(IVMInstall::getInstallLocation) //
86+
.filter(Objects::nonNull).noneMatch(install -> isSameCanonicalFile(candidate, install))) {
87+
VMStandin workingCopy = new VMStandin(standardType, candidate.getAbsolutePath());
88+
workingCopy.setInstallLocation(candidate);
89+
String name = candidate.getName();
90+
int i = 1;
91+
while(isDuplicateName(name)) {
92+
name = candidate.getName() + '(' + i++ + ')';
93+
}
94+
workingCopy.setName(name);
95+
IVMInstall newVM = workingCopy.convertToRealVM();
96+
// next lines workaround https://github.com/eclipse-jdt/eclipse.jdt.debug/issues/248
97+
if(!(newVM instanceof IVMInstall2 newVM2 && newVM2.getJavaVersion() != null)) {
98+
standardType.disposeVMInstall(newVM.getId());
99+
}
100+
}
101+
});
102+
}
105103

106-
private static boolean isDuplicateName(String name) {
107-
return Stream.of(JavaRuntime.getVMInstallTypes()) //
108-
.flatMap(vmType -> Arrays.stream(vmType.getVMInstalls())) //
109-
.map(IVMInstall::getName) //
110-
.anyMatch(name::equals);
111-
}
104+
private static boolean isDuplicateName(String name) {
105+
return Stream.of(JavaRuntime.getVMInstallTypes()) //
106+
.flatMap(vmType -> Arrays.stream(vmType.getVMInstalls())) //
107+
.map(IVMInstall::getName) //
108+
.anyMatch(name::equals);
109+
}
112110

113-
private static boolean isSameCanonicalFile(File f1, File f2) {
114-
try {
115-
return Objects.equals(f1.getCanonicalFile(), f2.getCanonicalFile());
116-
} catch (IOException ex) {
117-
return false;
118-
}
119-
}
111+
private static boolean isSameCanonicalFile(File f1, File f2) {
112+
try {
113+
return Objects.equals(f1.getCanonicalFile(), f2.getCanonicalFile());
114+
} catch(IOException ex) {
115+
return false;
116+
}
117+
}
120118
}

org.eclipse.m2e.maven.runtime/pom.xml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,6 @@
6666
<dependency>
6767
<groupId>org.apache.maven</groupId>
6868
<artifactId>maven-compat</artifactId>
69-
<version>${maven-core.version}</version>
7069
</dependency>
7170
<dependency>
7271
<groupId>org.eclipse.sisu</groupId>

0 commit comments

Comments
 (0)