redstorm 0.5.1 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -9,7 +9,7 @@ module RedStorm
9
9
  # block declaration style using auto-emit (default)
10
10
  #
11
11
  on_receive do |tuple|
12
- word = tuple.getString(0)
12
+ word = tuple.getValue(0).to_s
13
13
  @counts[word] += 1
14
14
 
15
15
  [word, @counts[word]]
data/lib/red_storm.rb CHANGED
@@ -1,42 +1,6 @@
1
- # this is the entry point for these two contexts:
2
- # - running red_storm.rake
3
- # - at remote cluster topology execution. Once topology_launcher.rb has submitted the topology
4
- # the spouts and bolts classes will be instanciated and will require red_storm.rb
5
-
6
- # we depends on rubygems begings loaded at this point for setting up gem/bundle environments
7
- # explicitely requiring rubygems is required in remote cluster environment
8
1
  require 'rubygems'
9
2
 
10
- # setup some environment constants
11
- # this is required here and in topology_launcher.rb which are both
12
- # entry points in redstorm.
13
- module RedStorm
14
- TOPOLOGY_LAUNCHED = defined?(LAUNCH_PATH)
15
-
16
- # do not redefine if already defined in topology_launcher.rb
17
- unless TOPOLOGY_LAUNCHED
18
- LAUNCH_PATH = File.expand_path(File.dirname(__FILE__))
19
- JAR_CONTEXT = !!(LAUNCH_PATH =~ /\.jar!$/)
20
-
21
- if JAR_CONTEXT
22
- BASE_PATH = LAUNCH_PATH
23
- else
24
- BASE_PATH = Dir.pwd
25
- end
26
- end
27
- end
28
-
29
- unless RedStorm::JAR_CONTEXT
30
- # in JAR context red_storm.rb and red_storm/* is in the JAR root.
31
- # otherwise this is in lib/...
32
- $:.unshift "#{RedStorm::BASE_PATH}/lib"
33
- end
34
-
35
- unless RedStorm::TOPOLOGY_LAUNCHED
36
- require 'red_storm/environment'
37
- RedStorm.setup_gems if RedStorm::JAR_CONTEXT
38
- end
39
-
3
+ require 'red_storm/environment'
40
4
  require 'red_storm/version'
41
5
  require 'red_storm/configuration'
42
6
  require 'red_storm/application'
@@ -1,31 +1,33 @@
1
1
  module RedStorm
2
-
3
- DEFAULT_RUBY_VERSION = "--1.8"
4
- RUNTIME = {}
5
2
 
6
3
  class Application
7
4
  TASKS_FILE = "#{RedStorm::REDSTORM_HOME}/lib/tasks/red_storm.rake"
8
5
 
9
6
  def usage
10
- puts("usage: redstorm [--1.8|--1.9] install | deps | build | examples | gems | bundle [--gemfile GEMFILE_PATH] | jar DIR1, DIR2, ... | local TOPOLOGY_CLASS_PATH")
7
+ puts("usage: redstorm install")
8
+ puts(" redstorm deps")
9
+ puts(" redstorm build")
10
+ puts(" redstorm examples")
11
+ puts(" redstorm bundle [BUNDLER_GROUP]")
12
+ puts(" redstorm jar DIR1, [DIR2, ...]")
13
+ puts(" redstorm local [--1.8|--1.9] TOPOLOGY_CLASS_PATH")
14
+ puts(" redstorm cluster [--1.8|--1.9] TOPOLOGY_CLASS_PATH")
11
15
  exit(1)
12
16
  end
13
17
 
14
18
  def run(args)
15
19
  if args.size > 0
16
- version = args.delete("--1.8") || args.delete("--1.9") || DEFAULT_RUBY_VERSION
17
- RUNTIME['RUBY_VERSION'] = version
18
-
19
- if ["install", "examples", "jar", "gems", "bundle", "deps", "build"].include?(args[0])
20
+ if ["install", "examples", "jar", "bundle", "deps", "build"].include?(args[0])
20
21
  load(TASKS_FILE)
21
22
  Rake::Task[args.shift].invoke(args.join(":"))
22
23
  exit
23
- elsif args.size >= 2 && args.include?("local")
24
- args.delete("local")
24
+ elsif args.size >= 2 && ["local", "cluster"].include?(args[0])
25
+ env = args.delete_at(0)
26
+ version = args.delete("--1.8") || args.delete("--1.9")
25
27
  if args.size == 1
