ruby2jar 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/LICENSE +674 -0
- data/README +48 -0
- data/Rakefile +83 -0
- data/TODO +2 -0
- data/lib/ruby2jar.rb +31 -0
- data/lib/ruby2jar/builder.rb +436 -0
- data/lib/ruby2jar/console.rb +34 -0
- data/lib/ruby2jar/error.rb +23 -0
- data/lib/ruby2jar/jartask.rb +85 -0
- data/lib/ruby2jar/listener.rb +38 -0
- data/spec/builder/before_spec.rb +105 -0
- data/spec/builder/builder_spec.rb +100 -0
- data/spec/builder/copy_spec.rb +138 -0
- data/spec/builder/create_init_spec.rb +69 -0
- data/spec/builder/fixtures/app/ext/greeters/JavaGreeter.java +7 -0
- data/spec/builder/fixtures/app/greeters/english.rb +8 -0
- data/spec/builder/fixtures/app/main.rb +4 -0
- data/spec/builder/fixtures/jruby/lib/jruby.jar +0 -0
- data/spec/builder/package_spec.rb +52 -0
- data/spec/builder/spec_helper.rb +121 -0
- data/spec/console/console_spec.rb +27 -0
- data/spec/console/spec_helper.rb +17 -0
- data/spec/jartask/jartask_spec.rb +37 -0
- data/spec/listener/listener_spec.rb +49 -0
- data/spec/spec_helper.rb +1 -0
- metadata +90 -0
@@ -0,0 +1,69 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe Ruby2Jar::Builder do
|
4
|
+
before :each do
|
5
|
+
@builder = Ruby2Jar::Builder.new
|
6
|
+
@builder.include_jruby = false
|
7
|
+
@app_path = TempDir.create
|
8
|
+
@builder.path = @app_path
|
9
|
+
@builder.before_compile << lambda { @builder.stop }
|
10
|
+
FileUtils.touch File.join(@builder.path, "main.rb")
|
11
|
+
@builder.main = "main.rb"
|
12
|
+
end
|
13
|
+
|
14
|
+
it "should create init script" do
|
15
|
+
@builder.before_compile << lambda {
|
16
|
+
File.exist?(File.join(@builder.build_dir, "ruby", "init.rb")).should be_true
|
17
|
+
}
|
18
|
+
@builder.build
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should create init script with gem and require methods and calling main" do
|
22
|
+
@builder.before_compile << lambda {
|
23
|
+
init = IO.read File.join(@builder.build_dir, "ruby", "init.rb")
|
24
|
+
init.should include('def gem')
|
25
|
+
init.should include('def require')
|
26
|
+
init.should include('require "ruby/app/main"')
|
27
|
+
}
|
28
|
+
@builder.build
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should add init_require_paths to LOAD_PATH in init script" do
|
32
|
+
@builder.before_create_init << lambda {
|
33
|
+
@builder.init_require_paths = ["one", "two/subdir"]
|
34
|
+
}
|
35
|
+
@builder.before_compile << lambda {
|
36
|
+
init = IO.read File.join(@builder.build_dir, "ruby", "init.rb")
|
37
|
+
init.should include('$LOAD_PATH << "one"')
|
38
|
+
init.should include('$LOAD_PATH << "two/subdir"')
|
39
|
+
}
|
40
|
+
@builder.build
|
41
|
+
end
|
42
|
+
|
43
|
+
it "shouldn't do any action if main script isn't set" do
|
44
|
+
@builder.main = nil
|
45
|
+
@builder.before_compile << lambda {
|
46
|
+
File.exist?(File.join(@builder.build_dir, "ruby", "init.rb")).should be_false
|
47
|
+
}
|
48
|
+
@builder.build
|
49
|
+
end
|
50
|
+
|
51
|
+
it "should add init script as Main-Class to manifest" do
|
52
|
+
@builder.before_compile << lambda {
|
53
|
+
@builder.manifest["Main-Class"].should == "ruby.init"
|
54
|
+
}
|
55
|
+
@builder.build
|
56
|
+
end
|
57
|
+
|
58
|
+
it "shouldn't replace Main-Class in manifest" do
|
59
|
+
@builder.manifest["Main-Class"] = "test"
|
60
|
+
@builder.before_compile << lambda {
|
61
|
+
@builder.manifest["Main-Class"].should == "test"
|
62
|
+
}
|
63
|
+
@builder.build
|
64
|
+
end
|
65
|
+
|
66
|
+
after :each do
|
67
|
+
@app_path.delete
|
68
|
+
end
|
69
|
+
end
|
Binary file
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "spec_helper")
|
2
|
+
|
3
|
+
describe Ruby2Jar::Builder do
|
4
|
+
include DirHelper
|
5
|
+
|
6
|
+
before :each do
|
7
|
+
@builder = Ruby2Jar::Builder.new
|
8
|
+
@builder.include_jruby = false
|
9
|
+
@app_path = TempDir.create
|
10
|
+
@result_path = TempDir.create
|
11
|
+
@builder.path = @app_path
|
12
|
+
@builder.jar = File.join(@result_path, "result.jar")
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should package all files to JAR" do
|
16
|
+
create_files @builder.path, ["one.class", "subdir/two.class"]
|
17
|
+
|
18
|
+
@builder.build
|
19
|
+
@builder.jar.should contain_files(
|
20
|
+
"ruby/app/one.class", "ruby/app/subdir/two.class", "META-INF/MANIFEST.MF")
|
21
|
+
end
|
22
|
+
|
23
|
+
it "should copy JRuby classes if it neccessary" do
|
24
|
+
@builder.include_jruby = true
|
25
|
+
@builder.jruby = File.join(File.expand_path(File.dirname(__FILE__)),
|
26
|
+
"fixtures", "jruby", "lib", "jruby.jar")
|
27
|
+
|
28
|
+
@builder.build
|
29
|
+
@builder.jar.should contain_files("jruby.class", "META-INF/MANIFEST.MF")
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should add manifest if it neccessary" do
|
33
|
+
@builder.create_manifest = true
|
34
|
+
@builder.manifest["test"] = "value"
|
35
|
+
|
36
|
+
@builder.build
|
37
|
+
dir = TempDir.create
|
38
|
+
current = Dir.getwd
|
39
|
+
Dir.chdir dir
|
40
|
+
|
41
|
+
`jar -xf #{@builder.jar}`
|
42
|
+
IO.read("META-INF/MANIFEST.MF").should include("test: value")
|
43
|
+
|
44
|
+
Dir.chdir current
|
45
|
+
dir.delete
|
46
|
+
end
|
47
|
+
|
48
|
+
after :each do
|
49
|
+
@app_path.delete
|
50
|
+
@result_path.delete
|
51
|
+
end
|
52
|
+
end
|
@@ -0,0 +1,121 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
2
|
+
|
3
|
+
require "tmpdir"
|
4
|
+
require "fileutils"
|
5
|
+
|
6
|
+
class TracerBuilder < Ruby2Jar::Builder
|
7
|
+
attr_accessor :steps
|
8
|
+
def initialize
|
9
|
+
super
|
10
|
+
@steps = []
|
11
|
+
@before_start << lambda { self.steps << "before_start" }
|
12
|
+
@before_copy << lambda { self.steps << "before_copy" }
|
13
|
+
@before_create_init << lambda { self.steps << "before_create_init" }
|
14
|
+
@before_compile << lambda { self.steps << "before_compile" }
|
15
|
+
@before_package << lambda { self.steps << "before_package" }
|
16
|
+
@before_finish << lambda { self.steps << "before_finish" }
|
17
|
+
@on_error << lambda { |error| self.steps << "on_error #{error}"; false }
|
18
|
+
end
|
19
|
+
def start
|
20
|
+
@steps << "start"
|
21
|
+
end
|
22
|
+
def copy
|
23
|
+
@steps << "copy"
|
24
|
+
end
|
25
|
+
def create_init
|
26
|
+
@steps << "create_init"
|
27
|
+
end
|
28
|
+
def compile
|
29
|
+
@steps << "compile"
|
30
|
+
end
|
31
|
+
def package
|
32
|
+
@steps << "package"
|
33
|
+
end
|
34
|
+
def finish
|
35
|
+
@steps << "finish"
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
class TempDir < String
|
40
|
+
def self.create
|
41
|
+
dir = self.new
|
42
|
+
Dir.mkdir dir
|
43
|
+
dir
|
44
|
+
end
|
45
|
+
def initialize
|
46
|
+
number = Time.now.to_i
|
47
|
+
begin
|
48
|
+
number += 1
|
49
|
+
tmpdir = File.join(Dir.tmpdir, "ruby2jar_test_#{number}")
|
50
|
+
end while File.exist? tmpdir
|
51
|
+
self.replace tmpdir
|
52
|
+
end
|
53
|
+
def delete
|
54
|
+
FileUtils.rm_r self
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
class FakeGems
|
59
|
+
attr_accessor :gems
|
60
|
+
def find_name(gem, version)
|
61
|
+
@gems["#{gem}-#{version}"].to_a
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
class FakeSpecification
|
66
|
+
attr_accessor :name, :full_name, :full_gem_path, :require_paths, :dependencies
|
67
|
+
def initialize(name, version, path, dependencies = [])
|
68
|
+
@name = name
|
69
|
+
@full_name = "#{name}-#{version}"
|
70
|
+
@full_gem_path = path
|
71
|
+
@require_paths = "lib"
|
72
|
+
@dependencies = dependencies
|
73
|
+
end
|
74
|
+
def to_a
|
75
|
+
[self]
|
76
|
+
end
|
77
|
+
end
|
78
|
+
|
79
|
+
module DirHelper
|
80
|
+
class ContainFiles
|
81
|
+
def initialize(files)
|
82
|
+
@files = files.sort
|
83
|
+
end
|
84
|
+
def files(dir)
|
85
|
+
Dir.glob(File.join(dir, "**", "*")).delete_if { |i| File.directory? i }.map { |i| i[dir.length+1..-1] }.sort
|
86
|
+
end
|
87
|
+
def matches?(path)
|
88
|
+
@path = path
|
89
|
+
if File.directory? @path
|
90
|
+
@in_dir = files @path
|
91
|
+
elsif ".jar" == File.extname(@path)
|
92
|
+
dir = TempDir.create
|
93
|
+
current = Dir.getwd
|
94
|
+
Dir.chdir dir
|
95
|
+
|
96
|
+
`jar -xf #{@path}`
|
97
|
+
@in_dir = files dir
|
98
|
+
|
99
|
+
Dir.chdir current
|
100
|
+
dir.delete
|
101
|
+
end
|
102
|
+
@in_dir == @files
|
103
|
+
end
|
104
|
+
def failure_message
|
105
|
+
"in #{@path} expected files [#{@files.join(", ")}], but found [#{@in_dir.join(", ")}]"
|
106
|
+
end
|
107
|
+
def negative_failure_message
|
108
|
+
"in #{@path} doesn't expected files [#{@files.join(", ")}], but it does"
|
109
|
+
end
|
110
|
+
end
|
111
|
+
def contain_files(*files)
|
112
|
+
ContainFiles.new(files)
|
113
|
+
end
|
114
|
+
def create_files(dir, files)
|
115
|
+
files.each do |file|
|
116
|
+
file = File.join(dir, file)
|
117
|
+
FileUtils.makedirs File.dirname(file)
|
118
|
+
FileUtils.touch file
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
2
|
+
|
3
|
+
require "tempfile"
|
4
|
+
|
5
|
+
describe Ruby2Jar::Console do
|
6
|
+
before :each do
|
7
|
+
@console = Ruby2Jar::Console.new
|
8
|
+
@real_stderr = STDERR.clone
|
9
|
+
@errors = Tempfile.new "ruby2jar_test_stderr"
|
10
|
+
STDERR.reopen(@errors)
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should print message from exception in STDERR" do
|
14
|
+
@console.on_error(Ruby2Jar::Error.new("ERROR_MSG"))
|
15
|
+
@errors.rewind
|
16
|
+
@errors.read.should include("ERROR_MSG")
|
17
|
+
end
|
18
|
+
|
19
|
+
it "shouldn't catch non-builder exceptions" do
|
20
|
+
@console.on_error(Ruby2Jar::Error.new).should be_true
|
21
|
+
@console.on_error(Exception.new).should be_false
|
22
|
+
end
|
23
|
+
|
24
|
+
after :each do
|
25
|
+
STDERR.reopen(@real_stderr)
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
2
|
+
|
3
|
+
module Ruby2Jar
|
4
|
+
class FakeConsole < Console
|
5
|
+
def initialize(builder, warnings = true)
|
6
|
+
super(builder, warnings)
|
7
|
+
@error_messages = []
|
8
|
+
@warning_messages = []
|
9
|
+
end
|
10
|
+
def error(msg)
|
11
|
+
@error_messages << msg
|
12
|
+
end
|
13
|
+
def warning(msg)
|
14
|
+
@warning_messages << msg
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
2
|
+
|
3
|
+
describe Ruby2Jar::JarTask do
|
4
|
+
|
5
|
+
it "should add task for create and clobber JAR" do
|
6
|
+
task = Ruby2Jar::JarTask.new do |jar|
|
7
|
+
jar.name = "app"
|
8
|
+
end
|
9
|
+
|
10
|
+
Rake::Task["jar"].comment.should == "Build the JAR file pkg/app.jar"
|
11
|
+
Rake::Task["clobber_jar"].comment.should == "Remove JAR file pkg/app.jar"
|
12
|
+
|
13
|
+
Rake::Task["package"].prerequisites.should include("jar")
|
14
|
+
Rake::Task["clobber"].prerequisites.should include("clobber_jar")
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should set JAR filename by application name and version" do
|
18
|
+
task = Ruby2Jar::JarTask.new do |jar|
|
19
|
+
jar.name = "MyProgram"
|
20
|
+
end
|
21
|
+
task.jar.should == "pkg/MyProgram.jar"
|
22
|
+
|
23
|
+
task = Ruby2Jar::JarTask.new do |jar|
|
24
|
+
jar.name = "MyProgram"
|
25
|
+
jar.version = "1.0"
|
26
|
+
end
|
27
|
+
task.jar.should == "pkg/MyProgram-1.0.jar"
|
28
|
+
end
|
29
|
+
|
30
|
+
it "shouldn't replace JAR filename if user set it" do
|
31
|
+
task = Ruby2Jar::JarTask.new do |jar|
|
32
|
+
jar.jar = "some path"
|
33
|
+
end
|
34
|
+
task.jar.should == "some path"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,49 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "spec_helper")
|
2
|
+
|
3
|
+
describe Ruby2Jar::Listener do
|
4
|
+
|
5
|
+
it "should add before_* functions as builder listeners" do
|
6
|
+
three_proc = lambda {}
|
7
|
+
|
8
|
+
class Builder1
|
9
|
+
attr_accessor :before_one
|
10
|
+
attr_accessor :before_two
|
11
|
+
attr_accessor :before_three
|
12
|
+
end
|
13
|
+
builder = Builder1.new
|
14
|
+
builder.before_one = []
|
15
|
+
builder.before_two = []
|
16
|
+
builder.before_three = [three_proc]
|
17
|
+
|
18
|
+
class Listener1 < Ruby2Jar::Listener
|
19
|
+
def before_two; end
|
20
|
+
def before_three; end
|
21
|
+
def before_four; end
|
22
|
+
end
|
23
|
+
listener = Listener1.new(builder)
|
24
|
+
|
25
|
+
builder.before_one.should == []
|
26
|
+
builder.before_two.should == [listener.method(:before_two)]
|
27
|
+
builder.before_three.should == [three_proc, listener.method(:before_three)]
|
28
|
+
end
|
29
|
+
|
30
|
+
it "should add on_error function as builder listener" do
|
31
|
+
class Builder2
|
32
|
+
attr_accessor :before_one
|
33
|
+
attr_accessor :on_error
|
34
|
+
end
|
35
|
+
builder = Builder2.new
|
36
|
+
builder.before_one = []
|
37
|
+
builder.on_error = []
|
38
|
+
|
39
|
+
class Listener2 < Ruby2Jar::Listener
|
40
|
+
def before_one; end
|
41
|
+
def on_error; end
|
42
|
+
end
|
43
|
+
listener = Listener2.new(builder)
|
44
|
+
|
45
|
+
builder.before_one.should == [listener.method(:before_one)]
|
46
|
+
builder.on_error.should == [listener.method(:on_error)]
|
47
|
+
end
|
48
|
+
|
49
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), "..", "lib", "ruby2jar")
|
metadata
ADDED
@@ -0,0 +1,90 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
rubygems_version: 0.9.4
|
3
|
+
specification_version: 1
|
4
|
+
name: ruby2jar
|
5
|
+
version: !ruby/object:Gem::Version
|
6
|
+
version: "0.1"
|
7
|
+
date: 2008-06-28 00:00:00 +04:00
|
8
|
+
summary: Build JAR from Ruby script.
|
9
|
+
require_paths:
|
10
|
+
- lib
|
11
|
+
email: andrey@sitnik.ru
|
12
|
+
homepage: http://ruby2jar.rubyforge.org/
|
13
|
+
rubyforge_project: ruby2jar
|
14
|
+
description: Ruby2Jar build JAR from Ruby script. It copy gems, compile sources and package JAR. It is a easy way to distribute your JRuby application or to create Applet or Java Web Start.
|
15
|
+
autorequire:
|
16
|
+
default_executable:
|
17
|
+
bindir: bin
|
18
|
+
has_rdoc: false
|
19
|
+
required_ruby_version: !ruby/object:Gem::Version::Requirement
|
20
|
+
requirements:
|
21
|
+
- - ">"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: 0.0.0
|
24
|
+
version:
|
25
|
+
platform: ruby
|
26
|
+
signing_key:
|
27
|
+
cert_chain:
|
28
|
+
post_install_message:
|
29
|
+
authors:
|
30
|
+
- Andrey "A.I." Sitnik
|
31
|
+
files:
|
32
|
+
- lib/ruby2jar
|
33
|
+
- lib/ruby2jar/console.rb
|
34
|
+
- lib/ruby2jar/jartask.rb
|
35
|
+
- lib/ruby2jar/listener.rb
|
36
|
+
- lib/ruby2jar/builder.rb
|
37
|
+
- lib/ruby2jar/error.rb
|
38
|
+
- lib/ruby2jar.rb
|
39
|
+
- spec/spec_helper.rb
|
40
|
+
- spec/builder
|
41
|
+
- spec/builder/spec_helper.rb
|
42
|
+
- spec/builder/fixtures
|
43
|
+
- spec/builder/fixtures/app
|
44
|
+
- spec/builder/fixtures/app/greeters
|
45
|
+
- spec/builder/fixtures/app/greeters/english.rb
|
46
|
+
- spec/builder/fixtures/app/main.rb
|
47
|
+
- spec/builder/fixtures/app/ext
|
48
|
+
- spec/builder/fixtures/app/ext/greeters
|
49
|
+
- spec/builder/fixtures/app/ext/greeters/JavaGreeter.java
|
50
|
+
- spec/builder/fixtures/jruby
|
51
|
+
- spec/builder/fixtures/jruby/lib
|
52
|
+
- spec/builder/fixtures/jruby/lib/jruby.jar
|
53
|
+
- spec/builder/create_init_spec.rb
|
54
|
+
- spec/builder/builder_spec.rb
|
55
|
+
- spec/builder/copy_spec.rb
|
56
|
+
- spec/builder/before_spec.rb
|
57
|
+
- spec/builder/package_spec.rb
|
58
|
+
- spec/console
|
59
|
+
- spec/console/spec_helper.rb
|
60
|
+
- spec/console/console_spec.rb
|
61
|
+
- spec/jartask
|
62
|
+
- spec/jartask/jartask_spec.rb
|
63
|
+
- spec/listener
|
64
|
+
- spec/listener/listener_spec.rb
|
65
|
+
- LICENSE
|
66
|
+
- TODO
|
67
|
+
- Rakefile
|
68
|
+
- README
|
69
|
+
test_files: []
|
70
|
+
|
71
|
+
rdoc_options: []
|
72
|
+
|
73
|
+
extra_rdoc_files: []
|
74
|
+
|
75
|
+
executables: []
|
76
|
+
|
77
|
+
extensions: []
|
78
|
+
|
79
|
+
requirements: []
|
80
|
+
|
81
|
+
dependencies:
|
82
|
+
- !ruby/object:Gem::Dependency
|
83
|
+
name: rake
|
84
|
+
version_requirement:
|
85
|
+
version_requirements: !ruby/object:Gem::Version::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: 0.0.0
|
90
|
+
version:
|