jruby-bundler 0.9.5
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.
- checksums.yaml +7 -0
- data/Gemfile +6 -0
- data/MIT-LICENSE +20 -0
- data/Readme.md +117 -0
- data/bin/jbundle +51 -0
- data/lib/jbundler/aether.rb +139 -0
- data/lib/jbundler/classpath_file.rb +115 -0
- data/lib/jbundler/cli.rb +148 -0
- data/lib/jbundler/config.rb +191 -0
- data/lib/jbundler/configurator.rb +27 -0
- data/lib/jbundler/context.rb +34 -0
- data/lib/jbundler/dependency_pom.rb +30 -0
- data/lib/jbundler/gemfile_lock.rb +69 -0
- data/lib/jbundler/jarfile_lock.rb +67 -0
- data/lib/jbundler/jruby_complete.rb +44 -0
- data/lib/jbundler/jruby_complete_pom.rb +31 -0
- data/lib/jbundler/lock_down.rb +166 -0
- data/lib/jbundler/pom.rb +153 -0
- data/lib/jbundler/pom_runner.rb +71 -0
- data/lib/jbundler/show.rb +53 -0
- data/lib/jbundler/tree.rb +31 -0
- data/lib/jbundler/vendor.rb +75 -0
- data/lib/jbundler.rb +73 -0
- data/spec/classpath_file_spec.rb +138 -0
- data/spec/config_spec.rb +180 -0
- data/spec/pom_spec.rb +30 -0
- data/spec/project/Settings.xml +0 -0
- data/spec/project/settings.xml +0 -0
- data/spec/setup.rb +16 -0
- data/spec/vendor_spec.rb +60 -0
- metadata +176 -0
@@ -0,0 +1,191 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'yaml'
|
22
|
+
require 'jar_dependencies'
|
23
|
+
|
24
|
+
module JBundler
|
25
|
+
|
26
|
+
# allow yaml config in $HOME/.jbundlerrc and $PWD/.jbundlerrc
|
27
|
+
class Config
|
28
|
+
|
29
|
+
RC_FILE = '.jbundlerrc'
|
30
|
+
|
31
|
+
attr_accessor :verbose, :local_repository, :jarfile, :gemfile, :skip, :settings, :offline, :work_dir, :vendor_dir, :basedir
|
32
|
+
|
33
|
+
def initialize
|
34
|
+
if ENV.has_key? 'HOME'
|
35
|
+
homefile = File.join(ENV['HOME'], RC_FILE)
|
36
|
+
home_config = YAML.load_file(homefile) if File.exists?(homefile)
|
37
|
+
else
|
38
|
+
home_config = nil
|
39
|
+
end
|
40
|
+
@config = (home_config || {})
|
41
|
+
@basedir = find_basedir( File.expand_path( '.' ) )
|
42
|
+
@basedir ||= File.expand_path( '.' )
|
43
|
+
file = join_basedir( RC_FILE )
|
44
|
+
pwd_config = YAML.load_file(file) if File.exists?(file)
|
45
|
+
@config.merge!(pwd_config || {})
|
46
|
+
end
|
47
|
+
|
48
|
+
def join_basedir( path )
|
49
|
+
if @basedir
|
50
|
+
File.join( @basedir, path )
|
51
|
+
else
|
52
|
+
path
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def find_basedir( dir )
|
57
|
+
f = File.join( dir, RC_FILE )
|
58
|
+
return dir if File.exists?( f )
|
59
|
+
f = File.join( dir, _jarfile )
|
60
|
+
return dir if File.exists?( f )
|
61
|
+
f = File.join( dir, _gemfile )
|
62
|
+
return dir if File.exists?( f )
|
63
|
+
parent = File.dirname( dir )
|
64
|
+
if dir != ENV['HOME'] && dir != parent
|
65
|
+
find_basedir( parent )
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
def absolute( file )
|
70
|
+
if file.nil? || file == File.expand_path( file )
|
71
|
+
file
|
72
|
+
else
|
73
|
+
File.join( @basedir, file )
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def _jbundler_env( key )
|
78
|
+
ENV[ key.upcase.gsub( /[.]/, '_' ) ] ||
|
79
|
+
@config[ key.downcase.sub(/^j?bundle_/, '' ).sub( /[.]/, '_' ) ]
|
80
|
+
end
|
81
|
+
private :_jbundler_env
|
82
|
+
|
83
|
+
if defined? JRUBY_VERSION
|
84
|
+
def jbundler_env( key )
|
85
|
+
java.lang.System.getProperty( key.downcase.gsub( /_/, '.' ) ) ||
|
86
|
+
_jbundler_env( key )
|
87
|
+
end
|
88
|
+
else
|
89
|
+
alias :jbundler_env :_jbundler_env
|
90
|
+
end
|
91
|
+
private :jbundler_env
|
92
|
+
|
93
|
+
def skip
|
94
|
+
skip = jbundler_env('JBUNDLE_SKIP')
|
95
|
+
# defaults to false
|
96
|
+
@skip ||= skip && skip != 'false'
|
97
|
+
end
|
98
|
+
|
99
|
+
def verbose
|
100
|
+
verbose = jbundler_env('JBUNDLE_VERBOSE')
|
101
|
+
# defaults to false
|
102
|
+
@verbose ||= verbose && verbose != 'false'
|
103
|
+
end
|
104
|
+
|
105
|
+
def jarfile
|
106
|
+
@jarfile ||= absolute( _jarfile )
|
107
|
+
end
|
108
|
+
|
109
|
+
def _jarfile
|
110
|
+
jbundler_env('JBUNDLE_JARFILE') || 'Jarfile'
|
111
|
+
end
|
112
|
+
private :_jarfile
|
113
|
+
|
114
|
+
def jarfile_lock
|
115
|
+
"#{jarfile}.lock"
|
116
|
+
end
|
117
|
+
|
118
|
+
def gemfile
|
119
|
+
@gemfile ||= absolute( _gemfile )
|
120
|
+
end
|
121
|
+
|
122
|
+
def _gemfile
|
123
|
+
jbundler_env('BUNDLE_GEMFILE') || 'Gemfile'
|
124
|
+
end
|
125
|
+
private :_gemfile
|
126
|
+
|
127
|
+
def gemfile_lock
|
128
|
+
"#{gemfile}.lock"
|
129
|
+
end
|
130
|
+
|
131
|
+
def classpath_file
|
132
|
+
absolute( jbundler_env('JBUNDLE_CLASSPATH_FILE') ||
|
133
|
+
'.jbundler/classpath.rb' )
|
134
|
+
end
|
135
|
+
|
136
|
+
def local_repository
|
137
|
+
# use maven default local repo as default
|
138
|
+
local_maven_repository = absolute( jbundler_env('JBUNDLE_LOCAL_REPOSITORY') )
|
139
|
+
if local_maven_repository
|
140
|
+
warn "JBUNDLE_LOCAL_REPOSITORY environment or jbundle.local.repository' system property is deprecated use JARS_HOME or jars.home instead"
|
141
|
+
ENV[ 'JARS_HOME' ] ||= local_maven_repository
|
142
|
+
else
|
143
|
+
# first load the right settings
|
144
|
+
self.settings
|
145
|
+
Jars.home
|
146
|
+
end
|
147
|
+
end
|
148
|
+
|
149
|
+
def settings
|
150
|
+
settings = absolute( jbundler_env('JBUNDLE_SETTINGS') )
|
151
|
+
if settings
|
152
|
+
warn "JBUNDLE_SETTINGS environment or jbundle.settings' system property is deprecated use JARS_MAVEN_SETTINGS or jars.maven.settings instead"
|
153
|
+
ENV[ Jars::MAVEN_SETTINGS ] ||= settings
|
154
|
+
end
|
155
|
+
Jars.maven_settings
|
156
|
+
end
|
157
|
+
|
158
|
+
def offline
|
159
|
+
@offline ||= jbundler_env('JBUNDLE_OFFLINE')
|
160
|
+
@offline == 'true' || @offline == true
|
161
|
+
end
|
162
|
+
|
163
|
+
def proxy
|
164
|
+
@proxy ||= jbundler_env('JBUNDLE_PROXY')
|
165
|
+
if @proxy
|
166
|
+
warn 'proxy config is deprecated, use settings.xml instead'
|
167
|
+
end
|
168
|
+
@proxy
|
169
|
+
end
|
170
|
+
|
171
|
+
def mirror
|
172
|
+
@mirror ||= jbundler_env('JBUNDLE_MIRROR')
|
173
|
+
# nice to have no leading slash
|
174
|
+
@mirror = @mirror.sub( /\/$/, '' ) if @mirror
|
175
|
+
if @mirror
|
176
|
+
warn 'mirror config is deprecated, use settings.xml instead'
|
177
|
+
end
|
178
|
+
@mirror
|
179
|
+
end
|
180
|
+
|
181
|
+
def work_dir
|
182
|
+
@work_dir ||= absolute( jbundler_env('JBUNDLE_WORK_DIR') || 'pkg' )
|
183
|
+
end
|
184
|
+
|
185
|
+
def vendor_dir
|
186
|
+
@vendor_dir ||= absolute( jbundler_env('JBUNDLE_VENDOR_DIR') ||
|
187
|
+
File.join( 'vendor', 'jars' ) )
|
188
|
+
end
|
189
|
+
|
190
|
+
end
|
191
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'jbundler/configurator'
|
2
|
+
module JBundler
|
3
|
+
class Configurator
|
4
|
+
|
5
|
+
attr_accessor :groups, :bootstrap, :verbose, :compile, :work_dir
|
6
|
+
|
7
|
+
def initialize( config )
|
8
|
+
@config = config
|
9
|
+
end
|
10
|
+
|
11
|
+
def configure( maven )
|
12
|
+
maven.property( 'jbundler.basedir', @config.basedir )
|
13
|
+
maven.property( 'jbundler.jarfile', @config.jarfile )
|
14
|
+
maven.property( 'jbundler.gemfile', @config.gemfile )
|
15
|
+
maven.property( 'jbundler.workdir', work_dir )
|
16
|
+
maven.property( 'jbundler.groups', @groups )
|
17
|
+
maven.property( 'jbundler.bootstrap', @bootstrap )
|
18
|
+
maven.property( 'maven.repo.local', @config.local_repository ) if @config.local_repository
|
19
|
+
maven.options[ '-s' ] = @config.settings if @config.settings
|
20
|
+
maven.options[ '-o' ] = nil if @config.offline
|
21
|
+
end
|
22
|
+
|
23
|
+
def work_dir
|
24
|
+
@work_dir ||= File.expand_path( @config.work_dir )
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'maven/tools/jarfile'
|
2
|
+
require 'jbundler/classpath_file'
|
3
|
+
require 'jbundler/vendor'
|
4
|
+
require 'jbundler/gemfile_lock'
|
5
|
+
require 'jbundler/aether'
|
6
|
+
|
7
|
+
module JBundler
|
8
|
+
|
9
|
+
class Context
|
10
|
+
|
11
|
+
attr_reader :config
|
12
|
+
|
13
|
+
def initialize
|
14
|
+
@config = JBundler::Config.new
|
15
|
+
end
|
16
|
+
|
17
|
+
def jarfile
|
18
|
+
@jarfile ||= Maven::Tools::Jarfile.new( @config.jarfile )
|
19
|
+
end
|
20
|
+
|
21
|
+
def vendor
|
22
|
+
@vendor ||= JBundler::Vendor.new( @config.vendor_dir )
|
23
|
+
end
|
24
|
+
|
25
|
+
def classpath
|
26
|
+
@classpath ||= JBundler::ClasspathFile.new( @config.classpath_file )
|
27
|
+
end
|
28
|
+
|
29
|
+
def gemfile_lock
|
30
|
+
@gemfile_lock ||= JBundler::GemfileLock.new( jarfile,
|
31
|
+
@config.gemfile_lock )
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
bdir = java.lang.System.getProperty( "jbundler.basedir" )
|
2
|
+
jfile = java.lang.System.getProperty( "jbundler.jarfile" )
|
3
|
+
gfile = java.lang.System.getProperty( "jbundler.gemfile" )
|
4
|
+
jworkdir = java.lang.System.getProperty( "jbundler.workdir" )
|
5
|
+
|
6
|
+
basedir( bdir )
|
7
|
+
if basedir != bdir
|
8
|
+
# older maven-tools needs this
|
9
|
+
self.instance_variable_set( :@basedir, bdir )
|
10
|
+
end
|
11
|
+
|
12
|
+
( 0..(java.lang.System.getProperty( "jbundler.jars.size" ).to_i - 1) ).each do |i|
|
13
|
+
coord = java.lang.System.getProperty( "jbundler.jars.#{i}" )
|
14
|
+
dependency_artifact( Maven::Tools::Artifact.from_coordinate( coord.to_s ) )
|
15
|
+
end
|
16
|
+
|
17
|
+
jarfile( jfile )
|
18
|
+
|
19
|
+
build do
|
20
|
+
directory = jworkdir
|
21
|
+
end
|
22
|
+
|
23
|
+
properties( 'project.build.sourceEncoding' => 'utf-8',
|
24
|
+
'tesla.dump.readOnly' => true,
|
25
|
+
'tesla.dump.pom' => 'tree.pom.xml' )
|
26
|
+
|
27
|
+
plugin( :dependency, '2.8',
|
28
|
+
:includeTypes => 'jar',
|
29
|
+
:outputAbsoluteArtifactFilename => true,
|
30
|
+
:outputFile => java.lang.System.getProperty( "jbundler.outputFile" ) )
|
@@ -0,0 +1,69 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2013 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'rubygems'
|
22
|
+
require 'jbundler/pom'
|
23
|
+
require 'bundler'
|
24
|
+
|
25
|
+
module JBundler
|
26
|
+
|
27
|
+
class GemfileLock
|
28
|
+
|
29
|
+
def initialize(jarfile, lockfile = 'Gemfile.lock')
|
30
|
+
@jarfile = jarfile
|
31
|
+
@lockfile = lockfile if File.exists?(lockfile)
|
32
|
+
end
|
33
|
+
|
34
|
+
def exists?
|
35
|
+
!@lockfile.nil?
|
36
|
+
end
|
37
|
+
|
38
|
+
def newer?( mtime )
|
39
|
+
exists? && ( self.mtime > mtime )
|
40
|
+
end
|
41
|
+
|
42
|
+
def mtime
|
43
|
+
File.mtime(@lockfile) if @lockfile
|
44
|
+
end
|
45
|
+
|
46
|
+
def populate_dependencies(aether)
|
47
|
+
if @lockfile
|
48
|
+
# assuming we run in Bundler context here
|
49
|
+
# since we have a Gemfile.lock :)
|
50
|
+
Bundler.load.specs.each do |spec|
|
51
|
+
jars = []
|
52
|
+
spec.requirements.each do |rr|
|
53
|
+
rr.split(/\n/).each do |r|
|
54
|
+
jars << r if r =~ /^\s*(jar|pom)\s/
|
55
|
+
end
|
56
|
+
end
|
57
|
+
unless jars.empty?
|
58
|
+
pom = Pom.new(spec.name, spec.version, jars, "pom")
|
59
|
+
aether.install(pom.coordinate, pom.file)
|
60
|
+
unless @jarfile.locked?(pom.coordinate)
|
61
|
+
aether.add_artifact(pom.coordinate)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
#
|
2
|
+
# Copyright (C) 2014 Christian Meier
|
3
|
+
#
|
4
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy of
|
5
|
+
# this software and associated documentation files (the "Software"), to deal in
|
6
|
+
# the Software without restriction, including without limitation the rights to
|
7
|
+
# use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
8
|
+
# the Software, and to permit persons to whom the Software is furnished to do so,
|
9
|
+
# subject to the following conditions:
|
10
|
+
#
|
11
|
+
# The above copyright notice and this permission notice shall be included in all
|
12
|
+
# copies or substantial portions of the Software.
|
13
|
+
#
|
14
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
15
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
16
|
+
# FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
17
|
+
# COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
18
|
+
# IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
19
|
+
# CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
20
|
+
#
|
21
|
+
require 'jar_dependencies'
|
22
|
+
require 'maven/tools/dsl/jarfile_lock'
|
23
|
+
module JBundler
|
24
|
+
class JarfileLock < Maven::Tools::DSL::JarfileLock
|
25
|
+
|
26
|
+
def require( scope = :runtime )
|
27
|
+
coordinates( scope ).each do |coord|
|
28
|
+
Jars.require_jar( coord.split( /:/ ) )
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def classpath( scope = :runtime )
|
33
|
+
coordinates( scope ).collect do |coord|
|
34
|
+
path_to_jar( coord.split( /:/ ) )
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def downloaded?
|
39
|
+
classpath.member?( nil ) == false &&
|
40
|
+
classpath( :test ).member?( nil ) == false
|
41
|
+
end
|
42
|
+
|
43
|
+
private
|
44
|
+
|
45
|
+
# TODO should move into jar-dependencies
|
46
|
+
def to_path( group_id, artifact_id, *classifier_version )
|
47
|
+
version = classifier_version[ -1 ]
|
48
|
+
classifier = classifier_version[ -2 ]
|
49
|
+
|
50
|
+
jar = to_jar( group_id, artifact_id, version, classifier )
|
51
|
+
( [ Jars.home ] + $LOAD_PATH ).each do |path|
|
52
|
+
if File.exists?( f = File.join( path, jar ) )
|
53
|
+
return f
|
54
|
+
end
|
55
|
+
end
|
56
|
+
nil
|
57
|
+
end
|
58
|
+
|
59
|
+
# TODO this is copy and paste from jar-dependncies
|
60
|
+
def to_jar( group_id, artifact_id, version, classifier )
|
61
|
+
file = "#{group_id.gsub( /\./, '/' )}/#{artifact_id}/#{version}/#{artifact_id}-#{version}"
|
62
|
+
file << "-#{classifier}" if classifier
|
63
|
+
file << '.jar'
|
64
|
+
file
|
65
|
+
end
|
66
|
+
end
|
67
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'jbundler/pom_runner'
|
2
|
+
require 'fileutils'
|
3
|
+
module JBundler
|
4
|
+
class JRubyComplete < PomRunner
|
5
|
+
|
6
|
+
def initialize( config, options )
|
7
|
+
super options
|
8
|
+
work_dir = File.expand_path( config.work_dir )
|
9
|
+
maven.property( 'jbundler.workdir', work_dir )
|
10
|
+
maven.property( 'jbundler.basedir', config.basedir )
|
11
|
+
maven.property( 'jbundler.jarfile', config.jarfile )
|
12
|
+
maven.property( 'jbundler.gemfile', config.gemfile )
|
13
|
+
@tree = File.join( work_dir, 'tree.txt' )
|
14
|
+
maven.property( 'jbundler.outputFile', @tree )
|
15
|
+
end
|
16
|
+
|
17
|
+
def pom_file
|
18
|
+
File.join( File.dirname( __FILE__ ), 'jruby_complete_pom.rb' )
|
19
|
+
end
|
20
|
+
|
21
|
+
def show_versions
|
22
|
+
puts '...'
|
23
|
+
|
24
|
+
FileUtils.rm_f( @tree )
|
25
|
+
|
26
|
+
exec( 'dependency:tree' )
|
27
|
+
|
28
|
+
if File.exists?( @tree )
|
29
|
+
puts File.read( @tree )
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def packit
|
34
|
+
puts '...'
|
35
|
+
exec( :package )
|
36
|
+
|
37
|
+
puts
|
38
|
+
puts 'now you can use jruby like this'
|
39
|
+
puts
|
40
|
+
puts "\tjava -jar jruby_complete_custom.jar"
|
41
|
+
puts
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
jfile = ::Maven::Tools::Jarfile.new( java.lang.System.getProperty( "jbundler.jarfile" ) )
|
2
|
+
workdir = java.lang.System.getProperty( "jbundler.workdir" )
|
3
|
+
jworkdir = File.join( workdir, 'jruby_complete' )
|
4
|
+
FileUtils.mkdir_p( jworkdir )
|
5
|
+
|
6
|
+
build.directory = jworkdir
|
7
|
+
|
8
|
+
properties( 'maven.test.skip' => true,
|
9
|
+
'project.build.sourceEncoding' => 'utf-8' )
|
10
|
+
|
11
|
+
jfile.populate_unlocked do |dsl|
|
12
|
+
setup_jruby( dsl.jruby || JRUBY_VERSION, :compile )
|
13
|
+
dsl.artifacts.select do |a|
|
14
|
+
a[ :scope ] == :provided
|
15
|
+
end.each do |a|
|
16
|
+
a[ :scope ] = :compile
|
17
|
+
artifact( a )
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
plugin( :shade, '2.1',
|
22
|
+
:outputFile => "${user.dir}/jruby-complete-custom.jar",
|
23
|
+
:transformers => [ { '@implementation' => 'org.apache.maven.plugins.shade.resource.ManifestResourceTransformer',
|
24
|
+
:mainClass => 'org.jruby.Main' } ] ) do
|
25
|
+
execute_goals( 'shade', :phase => 'package' )
|
26
|
+
end
|
27
|
+
|
28
|
+
plugin( :dependency, '2.8',
|
29
|
+
:includeTypes => 'jar',
|
30
|
+
:outputAbsoluteArtifactFilename => true,
|
31
|
+
:outputFile => java.lang.System.getProperty( "jbundler.outputFile" ) )
|
@@ -0,0 +1,166 @@
|
|
1
|
+
require 'jbundler/configurator'
|
2
|
+
require 'jbundler/classpath_file'
|
3
|
+
require 'jbundler/vendor'
|
4
|
+
require 'jbundler/gemfile_lock'
|
5
|
+
require 'jbundler/show'
|
6
|
+
require 'maven/tools/gemspec_dependencies'
|
7
|
+
require 'maven/tools/jarfile'
|
8
|
+
require 'maven/ruby/maven'
|
9
|
+
require 'fileutils'
|
10
|
+
require 'jar_installer'
|
11
|
+
|
12
|
+
module JBundler
|
13
|
+
class LockDown
|
14
|
+
|
15
|
+
def initialize( config )
|
16
|
+
@config = config
|
17
|
+
@configurator = Configurator.new( config )
|
18
|
+
end
|
19
|
+
|
20
|
+
def vendor
|
21
|
+
@vendor ||= JBundler::Vendor.new( @config.vendor_dir )
|
22
|
+
end
|
23
|
+
|
24
|
+
def update( debug = false, verbose = false )
|
25
|
+
if vendor.vendored?
|
26
|
+
raise 'Cannot update vendored jars'
|
27
|
+
end
|
28
|
+
|
29
|
+
FileUtils.rm_f( @config.jarfile_lock )
|
30
|
+
|
31
|
+
lock_down( false, debug, verbose )
|
32
|
+
end
|
33
|
+
|
34
|
+
def lock_down( needs_vendor = false, debug = false, verbose = false )
|
35
|
+
jarfile = Maven::Tools::Jarfile.new( @config.jarfile )
|
36
|
+
classpath = JBundler::ClasspathFile.new( @config.classpath_file )
|
37
|
+
if jarfile.exists_lock? && classpath.exists?
|
38
|
+
needs_update = false
|
39
|
+
else
|
40
|
+
needs_update = needs_update?( jarfile, classpath )
|
41
|
+
end
|
42
|
+
if ( ! needs_update && ! needs_vendor ) || vendor.vendored?
|
43
|
+
|
44
|
+
puts 'Jar dependencies are up to date !'
|
45
|
+
|
46
|
+
if needs_update?( jarfile, classpath )
|
47
|
+
f = classpath.file.sub(/#{Dir.pwd}#{File::SEPARATOR}/, '' )
|
48
|
+
"the #{f} is stale, i.e. Gemfile or Jarfile is newer. `jbundle update` will update it"
|
49
|
+
end
|
50
|
+
else
|
51
|
+
|
52
|
+
puts '...'
|
53
|
+
|
54
|
+
deps = install_dependencies( debug, verbose, jarfile.exists_lock? )
|
55
|
+
|
56
|
+
update_files( classpath, collect_jars( deps ) ) if needs_update
|
57
|
+
|
58
|
+
vendor_it( vendor, deps ) if needs_vendor
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
private
|
64
|
+
|
65
|
+
def needs_update?( jarfile, classpath )
|
66
|
+
gemfile_lock = JBundler::GemfileLock.new( jarfile,
|
67
|
+
@config.gemfile_lock )
|
68
|
+
classpath.needs_update?( jarfile, gemfile_lock )
|
69
|
+
end
|
70
|
+
|
71
|
+
def vendor_it( vendor, deps )
|
72
|
+
puts "vendor directory: #{@config.vendor_dir}"
|
73
|
+
vendor.vendor_dependencies( deps )
|
74
|
+
puts
|
75
|
+
end
|
76
|
+
|
77
|
+
def collect_jars( deps )
|
78
|
+
jars = {}
|
79
|
+
deps.each do |d|
|
80
|
+
case d.scope
|
81
|
+
when :provided
|
82
|
+
( jars[ :jruby ] ||= [] ) << d
|
83
|
+
when :test
|
84
|
+
( jars[ :test ] ||= [] ) << d
|
85
|
+
else
|
86
|
+
( jars[ :runtime ] ||= [] ) << d
|
87
|
+
end
|
88
|
+
end
|
89
|
+
jars
|
90
|
+
end
|
91
|
+
|
92
|
+
def update_files( classpath_file, jars )
|
93
|
+
if jars.values.flatten.size == 0
|
94
|
+
FileUtils.rm_f @config.jarfile_lock
|
95
|
+
else
|
96
|
+
lock = Maven::Tools::DSL::JarfileLock.new( @config.jarfile )
|
97
|
+
lock.replace( jars )
|
98
|
+
lock.dump
|
99
|
+
end
|
100
|
+
classpath_file.generate( (jars[ :runtime ] || []).collect { |j| j.file },
|
101
|
+
(jars[ :test ] || []).collect { |j| j.file },
|
102
|
+
(jars[ :jruby ] || []).collect { |j| j.file },
|
103
|
+
@config.local_repository )
|
104
|
+
end
|
105
|
+
|
106
|
+
def install_dependencies( debug, verbose, exclude_transitive = false )
|
107
|
+
deps_file = File.join( File.expand_path( @config.work_dir ),
|
108
|
+
'dependencies.txt' )
|
109
|
+
|
110
|
+
exec_maven( debug, verbose, deps_file, exclude_transitive )
|
111
|
+
|
112
|
+
result = []
|
113
|
+
File.read( deps_file ).each_line do |line|
|
114
|
+
dep = Jars::JarInstaller::Dependency.new( line )
|
115
|
+
result << dep if dep
|
116
|
+
end
|
117
|
+
result
|
118
|
+
ensure
|
119
|
+
FileUtils.rm_f( deps_file ) if deps_file
|
120
|
+
end
|
121
|
+
|
122
|
+
def exec_maven( debug, verbose, output, exclude_transitive = false )
|
123
|
+
m = Maven::Ruby::Maven.new
|
124
|
+
m.options[ '-f' ] = File.join( File.dirname( __FILE__ ),
|
125
|
+
'.polyglot.dependency_pom.rb' )
|
126
|
+
m.property( 'verbose', debug || verbose )
|
127
|
+
m.options[ '-q' ] = nil if !debug and !verbose
|
128
|
+
m.options[ '-e' ] = nil if !debug and verbose
|
129
|
+
m.options[ '-X' ] = nil if debug
|
130
|
+
m.options[ '-DexcludeTransitive' ] = exclude_transitive
|
131
|
+
m.verbose = debug
|
132
|
+
m.property( 'jbundler.outputFile', output )
|
133
|
+
|
134
|
+
@configurator.configure( m )
|
135
|
+
|
136
|
+
attach_jar_coordinates( m )
|
137
|
+
|
138
|
+
m.exec( 'dependency:list' )
|
139
|
+
end
|
140
|
+
|
141
|
+
private
|
142
|
+
|
143
|
+
def attach_jar_coordinates( maven )
|
144
|
+
load_path = $LOAD_PATH.dup
|
145
|
+
require 'bundler/setup'
|
146
|
+
done = []
|
147
|
+
index = 0
|
148
|
+
Gem.loaded_specs.each do |name, spec|
|
149
|
+
# TODO get rid of this somehow
|
150
|
+
deps = Maven::Tools::GemspecDependencies.new( spec )
|
151
|
+
deps.java_dependency_artifacts.each do |a|
|
152
|
+
if not done.include?( a.key ) and (a.scope.nil? or a.scope == :compile or a.scope == :runtime)
|
153
|
+
maven.property( "jbundler.jars.#{index}", a.to_s )
|
154
|
+
index += 1
|
155
|
+
done << a.key
|
156
|
+
end
|
157
|
+
end
|
158
|
+
end
|
159
|
+
if index > 0
|
160
|
+
maven.property( "jbundler.jars.size", index )
|
161
|
+
end
|
162
|
+
ensure
|
163
|
+
$LOAD_PATH.replace( load_path )
|
164
|
+
end
|
165
|
+
end
|
166
|
+
end
|