26
28
  file = args[0]
27
29
  load(TASKS_FILE)
28
- Rake::Task['launch'].invoke("local", file)
30
+ Rake::Task['launch'].invoke(env, version, file)
29
31
  exit
30
32
  end
31
33
  end
@@ -33,4 +35,5 @@ module RedStorm
33
35
  usage
34
36
  end
35
37
  end
38
+
36
39
  end
@@ -3,12 +3,13 @@ module RedStorm
3
3
  class Configurator
4
4
  attr_reader :config
5
5
 
6
- def initialize
6
+ def initialize(defaults = {})
7
7
  @config = Backtype::Config.new
8
+ defaults.each{|attribute, value| @config.put(attribute.to_s, value)}
8
9
  end
9
10
 
10
11
  def set(attribute, value)
11
- @config.put(attribute, value)
12
+ @config.put(attribute.to_s, value)
12
13
  end
13
14
 
14
15
  def method_missing(sym, *args)
@@ -1,28 +1,38 @@
1
1
  module RedStorm
2
- # LAUNCH_PATH, BASE_PATH and JAR_CONTEXT must be set before requiring this module
3
- # typically, they must be set in either red_storm.rb and topology_launcher.rd
4
- # which are the 2 entry points
2
+
3
+ LAUNCH_PATH = File.expand_path(File.dirname(__FILE__))
4
+ JAR_CONTEXT = !!(LAUNCH_PATH =~ /\.jar!\/red_storm$/)
5
5
 
6
6
  if JAR_CONTEXT
7
- REDSTORM_HOME = LAUNCH_PATH
8
- TARGET_PATH = LAUNCH_PATH
9
- BUNDLE_GEMFILE = "#{TARGET_PATH}/bundler/Gemfile"
10
- BUNDLE_PATH = "#{TARGET_PATH}/bundler/#{Gem.ruby_engine}/#{Gem::ConfigMap[:ruby_version]}/"
7
+ BASE_PATH = File.expand_path(LAUNCH_PATH + '/..')
8
+ REDSTORM_HOME = BASE_PATH
9
+ TARGET_PATH = BASE_PATH
10
+
11
11
  GEM_PATH = "#{TARGET_PATH}/gems/"
12
+ ENV["GEM_PATH"] = GEM_PATH
12
13
  else
13
- REDSTORM_HOME = File.expand_path(LAUNCH_PATH + '/..')
14
+ BASE_PATH = Dir.pwd
15
+ REDSTORM_HOME = File.expand_path(LAUNCH_PATH + '/../..')
14
16
  TARGET_PATH = "#{BASE_PATH}/target"
15
- BUNDLE_GEMFILE = "#{TARGET_PATH}/gems/bundler/Gemfile"
16
- BUNDLE_PATH = "#{TARGET_PATH}/gems/bundler/#{Gem.ruby_engine}/#{Gem::ConfigMap[:ruby_version]}/"
17
- GEM_PATH = "#{TARGET_PATH}/gems/gems"
18
17
  end
19
18
 
20
- def setup_gems
21
- ENV['BUNDLE_GEMFILE'] = RedStorm::BUNDLE_GEMFILE
22
- ENV['BUNDLE_PATH'] = RedStorm::BUNDLE_PATH
23
- ENV["GEM_PATH"] = RedStorm::GEM_PATH
24
- ENV['BUNDLE_DISABLE_SHARED_GEMS'] = "1"
19
+ def current_ruby_mode
20
+ RUBY_VERSION =~ /(\d+\.\d+)(\.\d+)*/
21
+ raise("unknown Ruby version #{$1}") unless $1 == "1.8" || $1 == "1.9"
22
+ $1
25
23
  end
26
24
 
