jbundler 0.5.5 → 0.6.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -19,34 +19,74 @@
19
19
  # CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
20
20
  #
21
21
  require 'yaml'
22
+ require 'jar_dependencies'
22
23
 
23
24
  module JBundler
24
25
 
25
26
  # allow yaml config in $HOME/.jbundlerrc and $PWD/.jbundlerrc
26
27
  class Config
27
28
 
28
- attr_accessor :verbose, :local_repository, :jarfile, :gemfile, :skip, :settings, :offline, :work_dir, :vendor_dir
29
+ RC_FILE = '.jbundlerrc'
30
+
31
+ attr_accessor :verbose, :local_repository, :jarfile, :gemfile, :skip, :settings, :offline, :work_dir, :vendor_dir, :basedir
29
32
 
30
33
  def initialize
31
- file = '.jbundlerrc'
32
- homefile = File.join(ENV['HOME'], file)
33
- home_config = YAML.load_file(homefile) if File.exists?(homefile)
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 )
34
44
  pwd_config = YAML.load_file(file) if File.exists?(file)
35
- File.expand_path( file )
36
- @config = (home_config || {}).merge(pwd_config || {})
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( /[.]/, '_' ) ]
37
80
  end
81
+ private :_jbundler_env
38
82
 
39
83
  if defined? JRUBY_VERSION
40
- def jbundler_env(key)
41
- java.lang.System.getProperty(key.downcase.gsub(/_/, '.')) ||
42
- ENV[key.upcase.gsub(/[.]/, '_')] ||
43
- @config[key.downcase.sub(/^j?bundle_/, '').sub(/[.]/, '_')]
84
+ def jbundler_env( key )
85
+ java.lang.System.getProperty( key.downcase.gsub( /_/, '.' ) ) ||
86
+ _jbundler_env( key )
44
87
  end
45
88
  else
46
- def jbundler_env(key)
47
- ENV[key.upcase.gsub(/[.]/, '_')] ||
48
- @config[key.downcase.sub(/^j?bundler/, '').sub(/[.]/, '_')]
49
- end
89
+ alias :jbundler_env :_jbundler_env
50
90
  end
51
91
  private :jbundler_env
52
92
 
@@ -63,36 +103,54 @@ module JBundler
63
103
  end
64
104
 
65
105
  def jarfile
66
- if File.exists?('Mvnfile')
67
- warn "'Mvnfile' name is deprecated, please use 'Jarfile' instead"
68
- @jarfile = 'Mvnfile'
69
- end
70
- @jarfile ||= jbundler_env('JBUNDLE_JARFILE') || 'Jarfile'
106
+ @jarfile ||= absolute( _jarfile )
71
107
  end
72
108
 
109
+ def _jarfile
110
+ jbundler_env('JBUNDLE_JARFILE') || 'Jarfile'
111
+ end
112
+ private :_jarfile
113
+
73
114
  def jarfile_lock
74
115
  "#{jarfile}.lock"
75
116
  end
76
117
 
77
118
  def gemfile
78
- @gemfile ||= jbundler_env('BUNDLE_GEMFILE') || 'Gemfile'
119
+ @gemfile ||= absolute( _gemfile )
120
+ end
121
+
122
+ def _gemfile
123
+ jbundler_env('BUNDLE_GEMFILE') || 'Gemfile'
79
124
  end
125
+ private :_gemfile
80
126
 
81
127
  def gemfile_lock
82
128
  "#{gemfile}.lock"
83
129
  end
84
130
 
85
131
  def classpath_file
86
- jbundler_env('JBUNDLE_CLASSPATH_FILE') || '.jbundler/classpath.rb'
132
+ absolute( jbundler_env('JBUNDLE_CLASSPATH_FILE') ||
133
+ '.jbundler/classpath.rb' )
87
134
  end
88
135
 
89
136
  def local_repository
90
137
  # use maven default local repo as default
91
- @local_maven_repository ||= jbundler_env('JBUNDLE_LOCAL_REPOSITORY')
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
+ Jars.home
144
+ end
92
145
  end
93
146
 
94
147
  def settings
