Bug 163376 JRE container is not initialized
diff --git a/org.eclipse.jdt.launching/.options b/org.eclipse.jdt.launching/.options
new file mode 100644
index 0000000..a7ae70a
--- /dev/null
+++ b/org.eclipse.jdt.launching/.options
@@ -0,0 +1,2 @@
+org.eclipse.jdt.launching/debug = false
+org.eclipse.jdt.launching/debug/classpath/jreContainer = false
\ No newline at end of file
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JREContainer.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JREContainer.java
index eb79b09..04a6436 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JREContainer.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JREContainer.java
@@ -18,6 +18,7 @@
import java.util.Map;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Platform;
import org.eclipse.jdt.core.IAccessRule;
import org.eclipse.jdt.core.IClasspathAttribute;
import org.eclipse.jdt.core.IClasspathContainer;
@@ -56,10 +57,45 @@
/**
* Cache of classpath entries per VM install. Cleared when a VM changes.
*/
- private static Map fgClasspathEntries = null;
+ private static Map fgClasspathEntries = new HashMap(10);
private static IAccessRule[] EMPTY_RULES = new IAccessRule[0];
+ // debug flags
+ public static boolean DEBUG_JRE_CONTAINER = false;
+
+ /**
+ * Add a vm changed listener to clear cached values when a VM changes or is removed
+ */
+ static {
+ IVMInstallChangedListener listener = new IVMInstallChangedListener() {
+ public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) {
+ }
+
+ public void vmChanged(PropertyChangeEvent event) {
+ if (event.getSource() != null) {
+ fgClasspathEntries.remove(event.getSource());
+ }
+ }
+
+ public void vmAdded(IVMInstall newVm) {
+ }
+
+ public void vmRemoved(IVMInstall removedVm) {
+ fgClasspathEntries.remove(removedVm);
+ }
+ };
+ JavaRuntime.addVMInstallChangedListener(listener);
+ }
+
+ /**
+ * Initialize debug flags
+ */
+ static {
+ DEBUG_JRE_CONTAINER =LaunchingPlugin.DEBUG && "true".equals( //$NON-NLS-1$
+ Platform.getDebugOption("org.eclipse.jdt.launching/debug/classpath/jreContainer")); //$NON-NLS-1$
+ }
+
/**
* Returns the classpath entries associated with the given VM
* in the context of the given path and project.
@@ -70,28 +106,6 @@
* @return classpath entries
*/
private static IClasspathEntry[] getClasspathEntries(IVMInstall vm, IPath containerPath, IJavaProject project) {
- if (fgClasspathEntries == null) {
- fgClasspathEntries = new HashMap(10);
- // add a listener to clear cached value when a VM changes or is removed
- IVMInstallChangedListener listener = new IVMInstallChangedListener() {
- public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) {
- }
-
- public void vmChanged(PropertyChangeEvent event) {
- if (event.getSource() != null) {
- fgClasspathEntries.remove(event.getSource());
- }
- }
-
- public void vmAdded(IVMInstall newVm) {
- }
-
- public void vmRemoved(IVMInstall removedVm) {
- fgClasspathEntries.remove(removedVm);
- }
- };
- JavaRuntime.addVMInstallChangedListener(listener);
- }
String id = JavaRuntime.getExecutionEnvironmentId(containerPath);
IClasspathEntry[] entries = null;
if (id == null) {
@@ -102,6 +116,9 @@
fgClasspathEntries.put(vm, entries);
}
} else {
+ if (DEBUG_JRE_CONTAINER) {
+ System.out.println("\tEE:\t" + id); //$NON-NLS-1$
+ }
// dynamically compute entries when bound to an EE
entries = computeClasspathEntries(vm, project, id);
}
@@ -181,7 +198,20 @@
* @see IClasspathContainer#getClasspathEntries()
*/
public IClasspathEntry[] getClasspathEntries() {
- return getClasspathEntries(fVMInstall, getPath(), fProject);
+ if (DEBUG_JRE_CONTAINER) {
+ System.out.println("<JRE_CONTAINER> getClasspathEntries() " + this.toString()); //$NON-NLS-1$
+ System.out.println("\tJRE:\t" + fVMInstall.getName()); //$NON-NLS-1$
+ System.out.println("\tPath:\t" + getPath().toString()); //$NON-NLS-1$
+ System.out.println("\tProj:\t" + fProject.getProject().getName()); //$NON-NLS-1$
+ }
+ IClasspathEntry[] entries = getClasspathEntries(fVMInstall, getPath(), fProject);
+ if (DEBUG_JRE_CONTAINER) {
+ System.out.println("\tResolved " + entries.length + " entries:"); //$NON-NLS-1$//$NON-NLS-2$
+// for (int i = 0; i < entries.length; i++) {
+// System.out.println("\t\t" + entries[i].getPath().toString() + " +[" + entries[i].getAccessRules().length + " access rules]"); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
+// }
+ }
+ return entries;
}
/**
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JREContainerInitializer.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JREContainerInitializer.java
index bb16130..be39741 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JREContainerInitializer.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/JREContainerInitializer.java
@@ -45,16 +45,36 @@
/**
* @see ClasspathContainerInitializer#initialize(IPath, IJavaProject)
*/
- public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
+ public void initialize(IPath containerPath, IJavaProject project) throws CoreException {
+ if (JREContainer.DEBUG_JRE_CONTAINER) {
+ System.out.println("<JRE_CONTAINER> initialize()"); //$NON-NLS-1$
+ System.out.println("\tPath: " + containerPath.toString()); //$NON-NLS-1$
+ System.out.println("\tProj: " + project.getProject().getName()); //$NON-NLS-1$
+ }
int size = containerPath.segmentCount();
if (size > 0) {
if (containerPath.segment(0).equals(JavaRuntime.JRE_CONTAINER)) {
IVMInstall vm = resolveVM(containerPath);
JREContainer container = null;
if (vm != null) {
+ if (JREContainer.DEBUG_JRE_CONTAINER) {
+ System.out.println("\tResolved VM: " + vm.getName()); //$NON-NLS-1$
+ }
container = new JREContainer(vm, containerPath, project);
+ } else {
+ if (JREContainer.DEBUG_JRE_CONTAINER) {
+ System.out.println("\t*** FAILED RESOLVE VM ***"); //$NON-NLS-1$
+ }
}
JavaCore.setClasspathContainer(containerPath, new IJavaProject[] {project}, new IClasspathContainer[] {container}, null);
+ } else {
+ if (JREContainer.DEBUG_JRE_CONTAINER) {
+ System.out.println("\t*** INVALID JRE CONTAINER PATH ***"); //$NON-NLS-1$
+ }
+ }
+ } else {
+ if (JREContainer.DEBUG_JRE_CONTAINER) {
+ System.out.println("\t*** NO SEGMENTS IN CONTAINER PATH ***"); //$NON-NLS-1$
}
}
}
@@ -69,10 +89,18 @@
// specific JRE
String id = getExecutionEnvironmentId(containerPath);
if (id != null) {
+ if (JREContainer.DEBUG_JRE_CONTAINER) {
+ System.out.println("<JRE_CONTAINER> resolveVM(IPath)"); //$NON-NLS-1$
+ System.out.println("\tEE: " + id); //$NON-NLS-1$
+ }
IExecutionEnvironmentsManager manager = JavaRuntime.getExecutionEnvironmentsManager();
IExecutionEnvironment environment = manager.getEnvironment(id);
if (environment != null) {
vm = resolveVM(environment);
+ } else {
+ if (JREContainer.DEBUG_JRE_CONTAINER) {
+ System.out.println("\t*** NO ENVIRONMENT ***"); //$NON-NLS-1$
+ }
}
} else {
String vmTypeId = getVMTypeId(containerPath);
@@ -98,20 +126,36 @@
* @since 3.2
*/
public static IVMInstall resolveVM(IExecutionEnvironment environment) {
+ if (JREContainer.DEBUG_JRE_CONTAINER) {
+ System.out.println("<JRE_CONTAINER> resolveVM(IExecutionEnvironment)"); //$NON-NLS-1$
+ }
IVMInstall vm = environment.getDefaultVM();
if (vm == null) {
IVMInstall[] installs = environment.getCompatibleVMs();
// take the first strictly compatible vm if there is no default
+ if (installs.length == 0 && JREContainer.DEBUG_JRE_CONTAINER) {
+ System.out.println("\t*** NO COMPATIBLE VMS ***"); //$NON-NLS-1$
+ }
for (int i = 0; i < installs.length; i++) {
IVMInstall install = installs[i];
if (environment.isStrictlyCompatible(install)) {
vm = install;
+ if (installs.length == 0 && JREContainer.DEBUG_JRE_CONTAINER) {
+ System.out.println("\tPerfect Match: " + vm.getName()); //$NON-NLS-1$
+ }
break;
}
}
// use the first vm failing that
if (vm == null && installs.length > 0) {
vm = installs[0];
+ if (installs.length == 0 && JREContainer.DEBUG_JRE_CONTAINER) {
+ System.out.println("\tFirst Match: " + vm.getName()); //$NON-NLS-1$
+ }
+ }
+ } else {
+ if (JREContainer.DEBUG_JRE_CONTAINER) {
+ System.out.println("\tUser Default VM: " + vm.getName()); //$NON-NLS-1$
}
}
return vm;
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingPlugin.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingPlugin.java
index 43d5a75..d618146 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingPlugin.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/LaunchingPlugin.java
@@ -153,6 +153,11 @@
private static DocumentBuilder fgXMLParser = null;
/**
+ * Whether debug options are turned on for this plug-in.
+ */
+ public static boolean DEBUG = false;
+
+ /**
* Stores VM changes resulting from a JRE preference change.
*/
class VMChanges implements IVMInstallChangedListener {
@@ -450,6 +455,7 @@
*/
public void start(BundleContext context) throws Exception {
super.start(context);
+ DEBUG = "true".equals(Platform.getDebugOption("org.eclipse.jdt.launching/debug")); //$NON-NLS-1$//$NON-NLS-2$
ResourcesPlugin.getWorkspace().addSaveParticipant(this, new ISaveParticipant() {
public void doneSaving(ISaveContext context1) {}
public void prepareToSave(ISaveContext context1) throws CoreException {}
diff --git a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/EnvironmentsManager.java b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/EnvironmentsManager.java
index e3de197..ac8eea8 100644
--- a/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/EnvironmentsManager.java
+++ b/org.eclipse.jdt.launching/launching/org/eclipse/jdt/internal/launching/environments/EnvironmentsManager.java
@@ -228,10 +228,10 @@
* Initializes compatibility settings.
*/
void initializeCompatibilities() {
- if (!fInitializedCompatibilities) {
- fInitializedCompatibilities = true;
- IVMInstallType[] installTypes = JavaRuntime.getVMInstallTypes();
- synchronized (this) {
+ IVMInstallType[] installTypes = JavaRuntime.getVMInstallTypes();
+ synchronized (this) {
+ if (!fInitializedCompatibilities) {
+ fInitializedCompatibilities = true;
for (int i = 0; i < installTypes.length; i++) {
IVMInstallType type = installTypes[i];
IVMInstall[] installs = type.getVMInstalls();
@@ -242,8 +242,8 @@
}
}
initializeDefaultVMs();
- }
- }
+ }
+ }
}
/**