27
- module_function :setup_gems
25
+ def jruby_mode_token(ruby_version = nil)
26
+ version_map = {"1.8" => "RUBY1_8", "--1.8" => "RUBY1_8", "1.9" => "RUBY1_9", "--1.9" => "RUBY1_9"}
27
+ version_map[ruby_version.to_s] || version_map[RedStorm.current_ruby_mode]
28
+ end
29
+
30
+ module_function :current_ruby_mode, :jruby_mode_token
31
+
32
+ # puts("*** LAUNCH_PATH=#{LAUNCH_PATH}")
33
+ # puts("*** JAR_CONTEXT=#{JAR_CONTEXT}")
34
+ # puts("*** BASE_PATH=#{BASE_PATH}")
35
+ # puts("*** REDSTORM_HOME=#{REDSTORM_HOME}")
36
+ # puts("*** TARGET_PATH=#{TARGET_PATH}")
37
+ # puts("*** GEM_PATH=#{GEM_PATH}") if defined?(GEM_PATH)
28
38
  end
@@ -1,3 +1,4 @@
1
+ require 'java'
1
2
  require 'red_storm/configuration'
2
3
  require 'red_storm/configurator'
3
4
 
@@ -56,6 +57,8 @@ module RedStorm
56
57
  declarer.globalGrouping(source_id)
57
58
  when :shuffle
58
59
  declarer.shuffleGrouping(source_id)
60
+ when :local_or_shuffle
61
+ declarer.localOrShuffleGrouping(source_id)
59
62
  when :none
60
63
  declarer.noneGrouping(source_id)
61
64
  when :all
@@ -109,28 +112,23 @@ module RedStorm
109
112
 
110
113
  builder = TopologyBuilder.new
111
114
  self.class.spouts.each do |spout|
112
- declarer = builder.setSpout(spout.id, spout.new_instance(base_class_path), spout.parallelism)
115
+ declarer = builder.setSpout(spout.id, spout.new_instance(base_class_path), spout.parallelism.to_java)
113
116
  declarer.addConfigurations(spout.config)
114
117
  end
115
118
  self.class.bolts.each do |bolt|
116
- declarer = builder.setBolt(bolt.id, bolt.new_instance(base_class_path), bolt.parallelism)
119
+ declarer = builder.setBolt(bolt.id, bolt.new_instance(base_class_path), bolt.parallelism.to_java)
117
120
  declarer.addConfigurations(bolt.config)
118
121
  bolt.define_grouping(declarer)
119
122
  end
120
123
 
121
- configurator = Configurator.new
124
+ # set the JRuby compatibility mode option for Storm workers, default to current JRuby mode
125
+ defaults = {"topology.worker.childopts" => "-Djruby.compat.version=#{RedStorm.jruby_mode_token}"}
126
+
127
+ configurator = Configurator.new(defaults)
122
128
  configurator.instance_exec(env, &self.class.configure_block)
123
129
 
124
- case env
125
- when :local
126
- @cluster = LocalCluster.new
127
- @cluster.submitTopology(self.class.topology_name, configurator.config, builder.createTopology)
128
- when :cluster
129
- StormSubmitter.submitTopology(self.class.topology_name, configurator.config, builder.createTopology);
130
- else
131
- raise("unsupported env=#{env.inspect}, expecting :local or :cluster")
132
- end
133
-
130
+ submitter = (env == :local) ? @cluster = LocalCluster.new : StormSubmitter
131
+ submitter.submitTopology(self.class.topology_name, configurator.config, builder.createTopology)
134
132
  instance_exec(env, &self.class.submit_block)
135
133
  end
136
134
 
@@ -17,33 +17,12 @@ java_import 'redstorm.storm.jruby.JRubySpout'
17
17
 
18
18
  java_package 'redstorm'
19
19
 
20
- # setup some environment constants
21
- # this is required here and in red_storm.rb which are both
22
- # entry points in redstorm.
23
- module RedStorm
24
- LAUNCH_PATH = File.expand_path(File.dirname(__FILE__))
25
- JAR_CONTEXT = !!(LAUNCH_PATH =~ /\.jar!$/)
26
-
27
- if JAR_CONTEXT
28
- BASE_PATH = LAUNCH_PATH
29
- LIB_PATH = "#{BASE_PATH}/lib"
30
- else
31
- BASE_PATH = Dir.pwd
32
- LIB_PATH = "#{BASE_PATH}/target/lib"
33
- end
34
- end
35
-
36
20
  # TopologyLauncher is the application entry point when launching a topology. Basically it will
37
21
  # call require on the specified Ruby topology class file path and call its start method
38
22
  class TopologyLauncher
39
23
 
40
24
  java_signature 'void main(String[])'
41
25
  def self.main(args)
