Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Updated samples to use new Java Integration syntax

JRUBY-673: Dir.chdir with no arguments does not honor ENV['HOME']

git-svn-id: http://svn.codehaus.org/jruby/trunk/jruby@3604 961051c9-f516-0410-bf72-c9f7e237a7b7
  • Loading branch information...
commit 5adc3ef89d5a351ff4067244c33b50dfefddf9bf 1 parent 363b79a
@enebo enebo authored
Showing with 29 additions and 20 deletions.
  1. +13 −9 samples/swing2.rb
  2. +7 −7 samples/xslt.rb
  3. +9 −4 src/org/jruby/RubyDir.java
View
22 samples/swing2.rb
@@ -1,22 +1,26 @@
# Import Java packages
-require 'java'
+include Java
-JFrame = javax.swing.JFrame
+import javax.swing.JFrame
frame = JFrame.new("Hello Swing")
button = javax.swing.JButton.new("Klick Me!")
-class ClickAction < java.awt.event.ActionListener
+class ClickAction
+ include java.awt.event.ActionListener
def actionPerformed(evt)
- javax.swing.JOptionPane.showMessageDialog(nil, "<html>Hello from <b><u>JRuby</u></b>.<br> Button '#{evt.getActionCommand()}' clicked.")
+ javax.swing.JOptionPane.showMessageDialog(nil, <<EOS)
+<html>Hello from <b><u>JRuby</u></b>.<br>
+Button '#{evt.getActionCommand()}' clicked.
+EOS
end
end
-button.addActionListener(ClickAction.new)
+button.add_action_listener(ClickAction.new)
# Add the button to the frame
-frame.getContentPane().add(button)
+frame.get_content_pane.add(button)
# Show frame
-frame.setDefaultCloseOperation(JFrame::EXIT_ON_CLOSE)
-frame.pack()
-frame.setVisible(true)
+frame.set_default_close_operation(JFrame::EXIT_ON_CLOSE)
+frame.pack
+frame.visible = true
View
14 samples/xslt.rb
@@ -1,9 +1,10 @@
-require 'java'
+include Java
require 'optparse'
require 'ostruct'
-FileOutputStream = java.io.FileOutputStream
-StreamSource = javax.xml.transform.stream.StreamSource
+import java.io.FileOutputStream
+import javax.xml.transform.stream.StreamSource
+import javax.xml.transform.TransformerFactory
class XSLTOptions
def self.parse(args)
@@ -21,7 +22,6 @@ def self.parse(args)
options.parameters[name] = value
end
end
-
end
opts.parse!(args)
options
@@ -37,12 +37,12 @@ def self.parse(args)
document = StreamSource.new ARGV[0]
stylesheet = StreamSource.new ARGV[1]
-output = ARGV.length == 2 ? java.lang.System::out : FileOutputStream.new(ARGV[2])
+output = ARGV.length < 3 ? java.lang.System::out : FileOutputStream.new(ARGV[2])
result = javax.xml.transform.stream.StreamResult.new output
begin
- transformer = javax.xml.transform.TransformerFactory.newInstance.newTransformer(stylesheet)
- options.parameters.each {|name, value| transformer.setParameter name, value }
+ transformer = TransformerFactory.newInstance.newTransformer(stylesheet)
+ options.parameters.each {|name, value| transformer.setParameter(name, value) }
transformer.transform(document, result)
rescue java.lang.Exception => e
puts e
View
13 src/org/jruby/RubyDir.java
@@ -463,11 +463,16 @@ public static IRubyObject getHomeDirectoryPath(IRubyObject recv, String user) {
}
public static RubyString getHomeDirectoryPath(IRubyObject recv) {
- RubyHash hash = (RubyHash) recv.getRuntime().getObject().getConstant("ENV_JAVA");
- IRubyObject home = hash.aref(recv.getRuntime().newString("user.home"));
-
+ RubyHash systemHash = (RubyHash) recv.getRuntime().getObject().getConstant("ENV_JAVA");
+ RubyHash envHash = (RubyHash) recv.getRuntime().getObject().getConstant("ENV");
+ IRubyObject home = envHash.aref(recv.getRuntime().newString("HOME"));
+
+ if (home == null || home.isNil()) {
+ home = systemHash.aref(recv.getRuntime().newString("user.home"));
+ }
+
if (home == null || home.isNil()) {
- home = hash.aref(recv.getRuntime().newString("LOGDIR"));
+ home = envHash.aref(recv.getRuntime().newString("LOGDIR"));
}
if (home == null || home.isNil()) {
Please sign in to comment.
Something went wrong with that request. Please try again.