|
From: <caw...@us...> - 2007-01-29 14:49:12
|
Revision: 1891
http://svn.sourceforge.net/rubyeclipse/?rev=1891&view=rev
Author: cawilliams
Date: 2007-01-29 06:49:11 -0800 (Mon, 29 Jan 2007)
Log Message:
-----------
move the core_stuibber ruby script over to launching. Invoke it under the hood of StandardVM so we can generate core stubs and add them to our default load path (really only so we can treat them like the rest of the libraries and get them into the model).
Modified Paths:
--------------
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVM.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVMType.java
trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/AbstractVMInstall.java
Added Paths:
-----------
trunk/org.rubypeople.rdt.launching/ruby/core_stubber.rb
Removed Paths:
-------------
trunk/org.rubypeople.rdt.core/ruby/core_stubber.rb
Deleted: trunk/org.rubypeople.rdt.core/ruby/core_stubber.rb
===================================================================
--- trunk/org.rubypeople.rdt.core/ruby/core_stubber.rb 2007-01-29 09:09:18 UTC (rev 1890)
+++ trunk/org.rubypeople.rdt.core/ruby/core_stubber.rb 2007-01-29 14:49:11 UTC (rev 1891)
@@ -1,81 +0,0 @@
-OUTPUT_PATH = "ruby/lib/"
-
-def file_name(klass)
- file_name = OUTPUT_PATH + klass.to_s.downcase
- file_name.gsub!("::", "/")
- file_name << ".rb"
- return file_name
-end
-
-def dir_names(file_name)
- last_slash = file_name.rindex("/")
- return nil if last_slash.nil?
- file_name[0...last_slash]
-end
-
-def print_method(f, method, method_name, singleton = false)
- f << " def "
- f << "self." if singleton
- f << method_name.to_s
- if !method.nil? and method.arity != 0
- # TODO We need to handle methods that take blocks!
- f << "("
- if method.arity < 0
- args = []
- (method.arity.abs + 1).times {|i| args << "arg#{i}" }
- args << "*rest"
- f << args.join(", ")
- else
- args = []
- method.arity.times {|i| args << "arg#{i}" }
- f << args.join(", ")
- end
- f << ")"
- end
- f << "\n end\n"
-end
-
-require 'FileUtils'
-@klasses = Module.constants.select {|c| ["Class", "Module"].include?(eval("#{c}.class").to_s) }
-@klasses = @klasses.collect {|k| eval("#{k}")}
-@klasses = @klasses.uniq.sort_by {|klass| klass.to_s }
-@klasses.each do |klass|
- next if klass.to_s[0].chr == "f" # TODO Skip if first char is lowercase
- file_name = file_name(klass)
- dirs = dir_names(file_name)
- FileUtils.mkdir_p(dirs) if !dirs.nil? and !File.exist?(file_name)
- open(file_name, 'w') do |f|
- f << "#{klass.class.to_s.downcase} #{klass}"
- f << " < #{klass.superclass.to_s }" if klass.respond_to?(:superclass) and !klass.superclass.nil?
- f << "\n"
- klass.included_modules.each {|mod| f << " include #{mod.to_s}\n" unless mod.to_s == "Kernel" && klass.to_s != "Object"}
- f << "\n"
- klass.methods(false).each do |method_name|
- method = eval("#{klass}").method(method_name) rescue nil
- print_method(f, method, method_name.to_s, true)
- end
- # TODO Fix it so we can get a hold of the module instance methods properly
- klass.instance_methods(false).each do |method_name|
- begin
- obj = if klass.class.to_s == "Module" then klass else klass.new end
- method = obj.method(method_name.to_s)
- rescue StandardError => e
- puts e
- # TODO If we can't create an instance of a class, generate dynamic subclass where we can, and then
- # grab methods from there
- begin
- # If we're a module, we may need to force the function to be more visible to grab it
- obj.module_eval do
- module_function(method_name.to_s)
- end
- method = obj.method(method_name.to_s)
- rescue StandardError => e
- puts e
- method = nil
- end
- end
- print_method(f, method, method_name.to_s)
- end
- f << "end\n"
- end
-end
\ No newline at end of file
Added: trunk/org.rubypeople.rdt.launching/ruby/core_stubber.rb
===================================================================
--- trunk/org.rubypeople.rdt.launching/ruby/core_stubber.rb (rev 0)
+++ trunk/org.rubypeople.rdt.launching/ruby/core_stubber.rb 2007-01-29 14:49:11 UTC (rev 1891)
@@ -0,0 +1,81 @@
+OUTPUT_PATH = ARGV.first + "/"
+
+def file_name(klass)
+ file_name = OUTPUT_PATH + klass.to_s.downcase
+ file_name.gsub!("::", "/")
+ file_name << ".rb"
+ return file_name
+end
+
+def dir_names(file_name)
+ last_slash = file_name.rindex("/")
+ return nil if last_slash.nil?
+ file_name[0...last_slash]
+end
+
+def print_method(f, method, method_name, singleton = false)
+ f << " def "
+ f << "self." if singleton
+ f << method_name.to_s
+ if !method.nil? and method.arity != 0
+ # TODO We need to handle methods that take blocks!
+ f << "("
+ if method.arity < 0
+ args = []
+ (method.arity.abs + 1).times {|i| args << "arg#{i}" }
+ args << "*rest"
+ f << args.join(", ")
+ else
+ args = []
+ method.arity.times {|i| args << "arg#{i}" }
+ f << args.join(", ")
+ end
+ f << ")"
+ end
+ f << "\n end\n"
+end
+
+require 'FileUtils'
+@klasses = Module.constants.select {|c| ["Class", "Module"].include?(eval("#{c}.class").to_s) }
+@klasses = @klasses.collect {|k| eval("#{k}")}
+@klasses = @klasses.uniq.sort_by {|klass| klass.to_s }
+@klasses.each do |klass|
+ next if klass.to_s[0].chr == "f" # TODO Skip if first char is lowercase
+ file_name = file_name(klass)
+ dirs = dir_names(file_name)
+ FileUtils.mkdir_p(dirs) if !dirs.nil? and !File.exist?(file_name)
+ open(file_name, 'w') do |f|
+ f << "#{klass.class.to_s.downcase} #{klass}"
+ f << " < #{klass.superclass.to_s }" if klass.respond_to?(:superclass) and !klass.superclass.nil?
+ f << "\n"
+ klass.included_modules.each {|mod| f << " include #{mod.to_s}\n" unless mod.to_s == "Kernel" && klass.to_s != "Object"}
+ f << "\n"
+ klass.methods(false).each do |method_name|
+ method = eval("#{klass}").method(method_name) rescue nil
+ print_method(f, method, method_name.to_s, true)
+ end
+ # TODO Fix it so we can get a hold of the module instance methods properly
+ klass.instance_methods(false).each do |method_name|
+ begin
+ obj = if klass.class.to_s == "Module" then klass else klass.new end
+ method = obj.method(method_name.to_s)
+ rescue StandardError => e
+ puts e
+ # TODO If we can't create an instance of a class, generate dynamic subclass where we can, and then
+ # grab methods from there
+ begin
+ # If we're a module, we may need to force the function to be more visible to grab it
+ obj.module_eval do
+ module_function(method_name.to_s)
+ end
+ method = obj.method(method_name.to_s)
+ rescue StandardError => e
+ puts e
+ method = nil
+ end
+ end
+ print_method(f, method, method_name.to_s)
+ end
+ f << "end\n"
+ end
+end
\ No newline at end of file
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVM.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVM.java 2007-01-29 09:09:18 UTC (rev 1890)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVM.java 2007-01-29 14:49:11 UTC (rev 1891)
@@ -1,14 +1,25 @@
package org.rubypeople.rdt.internal.launching;
import java.io.File;
+import java.io.IOException;
+import org.eclipse.core.runtime.IPath;
+import org.eclipse.core.runtime.Path;
+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.rubypeople.rdt.launching.AbstractVMInstall;
+import org.rubypeople.rdt.launching.IVMInstallChangedListener;
import org.rubypeople.rdt.launching.IVMInstallType;
import org.rubypeople.rdt.launching.IVMRunner;
+import org.rubypeople.rdt.launching.PropertyChangeEvent;
+import org.rubypeople.rdt.launching.RubyRuntime;
public class StandardVM extends AbstractVMInstall {
+ private String fgSeparator;
+
public StandardVM(IVMInstallType type, String id) {
super(type, id);
}
@@ -55,4 +66,90 @@
return null;
}
+ @Override
+ public void setLibraryLocations(IPath[] locations) {
+ if (locations == fSystemLibraryDescriptions) {
+ return;
+ }
+ IPath[] newLocations = locations;
+ if (newLocations == null) {
+ newLocations = getDefaultLibraryLocations();
+ }
+ IPath[] prevLocations = fSystemLibraryDescriptions;
+ if (prevLocations == null) {
+ prevLocations = getDefaultLibraryLocations();
+ }
+
+ if (newLocations.length == prevLocations.length) {
+ int i = 0;
+ boolean equal = true;
+ while (i < newLocations.length && equal) {
+ equal = newLocations[i].equals(prevLocations[i]);
+ i++;
+ }
+ if (equal) {
+ // no change
+ return;
+ }
+ }
+
+ PropertyChangeEvent event = new PropertyChangeEvent(this, IVMInstallChangedListener.PROPERTY_LIBRARY_LOCATIONS, prevLocations, newLocations);
+ fSystemLibraryDescriptions = locations;
+ if (fNotify) {
+ RubyRuntime.fireVMChanged(event);
+ }
+ }
+
+ private IPath[] getDefaultLibraryLocations() {
+ IPath[] dflts = getVMInstallType().getDefaultLibraryLocations(getInstallLocation());
+ IPath[] paths = new IPath[dflts.length + 1];
+ for (int i = 0; i < dflts.length; i++) {
+ paths[i] = dflts[i];
+ }
+ // FIXME Handle possible null pointer being returned by findRubyExecutable
+ paths[dflts.length] = generateCoreStubs(StandardVMType.findRubyExecutable(getInstallLocation()));
+ return dflts;
+ }
+
+ /**
+ * Launch a ruby script to generate core class stubs for use in RDT internally (since Ruby core
+ * stuff is not in any scripts, they're built into the VM in C code).
+ * @param rubyExecutable
+ * @return an IPath pointing to the directory containing the core library stubs
+ */
+ private IPath generateCoreStubs(File rubyExecutable) {
+ //locate the script to generate our core stubs
+ File file = LaunchingPlugin.getFileInPlugin(new Path("ruby" + fgSeparator + "core_stubber.rb")); //$NON-NLS-1$
+ IPath path = new Path(file.getParentFile().getAbsolutePath() + fgSeparator + getId() + fgSeparator + "lib"); //$NON-NLS-1$
+ if (path.toFile().exists()) {
+ return path; // we've already created the stubs for this VM
+ }
+ path.toFile().mkdirs(); // Make the directory structure to throw the files into
+ if (file.exists()) {
+ String rubyExecutablePath = rubyExecutable.getAbsolutePath();
+ String[] cmdLine = new String[] {rubyExecutablePath, file.getAbsolutePath(), path.toOSString()};
+ Process p = null;
+ try {
+ p = Runtime.getRuntime().exec(cmdLine);
+ IProcess process = DebugPlugin.newProcess(new Launch(null, ILaunchManager.RUN_MODE, null), p, "Core Classes Stub Generation"); //$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) {
+ }
+ }
+ } catch (IOException ioe) {
+ LaunchingPlugin.log(ioe);
+ } finally {
+ if (p != null) {
+ p.destroy();
+ }
+ }
+ }
+ return path;
+ }
}
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-29 09:09:18 UTC (rev 1890)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/internal/launching/StandardVMType.java 2007-01-29 14:49:11 UTC (rev 1891)
@@ -28,7 +28,7 @@
* Map of the install path for which we were unable to generate
* the library info during this session.
*/
- private static Map fgFailedInstallPath= new HashMap();
+ private static Map<String, LibraryInfo> fgFailedInstallPath= new HashMap<String, LibraryInfo>();
/**
* Convenience handle to the system-specific file separator character
@@ -56,11 +56,6 @@
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;
}
@@ -90,12 +85,12 @@
*/
public static File findRubyExecutable(File vmInstallLocation) {
// Try each candidate in order. The first one found wins. Thus, the order
- // of fgCandidateJavaLocations and fgCandidateJavaFiles is significant.
+ // of fgCandidateRubyLocations and fgCandidateRubyFiles is significant.
for (int i = 0; i < fgCandidateRubyFiles.length; i++) {
for (int j = 0; j < fgCandidateRubyLocations.length; j++) {
- File javaFile = new File(vmInstallLocation, fgCandidateRubyLocations[j] + fgCandidateRubyFiles[i]);
- if (javaFile.isFile()) {
- return javaFile;
+ File rubyFile = new File(vmInstallLocation, fgCandidateRubyLocations[j] + fgCandidateRubyFiles[i]);
+ if (rubyFile.isFile()) {
+ return rubyFile;
}
}
}
@@ -133,7 +128,6 @@
info = getDefaultLibraryInfo(rubyHome);
fgFailedInstallPath.put(installPath, info);
} else {
- // only persist if we were able to generate info - see bug 70011
LaunchingPlugin.setLibraryInfo(installPath, info);
}
}
@@ -144,10 +138,10 @@
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$
+ File file = LaunchingPlugin.getFileInPlugin(new Path("ruby" + fgSeparator + "loadpath.rb")); //$NON-NLS-1$
if (file.exists()) {
- String javaExecutablePath = rubyExecutable.getAbsolutePath();
- String[] cmdLine = new String[] {javaExecutablePath, file.getAbsolutePath()}; //$NON-NLS-1$
+ String rubyExecutablePath = rubyExecutable.getAbsolutePath();
+ String[] cmdLine = new String[] {rubyExecutablePath, file.getAbsolutePath()}; //$NON-NLS-1$
Process p = null;
try {
p = Runtime.getRuntime().exec(cmdLine);
@@ -195,8 +189,7 @@
lines.add(line);
}
} catch (IOException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
+ LaunchingPlugin.log(e);
}
if (lines.size() > 0) {
String version = lines.remove(0);
@@ -215,16 +208,25 @@
* @return LibraryInfo
*/
protected LibraryInfo getDefaultLibraryInfo(File installLocation) {
- IPath rtjar = getDefaultSystemLibrary(installLocation);
- return new LibraryInfo("1.8.4", new String[] {rtjar.toOSString()}); //$NON-NLS-1$
+ IPath[] dflts = getDefaultSystemLibrary(installLocation);
+ String[] strings = new String[dflts.length];
+ for (int i = 0; i < dflts.length; i++) {
+ strings[i] = dflts[i].toOSString();
+ }
+ return new LibraryInfo("1.8.4", strings); //$NON-NLS-1$
}
/**
* Return an <code>IPath</code> corresponding to the single library file containing the
* standard Ruby classes for VMs version 1.8.x.
*/
- protected IPath getDefaultSystemLibrary(File rubyHome) {
- return new Path(rubyHome.getPath()).append("lib").append("ruby").append("1.8"); //$NON-NLS-2$ //$NON-NLS-1$ //$NON-NLS-3$
+ protected IPath[] getDefaultSystemLibrary(File rubyHome) {
+ String stdPath = rubyHome.getAbsolutePath() + fgSeparator + "lib" + fgSeparator + "ruby" + fgSeparator + "1.8";
+ String sitePath = rubyHome.getAbsolutePath() + fgSeparator + "lib" + fgSeparator + "ruby" + fgSeparator + "site_ruby" + fgSeparator + "1.8";
+ IPath[] paths = new IPath[2];
+ paths[0] = new Path(sitePath);
+ paths[1] = new Path(stdPath);
+ return paths;
}
}
Modified: trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/AbstractVMInstall.java
===================================================================
--- trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/AbstractVMInstall.java 2007-01-29 09:09:18 UTC (rev 1890)
+++ trunk/org.rubypeople.rdt.launching/src/org/rubypeople/rdt/launching/AbstractVMInstall.java 2007-01-29 14:49:11 UTC (rev 1891)
@@ -31,13 +31,13 @@
private String fId;
private String fName;
private File fInstallLocation;
- private IPath[] fSystemLibraryDescriptions;
+ protected IPath[] fSystemLibraryDescriptions;
private String fVMArgs;
// system properties are cached in user preferences prefixed with this key, followed
// by vm type, vm id, and system property name
private static final String PREF_VM_INSTALL_SYSTEM_PROPERTY = "PREF_VM_INSTALL_SYSTEM_PROPERTY"; //$NON-NLS-1$
// whether change events should be fired
- private boolean fNotify = true;
+ protected boolean fNotify = true;
/**
* Constructs a new VM install.
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
|