42
- # this is the entry point for these two contexts:
43
- # - runnig a topology in local mode. the current Ruby env will stay the same at topology execution
44
- # - submitting a topology in cluster mode. the current Ruby env will be valid only at topology submission. At topology execution
45
- # in the cluster, the new entry point will be the red_storm.rb, topology_launcher will not be called
46
-
47
26
  unless args.size > 1
48
27
  puts("Usage: redstorm local|cluster topology_class_file_name")
49
28
  exit(1)
@@ -52,11 +31,9 @@ class TopologyLauncher
52
31
  env = args[0].to_sym
53
32
  class_path = args[1]
54
33
 
55
- $:.unshift "#{RedStorm::BASE_PATH}"
56
- $:.unshift "#{RedStorm::LIB_PATH}"
57
-
58
- require 'red_storm/environment'
59
- RedStorm.setup_gems
34
+ launch_path = Dir.pwd
35
+ $:.unshift File.expand_path(launch_path)
36
+ $:.unshift File.expand_path(launch_path + '/lib')
60
37
 
61
38
  require "#{class_path}"
62
39
 
@@ -1,3 +1,3 @@
1
1
  module RedStorm
2
- VERSION = '0.5.1'
2
+ VERSION = '0.6.0'
3
3
  end
@@ -1,28 +1,20 @@
1
1
  require 'ant'
2
+ require 'jruby/jrubyc'
3
+ require 'pompompom'
2
4
  require 'red_storm'
3
-
4
- # begin
5
- # # will work from gem, since lib dir is in gem require_paths
6
- # require 'red_storm'
7
- # rescue LoadError
8
- # # will work within RedStorm dev project
9
- # $:.unshift './lib'
10
- # require 'red_storm'
11
- # end
12
5
 
13
- INSTALL_STORM_VERSION = "0.7.1"
14
- INSTALL_JRUBY_VERSION = "1.6.7"
15
- DEFAULT_GEMFILE = "Gemfile"
6
+ INSTALL_STORM_VERSION = "0.7.3"
7
+ INSTALL_JRUBY_VERSION = "1.6.7.2"
16
8
 
17
9
  CWD = Dir.pwd
18
10
  TARGET_DIR = "#{CWD}/target"
19
11
  TARGET_LIB_DIR = "#{TARGET_DIR}/lib"
20
12
  TARGET_SRC_DIR = "#{TARGET_DIR}/src"
13
+ TARGET_GEM_DIR = "#{TARGET_DIR}/gems/gems"
14
+ TARGET_SPECS_DIR = "#{TARGET_DIR}/gems/specifications"
21
15
  TARGET_CLASSES_DIR = "#{TARGET_DIR}/classes"
22
16
  TARGET_DEPENDENCY_DIR = "#{TARGET_DIR}/dependency"
23
17
  TARGET_DEPENDENCY_UNPACKED_DIR = "#{TARGET_DIR}/dependency-unpacked"
24
- TARGET_MARKERS_DIR = "#{TARGET_DIR}/dependency-markers"
25
- TARGET_GEMS_DIR = "#{TARGET_DIR}/gems"
26
18
  TARGET_CLUSTER_JAR = "#{TARGET_DIR}/cluster-topology.jar"
27
19
 
28
20
  REDSTORM_JAVA_SRC_DIR = "#{RedStorm::REDSTORM_HOME}/src/main"
@@ -31,13 +23,29 @@ REDSTORM_LIB_DIR = "#{RedStorm::REDSTORM_HOME}/lib"
31
23
  SRC_EXAMPLES = "#{RedStorm::REDSTORM_HOME}/examples"
32
24
  DST_EXAMPLES = "#{CWD}/examples"
33
25
 
