jar-dependencies 0.1.15 → 0.1.16.pre

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: 5eec8cd538aef1d82692bc4c955a3c3836530fae
4
- data.tar.gz: 0f3c2d90c39f9b162e0cde6e48b2b3a1555ad694
3
+ metadata.gz: 61323d91e4b550079bc732eaacd34c43d6938522
4
+ data.tar.gz: 44458b80a2e517b6a166ac43ad452daa4ce432fc
5
5
  SHA512:
6
- metadata.gz: 6c306e7d5452f34d951982e0614ea333f7c3c634803371b45051b72095e3a68b456fa4cb4162d3e6df73a30f05e4be2471e7e6dfae927d65d0fe81bdda9ca46f
7
- data.tar.gz: 27bfde1dbc03629636af5e140a1deabaa3714370ca7016df96e7df021ba8dbb5740631672df12d80e838aa124758c4acee591eaaee592825ddbd14fd3cc1a204
6
+ metadata.gz: 941f4704dadfeeb3e1074e91eafd9c57efbfbbb48fb7ef4a118b5a1ff56c1f211ff9a3bdf0d5a451381684a63de289b1ab452b62e0d4e6ec35a7f66da2e7c969
7
+ data.tar.gz: f1203ff4ab4b688a23c5f1b2bb6e724a48edd95d4e3cef9f753c411f92944c05d9e21cdfa10c85c827f274f9ba48f67c4737ea981399d45c0fc4f130f74825d9
data/bin/lock_jars ADDED
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+ require 'jar_dependencies'
3
+ require 'optparse'
4
+ options = {}
5
+ optparse = OptionParser.new do|opts|
6
+
7
+ opts.banner = "Usage: #{File.basename(__FILE__)} [options]"
8
+
9
+ opts.separator ''
10
+ opts.separator '* load jars "Jars.lock" from current working directory: `Jars.require_jars_lock!`'
11
+ opts.separator '* classpath features: see `Jars::Classpath'
12
+ opts.separator ''
13
+ opts.separator 'Options:'
14
+ opts.separator ''
15
+
16
+ opts.on( '-v', '--verbose', 'Output more information' ) do |t|
17
+ options[:verbose] = t
18
+ end
19
+
20
+ opts.on( '-d', '--debug', 'Output debug information' ) do |t|
21
+ options[:debug] = t
22
+ end
23
+
24
+ opts.on( '-f', '--force', 'Force creation of Jars.lock' ) do |t|
25
+ options[:force] = t
26
+ end
27
+
28
+ opts.on( '-t', '--tree', 'Show dependency tree' ) do |t|
29
+ options[:tree] = t
30
+ end
31
+
32
+ opts.on( '-u', '--update JAR_COORDINATE', 'Resolves given dependency and use latest version' ) do |u|
33
+ options[:update] = u
34
+ end
35
+
36
+ opts.on( '--vendor-dir DIRECTORY', 'Vendor directory where to copy the installed jars.', 'add this directory to $LOAD_PATH or set JARS_HOME respectively.' ) do |dir|
37
+ options[:vendor_dir] = dir
38
+ end
39
+
40
+ opts.on( '-h', '--help', 'Display this screen' ) do
41
+ puts opts
42
+ exit
43
+ end
44
+ end
45
+ optparse.parse!
46
+
47
+ Jars.lock_down( options[:debug], options[:verbose], options )
@@ -11,6 +11,9 @@ Gem::Specification.new do |s|
11
11
  s.summary = 'manage jar dependencies for gems'
12
12
  s.homepage = 'https://github.com/mkristian/jar-dependencies'
13
13
 
14
+ s.bindir = "bin"
15
+ s.executables = ['lock_jars']
16
+
14
17
  s.license = 'MIT'
15
18
 
16
19
  s.files = `git ls-files`.split($/).select do |file|
@@ -48,6 +48,11 @@ module Jars
48
48
 
49
49
  class << self
50
50
 
51
+ def lock_down( debug = false, verbose = false, options = {} )
52
+ require 'jars/executor' # do this lazy to keep things clean
53
+ Jars::Executor.new( debug, verbose ).lock_down( options )
54
+ end
55
+
51
56
  if defined? JRUBY_VERSION
