jar_wrapper 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGES +6 -0
- data/README +31 -0
- data/Rakefile +54 -0
- data/VERSION +1 -0
- data/jar_wrapper.gemspec +54 -0
- data/lib/jar_wrapper/jar_wrapper.rb +154 -0
- data/lib/jar_wrapper.rb +14 -0
- metadata +97 -0
data/CHANGES
ADDED
data/README
ADDED
@@ -0,0 +1,31 @@
|
|
1
|
+
= Jar Wrapper -- Jar wrapper for executable java jarjava jar
|
2
|
+
|
3
|
+
= Installing Jar Wrapper
|
4
|
+
|
5
|
+
== Installing Jar Wrapper
|
6
|
+
$ gem install jar_wrapper
|
7
|
+
|
8
|
+
== Usage
|
9
|
+
|
10
|
+
require 'jar_wrapper'
|
11
|
+
|
12
|
+
wrapper = JarWrapper.new
|
13
|
+
wrapper.java_opts = ["-Xmx1024m", "-Xss1024k" ]
|
14
|
+
|
15
|
+
# 1. install jar file from source URL into target file:
|
16
|
+
|
17
|
+
wrapper.install source, target
|
18
|
+
|
19
|
+
# 2. execute jar file (java -jar jar_file):
|
20
|
+
|
21
|
+
wrapper.jar_file = jar_file
|
22
|
+
wrapper.run ARGV
|
23
|
+
|
24
|
+
# 3. execute main class (java -cp ... main_class):
|
25
|
+
|
26
|
+
wrapper.classpath = some_class_path
|
27
|
+
wrapper.main_class = main_class
|
28
|
+
wrapper.run ARGV
|
29
|
+
|
30
|
+
|
31
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Rakefile for winstone
|
2
|
+
|
3
|
+
task :default => :gemspec
|
4
|
+
|
5
|
+
begin
|
6
|
+
require 'bundler'
|
7
|
+
|
8
|
+
begin
|
9
|
+
require 'jeweler'
|
10
|
+
|
11
|
+
Jeweler::Tasks.new do |gemspec|
|
12
|
+
gemspec.name = "jar_wrapper"
|
13
|
+
gemspec.summary = "Jar wrapper for executable java jar (Summary)."
|
14
|
+
gemspec.description = "Jar wrapper for executable java jar."
|
15
|
+
gemspec.email = "alexander.shvets@gmail.com"
|
16
|
+
gemspec.homepage = "http://github.com/shvets/jar_wrapper"
|
17
|
+
gemspec.authors = ["Alexander Shvets"]
|
18
|
+
gemspec.files = FileList["CHANGES", "jar_wrapper.gemspec", "Rakefile", "README", "VERSION",
|
19
|
+
"lib/**/*", "bin/**/*"]
|
20
|
+
gemspec.requirements = ["none"]
|
21
|
+
gemspec.bindir = "bin"
|
22
|
+
|
23
|
+
gemspec.add_bundler_dependencies
|
24
|
+
end
|
25
|
+
rescue LoadError
|
26
|
+
puts "Jeweler not available. Install it s with: [sudo] gem install jeweler"
|
27
|
+
end
|
28
|
+
rescue LoadError
|
29
|
+
puts "Bundler not available. Install it s with: [sudo] gem install bundler"
|
30
|
+
end
|
31
|
+
|
32
|
+
|
33
|
+
desc "Release the gem"
|
34
|
+
task :"release:gem" do
|
35
|
+
%x(
|
36
|
+
rake gemspec
|
37
|
+
rake build
|
38
|
+
rake install
|
39
|
+
git add .
|
40
|
+
)
|
41
|
+
puts "Commit message:"
|
42
|
+
message = STDIN.gets
|
43
|
+
|
44
|
+
version = "#{File.open(File::dirname(__FILE__) + "/VERSION").readlines().first}"
|
45
|
+
|
46
|
+
%x(
|
47
|
+
git commit -m "#{message}"
|
48
|
+
|
49
|
+
git push origin master
|
50
|
+
|
51
|
+
gem push pkg/jar_wrapper-#{version}.gem
|
52
|
+
)
|
53
|
+
end
|
54
|
+
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/jar_wrapper.gemspec
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{jar_wrapper}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = [%q{Alexander Shvets}]
|
12
|
+
s.date = %q{2011-09-23}
|
13
|
+
s.description = %q{Jar wrapper for executable java jar.}
|
14
|
+
s.email = %q{alexander.shvets@gmail.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"CHANGES",
|
20
|
+
"README",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"jar_wrapper.gemspec",
|
24
|
+
"lib/jar_wrapper.rb",
|
25
|
+
"lib/jar_wrapper/jar_wrapper.rb"
|
26
|
+
]
|
27
|
+
s.homepage = %q{http://github.com/shvets/jar_wrapper}
|
28
|
+
s.require_paths = [%q{lib}]
|
29
|
+
s.requirements = [%q{none}]
|
30
|
+
s.rubygems_version = %q{1.8.6}
|
31
|
+
s.summary = %q{Jar wrapper for executable java jar (Summary).}
|
32
|
+
|
33
|
+
if s.respond_to? :specification_version then
|
34
|
+
s.specification_version = 3
|
35
|
+
|
36
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
37
|
+
s.add_runtime_dependency(%q<jeweler>, [">= 0"])
|
38
|
+
s.add_runtime_dependency(%q<zip>, [">= 0"])
|
39
|
+
s.add_runtime_dependency(%q<jeweler>, [">= 0"])
|
40
|
+
s.add_runtime_dependency(%q<zip>, [">= 0"])
|
41
|
+
else
|
42
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
43
|
+
s.add_dependency(%q<zip>, [">= 0"])
|
44
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
45
|
+
s.add_dependency(%q<zip>, [">= 0"])
|
46
|
+
end
|
47
|
+
else
|
48
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
49
|
+
s.add_dependency(%q<zip>, [">= 0"])
|
50
|
+
s.add_dependency(%q<jeweler>, [">= 0"])
|
51
|
+
s.add_dependency(%q<zip>, [">= 0"])
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
@@ -0,0 +1,154 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
class JarWrapper
|
4
|
+
attr_accessor :main_class, :classpath, :jar_file, :java_opts
|
5
|
+
|
6
|
+
def install source, destination
|
7
|
+
download_file_to(source, destination)
|
8
|
+
|
9
|
+
unzip_file(destination) if destination =~ /\.zip$/
|
10
|
+
end
|
11
|
+
|
12
|
+
def run args
|
13
|
+
construct_command(args) do |command|
|
14
|
+
exec(command.join(" "))
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
private
|
19
|
+
|
20
|
+
def construct_command(args="")
|
21
|
+
command = ["java"]
|
22
|
+
command.push(*java_args)
|
23
|
+
# command.push("-Xbootclasspath/a:#{jruby_complete}")
|
24
|
+
# command.push("-Dfile.encoding=UTF8", "-Xmx320m", "-Xss1024k", "-Djruby.memory.max=320m", "-Djruby.stack.max=1024k", "org.jruby.Main")
|
25
|
+
command.push(*java_opts) if java_opts.length > 0
|
26
|
+
|
27
|
+
command.push("-jar", jar_file) if jar_file
|
28
|
+
command.push("-cp", classpath, main_class) if main_class
|
29
|
+
|
30
|
+
#command.push("-Djruby.memory.max=500m", "-Djruby.stack.max=1024k", "-cp", jruby_complete, "org.jruby.Main")
|
31
|
+
|
32
|
+
command.push "--debug" if debug_mode?
|
33
|
+
|
34
|
+
command.push(*cleaned_args(args))
|
35
|
+
|
36
|
+
puts command.join(' ')
|
37
|
+
yield command
|
38
|
+
end
|
39
|
+
|
40
|
+
def cleaned_args args
|
41
|
+
# We should never pass --fork to a subprocess
|
42
|
+
result = args.find_all { |arg| arg != '--fork' }.map do |arg|
|
43
|
+
if arg =~ /--(.+)=(.+)/
|
44
|
+
"--" + $1 + "=\"" + $2 + "\""
|
45
|
+
else
|
46
|
+
arg
|
47
|
+
end
|
48
|
+
end
|
49
|
+
result.delete("install")
|
50
|
+
result
|
51
|
+
end
|
52
|
+
|
53
|
+
def debug_mode?
|
54
|
+
ARGV.include?("--debug")
|
55
|
+
end
|
56
|
+
|
57
|
+
def java_args
|
58
|
+
str = []
|
59
|
+
if Config::CONFIG["host_os"] =~ /darwin/
|
60
|
+
str.push "-XstartOnFirstThread"
|
61
|
+
end
|
62
|
+
|
63
|
+
str.push "-d32" if d32?
|
64
|
+
str.push "-client" if client?
|
65
|
+
|
66
|
+
str
|
67
|
+
end
|
68
|
+
|
69
|
+
def redirect
|
70
|
+
@redirect ||= "> #{null_device} 2>&1"
|
71
|
+
end
|
72
|
+
|
73
|
+
def d32?
|
74
|
+
@d32 ||= system("java -d32 #{redirect}")
|
75
|
+
end
|
76
|
+
|
77
|
+
def client?
|
78
|
+
@client ||= system("java -client #{redirect}")
|
79
|
+
end
|
80
|
+
|
81
|
+
# @return [:osx/:windows/:linux]
|
82
|
+
def platform
|
83
|
+
case Config::CONFIG["target_os"]
|
84
|
+
when /darwin/
|
85
|
+
:osx
|
86
|
+
when /mswin|mingw/
|
87
|
+
:windows
|
88
|
+
when /linux/
|
89
|
+
:linux
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
def null_device
|
94
|
+
case platform
|
95
|
+
when :windows
|
96
|
+
'nul'
|
97
|
+
else
|
98
|
+
'/dev/null'
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
def download_file_to(uri, destination_file)
|
103
|
+
print " downloading #{uri}... "; $stdout.flush
|
104
|
+
|
105
|
+
temp = destination_file + ".part"
|
106
|
+
FileUtils.mkdir_p(File.dirname(destination_file))
|
107
|
+
|
108
|
+
File.open(temp, "wb") do |out_file|
|
109
|
+
open(uri) do |in_file|
|
110
|
+
done = false
|
111
|
+
|
112
|
+
while(!done) do
|
113
|
+
buffer = in_file.read(1024*1000)
|
114
|
+
out_file.write(buffer)
|
115
|
+
|
116
|
+
if buffer.nil? || buffer.size == 0
|
117
|
+
done = true
|
118
|
+
else
|
119
|
+
print("#"); $stdout.flush
|
120
|
+
end
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
if File.open(temp).read(200) =~ /Access Denied/
|
126
|
+
puts "\n\n*** Error downloading #{uri}, got Access Denied from S3."
|
127
|
+
FileUtils.rm_rf(temp)
|
128
|
+
exit
|
129
|
+
end
|
130
|
+
|
131
|
+
FileUtils.cp(temp, destination_file)
|
132
|
+
FileUtils.rm_rf(temp)
|
133
|
+
puts "\ndone!"
|
134
|
+
end
|
135
|
+
|
136
|
+
# unzip a .zip file into the directory it is located
|
137
|
+
def unzip_file(path)
|
138
|
+
print "unzipping #{path}..."; $stdout.flush
|
139
|
+
source = File.expand_path(path)
|
140
|
+
Dir.chdir(File.dirname(source)) do
|
141
|
+
Zip::ZipFile.open(source) do |zipfile|
|
142
|
+
zipfile.entries.each do |entry|
|
143
|
+
FileUtils.mkdir_p(File.dirname(entry.name))
|
144
|
+
begin
|
145
|
+
entry.extract
|
146
|
+
rescue Zip::ZipDestinationFileExistsError
|
147
|
+
end
|
148
|
+
end
|
149
|
+
end
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
|
data/lib/jar_wrapper.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
require 'rubygems' unless RUBY_VERSION =~ /1.9.*/
|
2
|
+
|
3
|
+
$:.unshift(File.dirname(__FILE__)) unless
|
4
|
+
$:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
|
5
|
+
|
6
|
+
require 'fileutils'
|
7
|
+
require 'net/http'
|
8
|
+
|
9
|
+
require 'jar_wrapper/jar_wrapper'
|
10
|
+
|
11
|
+
require 'rbconfig'
|
12
|
+
WINDOZE = Config::CONFIG['host_os'] =~ /mswin|mingw|windows/
|
13
|
+
|
14
|
+
WINDOZE ? (require "zip/zipfilesystem") : (require 'zip/zip')
|
metadata
ADDED
@@ -0,0 +1,97 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jar_wrapper
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Alexander Shvets
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-09-23 00:00:00.000000000Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: jeweler
|
16
|
+
requirement: &2157099060 !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: *2157099060
|
25
|
+
- !ruby/object:Gem::Dependency
|
26
|
+
name: zip
|
27
|
+
requirement: &2157097980 !ruby/object:Gem::Requirement
|
28
|
+
none: false
|
29
|
+
requirements:
|
30
|
+
- - ! '>='
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
type: :runtime
|
34
|
+
prerelease: false
|
35
|
+
version_requirements: *2157097980
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: jeweler
|
38
|
+
requirement: &2157097320 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :runtime
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *2157097320
|
47
|
+
- !ruby/object:Gem::Dependency
|
48
|
+
name: zip
|
49
|
+
requirement: &2157096540 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
type: :runtime
|
56
|
+
prerelease: false
|
57
|
+
version_requirements: *2157096540
|
58
|
+
description: Jar wrapper for executable java jar.
|
59
|
+
email: alexander.shvets@gmail.com
|
60
|
+
executables: []
|
61
|
+
extensions: []
|
62
|
+
extra_rdoc_files:
|
63
|
+
- README
|
64
|
+
files:
|
65
|
+
- CHANGES
|
66
|
+
- README
|
67
|
+
- Rakefile
|
68
|
+
- VERSION
|
69
|
+
- jar_wrapper.gemspec
|
70
|
+
- lib/jar_wrapper.rb
|
71
|
+
- lib/jar_wrapper/jar_wrapper.rb
|
72
|
+
homepage: http://github.com/shvets/jar_wrapper
|
73
|
+
licenses: []
|
74
|
+
post_install_message:
|
75
|
+
rdoc_options: []
|
76
|
+
require_paths:
|
77
|
+
- lib
|
78
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
79
|
+
none: false
|
80
|
+
requirements:
|
81
|
+
- - ! '>='
|
82
|
+
- !ruby/object:Gem::Version
|
83
|
+
version: '0'
|
84
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
85
|
+
none: false
|
86
|
+
requirements:
|
87
|
+
- - ! '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
requirements:
|
91
|
+
- none
|
92
|
+
rubyforge_project:
|
93
|
+
rubygems_version: 1.8.6
|
94
|
+
signing_key:
|
95
|
+
specification_version: 3
|
96
|
+
summary: Jar wrapper for executable java jar (Summary).
|
97
|
+
test_files: []
|