34
- task :launch, :env, :class_file do |t, args|
35
- version_token = RedStorm::RUNTIME['RUBY_VERSION'] == "--1.9" ? "RUBY1_9" : "RUBY1_8"
36
- # gem_home = ENV["GEM_HOME"].to_s.empty? ? " -Djruby.gem.home=`gem env home`" : ""
37
- gem_home = " -Djruby.gem.home=#{RedStorm::GEM_PATH}"
38
- command = "java -Djruby.compat.version=#{version_token} -cp \"#{TARGET_CLASSES_DIR}:#{TARGET_DEPENDENCY_DIR}/*\"#{gem_home} redstorm.TopologyLauncher #{args[:env]} #{args[:class_file]}"
26
+ module JavaZip
27
+ import 'java.util.zip.ZipFile'
28
+ end
29
+
30
+ task :launch, :env, :ruby_mode, :class_file do |t, args|
31
+ # use ruby mode parameter or default to current interpreter version
32
+ version_token = RedStorm.jruby_mode_token(args[:ruby_mode])
33
+
34
+ command = case args[:env]
35
+ when "local"
36
+ "java -Djruby.compat.version=#{version_token} -cp \"#{TARGET_CLASSES_DIR}:#{TARGET_DEPENDENCY_DIR}/*\" redstorm.TopologyLauncher local #{args[:class_file]}"
37
+ when "cluster"
38
+ unless File.exist?(TARGET_CLUSTER_JAR)
39
+ puts("cluster jar file #{TARGET_CLUSTER_JAR} not found. Generate it using $redstorm jar DIR1 [DIR2, ...]")
40
+ exit(1)
41
+ end
42
+ "storm jar #{TARGET_CLUSTER_JAR} -Djruby.compat.version=#{version_token} redstorm.TopologyLauncher cluster #{args[:class_file]}"
43
+ end
44
+
39
45
  puts("launching #{command}")
40
- system(command)
46
+ unless system(command)
47
+ puts($!)
48
+ end
41
49
  end
42
50
 
43
51
  task :clean do
@@ -52,45 +60,53 @@ task :setup do
52
60
  puts("\n--> Setting up target directories")
53
61
  ant.mkdir :dir => TARGET_DIR
54
62
  ant.mkdir :dir => TARGET_CLASSES_DIR
63
+ ant.mkdir :dir => TARGET_DEPENDENCY_DIR
55
64
  ant.mkdir :dir => TARGET_SRC_DIR
56
- ant.mkdir :dir => TARGET_GEMS_DIR
57
- ant.mkdir :dir => "#{TARGET_GEMS_DIR}/gems"
58
- ant.mkdir :dir => "#{TARGET_GEMS_DIR}/bundler"
65
+ ant.mkdir :dir => TARGET_GEM_DIR
66
+ ant.mkdir :dir => TARGET_SPECS_DIR
59
67
  ant.path :id => 'classpath' do
60
68
  fileset :dir => TARGET_DEPENDENCY_DIR
61
69
  fileset :dir => TARGET_CLASSES_DIR
62
70
  end
63
71
  end
64
72
 
65
- task :install => [:deps, :build, :gems] do
73
+ task :install => [:deps, :build] do
66
74
  puts("\nRedStorm install completed. All dependencies installed in #{TARGET_DIR}")
67
75
  end
68
76
 
69
77
  task :unpack do
70
- system("rmvn dependency:unpack " + \
71
- "-f #{RedStorm::REDSTORM_HOME}/pom.xml " + \
72
- "-DoutputDirectory=#{TARGET_DEPENDENCY_UNPACKED_DIR} " + \
73
- "-DmarkersDirectory=#{TARGET_MARKERS_DIR} " + \
74
- "-Dstorm-storm.version=#{INSTALL_STORM_VERSION} " + \
75
- "-Dorg.jruby-jruby-complete.version=#{INSTALL_JRUBY_VERSION}")
78
+ unpack_artifacts = %w[jruby-complete]
79
+ unpack_glob = "#{TARGET_DEPENDENCY_DIR}/{#{unpack_artifacts.join(',')}}-*-jar.jar"
80
+ Dir[unpack_glob].each do |jar|
81
+ puts("Extracting #{jar}")
82
+ zf = JavaZip::ZipFile.new(jar)
83
+ zf.entries.each do |entry|
84
+ next if entry.directory?
85
+ destination = "#{TARGET_DEPENDENCY_UNPACKED_DIR}/#{entry.name}"
86
+ in_io = zf.get_input_stream(entry).to_io
87
+ FileUtils.mkdir_p(File.dirname(destination))
88
+ File.open(destination, 'w') { |out_io| out_io.write(in_io.read) }
89
+ end
90
+ end
76
91
  end
77
92
 
78
93
  task :jar, [:include_dir] => [:unpack, :clean_jar] do |t, args|
79
94
  puts("\n--> Generating JAR file #{TARGET_CLUSTER_JAR}")
80
95
  ant.jar :destfile => TARGET_CLUSTER_JAR do
