Skip to content

Commit

Permalink
Ruby in Java demo
Browse files Browse the repository at this point in the history
  • Loading branch information
bookshelfdave committed Dec 13, 2011
1 parent bbe3770 commit 92bd1e7
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 17 deletions.
Binary file modified Hacksaw.jar
Binary file not shown.
6 changes: 3 additions & 3 deletions demo/demo4_bytecode.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@
modify :classes=>/com.quadcs.hacksaw.demo.DemoAccount/ do |c|
c.modify :method=>"deposit" do |m|
# actual, this just shows the opcodes for now
m.show_bytecode
#m.show_bytecode

# this replaces ALL exceptions thrown with a NOP *and* a POP
m.map_bytecode do |bytes,op|
op == "athrow" ? 0 : bytes
end
op == "athrow" ? 0 : bytes
end
end
#c.save_to("hacksaw")
end
Expand Down
10 changes: 6 additions & 4 deletions demo/demo5_ruby_in_java.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,16 @@
#show_matches_enable
modify :classes=>/com.quadcs.hacksaw.demo.DemoAccount/ do |c|
c.modify :method=>"getBetterAccountNumber" do |m|
m.add_callback_before ["$1"] do |x|
puts "This is a Ruby block in your Java method: #{x[0]} <<<<"
m.add_callback_before ["$1"] do |prefix,suffix|
puts "Ruby in your Java!!"
puts "Prefix in Ruby=#{prefix}"
puts "Suffix in Ruby=#{suffix}"
end
end
end



account = com.quadcs.hacksaw.demo.DemoAccount.new("1234")
puts account.getBetterAccountNumber("Mike Smith")
puts "Finished"
puts account.getBetterAccountNumber(">>>","<<<")
puts "Finished"
9 changes: 4 additions & 5 deletions javac.classes
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,6 @@ src/com/quadcs/hacksaw/ClassModification.java
src/com/quadcs/hacksaw/CtorAction.java
src/com/quadcs/hacksaw/CtorMatcher.java
src/com/quadcs/hacksaw/CtorModification.java
src/com/quadcs/hacksaw/demo/Bar.java
src/com/quadcs/hacksaw/demo/DemoAccount.java
src/com/quadcs/hacksaw/demo/DemoUser.java
src/com/quadcs/hacksaw/demo/Foo.java
src/com/quadcs/hacksaw/FieldAction.java
src/com/quadcs/hacksaw/FieldMatcher.java
src/com/quadcs/hacksaw/FieldModification.java
Expand All @@ -17,6 +13,9 @@ src/com/quadcs/hacksaw/MethodAction.java
src/com/quadcs/hacksaw/MethodMatcher.java
src/com/quadcs/hacksaw/MethodModification.java
src/com/quadcs/hacksaw/ProcStub.java
src/com/quadcs/hacksaw/Utils.java
src/com/quadcs/hacksaw/demo/Bar.java
src/com/quadcs/hacksaw/demo/DemoAccount.java
src/com/quadcs/hacksaw/demo/Foo.java
src/com/quadcs/hacksaw/tests/DecTests.java
src/com/quadcs/hacksaw/tests/DescriptorTests.java
src/com/quadcs/hacksaw/Utils.java
2 changes: 1 addition & 1 deletion javac.options
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
-d dist
-g
-sourcepath src
-classpath javalibs/javassist.jar;javalibs/junit-4.8.2.jar
-classpath javalibs/javassist.jar:javalibs/junit-4.8.2.jar
3 changes: 2 additions & 1 deletion lib/hacksaw_core.rb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,8 @@ def initialize(params,blk)

def call(params)
# TODO: No params being called yet
@blk.call(params)

@blk.call(*params)
end
end

Expand Down
1 change: 0 additions & 1 deletion src/com/quadcs/hacksaw/HacksawMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ public byte[] transform(ClassLoader loader, String className,
}
if(!started) {
started = true;
System.out.println("Adding system classpath!");

ClassPool cp = ClassPool.getDefault();

Expand Down
4 changes: 2 additions & 2 deletions src/com/quadcs/hacksaw/demo/DemoAccount.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ public String getAccountNumber() {
return accountNumber;
}

public String getBetterAccountNumber(String s) {
return s;
public String getBetterAccountNumber(String prefix, String suffix) {
return prefix + accountNumber + suffix;
}

@Test
Expand Down

0 comments on commit 92bd1e7

Please sign in to comment.