52
57
  def to_prop( key )
53
58
  key = key.gsub( '_', '.' )
@@ -86,7 +91,11 @@ module Jars
86
91
  def quiet?
87
92
  ( @silent ||= false ) || to_boolean( QUIET )
88
93
  end
89
-
94
+
95
+ def self.jarfile
96
+ ENV[ 'JARFILE' ] || ENV_JAVA[ 'jarfile' ] || ENV[ 'JBUNDLER_JARFILE' ] || ENV_JAVA[ 'jbundler.jarfile' ] || 'Jarfile'
97
+ end
98
+
90
99
  # @deprecated
91
100
  def no_require?; ! require? end
92
101
 
@@ -204,8 +213,8 @@ module Jars
204
213
 
205
214
  def require_jar( group_id, artifact_id, *classifier_version )
206
215
  require_jars_lock
207
- require_jar_with_block( group_id, artifact_id, *classifier_version ) do |group_id, artifact_id, version, classifier|
208
- do_require( group_id, artifact_id, version, classifier )
216
+ require_jar_with_block( group_id, artifact_id, *classifier_version ) do |gid, aid, version, classifier|
217
+ do_require( gid, aid, version, classifier )
209
218
  end
210
219
  end
211
220
 
@@ -0,0 +1,107 @@
1
+ require 'maven/ruby/maven'
2
+ require 'maven/tools/artifact'
3
+ require 'maven/tools/gemspec_dependencies'
4
+ require 'fileutils'
5
+ require 'jar_dependencies'
6
+ module Jars
7
+
8
+ class Executor
9
+
10
+ attr_reader :debug, :verbose
11
+
12
+ def initialize( debug = false, verbose = false )
13
+ @debug = debug
14
+ @verbose = verbose
15
+ end
16
+
17
+ def maven_new
18
+ m = Maven::Ruby::Maven.new
19
+ m.property( 'jars.basedir', File.expand_path( basedir ) )
20
+ m.property( 'jars.jarfile', File.expand_path( Jars.jarfile ) )
21
+ m.property( 'verbose', (debug || verbose) == true )
22
+ if debug
23
+ m.options[ '-X' ] = nil
24
+ elsif verbose
25
+ m.options[ '-e' ] = nil
26
+ else
27
+ m.options[ '-q' ] = nil
28
+ end
29
+ m.verbose = debug
30
+ attach_jar_coordinates( m )
31
+ m
32
+ end
33
+ private :maven_new
34
+
35
+ def maven
36
+ @maven ||= maven_new
37
+ end
38
+
39
+ def basedir
40
+ File.expand_path( '.' )
41
+ end
42
+
43
+ def exec( *args )
44
+ maven.options[ '-f' ] = File.expand_path( '../lock_down_pom.rb', __FILE__ )
45
+ maven.exec( *args )
46
+ end
47
+
48
+ def attach_jar_coordinates( maven )
49
+ load_path = $LOAD_PATH.dup
50
+ require 'bundler/setup'
51
+ done = []
52
+ index = 0
53
+ Gem.loaded_specs.each do |name, spec|
54
+ # TODO get rid of this somehow
55
+ deps = Maven::Tools::GemspecDependencies.new( spec )
56
+ deps.java_dependency_artifacts.each do |a|
57
+ unless done.include? a.key
58
+ maven.property( "jars.#{index}", a.to_s )
59
+ index += 1
60
+ done << a.key
61
+ end
62
+ end
63
+ end
64
+ rescue LoadError
65
+ warn "no bundler found - ignore Gemfile if exists"
66
+ ensure
67
+ $LOAD_PATH.replace( load_path )
68
+ end
69
+
70
+ def lock_down( options = {} )
71
+ vendor_dir = File.expand_path( options[ :vendor_dir ] ) if options[ :vendor_dir ]
72
+ out = File.expand_path( '.jars.output' )
73
+ tree = File.expand_path( '.jars.tree' )
74
+ maven.property( 'jars.outputFile', out )
75
+ maven.property( 'maven.repo.local', Jars.home )
76
+ maven.property( 'jars.home', vendor_dir ) if vendor_dir
77
+ # TODO move into jar-dependencies
78
+ maven.property( 'jars.lock', File.expand_path( Jars.lock ) )
79
+ maven.property( 'jars.force', options[ :force ] == true )
80
+ maven.property( 'jars.update', options[ :update ] ) if options[ :update ]
81
+
82
+ args = [ 'gem:jars-lock' ]
83
+ if options[ :tree ]
84
+ args += [ 'dependency:tree', '-P -gemfile.lock', '-DoutputFile=' + tree ]
85
+ end
86
+
87
+ puts
88
+ puts '-- jar root dependencies --'
89
+ puts
90
+ status = exec( *args )
91
+ exit 1 unless status
92
+ if File.exists?( tree )
93
+ puts
94
+ puts '-- jar dependency tree --'
95
+ puts
96
+ puts File.read( tree )
97
+ puts
98
+ end
99
+ puts
100
+ puts File.read( out ).gsub( /#{File.dirname(out)}\//, '' )
101
+ puts
102
+ ensure
103
+ FileUtils.rm_f out
104
+ FileUtils.rm_f tree
105
+ end
106
+ end
107
+ end
@@ -80,11 +80,11 @@ module Jars
80
80
  end
81
81
 
82
82
  def self.write_require_file( require_filename )
83
- FileUtils.mkdir_p( File.dirname( require_filename ) )
84
- comment = '# this is a generated file, to avoid over-writing it just delete this comment'
85
- if ! File.exists?( require_filename ) || File.read( require_filename ).match( comment )
83
+ warn "deprecated"
84
+ if needs_to_write?(require_filename)
85
+ FileUtils.mkdir_p( File.dirname( require_filename ) )
86
86
  f = File.open( require_filename, 'w' )
87
- f.puts comment
87
+ f.puts COMMENT
88
88
  f.puts "require 'jar_dependencies'"
89
89
  f.puts
90
90
  f
@@ -92,29 +92,58 @@ module Jars
92
92
  end
93
93
 
94
94
  def self.vendor_file( dir, dep )
95
- vendored = File.join( dir, dep.path )
96
- FileUtils.mkdir_p( File.dirname( vendored ) )
97
- FileUtils.cp( dep.file, vendored ) unless dep.system?
95
+ if !dep.system? && dep.type == :jar && dep.scope == :runtime
96
+ vendored = File.join( dir, dep.path )
97
+ FileUtils.mkdir_p( File.dirname( vendored ) )
98
+ FileUtils.cp( dep.file, vendored )
99
+ end
98
100
  end
99
101
 
100
102
  def self.write_dep( file, dir, dep, vendor )
103
+ warn "deprecated"
104
+ print_require_jar( file, dep )
105
+ end
106
+
107
+ def self.print_require_jar( file, dep )
101
108
  return if dep.type != :jar || dep.scope != :runtime
102
109
  if dep.system?
103
110
  file.puts( "require( '#{dep.file}' )" ) if file
104
111
  elsif dep.scope == :runtime
105
- vendor_file( dir, dep ) if vendor
106
112
  file.puts( "require_jar( '#{dep.gav.gsub( ':', "', '" )}' )" ) if file
107
113
  end
108
114
  end
109
115
 
116
+ COMMENT = '# this is a generated file, to avoid over-writing it just delete this comment'
117
+ def self.needs_to_write?(require_filename)
118
+ ( require_filename and not File.exists?( require_filename ) ) or
119
+ File.read( require_filename ).match( COMMENT)
120
+ end
121
+
110
122
  def self.install_deps( deps, dir, require_filename, vendor )
111
- f = write_require_file( require_filename ) if require_filename
123
+ warn "deprecated"
124
+ write_require_jars( deps, require_filename )
125
+ vendor_jars( deps, dir ) if dir && vendor
126
+ end
127
+
128
+ def self.write_require_jars( deps, require_filename )
129
+ if needs_to_write?(require_filename)
130
+ FileUtils.mkdir_p( File.dirname( require_filename ) )
131
+ File.open( require_filename, 'w' ) do |f|
132
+ f.puts COMMENT
133
+ f.puts "require 'jar_dependencies'"
134
+ f.puts
135
+ deps.each do |dep|
136
+ print_require_jar( f, dep )
137
+ end
138
+ yield f if block_given?
139
+ end
140
+ end
141
+ end
142
+
143
+ def self.vendor_jars( deps, dir )
112
144
  deps.each do |dep|
113
- write_dep( f, dir, dep, vendor )
145
+ vendor_file( dir, dep )
114
146
  end
115
- yield f if block_given? and f
116
- ensure
117
- f.close if f
118
147
  end
119
148
 
120
149
  def initialize( spec = nil )
@@ -165,8 +194,8 @@ module Jars
165
194
  private
166
195
 
167
196
  def do_install( vendor, write_require_file )
168
- vendor_dir = File.join( @mvn.basedir, spec.require_path )
169
- jars_file = File.join( vendor_dir, "#{spec.name}_jars.rb" )
197
+ target_dir = File.join( @mvn.basedir, spec.require_path )
198
+ jars_file = File.join( target_dir, "#{spec.name}_jars.rb" )
170
199
 
171
200
  # write out new jars_file it write_require_file is true or
172
201
  # check timestamps:
@@ -177,8 +206,11 @@ module Jars
177
206
  # leave jars_file as is
178
207
  jars_file = nil
179
208
  end
180
- self.class.install_deps( install_dependencies, vendor_dir,
181
- jars_file, vendor )
209
+ deps = install_dependencies()
210
+ self.class.write_require_jars( deps, jars_file )
211
+ if vendor
212
+ self.class.vendor_jars( deps, target_dir )
213
+ end
182
214
  end
183
215
 
184
216
  def install_dependencies
@@ -0,0 +1,35 @@
1
+ bdir = java.lang.System.getProperty( "jars.basedir" )
2
+ jfile = java.lang.System.getProperty( "jars.jarfile" )
3
+
4
+ basedir( bdir )
5
+ if basedir != bdir
6
+ # older maven-tools needs this
7
+ self.instance_variable_set( :@basedir, bdir )
8
+ end
9
+
10
+ ( 0..10000 ).each do |i|
11
+ coord = java.lang.System.getProperty( "jars.#{i}" )
12
+ break unless coord
13
+ artifact = Maven::Tools::Artifact.from_coordinate( coord.to_s )
14
+ # HACK around broken maven-tools
15
+ if artifact.exclusions
16
+ ex = artifact.classifier[1..-1] + ':' + artifact.exclusions.join(':')
17
+ artifact.classifier = nil
18
+ artifact.exclusions = ex.split /,/
19
+ end
20
+ dependency_artifact( artifact )
21
+ end
22
+
23
+ jarfile( jfile )
24
+
25
+ properties( 'project.build.sourceEncoding' => 'utf-8' )
26
+
27
+ plugin_repository :id => 'sonatype-snapshots', :url => 'https://oss.sonatype.org/content/repositories/snapshots'
28
+ jruby_plugin :gem, '1.0.10-SNAPSHOT'
29
+
30
+ plugin :dependency, '2.8'
31
+
32
+ # some output
33
+ model.dependencies.each do |d|
34
+ puts " " + d.group_id + ':' + d.artifact_id + (d.classifier ? ":" + d.classifier : "" ) + ":" + d.version + ':' + (d.scope || 'compile')
35
+ end
@@ -20,6 +20,10 @@ module Jars
20
20
 
21
21
  def initialize( spec = nil )
22
22
  setup( spec )
23
+ rescue StandardError, LoadError => e
24
+ # If spec load fails, skip looking for jar-dependencies
25
+ warn "jar-dependencies: " + e.to_s
26
+ warn e.backtrace.join( "\n" ) if Jars.verbose?
23
27
  end
24
28
 
25
29
  def setup( spec = nil, allow_no_file = false )
@@ -48,10 +52,7 @@ module Jars
48
52
  else
49
53
  raise 'spec must be either String or Gem::Specification'
50
54
  end
51
-
52
55
  @spec = spec
53
- rescue
54
- # for all those strange gemspec we skip looking for jar-dependencies
55
56
  end
56
57
 
57
58
  def ruby_maven_install_options=( options )
@@ -84,6 +85,7 @@ module Jars
84
85
  args << '-DoutputScope=true'
85
86
  args << '-DuseRepositoryLayout=true'
86
87
  args << "-DoutputDirectory=#{Jars.home}"
88
+ # TODO copy pom to tmp dir in case it is not a real file
87
89
  args << '-f' << "#{File.dirname( __FILE__ )}/#{pom}"
88
90
  args << "-Djars.specfile=#{@specfile}"
89
91
 
@@ -139,6 +141,7 @@ module Jars
139
141
  end
140
142
 
141
143
  def install_gem( name )
144
+ puts "Installing gem '#{name}' . . ."
142
145
  require 'rubygems/dependency_installer'
143
146
  jars = Gem.loaded_specs[ 'jar-dependencies' ]
144
147
  dep = jars.dependencies.detect { |d| d.name == name }
@@ -146,8 +149,11 @@ module Jars
146
149
  inst = Gem::DependencyInstaller.new( @options ||= {} )
147
150
  inst.install( name, req ).first
148
151
  rescue => e
149
- warn e.backtrace.join( "\n" ) if Jars.verbose?
150
- raise "there was an error installing '#{name}'. please install it manually: #{e.inspect}"
152
+ if Jars.verbose?
153
+ warn "#{e.inspect}"
154
+ warn e.backtrace.join( "\n" )
155
+ end
156
+ raise "there was an error installing '#{name} (#{req})' #{@option[:domain]}. please install it manually: #{e.inspect}"
151
157
  end
152
158
  end
153
159
  end
data/lib/jars/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Jars
2
- VERSION = '0.1.15'.freeze
2
+ VERSION = '0.1.16.pre'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jar-dependencies
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.15
4
+ version: 0.1.16.pre
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian meier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-06-22 00:00:00.000000000 Z
11
+ date: 2015-07-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: minitest
@@ -69,7 +69,8 @@ dependencies:
69
69
  description: manage jar dependencies for gems and keep track which jar was already loaded using maven artifact coordinates. it warns on version conflicts and loads only ONE jar assuming the first one is compatible to the second one otherwise your project needs to lock down the right version by providing a Jars.lock file.
70
70
  email:
71
71
  - mkristian@web.de
72
- executables: []
72
+ executables:
73
+ - lock_jars
73
74
  extensions: []
74
75
  extra_rdoc_files: []
75
76
  files:
@@ -77,16 +78,19 @@ files:
77
78
  - Mavenfile
78
79
  - Rakefile
79
80
  - Readme.md
81
+ - bin/lock_jars
80
82
  - jar-dependencies.gemspec
81
83
  - lib/jar-dependencies.rb
82
84
  - lib/jar_dependencies.rb
83
85
  - lib/jar_install_post_install_hook.rb
84
86
  - lib/jar_installer.rb
85
87
  - lib/jars/classpath.rb
88
+ - lib/jars/executor.rb
86
89
  - lib/jars/installer.rb
87
90
  - lib/jars/jar_pom.rb
88
91
  - lib/jars/jars_lock_pom.rb
89
92
  - lib/jars/lock.rb
93
+ - lib/jars/lock_down_pom.rb
90
94
  - lib/jars/maven_exec.rb
91
95
  - lib/jars/post_install_hook.rb
92
96
  - lib/jars/setup.rb
@@ -107,9 +111,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
107
111
  version: '0'
108
112
  required_rubygems_version: !ruby/object:Gem::Requirement
109
113
  requirements:
110
- - - '>='
114
+ - - '>'
111
115
  - !ruby/object:Gem::Version
112
- version: '0'
116
+ version: 1.3.1
113
117
  requirements: []
114
118
  rubyforge_project:
115
119
  rubygems_version: 2.4.6