81
- fileset :dir => TARGET_CLASSES_DIR
82
96
  fileset :dir => TARGET_DEPENDENCY_UNPACKED_DIR
83
- fileset :dir => TARGET_GEMS_DIR do
84
- # remove bundler config dir to avoid setting BUNDLE_PATH
85
- exclude :name => "bundler/.bundle/**"
97
+ fileset :dir => TARGET_DIR do
98
+ include :name => "gems/**"
86
99
  end
100
+ fileset :dir => TARGET_CLASSES_DIR
87
101
  # red_storm.rb and red_storm/* must be in root of jar so that "require 'red_storm'"
88
102
  # in bolts/spouts works in jar context
89
103
  fileset :dir => TARGET_LIB_DIR do
90
104
  exclude :name => "tasks/**"
91
105
  end
92
- fileset :dir => CWD do
93
- args[:include_dir].split(":").each{|dir| include :name => "#{dir}/**/*"}
106
+ if args[:include_dir]
107
+ fileset :dir => CWD do
108
+ args[:include_dir].split(":").each{|dir| include :name => "#{dir}/**/*"}
109
+ end
94
110
  end
95
111
  manifest do
96
112
  attribute :name => "Main-Class", :value => "redstorm.TopologyLauncher"
@@ -110,25 +126,33 @@ task :examples do
110
126
  end
111
127
 
112
128
  puts("\n--> Installing examples into #{DST_EXAMPLES}")
113
- system("mkdir #{DST_EXAMPLES}")
114
- system("cp -r #{SRC_EXAMPLES}/* #{DST_EXAMPLES}")
129
+ FileUtils.mkdir(DST_EXAMPLES)
130
+ FileUtils.cp_r(Dir["#{SRC_EXAMPLES}/*"], DST_EXAMPLES)
131
+ end
132
+
133
+ task :copy_red_storm do
134
+ FileUtils.cp_r(REDSTORM_LIB_DIR, TARGET_DIR)
115
135
  end
116
136
 
117
137
  task :deps => :setup do
118
138
  puts("\n--> Installing dependencies")
119
- # install maven dependencies in target
120
- system("rmvn dependency:copy-dependencies " + \
121
- "-f #{RedStorm::REDSTORM_HOME}/pom.xml " + \
122
- "-DoutputDirectory=#{TARGET_DEPENDENCY_DIR} " + \
123
- "-DmarkersDirectory=#{TARGET_MARKERS_DIR} " + \
124
- "-Dstorm-storm.version=#{INSTALL_STORM_VERSION} " + \
125
- "-Dorg.jruby-jruby-complete.version=#{INSTALL_JRUBY_VERSION}")
126
-
127
- # copy RedStorm lib dir in target
128
- system("cp -r #{REDSTORM_LIB_DIR} #{TARGET_DIR}")
139
+
140
+ configuration = {
141
+ :repositories => {:clojars => 'http://clojars.org/repo/', :sonatype => "http://oss.sonatype.org/content/groups/public/"},
142
+ :dependencies => [
143
+ "storm:storm:#{INSTALL_STORM_VERSION}|type_filter=jar",
144
+ "org.slf4j:slf4j-api:1.5.8|type_filter=jar",
145
+ "org.slf4j:slf4j-log4j12:1.5.8|type_filter=jar",
146
+ "org.jruby:jruby-complete:#{INSTALL_JRUBY_VERSION}|transitive=false,type_filter=jar",
147
+ ],
148
+ :destination => TARGET_DEPENDENCY_DIR
149
+ }
150
+
151
+ installer = PomPomPom::Runner.new(configuration)
152
+ installer.run
129
153
  end
130
154
 
131
- task :build => :setup do
155
+ task :build => [:setup, :copy_red_storm] do
132
156
  # compile the JRuby proxy classes to Java
133
157
  build_jruby("#{REDSTORM_LIB_DIR}/red_storm/proxy")
134
158
 
@@ -145,46 +169,26 @@ task :build => :setup do
145
169
  build_java_dir("#{TARGET_SRC_DIR}")
146
170
  end
147
171
 
