puck 1.0.0.pre3 → 1.0.0.pre4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 432986a4cfe6119ebfc1f5b8c9edb661391c4d3f
4
- data.tar.gz: 13ff7d59ffc31670bab672f4e53049c72e4a73c1
3
+ metadata.gz: 3a3b334379dcfae40844e870c93ce61732db4d84
4
+ data.tar.gz: acb8397baabc28a89948612c4ed1d40828eee215
5
5
  SHA512:
6
- metadata.gz: a4f379593f83a960811fed5754fc009eeb122945cd8a68e3d2feabd6a46a5669afc2fe21519de2c8c9908a979df9524521db67b018afe06fa202f666ef2bd342
7
- data.tar.gz: fbf8b392a18397da8c9db81b5e7af6665c314910fa8b306ccf5da3be9081fdc365a84b2b34dc0825a2d616f912451c532615bc4139f514a67d9ac2e0a78de02c
6
+ metadata.gz: a45da0b368ade1e40e679041958dc041a75bff04b4ac6432457952d943ce0979bed946a347ebfeb58a0f062b38e1868158ced1a09635b3c90f19fb528d22aff8
7
+ data.tar.gz: 509bd3b10056e731e9ee5c09d0d3903b2a57c7de9df696fdb06caa393d7b22cc6022b4dcf426d4f92b04535a63819f0920f8c9ed47ce39156d83aadb7fb8ec3a
@@ -6,4 +6,5 @@ module Puck
6
6
  end
7
7
 
8
8
  require 'puck/configuration'
9
+ require 'puck/dependency_resolver'
9
10
  require 'puck/jar'
@@ -3,6 +3,7 @@ if ARGV.any?
3
3
  PUCK_BIN_PATH.each do |dir|
4
4
  path = __FILE__.sub('jar-bootstrap.rb', File.join(dir, file_name))
5
5
  if File.exists?(path)
6
+ $0 = path
6
7
  load(path)
7
8
  return
8
9
  end
@@ -0,0 +1,75 @@
1
+
2
+ require 'bundler'
3
+
4
+ module Puck
5
+ class DependencyResolver
6
+ def resolve_gem_dependencies(options = {})
7
+ gem_home = options[:gem_home] || ENV['GEM_HOME']
8
+ gemfile = options[:gemfile] || File.expand_path('Gemfile', options[:app_dir] || Dir.pwd)
9
+ lockfile = options[:lockfile] || "#{gemfile}.lock"
10
+ groups = options[:gem_groups] || [:default]
11
+
12
+ bundler_specs = contained_bundler(gem_home, gemfile, lockfile, groups)
13
+ bundler_specs.delete_if { |spec| spec[:name] == 'bundler' }
14
+ bundler_specs.map do |spec|
15
+ base_path = spec[:full_gem_path].chomp('/')
16
+ load_paths = spec[:load_paths].map do |load_path|
17
+ unless load_path.start_with?(base_path)
18
+ raise PuckError, 'Unsupported load path "%s" in gem "%s"' % [load_path, bundler_spec.name]
19
+ end
20
+ load_path[base_path.size + 1, load_path.length - base_path.size - 1]
21
+ end
22
+ {
23
+ :name => spec[:name],
24
+ :versioned_name => spec[:full_name],
25
+ :base_path => base_path,
26
+ :load_paths => load_paths,
27
+ :bin_path => spec[:bindir],
28
+ }
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def contained_bundler(gem_home, gemfile, lockfile, groups)
35
+ Bundler.with_clean_env do
36
+ scripting_container = Java::OrgJrubyEmbed::ScriptingContainer.new(Java::OrgJrubyEmbed::LocalContextScope::SINGLETHREAD)
37
+ scripting_container.compat_version = Java::OrgJruby::CompatVersion::RUBY1_9
38
+ scripting_container.current_directory = Dir.pwd
39
+ scripting_container.environment = Hash[ENV.merge('GEM_HOME' => gem_home).map { |k,v| [k.to_java, v.to_java] }]
40
+ scripting_container.put('arguments', Marshal.dump([gemfile, lockfile, groups]).to_java_bytes)
41
+ begin
42
+ line = __LINE__ + 1 # as __LINE__ represents next statement line i JRuby, and that becomes difficult to offset
43
+ unit = scripting_container.parse(StringIO.new(<<-"EOS").to_inputstream, __FILE__, line)
44
+ require 'stringio'
45
+ begin
46
+ require 'bundler'
47
+ gemfile, lockfile, groups = Marshal.load(String.from_java_bytes(arguments))
48
+ definition = Bundler::Definition.build(gemfile, lockfile, false)
49
+ ENV['BUNDLE_WITHOUT'] = (definition.groups - groups).join(':')
50
+ specs = definition.specs.map do |gem_spec|
51
+ {
52
+ :name => gem_spec.name,
53
+ :full_name => gem_spec.full_name,
54
+ :full_gem_path => gem_spec.full_gem_path,
55
+ :load_paths => gem_spec.load_paths,
56
+ :bindir => gem_spec.bindir,
57
+ }
58
+ end
59
+ Marshal.dump([specs]).to_java_bytes
60
+ rescue => e
61
+ Marshal.dump([nil, e.class, e.message, e.backtrace]).to_java_bytes
62
+ end
63
+ EOS
64
+ result, error, message, backtrace = Marshal.load(String.from_java_bytes(unit.run))
65
+ if error
66
+ raise error, message, Array(backtrace)+caller
67
+ end
68
+ result
69
+ ensure
70
+ scripting_container.terminate
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end
@@ -5,7 +5,6 @@ require 'tmpdir'
5
5
  require 'pathname'
