Author: kono
Date: 2010-07-23 20:10:09 -0700 (Fri, 23 Jul 2010)
New Revision: 21020

Added:
   csplugins/trunk/ucsd/kono/JRubyEngine/lib/jruby.jar
Removed:
   csplugins/trunk/ucsd/kono/JRubyEngine/lib/jruby-complete-1.4.0.jar
   csplugins/trunk/ucsd/kono/JRubyEngine/lib/jruby-embed-0.1.3.jar
Modified:
   csplugins/trunk/ucsd/kono/JRubyEngine/build.xml
   csplugins/trunk/ucsd/kono/JRubyEngine/lib/ScriptEngineManager.jar
   csplugins/trunk/ucsd/kono/JRubyEngine/plugin.props
   
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/RubyEnginePlugin.java
   
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/console/CyIRBConsole.java
   csplugins/trunk/ucsd/kono/JRubyEngine/utilscripts/biorubyshell.rb
Log:
RubyEngine version 0.3.

Modified: csplugins/trunk/ucsd/kono/JRubyEngine/build.xml
===================================================================
--- csplugins/trunk/ucsd/kono/JRubyEngine/build.xml     2010-07-24 03:08:13 UTC 
(rev 21019)
+++ csplugins/trunk/ucsd/kono/JRubyEngine/build.xml     2010-07-24 03:10:09 UTC 
(rev 21020)
@@ -9,7 +9,7 @@
 
 <project name="RubyScriptingEngine" default="all" basedir=".">
 
-       <property name="jruby.version" value="jruby-1.4.0" />
+       <property name="jruby.version" value="jruby-1.5.1" />
 
        <!-- You need modify this to your Cytoscape -->
        <property name="cytoscape.dir" value="../cytoscape" />

Modified: csplugins/trunk/ucsd/kono/JRubyEngine/lib/ScriptEngineManager.jar
===================================================================
(Binary files differ)

Deleted: csplugins/trunk/ucsd/kono/JRubyEngine/lib/jruby-complete-1.4.0.jar
===================================================================
(Binary files differ)

Deleted: csplugins/trunk/ucsd/kono/JRubyEngine/lib/jruby-embed-0.1.3.jar
===================================================================
(Binary files differ)

Added: csplugins/trunk/ucsd/kono/JRubyEngine/lib/jruby.jar
===================================================================
(Binary files differ)


Property changes on: csplugins/trunk/ucsd/kono/JRubyEngine/lib/jruby.jar
___________________________________________________________________
Name: svn:mime-type
   + application/octet-stream

Modified: csplugins/trunk/ucsd/kono/JRubyEngine/plugin.props
===================================================================
--- csplugins/trunk/ucsd/kono/JRubyEngine/plugin.props  2010-07-24 03:08:13 UTC 
(rev 21019)
+++ csplugins/trunk/ucsd/kono/JRubyEngine/plugin.props  2010-07-24 03:10:09 UTC 
(rev 21020)
@@ -5,13 +5,13 @@
 
 # Description used to give users information about the plugin such as what it 
does.  
 # Html tags are encouraged for formatting purposes.
-pluginDescription=<p>Scripting Engine based on jruby 1.4.0 implementation.  
The console is now integrated with BioRuby Shell.</p><p><strong><font 
color="red">You need to install JRuby 1.4.0 and BioRuby 1.3.1 by 
yourself.</font></strong>
+pluginDescription=<p>Scripting Engine based on jruby 1.5.1 implementation.  
The console is now integrated with BioRuby Shell.</p><p><strong>You need to 
install JRuby 1.5.1 and BioRuby 1.4.0 by yourself.</strong>
 
 # Plugin version number, this must be two numbers separated by a decimlal.  
Ex. 0.2, 14.03
-pluginVersion=0.22
+pluginVersion=0.30
 
 # Compatible Cytoscape version
-cytoscapeVersion=2.6, 2.7
+cytoscapeVersion=2.7, 2.8
 
 # Category, use one of the categories listed on the website or create your own
 pluginCategory=Communication/Scripting