95
- @settings ||= jbundler_env('JBUNDLE_SETTINGS')
148
+ settings = absolute( jbundler_env('JBUNDLE_SETTINGS') )
149
+ if settings
150
+ warn "JBUNDLE_SETTINGS environment or jbundle.settings' system property is deprecated use JARS_MAVEN_SETTINGS or jars.maven.settings instead"
151
+ ENV[ Jars::MAVEN_SETTINGS ] ||= settings
152
+ end
153
+ Jars.maven_settings
96
154
  end
97
155
 
98
156
  def offline
@@ -118,20 +176,13 @@ module JBundler
118
176
  @mirror
119
177
  end
120
178
 
121
- def rubygems_mirror
122
- @rubygems_mirror ||= jbundler_env('BUNDLE_RUBYGEMS_MIRROR')
123
- # here a leading slash is needed !!
124
- @rubygems_mirror = @rubygems_mirror.sub( /([^\/])$/ , "\\1/" ) if @rubygems_mirror
125
- warn 'reubygems mirror config is deprecated, use bundler >=1.5 and its mirror config'
126
- @rubygems_mirror
127
- end
128
-
129
179
  def work_dir
130
- @work_dir ||= jbundler_env('JBUNDLE_WORK_DIR') || 'pkg'
180
+ @work_dir ||= absolute( jbundler_env('JBUNDLE_WORK_DIR') || 'pkg' )
131
181
  end
132
182
 
133
183
  def vendor_dir
134
- @vendor_dir ||= jbundler_env('JBUNDLE_VENDOR_DIR') || File.join( 'vendor', 'jars' )
184
+ @vendor_dir ||= absolute( jbundler_env('JBUNDLE_VENDOR_DIR') ||
185
+ File.join( 'vendor', 'jars' ) )
135
186
  end
136
187
 
137
188
  end
@@ -9,6 +9,7 @@ module JBundler
9
9
  end
10
10
 
11
11
  def configure( maven )
12
+ maven.property( 'jbundler.basedir', @config.basedir )
12
13
  maven.property( 'jbundler.jarfile', @config.jarfile )
13
14
  maven.property( 'jbundler.gemfile', @config.gemfile )
14
15
  maven.property( 'jbundler.workdir', work_dir )
@@ -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
@@ -1,23 +1,27 @@
1
+ bdir = java.lang.System.getProperty( "jbundler.basedir" )
1
2
  jfile = java.lang.System.getProperty( "jbundler.jarfile" )
2
3
  gfile = java.lang.System.getProperty( "jbundler.gemfile" )
3
4
  jworkdir = java.lang.System.getProperty( "jbundler.workdir" )
4
5
 
5
- basedir( File.dirname( jfile ) )
6
+ basedir( bdir )
7
+ if basedir != bdir
8
+ # older maven-tools needs this
9
+ self.instance_variable_set( :@basedir, bdir )
10
+ end
6
11
 
7
12
  gemfile( gfile ) if File.exists? gfile
8
13
 
9
- jarfile( jfile )
14
+ jarfile( jfile, :skip_locked => true )
10
15
 
11
16
  build do
12
17
  directory = jworkdir
13
- default_goal 'dependency:list'
14
18
  end
15
19
 
