jrmvnrunner 0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +45 -0
- data/bin/jrmvnrun +16 -0
- data/bin/jrmvnrun.bat +1 -0
- data/lib/jrmvnrunner.rb +33 -0
- data/lib/jrmvnrunner/dsl.rb +83 -0
- data/lib/jrmvnrunner/runner.rb +238 -0
- data/spec/spec_helper.rb +17 -0
- metadata +70 -0
data/README.md
ADDED
@@ -0,0 +1,45 @@
|
|
1
|
+
# JRMVNRunner
|
2
|
+
|
3
|
+
If you are looking for the easy way to run your JRuby application and to indicate the gem and jar dependencies in a
|
4
|
+
single place, this library might be one of the acceptable options for you. Please take a look at the analogues first,
|
5
|
+
like [JBundler](https://github.com/mkristian/jbundler) and [Doubleshot](https://github.com/sam/doubleshot).
|
6
|
+
|
7
|
+
## Why?
|
8
|
+
|
9
|
+
Doubleshot looks ok, but it requires java 1.7+. JBundler is good, but sometimes does not do what you want.
|
10
|
+
|
11
|
+
## What it gives
|
12
|
+
|
13
|
+
You can create the Jrmvnrunner file at the root level of your project with the following content:
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
|
17
|
+
project 'mygroup:myproject:0.1'
|
18
|
+
|
19
|
+
Pomfile do
|
20
|
+
source 'http://maven.smecsia.me'
|
21
|
+
jar 'commons-lang:commons-lang:2.6:jar'
|
22
|
+
end
|
23
|
+
|
24
|
+
Gemfile do
|
25
|
+
source :rubygems
|
26
|
+
gem 'json'
|
27
|
+
gem 'rspec', '~> 2.12.0'
|
28
|
+
gem 'rake', '10.0.3'
|
29
|
+
gem 'activesupport', '~> 3.2.8'
|
30
|
+
gem 'activerecord', '~> 3.2.8'
|
31
|
+
gem 'cucumber'
|
32
|
+
end
|
33
|
+
|
34
|
+
```
|
35
|
+
|
36
|
+
Then you can execute:
|
37
|
+
|
38
|
+
```
|
39
|
+
jrmvnrun exec rake features
|
40
|
+
```
|
41
|
+
|
42
|
+
This will execute a command with the full jar dependencies list in the classpath,
|
43
|
+
so you can use them inside your ruby code.
|
44
|
+
|
45
|
+
## How to install
|
data/bin/jrmvnrun
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env jruby
|
2
|
+
require File.expand_path(File.join(File.dirname(__FILE__), '../lib/jrmvnrunner.rb'))
|
3
|
+
|
4
|
+
args = ARGV.dup
|
5
|
+
command = args.shift
|
6
|
+
case command
|
7
|
+
when "exec"
|
8
|
+
cmd = args.shift
|
9
|
+
Jrmvnrunner.init!(Dir.pwd, cmd, args)
|
10
|
+
when "help"
|
11
|
+
puts "jrmvnrun exec [COMMAND]"
|
12
|
+
else
|
13
|
+
puts "Unknown command '#{command}'! Exec jrmvnrun help to see the options!"
|
14
|
+
end
|
15
|
+
|
16
|
+
|
data/bin/jrmvnrun.bat
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
jruby run jrmvnrun
|
data/lib/jrmvnrunner.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
|
3
|
+
module Jrmvnrunner
|
4
|
+
VERSION=0.1
|
5
|
+
MYDIR = Pathname.new(File.dirname(File.expand_path(__FILE__)))
|
6
|
+
autoload :Runner, MYDIR.join('jrmvnrunner/runner')
|
7
|
+
autoload :Dsl, MYDIR.join('jrmvnrunner/dsl')
|
8
|
+
|
9
|
+
def self.init!(wdir = Dir.pwd, cmd = nil, args = [])
|
10
|
+
root = Pathname.new(wdir)
|
11
|
+
|
12
|
+
runnerfile = root.join("Jrmvnrunner")
|
13
|
+
if File.exists?(runnerfile)
|
14
|
+
dsl = Dsl.new
|
15
|
+
runner_conf = File.read(runnerfile)
|
16
|
+
|
17
|
+
dsl.instance_exec do
|
18
|
+
eval(runner_conf.match(/(project .+)\n/)[1])
|
19
|
+
end
|
20
|
+
|
21
|
+
dsl.Pomfile(runner_conf.match(/Pomfile\s+do\s(.+?)end/m)[1])
|
22
|
+
dsl.Gemfile(runner_conf.match(/Gemfile\s+do\s(.+?)end/m)[1])
|
23
|
+
runner = Runner.new(cmd, {
|
24
|
+
:gem => dsl.gem,
|
25
|
+
:pom => dsl.pom,
|
26
|
+
:project => dsl.project_info,
|
27
|
+
:root => root,
|
28
|
+
:args => args
|
29
|
+
})
|
30
|
+
runner.execute!
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require 'sourcify'
|
2
|
+
|
3
|
+
module Jrmvnrunner
|
4
|
+
class Dsl
|
5
|
+
|
6
|
+
class Pom
|
7
|
+
attr_reader :repositories
|
8
|
+
attr_reader :dependencies
|
9
|
+
|
10
|
+
def initialize
|
11
|
+
@repositories = []
|
12
|
+
@dependencies = []
|
13
|
+
end
|
14
|
+
|
15
|
+
def jar(path)
|
16
|
+
path = path.split(':')
|
17
|
+
@dependencies << {
|
18
|
+
:group_id => path[0],
|
19
|
+
:artifact_id => path[1],
|
20
|
+
:version => path[2],
|
21
|
+
:type => path[3] || 'jar',
|
22
|
+
:classifier => path[4]
|
23
|
+
}
|
24
|
+
end
|
25
|
+
|
26
|
+
def source(path)
|
27
|
+
@repositories << {
|
28
|
+
:name => path,
|
29
|
+
:url => path,
|
30
|
+
}
|
31
|
+
end
|
32
|
+
end
|
33
|
+
|
34
|
+
class Gem
|
35
|
+
attr_reader :source
|
36
|
+
|
37
|
+
def initialize
|
38
|
+
@source = ""
|
39
|
+
end
|
40
|
+
|
41
|
+
def source=(src)
|
42
|
+
@source = src
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
attr_reader :pom
|
47
|
+
attr_reader :gem
|
48
|
+
attr_reader :project_info
|
49
|
+
|
50
|
+
def initialize
|
51
|
+
@pom = Pom.new
|
52
|
+
@gem = Gem.new
|
53
|
+
@project_info = {:name => "jrmvnrunner", :version => '1.0'}
|
54
|
+
end
|
55
|
+
|
56
|
+
def Pomfile(code=nil, &block)
|
57
|
+
if code
|
58
|
+
@pom.instance_exec do
|
59
|
+
eval(code)
|
60
|
+
end
|
61
|
+
else
|
62
|
+
@pom.instance_exec(&block) if block_given?
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def Gemfile(code=nil, &block)
|
67
|
+
if code
|
68
|
+
@gem.source=code
|
69
|
+
else
|
70
|
+
@gem.source=block.to_ruby if block_given?
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
def project(path)
|
75
|
+
path = path.split(':')
|
76
|
+
@project_info.merge!(
|
77
|
+
:group_id => path[0],
|
78
|
+
:name => path[1],
|
79
|
+
:version => path[2]
|
80
|
+
)
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,238 @@
|
|
1
|
+
require 'pathname'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'tmpdir'
|
4
|
+
require 'securerandom'
|
5
|
+
require 'yaml'
|
6
|
+
|
7
|
+
module Jrmvnrunner
|
8
|
+
class Runner
|
9
|
+
def initialize(cmd = nil, opts={})
|
10
|
+
@args = opts[:args] || []
|
11
|
+
@opts = opts
|
12
|
+
@pom = opts[:pom] || Dsl::Pom.new
|
13
|
+
@gem = opts[:gem] || Dsl::Gem.new
|
14
|
+
@root = opts[:root] || root
|
15
|
+
@cmd = cmd
|
16
|
+
@tmpdir = opts[:tmpdir]
|
17
|
+
@config = YAML::load(File.read(cfg_file)) if File.exists?(cfg_file)
|
18
|
+
@config ||= {}
|
19
|
+
@opts[:project] ||= {:group_id => 'test', :artifact_id => 'test', :version => '0.1-SNAPSHOT'}
|
20
|
+
end
|
21
|
+
|
22
|
+
def execute!
|
23
|
+
log "Current directory: #{Dir.pwd}"
|
24
|
+
|
25
|
+
ensure_jruby!
|
26
|
+
write_gem!
|
27
|
+
ensure_bundle!
|
28
|
+
write_pom!
|
29
|
+
maven_build!
|
30
|
+
remove_gem_and_pom!
|
31
|
+
|
32
|
+
if @cmd
|
33
|
+
# Generating command and exec...
|
34
|
+
ensure_cmd!
|
35
|
+
cmd=%Q["#{cmd_path("jruby")}" #{cp_string} #{jruby_opts} "#{cmd_path(@cmd)}" #{@args.join(" ")}]
|
36
|
+
log "Executing '#{cmd}'..."
|
37
|
+
exec cmd
|
38
|
+
else
|
39
|
+
require 'java'
|
40
|
+
ENV['BUNDLE_GEMFILE'] = gem_file
|
41
|
+
require 'bundler/setup'
|
42
|
+
jar_files.each { |jf| require jf }
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
def cfg_file
|
49
|
+
root.join("config", "adapter.yml")
|
50
|
+
end
|
51
|
+
|
52
|
+
def which_cmd
|
53
|
+
windows? ? "where" : "which"
|
54
|
+
end
|
55
|
+
|
56
|
+
def jruby_opts
|
57
|
+
@opts[:jruby_opts] || "--1.9"
|
58
|
+
end
|
59
|
+
|
60
|
+
def windows?
|
61
|
+
@opts[:platform] == "windows"
|
62
|
+
end
|
63
|
+
|
64
|
+
def root
|
65
|
+
@root ||= Pathname.new(File.expand_path(File.join(File.dirname(__FILE__), '..')))
|
66
|
+
@root
|
67
|
+
end
|
68
|
+
|
69
|
+
def cp_join_sign
|
70
|
+
windows? ? ";" : ":"
|
71
|
+
end
|
72
|
+
|
73
|
+
def cmd_path(cmd)
|
74
|
+
@config["#{cmd}.bin"] || `#{which_cmd} #{cmd}`.split("\n").select { |l| !l.nil? && !l.empty? }.first
|
75
|
+
end
|
76
|
+
|
77
|
+
def cp_string
|
78
|
+
# Searching through dependent jars
|
79
|
+
cp = jar_files.join(cp_join_sign)
|
80
|
+
%Q{-J-cp "#{cp}"}
|
81
|
+
end
|
82
|
+
|
83
|
+
def jar_files
|
84
|
+
Dir[Pathname.new(build_dir).join("#{@opts[:project][:name]}", "*.jar")]
|
85
|
+
end
|
86
|
+
|
87
|
+
def gems_list
|
88
|
+
`"#{cmd_path("jgem")}" list`
|
89
|
+
end
|
90
|
+
|
91
|
+
def ensure_cmd!
|
92
|
+
raise "Cannot find command '#{@cmd}': (tried '#{which_cmd} #{@cmd}')!" if cmd_path(@cmd).nil?
|
93
|
+
end
|
94
|
+
|
95
|
+
def ensure_jruby!
|
96
|
+
raise "Cannot find valid JRuby installation (tried command '#{which_cmd} jruby')!" if cmd_path("jruby").nil?
|
97
|
+
end
|
98
|
+
|
99
|
+
def ensure_bundle!
|
100
|
+
unless gems_list =~ /bundler/
|
101
|
+
log "Installing bundler..."
|
102
|
+
res = `"#{cmd_path("jgem")}" install bundler`
|
103
|
+
raise "Cannot install bundler: \n #{res}" unless res =~ /Successfully installed bundler/
|
104
|
+
end
|
105
|
+
log "Installing bundle..."
|
106
|
+
res = `"#{cmd_path("bundle")}" install --gemfile #{gem_file}`
|
107
|
+
raise "Cannot install bundle: \n #{res}" unless res =~ /Your bundle is complete!/
|
108
|
+
end
|
109
|
+
|
110
|
+
def maven_build!
|
111
|
+
# Building Maven dependencies...
|
112
|
+
raise "Cannot find valid Maven installation (tried command '#{which_cmd} mvn')!" if cmd_path("mvn").nil?
|
113
|
+
log "Building dependencies..."
|
114
|
+
build_res = `"#{cmd_path("mvn")}" -f #{pom_file} clean install`
|
115
|
+
raise "Cannot build project: \n #{build_res}" unless build_res =~ /BUILD SUCCESS/
|
116
|
+
end
|
117
|
+
|
118
|
+
def log(msg)
|
119
|
+
puts msg
|
120
|
+
end
|
121
|
+
|
122
|
+
def gem
|
123
|
+
@gem
|
124
|
+
end
|
125
|
+
|
126
|
+
def pom
|
127
|
+
@pom
|
128
|
+
end
|
129
|
+
|
130
|
+
def gem_file
|
131
|
+
@gem_file ||= Pathname.new(tmpdir).join('Gemfile').to_s
|
132
|
+
@gem_file
|
133
|
+
end
|
134
|
+
|
135
|
+
def pom_file
|
136
|
+
@pom_file ||= Pathname.new(tmpdir).join('pom.xml').to_s
|
137
|
+
@pom_file
|
138
|
+
end
|
139
|
+
|
140
|
+
def tmpdir
|
141
|
+
@tmpdir ||= Pathname.new(Etc.systmpdir).join(SecureRandom.hex(5)).to_s
|
142
|
+
FileUtils.mkdir_p(@tmpdir)
|
143
|
+
@tmpdir
|
144
|
+
end
|
145
|
+
|
146
|
+
def build_dir
|
147
|
+
@builddir ||= Pathname.new(tmpdir).join('target').to_s
|
148
|
+
@builddir
|
149
|
+
end
|
150
|
+
|
151
|
+
def generate_gem
|
152
|
+
@gem.source
|
153
|
+
end
|
154
|
+
|
155
|
+
def write_gem!
|
156
|
+
log "Writing temporary Gemfile: #{gem_file}"
|
157
|
+
File.open(gem_file, "w+") do |f|
|
158
|
+
f.write(generate_gem)
|
159
|
+
end
|
160
|
+
end
|
161
|
+
|
162
|
+
def write_pom!
|
163
|
+
log "Writing temporary Pomfile: #{pom_file}"
|
164
|
+
File.open(pom_file, "w+") do |f|
|
165
|
+
f.write(generate_pom)
|
166
|
+
end
|
167
|
+
end
|
168
|
+
|
169
|
+
def remove_gem_and_pom!
|
170
|
+
File.unlink(gem_file)
|
171
|
+
File.unlink(pom_file)
|
172
|
+
end
|
173
|
+
|
174
|
+
def generate_pom
|
175
|
+
<<-XML
|
176
|
+
<?xml version="1.0" encoding="UTF-8"?>
|
177
|
+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
178
|
+
<modelVersion>4.0.0</modelVersion>
|
179
|
+
<groupId>#{@opts[:project][:group_id]}</groupId>
|
180
|
+
<artifactId>#{@opts[:project][:name]}</artifactId>
|
181
|
+
<version>#{@opts[:project][:version]}</version>
|
182
|
+
<packaging>ear</packaging>
|
183
|
+
|
184
|
+
<properties>
|
185
|
+
<project.compiler.version>1.6</project.compiler.version>
|
186
|
+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
|
187
|
+
</properties>
|
188
|
+
|
189
|
+
<repositories>
|
190
|
+
#{
|
191
|
+
pom.repositories.map do |r|
|
192
|
+
%Q[
|
193
|
+
<repository>
|
194
|
+
<id>#{r[:name]}</id>
|
195
|
+
<name>#{r[:description]}</name>
|
196
|
+
<url>#{r[:url]}</url>
|
197
|
+
</repository>
|
198
|
+
]
|
199
|
+
end.join("\n")
|
200
|
+
}
|
201
|
+
</repositories>
|
202
|
+
|
203
|
+
<dependencies>
|
204
|
+
#{
|
205
|
+
pom.dependencies.map do |d|
|
206
|
+
%Q[
|
207
|
+
<dependency>
|
208
|
+
<groupId>#{d[:group_id]}</groupId>
|
209
|
+
<artifactId>#{d[:artifact_id]}</artifactId>
|
210
|
+
<version>#{d[:version]}</version>
|
211
|
+
<type>#{d[:type]}</type>
|
212
|
+
</dependency>
|
213
|
+
]
|
214
|
+
end.join("\n")
|
215
|
+
}
|
216
|
+
</dependencies>
|
217
|
+
<build>
|
218
|
+
<finalName>#{@opts[:project][:name]}</finalName>
|
219
|
+
<directory>#{build_dir}</directory>
|
220
|
+
<plugins>
|
221
|
+
<plugin>
|
222
|
+
<groupId>org.apache.maven.plugins</groupId>
|
223
|
+
<artifactId>maven-compiler-plugin</artifactId>
|
224
|
+
<version>2.3.2</version>
|
225
|
+
<configuration>
|
226
|
+
<encoding>${project.build.sourceEncoding}</encoding>
|
227
|
+
<source>${project.compiler.version}</source>
|
228
|
+
<target>${project.compiler.version}</target>
|
229
|
+
<optimize>true</optimize>
|
230
|
+
</configuration>
|
231
|
+
</plugin>
|
232
|
+
</plugins>
|
233
|
+
</build>
|
234
|
+
</project>
|
235
|
+
XML
|
236
|
+
end
|
237
|
+
end
|
238
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require File.expand_path(File.dirname(__FILE__) + '/../config/environment')
|
2
|
+
|
3
|
+
RSpec.configure do |config|
|
4
|
+
# ## Mock Framework
|
5
|
+
#
|
6
|
+
# If you prefer to use mocha, flexmock or RR, uncomment the appropriate line:
|
7
|
+
#
|
8
|
+
# config.mock_with :mocha
|
9
|
+
# config.mock_with :flexmock
|
10
|
+
# config.mock_with :rr
|
11
|
+
|
12
|
+
# Run specs in random order to surface order dependencies. If you find an
|
13
|
+
# order dependency and want to debug it, you can fix the order by providing
|
14
|
+
# the seed, which is printed after each run.
|
15
|
+
# --seed 1234
|
16
|
+
#config.order = "random"
|
17
|
+
end
|
metadata
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jrmvnrunner
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: '0.1'
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Ilya Sadykov
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-03-02 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
17
|
+
requirements:
|
18
|
+
- - "~>"
|
19
|
+
- !ruby/object:Gem::Version
|
20
|
+
version: 2.10.0
|
21
|
+
none: false
|
22
|
+
requirement: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 2.10.0
|
27
|
+
none: false
|
28
|
+
prerelease: false
|
29
|
+
type: :development
|
30
|
+
description: This gem allows you to specify the jar-dependencies of your project and run your tasks with the classpath
|
31
|
+
email: smecsia@gmail.com
|
32
|
+
executables:
|
33
|
+
- jrmvnrun
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- bin/jrmvnrun.bat
|
38
|
+
- bin/jrmvnrun
|
39
|
+
- lib/jrmvnrunner.rb
|
40
|
+
- lib/jrmvnrunner/runner.rb
|
41
|
+
- lib/jrmvnrunner/dsl.rb
|
42
|
+
- spec/spec_helper.rb
|
43
|
+
- README.md
|
44
|
+
homepage: ''
|
45
|
+
licenses: []
|
46
|
+
post_install_message:
|
47
|
+
rdoc_options: []
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: !binary |-
|
55
|
+
MA==
|
56
|
+
none: false
|
57
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: !binary |-
|
62
|
+
MA==
|
63
|
+
none: false
|
64
|
+
requirements: []
|
65
|
+
rubyforge_project:
|
66
|
+
rubygems_version: 1.8.24
|
67
|
+
signing_key:
|
68
|
+
specification_version: 3
|
69
|
+
summary: Simple lib to execute jruby task with the java classpath
|
70
|
+
test_files: []
|