gemjam 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,17 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ .yardoc
6
+ Gemfile.lock
7
+ InstalledFiles
8
+ _yardoc
9
+ coverage
10
+ doc/
11
+ lib/bundler/man
12
+ pkg
13
+ rdoc
14
+ spec/reports
15
+ test/tmp
16
+ test/version_tmp
17
+ tmp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gemjar.gemspec
4
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Vincent Batts
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,99 @@
1
+ # Gemjam
2
+
3
+ Create java jar, for jRuby, from gems or a bundler Gemfile
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'gemjam'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install gemjam
18
+
19
+ ## Usage
20
+
21
+ Package up a specific version of one gem, and latest version of another
22
+
23
+ gemjam -g sinatra,1.3.5 -g hurp
24
+
25
+ Package up the dependencies from the Gemfile in the current directory
26
+
27
+ gemjam -b
28
+
29
+ Combo, but Gemfile from another directory
30
+
31
+ gemjam -b ../foo/Gemfile -g sinatra,1.3.5 -g hurp
32
+
33
+ You'll get an output like
34
+
35
+ $ gemjam -g sinatra
36
+ {:jruby=>"jruby", :gems=>["sinatra"]}
37
+ Successfully installed rack-1.5.2
38
+ Successfully installed tilt-1.4.1
39
+ Successfully installed rack-protection-1.5.0
40
+ Successfully installed sinatra-1.4.3
41
+ 4 gems installed
42
+ Created d20130723-10726-1sgce23.jar
43
+
44
+ To grep only the jar name
45
+
46
+ $ gemjam -g sinatra | grep -e ^Created.*jar$ | cut -d " " -f 2
47
+ d20130723-10726-1sgce23.jar
48
+
49
+ To specify an alternate jruby executable
50
+
51
+ $ gemjam -j "java -jar ~/Downloads/jruby-complete-1.7.4.jar" -g sinatra
52
+ {:jruby=>"java -jar ~/Downloads/jruby-complete-1.7.4.jar", :gems=>["sinatra"]}
53
+ Successfully installed rack-1.5.2
54
+ Successfully installed tilt-1.4.1
55
+ Successfully installed rack-protection-1.5.0
56
+ Successfully installed sinatra-1.4.3
57
+ 4 gems installed
58
+ Created d20130723-24156-1omlum7.jar
59
+
60
+ How this is used practically aftwards
61
+
62
+ $ gemjam -j "java -jar ~/Downloads/jruby-complete-1.7.4.jar" -g rye
63
+ {:jruby=>"java -jar ~/Downloads/jruby-complete-1.7.4.jar", :gems=>["rye"]}
64
+ Successfully installed highline-1.6.19
65
+ Successfully installed annoy-0.5.6
66
+ Successfully installed storable-0.8.9
67
+ Successfully installed drydock-0.6.9
68
+ Successfully installed sysinfo-0.8.0
69
+ Successfully installed net-ssh-2.6.8
70
+ Successfully installed net-scp-1.1.2
71
+ Successfully installed docile-1.0.3
72
+ Successfully installed rye-0.9.8
73
+ 9 gems installed
74
+ Created d20130723-835-1i0moio.jar
75
+ $ java -jar ~/Downloads/jruby-complete-1.7.4.jar -r ./d20130723-835-1i0moio.jar -r rye -e 'puts Rye::Box.new("mybox.example.com").uptime'
76
+ 23:36:22 up 133 days, 9:23, 0 users, load average: 0.06, 0.05, 0.05
77
+
78
+
79
+ or
80
+
81
+ $ gemjam -g warbler
82
+ {:jruby=>"jruby", :gems=>["warbler"]}
83
+ Successfully installed rake-10.1.0
84
+ Successfully installed jruby-jars-1.7.4
85
+ Successfully installed warbler-1.3.8
86
+ 3 gems installed
87
+ Created d20130723-24956-4o39ld.jar
88
+ $ jruby -r ./d20130723-24956-4o39ld.jar -S warble
89
+ rm -f hurp.war
90
+ Creating hurp.war
91
+
92
+
93
+ ## Contributing
94
+
95
+ 1. Fork it
96
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
97
+ 3. Commit your changes (`git commit -am 'Added some feature'`)
98
+ 4. Push to the branch (`git push origin my-new-feature`)
99
+ 5. Create new Pull Request
@@ -0,0 +1,37 @@
1
+ #!/usr/bin/env rake
2
+
3
+ require "bundler/gem_tasks"
4
+ require "rake/clean"
5
+ require File.expand_path('../lib/gemjam/version', __FILE__)
6
+
7
+ def git_rev
8
+ `git rev-parse --short HEAD`.chomp
9
+ end
10
+
11
+ @dist = ENV["dist"] || ".fc16"
12
+ @d_dist = " --define 'dist #{@dist}'"
13
+ @d_version = " --define 'version #{Gemjam::VERSION}'"
14
+ @d_gitrev = "--define 'gitrev #{git_rev}'"
15
+
16
+ @gemfile = "pkg/gemjam-#{Gemjam::VERSION}.gem"
17
+ @srpmfile = "rpmbuild/SRPMS/jrubygem-gemjam-#{Gemjam::VERSION}-#{git_rev}#{@dist}.src.rpm"
18
+
19
+ task :default => :build
20
+
21
+ CLEAN.include 'pkg/'
22
+ CLEAN.include 'rpmbuild/'
23
+
24
+ desc "Build a SRPM for brew"
25
+ task :srpm => [:build] do
26
+ cmd = "rpmbuild -bs --nodeps #{@d_dist} #{@d_version} #{@d_gitrev} --define '_sourcedir ./pkg/' --define '_srcrpmdir rpmbuild/SRPMS' ./jrubygem-gemjam.spec"
27
+ puts cmd
28
+ system cmd
29
+ end
30
+
31
+
32
+ desc "Build an RPM (Optional: set 'dist' env)"
33
+ task :rpm => [:srpm] do
34
+ cmd = "rpmbuild --rebuild #{@d_dist} #{@d_version} #{@d_gitrev} --define '_rpmdir rpmbuild/RPMS' ./#{@srpmfile}"
35
+ puts cmd
36
+ system cmd
37
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "gemjam"
4
+
5
+ include Gemjam
6
+ main(ARGV)
7
+
@@ -0,0 +1,17 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/gemjam/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = ["Vincent Batts"]
6
+ gem.email = ["vbatts@redhat.com"]
7
+ gem.description = %q{Create java jar, for jRuby, from gems or a bundler Gemfile}
8
+ gem.summary = %q{Create java jar, for jRuby, from gems or a bundler Gemfile}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = "gemjam"
15
+ gem.require_paths = ["lib"]
16
+ gem.version = Gemjam::VERSION
17
+ end
@@ -0,0 +1,73 @@
1
+ %global ruby_exec jruby
2
+ %global gem_exec %{ruby_exec} -S gem
3
+
4
+ %global gemname gemjam
5
+
6
+ %global gemdir %(%{ruby_exec} -rubygems -e 'puts Gem::dir' 2>/dev/null)
7
+ %global geminstdir %{gemdir}/gems/%{gemname}-%{version}
8
+
9
+ %define rel %{?gitrev}%{!?gitrev:1}
10
+
11
+ Summary: Tool for packing rubygem dependencies, into a java jar
12
+ Name: jrubygem-%{gemname}
13
+ Version: %{?version}%{!?version:0.0.2}
14
+ Release: %{rel}%{?dist}
15
+ Group: Development/Languages
16
+ License: GPLv2+ or Ruby
17
+ URL: http://git.corp.redhat.com/cgit/dev/towers/engineering/gems/gemjam/
18
+ Source0: %{gemname}-%{version}.gem
19
+ Requires: jruby
20
+ Requires: jrubygem(bundler)
21
+ BuildRequires: jruby
22
+ BuildArch: noarch
23
+ Provides: jrubygem(%{gemname}) = %{version}
24
+
25
+ %description
26
+ %{summary}
27
+
28
+ %prep
29
+ rm -rf %{buildroot}
30
+ %setup -q -c -T
31
+ mkdir -p .%{gemdir}
32
+ %{gem_exec} install --local --install-dir .%{gemdir} \
33
+ --bindir .%{_bindir} \
34
+ --force %{SOURCE0}
35
+
36
+ %build
37
+
38
+ %install
39
+ mkdir -p %{buildroot}%{gemdir}
40
+ cp -a .%{gemdir}/* \
41
+ %{buildroot}%{gemdir}
42
+
43
+ mkdir -p %{buildroot}%{_bindir}
44
+ cp -a .%{_bindir}/* \
45
+ %{buildroot}%{_bindir}/
46
+
47
+ %clean
48
+ rm -rf %{buildroot}
49
+
50
+ %files
51
+ %dir %{geminstdir}
52
+ %{_bindir}/gemjam
53
+ %{geminstdir}/bin/gemjam
54
+ %{geminstdir}/lib
55
+ %{geminstdir}/LICENSE
56
+ %{geminstdir}/README.md
57
+ %exclude %{geminstdir}/%{name}.spec
58
+ %exclude %{geminstdir}/%{gemname}.gemspec
59
+ %exclude %{geminstdir}/Gemfile
60
+ %exclude %{geminstdir}/Rakefile
61
+ %exclude %{geminstdir}/.gitignore
62
+ %exclude %{gemdir}/cache/%{gemname}-%{version}.gem
63
+ %{gemdir}/specifications/%{gemname}-%{version}.gemspec
64
+
65
+ %changelog
66
+ * Wed Jun 24 2013 Vincent Batts - 0.0.2-1
67
+ - fail on a command failure
68
+ - `bundle` uses jruby now
69
+ - flag for quiet output
70
+ - a few comments
71
+
72
+ * Tue Jun 23 2013 Vincent Batts - 0.0.1-1
73
+ - initial package
@@ -0,0 +1,129 @@
1
+ =begin
2
+ This could just as well be a shell script ...
3
+
4
+ Create a *.jar, for jRuby, from installing gems or a bundler Gemfile
5
+
6
+ --vbatts
7
+ =end
8
+
9
+ require "gemjar/version"
10
+ require "optparse"
11
+ require "rbconfig"
12
+ require "tmpdir"
13
+ require "fileutils"
14
+
15
+ module Gemjam
16
+ def parse_args(args)
17
+ options = {
18
+ :quiet => false,
19
+ :jruby => "jruby",
20
+ :gems => [],
21
+ }
22
+ opts = OptionParser.new do |opts|
23
+ opts.banner = File.basename(__FILE__) + "[-b [Gemfile]] [-g gem[,version]]..."
24
+ opts.on("-q", "--quiet", "less output") do |o|
25
+ options[:quiet] = o
26
+ end
27
+ opts.on("-j", "--jruby CMD", "CMD to use to call jruby (Default '#{options[:jruby]}')") do |o|
28
+ options[:jruby] = o
29
+ end
30
+ opts.on("-g", "--gem GEMNAME", "GEMNAME to install. If ',<version>' is a append, it will specify that version of the gem") do |o|
31
+ options[:gems] << o
32
+ end
33
+ opts.on("-b", "--bundle [GEMFILE]", "make the gemjar from a current directory Gemfile or specified") do |o|
34
+ if o.nil? and ! FileTest.file?("Gemfile")
35
+ raise "No Gemfile present or provided"
36
+ end
37
+ options[:bundle] = if o.nil?
38
+ File.join(Dir.pwd, "Gemfile")
39
+ else
40
+ File.expand_path(o)
41
+ end
42
+ end
43
+ end.parse!(args)
44
+ return options
45
+ end
46
+
47
+ # runs +cmd+, and sets $? with that commands return value
48
+ def cmd(cmd_str, quiet = false)
49
+ p cmd_str unless quiet
50
+ IO.popen(cmd_str) do |f|
51
+ loop do
52
+ buf = f.read(1)
53
+ break if buf.nil?
54
+ unless quiet
55
+ print buf
56
+ $stdout.flush
57
+ end
58
+ end
59
+ end
60
+ end
61
+
62
+ # install rubygem +gemname+ to directory +basedir+ using jruby command +jruby+
63
+ #
64
+ # sets $? with that commands return value
65
+ def gem_install(jruby, basedir, gemname, quiet = false)
66
+ if gemname.include?(",")
67
+ g, v = gemname.split(",",2)
68
+ cmd("#{jruby} -S gem install -i #{basedir} #{g} -v=#{v}", quiet)
69
+ else
70
+ cmd("#{jruby} -S gem install -i #{basedir} #{gemname}", quiet)
71
+ end
72
+ end
73
+
74
+ # pack up the installed gems in +dirname+, to jar file +jarname+
75
+ #
76
+ # sets $? with that commands return value
77
+ def make_jar(jarname, dirname, quiet = false)
78
+ cmd("jar cf #{jarname} -C #{dirname} .", quiet)
79
+ end
80
+
81
+ # install the bundle, using jruby command +jruby+
82
+ #
83
+ # sets $? with that commands return value
84
+ def bundle_install(jruby, quiet = false)
85
+ cmd("#{jruby} -S bundle install --path ./vendor/bundle/", quiet)
86
+ end
87
+
88
+ def bundler_vendor_dir
89
+ return ["vendor","bundle",
90
+ RbConfig::CONFIG["ruby_install_name"],
91
+ RbConfig::CONFIG["ruby_version"]].join("/")
92
+
93
+ end
94
+
95
+ def main(args)
96
+ o = parse_args(args)
97
+ p o unless o[:quiet]
98
+
99
+ tmpdir = Dir.mktmpdir
100
+ begin
101
+ cwd = Dir.pwd
102
+ if o[:bundle]
103
+ FileUtils.cd tmpdir
104
+ FileUtils.cp o[:bundle], "Gemfile"
105
+ bundle_install(o[:jruby], o[:quiet])
106
+ FileUtils.cd cwd
107
+ abort("FAIL: bundler returned: #{$?}") if $? != 0
108
+ end
109
+
110
+ o[:gems].each do |gem|
111
+ gem_install(o[:jruby], File.join(tmpdir, bundler_vendor_dir), gem, o[:quiet])
112
+ abort("FAIL: gem install returned: #{$?}") if $? != 0
113
+ end
114
+
115
+ jarname = File.basename(tmpdir) + ".jar"
116
+ make_jar(jarname, File.join(tmpdir, bundler_vendor_dir), o[:quiet])
117
+ abort("FAIL: jar packaging returned: #{$?}") if $? != 0
118
+
119
+ if o[:quiet]
120
+ puts jarname
121
+ else
122
+ puts "Created #{jarname}"
123
+ end
124
+ ensure
125
+ # remove the directory.
126
+ FileUtils.remove_entry_secure(tmpdir, true)
127
+ end
128
+ end
129
+ end
@@ -0,0 +1,3 @@
1
+ module Gemjam
2
+ VERSION = "0.0.3"
3
+ end
metadata ADDED
@@ -0,0 +1,57 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gemjam
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.3
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Vincent Batts
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-25 00:00:00.000000000 Z
13
+ dependencies: []
14
+ description: Create java jar, for jRuby, from gems or a bundler Gemfile
15
+ email:
16
+ - vbatts@redhat.com
17
+ executables:
18
+ - gemjar
19
+ extensions: []
20
+ extra_rdoc_files: []
21
+ files:
22
+ - .gitignore
23
+ - Gemfile
24
+ - LICENSE
25
+ - README.md
26
+ - Rakefile
27
+ - bin/gemjar
28
+ - gemjam.gemspec
29
+ - jrubygem-gemjam.spec
30
+ - lib/gemjam.rb
31
+ - lib/gemjam/version.rb
32
+ homepage: ''
33
+ licenses: []
34
+ post_install_message:
35
+ rdoc_options: []
36
+ require_paths:
37
+ - lib
38
+ required_ruby_version: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ! '>='
42
+ - !ruby/object:Gem::Version
43
+ version: '0'
44
+ required_rubygems_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ! '>='
48
+ - !ruby/object:Gem::Version
49
+ version: '0'
50
+ requirements: []
51
+ rubyforge_project:
52
+ rubygems_version: 1.8.17
53
+ signing_key:
54
+ specification_version: 3
55
+ summary: Create java jar, for jRuby, from gems or a bundler Gemfile
56
+ test_files: []
57
+ has_rdoc: