|
From: <caw...@us...> - 2007-01-19 19:03:29
|
Revision: 1814
http://svn.sourceforge.net/rubyeclipse/?rev=1814&view=rev
Author: cawilliams
Date: 2007-01-19 11:03:28 -0800 (Fri, 19 Jan 2007)
Log Message:
-----------
yay for no broken builds!
Modified Paths:
--------------
trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyCore.java
trunk/org.rubypeople.rdt.launching/plugin.xml
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LaunchingMessages.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IRubyLaunchConfigurationConstants.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/RubyRuntime.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RubyVMRuntimeLoadpathEntryResolver.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RuntimeLoadpathEntry.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RuntimeLoadpathEntryResolver.java
Modified: trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyCore.java
===================================================================
--- trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyCore.java 2007-01-19 18:38:07 UTC (rev 1813)
+++ trunk/org.rubypeople.rdt.core/src/org/rubypeople/rdt/core/RubyCore.java 2007-01-19 19:03:28 UTC (rev 1814)
@@ -1312,4 +1312,20 @@
RubyModelManager.getRubyModelManager().updateVariableValues(variableNames, paths, true/*update preferences*/, monitor);
}
+ public static ILoadpathEntry newProjectEntry(IPath fullPath) {
+ return newProjectEntry(fullPath, false);
+ }
+
+ public static ILoadpathEntry newVariableEntry(IPath path) {
+ return newVariableEntry(path, false);
+ }
+
+ public static ILoadpathEntry newContainerEntry(IPath path) {
+ return newContainerEntry(path, false);
+ }
+
+ public static ILoadpathEntry newLibraryEntry(IPath p) {
+ return newLibraryEntry(p, false);
+ }
+
}
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.launching/plugin.xml
===================================================================
--- trunk/org.rubypeople.rdt.launching/plugin.xml 2007-01-19 18:38:07 UTC (rev 1813)
+++ trunk/org.rubypeople.rdt.launching/plugin.xml 2007-01-19 19:03:28 UTC (rev 1814)
@@ -59,5 +59,30 @@
id="org.rubypeople.rdt.launching.RUBY_CONTAINER">
</loadpathContainerInitializer>
</extension>
+ <extension
+ point="org.rubypeople.rdt.launching.runtimeLoadpathEntryResolvers">
+ <runtimeLoadpathEntryResolver
+ container="org.rubypeople.rdt.launching.JRE_CONTAINER"
+ variable="JRE_LIB"
+ class="org.rubypeople.rdt.internal.launching.JRERuntimeLoadpathEntryResolver"
+ id="org.rubypeople.rdt.launching.JRE_RESOLVER">
+ </runtimeLoadpathEntryResolver>
+ <runtimeLoadpathEntryResolver
+ runtimeLoadpathEntryId="org.rubypeople.rdt.launching.loadpathentry.variableLoadpathEntry"
+ class="org.rubypeople.rdt.internal.launching.VariableLoadpathResolver"
+ id="org.rubypeople.rdt.launching.variableLoadpathResolver">
+ </runtimeLoadpathEntryResolver>
+ </extension>
+ <extension
+ point="org.rubypeople.rdt.launching.runtimeLoadpathEntries">
+ <runtimeLoadpathEntry
+ id="org.rubypeople.rdt.launching.loadpathentry.defaultLoadpath"
+ class="org.rubypeople.rdt.internal.launching.DefaultProjectLoadpathEntry">
+ </runtimeLoadpathEntry>
+ <runtimeLoadpathEntry
+ id="org.rubypeople.rdt.launching.loadpathentry.variableLoadpathEntry"
+ class="org.rubypeople.rdt.internal.launching.VariableLoadpathEntry">
+ </runtimeLoadpathEntry>
+ </extension>
</plugin>
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-19 18:38:07 UTC (rev 1813)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LaunchingMessages.java 2007-01-19 19:03:28 UTC (rev 1814)
@@ -44,6 +44,26 @@
public static String StandardVMRunner_Launching_VM____1;
public static String StandardVMRunner_Constructing_command_line____2;
public static String StandardVMRunner_Starting_virtual_machine____3;
+ public static String JavaLocalApplicationLaunchConfigurationDelegate_Creating_source_locator____2;
+ public static String JavaLocalApplicationLaunchConfigurationDelegate_Verifying_launch_attributes____1;
+ public static String AbstractJavaLaunchConfigurationDelegate_The_specified_JRE_installation_does_not_exist_4;
+ public static String AbstractJavaLaunchConfigurationDelegate_JRE_home_directory_not_specified_for__0__5;
+ public static String AbstractJavaLaunchConfigurationDelegate_JRE_home_directory_for__0__does_not_exist___1__6;
+ public static String JavaLocalApplicationLaunchConfigurationDelegate_0;
+ public static String JavaRuntime_Specified_VM_install_type_does_not_exist___0__2;
+ public static String JavaRuntime_Specified_VM_install_not_found__type__0___name__1__2;
+ public static String JavaRuntime_VM_not_fully_specified_in_launch_configuration__0____missing_VM_name__Reverting_to_default_VM__1;
+ public static String JavaRuntime_28;
+ public static String JavaRuntime_Launch_configuration__0__references_non_existing_project__1___1;
+ public static String AbstractJavaLaunchConfigurationDelegate_Working_directory_does_not_exist___0__12;
+ public static String AbstractJavaLaunchConfigurationDelegate_Main_type_not_specified_11;
+ public static String RuntimeLoadpathEntry_Illegal_classpath_entry__0__1;
+ public static String RuntimeLoadpathEntry_Unable_to_recover_runtime_class_path_entry_type_2;
+ public static String RuntimeLoadpathEntry_Unable_to_recover_runtime_class_path_entry_location_3;
+ public static String RuntimeLoadpathEntry_Unable_to_recover_runtime_class_path_entry___missing_project_name_4;
+ public static String RuntimeLoadpathEntry_Unable_to_recover_runtime_class_path_entry___missing_archive_path_5;
+ public static String RuntimeLoadpathEntry_Unable_to_recover_runtime_class_path_entry___missing_variable_name_6;
+ public static String RuntimeLoadpathEntry_An_exception_occurred_generating_runtime_classpath_memento_8;
private LaunchingMessages() {}
Added: 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 (rev 0)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RubyVMRuntimeLoadpathEntryResolver.java 2007-01-19 19:03:28 UTC (rev 1814)
@@ -0,0 +1,208 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.launching;
+
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.rubypeople.rdt.core.ILoadpathEntry;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.launching.IRuntimeLoadpathEntry;
+import org.rubypeople.rdt.launching.IRuntimeLoadpathEntryResolver;
+import org.rubypeople.rdt.launching.IRuntimeLoadpathEntryResolver2;
+import org.rubypeople.rdt.launching.IVMInstall;
+import org.rubypeople.rdt.launching.RubyRuntime;
+
+/**
+ * Resolves for JRELIB_VARIABLE and JRE_CONTAINER
+ */
+public class RubyVMRuntimeLoadpathEntryResolver implements IRuntimeLoadpathEntryResolver2 {
+
+ /**
+ * @see IRuntimeLoadpathEntryResolver#resolveRuntimeLoadpathEntry(IRuntimeLoadpathEntry, ILaunchConfiguration)
+ */
+ public IRuntimeLoadpathEntry[] resolveRuntimeLoadpathEntry(IRuntimeLoadpathEntry entry, ILaunchConfiguration configuration) throws CoreException {
+ IVMInstall jre = null;
+ if (entry.getType() == IRuntimeLoadpathEntry.CONTAINER && entry.getPath().segmentCount() > 1) {
+ // a specific VM
+ jre = RubyContainerInitializer.resolveInterpreter(entry.getPath());
+ } else {
+ // default VM for config
+ jre = RubyRuntime.computeVMInstall(configuration);
+ }
+ if (jre == null) {
+ // cannot resolve JRE
+ return new IRuntimeLoadpathEntry[0];
+ }
+ return resolveLibraryLocations(jre, entry.getLoadpathProperty());
+ }
+
+ /**
+ * @see IRuntimeLoadpathEntryResolver#resolveRuntimeLoadpathEntry(IRuntimeLoadpathEntry, IRubyProject)
+ */
+ public IRuntimeLoadpathEntry[] resolveRuntimeLoadpathEntry(IRuntimeLoadpathEntry entry, IRubyProject project) throws CoreException {
+ IVMInstall jre = null;
+ if (entry.getType() == IRuntimeLoadpathEntry.CONTAINER && entry.getPath().segmentCount() > 1) {
+ // a specific VM
+ jre = RubyContainerInitializer.resolveInterpreter(entry.getPath());
+ } else {
+ // default VM for project
+ jre = RubyRuntime.getVMInstall(project);
+ }
+ if (jre == null) {
+ // cannot resolve JRE
+ return new IRuntimeLoadpathEntry[0];
+ }
+ return resolveLibraryLocations(jre, entry.getLoadpathProperty());
+ }
+
+ /**
+ * Resolves libray locations for the given VM install
+ */
+ protected IRuntimeLoadpathEntry[] resolveLibraryLocations(IVMInstall vm, int kind) {
+ IPath[] libs = vm.getLibraryLocations();
+ IPath[] defaultLibs = vm.getVMInstallType().getDefaultLibraryLocations(vm.getInstallLocation());
+ boolean overrideRubydoc = false;
+ if (libs == null) {
+ // default system libs
+ libs = defaultLibs;
+ overrideRubydoc = true;
+ } else if (!isSameArchives(libs, defaultLibs)) {
+ // determine if bootpath should be explicit
+ kind = IRuntimeLoadpathEntry.BOOTSTRAP_CLASSES;
+ }
+ if (kind == IRuntimeLoadpathEntry.BOOTSTRAP_CLASSES) {
+ File vmInstallLocation= vm.getInstallLocation();
+ if (vmInstallLocation != null) {
+ LibraryInfo libraryInfo= LaunchingPlugin.getLibraryInfo(vmInstallLocation.getAbsolutePath());
+ if (libraryInfo != null) {
+ // only return endorsed and bootstrap classpath entries if we have the info
+ // libs in the ext dirs are not loaded by the boot class loader
+ String[] extensionDirsArray = libraryInfo.getExtensionDirs();
+ Set extensionDirsSet = new HashSet();
+ for (int i = 0; i < extensionDirsArray.length; i++) {
+ extensionDirsSet.add(extensionDirsArray[i]);
+ }
+ List resolvedEntries = new ArrayList(libs.length);
+ for (int i = 0; i < libs.length; i++) {
+ IPath location = libs[i];
+ IPath libraryPath = location;
+ String dir = libraryPath.toFile().getParent();
+ // exclude extension directory entries
+ if (!extensionDirsSet.contains(dir)) {
+ resolvedEntries.add(resolveLibraryLocation(vm, location, kind, overrideRubydoc));
+ }
+ }
+ return (IRuntimeLoadpathEntry[]) resolvedEntries.toArray(new IRuntimeLoadpathEntry[resolvedEntries.size()]);
+ }
+ }
+ }
+ List resolvedEntries = new ArrayList(libs.length);
+ for (int i = 0; i < libs.length; i++) {
+ IPath systemLibraryPath = libs[i];
+ if (systemLibraryPath.toFile().exists()) {
+ resolvedEntries.add(resolveLibraryLocation(vm, libs[i], kind, overrideRubydoc));
+ }
+ }
+ return (IRuntimeLoadpathEntry[]) resolvedEntries.toArray(new IRuntimeLoadpathEntry[resolvedEntries.size()]);
+ }
+
+ /**
+ * Return whether the given list of libraries refer to the same archives in the same
+ * order. Only considers the binary archive (not source or javadoc locations).
+ *
+ * @param libs
+ * @param defaultLibs
+ * @return whether the given list of libraries refer to the same archives in the same
+ * order
+ */
+ public static boolean isSameArchives(IPath[] libs, IPath[] defaultLibs) {
+ if (libs.length != defaultLibs.length) {
+ return false;
+ }
+ for (int i = 0; i < defaultLibs.length; i++) {
+ IPath def = defaultLibs[i];
+ IPath lib = libs[i];
+ if (!def.equals(lib)) {
+ return false;
+ }
+ }
+ return true;
+ }
+
+ /**
+ * @see IRuntimeLoadpathEntryResolver#resolveVMInstall(ILoadpathEntry)
+ */
+ public IVMInstall resolveVMInstall(ILoadpathEntry entry) {
+ switch (entry.getEntryKind()) {
+ case ILoadpathEntry.CPE_VARIABLE:
+ if (entry.getPath().segment(0).equals(RubyRuntime.RUBYLIB_VARIABLE)) {
+ return RubyRuntime.getDefaultVMInstall();
+ }
+ break;
+ case ILoadpathEntry.CPE_CONTAINER:
+ if (entry.getPath().segment(0).equals(RubyRuntime.RUBY_CONTAINER)) {
+ return RubyContainerInitializer.resolveInterpreter(entry.getPath());
+ }
+ break;
+ default:
+ break;
+ }
+ return null;
+ }
+
+ /* (non-Rubydoc)
+ * @see org.eclipse.jdt.launching.IRuntimeLoadpathEntryResolver2#isVMInstallReference(org.eclipse.jdt.core.ILoadpathEntry)
+ */
+ public boolean isVMInstallReference(ILoadpathEntry entry) {
+ switch (entry.getEntryKind()) {
+ case ILoadpathEntry.CPE_VARIABLE:
+ if (entry.getPath().segment(0).equals(RubyRuntime.RUBYLIB_VARIABLE)) {
+ return true;
+ }
+ break;
+ case ILoadpathEntry.CPE_CONTAINER:
+ if (entry.getPath().segment(0).equals(RubyRuntime.RUBY_CONTAINER)) {
+ return true;
+ }
+ break;
+ default:
+ break;
+ }
+ return false;
+ }
+
+ /**
+ * Returns a runtime classpath entry for the given library in the specified VM.
+ *
+ * @param vm
+ * @param location
+ * @param kind
+ * @return runtime classpath entry
+ * @since 0.9.0
+ */
+ private IRuntimeLoadpathEntry resolveLibraryLocation(IVMInstall vm, IPath location, int kind, boolean overrideRubyDoc) {
+ IPath libraryPath = location;
+ ILoadpathEntry cpe = RubyCore.newLibraryEntry(libraryPath, false);
+ IRuntimeLoadpathEntry resolved = new RuntimeLoadpathEntry(cpe);
+ resolved.setLoadpathProperty(kind);
+ return resolved;
+ }
+
+}
Added: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RuntimeLoadpathEntry.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RuntimeLoadpathEntry.java (rev 0)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RuntimeLoadpathEntry.java 2007-01-19 19:03:28 UTC (rev 1814)
@@ -0,0 +1,555 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2006 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ * BEA - Daniel R Somerfield - Bug 88939
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.launching;
+
+
+import java.io.IOException;
+import java.text.MessageFormat;
+
+import javax.xml.parsers.ParserConfigurationException;
+import javax.xml.transform.TransformerException;
+
+import org.eclipse.core.resources.IContainer;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.core.runtime.Status;
+import org.rubypeople.rdt.core.ILoadpathEntry;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.LoadpathContainerInitializer;
+import org.rubypeople.rdt.core.RubyCore;
+import org.rubypeople.rdt.core.RubyModelException;
+import org.rubypeople.rdt.launching.IRubyLaunchConfigurationConstants;
+import org.rubypeople.rdt.launching.IRuntimeLoadpathEntry;
+import org.rubypeople.rdt.launching.RubyRuntime;
+import org.w3c.dom.Document;
+import org.w3c.dom.Element;
+
+/**
+ * An entry on the runtime classpath that the user can manipulate
+ * and share in a launch configuration.
+ *
+ * @see org.eclipse.jdt.launching.IRuntimeLoadpathEntry
+ * @since 2.0
+ */
+public class RuntimeLoadpathEntry implements IRuntimeLoadpathEntry {
+
+ /**
+ * This entry's type - must be set on creation.
+ */
+ private int fType = -1;
+
+ /**
+ * This entry's classpath property.
+ */
+ private int fLoadpathProperty = -1;
+
+ /**
+ * This entry's associated build path entry.
+ */
+ private ILoadpathEntry fLoadpathEntry = null;
+
+ /**
+ * The entry's resolved entry (lazily initialized)
+ */
+ private ILoadpathEntry fResolvedEntry = null;
+
+ /**
+ * Associated Ruby project, or <code>null</code>
+ */
+ private IRubyProject fRubyProject = null;
+
+ /**
+ * The path if the entry was invalid and fLoadpathEntry is null
+ */
+ private IPath fInvalidPath;
+
+ /**
+ * Constructs a new runtime classpath entry based on the
+ * (build) classpath entry.
+ *
+ * @param entry the associated classpath entry
+ */
+ public RuntimeLoadpathEntry(ILoadpathEntry entry) {
+ switch (entry.getEntryKind()) {
+ case ILoadpathEntry.CPE_PROJECT:
+ setType(PROJECT);
+ break;
+ case ILoadpathEntry.CPE_LIBRARY:
+ setType(ARCHIVE);
+ break;
+ case ILoadpathEntry.CPE_VARIABLE:
+ setType(VARIABLE);
+ break;
+ default:
+ throw new IllegalArgumentException(MessageFormat.format(LaunchingMessages.RuntimeLoadpathEntry_Illegal_classpath_entry__0__1, new String[] {entry.toString()}));
+ }
+ setLoadpathEntry(entry);
+ initializeLoadpathProperty();
+ }
+
+ /**
+ * Constructs a new container entry in the context of the given project
+ *
+ * @param entry classpath entry
+ * @param classpathProperty this entry's classpath property
+ */
+ public RuntimeLoadpathEntry(ILoadpathEntry entry, int classpathProperty) {
+ switch (entry.getEntryKind()) {
+ case ILoadpathEntry.CPE_CONTAINER:
+ setType(CONTAINER);
+ break;
+ default:
+ throw new IllegalArgumentException(MessageFormat.format(LaunchingMessages.RuntimeLoadpathEntry_Illegal_classpath_entry__0__1, new String[] {entry.toString()}));
+ }
+ setLoadpathEntry(entry);
+ setLoadpathProperty(classpathProperty);
+ }
+
+ /**
+ * Reconstructs a runtime classpath entry from the given
+ * XML document root not.
+ *
+ * @param root a memento root doc element created by this class
+ * @exception CoreException if unable to restore from the given memento
+ */
+ public RuntimeLoadpathEntry(Element root) throws CoreException {
+ try {
+ setType(Integer.parseInt(root.getAttribute("type"))); //$NON-NLS-1$
+ } catch (NumberFormatException e) {
+ abort(LaunchingMessages.RuntimeLoadpathEntry_Unable_to_recover_runtime_class_path_entry_type_2, e);
+ }
+ try {
+ setLoadpathProperty(Integer.parseInt(root.getAttribute("path"))); //$NON-NLS-1$
+ } catch (NumberFormatException e) {
+ abort(LaunchingMessages.RuntimeLoadpathEntry_Unable_to_recover_runtime_class_path_entry_location_3, e);
+ }
+
+ // source attachment
+ IPath sourcePath = null;
+ IPath rootPath = null;
+ String path = root.getAttribute("sourceAttachmentPath"); //$NON-NLS-1$
+ if (path != null && path.length() > 0) {
+ sourcePath = new Path(path);
+ }
+ path = root.getAttribute("sourceRootPath"); //$NON-NLS-1$
+ if (path != null && path.length() > 0) {
+ rootPath = new Path(path);
+ }
+
+ switch (getType()) {
+ case PROJECT :
+ String name = root.getAttribute("projectName"); //$NON-NLS-1$
+ if (isEmpty(name)) {
+ abort(LaunchingMessages.RuntimeLoadpathEntry_Unable_to_recover_runtime_class_path_entry___missing_project_name_4, null);
+ } else {
+ IProject proj = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
+ setLoadpathEntry(RubyCore.newProjectEntry(proj.getFullPath()));
+ }
+ break;
+ case ARCHIVE :
+ path = root.getAttribute("externalArchive"); //$NON-NLS-1$
+ if (isEmpty(path)) {
+ // internal
+ path = root.getAttribute("internalArchive"); //$NON-NLS-1$
+ if (isEmpty(path)) {
+ abort(LaunchingMessages.RuntimeLoadpathEntry_Unable_to_recover_runtime_class_path_entry___missing_archive_path_5, null);
+ } else {
+ setLoadpathEntry(createLibraryEntry(sourcePath, rootPath, path));
+ }
+ } else {
+ // external
+ setLoadpathEntry(createLibraryEntry(sourcePath, rootPath, path));
+ }
+ break;
+ case VARIABLE :
+ String var = root.getAttribute("containerPath"); //$NON-NLS-1$
+ if (isEmpty(var)) {
+ abort(LaunchingMessages.RuntimeLoadpathEntry_Unable_to_recover_runtime_class_path_entry___missing_variable_name_6, null);
+ } else {
+ setLoadpathEntry(RubyCore.newVariableEntry(new Path(var)));
+ }
+ break;
+ case CONTAINER :
+ var = root.getAttribute("containerPath"); //$NON-NLS-1$
+ if (isEmpty(var)) {
+ abort(LaunchingMessages.RuntimeLoadpathEntry_Unable_to_recover_runtime_class_path_entry___missing_variable_name_6, null);
+ } else {
+ setLoadpathEntry(RubyCore.newContainerEntry(new Path(var)));
+ }
+ break;
+ }
+
+ String name = root.getAttribute("rubyProject"); //$NON-NLS-1$
+ if (isEmpty(name)) {
+ fRubyProject = null;
+ } else {
+ IProject project2 = ResourcesPlugin.getWorkspace().getRoot().getProject(name);
+ fRubyProject = RubyCore.create(project2);
+ }
+ }
+
+ private ILoadpathEntry createLibraryEntry(IPath sourcePath, IPath rootPath, String path) {
+ Path p = new Path(path);
+ if (!p.isAbsolute())
+ {
+ fInvalidPath = p;
+ return null;
+ //abort("There was a problem with path \" " + path + "\": paths must be absolute.", null);
+ }
+ return RubyCore.newLibraryEntry(p);
+ }
+
+ /**
+ * Throws an internal error exception
+ */
+ protected void abort(String message, Throwable e) throws CoreException {
+ IStatus s = new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), IRubyLaunchConfigurationConstants.ERR_INTERNAL_ERROR, message, e);
+ throw new CoreException(s);
+ }
+
+ /**
+ * @see IRuntimeLoadpathEntry#getType()
+ */
+ public int getType() {
+ return fType;
+ }
+
+ /**
+ * Sets this entry's type
+ *
+ * @param type this entry's type
+ */
+ private void setType(int type) {
+ fType = type;
+ }
+
+ /**
+ * Sets the classpath entry associated with this runtime classpath entry.
+ * Clears the cache of the resolved entry.
+ *
+ * @param entry the classpath entry associated with this runtime classpath entry
+ */
+ private void setLoadpathEntry(ILoadpathEntry entry) {
+ fLoadpathEntry = entry;
+ fResolvedEntry = null;
+ }
+
+ /**
+ * @see IRuntimeLoadpathEntry#getLoadpathEntry()
+ */
+ public ILoadpathEntry getLoadpathEntry() {
+ return fLoadpathEntry;
+ }
+
+ /**
+ * @see IRuntimeLoadpathEntry#getMemento()
+ */
+ public String getMemento() throws CoreException {
+
+ Document doc;
+ try {
+ doc = LaunchingPlugin.getDocument();
+ } catch (ParserConfigurationException e) {
+ IStatus status = new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), IRubyLaunchConfigurationConstants.ERR_INTERNAL_ERROR, LaunchingMessages.RuntimeLoadpathEntry_An_exception_occurred_generating_runtime_classpath_memento_8, e);
+ throw new CoreException(status);
+ }
+ Element node = doc.createElement("runtimeLoadpathEntry"); //$NON-NLS-1$
+ doc.appendChild(node);
+ node.setAttribute("type", (new Integer(getType())).toString()); //$NON-NLS-1$
+ node.setAttribute("path", (new Integer(getLoadpathProperty())).toString()); //$NON-NLS-1$
+ switch (getType()) {
+ case PROJECT :
+ node.setAttribute("projectName", getPath().lastSegment()); //$NON-NLS-1$
+ break;
+ case ARCHIVE :
+ IResource res = getResource();
+ if (res == null) {
+ node.setAttribute("externalArchive", getPath().toString()); //$NON-NLS-1$
+ } else {
+ node.setAttribute("internalArchive", res.getFullPath().toString()); //$NON-NLS-1$
+ }
+ break;
+ case VARIABLE :
+ case CONTAINER :
+ node.setAttribute("containerPath", getPath().toString()); //$NON-NLS-1$
+ break;
+ }
+ if (getRubyProject() != null) {
+ node.setAttribute("rubyProject", getRubyProject().getElementName()); //$NON-NLS-1$
+ }
+ try {
+ return LaunchingPlugin.serializeDocument(doc);
+ } catch (IOException e) {
+ IStatus status = new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), IRubyLaunchConfigurationConstants.ERR_INTERNAL_ERROR, LaunchingMessages.RuntimeLoadpathEntry_An_exception_occurred_generating_runtime_classpath_memento_8, e);
+ throw new CoreException(status);
+ } catch (TransformerException e) {
+ IStatus status = new Status(IStatus.ERROR, LaunchingPlugin.getUniqueIdentifier(), IRubyLaunchConfigurationConstants.ERR_INTERNAL_ERROR, LaunchingMessages.RuntimeLoadpathEntry_An_exception_occurred_generating_runtime_classpath_memento_8, e);
+ throw new CoreException(status);
+ }
+ }
+
+ /**
+ * @see IRuntimeLoadpathEntry#getPath()
+ */
+ public IPath getPath() {
+ ILoadpathEntry entry = getLoadpathEntry();
+ return entry != null ? entry.getPath() : fInvalidPath;
+ }
+
+ /**
+ * @see IRuntimeLoadpathEntry#getResource()
+ */
+ public IResource getResource() {
+ switch (getType()) {
+ case CONTAINER:
+ case VARIABLE:
+ return null;
+ default:
+ return getResource(getPath());
+ }
+ }
+
+ /**
+ * Returns the resource in the workspace assciated with the given
+ * absolute path, or <code>null</code> if none. The path may have
+ * a device.
+ *
+ * @param path absolute path, or <code>null</code>
+ * @return resource or <code>null</code>
+ */
+ protected IResource getResource(IPath path) {
+ if (path != null) {
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ if (path.getDevice() == null) {
+ // search relative to the workspace if no device present
+ return root.findMember(path);
+ }
+ // look for files or folders with the given path
+ IFile[] files = root.findFilesForLocation(path);
+ if (files.length > 0) {
+ return files[0];
+ }
+ IContainer[] containers = root.findContainersForLocation(path);
+ if (containers.length > 0) {
+ return containers[0];
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Initlaizes the classpath property based on this entry's type.
+ */
+ private void initializeLoadpathProperty() {
+ switch (getType()) {
+ case VARIABLE:
+ if (getVariableName().equals(RubyRuntime.RUBYLIB_VARIABLE)) {
+ setLoadpathProperty(STANDARD_CLASSES);
+ } else {
+ setLoadpathProperty(USER_CLASSES);
+ }
+ break;
+ case PROJECT:
+ case ARCHIVE:
+ setLoadpathProperty(USER_CLASSES);
+ break;
+ default:
+ break;
+ }
+ }
+
+
+ /**
+ * @see IRuntimeLoadpathEntry#setLoadpathProperty(int)
+ */
+ public void setLoadpathProperty(int location) {
+ fLoadpathProperty = location;
+ }
+
+ /**
+ * @see IRuntimeLoadpathEntry#setLoadpathProperty(int)
+ */
+ public int getLoadpathProperty() {
+ return fLoadpathProperty;
+ }
+
+ /**
+ * @see IRuntimeLoadpathEntry#getLocation()
+ */
+ public String getLocation() {
+
+ IPath path = null;
+ switch (getType()) {
+ case PROJECT :
+ IRubyProject pro = (IRubyProject) RubyCore.create(getResource());
+ if (pro != null) {
+ path = pro.getPath();
+ }
+ break;
+ case ARCHIVE :
+ path = getPath();
+ break;
+ case VARIABLE :
+ ILoadpathEntry resolved = getResolvedLoadpathEntry();
+ if (resolved != null) {
+ path = resolved.getPath();
+ }
+ break;
+ case CONTAINER :
+ break;
+ }
+ return resolveToOSPath(path);
+ }
+
+ /**
+ * Returns the OS path for the given aboslute or workspace relative path
+ */
+ protected String resolveToOSPath(IPath path) {
+ if (path != null) {
+ IResource res = null;
+ if (path.getDevice() == null) {
+ // if there is no device specified, find the resource
+ res = getResource(path);
+ }
+ if (res == null) {
+ return path.toOSString();
+ }
+ IPath location = res.getLocation();
+ if (location != null) {
+ return location.toOSString();
+ }
+ }
+ return null;
+ }
+
+ /**
+ * @see IRuntimeLoadpathEntry#getVariableName()
+ */
+ public String getVariableName() {
+ if (getType() == IRuntimeLoadpathEntry.VARIABLE || getType() == IRuntimeLoadpathEntry.CONTAINER) {
+ return getPath().segment(0);
+ }
+ return null;
+ }
+
+ /**
+ * @see Object#equals(Object)
+ */
+ public boolean equals(Object obj) {
+ if (obj instanceof IRuntimeLoadpathEntry) {
+ IRuntimeLoadpathEntry r = (IRuntimeLoadpathEntry)obj;
+ if (getType() == r.getType() && getLoadpathProperty() == r.getLoadpathProperty()) {
+ if (getType() == IRuntimeLoadpathEntry.CONTAINER) {
+ String id = getPath().segment(0);
+ LoadpathContainerInitializer initializer = RubyCore.getLoadpathContainerInitializer(id);
+ IRubyProject javaProject1 = getRubyProject();
+ IRubyProject javaProject2 = r.getRubyProject();
+ if (initializer == null || javaProject1 == null || javaProject2 == null) {
+ // containers are equal if their ID is equal by default
+ return getPath().equals(r.getPath());
+ }
+ Object comparisonID1 = initializer.getComparisonID(getPath(), javaProject1);
+ Object comparisonID2 = initializer.getComparisonID(r.getPath(), javaProject2);
+ return comparisonID1.equals(comparisonID2);
+ } else {
+ return getPath() != null && getPath().equals(r.getPath());
+ }
+ }
+ }
+ return false;
+ }
+
+ /**
+ * Returns whether the given objects are equal, accounting for null
+ */
+ protected boolean equal(Object one, Object two) {
+ if (one == null) {
+ return two == null;
+ }
+ return one.equals(two);
+ }
+
+ /**
+ * @see Object#hashCode()
+ */
+ public int hashCode() {
+ if (getType() == CONTAINER) {
+ return getPath().segment(0).hashCode() + getType();
+ }
+ return getPath().hashCode() + getType();
+ }
+
+ /**
+ * Creates a new underlying classpath entry for this runtime classpath entry
+ * with the given paths, due to a change in source attachment.
+ */
+ protected void updateLoadpathEntry(IPath path, IPath sourcePath, IPath rootPath) {
+ ILoadpathEntry entry = null;
+ ILoadpathEntry original = getLoadpathEntry();
+ switch (getType()) {
+ case ARCHIVE:
+ entry = RubyCore.newLibraryEntry(path, original.isExported());
+ break;
+ case VARIABLE:
+ entry = RubyCore.newVariableEntry(path);
+ break;
+ default:
+ return;
+ }
+ setLoadpathEntry(entry);
+ }
+
+ /**
+ * Returns the resolved classpath entry associated with this runtime
+ * entry, resolving if required.
+ */
+ protected ILoadpathEntry getResolvedLoadpathEntry() {
+ if (fResolvedEntry == null) {
+ fResolvedEntry = RubyCore.getResolvedLoadpathEntry(getLoadpathEntry());
+ }
+ return fResolvedEntry;
+ }
+
+ protected boolean isEmpty(String string) {
+ return string == null || string.length() == 0;
+ }
+
+ public String toString() {
+ if (fLoadpathEntry != null) {
+ return fLoadpathEntry.toString();
+ }
+ return super.toString();
+
+ }
+ /* (non-Rubydoc)
+ * @see org.eclipse.jdt.launching.IRuntimeLoadpathEntry#getRubyProject()
+ */
+ public IRubyProject getRubyProject() {
+ return fRubyProject;
+ }
+
+ /**
+ * Sets the Ruby project associated with this classpath entry.
+ *
+ * @param project Ruby project
+ */
+ public void setRubyProject(IRubyProject project) {
+ fRubyProject = project;
+ }
+}
Added: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RuntimeLoadpathEntryResolver.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RuntimeLoadpathEntryResolver.java (rev 0)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RuntimeLoadpathEntryResolver.java 2007-01-19 19:03:28 UTC (rev 1814)
@@ -0,0 +1,110 @@
+/*******************************************************************************
+ * Copyright (c) 2000, 2005 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * IBM Corporation - initial API and implementation
+ *******************************************************************************/
+package org.rubypeople.rdt.internal.launching;
+
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.IConfigurationElement;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.rubypeople.rdt.core.ILoadpathEntry;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.launching.IRuntimeLoadpathEntry;
+import org.rubypeople.rdt.launching.IRuntimeLoadpathEntryResolver;
+import org.rubypeople.rdt.launching.IRuntimeLoadpathEntryResolver2;
+import org.rubypeople.rdt.launching.IVMInstall;
+
+/**
+ * Proxy to a runtime classpath entry resolver extension.
+ */
+public class RuntimeLoadpathEntryResolver implements IRuntimeLoadpathEntryResolver2 {
+
+ private IConfigurationElement fConfigurationElement;
+
+ private IRuntimeLoadpathEntryResolver fDelegate;
+
+ /**
+ * Constructs a new resolver on the given configuration element
+ */
+ public RuntimeLoadpathEntryResolver(IConfigurationElement element) {
+ fConfigurationElement = element;
+ }
+
+ /**
+ * @see IRuntimeLoadpathEntryResolver#resolveRuntimeLoadpathEntry(IRuntimeLoadpathEntry, ILaunchConfiguration)
+ */
+ public IRuntimeLoadpathEntry[] resolveRuntimeLoadpathEntry(IRuntimeLoadpathEntry entry, ILaunchConfiguration configuration) throws CoreException {
+ return getResolver().resolveRuntimeLoadpathEntry(entry, configuration);
+ }
+
+ /**
+ * Returns the resolver delegate (and creates if required)
+ */
+ protected IRuntimeLoadpathEntryResolver getResolver() throws CoreException {
+ if (fDelegate == null) {
+ fDelegate = (IRuntimeLoadpathEntryResolver)fConfigurationElement.createExecutableExtension("class"); //$NON-NLS-1$
+ }
+ return fDelegate;
+ }
+
+ /**
+ * Returns the variable name this resolver is registered for, or <code>null</code>
+ */
+ public String getVariableName() {
+ return fConfigurationElement.getAttribute("variable"); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns the container id this resolver is registered for, or <code>null</code>
+ */
+ public String getContainerId() {
+ return fConfigurationElement.getAttribute("container"); //$NON-NLS-1$
+ }
+
+ /**
+ * Returns the runtime classpath entry id this resolver is registered
+ * for,or <code>null</code> if none.
+ */
+ public String getRuntimeLoadpathEntryId() {
+ return fConfigurationElement.getAttribute("runtimeLoadpathEntryId"); //$NON-NLS-1$
+ }
+
+ /**
+ * @see IRuntimeLoadpathEntryResolver#resolveVMInstall(ILoadpathEntry)
+ */
+ public IVMInstall resolveVMInstall(ILoadpathEntry entry) throws CoreException {
+ return getResolver().resolveVMInstall(entry);
+ }
+
+ /**
+ * @see IRuntimeLoadpathEntryResolver#resolveRuntimeLoadpathEntry(IRuntimeLoadpathEntry, IRubyProject)
+ */
+ public IRuntimeLoadpathEntry[] resolveRuntimeLoadpathEntry(IRuntimeLoadpathEntry entry, IRubyProject project) throws CoreException {
+ return getResolver().resolveRuntimeLoadpathEntry(entry, project);
+ }
+
+ /* (non-Rubydoc)
+ * @see org.eclipse.jdt.launching.IRuntimeLoadpathEntryResolver2#isVMInstallReference(org.eclipse.jdt.core.ILoadpathEntry)
+ */
+ public boolean isVMInstallReference(ILoadpathEntry entry) {
+ try {
+ IRuntimeLoadpathEntryResolver resolver = getResolver();
+ if (resolver instanceof IRuntimeLoadpathEntryResolver2) {
+ IRuntimeLoadpathEntryResolver2 resolver2 = (IRuntimeLoadpathEntryResolver2) resolver;
+ return resolver2.isVMInstallReference(entry);
+ } else {
+ return resolver.resolveVMInstall(entry) != null;
+ }
+ } catch (CoreException e) {
+ return false;
+ }
+ }
+
+}
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IRubyLaunchConfigurationConstants.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IRubyLaunchConfigurationConstants.java 2007-01-19 18:38:07 UTC (rev 1813)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/IRubyLaunchConfigurationConstants.java 2007-01-19 19:03:28 UTC (rev 1814)
@@ -3,6 +3,18 @@
import org.rubypeople.rdt.internal.launching.LaunchingPlugin;
public interface IRubyLaunchConfigurationConstants {
+
+ /**
+ * Status code indicating a launch configuration does not
+ * specify a VM Install
+ */
+ public static final int ERR_UNSPECIFIED_VM_INSTALL = 103;
+
+ /**
+ * Status code indicating the project associated with
+ * a launch configuration is not a Ruby project.
+ */
+ public static final int ERR_NOT_A_RUBY_PROJECT = 107;
/**
* Status code indicating the specified working directory
@@ -11,6 +23,14 @@
public static final int ERR_WORKING_DIRECTORY_DOES_NOT_EXIST = 108;
/**
+ * Status code indicating that the project referenced by a launch configuration
+ * is closed.
+ *
+ * @since 0.9.0
+ */
+ public static final int ERR_PROJECT_CLOSED = 124;
+
+ /**
* Status code indicating an unexpected internal error.
*/
public static final int ERR_INTERNAL_ERROR = 150;
@@ -30,4 +50,46 @@
*/
public static final String ATTR_RUBY_COMMAND = LaunchingPlugin.getUniqueIdentifier() + ".RUBY_COMMAND"; //$NON-NLS-1$
+ /**
+ * Launch configuration attribute key. The value is a name of
+ * a Ruby project associated with a Ruby launch configuration.
+ */
+ public static final String ATTR_PROJECT_NAME = LaunchingPlugin.getUniqueIdentifier() + ".PROJECT_ATTR"; //$NON-NLS-1$
+
+
+ /**
+ * Launch configuration attribute key. The value is a path identifying the JRE used
+ * when launching a local VM. The path is a classpath container corresponding
+ * to the <code>JavaRuntime.JRE_CONTAINER</code> classpath container.
+ * <p>
+ * When unspecified the default JRE for a launch configuration is used (which is the
+ * JRE associated with the project being launched, or the workspace default JRE when
+ * no project is associated with a configuration). The default JRE classpath container
+ * refers explicitly to the workspace default JRE.
+ * </p>
+ * @since 3.2
+ */
+ public static final String ATTR_JRE_CONTAINER_PATH = RubyRuntime.RUBY_CONTAINER;
+
+ /**
+ * Launch configuration attribute key. The value is a name of a VM install
+ * to use when launching a local VM. This attribute must be qualified
+ * by a VM install type, via the <code>ATTR_VM_INSTALL_TYPE</code>
+ * attribute. When unspecified, the default VM is used.
+ *
+ * @deprecated use <code>ATTR_JRE_CONTAINER_PATH</code>
+ */
+ public static final String ATTR_VM_INSTALL_NAME = LaunchingPlugin.getUniqueIdentifier() + ".VM_INSTALL_NAME"; //$NON-NLS-1$
+
+ /**
+ * Launch configuration attribute key. The value is an identifier of
+ * a VM install type. Used in conjunction with a VM install name, to
+ * specify the VM to use when launching a local Java application.
+ * The associated VM install name is specified via the attribute
+ * <code>ATTR_VM_INSTALL_NAME</code>.
+ *
+ * @deprecated use <code>ATTR_JRE_CONTAINER_PATH</code>
+ */
+ public static final String ATTR_VM_INSTALL_TYPE = LaunchingPlugin.getUniqueIdentifier() + ".VM_INSTALL_TYPE_ID"; //$NON-NLS-1$
+
}
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-19 18:38:07 UTC (rev 1813)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/RubyRuntime.java 2007-01-19 19:03:28 UTC (rev 1814)
@@ -6,14 +6,17 @@
import java.io.IOException;
import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
+import java.util.Map;
import java.util.Set;
import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.TransformerException;
+import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
@@ -25,17 +28,19 @@
import org.eclipse.core.runtime.Preferences;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.variables.VariablesPlugin;
+import org.eclipse.debug.core.ILaunchConfiguration;
+import org.rubypeople.rdt.core.ILoadpathEntry;
+import org.rubypeople.rdt.core.IRubyModel;
+import org.rubypeople.rdt.core.IRubyProject;
+import org.rubypeople.rdt.core.RubyCore;
import org.rubypeople.rdt.internal.launching.CompositeId;
import org.rubypeople.rdt.internal.launching.LaunchingMessages;
import org.rubypeople.rdt.internal.launching.LaunchingPlugin;
import org.rubypeople.rdt.internal.launching.ListenerList;
+import org.rubypeople.rdt.internal.launching.RuntimeLoadpathEntryResolver;
import org.rubypeople.rdt.internal.launching.VMDefinitionsContainer;
public class RubyRuntime {
- private static final String TAG_INTERPRETER = "interpreter";
- private static final String ATTR_PATH = "path";
- private static final String ATTR_NAME = "name";
- private static final String ATTR_SELECTED = "selected";
/**
* Loadpath container used for a project's Ruby
@@ -79,6 +84,13 @@
*/
public static final String RUBYLIB_VARIABLE= "RUBY_LIB"; //$NON-NLS-1$
+ /**
+ * Simple identifier constant (value <code>"runtimeLoadpathEntryResolvers"</code>) for the
+ * runtime loadpath entry resolvers extension point.
+ *
+ * @since 0.9.0
+ */
+ public static final String EXTENSION_POINT_RUNTIME_CLASSPATH_ENTRY_RESOLVERS= "runtimeLoadpathEntryResolvers"; //$NON-NLS-1$
private static IVMInstallType[] fgVMTypes= null;
@@ -86,16 +98,21 @@
private static Object fgVMLock = new Object();
private static boolean fgInitializingVMs;
private static String fgDefaultVMId;
+ private static ListenerList fgVMListeners = new ListenerList(5);
+ private static String fgDefaultVMConnectorId;
/**
* Set of IDs of VMs contributed via vmInstalls extension point.
*/
private static Set<String> fgContributedVMs = new HashSet<String>();
-
- protected static List<IVMInstall> installedInterpreters;
- protected static IVMInstall selectedInterpreter;
- private static ListenerList fgVMListeners = new ListenerList(5);
- private static String fgDefaultVMConnectorId;
+
+ /**
+ * Resolvers keyed by variable name, container id,
+ * and runtime classpath entry id.
+ */
+ private static Map fgVariableResolvers = null;
+ private static Map fgContainerResolvers = null;
+ private static Map fgRuntimeClasspathEntryResolvers = null;
protected RubyRuntime() {
super();
@@ -648,4 +665,223 @@
}
return libraryPaths;
}
+
+ /**
+ * Returns the VM install for the given launch configuration.
+ * The VM install is determined in the following prioritized way:
+ * <ol>
+ * <li>The VM install is explicitly specified on the launch configuration
+ * via the <code>ATTR_JRE_CONTAINER_PATH</code> attribute (since 3.2).</li>
+ * <li>The VM install is explicitly specified on the launch configuration
+ * via the <code>ATTR_VM_INSTALL_TYPE</code> and <code>ATTR_VM_INSTALL_ID</code>
+ * attributes.</li>
+ * <li>If no explicit VM install is specified, the VM install associated with
+ * the launch configuration's project is returned.</li>
+ * <li>If no project is specified, or the project does not specify a custom
+ * VM install, the workspace default VM install is returned.</li>
+ * </ol>
+ *
+ * @param configuration launch configuration
+ * @return vm install
+ * @exception CoreException if unable to compute a vm install
+ * @since 0.9.0
+ */
+ public static IVMInstall computeVMInstall(ILaunchConfiguration configuration) throws CoreException {
+ String jreAttr = configuration.getAttribute(IRubyLaunchConfigurationConstants.ATTR_JRE_CONTAINER_PATH, (String)null);
+ if (jreAttr == null) {
+ String type = configuration.getAttribute(IRubyLaunchConfigurationConstants.ATTR_VM_INSTALL_TYPE, (String)null);
+ if (type == null) {
+ IRubyProject proj = getRubyProject(configuration);
+ if (proj != null) {
+ IVMInstall vm = getVMInstall(proj);
+ if (vm != null) {
+ return vm;
+ }
+ }
+ } else {
+ String name = configuration.getAttribute(IRubyLaunchConfigurationConstants.ATTR_VM_INSTALL_NAME, (String)null);
+ return resolveVM(type, name, configuration);
+ }
+ } else {
+ IPath jrePath = Path.fromPortableString(jreAttr);
+ ILoadpathEntry entry = RubyCore.newContainerEntry(jrePath);
+ IRuntimeLoadpathEntryResolver2 resolver = getVariableResolver(jrePath.segment(0));
+ if (resolver != null) {
+ return resolver.resolveVMInstall(entry);
+ } else {
+ resolver = getContainerResolver(jrePath.segment(0));
+ if (resolver != null) {
+ return resolver.resolveVMInstall(entry);
+ }
+ }
+ }
+
+ return getDefaultVMInstall();
+ }
+
+ /**
+ * Returns the VM of the given type with the specified name.
+ *
+ * @param type vm type identifier
+ * @param name vm name
+ * @return vm install
+ * @exception CoreException if unable to resolve
+ * @since 0.9.0
+ */
+ private static IVMInstall resolveVM(String type, String name, ILaunchConfiguration configuration) throws CoreException {
+ IVMInstallType vt = getVMInstallType(type);
+ if (vt == null) {
+ // error type does not exist
+ abort(MessageFormat.format(LaunchingMessages.JavaRuntime_Specified_VM_install_type_does_not_exist___0__2, new String[] {type}), null);
+ }
+ IVMInstall vm = null;
+ // look for a name
+ if (name == null) {
+ // error - type specified without a specific install (could be an old config that specified a VM ID)
+ // log the error, but choose the default VM.
+ IStatus status = new Status(IStatus.WARNING, LaunchingPlugin.getUniqueIdentifier(), IRubyLaunchConfigurationConstants.ERR_UNSPECIFIED_VM_INSTALL, MessageFormat.format(LaunchingMessages.JavaRuntime_VM_not_fully_specified_in_launch_configuration__0____missing_VM_name__Reverting_to_default_VM__1, new String[] {configuration.getName()}), null);
+ LaunchingPlugin.log(status);
+ return getDefaultVMInstall();
+ }
+ vm = vt.findVMInstallByName(name);
+ if (vm == null) {
+ // error - install not found
+ abort(MessageFormat.format(LaunchingMessages.JavaRuntime_Specified_VM_install_not_found__type__0___name__1__2, new String[] {vt.getName(), name}), null);
+ } else {
+ return vm;
+ }
+ // won't reach here
+ return null;
+ }
+
+ /**
+ * Returns the resolver registered for the given variable, or
+ * <code>null</code> if none.
+ *
+ * @param variableName the variable to determine the resolver for
+ * @return the resolver registered for the given variable, or
+ * <code>null</code> if none
+ */
+ private static IRuntimeLoadpathEntryResolver2 getVariableResolver(String variableName) {
+ return (IRuntimeLoadpathEntryResolver2)getVariableResolvers().get(variableName);
+ }
+
+ /**
+ * Returns the resolver registered for the given container id, or
+ * <code>null</code> if none.
+ *
+ * @param containerId the container to determine the resolver for
+ * @return the resolver registered for the given container id, or
+ * <code>null</code> if none
+ */
+ private static IRuntimeLoadpathEntryResolver2 getContainerResolver(String containerId) {
+ return (IRuntimeLoadpathEntryResolver2)getContainerResolvers().get(containerId);
+ }
+
+ private static Map getVariableResolvers() {
+ if (fgVariableResolvers == null) {
+ initializeResolvers();
+ }
+ return fgVariableResolvers;
+ }
+
+ /**
+ * Returns all registered container resolvers.
+ */
+ private static Map getContainerResolvers() {
+ if (fgContainerResolvers == null) {
+ initializeResolvers();
+ }
+ return fgContainerResolvers;
+ }
+
+ private static void initializeResolvers() {
+ IExtensionPoint point = Platform.getExtensionRegistry().getExtensionPoint(LaunchingPlugin.PLUGIN_ID, EXTENSION_POINT_RUNTIME_CLASSPATH_ENTRY_RESOLVERS);
+ IConfigurationElement[] extensions = point.getConfigurationElements();
+ fgVariableResolvers = new HashMap(extensions.length);
+ fgContainerResolvers = new HashMap(extensions.length);
+ fgRuntimeClasspathEntryResolvers = new HashMap(extensions.length);
+ for (int i = 0; i < extensions.length; i++) {
+ RuntimeLoadpathEntryResolver res = new RuntimeLoadpathEntryResolver(extensions[i]);
+ String variable = res.getVariableName();
+ String container = res.getContainerId();
+ String entryId = res.getRuntimeLoadpathEntryId();
+ if (variable != null) {
+ fgVariableResolvers.put(variable, res);
+ }
+ if (container != null) {
+ fgContainerResolvers.put(container, res);
+ }
+ if (entryId != null) {
+ fgRuntimeClasspathEntryResolvers.put(entryId, res);
+ }
+ }
+ }
+
+ /**
+ * Returns the VM assigned to build the given Java project.
+ * The project must exist. The VM assigned to a project is
+ * determined from its build path.
+ *
+ * @param project the project to retrieve the VM from
+ * @return the VM instance that is assigned to build the given Java project
+ * Returns <code>null</code> if no VM is referenced on the project's build path.
+ * @throws CoreException if unable to determine the project's VM install
+ */
+ public static IVMInstall getVMInstall(IRubyProject project) throws CoreException {
+ // check the classpath
+ IVMInstall vm = null;
+ ILoadpathEntry[] classpath = project.getRawLoadpath();
+ IRuntimeLoadpathEntryResolver resolver = null;
+ for (int i = 0; i < classpath.length; i++) {
+ ILoadpathEntry entry = classpath[i];
+ switch (entry.getEntryKind()) {
+ case ILoadpathEntry.CPE_VARIABLE:
+ resolver = getVariableResolver(entry.getPath().segment(0));
+ if (resolver != null) {
+ vm = resolver.resolveVMInstall(entry);
+ }
+ break;
+ case ILoadpathEntry.CPE_CONTAINER:
+ resolver = getContainerResolver(entry.getPath().segment(0));
+ if (resolver != null) {
+ vm = resolver.resolveVMInstall(entry);
+ }
+ break;
+ }
+ if (vm != null) {
+ return vm;
+ }
+ }
+ return null;
+ }
+
+ /**
+ * Return the <code>IRubyProject</code> referenced in the specified configuration or
+ * <code>null</code> if none.
+ *
+ * @exception CoreException if the referenced Ruby project does not exist
+ * @since 0.9.0
+ */
+ public static IRubyProject getRubyProject(ILaunchConfiguration configuration) throws CoreException {
+ String projectName = configuration.getAttribute(IRubyLaunchConfigurationConstants.ATTR_PROJECT_NAME, (String)null);
+ if ((projectName == null) || (projectName.trim().length() < 1)) {
+ return null;
+ }
+ IRubyProject javaProject = getRubyModel().getRubyProject(projectName);
+ if (javaProject != null && javaProject.getProject().exists() && !javaProject.getProject().isOpen()) {
+ abort(MessageFormat.format(LaunchingMessages.JavaRuntime_28, new String[] {configuration.getName(), projectName}), IRubyLaunchConfigurationConstants.ERR_PROJECT_CLOSED, null);
+ }
+ if ((javaProject == null) || !javaProject.exists()) {
+ abort(MessageFormat.format(LaunchingMessages.JavaRuntime_Launch_configuration__0__references_non_existing_project__1___1, new String[] {configuration.getName(), projectName}), IRubyLaunchConfigurationConstants.ERR_NOT_A_RUBY_PROJECT, null);
+ }
+ return javaProject;
+ }
+
+ /**
+ * Convenience method to get the ruby model.
+ */
+ private static IRubyModel getRubyModel() {
+ return RubyCore.create(ResourcesPlugin.getWorkspace().getRoot());
+ }
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|