puck 1.0.0.pre0

Sign up to get free protection for your applications and to get access to all the features.
data/bin/puck ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $: << File.expand_path('../../lib', __FILE__)
4
+
5
+ require 'puck'
6
+
7
+
8
+ Puck::Jar.new(Puck::Configuration.get).create!
data/lib/puck.rb ADDED
@@ -0,0 +1,8 @@
1
+ # encoding: utf-8
2
+
3
+ module Puck
4
+ PuckError = Class.new(StandardError)
5
+ end
6
+
7
+ require 'puck/configuration'
8
+ require 'puck/jar'
@@ -0,0 +1,10 @@
1
+ if ARGV.any?
2
+ file_name = ARGV.shift
3
+ bootstrap_path = __FILE__.sub('jar-bootstrap.rb', "META-INF/app.home/bin/#{file_name}")
4
+ begin
5
+ load(bootstrap_path)
6
+ rescue LoadError => e
7
+ abort(e.message)
8
+ end
9
+ end
10
+
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ require 'optparse'
4
+
5
+
6
+ module Puck
7
+ class Configuration
8
+ def initialize(defaults={})
9
+ @argv = defaults[:argv] || ARGV
10
+ end
11
+
12
+ def self.get(defaults={})
13
+ new(defaults).get
14
+ end
15
+
16
+ def get
17
+ command_line_options
18
+ end
19
+
20
+ private
21
+
22
+ def command_line_options
23
+ options = {}
24
+
25
+ state = nil
26
+
27
+ until @argv.empty?
28
+ arg = @argv.shift
29
+ case arg
30
+ when '--extra-files'
31
+ state = :extra_files
32
+ options[:extra_files] ||= []
33
+ else
34
+ case state
35
+ when :extra_files
36
+ options[:extra_files] << arg
37
+ end
38
+ end
39
+ end
40
+
41
+ options
42
+ end
43
+ end
44
+ end
data/lib/puck/jar.rb ADDED
@@ -0,0 +1,117 @@
1
+ # encoding: utf-8
2
+
3
+ require 'fileutils'
4
+ require 'tmpdir'
5
+ require 'pathname'
6
+ require 'set'
7
+ require 'ant'
8
+ require 'bundler'
9
+ require 'jruby-jars'
10
+ require 'puck/version'
11
+
12
+
13
+ module Puck
14
+ class Jar
15
+ def initialize(configuration={})
16
+ @configuration = configuration.dup
17
+ @configuration[:base_dir] ||= Dir.pwd
18
+ @configuration[:project_name] ||= File.basename(@configuration[:base_dir])
19
+ @configuration[:build_dir] ||= File.join(@configuration[:base_dir], 'build')
20
+ @configuration[:jar_name] ||= @configuration[:project_name] + '.jar'
21
+ end
22
+
23
+ def create!
24
+ FileUtils.mkdir_p(@configuration[:build_dir])
25
+
26
+ Dir.mktmpdir do |tmp_dir|
27
+ output_path = File.join(@configuration[:build_dir], @configuration[:jar_name])
28
+ project_dir = Pathname.new(@configuration[:base_dir])
29
+ extra_files = @configuration[:extra_files] || []
30
+ gem_dependencies = resolve_gem_dependencies
31
+ create_jar_bootstrap!(tmp_dir, gem_dependencies)
32
+
33
+ ant = Ant.new(output_level: 1)
34
+ ant.jar(destfile: output_path) do
35
+ manifest do
36
+ attribute name: 'Main-Class', value: 'org.jruby.JarBootstrapMain'
37
+ attribute name: 'Created-By', value: "Puck v#{Puck::VERSION}"
38
+ end
39
+
40
+ zipfileset dir: tmp_dir, includes: 'jar-bootstrap.rb'
41
+ zipfileset src: JRubyJars.core_jar_path
42
+ zipfileset src: JRubyJars.stdlib_jar_path
43
+
44
+ %w[bin lib].each do |sub_dir|
45
+ zipfileset dir: project_dir + sub_dir, prefix: "META-INF/app.home/#{sub_dir}"
46
+ end
47
+
48
+ extra_files.each do |ef|
49
+ path = Pathname.new(ef).expand_path.cleanpath
50
+ prefix = 'META-INF/app.home/' + path.relative_path_from(project_dir).dirname.to_s
51
+ zipfileset dir: path.dirname, prefix: prefix, includes: path.basename
52
+ end
53
+
54
+ gem_dependencies.each do |spec|
55
+ zipfileset dir: spec[:base_path], prefix: spec[:jar_path]
56
+ end
57
+ end
58
+ end
59
+ end
60
+
61
+ def resolve_gem_dependencies
62
+ gem_specs = Bundler::LockfileParser.new(File.read('Gemfile.lock')).specs.group_by(&:name)
63
+ definition = Bundler::Definition.build('Gemfile', 'Gemfile.lock', false)
64
+ dependencies = definition.dependencies.select { |d| d.groups.include?(:default) }.map(&:name)
65
+ specs = resolve_gem_specs(gem_specs, dependencies)
66
+ specs = specs.map do |bundler_spec|
67
+ case bundler_spec.source
68
+ when Bundler::Source::Git
69
+ revision = bundler_spec.source.options['revision']
70
+ gemspec_path = File.join(ENV['GEM_HOME'], 'bundler', 'gems', "#{bundler_spec.name}-#{revision[0, 12]}", "#{bundler_spec.name}.gemspec")
71
+ base_path = File.dirname(gemspec_path)
72
+ else
73
+ platform_ext = bundler_spec.platform == 'ruby' ? '' : "-#{bundler_spec.platform}"
74
+ gemspec_path = File.join(ENV['GEM_HOME'], 'specifications', "#{bundler_spec.full_name}#{platform_ext}.gemspec")
75
+ base_path = File.join(ENV['GEM_HOME'], 'gems', bundler_spec.full_name)
76
+ end
77
+ if File.exists?(gemspec_path)
78
+ gem_spec = Gem::Specification.load(gemspec_path)
79
+ load_paths = gem_spec.load_paths.map do |load_path|
80
+ index = load_path.index(gem_spec.full_name)
81
+ 'META-INF/gem.home/' + load_path[index, load_path.length - index]
82
+ end
83
+ {
84
+ :name => gem_spec.name,
85
+ :versioned_name => gem_spec.full_name,
86
+ :base_path => base_path,
87
+ :jar_path => "META-INF/gem.home/#{gem_spec.full_name}",
88
+ :load_paths => load_paths
89
+ }
90
+ else
91
+ nil
92
+ end
93
+ end
94
+ specs.compact.uniq { |s| s[:versioned_name] }
95
+ end
96
+
97
+ def resolve_gem_specs(gem_specs, gem_names)
98
+ gem_names.flat_map do |name|
99
+ gem_specs[name].flat_map do |spec|
100
+ [spec, *resolve_gem_specs(gem_specs, spec.dependencies.map(&:name))]
101
+ end
102
+ end
103
+ end
104
+
105
+ def create_jar_bootstrap!(tmp_dir, gem_dependencies)
106
+ File.open(File.join(tmp_dir, 'jar-bootstrap.rb'), 'w') do |io|
107
+ gem_dependencies.each do |spec|
108
+ spec[:load_paths].each do |load_path|
109
+ io.puts(%($LOAD_PATH << 'classpath:#{load_path}'))
110
+ end
111
+ end
112
+ io.puts
113
+ io.puts(File.read(File.expand_path('../bootstrap.rb', __FILE__)))
114
+ end
115
+ end
116
+ end
117
+ end
@@ -0,0 +1,5 @@
1
+ # encoding: utf-8
2
+
3
+ module Puck
4
+ VERSION = '1.0.0.pre0'.freeze
5
+ end
metadata ADDED
@@ -0,0 +1,69 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: puck
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0.pre0
5
+ prerelease: 6
6
+ platform: ruby
7
+ authors:
8
+ - Theo Hultberg
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-07-18 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: jruby-jars
16
+ version_requirements: !ruby/object:Gem::Requirement
17
+ requirements:
18
+ - - '='
19
+ - !ruby/object:Gem::Version
20
+ version: 1.7.3
21
+ none: false
22
+ requirement: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '='
25
+ - !ruby/object:Gem::Version
26
+ version: 1.7.3
27
+ none: false
28
+ prerelease: false
29
+ type: :runtime
30
+ 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 …`
31
+ email:
32
+ - theo@iconara.net
33
+ executables: []
34
+ extensions: []
35
+ extra_rdoc_files: []
36
+ files:
37
+ - lib/puck.rb
38
+ - lib/puck/bootstrap.rb
39
+ - lib/puck/configuration.rb
40
+ - lib/puck/jar.rb
41
+ - lib/puck/version.rb
42
+ - bin/puck
43
+ homepage: http://github.com/iconara/puck
44
+ licenses: []
45
+ post_install_message:
46
+ rdoc_options: []
47
+ require_paths:
48
+ - lib
49
+ required_ruby_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: !binary |-
54
+ MA==
55
+ none: false
56
+ required_rubygems_version: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - !binary |-
59
+ Pg==
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.1
62
+ none: false
63
+ requirements: []
64
+ rubyforge_project: puck
65
+ rubygems_version: 1.8.24
66
+ signing_key:
67
+ specification_version: 3
68
+ summary: Packs your JRuby app as a standalone Jar file
69
+ test_files: []