|
From: <caw...@us...> - 2007-01-25 14:19:06
|
Revision: 1879
http://svn.sourceforge.net/rubyeclipse/?rev=1879&view=rev
Author: cawilliams
Date: 2007-01-25 06:19:04 -0800 (Thu, 25 Jan 2007)
Log Message:
-----------
modify detctection of default libraries. Now we execute a script which spits our the ruby version and loadpaths for us, then we parse them to get our LibraryInfo. Removed extension and endorsed directories from library/vm stuff since that sort of thing doesn't make sense for ruby
Modified Paths:
--------------
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LaunchingPlugin.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LibraryInfo.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RubyVMRuntimeLoadpathEntryResolver.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVMType.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.launching/ruby/loadpath.rb
Added: trunk/org.rubypeople.rdt.launching/ruby/loadpath.rb
===================================================================
--- trunk/org.rubypeople.rdt.launching/ruby/loadpath.rb (rev 0)
+++ trunk/org.rubypeople.rdt.launching/ruby/loadpath.rb 2007-01-25 14:19:04 UTC (rev 1879)
@@ -0,0 +1,2 @@
+puts RUBY_VERSION
+puts $LOAD_PATH - ['.']
\ No newline at end of file
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-25 14:18:01 UTC (rev 1878)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LaunchingPlugin.java 2007-01-25 14:19:04 UTC (rev 1879)
@@ -7,6 +7,7 @@
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
+import java.net.URL;
import java.text.MessageFormat;
import java.util.ArrayList;
import java.util.HashMap;
@@ -29,6 +30,7 @@
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IConfigurationElement;
import org.eclipse.core.runtime.IExtensionPoint;
import org.eclipse.core.runtime.IPath;
@@ -456,8 +458,6 @@
Element libraryElement = doc.createElement("libraryInfo"); //$NON-NLS-1$
libraryElement.setAttribute("version", info.getVersion()); //$NON-NLS-1$
appendPathElements(doc, "bootpath", libraryElement, info.getBootpath()); //$NON-NLS-1$
- appendPathElements(doc, "extensionDirs", libraryElement, info.getExtensionDirs()); //$NON-NLS-1$
- appendPathElements(doc, "endorsedDirs", libraryElement, info.getEndorsedDirs()); //$NON-NLS-1$
return libraryElement;
}
@@ -527,10 +527,8 @@
String version = element.getAttribute("version"); //$NON-NLS-1$
String location = element.getAttribute("home"); //$NON-NLS-1$
String[] bootpath = getPathsFromXML(element, "bootpath"); //$NON-NLS-1$
- String[] extDirs = getPathsFromXML(element, "extensionDirs"); //$NON-NLS-1$
- String[] endDirs = getPathsFromXML(element, "endorsedDirs"); //$NON-NLS-1$
if (location != null) {
- LibraryInfo info = new LibraryInfo(version, bootpath, extDirs, endDirs);
+ LibraryInfo info = new LibraryInfo(version, bootpath);
fgLibraryInfoMap.put(location, info);
}
}
@@ -819,4 +817,19 @@
}
}
+
+ /**
+ * Return a <code>java.io.File</code> object that corresponds to the specified
+ * <code>IPath</code> in the plugin directory.
+ */
+ public static File getFileInPlugin(IPath path) {
+ try {
+ URL installURL =
+ new URL(getDefault().getBundle().getEntry("/"), path.toString()); //$NON-NLS-1$
+ URL localURL = FileLocator.toFileURL(installURL);
+ return new File(localURL.getFile());
+ } catch (IOException ioe) {
+ return null;
+ }
+ }
}
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LibraryInfo.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LibraryInfo.java 2007-01-25 14:18:01 UTC (rev 1878)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/LibraryInfo.java 2007-01-25 14:19:04 UTC (rev 1879)
@@ -18,14 +18,10 @@
private String fVersion;
private String[] fBootpath;
- private String[] fExtensionDirs;
- private String[] fEndorsedDirs;
- public LibraryInfo(String version, String[] bootpath, String[] extDirs, String[] endDirs) {
+ public LibraryInfo(String version, String[] bootpath) {
fVersion = version;
fBootpath = bootpath;
- fExtensionDirs = extDirs;
- fEndorsedDirs = endDirs;
}
/**
@@ -36,17 +32,8 @@
public String getVersion() {
return fVersion;
}
-
+
/**
- * Returns a collection of extension directory paths for this VM install.
- *
- * @return a collection of absolute paths
- */
- public String[] getExtensionDirs() {
- return fExtensionDirs;
- }
-
- /**
* Returns a collection of bootpath entries for this VM install.
*
* @return a collection of absolute paths
@@ -54,13 +41,4 @@
public String[] getBootpath() {
return fBootpath;
}
-
- /**
- * Returns a collection of endorsed directory paths for this VM install.
- *
- * @return a collection of absolute paths
- */
- public String[] getEndorsedDirs() {
- return fEndorsedDirs;
- }
}
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-25 14:18:01 UTC (rev 1878)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/RubyVMRuntimeLoadpathEntryResolver.java 2007-01-25 14:19:04 UTC (rev 1879)
@@ -13,9 +13,7 @@
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;
@@ -94,20 +92,13 @@
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));
- }
+ resolvedEntries.add(resolveLibraryLocation(vm, location, kind, overrideRubydoc));
}
return (IRuntimeLoadpathEntry[]) resolvedEntries.toArray(new IRuntimeLoadpathEntry[resolvedEntries.size()]);
}
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVMType.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVMType.java 2007-01-25 14:18:01 UTC (rev 1878)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVMType.java 2007-01-25 14:19:04 UTC (rev 1879)
@@ -1,13 +1,24 @@
package org.rubypeople.rdt.internal.launching;
+import java.io.BufferedReader;
import java.io.File;
+import java.io.IOException;
+import java.io.StringReader;
+import java.text.MessageFormat;
+import java.util.ArrayList;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
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.eclipse.debug.core.DebugPlugin;
+import org.eclipse.debug.core.ILaunchManager;
+import org.eclipse.debug.core.Launch;
+import org.eclipse.debug.core.model.IProcess;
+import org.eclipse.debug.core.model.IStreamsProxy;
import org.rubypeople.rdt.launching.AbstractVMInstallType;
import org.rubypeople.rdt.launching.IVMInstall;
@@ -37,12 +48,19 @@
return new StandardVM(this, id);
}
- public IPath[] getDefaultLibraryLocations(File installLocation) {
- String stdPath = installLocation.getAbsolutePath() + fgSeparator + "lib" + fgSeparator + "ruby" + fgSeparator + "1.8";
- String sitePath = installLocation.getAbsolutePath() + fgSeparator + "lib" + fgSeparator + "ruby" + fgSeparator + "site_ruby" + fgSeparator + "1.8";
- IPath[] paths = new IPath[2];
- paths[0] = new Path(stdPath);
- paths[1] = new Path(sitePath);
+ public IPath[] getDefaultLibraryLocations(File installLocation) {
+ File rubyExecutable = findRubyExecutable(installLocation);
+ LibraryInfo info = getLibraryInfo(installLocation, rubyExecutable);
+ String[] loadpath = info.getBootpath();
+ IPath[] paths = new IPath[loadpath.length];
+ for (int i = 0; i < loadpath.length; i++) {
+ paths[i] = new Path(loadpath[i]);
+ }
+// String stdPath = installLocation.getAbsolutePath() + fgSeparator + "lib" + fgSeparator + "ruby" + fgSeparator + "1.8";
+// String sitePath = installLocation.getAbsolutePath() + fgSeparator + "lib" + fgSeparator + "ruby" + fgSeparator + "site_ruby" + fgSeparator + "1.8";
+// IPath[] paths = new IPath[2];
+// paths[0] = new Path(stdPath);
+// paths[1] = new Path(sitePath);
return paths;
}
@@ -103,8 +121,7 @@
* location. If the info does not exist, create it using the given Java
* executable.
*/
- protected synchronized LibraryInfo getLibraryInfo(File rubyHome, File rubyExecutable) {
-
+ protected synchronized LibraryInfo getLibraryInfo(File rubyHome, File rubyExecutable) {
// See if we already know the info for the requested VM. If not, generate it.
String installPath = rubyHome.getAbsolutePath();
LibraryInfo info = LaunchingPlugin.getLibraryInfo(installPath);
@@ -124,9 +141,70 @@
return info;
}
- private LibraryInfo generateLibraryInfo(
- File javaHome, File javaExecutable) {
- // TODO Auto-generated method stub
+ private LibraryInfo generateLibraryInfo(File rubyHome, File rubyExecutable) {
+ LibraryInfo info = null;
+ //locate the script to grab us our loadpaths
+ File file = LaunchingPlugin.getFileInPlugin(new Path("ruby/loadpath.rb")); //$NON-NLS-1$
+ if (file.exists()) {
+ String javaExecutablePath = rubyExecutable.getAbsolutePath();
+ String[] cmdLine = new String[] {javaExecutablePath, file.getAbsolutePath()}; //$NON-NLS-1$
+ Process p = null;
+ try {
+ p = Runtime.getRuntime().exec(cmdLine);
+ IProcess process = DebugPlugin.newProcess(new Launch(null, ILaunchManager.RUN_MODE, null), p, "Library Detection"); //$NON-NLS-1$
+ for (int i= 0; i < 200; i++) {
+ // Wait no more than 10 seconds (200 * 50 mils)
+ if (process.isTerminated()) {
+ break;
+ }
+ try {
+ Thread.sleep(50);
+ } catch (InterruptedException e) {
+ }
+ }
+ info = parseLibraryInfo(process);
+ } catch (IOException ioe) {
+ LaunchingPlugin.log(ioe);
+ } finally {
+ if (p != null) {
+ p.destroy();
+ }
+ }
+ }
+ if (info == null) {
+ // log error that we were unable to generate library info - see bug 70011
+ LaunchingPlugin.log(MessageFormat.format("Failed to retrieve default libraries for {0}", new String[]{rubyHome.getAbsolutePath()})); //$NON-NLS-1$
+ }
+ return info;
+ }
+
+ /**
+ * Parses the output from 'LibraryDetector'.
+ */
+ protected LibraryInfo parseLibraryInfo(IProcess process) {
+ IStreamsProxy streamsProxy = process.getStreamsProxy();
+ String text = null;
+ if (streamsProxy != null) {
+ text = streamsProxy.getOutputStreamMonitor().getContents();
+ }
+ BufferedReader reader = new BufferedReader(new StringReader(text));
+ List<String> lines = new ArrayList<String>();
+ try {
+ String line = null;
+ while ((line = reader.readLine()) != null) {
+ lines.add(line);
+ }
+ } catch (IOException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ if (lines.size() > 0) {
+ String version = lines.remove(0);
+ if (lines.size() > 0) {
+ String[] loadpath = (String[]) lines.toArray(new String[lines.size()]);
+ return new LibraryInfo(version, loadpath);
+ }
+ }
return null;
}
@@ -138,21 +216,7 @@
*/
protected LibraryInfo getDefaultLibraryInfo(File installLocation) {
IPath rtjar = getDefaultSystemLibrary(installLocation);
- File extDir = null;
- File endDir = null;
- String[] dirs = null;
- if (extDir == null) {
- dirs = new String[0];
- } else {
- dirs = new String[] {extDir.getAbsolutePath()};
- }
- String[] endDirs = null;
- if (endDir == null) {
- endDirs = new String[0];
- } else {
- endDirs = new String[] {endDir.getAbsolutePath()};
- }
- return new LibraryInfo("1.8.4", new String[] {rtjar.toOSString()}, dirs, endDirs); //$NON-NLS-1$
+ return new LibraryInfo("1.8.4", new String[] {rtjar.toOSString()}); //$NON-NLS-1$
}
/**
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|