6
6
  require 'set'
7
7
  require 'ant'
8
- require 'bundler'
9
8
  require 'puck/version'
10
9
 
11
10
  begin
@@ -74,6 +73,7 @@ module Puck
74
73
  @configuration[:build_dir] ||= File.join(@configuration[:app_dir], 'build')
75
74
  @configuration[:jar_name] ||= @configuration[:app_name] + '.jar'
76
75
  @configuration[:gem_groups] ||= [:default]
76
+ @dependency_resolver = @configuration[:dependency_resolver] || DependencyResolver.new
77
77
  end
78
78
 
79
79
  # Create the Jar file using the instance's configuration.
@@ -83,7 +83,7 @@ module Puck
83
83
 
84
84
  Dir.mktmpdir do |tmp_dir|
85
85
  output_path = File.join(@configuration[:build_dir], @configuration[:jar_name])
86
- project_dir = Pathname.new(@configuration[:app_dir])
86
+ project_dir = Pathname.new(@configuration[:app_dir]).expand_path.cleanpath
87
87
  extra_files = @configuration[:extra_files] || []
88
88
  jruby_complete_path = @configuration[:jruby_complete]
89
89
 
@@ -91,7 +91,7 @@ module Puck
91
91
  raise PuckError, 'Cannot build Jar: jruby-jars must be installed, or :jruby_complete must be specified'
92
92
  end
93
93
 
94
- gem_dependencies = resolve_gem_dependencies
94
+ gem_dependencies = @dependency_resolver.resolve_gem_dependencies(@configuration)
95
95
  create_jar_bootstrap!(tmp_dir, gem_dependencies)
96
96
 
97
97
  ant = Ant.new(output_level: 1)
@@ -121,7 +121,10 @@ module Puck
121
121
  end
122
122
 
123
123
  gem_dependencies.each do |spec|
124
- zipfileset dir: spec[:base_path], prefix: spec[:jar_path]
124
+ base_path = Pathname.new(spec[:base_path]).expand_path.cleanpath
125
+ unless project_dir == base_path
126
+ zipfileset dir: spec[:base_path], prefix: File.join(JAR_GEM_HOME, spec[:versioned_name])
127
+ end
125
128
  end
126
129
  end
127
130
  end
@@ -133,60 +136,16 @@ module Puck
133
136
  JAR_GEM_HOME = 'META-INF/gem.home'.freeze
134
137
  JAR_JRUBY_HOME = 'META-INF/jruby.home'.freeze
135
138
 
