|
From: <caw...@us...> - 2007-01-23 16:29:40
|
Revision: 1860
http://svn.sourceforge.net/rubyeclipse/?rev=1860&view=rev
Author: cawilliams
Date: 2007-01-23 08:29:38 -0800 (Tue, 23 Jan 2007)
Log Message:
-----------
more hooking up the launching stuff for loadpaths to core
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/LoadpathContainerInitializer.java
trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/preferences/RubyInterpreterPreferencePage.java
trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/rubyvms/RubyVMsUpdater.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LaunchingMessages.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LaunchingPlugin.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RubyVMRuntimeLoadpathEntryResolver.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/RubyRuntime.java
trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyRuntime.java
trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RunnerLaunching.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/LoadpathContainerInitializer.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/LoadpathContainerInitializer.java 2007-01-23 15:40:11 UTC (rev 1859)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/LoadpathContainerInitializer.java 2007-01-23 16:29:38 UTC (rev 1860)
@@ -22,8 +22,8 @@
/**
* Abstract base implementation of all classpath container initializer.
- * Classpath variable containers are used in conjunction with the
- * "org.eclipse.jdt.core.classpathContainerInitializer" extension point.
+ * Loadpath variable containers are used in conjunction with the
+ * "org.rubypeople.rdt.core.classpathContainerInitializer" extension point.
* <p>
* Clients should subclass this class to implement a specific classpath
* container initializer. The subclass must have a public 0-argument
Modified: trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/preferences/RubyInterpreterPreferencePage.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/preferences/RubyInterpreterPreferencePage.java 2007-01-23 15:40:11 UTC (rev 1859)
+++ trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/preferences/RubyInterpreterPreferencePage.java 2007-01-23 16:29:38 UTC (rev 1860)
@@ -218,7 +218,8 @@
}
protected void removeInterpreter() {
- fVMList.remove(getSelectedInterpreter());
+ fVMs.remove(getSelectedInterpreter());
+ fVMList.refresh();
}
protected void enableButtons() {
@@ -271,7 +272,7 @@
IVMInstall defaultVM = getCheckedRubyVM();
IVMInstall[] vms = getRubyVMs();
RubyVMsUpdater updater = new RubyVMsUpdater();
- if (!updater.updateJRESettings(vms, defaultVM)) {
+ if (!updater.updateRubyVMSettings(vms, defaultVM)) {
canceled[0] = true;
}
}
Modified: trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/rubyvms/RubyVMsUpdater.java
===================================================================
--- trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/rubyvms/RubyVMsUpdater.java 2007-01-23 15:40:11 UTC (rev 1859)
+++ trunk/org.rubypeople.rdt.debug.ui/src/org/rubypeople/rdt/internal/debug/ui/rubyvms/RubyVMsUpdater.java 2007-01-23 16:29:38 UTC (rev 1860)
@@ -54,22 +54,22 @@
/**
* Updates VM settings and returns whether the update was successful.
*
- * @param jres new installed JREs
- * @param defaultJRE new default VM
+ * @param rubyVMs new installed JREs
+ * @param defaultRubyVM new default VM
* @return whether the update was successful
*/
- public boolean updateJRESettings(IVMInstall[] jres, IVMInstall defaultJRE) {
+ public boolean updateRubyVMSettings(IVMInstall[] rubyVMs, IVMInstall defaultRubyVM) {
// Create a VM definition container
VMDefinitionsContainer vmContainer = new VMDefinitionsContainer();
// Set the default VM Id on the container
- String defaultVMId = RubyRuntime.getCompositeIdFromVM(defaultJRE);
+ String defaultVMId = RubyRuntime.getCompositeIdFromVM(defaultRubyVM);
vmContainer.setDefaultVMInstallCompositeID(defaultVMId);
// Set the VMs on the container
- for (int i = 0; i < jres.length; i++) {
- vmContainer.addVM(jres[i]);
+ for (int i = 0; i < rubyVMs.length; i++) {
+ vmContainer.addVM(rubyVMs[i]);
}
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LaunchingMessages.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LaunchingMessages.java 2007-01-23 15:40:11 UTC (rev 1859)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LaunchingMessages.java 2007-01-23 16:29:38 UTC (rev 1860)
@@ -80,6 +80,8 @@
public static String StandardVMDebugger_Establishing_debug_connection____5;
public static String StandardVMDebugger_Couldn__t_connect_to_VM_4;
public static String StandardVMDebugger_Couldn__t_connect_to_VM_5;
+ public static String LaunchingPlugin_0;
+ public static String LaunchingPlugin_1;
private LaunchingMessages() {}
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LaunchingPlugin.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LaunchingPlugin.java 2007-01-23 15:40:11 UTC (rev 1859)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LaunchingPlugin.java 2007-01-23 16:29:38 UTC (rev 1860)
@@ -1,5 +1,6 @@
package org.rubypeople.rdt.internal.launching;
+import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
@@ -25,17 +26,30 @@
import javax.xml.transform.stream.StreamResult;
import org.eclipse.core.resources.IWorkspace;
+import org.eclipse.core.resources.IWorkspaceRunnable;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.Plugin;
import org.eclipse.core.runtime.Status;
+import org.eclipse.core.runtime.Preferences.IPropertyChangeListener;
+import org.eclipse.core.runtime.jobs.Job;
import org.osgi.framework.BundleContext;
+import org.rubypeople.rdt.core.ILoadpathEntry;
+import org.rubypeople.rdt.core.IRubyProject;
import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.launching.IRuntimeLoadpathEntry2;
+import org.rubypeople.rdt.launching.IVMInstall;
+import org.rubypeople.rdt.launching.IVMInstallChangedListener;
+import org.rubypeople.rdt.launching.PropertyChangeEvent;
+import org.rubypeople.rdt.launching.RubyRuntime;
+import org.rubypeople.rdt.launching.VMStandin;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
@@ -44,7 +58,7 @@
import org.xml.sax.SAXException;
import org.xml.sax.helpers.DefaultHandler;
-public class LaunchingPlugin extends Plugin {
+public class LaunchingPlugin extends Plugin implements IVMInstallChangedListener, IPropertyChangeListener {
public static final String PLUGIN_ID = "org.rubypeople.rdt.launching"; //$NON-NLS-1$
@@ -65,6 +79,16 @@
*/
private static Map fgLibraryInfoMap = null;
+ /**
+ * Whether changes in VM preferences are being batched. When being batched
+ * the plug-in can ignore processing and changes.
+ */
+ private boolean fBatchingChanges = false;
+
+ private boolean fIgnoreVMDefPropertyChangeEvents = false;
+ private String fOldVMPrefString = EMPTY_STRING;
+ private static final String EMPTY_STRING = ""; //$NON-NLS-1$
+
public static String osDependentPath(String aPath) {
if (Platform.getOS().equals(Platform.OS_WIN32)) {
if (aPath.startsWith(File.separator)) {
@@ -103,17 +127,172 @@
System.out.println(message);
}
}
+
@Override
- public void stop(BundleContext arg0) throws Exception {
- super.stop(arg0);
- savePluginPreferences() ;
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+
+ RubyRuntime.addVMInstallChangedListener(this);
}
+
+ @Override
+ public void stop(BundleContext context) throws Exception {
+ try {
+ RubyRuntime.removeVMInstallChangedListener(this);
+ RubyRuntime.saveVMConfiguration();
+ savePluginPreferences();
+ fgXMLParser = null;
+ } finally {
+ super.stop(context);
+ }
+ }
public static String getUniqueIdentifier() {
return PLUGIN_ID;
}
+
+ /**
+ * Save preferences whenever the connect timeout changes.
+ * Process changes to the list of installed JREs.
+ *
+ * @see org.eclipse.core.runtime.Preferences.IPropertyChangeListener#propertyChange(PropertyChangeEvent)
+ */
+ public void propertyChange(org.eclipse.core.runtime.Preferences.PropertyChangeEvent event) {
+ String property = event.getProperty();
+// if (property.equals(RubyRuntime.PREF_CONNECT_TIMEOUT)) {
+// savePluginPreferences();
+// } else
+ if (property.equals(RubyRuntime.PREF_VM_XML)) {
+ if (!isIgnoreVMDefPropertyChangeEvents()) {
+ processVMPrefsChanged((String)event.getOldValue(), (String)event.getNewValue());
+ }
+ }
+ }
+ public void setIgnoreVMDefPropertyChangeEvents(boolean ignore) {
+ fIgnoreVMDefPropertyChangeEvents = ignore;
+ }
+
+ public boolean isIgnoreVMDefPropertyChangeEvents() {
+ return fIgnoreVMDefPropertyChangeEvents;
+ }
+
/**
+ * Check for differences between the old & new sets of installed JREs.
+ * Differences may include additions, deletions and changes. Take
+ * appropriate action for each type of difference.
+ *
+ * When importing preferences, TWO propertyChange events are fired. The first
+ * has an old value but an empty new value. The second has a new value, but an empty
+ * old value. Normal user changes to the preferences result in a single propertyChange
+ * event, with both old and new values populated. This method handles both types
+ * of notification.
+ */
+ protected void processVMPrefsChanged(String oldValue, String newValue) {
+
+ // batch changes
+ fBatchingChanges = true;
+ VMChanges vmChanges = null;
+ try {
+
+ String oldPrefString;
+ String newPrefString;
+
+ // If empty new value, save the old value and wait for 2nd propertyChange notification
+ if (newValue == null || newValue.equals(EMPTY_STRING)) {
+ fOldVMPrefString = oldValue;
+ return;
+ }
+ // An empty old value signals the second notification in the import preferences
+ // sequence. Now that we have both old & new prefs, we can parse and compare them.
+ else if (oldValue == null || oldValue.equals(EMPTY_STRING)) {
+ oldPrefString = fOldVMPrefString;
+ newPrefString = newValue;
+ }
+ // If both old & new values are present, this is a normal user change
+ else {
+ oldPrefString = oldValue;
+ newPrefString = newValue;
+ }
+
+ vmChanges = new VMChanges();
+ RubyRuntime.addVMInstallChangedListener(vmChanges);
+
+ // Generate the previous VMs
+ VMDefinitionsContainer oldResults = getVMDefinitions(oldPrefString);
+
+ // Generate the current
+ VMDefinitionsContainer newResults = getVMDefinitions(newPrefString);
+
+ // Determine the deteled VMs
+ List deleted = oldResults.getVMList();
+ List current = newResults.getValidVMList();
+ deleted.removeAll(current);
+
+ // Dispose deleted VMs. The 'disposeVMInstall' method fires notification of the
+ // deletion.
+ Iterator deletedIterator = deleted.iterator();
+ while (deletedIterator.hasNext()) {
+ VMStandin deletedVMStandin = (VMStandin) deletedIterator.next();
+ deletedVMStandin.getVMInstallType().disposeVMInstall(deletedVMStandin.getId());
+ }
+
+ // Fire change notification for added and changed VMs. The 'convertToRealVM'
+ // fires the appropriate notification.
+ Iterator iter = current.iterator();
+ while (iter.hasNext()) {
+ VMStandin standin = (VMStandin)iter.next();
+ standin.convertToRealVM();
+ }
+
+ // set the new default VM install. This will fire a 'defaultVMChanged',
+ // if it in fact changed
+ String newDefaultId = newResults.getDefaultVMInstallCompositeID();
+ if (newDefaultId != null) {
+ IVMInstall newDefaultVM = RubyRuntime.getVMFromCompositeId(newDefaultId);
+ if (newDefaultVM != null) {
+ try {
+ RubyRuntime.setDefaultVMInstall(newDefaultVM, null, false);
+ } catch (CoreException ce) {
+ log(ce);
+ }
+ }
+ }
+
+ } finally {
+ // stop batch changes
+ fBatchingChanges = false;
+ if (vmChanges != null) {
+ RubyRuntime.removeVMInstallChangedListener(vmChanges);
+ try {
+ vmChanges.process();
+ } catch (CoreException e) {
+ log(e);
+ }
+ }
+ }
+ }
+
+ /**
+ * Parse the given xml into a VM definitions container, returning an empty
+ * container if an exception occurs.
+ *
+ * @param xml
+ * @return VMDefinitionsContainer
+ */
+ private VMDefinitionsContainer getVMDefinitions(String xml) {
+ if (xml.length() > 0) {
+ try {
+ ByteArrayInputStream stream = new ByteArrayInputStream(xml.getBytes("UTF8")); //$NON-NLS-1$
+ return VMDefinitionsContainer.parseXMLIntoContainer(stream);
+ } catch (IOException e) {
+ LaunchingPlugin.log(e);
+ }
+ }
+ return new VMDefinitionsContainer();
+ }
+
+ /**
* Returns a Document that can be used to build a DOM tree
* @return the Document
* @throws ParserConfigurationException if an exception occurs creating the document builder
@@ -427,5 +606,216 @@
for (int i= 0; i < configs.length; i++) {
fClasspathEntryExtensions.put(configs[i].getAttribute("id"), configs[i]); //$NON-NLS-1$
}
+ }
+
+ public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) {
+ if (!fBatchingChanges) {
+ try {
+ VMChanges changes = new VMChanges();
+ changes.defaultVMInstallChanged(previous, current);
+ changes.process();
+ } catch (CoreException e) {
+ log(e);
+ }
+ }
+ }
+
+ public void vmAdded(IVMInstall newVm) {
+ }
+
+ public void vmChanged(PropertyChangeEvent event) {
+ if (!fBatchingChanges) {
+ try {
+ VMChanges changes = new VMChanges();
+ changes.vmChanged(event);
+ changes.process();
+ } catch (CoreException e) {
+ log(e);
+ }
+ }
+ }
+
+ public void vmRemoved(IVMInstall vm) {
+ if (!fBatchingChanges) {
+ try {
+ VMChanges changes = new VMChanges();
+ changes.vmRemoved(vm);
+ changes.process();
+ } catch (CoreException e) {
+ log(e);
+ }
+ }
}
+
+ /**
+ * Stores VM changes resulting from a JRE preference change.
+ */
+ class VMChanges implements IVMInstallChangedListener {
+
+ // true if the default VM changes
+ private boolean fDefaultChanged = false;
+
+ // old container ids to new
+ private HashMap fRenamedContainerIds = new HashMap();
+
+ /**
+ * Returns the JRE container id that the given VM would map to, or
+ * <code>null</code> if none.
+ *
+ * @param vm
+ * @return container id or <code>null</code>
+ */
+ private IPath getContainerId(IVMInstall vm) {
+ if (vm != null) {
+ String name = vm.getName();
+ if (name != null) {
+ IPath path = new Path(RubyRuntime.RUBY_CONTAINER);
+ path = path.append(new Path(vm.getVMInstallType().getId()));
+ path = path.append(new Path(name));
+ return path;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @see org.rubypeople.rdt.launching.IVMInstallChangedListener#defaultVMInstallChanged(org.rubypeople.rdt.launching.IVMInstall, org.rubypeople.rdt.launching.IVMInstall)
+ */
+ public void defaultVMInstallChanged(IVMInstall previous, IVMInstall current) {
+ fDefaultChanged = true;
+ }
+
+ /**
+ * @see org.rubypeople.rdt.launching.IVMInstallChangedListener#vmAdded(org.rubypeople.rdt.launching.IVMInstall)
+ */
+ public void vmAdded(IVMInstall vm) {
+ }
+
+ /**
+ * @see org.rubypeople.rdt.launching.IVMInstallChangedListener#vmChanged(org.rubypeople.rdt.launching.PropertyChangeEvent)
+ */
+ public void vmChanged(org.rubypeople.rdt.launching.PropertyChangeEvent event) {
+ String property = event.getProperty();
+ IVMInstall vm = (IVMInstall)event.getSource();
+ if (property.equals(IVMInstallChangedListener.PROPERTY_NAME)) {
+ IPath newId = getContainerId(vm);
+ IPath oldId = new Path(RubyRuntime.RUBY_CONTAINER);
+ oldId = oldId.append(vm.getVMInstallType().getId());
+ String oldName = (String)event.getOldValue();
+ // bug 33746 - if there is no old name, then this is not a re-name.
+ if (oldName != null) {
+ oldId = oldId.append(oldName);
+ fRenamedContainerIds.put(oldId, newId);
+ }
+ }
+ }
+
+ /**
+ * @see org.rubypeople.rdt.launching.IVMInstallChangedListener#vmRemoved(org.rubypeople.rdt.launching.IVMInstall)
+ */
+ public void vmRemoved(IVMInstall vm) {
+ }
+
+ /**
+ * Re-bind loadpath variables and containers affected by the JRE
+ * changes.
+ */
+ public void process() throws CoreException {
+ RubyVMUpdateJob job = new RubyVMUpdateJob(this);
+ job.schedule();
+ }
+
+ protected void doit(IProgressMonitor monitor) throws CoreException {
+ IWorkspaceRunnable runnable = new IWorkspaceRunnable() {
+ public void run(IProgressMonitor monitor1) throws CoreException {
+ IRubyProject[] projects = RubyCore.create(ResourcesPlugin.getWorkspace().getRoot()).getRubyProjects();
+ monitor1.beginTask(LaunchingMessages.LaunchingPlugin_0, projects.length + 1);
+ rebind(monitor1, projects);
+ monitor1.done();
+ }
+ };
+ RubyCore.run(runnable, null, monitor);
+ }
+
+ /**
+ * Re-bind loadpath variables and containers affected by the Ruby VM
+ * changes.
+ * @param monitor
+ */
+ private void rebind(IProgressMonitor monitor, IRubyProject[] projects) throws CoreException {
+
+ if (fDefaultChanged) {
+ // re-bind RUBYLIB if the default VM changed
+ RubyLoadpathVariablesInitializer initializer = new RubyLoadpathVariablesInitializer();
+ initializer.initialize(RubyRuntime.RUBYLIB_VARIABLE);
+ }
+ monitor.worked(1);
+
+ // re-bind all container entries
+ for (int i = 0; i < projects.length; i++) {
+ IRubyProject project = projects[i];
+ ILoadpathEntry[] entries = project.getRawLoadpath();
+ boolean replace = false;
+ for (int j = 0; j < entries.length; j++) {
+ ILoadpathEntry entry = entries[j];
+ switch (entry.getEntryKind()) {
+ case ILoadpathEntry.CPE_CONTAINER:
+ IPath reference = entry.getPath();
+ IPath newBinding = null;
+ String firstSegment = reference.segment(0);
+ if (RubyRuntime.RUBY_CONTAINER.equals(firstSegment)) {
+ if (reference.segmentCount() > 1) {
+ IPath renamed = (IPath)fRenamedContainerIds.get(reference);
+ if (renamed != null) {
+ // The JRE was re-named. This changes the identifier of
+ // the container entry.
+ newBinding = renamed;
+ }
+ }
+ RubyContainerInitializer initializer = new RubyContainerInitializer();
+ if (newBinding == null){
+ // rebind old path
+ initializer.initialize(reference, project);
+ } else {
+ // replace old cp entry with a new one
+ ILoadpathEntry newEntry = RubyCore.newContainerEntry(newBinding, entry.isExported());
+ entries[j] = newEntry;
+ replace = true;
+ }
+ }
+ break;
+ default:
+ break;
+ }
+ }
+ if (replace) {
+ project.setRawLoadpath(entries, null);
+ }
+ monitor.worked(1);
+ }
+ }
+ }
+
+ class RubyVMUpdateJob extends Job {
+ private VMChanges fChanges;
+
+ public RubyVMUpdateJob(VMChanges changes) {
+ super(LaunchingMessages.LaunchingPlugin_1);
+ fChanges = changes;
+ setSystem(true);
+ }
+
+ /* (non-Javadoc)
+ * @see org.eclipse.core.runtime.jobs.Job#run(org.eclipse.core.runtime.IProgressMonitor)
+ */
+ protected IStatus run(IProgressMonitor monitor) {
+ try {
+ fChanges.doit(monitor);
+ } catch (CoreException e) {
+ return e.getStatus();
+ }
+ return Status.OK_STATUS;
+ }
+
+ }
}
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RubyVMRuntimeLoadpathEntryResolver.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RubyVMRuntimeLoadpathEntryResolver.java 2007-01-23 15:40:11 UTC (rev 1859)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RubyVMRuntimeLoadpathEntryResolver.java 2007-01-23 16:29:38 UTC (rev 1860)
@@ -30,7 +30,7 @@
import org.rubypeople.rdt.launching.RubyRuntime;
/**
- * Resolves for JRELIB_VARIABLE and JRE_CONTAINER
+ * Resolves for RUBYLIB_VARIABLE and RUBY_CONTAINER
*/
public class RubyVMRuntimeLoadpathEntryResolver implements IRuntimeLoadpathEntryResolver2 {
@@ -38,38 +38,38 @@
* @see IRuntimeLoadpathEntryResolver#resolveRuntimeLoadpathEntry(IRuntimeLoadpathEntry, ILaunchConfiguration)
*/
public IRuntimeLoadpathEntry[] resolveRuntimeLoadpathEntry(IRuntimeLoadpathEntry entry, ILaunchConfiguration configuration) throws CoreException {
- IVMInstall jre = null;
+ IVMInstall rubyVM = null;
if (entry.getType() == IRuntimeLoadpathEntry.CONTAINER && entry.getPath().segmentCount() > 1) {
// a specific VM
- jre = RubyContainerInitializer.resolveInterpreter(entry.getPath());
+ rubyVM = RubyContainerInitializer.resolveInterpreter(entry.getPath());
} else {
// default VM for config
- jre = RubyRuntime.computeVMInstall(configuration);
+ rubyVM = RubyRuntime.computeVMInstall(configuration);
}
- if (jre == null) {
- // cannot resolve JRE
+ if (rubyVM == null) {
+ // cannot resolve Ruby VM
return new IRuntimeLoadpathEntry[0];
}
- return resolveLibraryLocations(jre, entry.getLoadpathProperty());
+ return resolveLibraryLocations(rubyVM, entry.getLoadpathProperty());
}
/**
* @see IRuntimeLoadpathEntryResolver#resolveRuntimeLoadpathEntry(IRuntimeLoadpathEntry, IRubyProject)
*/
public IRuntimeLoadpathEntry[] resolveRuntimeLoadpathEntry(IRuntimeLoadpathEntry entry, IRubyProject project) throws CoreException {
- IVMInstall jre = null;
+ IVMInstall rubyVM = null;
if (entry.getType() == IRuntimeLoadpathEntry.CONTAINER && entry.getPath().segmentCount() > 1) {
// a specific VM
- jre = RubyContainerInitializer.resolveInterpreter(entry.getPath());
+ rubyVM = RubyContainerInitializer.resolveInterpreter(entry.getPath());
} else {
// default VM for project
- jre = RubyRuntime.getVMInstall(project);
+ rubyVM = RubyRuntime.getVMInstall(project);
}
- if (jre == null) {
- // cannot resolve JRE
+ if (rubyVM == null) {
+ // cannot resolve RubyVM
return new IRuntimeLoadpathEntry[0];
}
- return resolveLibraryLocations(jre, entry.getLoadpathProperty());
+ return resolveLibraryLocations(rubyVM, entry.getLoadpathProperty());
}
/**
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/RubyRuntime.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/RubyRuntime.java 2007-01-23 15:40:11 UTC (rev 1859)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/RubyRuntime.java 2007-01-23 16:29:38 UTC (rev 1860)
@@ -25,6 +25,7 @@
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.MultiStatus;
import org.eclipse.core.runtime.Path;
@@ -218,29 +219,7 @@
initializeVMs();
return fgDefaultVMId;
}
-
- public static void setSelectedInterpreter(IVMInstall vm) throws CoreException {
- setDefaultVMInstall(vm, true);
- }
-
- public static void setDefaultVMInstall(IVMInstall vm, boolean savePreference) throws CoreException {
- IVMInstall previous = null;
- if (fgDefaultVMId != null) {
- previous = getVMFromCompositeId(fgDefaultVMId);
- }
- fgDefaultVMId= getCompositeIdFromVM(vm);
- if (savePreference) {
- saveVMConfiguration();
- }
- IVMInstall current = null;
- if (fgDefaultVMId != null) {
- current = getVMFromCompositeId(fgDefaultVMId);
- }
- if (previous != current) {
- notifyDefaultVMChanged(previous, current);
- }
- }
-
+
/**
* Saves the VM configuration information to the preferences. This includes
* the following information:
@@ -1593,5 +1572,35 @@
public static IRuntimeLoadpathEntry[] resolveRuntimeLoadpath(
IRuntimeLoadpathEntry[] entries, ILaunchConfiguration configuration) throws CoreException {
return getLoadpathProvider(configuration).resolveLoadpath(entries, configuration);
+ }
+
+ /**
+ * Sets a VM as the system-wide default VM, and notifies registered VM install
+ * change listeners of the change.
+ *
+ * @param vm The vm to make the default. May be <code>null</code> to clear
+ * the default.
+ * @param monitor progress monitor or <code>null</code>
+ * @param savePreference If <code>true</code>, update workbench preferences to reflect
+ * the new default VM.
+ * @throws CoreException
+ * @since 0.9.0
+ */
+ public static void setDefaultVMInstall(IVMInstall vm, IProgressMonitor monitor, boolean savePreference) throws CoreException {
+ IVMInstall previous = null;
+ if (fgDefaultVMId != null) {
+ previous = getVMFromCompositeId(fgDefaultVMId);
+ }
+ fgDefaultVMId = getCompositeIdFromVM(vm);
+ if (savePreference) {
+ saveVMConfiguration();
+ }
+ IVMInstall current = null;
+ if (fgDefaultVMId != null) {
+ current = getVMFromCompositeId(fgDefaultVMId);
+ }
+ if (previous != current) {
+ notifyDefaultVMChanged(previous, current);
+ }
}
}
Modified: trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyRuntime.java
===================================================================
--- trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyRuntime.java 2007-01-23 15:40:11 UTC (rev 1859)
+++ trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RubyRuntime.java 2007-01-23 16:29:38 UTC (rev 1860)
@@ -78,7 +78,7 @@
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<vmSettings defaultVM=\"\" defaultVMConnector=\"\">\r\n<vmType id=\"org.rubypeople.rdt.launching.StandardVMType\">\r\n<vm id=\"InterpreterOne\" name=\"InterpreterOne\" path=\"C:\\RubyInstallRootOne\"/>\r\n<vm id=\"InterpreterTwo\" name=\"InterpreterTwo\" path=\"C:\\RubyInstallRootTwo\"/>\r\n</vmType>\r\n</vmSettings>\r\n",
getVMsXML());
- RubyRuntime.setSelectedInterpreter(standin2);
+ RubyRuntime.setDefaultVMInstall(standin2, null,true);
assertEquals(
"XML should indicate both interpreters with the first one being selected.",
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\r\n<vmSettings defaultVM=\"" + RubyRuntime.getCompositeIdFromVM(standin2) + "\" defaultVMConnector=\"\">\r\n<vmType id=\"org.rubypeople.rdt.launching.StandardVMType\">\r\n<vm id=\"InterpreterOne\" name=\"InterpreterOne\" path=\"C:\\RubyInstallRootOne\"/>\r\n<vm id=\"InterpreterTwo\" name=\"InterpreterTwo\" path=\"C:\\RubyInstallRootTwo\"/>\r\n</vmType>\r\n</vmSettings>\r\n",
Modified: trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RunnerLaunching.java
===================================================================
--- trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RunnerLaunching.java 2007-01-23 15:40:11 UTC (rev 1859)
+++ trunk/org.rubypeople.rdt.launching.tests/src/org/rubypeople/rdt/internal/launching/TC_RunnerLaunching.java 2007-01-23 16:29:38 UTC (rev 1860)
@@ -53,7 +53,7 @@
standin.setName("fake");
standin.setInstallLocation(new File("C:\ruby"));
IVMInstall real = standin.convertToRealVM();
- RubyRuntime.setDefaultVMInstall(real, true);
+ RubyRuntime.setDefaultVMInstall(real, null, true);
}
protected ILaunchManager getLaunchManager() {
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|