148
- task :bundle, [:bundler_options] => :gems do |t, args|
149
- bundler_options = args[:bundler_options].to_s.split(":").join(" ")
150
-
151
- gemfile = ""
152
- if bundler_options.split(" ").size == 1
153
- gemfile = bundler_options
154
- bundler_options = ""
155
- else
156
- gemfile = (bundler_options =~ /--gemfile\s+([^\s]+)/) ? $1 : DEFAULT_GEMFILE
157
- end
158
-
159
- if bundler_options =~ /--gemfile\s+[^\s]+/
160
- bundler_options.gsub!(/--gemfile\s+[^\s]+/, "--gemfile ./Gemfile ")
161
- else
162
- bundler_options = bundler_options + " --gemfile ./Gemfile"
163
- end
164
- bundler_options = bundler_options + " --path ./"
165
-
166
- if File.exist?(gemfile)
167
- puts("\n--> Bundling gems in #{TARGET_GEMS_DIR}/bundler using #{gemfile}")
168
- system("cp #{gemfile} #{TARGET_GEMS_DIR}/bundler/Gemfile")
169
- cmd = "(cd #{TARGET_GEMS_DIR}/bundler; " + \
170
- "unset BUNDLE_GEMFILE; " + \
171
- "unset BUNDLE_PATH; " + \
172
- "unset RUBYOPT; " + \
173
- "export GEM_PATH=#{RedStorm::GEM_PATH}; " + \
174
- "export GEM_HOME=#{RedStorm::GEM_PATH}; " + \
175
- "jruby #{RedStorm::RUNTIME['RUBY_VERSION']} -S bundle install #{bundler_options})"
176
- system(cmd)
177
- elsif gemfile != DEFAULT_GEMFILE
178
- puts("WARNING: #{gemfile} not found, cannot bundle gems")
172
+ task :bundle, [:groups] => :setup do |t, args|
173
+ require 'bundler'
174
+ args.with_defaults(:groups => 'default')
175
+ groups = args[:groups].split(':').map(&:to_sym)
176
+ Bundler.definition.specs_for(groups).each do |spec|
177
+ unless spec.full_name =~ /^bundler-\d+/
178
+ destination_path = "#{TARGET_GEM_DIR}/#{spec.full_name}"
179
+ unless File.directory?(destination_path)
180
+ puts("installing gem #{spec.full_name} into #{destination_path}")
181
+ # copy the actual gem dir
182
+ FileUtils.cp_r(spec.full_gem_path, destination_path)
183
+ # copy the gemspec into the specifications/ dir
184
+ FileUtils.cp_r(spec.loaded_from, TARGET_SPECS_DIR)
185
+ # strip the .git directory from git dependencies, it can be huge
186
+ FileUtils.rm_rf("#{destination_path}/.git")
187
+ end
188
+ end
179
189
  end
180
190
  end
181
191
 
182
- task :gems => :setup do
183
- puts("\n--> Installing base gems in #{TARGET_GEMS_DIR}/gems")
184
- system("gem install bundler --install-dir #{TARGET_GEMS_DIR}/gems --no-ri --no-rdoc --quiet --no-verbose")
185
- system("gem install rake --install-dir #{TARGET_GEMS_DIR}/gems --no-ri --no-rdoc --quiet --no-verbose")
186
- end
187
-
188
192
  def build_java_dir(source_folder)
189
193
  puts("\n--> Compiling Java")
190
194
  ant.javac(
@@ -204,5 +208,14 @@ end
204
208
 
205
209
  def build_jruby(source_path)
206
210
  puts("\n--> Compiling JRuby")
207
- system("cd #{RedStorm::REDSTORM_HOME}; jrubyc -t #{TARGET_SRC_DIR} --verbose --java -c \"#{TARGET_DEPENDENCY_DIR}/storm-#{INSTALL_STORM_VERSION}.jar\" -c \"#{TARGET_CLASSES_DIR}\" #{source_path}")
211
+ Dir.chdir(RedStorm::REDSTORM_HOME) do
212
+ argv = []
213
+ argv << '-t' << TARGET_SRC_DIR
214
+ argv << '--verbose'
215
+ argv << '--java'
216
+ argv << '-c' << %("#{TARGET_DEPENDENCY_DIR}/storm-#{INSTALL_STORM_VERSION}.jar")
217
+ argv << '-c' << %("#{TARGET_CLASSES_DIR}")
218
+ argv << source_path
219
+ status = JRuby::Compiler::compile_argv(argv)
220
+ end
208
221
  end