Skip to content

Commit 01a6387

Browse files
committed
Move org.eclipse.m2e.core to Java 17
+ Adopt named instanceof + adopt switch-expressions + Use Objects.equals/hash
1 parent 53a40c8 commit 01a6387

32 files changed

+134
-226
lines changed

org.eclipse.m2e.core/.classpath

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<classpath>
3-
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-11">
3+
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
44
<attributes>
55
<attribute name="module" value="true"/>
66
</attributes>

org.eclipse.m2e.core/.settings/org.eclipse.jdt.core.prefs

+3-3
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ org.eclipse.jdt.core.compiler.annotation.nullable.secondary=
2929
org.eclipse.jdt.core.compiler.annotation.nullanalysis=disabled
3030
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
3131
org.eclipse.jdt.core.compiler.codegen.methodParameters=do not generate
32-
org.eclipse.jdt.core.compiler.codegen.targetPlatform=11
32+
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
3333
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
34-
org.eclipse.jdt.core.compiler.compliance=11
34+
org.eclipse.jdt.core.compiler.compliance=17
3535
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
3636
org.eclipse.jdt.core.compiler.debug.localVariable=generate
3737
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
@@ -146,7 +146,7 @@ org.eclipse.jdt.core.compiler.problem.unusedTypeParameter=warning
146146
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
147147
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
148148
org.eclipse.jdt.core.compiler.release=enabled
149-
org.eclipse.jdt.core.compiler.source=11
149+
org.eclipse.jdt.core.compiler.source=17
150150
org.eclipse.jdt.core.compiler.taskCaseSensitive=enabled
151151
org.eclipse.jdt.core.compiler.taskPriorities=NORMAL,HIGH,HIGH
152152
org.eclipse.jdt.core.compiler.taskTags=TODO,FIXME,XXX

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ Require-Bundle: org.eclipse.osgi;bundle-version="3.10.0",
1515
org.eclipse.core.filesystem;bundle-version="1.7.700",
1616
org.apache.commons.codec;bundle-version="1.14.0"
1717
Bundle-ActivationPolicy: lazy
18-
Bundle-RequiredExecutionEnvironment: JavaSE-11
18+
Bundle-RequiredExecutionEnvironment: JavaSE-17
1919
Export-Package: org.eclipse.m2e.core,
2020
org.eclipse.m2e.core.archetype;x-friends:="org.eclipse.m2e.core.ui",
2121
org.eclipse.m2e.core.embedder,

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

+8-18
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package org.eclipse.m2e.core.embedder;
1515

1616
import java.io.Serializable;
17+
import java.util.Objects;
1718

1819
import org.eclipse.osgi.util.NLS;
1920

