gem_bundler 0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2010 Martin Vielsmaier
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
@@ -0,0 +1,9 @@
1
+ require 'rake'
2
+ require 'spec/rake/spectask'
3
+
4
+ desc "Run all specs"
5
+ Spec::Rake::SpecTask.new('spec') do |t|
6
+ t.spec_opts = ["--colour", "--format progress", "--loadby mtime"]
7
+ t.spec_files = FileList['spec/**/*_spec.rb']
8
+ t.libs = [File.dirname(__FILE__) + '/lib']
9
+ end
@@ -0,0 +1,30 @@
1
+ = Gem bundler
2
+ A simple lib for bundling gems into jars. This obviously is intended for use with JRuby.
3
+ Install the gem and create a rake task and a configuration file in your project:
4
+
5
+ your/config/gems.rb:
6
+ GemBundler.instance.configure do |g|
7
+ g.gem "foo_gem"
8
+ g.gem "activerecord", ">= 2.3"
9
+
10
+ g.setup "tmp/gems", "foo/lib"
11
+ end
12
+
13
+ Rake task:
14
+ require 'gem_bundler'
15
+ require 'path/to/your/config/gems.rb'
16
+
17
+ desc "Bundle gems into a JAR file"
18
+ task :bundle_gems do
19
+ GemBundler.instance.bundle
20
+ end
21
+
22
+ This will install the configured gems into "tmp/gems" (this dir will be deleted, so be cautious), move
23
+ any JAR files inside the gems to "foo/lib" and package the gems into "foo/lib/gems.jar".
24
+
25
+ In your JRuby application you should put "foo/lib" onto your $LOAD_PATH (because the moved jars from the gems
26
+ will probably be required) and require gems.jar.
27
+
28
+ See http://blog.nicksieger.com/articles/2009/01/10/jruby-1-1-6-gems-in-a-jar for details.
29
+
30
+ I use this mechanism to bundle gems to go with applications packaged using rawr[http://rawr.rubyforge.org/].
@@ -0,0 +1,59 @@
1
+ require 'rubygems'
2
+ require 'fileutils'
3
+ require 'rubygems/dependency_installer'
4
+ require 'singleton'
5
+
6
+ # :include:../Readme.rdoc
7
+ class GemBundler
8
+ include Singleton
9
+
10
+ attr_accessor :install_dir, :jar_dir, :gems
11
+
12
+ # Set the needed paths.
13
+ # - install_dir: The gems will be temporarily installed into this directory. Caution: Before installing the directory will be delete.
14
+ # - jar_dir: The directory where the JAR files will be put.
15
+ def setup(install_dir, jar_dir)
16
+ @install_dir = install_dir
17
+ @jar_dir = jar_dir
18
+ end
19
+
20
+ def configure
21
+ yield self if block_given?
22
+ end
23
+
24
+ # Adds a gem
25
+ # gem "activerecord", ">= 2.3.1"
26
+ def gem(name, version = Gem::Requirement.default)
27
+ @gems ||= {}
28
+ @gems[name] = version
29
+ end
30
+
31
+ # Checks if all required gems are installed and returns
32
+ # gems that miss.
33
+ def check_gems
34
+ @gems ||= {}
35
+ @gems.keys.select { |g| Gem.source_index.find_name(g, @gems[g]).size == 0 }
36
+ end
37
+
38
+ # Bundles the required gems into a JAR file.
39
+ # Before the gems are packed into the JAR, all JARs inside the gems are moved to the jar_dir.
40
+ def bundle
41
+ raise "Paths not given! Call setup first." if @install_dir.nil? || @jar_dir.nil?
42
+ gems_jar = File.join(jar_dir, 'gems.jar')
43
+ default_options = { :generate_rdoc => false,
44
+ :generate_ri => false,
45
+ :install_dir => install_dir }
46
+ FileUtils.rm_rf install_dir if File.exists? install_dir
47
+ FileUtils.mkdir_p install_dir
48
+ installer = Gem::DependencyInstaller.new(default_options)
49
+ @gems.each do |name, version|
50
+ puts "Installing #{name}"
51
+ installer.install(name, version || Gem::Requirement.default)
52
+ end
53
+ Dir.glob("#{install_dir}/**/*.jar").each do |jar|
54
+ FileUtils.mv jar, File.join(jar_dir, jar.split("/").last)
55
+ end
56
+ FileUtils.rm gems_jar if File.exists? gems_jar
57
+ `jar cf #{gems_jar} -C #{install_dir} .`
58
+ end
59
+ end
@@ -0,0 +1,27 @@
1
+ require 'gem_bundler'
2
+
3
+ describe "GemBundler" do
4
+ before(:all) do
5
+ GemBundler.instance.configure do |c|
6
+ c.gem "gem1"
7
+ c.gem "gem2", ">= 1.1.1"
8
+ end
9
+ end
10
+
11
+ it "should install and package the gems" do
12
+ FileUtils.rm_rf "spec/tmp" if File.exists? "spec/tmp"
13
+ FileUtils.rm_rf "spec/lib" if File.exists? "spec/lib"
14
+
15
+ FileUtils.mkdir_p "spec/lib"
16
+ GemBundler.instance.setup("spec/tmp", "spec/lib")
17
+ m = mock("DepInst")
18
+ m.stub(:install)
19
+ Gem::DependencyInstaller.should_receive(:new).and_return { FileUtils.cp_r "spec/skel", "spec/tmp"; m }
20
+ GemBundler.instance.bundle
21
+ File.exists?("spec/lib/1.jar").should be_true
22
+ File.exists?("spec/lib/gems.jar").should be_true
23
+
24
+ FileUtils.rm_rf "spec/tmp" if File.exists? "spec/tmp"
25
+ FileUtils.rm_rf "spec/lib" if File.exists? "spec/lib"
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,59 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gem_bundler
3
+ version: !ruby/object:Gem::Version
4
+ version: "0.1"
5
+ platform: ruby
6
+ authors:
7
+ - Martin Vielsmaier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2010-02-05 00:00:00 +01:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description:
17
+ email: martin.vielsmaier@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files: []
23
+
24
+ files:
25
+ - LICENSE
26
+ - Rakefile
27
+ - Readme.rdoc
28
+ - spec/gem_bundler_spec.rb
29
+ - lib/gem_bundler.rb
30
+ has_rdoc: true
31
+ homepage: http://moserei.de
32
+ licenses: []
33
+
34
+ post_install_message:
35
+ rdoc_options: []
36
+
37
+ require_paths:
38
+ - lib
39
+ required_ruby_version: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - ">="
42
+ - !ruby/object:Gem::Version
43
+ version: "0"
44
+ version:
45
+ required_rubygems_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ requirements:
52
+ - Java's jar executable on path
53
+ rubyforge_project:
54
+ rubygems_version: 1.3.5
55
+ signing_key:
56
+ specification_version: 3
57
+ summary: Bundles gems into jars.
58
+ test_files: []
59
+