Skip to content

Commit

Permalink
Drop support for older Java versions in debugger
Browse files Browse the repository at this point in the history
- Added API
`org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager.getSupportedExecutionEnvironments()`
- UI shows only supported Java versions starting from 1.8 in container
configuration

Requires eclipse-jdt/eclipse.jdt.core#2606
See #451
  • Loading branch information
iloveeclipse committed Jun 19, 2024
1 parent 8ceaa21 commit 903dc2a
Show file tree
Hide file tree
Showing 8 changed files with 98 additions and 69 deletions.
4 changes: 2 additions & 2 deletions org.eclipse.jdt.debug.ui/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ Require-Bundle: org.eclipse.ui.ide;bundle-version="[3.5.0,4.0.0)",
org.eclipse.core.filebuffers;bundle-version="[3.5.0,4.0.0)",
org.eclipse.core.variables;bundle-version="[3.2.0,4.0.0)",
org.eclipse.core.expressions;bundle-version="[3.4.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.32.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.39.0,4.0.0)",
org.eclipse.debug.ui;bundle-version="[3.13.400,4.0.0)",
org.eclipse.jdt.debug;bundle-version="[3.20.0,4.0.0)",
org.eclipse.jdt.launching;bundle-version="[3.19.0,4.0.0)",
org.eclipse.jdt.launching;bundle-version="[3.23.0,4.0.0)",
org.eclipse.jdt.ui;bundle-version="[3.29.0,4.0.0)",
org.eclipse.core.runtime;bundle-version="[3.29.0,4.0.0)",
org.eclipse.ltk.core.refactoring;bundle-version="[3.5.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -463,11 +463,7 @@ protected void fillWithWorkspaceJREs() {
*/
protected void fillWithWorkspaceProfiles() {
fEnvironments.clear();
IExecutionEnvironment[] environments = JavaRuntime.getExecutionEnvironmentsManager().getExecutionEnvironments();
for (int i = 0; i < environments.length; i++) {
fEnvironments.add(environments[i]);
}

fEnvironments.addAll(JavaRuntime.getExecutionEnvironmentsManager().getSupportedExecutionEnvironments());
String[] names = new String[fEnvironments.size()];
Iterator<Object> iter = fEnvironments.iterator();
int i = 0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ private void validateComplianceAndJRE(IVMInstall vmInstall) {
fCompliance.setVisible(true);
}
else {
List<String> allVersions = JavaCore.getAllVersions();
List<String> allVersions = JavaCore.getAllJavaProjectVersions();
String latest = allVersions.get(allVersions.size() - 1);
String vmver = null;
if (vmInstall instanceof AbstractVMInstall) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -247,7 +247,7 @@ else if (segs >= 2) {
}
detectJavadocLocation();
if (s.isOK()) {
List<String> allVersions = JavaCore.getAllVersions();
List<String> allVersions = JavaCore.getAllJavaProjectVersions();
String latest = allVersions.get(allVersions.size() - 1);
IVMInstallType vmType = fVM.getVMInstallType();
if (vmType instanceof StandardVMType) {
Expand Down
4 changes: 2 additions & 2 deletions org.eclipse.jdt.launching/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-Name: %pluginName
Bundle-SymbolicName: org.eclipse.jdt.launching; singleton:=true
Bundle-Version: 3.22.100.qualifier
Bundle-Version: 3.23.0.qualifier
Bundle-Activator: org.eclipse.jdt.internal.launching.LaunchingPlugin
Bundle-Vendor: %providerName
Bundle-Localization: plugin
Expand All @@ -15,7 +15,7 @@ Export-Package: org.eclipse.jdt.internal.launching;x-friends:="org.eclipse.jdt.d
org.eclipse.jdt.launching.sourcelookup.advanced,
org.eclipse.jdt.launching.sourcelookup.containers
Require-Bundle: org.eclipse.core.resources;bundle-version="[3.14.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.34.0,4.0.0)",
org.eclipse.jdt.core;bundle-version="[3.39.0,4.0.0)",
org.eclipse.debug.core;bundle-version="[3.17.0,4.0.0)",
org.eclipse.jdt.debug;bundle-version="[3.21.0,4.0.0)",
org.eclipse.core.variables;bundle-version="[3.2.0,4.0.0)",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.util.Collection;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.LinkedHashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeSet;
Expand Down Expand Up @@ -89,6 +92,8 @@ public class EnvironmentsManager implements IExecutionEnvironmentsManager, IVMIn
*/
private TreeSet<IExecutionEnvironment> fEnvironments = null;

private List<IExecutionEnvironment> supportedEnvironments;

/**
* List of access rule participants
*/
Expand Down Expand Up @@ -154,15 +159,18 @@ private EnvironmentsManager() {
InstanceScope.INSTANCE.getNode(LaunchingPlugin.ID_PLUGIN).addPreferenceChangeListener(this);
}

/* (non-Javadoc)
* @see org.eclipse.jdt.launching.environments.IExecutionEnvironmentsManager#getExecutionEnvironments()
*/
@Override
public synchronized IExecutionEnvironment[] getExecutionEnvironments() {
initializeExtensions();
return fEnvironments.toArray(new IExecutionEnvironment[fEnvironments.size()]);
}

@Override
public synchronized List<IExecutionEnvironment> getSupportedExecutionEnvironments() {
initializeExtensions();
return supportedEnvironments;
}

/**
* Returns all access rule participants that are not specific to an execution environment.
*
Expand Down Expand Up @@ -249,63 +257,74 @@ private String getExecutionEnvironmentCompliance(IExecutionEnvironment execution
}

private synchronized void initializeExtensions() {
if (fEnvironments == null) {
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(LaunchingPlugin.ID_PLUGIN, JavaRuntime.EXTENSION_POINT_EXECUTION_ENVIRONMENTS);
IConfigurationElement[] configs= extensionPoint.getConfigurationElements();
fEnvironments = new TreeSet<>(new Comparator<IExecutionEnvironment>() {
@Override
public int compare(IExecutionEnvironment o1, IExecutionEnvironment o2) {
String compliance1 = getExecutionEnvironmentCompliance(o1);
String compliance2 = getExecutionEnvironmentCompliance(o2);
int result = JavaCore.compareJavaVersions(compliance1, compliance2);
if (result == 0) {
return o1.getId().compareTo(o2.getId());
}
return result;
}
});
fRuleParticipants = new LinkedHashSet<>();
fEnvironmentsMap = new HashMap<>(configs.length);
fAnalyzers = new HashMap<>(configs.length);
for (int i = 0; i < configs.length; i++) {
IConfigurationElement element = configs[i];
String name = element.getName();
switch (name) {
case ENVIRONMENT_ELEMENT:
String id = element.getAttribute("id"); //$NON-NLS-1$
if (id == null) {
LaunchingPlugin.log(NLS.bind("Execution environment must specify \"id\" attribute. Contributed by {0}.", new String[] { //$NON-NLS-1$
element.getContributor().getName() }));
} else {
IExecutionEnvironment env = new ExecutionEnvironment(element);
fEnvironments.add(env);
fEnvironmentsMap.put(id, env);
}
break;
case ANALYZER_ELEMENT:
id = element.getAttribute("id"); //$NON-NLS-1$
if (id == null) {
LaunchingPlugin.log(NLS.bind("Execution environment analyzer must specify \"id\" attribute. Contributed by {0}", new String[] { //$NON-NLS-1$
element.getContributor().getName() }));
} else {
fAnalyzers.put(id, new Analyzer(element));
}
break;
case RULE_PARTICIPANT_ELEMENT:
id = element.getAttribute("id"); //$NON-NLS-1$
if (id == null) {
LaunchingPlugin.log(NLS.bind("Execution environment rule participant must specify \"id\" attribute. Contributed by {0}", new String[] { //$NON-NLS-1$
element.getContributor().getName() }));
} else {
// use a linked hash set to avoid duplicate rule participants
fRuleParticipants.add(new AccessRuleParticipant(element));
}
break;
default:
break;
if (fEnvironments != null) {
return;
}
IExtensionPoint extensionPoint = Platform.getExtensionRegistry().getExtensionPoint(LaunchingPlugin.ID_PLUGIN, JavaRuntime.EXTENSION_POINT_EXECUTION_ENVIRONMENTS);
IConfigurationElement[] configs = extensionPoint.getConfigurationElements();
fEnvironments = new TreeSet<>(new Comparator<IExecutionEnvironment>() {
@Override
public int compare(IExecutionEnvironment o1, IExecutionEnvironment o2) {
String compliance1 = getExecutionEnvironmentCompliance(o1);
String compliance2 = getExecutionEnvironmentCompliance(o2);
int result = JavaCore.compareJavaVersions(compliance1, compliance2);
if (result == 0) {
return o1.getId().compareTo(o2.getId());
}
return result;
}
});
fRuleParticipants = new LinkedHashSet<>();
fEnvironmentsMap = new HashMap<>(configs.length);
fAnalyzers = new HashMap<>(configs.length);
for (int i = 0; i < configs.length; i++) {
IConfigurationElement element = configs[i];
String name = element.getName();
switch (name) {
case ENVIRONMENT_ELEMENT:
String id = element.getAttribute("id"); //$NON-NLS-1$
if (id == null) {
LaunchingPlugin.log(NLS.bind("Execution environment must specify \"id\" attribute. Contributed by {0}.", new String[] { //$NON-NLS-1$
element.getContributor().getName() }));
} else {
IExecutionEnvironment env = new ExecutionEnvironment(element);
fEnvironments.add(env);
fEnvironmentsMap.put(id, env);
}
break;
case ANALYZER_ELEMENT:
id = element.getAttribute("id"); //$NON-NLS-1$
if (id == null) {
LaunchingPlugin.log(NLS.bind("Execution environment analyzer must specify \"id\" attribute. Contributed by {0}", new String[] { //$NON-NLS-1$
element.getContributor().getName() }));
} else {
fAnalyzers.put(id, new Analyzer(element));
}
break;
case RULE_PARTICIPANT_ELEMENT:
id = element.getAttribute("id"); //$NON-NLS-1$
if (id == null) {
LaunchingPlugin.log(NLS.bind("Execution environment rule participant must specify \"id\" attribute. Contributed by {0}", new String[] { //$NON-NLS-1$
element.getContributor().getName() }));
} else {
// use a linked hash set to avoid duplicate rule participants
fRuleParticipants.add(new AccessRuleParticipant(element));
}
break;
default:
break;
}
}

List<IExecutionEnvironment> filtered = new LinkedList<>();
for (IExecutionEnvironment environment : fEnvironments) {
Map<String, String> options = environment.getComplianceOptions();
if (options != null && JavaCore.isSupportedJavaProjectVersion(options.get(JavaCore.COMPILER_COMPLIANCE))) {
filtered.add(environment);
}
}
Collections.reverse(filtered);
supportedEnvironments = Collections.unmodifiableList(filtered);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
*******************************************************************************/
package org.eclipse.jdt.launching.environments;

import java.util.List;

import org.eclipse.jdt.core.JavaCore;

/**
* Manager for execution environments. The singleton manager is available
Expand All @@ -32,6 +35,17 @@ public interface IExecutionEnvironmentsManager {
*/
public IExecutionEnvironment[] getExecutionEnvironments();

/**
* Returns all execution environments supported by Java projects, <b>reverse</b> sorted by their id.
*
* @see IExecutionEnvironment#getId()
* @see JavaCore#isSupportedJavaProjectVersion(String)
*
* @return all registered execution environments sorted by their id
* @since 3.23
*/
public List<IExecutionEnvironment> getSupportedExecutionEnvironments();

/**
* Returns the execution environment associated with the given
* identifier or <code>null</code> if none.
Expand Down
2 changes: 1 addition & 1 deletion org.eclipse.jdt.launching/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
</parent>
<groupId>org.eclipse.jdt</groupId>
<artifactId>org.eclipse.jdt.launching</artifactId>
<version>3.22.100-SNAPSHOT</version>
<version>3.23.0-SNAPSHOT</version>
<packaging>eclipse-plugin</packaging>

<build>
Expand Down

0 comments on commit 903dc2a

Please sign in to comment.