@@ -53,26 +54,15 @@ public ArtifactKey(String groupId, String artifactId, String version, String cla
5354
public boolean equals(Object o) {
5455
if(this == o)
5556
return true;
56-
if(o instanceof ArtifactKey) {
57-
ArtifactKey other = (ArtifactKey) o;
58-
return equals(groupId, other.groupId) && equals(artifactId, other.artifactId) && equals(version, other.version)
59-
&& equals(classifier, other.classifier);
60-
}
61-
return false;
57+
return o instanceof ArtifactKey other && //
58+
59+
Objects.equals(groupId, other.groupId) && Objects.equals(artifactId, other.artifactId)
60+
&& Objects.equals(version, other.version) && Objects.equals(classifier, other.classifier);
6261
}
6362

6463
@Override
6564
public int hashCode() {
66-
int hash = 17;
67-
hash = hash * 31 + (groupId != null ? groupId.hashCode() : 0);
68-
hash = hash * 31 + (artifactId != null ? artifactId.hashCode() : 0);
69-
hash = hash * 31 + (version != null ? version.hashCode() : 0);
70-
hash = hash * 31 + (classifier != null ? classifier.hashCode() : 0);
71-
return hash;
72-
}
73-
74-
private static boolean equals(Object o1, Object o2) {
75-
return o1 == null ? o2 == null : o1.equals(o2);
65+
return Objects.hash(groupId, artifactId, version, classifier);
7666
}
7767

7868
// XXX this method does not belong here, it compares versions, while ArtifactKey uses baseVersions in many cases
@@ -83,8 +73,8 @@ public static boolean equals(Artifact a1, Artifact a2) {
8373
if(a2 == null) {
8474
return false;
8575
}
86-
return equals(a1.getGroupId(), a2.getGroupId()) && equals(a1.getArtifactId(), a2.getArtifactId())
87-
&& equals(a1.getVersion(), a2.getVersion()) && equals(a1.getClassifier(), a2.getClassifier());
76+
return Objects.equals(a1.getGroupId(), a2.getGroupId()) && Objects.equals(a1.getArtifactId(), a2.getArtifactId())
77+
&& Objects.equals(a1.getVersion(), a2.getVersion()) && Objects.equals(a1.getClassifier(), a2.getClassifier());
8878
}
8979

9080
@Override

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

+4-14
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
package org.eclipse.m2e.core.embedder;
1515

1616
import java.io.Serializable;
17+
import java.util.Objects;
1718

1819
import org.apache.maven.artifact.repository.ArtifactRepository;
1920

@@ -48,26 +49,15 @@ public String getUsername() {
4849

4950
@Override
5051
public int hashCode() {
51-
int hash = 17;
52-
hash = hash * 31 + (id != null ? id.hashCode() : 0);
53-
hash = hash * 31 + (url != null ? url.hashCode() : 0);
54-
hash = hash * 31 + (username != null ? username.hashCode() : 0);
55-
return hash;
52+
return Objects.hash(id, url, username);
5653
}
5754

5855
@Override
5956
public boolean equals(Object o) {
6057
if(o == this) {
6158
return true;
6259
}
63-
if(!(o instanceof ArtifactRepositoryRef)) {
64-
return false;
65-
}
66-
ArtifactRepositoryRef other = (ArtifactRepositoryRef) o;
67-
return eq(id, other.id) && eq(url, other.url) && eq(username, other.username);
68-
}
69-
70-
private static <T> boolean eq(T a, T b) {
71-
return a != null ? a.equals(b) : b == null;
60+
return o instanceof ArtifactRepositoryRef other && //
61+
Objects.equals(id, other.id) && Objects.equals(url, other.url) && Objects.equals(username, other.username);
7262
}
7363
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -114,8 +114,8 @@ public static IFile getPomFile(MavenProject project) {
114114
}
115115
while(path.segmentCount() > 1) {
116116
IResource ires = ResourcesPlugin.getWorkspace().getRoot().findMember(path);
117-
if(ires instanceof IFile) {
118-
stack.push((IFile) ires);
117+
if(ires instanceof IFile f) {
118+
stack.push(f);
119119
}
120120
path = path.removeFirstSegments(1);
121121
}

org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/MavenBuilderImpl.java

+4-4
Original file line numberDiff line numberDiff line change
@@ -126,8 +126,8 @@ public Set<IProject> build(MavenSession session, IMavenProjectFacade projectFaca
126126
participant.setGetDeltaCallback(getDeltaProvider());
127127
participant.setSession(session);
128128
participant.setBuildContext((AbstractEclipseBuildContext) incrementalContexts.get(0));
129-
if(participant instanceof InternalBuildParticipant2) {
130-
((InternalBuildParticipant2) participant).setArgs(args);
129+
if(participant instanceof InternalBuildParticipant2 participant2) {
130+
participant2.setArgs(args);
131131
}
132132
long executionStartTime = System.currentTimeMillis();
133133
try {
@@ -146,8 +146,8 @@ public Set<IProject> build(MavenSession session, IMavenProjectFacade projectFaca
146146
participant.setGetDeltaCallback(null);
147147
participant.setSession(null);
148148
participant.setBuildContext(null);
149-
if(participant instanceof InternalBuildParticipant2) {
150-
((InternalBuildParticipant2) participant).setArgs(Collections.<String, String> emptyMap());
149+
if(participant instanceof InternalBuildParticipant2 participant2) {
150+
participant2.setArgs(Collections.<String, String> emptyMap());
151151
}
152152

153153
processMavenSessionErrors(session, mojoExecutionKey, buildErrors);

org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/builder/plexusbuildapi/AbstractEclipseBuildContext.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -74,8 +74,8 @@ protected IResource getResource(File file) {
7474
return null;
7575
}
7676
IResource baseResource = getBaseResource();
77-
if(baseResource instanceof IContainer) {
78-
return ((IContainer) baseResource).findMember(relpath);
77+
if(baseResource instanceof IContainer container) {
78+
return container.findMember(relpath);
7979
}
8080
return null;
8181
}

org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/AbstractMavenRuntime.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -91,8 +91,8 @@ protected void collectExtensions(IMavenLauncherConfiguration collector, IProgres
9191
if(extensions != null) {
9292
IMavenProjectRegistry registry = MavenPlugin.getMavenProjectRegistry();
9393
for(ClasspathEntry entry : extensions) {
94-
if(entry instanceof ProjectClasspathEntry) {
95-
collectProject(collector, (ProjectClasspathEntry) entry, registry, monitor);
94+
if(entry instanceof ProjectClasspathEntry projectClasspathEntry) {
95+
collectProject(collector, projectClasspathEntry, registry, monitor);
9696
}
9797
}
9898
}

org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/ClasspathEntry.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
*/
2121
public abstract class ClasspathEntry {
2222
public String toExternalForm() {
23-
if(this instanceof ProjectClasspathEntry) {
24-
return "P/" + ((ProjectClasspathEntry) this).getProject();
23+
if(this instanceof ProjectClasspathEntry projectClasspathEntry) {
24+
return "P/" + projectClasspathEntry.getProject();
2525
}
2626
throw new IllegalArgumentException();
2727
}

org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/launch/MavenExternalRuntime.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,8 @@ public void setAppMain(String mainClassName, String mainRealmName) {
147147
try (FileInputStream is = new FileInputStream(getLauncherConfigurationFile())) {
148148
parser.parse(is);
149149
} catch(Exception e) {
150-
if(e instanceof ExceptionWrapper && e.getCause() instanceof CoreException) {
151-
throw (CoreException) e.getCause();
150+
if(e instanceof ExceptionWrapper && e.getCause() instanceof CoreException coreException) {
151+
throw coreException;
152152
}
153153
throw new CoreException(Status.error(Messages.MavenExternalRuntime_error_cannot_parse, e));
154154
}

org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/AnnotationMappingMetadataSource.java

+11-14
Original file line numberDiff line numberDiff line change
@@ -247,21 +247,19 @@ private static Xpp3Dom parse(String pi) {
247247
if(a == null) {
248248
return null;
249249
}
250-
switch(a) {
251-
case ignore:
252-
return new Xpp3Dom("ignore"); //$NON-NLS-1$
253-
254-
case configurator:
250+
return switch(a) {
251+
case ignore -> new Xpp3Dom("ignore"); //$NON-NLS-1$
252+
case configurator -> {
255253
if(split.size() != 2) {
256-
return null;
254+
yield null;
257255
}
258256
Xpp3Dom conf = new Xpp3Dom("configurator"); //$NON-NLS-1$
259257
Xpp3Dom id = new Xpp3Dom("id"); //$NON-NLS-1$
260258
id.setValue(split.get(1));
261259
conf.addChild(id);
262-
return conf;
263-
264-
case execute:
260+
yield conf;
261+
}
262+
case execute -> {
265263
Xpp3Dom exec = new Xpp3Dom("execute"); //$NON-NLS-1$
266264
if(split.size() > 1) {
267265
EXECUTE_SPLITTER.splitAsStream(split.get(1)).map(String::strip).map(EXECUTE_OPTIONS::get)
@@ -271,11 +269,10 @@ private static Xpp3Dom parse(String pi) {
271269
exec.addChild(opt);
272270
});
273271
}
274-
return exec;
275-
276-
default:
277-
return null;
278-
}
272+
yield exec;
273+
}
274+
default -> null;
275+
};
279276
}
280277

281278
private static PluginExecutionAction getAction(String value) {

org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/LifecycleMappingFactory.java

+5-9
Original file line numberDiff line numberDiff line change
@@ -758,15 +758,11 @@ private static List<PluginExecutionMetadata> applyParametersFilter(List<PluginEx
758758
}
759759

760760
private static boolean isValidPluginExecutionMetadata(PluginExecutionMetadata metadata) {
761-
switch(metadata.getAction()) {
762-
case error:
763-
case execute:
764-
case ignore:
765-
return true;
766-
case configurator:
767-
return isConfigurator(metadata);
768-
}
769-
return false;
761+
return switch(metadata.getAction()) {
762+
case error, execute, ignore -> true;
763+
case configurator -> isConfigurator(metadata);
764+
default -> false;
765+
};
770766
}
771767

772768
static boolean isConfigurator(PluginExecutionMetadata metadata) {

org.eclipse.m2e.core/src/org/eclipse/m2e/core/internal/lifecyclemapping/discovery/MojoExecutionMappingConfiguration.java

+25-43
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@
1414

1515
package org.eclipse.m2e.core.internal.lifecyclemapping.discovery;
1616

17+
import java.util.Objects;
18+
1719
import org.eclipse.core.runtime.Assert;
1820

1921
import org.eclipse.m2e.core.internal.lifecyclemapping.LifecycleMappingFactory;
@@ -67,14 +69,7 @@ public boolean equals(Object obj) {
6769
return true;
6870
}
6971

70-
if(!(obj instanceof MojoExecutionMappingRequirement)) {
71-
return false;
72-
}
73-
74-
MojoExecutionMappingRequirement other = (MojoExecutionMappingRequirement) obj;
75-
76-
return execution.equals(other.execution);
77-
72+
return obj instanceof MojoExecutionMappingRequirement other && execution.equals(other.execution);
7873
}
7974

8075
/**
@@ -118,13 +113,8 @@ public boolean equals(Object obj) {
118113
return true;
119114
}
120115

121-
if(!(obj instanceof ProjectConfiguratorMappingRequirement)) {
122-
return false;
123-
}
124-
125-
ProjectConfiguratorMappingRequirement other = (ProjectConfiguratorMappingRequirement) obj;
126-
127-
return configuratorId.equals(other.configuratorId) && execution.equals(other.execution);
116+
return obj instanceof ProjectConfiguratorMappingRequirement other && configuratorId.equals(other.configuratorId)
117+
&& execution.equals(other.execution);
128118
}
129119

130120
public MojoExecutionKey getExecution() {
@@ -212,39 +202,31 @@ public boolean equals(Object obj) {
212202
if(this == obj) {
213203
return true;
214204
}
215-
if(!(obj instanceof MojoExecutionMappingConfiguration)) {
216-
return false;
217-
}
218-
MojoExecutionMappingConfiguration other = (MojoExecutionMappingConfiguration) obj;
219-
220-
if(!execution.equals(other.execution)) {
221-
return false;
222-
}
223-
224-
if(mapping == null) {
225-
return other.mapping == null;
226-
}
227-
228-
if(other.mapping == null) {
229-
return false;
230-
}
205+
if(obj instanceof MojoExecutionMappingConfiguration other) {
206+
if(!execution.equals(other.execution)) {
207+
return false;
208+
}
231209

232-
if(mapping.getAction() != other.mapping.getAction()) {
233-
return false;
234-
}
210+
if(mapping == null) {
211+
return other.mapping == null;
212+
}
235213

236-
if(mapping.getAction() == PluginExecutionAction.configurator) {
237-
String configuratorId = LifecycleMappingFactory.getProjectConfiguratorId(mapping);
238-
String otherConfiguratorId = LifecycleMappingFactory.getProjectConfiguratorId(other.mapping);
239-
if(!eq(configuratorId, otherConfiguratorId)) {
214+
if(other.mapping == null) {
240215
return false;
241216
}
242-
}
243217

244-
return true;
245-
}
218+
if(mapping.getAction() != other.mapping.getAction()) {
219+
return false;
220+
}
246221

247-
private static <T> boolean eq(T a, T b) {
248-
return a != null ? a.equals(b) : b == null;
222+
if(mapping.getAction() == PluginExecutionAction.configurator) {
223+
String configuratorId = LifecycleMappingFactory.getProjectConfiguratorId(mapping);
224+
String otherConfiguratorId = LifecycleMappingFactory.getProjectConfiguratorId(other.mapping);
225+
if(!Objects.equals(configuratorId, otherConfiguratorId)) {
226+
return false;
227+
}
228+
}
229+
}
230+
return false;
249231
}
250232
}

0 commit comments

Comments
 (0)