20
+ properties( 'project.build.sourceEncoding' => 'utf-8',
21
+ 'tesla.dump.readOnly' => true,
22
+ 'tesla.dump.pom' => 'tree.pom.xml' )
23
+
16
24
  plugin( :dependency, '2.8',
17
25
  :includeTypes => 'jar',
18
26
  :outputAbsoluteArtifactFilename => true,
19
- :outputFile => "#{jworkdir}/dependencies.txt" )
20
-
21
- properties( 'project.build.sourceEncoding' => 'utf-8',
22
- 'tesla.dump.readOnly' => true,
23
- 'tesla.dump.pom' => 'lockdown.pom.xml' )
27
+ :outputFile => java.lang.System.getProperty( "jbundler.outputFile" ) )
@@ -21,7 +21,6 @@ FileUtils.cp( java.lang.System.getProperty( 'jbundler.bootstrap'),
21
21
  def jruby_home( path )
22
22
  File.join( 'META-INF/jruby.home/lib/ruby/gems/shared', path )
23
23
  end
24
-
25
24
 
26
25
  jfile.locked.each do |dep|
27
26
  artifact( dep )
@@ -54,19 +53,13 @@ properties( 'maven.test.skip' => true,
54
53
 
55
54
  jfile.populate_unlocked do |dsl|
56
55
 
57
- # setup jruby version
58
- jruby_version = dsl.jruby || JRUBY_VERSION
59
- if ( jruby_version < '1.6' )
60
- raise 'jruby before 1.6 are not supported'
61
- elsif ( jruby_version < '1.7' )
62
- warn 'jruby version below 1.7 uses jruby-complete'
63
- jar 'org.jruby:jruby-complete', jruby_version
64
- elsif ( jruby_version < '1.7.5' )
65
- jar 'org.jruby:jruby-core', jruby_version
66
- else
67
- jar 'org.jruby:jruby', jruby_version
56
+ setup_jruby( dsl.jruby || JRUBY_VERSION, :compile )
57
+ dsl.artifacts.select do |a|
58
+ a[ :scope ] == :provided
59
+ end.each do |a|
60
+ a[ :scope ] = :compile
61
+ artifact( a )
68
62
  end
69
-
70
63
  local = dsl.artifacts.select do |a|
71
64
  a[ :system_path ]
72
65
  end
@@ -35,6 +35,10 @@ module JBundler
35
35
  !@lockfile.nil?
36
36
  end
37
37
 
38
+ def newer?( mtime )
39
+ exists? && ( self.mtime > mtime )
40
+ end
41
+
38
42
  def mtime
39
43
  File.mtime(@lockfile) if @lockfile
40
44
  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" ) )
@@ -6,6 +6,7 @@ require 'jbundler/show'
6
6
  require 'maven/tools/jarfile'
7
7
  require 'maven/ruby/maven'
8
8
  require 'fileutils'
9
+ require 'jar_installer'
9
10
  module JBundler
10
11
  class LockDown
11
12
 
@@ -13,93 +14,125 @@ module JBundler
13
14
  @config = config
14
15
  @configurator = Configurator.new( config )
15
16
  end
17
+
18
+ def vendor
19
+ @vendor ||= JBundler::Vendor.new( @config.vendor_dir )
20
+ end
16
21
 
17
- def lock_down( needs_vendor = false, debug = false )
18
- jarfile = Maven::Tools::Jarfile.new( @config.jarfile )
19
- vendor = JBundler::Vendor.new( @config.vendor_dir )
20
- classpath_file = JBundler::ClasspathFile.new( @config.classpath_file )
21
- gemfile_lock = JBundler::GemfileLock.new( jarfile,
22
- @config.gemfile_lock )
22
+ def update( debug = false, verbose = false )
23
+ if vendor.vendored?
24
+ raise 'can not update vendored jars'
25
+ end
23
26
 
24
- needs_update = classpath_file.needs_update?( jarfile, gemfile_lock )
25
- if( ( ! needs_update ||
26
- vendor.vendored? ) && ! vendor )
27
+ FileUtils.rm_f( @config.jarfile_lock )
28
+
29
+ lock_down( false, debug, verbose )
30
+ end
31
+
32
+ def lock_down( needs_vendor = false, debug = false, verbose = false )
33
+ classpath = JBundler::ClasspathFile.new( @config.classpath_file )
34
+ needs_update = needs_update?( classpath )
35
+ if ( ! needs_update && ! needs_vendor ) || vendor.vendored?
27
36
 
28
- puts 'up to date'
37
+ puts 'Jar dependencies are up to date !'
29
38
 
30
39
  else
31
40
 
32
41
  puts '...'
42
+
43
+ locked = StringIO.new
33
44
 
34
- exec_maven( debug )
45
+ deps = install_dependencies( debug, verbose )
35
46
 
36
- deps_file = File.join( File.expand_path( @config.work_dir ),
37
- 'dependencies.txt' )
38
- deps = StringIO.new
39
- jars = {}
40
- vendor_map = {}
41
- File.read( deps_file ).each_line do |line|
42
- if line.match /:jar:/
43
- jar = line.sub( /.+:/, '' ).sub( /\s$/, '' )
44
- unless line.match /:provided/
45
- vendor_map[ line.sub( /:[^:]+:[^:]+$/, '' )
46
- .sub( /^\s+/, '' ) ] = jar
47
- end
48
- case line
49
- when /:provided:/
50
- ( jars[ :jruby ] ||= [] ) << jar
51
- when /:test:/
52
- ( jars[ :test ] ||= [] ) << jar
53
- else
54
- ( jars[ :runtime ] ||= [] ) << jar
55
- end
56
- end
57
- # TODO make lock depend on jruby version as well on
58
- # include test as well, i.e. keep the scope in place
59
- if( line.match( /:compile:|:runtime:/ ) &&
60
- ! line.match( /^ruby.bundler:/ ) )
61
- deps.puts line.sub( /:[^:]+:[^:]+$/, '' ).sub( /^\s+/, '' )
62
- end
63
- end
64
- if needs_update
65
- if deps.string.empty?
66
- FileUtils.rm_f @config.jarfile_lock
67
- else
68
- File.open( @config.jarfile_lock, 'w' ) do |f|
69
- f.print deps.string
70
- end
71
- end
72
- classpath_file.generate( jars[ :runtime ],
73
- jars[ :test ],
74
- jars[ :jruby ] )
75
- end
76
- if needs_vendor
77
- puts "vendor directory: #{@config.vendor_dir}"
78
- vendor_map.each do |key, file|
79
- vendor.copy_jar( key, file )
47
+ jars = collect_jars( deps, locked, debug, verbose )
48
+
49
+ update_files( classpath, locked, jars ) if needs_update
50
+
51
+ vendor_it( vendor, deps ) if needs_vendor
52
+
53
+ end
54
+ end
55
+
56
+ private
57
+
58
+ def needs_update?( classpath )
59
+ jarfile = Maven::Tools::Jarfile.new( @config.jarfile )
60
+ gemfile_lock = JBundler::GemfileLock.new( jarfile,
61
+ @config.gemfile_lock )
62
+
63
+ classpath.needs_update?( jarfile, gemfile_lock )
64
+ end
65
+
66
+ def vendor_it( vendor, deps )
67
+ puts "vendor directory: #{@config.vendor_dir}"
68
+ vendor.vendor_dependencies( deps )
69
+ puts
70
+ end
71
+
72
+ def collect_jars( deps, locked, debug, verbose )
73
+ jars = {}
74
+ deps.each do |d|
75
+ case d.scope
76
+ when :provided
77
+ ( jars[ :jruby ] ||= [] ) << d.file
78
+ when :test
79
+ ( jars[ :test ] ||= [] ) << d.file
80
+ else
81
+ ( jars[ :runtime ] ||= [] ) << d.file
82
+ if( ! d.gav.match( /^ruby.bundler:/ ) )
83
+ # TODO make Jarfile.lock depend on jruby version as well on
84
+ # include test as well, i.e. keep the scope in place
85
+ locked.puts d.coord
80
86
  end
81
- puts
82
87
  end
83
- if @config.verbose
84
- Show.new( @config ).show_classpath
85
- puts
88
+ end
89
+ jars
90
+ end
91
+
92
+ def update_files( classpath_file, locked, jars )
93
+ if locked.string.empty?
94
+ FileUtils.rm_f @config.jarfile_lock
95
+ else
96
+ File.open( @config.jarfile_lock, 'w' ) do |f|
97
+ f.print locked.string
86
98
  end
87
- puts 'jbundle complete'
88
99
  end
100
+ classpath_file.generate( jars[ :runtime ],
101
+ jars[ :test ],
102
+ jars[ :jruby ],
103
+ @config.local_repository )
89
104
  end
90
105
 
91
- private
92
-
93
- def exec_maven( debug )
106
+ def install_dependencies( debug, verbose )
107
+ deps_file = File.join( File.expand_path( @config.work_dir ),
108
+ 'dependencies.txt' )
109
+
110
+ exec_maven( debug, verbose, deps_file )
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 )
94
123
  m = Maven::Ruby::Maven.new
95
124
  m.options[ '-f' ] = File.join( File.dirname( __FILE__ ),
96
- 'lock_down_pom.rb' )
97
- m.options[ '-q' ] = nil unless debug
125
+ '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
98
130
  m.verbose = debug
99
-
131
+ m.property( 'jbundler.outputFile', output )
132
+
100
133
  @configurator.configure( m )
101
-
102
- m.exec
134
+
135
+ m.exec( 'dependency:list' )
103
136
  end
104
137
  end
105
138
  end