Modified: 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/RubyEnginePlugin.java
===================================================================
--- 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/RubyEnginePlugin.java
        2010-07-24 03:08:13 UTC (rev 21019)
+++ 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/RubyEnginePlugin.java
        2010-07-24 03:10:09 UTC (rev 21020)
@@ -36,15 +36,12 @@
 
 import java.awt.event.ActionEvent;
 import java.beans.PropertyChangeEvent;
-import java.io.IOException;
-import java.lang.reflect.Method;
 
 import javax.swing.AbstractAction;
 import javax.swing.Icon;
 import javax.swing.ImageIcon;
 import javax.swing.JMenuItem;
 
-import org.apache.bsf.BSFManager;
 import org.jruby.embed.ScriptingContainer;
 
 import cytoscape.Cytoscape;
@@ -60,11 +57,19 @@
  */
 public class RubyEnginePlugin extends CytoscapePlugin implements 
ScriptingEngine {
        private static final String ENGINE_NAME = "jruby";
-       private static final String ENGINE_DISPLAY_NAME = "Ruby Scripting 
Engine (based on JRuby v1.4.0)";
+       
+       private static final String ENGINE_VERSION = "1.5.1";
+       
+       private static final String ENGINE_DISPLAY_NAME = "Ruby Scripting 
Engine (JRuby v1.5.1 and BioRuby 1.4.0)";
        private static final Icon ICON = new 
ImageIcon(RubyEnginePlugin.class.getResource("/images/ruby.png"));
-       private static final RubyEnginePlugin engine = new RubyEnginePlugin();
+       private static final Icon CONSOLE_ICON = new 
ImageIcon(RubyEnginePlugin.class.getResource("/images/ruby22x22.png"));
        
-
+       private static RubyEnginePlugin engine = new RubyEnginePlugin();
+       
+       private static final CyLogger logger = CyLogger.getLogger();
+       
+       private static String jRubyHome;
+       
        /**
         * Creates a new RubyEnginePlugin object.
         */
@@ -78,7 +83,6 @@
         * @return  DOCUMENT ME!
         */
        public String getDisplayName() {
-               // TODO Auto-generated method stub
                return ENGINE_DISPLAY_NAME;
        }
 
@@ -88,7 +92,6 @@
         * @return  DOCUMENT ME!
         */
        public Icon getIcon() {
-               // TODO Auto-generated method stub
                return ICON;
        }
 
@@ -98,45 +101,56 @@
         * @return  DOCUMENT ME!
         */
        public String getIdentifier() {
-               // TODO Auto-generated method stub
                return ENGINE_NAME;
        }
+       
+       /**
+        * Returns version number of Scripting Engine as string
+        * 
+        * @return
+        */
+       public static String getEngineVersion() {
+               return ENGINE_VERSION;
+       }
+       
+       
+       public static String getJRubyHome() {
+               return jRubyHome;
+       }
 
        /**
         *  DOCUMENT ME!
         */
        public static void register() {
-//             System.setProperty("jruby.home", 
"/Users/kono/Library/jruby-1.4.0");
-               ScriptingContainer container = new ScriptingContainer();
                
-               BSFManager.registerScriptingEngine("jruby", 
"org.jruby.embed.bsf.JRubyEngine", new String[] {ENGINE_NAME});
+               //System.setProperty("jruby.home", 
"/Users/kono/Documents/jruby-1.5.1");
+               jRubyHome = System.getenv("JRUBY_HOME");
+               
+               if(jRubyHome == null)
+                       throw new IllegalStateException("This system does not 
have enviroment variable \"JRUBY_HOME.\"  Please set it and restart 
Cytoscape.");
+               System.setProperty("org.jruby.embed.class.path", jRubyHome);
+               logger.info("JRuby Home Dir = " + jRubyHome);
+               
+               final ScriptingContainer container = new ScriptingContainer();
+               
ScriptEngineManagerPlugin.getManager().registerEngine(ENGINE_NAME, engine);
 
-               System.out.println("*JRuby scripting engine loaded!");
+               logger.info("JRuby scripting engine registered.");
 
-               try {
-                       final Class<?> engineClass = 
Class.forName("edu.ucsd.bioeng.idekerlab.scriptenginemanager.ScriptEngineManager");
-                       Method method = engineClass.getMethod("registerEngine",
-                                                             new Class[] { 
String.class, ScriptingEngine.class });
-                       method.invoke(null, new Object[] { ENGINE_NAME, engine 
});
-               } catch (Exception e) {
-                       e.printStackTrace();
-               }
-
                final JMenuItem consoleMenuItem = new JMenuItem(new 
AbstractAction("Open Ruby Console") {
                                public void actionPerformed(ActionEvent e) {
                                        try {
                                                CyIRBConsole.showConsole();
-                                       } catch (IOException e1) {
-                                               
CyLogger.getLogger().error("Ruby Colsone Error", e1);
+                                       } catch (Exception e1) {
+                                               logger.error("Could not start 
JRuby Colsone", e1);
                                        }
                                }
                        });
 
-               consoleMenuItem.setIcon(new 
ImageIcon(RubyEnginePlugin.class.getResource("/images/ruby22x22.png")));
+               consoleMenuItem.setIcon(CONSOLE_ICON);
 
                
ScriptEngineManagerPlugin.getManager().addConsoleMenu(consoleMenuItem);
 
-               CyLogger.getLogger().info("Ruby scripting engine registered 
successfully.");
+               logger.info("JRuby colsole registered.");
        }
 
        /**
@@ -145,12 +159,17 @@
         * @param e DOCUMENT ME!
         */
        public void propertyChange(PropertyChangeEvent e) {
+               // If already registered, ignore.
                if 
(ScriptEngineManagerPlugin.getManager().getEngine(ENGINE_NAME) != null)
                        return;
 
                if 
(e.getPropertyName().equals(Cytoscape.CYTOSCAPE_INITIALIZED)) {
                        // Register this to ScriptEngineManager.
-                       register();
+                       try {
+                               register();
+                       } catch(Exception ex) {
+                               logger.error("Could not register JRuby Engine 
to the Manager.", ex);
+                       }
                }
        }
 }

Modified: 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/console/CyIRBConsole.java
===================================================================
--- 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/console/CyIRBConsole.java
    2010-07-24 03:08:13 UTC (rev 21019)
+++ 
csplugins/trunk/ucsd/kono/JRubyEngine/src/edu/ucsd/bioeng/idekerlab/rubyengine/console/CyIRBConsole.java
    2010-07-24 03:10:09 UTC (rev 21020)
@@ -44,11 +44,13 @@
 import java.io.IOException;
 import java.io.InputStreamReader;
 import java.io.PrintStream;
+import java.net.URL;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 
+import javax.script.ScriptException;
 import javax.swing.BorderFactory;
 import javax.swing.ImageIcon;
 import javax.swing.JEditorPane;
@@ -62,6 +64,8 @@
 import org.jruby.internal.runtime.ValueAccessor;
 
 import cytoscape.Cytoscape;
+import cytoscape.CytoscapeInit;
+import cytoscape.logger.CyLogger;
 import cytoscape.view.cytopanels.CytoPanelState;
 import edu.ucsd.bioeng.idekerlab.rubyengine.RubyEnginePlugin;
 
@@ -71,16 +75,24 @@
  * @author Keiichiro Ono
  */
 public class CyIRBConsole extends JPanel {
+
+       public static final String STARTUP_SCRIPT_LOCATION = 
"scripting.jruby.consolestartup";
+
+       private static final long serialVersionUID = -3402131526354557834L;
+
        private static CyIRBConsole console = null;
        private static Ruby runtime = null;
        private static final ExecutorService consoleService = Executors
-                       .newCachedThreadPool();
+                       .newSingleThreadExecutor();
+
        private static final String BIORUBY_SCRIPT_LOCATION = 
"/utilscripts/biorubyshell.rb";
        private static String startScript;
 
        private static final ImageIcon tabIcon = new ImageIcon(
                        
RubyEnginePlugin.class.getResource("/images/ruby22x22.png"));
 
+       private static final CyLogger logger = CyLogger.getLogger();
+
        /**
         * Creates a new CyIRBConsole object.
         * 
@@ -88,14 +100,28 @@
         *            DOCUMENT ME!
         * @throws IOException
         */
-       public CyIRBConsole(String title) throws IOException {
-               // super(title);
+       public CyIRBConsole() throws IOException {
 
+               final String scriptLocation = CytoscapeInit.getProperties()
+                               .getProperty(STARTUP_SCRIPT_LOCATION);
+               final URL scriptURL;
+               if (scriptLocation == null) {
+                       scriptURL = RubyEnginePlugin.class
+                                       .getResource(BIORUBY_SCRIPT_LOCATION);
+                       logger.info("Default initialization script will be used 
for JRuby Console.");
+               } else {
+                       scriptURL = new URL(scriptLocation);
+                       logger.info("Custom initialization script found for 
JRuby Console: " + scriptURL.toString());
+               }
+               extractScript(scriptURL);
+       }
+
+       
+       private void extractScript(final URL scriptURL) throws IOException {
                InputStreamReader in = null;
                StringBuilder builder = new StringBuilder();
 
-               in = new InputStreamReader(RubyEnginePlugin.class.getResource(
-                               BIORUBY_SCRIPT_LOCATION).openStream());
+               in = new InputStreamReader(scriptURL.openStream());
 
                BufferedReader br = new BufferedReader(in);
 
@@ -118,39 +144,72 @@
         * DOCUMENT ME!
         * 
         * @throws IOException
+        * @throws ScriptException
         */
-       public static void showConsole() throws IOException {
+       public static void showConsole() throws IOException, ScriptException {
                if (console == null) {
                        // Initialize console
-                       if (runtime == null)
+
+                       if (runtime == null) {
                                runtime = Ruby.newInstance();
-
-                       console = new CyIRBConsole("Cytoscape-Ruby Interactive 
Console");
+                               final String rubyHome = 
RubyEnginePlugin.getJRubyHome();
+                               if (rubyHome == null)
+                                       throw new IllegalStateException(
+                                                       "This system does not 
have enviroment variable \"JRUBY_HOME.\"  Please set it and restart 
Cytoscape.");
+                               else
+                                       runtime.setJRubyHome(rubyHome);
+                       }
+                       console = new CyIRBConsole();
+                       
                        buildConsole(null);
+                       Cytoscape
+                                       .getDesktop()
+                                       .getCytoPanel(SwingConstants.EAST)
+                                       .add("BioRuby Console (Powered by JRuby 
"
+                                                       + 
RubyEnginePlugin.getEngineVersion() + ")",
+                                                       tabIcon, console);
 
-                       
Cytoscape.getDesktop().getCytoPanel(SwingConstants.EAST).add(
-                                       "Cytoscape-BioRuby Console", tabIcon, 
console);
-
-                       
Cytoscape.getDesktop().getCytoPanel(SwingConstants.EAST).setState(
-                                       CytoPanelState.DOCK);
+                       Cytoscape.getDesktop().getCytoPanel(SwingConstants.EAST)
+                                       .setState(CytoPanelState.DOCK);
                }
 
-               consoleService.execute(new Runnable() {
-                       public void run() {
-                               runtime.evalScriptlet(startScript);
+               try {
+                       consoleService.execute(new Runnable() {
 
-                               
Cytoscape.getDesktop().getCytoPanel(SwingConstants.EAST)
-                                               .remove(console);
-                               if 
(Cytoscape.getDesktop().getCytoPanel(SwingConstants.EAST)
-                                               .getCytoPanelComponentCount() 
== 0)
+                               private void terminate() {
                                        
Cytoscape.getDesktop().getCytoPanel(SwingConstants.EAST)
-                                                       
.setState(CytoPanelState.HIDE);
-                               runtime.tearDown();
-                               console = null;
-                               System.out.println("Console terminated!");
-                       }
-               });
+                                                       .remove(console);
+                                       if (Cytoscape.getDesktop()
+                                                       
.getCytoPanel(SwingConstants.EAST)
+                                                       
.getCytoPanelComponentCount() == 0)
+                                               Cytoscape.getDesktop()
+                                                               
.getCytoPanel(SwingConstants.EAST)
+                                                               
.setState(CytoPanelState.HIDE);
+                                       runtime.tearDown();
 
+                                       console = null;
+                                       logger.info("JRuby Console 
terminated.");
+                               }
+
+                               public void run() {
+                                       try {
+                                               
runtime.evalScriptlet(startScript);
+                                       } catch (Exception ex) {
+                                               ex.printStackTrace();
+                                               logger.error("Could not 
initialize BioRuby Console.",
+                                                               new 
ScriptException(ex));
+                                               terminate();
+                                               return;
+                                       }
+
+                                       terminate();
+                               }
+                       });
+               } catch (Exception e) {
+                       e.printStackTrace();
+                       throw new ScriptException(e);
+               }
+
        }
 
        /**
@@ -161,16 +220,17 @@
         */
        public static void buildConsole(final String[] args) {
                console.setLayout(new BorderLayout());
-               console.setPreferredSize(new Dimension(500, 600));
+               console.setPreferredSize(new Dimension(600, 600));
 
                final JEditorPane text = new JTextPane();
+               text.setPreferredSize(new Dimension(600, 600));
                text.setMargin(new Insets(8, 8, 8, 8));
                text.setCaretColor(new Color(0xa4, 0x00, 0x00));
                text.setBackground(Color.white);
                text.setForeground(Color.red);
 
-               final Font font = console.findFont("Monospaced", Font.PLAIN, 14,
-                               new String[] { "Monaco", "Andale Mono" });
+               final Font font = console.findFont("SansSerif", Font.PLAIN, 14,
+                               new String[] { "Menlo", "Monaco", "Andale Mono" 
});
                text.setFont(font);
 
                final JScrollPane pane = new JScrollPane();
@@ -190,8 +250,6 @@
                                setOutput(new 
PrintStream(tar.getOutputStream()));
                                setError(new 
PrintStream(tar.getOutputStream()));
                                setObjectSpaceEnabled(true); // useful for code 
completion
-                               // inside the IRB
-                               // setArgv(args);
                        }
                };
 
@@ -209,8 +267,11 @@
 
        private Font findFont(String otherwise, int style, int size,
                        String[] families) {
-               String[] fonts = 
GraphicsEnvironment.getLocalGraphicsEnvironment()
-                               .getAvailableFontFamilyNames();
+
+               // Get all available fonts
+               final String[] fonts = GraphicsEnvironment
+                               
.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
+
                Arrays.sort(fonts);
 
                Font font = null;

Modified: csplugins/trunk/ucsd/kono/JRubyEngine/utilscripts/biorubyshell.rb
===================================================================
--- csplugins/trunk/ucsd/kono/JRubyEngine/utilscripts/biorubyshell.rb   
2010-07-24 03:08:13 UTC (rev 21019)
+++ csplugins/trunk/ucsd/kono/JRubyEngine/utilscripts/biorubyshell.rb   
2010-07-24 03:10:09 UTC (rev 21020)
@@ -1,9 +1,7 @@
 $LOAD_PATH << ENV['JRUBY_HOME'] + '/lib/ruby/1.8'
-$LOAD_PATH << ENV['JRUBY_HOME'] + '/lib/ruby/gems/1.8/gems/bio-1.3.1/lib'
-$LOAD_PATH << ENV['HOME'] + '/.gem/ruby/1.8/gems/bio-1.3.1/lib'
+$LOAD_PATH << ENV['JRUBY_HOME'] + '/lib/ruby/site_ruby/shared'
+$LOAD_PATH << ENV['JRUBY_HOME'] + '/lib/ruby/gems/1.8/gems/bio-1.4.0/lib'
 
-#puts "LOAD_PATH: " + $:.inspect
-
 require 'bio'
 require 'bio/shell'
 
@@ -15,7 +13,6 @@
 Bio::Shell::Setup.new
 Bio::Shell.load_session
 
-
 if Bio::Shell.cache[:rails]
   Bio::Shell.cache[:rails].join
 else

-- 
You received this message because you are subscribed to the Google Groups 
"cytoscape-cvs" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/cytoscape-cvs?hl=en.

Reply via email to