136
- def resolve_gem_dependencies
137
- gem_specs = Bundler::LockfileParser.new(File.read('Gemfile.lock')).specs.group_by(&:name)
138
- definition = Bundler::Definition.build('Gemfile', 'Gemfile.lock', false)
139
- dependencies = definition.dependencies.select { |d| (d.groups & @configuration[:gem_groups]).any? }.map(&:name)
140
- specs = resolve_gem_specs(gem_specs, dependencies)
141
- specs = specs.map do |bundler_spec|
142
- case bundler_spec.source
143
- when Bundler::Source::Git
144
- gemspec_path = File.join(ENV['GEM_HOME'], 'bundler', 'gems', "#{bundler_spec.source.extension_dir_name}", "#{bundler_spec.name}.gemspec")
145
- base_path = File.dirname(gemspec_path)
146
- else
147
- gemspec_path = File.join(ENV['GEM_HOME'], 'specifications', "#{bundler_spec.full_name}.gemspec")
148
- base_path = File.join(ENV['GEM_HOME'], 'gems', bundler_spec.full_name)
149
- end
150
- if File.exists?(gemspec_path)
151
- gem_spec = Gem::Specification.load(gemspec_path)
152
- load_paths = gem_spec.load_paths.map do |load_path|
153
- index = load_path.index(gem_spec.full_name)
154
- File.join(JAR_GEM_HOME, load_path[index, load_path.length - index])
155
- end
156
- bin_path = File.join(JAR_GEM_HOME, gem_spec.full_name, gem_spec.bindir)
157
- {
158
- :name => gem_spec.name,
159
- :versioned_name => gem_spec.full_name,
160
- :base_path => base_path,
161
- :jar_path => File.join(JAR_GEM_HOME, gem_spec.full_name),
162
- :load_paths => load_paths,
163
- :bin_path => bin_path,
164
- }
165
- else
166
- raise GemNotFoundError, "Could not package #{bundler_spec.name} because no gemspec could be found at #{gemspec_path}."
167
- end
168
- end
169
- specs.uniq { |s| s[:versioned_name] }
170
- end
171
-
172
- def resolve_gem_specs(gem_specs, gem_names)
173
- gem_names.flat_map do |name|
174
- gem_specs[name].flat_map do |spec|
175
- [spec, *resolve_gem_specs(gem_specs, spec.dependencies.map(&:name))]
176
- end
177
- end
178
- end
179
-
180
139
  def create_jar_bootstrap!(tmp_dir, gem_dependencies)
181
140
  File.open(File.join(tmp_dir, 'jar-bootstrap.rb'), 'w') do |io|
182
141
  io.puts(%(PUCK_BIN_PATH = ['/#{JAR_APP_HOME}/bin', '/#{JAR_JRUBY_HOME}/bin']))
183
142
  gem_dependencies.each do |spec|
184
- io.puts("PUCK_BIN_PATH << '/#{spec[:bin_path]}'")
143
+ io.puts("PUCK_BIN_PATH << '/#{JAR_GEM_HOME}/#{spec[:versioned_name]}/#{spec[:bin_path]}'")
185
144
  end
186
145
  io.puts
187
146
  gem_dependencies.each do |spec|
188
147
  spec[:load_paths].each do |load_path|
189
- io.puts(%($LOAD_PATH << 'classpath:#{load_path}'))
148
+ io.puts(%($LOAD_PATH << 'classpath:#{JAR_GEM_HOME}/#{spec[:versioned_name]}/#{load_path}'))
190
149
  end
191
150
  end
192
151
  io.puts
@@ -1,5 +1,5 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Puck
4
- VERSION = '1.0.0.pre3'.freeze
4
+ VERSION = '1.0.0.pre4'.freeze
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: puck
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.pre3
4
+ version: 1.0.0.pre4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Theo Hultberg
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-27 00:00:00.000000000 Z
11
+ date: 2015-01-28 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: Puck takes your app and packs it along with all your gems and a complete JRuby runtime in a standalone Jar file that can be run with just `java -jar …`
14
14
  email:
@@ -22,6 +22,7 @@ files:
22
22
  - lib/puck.rb
23
23
  - lib/puck/bootstrap.rb
24
24
  - lib/puck/configuration.rb
25
+ - lib/puck/dependency_resolver.rb
25
26
  - lib/puck/jar.rb
26
27
  - lib/puck/version.rb
27
28
  homepage: http://github.com/iconara/puck