jar-dependencies 0.1.16.pre → 0.2.1

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: 61323d91e4b550079bc732eaacd34c43d6938522
4
- data.tar.gz: 44458b80a2e517b6a166ac43ad452daa4ce432fc
3
+ metadata.gz: 9a8eb8cba64115cb2e8051ccdcae9fcb547795c7
4
+ data.tar.gz: 6887fefbfe325001e00fa2a6e35cd4bf19649775
5
5
  SHA512:
6
- metadata.gz: 941f4704dadfeeb3e1074e91eafd9c57efbfbbb48fb7ef4a118b5a1ff56c1f211ff9a3bdf0d5a451381684a63de289b1ab452b62e0d4e6ec35a7f66da2e7c969
7
- data.tar.gz: f1203ff4ab4b688a23c5f1b2bb6e724a48edd95d4e3cef9f753c411f92944c05d9e21cdfa10c85c827f274f9ba48f67c4737ea981399d45c0fc4f130f74825d9
6
+ metadata.gz: 5be5306505b67b6872d483c504b0abdfef02d99b39c1d2e39f8d18dca1795e5ef0e02590b1ffb9162b2d3cb407f5e57a9f0118f15bbd42094b6ad96f8e01db4c
7
+ data.tar.gz: f99747cdc5985dcaedd93d9d30f6d614f7c0e8e132217cdb5339eba7757528c1cbc696a6131fe186de7899c486598a462239c4917463aa6af9ddcb69ee3830b6
data/Mavenfile CHANGED
@@ -14,13 +14,13 @@ end
14
14
  pro = @model.profiles.detect { |p| p.id.to_sym == :gemfile } || @model
15
15
  ruby_maven = pro.dependencies.detect { |d| d.artifact_id == 'ruby-maven' }
16
16
 
17
- properties( 'jruby.versions' => ['1.7.12', '${jruby.version}', '9.0.0.0.rc1'
17
+ properties( 'jruby.versions' => ['1.7.12', '${jruby.version}', '9.0.1.0'
18
18
  ].join(','),
19
19
  'jruby.modes' => ['1.9', '2.0', '2.1'].join(','),
20
20
  # just lock the version
21
21
  'bundler.version' => '1.9.2',
22
22
  'ruby-maven.version' => ruby_maven.version,
23
- 'jruby.version' => '1.7.20',
23
+ 'jruby.version' => '1.7.22',
24
24
  'jruby.plugins.version' => '1.0.9',
25
25
  'push.skip' => true )
26
26
 
@@ -30,7 +30,8 @@ plugin :invoker, '1.8' do
30
30
  :projectsDirectory => 'integration',
31
31
  :streamLogs => true,
32
32
  :goals => ['install'],
33
- :postBuildHookScript => 'verify.bsh',
33
+ :preBuildHookScript => 'setup.bsh',
34
+ :postBuildHookScript => 'verify.bsh',
34
35
  :cloneProjectsTo => '${project.build.directory}',
35
36
  :properties => { 'jar-dependencies.version' => '${project.version}',
36
37
  'jruby.version' => '${jruby.version}',
data/bin/lock_jars CHANGED
@@ -6,6 +6,8 @@ optparse = OptionParser.new do|opts|
6
6
 
7
7
  opts.banner = "Usage: #{File.basename(__FILE__)} [options]"
8
8
 
9
+ opts.separator ''
10
+ opts.separator 'THIS IS A EXPERIMETAL FEATURE !!!'
9
11
  opts.separator ''
10
12
  opts.separator '* load jars "Jars.lock" from current working directory: `Jars.require_jars_lock!`'
11
13
  opts.separator '* classpath features: see `Jars::Classpath'
@@ -29,7 +31,7 @@ optparse = OptionParser.new do|opts|
29
31
  options[:tree] = t
30
32
  end
31
33
 
32
- opts.on( '-u', '--update JAR_COORDINATE', 'Resolves given dependency and use latest version' ) do |u|
34
+ opts.on( '-u', '--update JAR_COORDINATE', 'Resolves given dependency and use latest version. JAR_COORDINATE is either artifact_id or group_id:artifact_id' ) do |u|
33
35
  options[:update] = u
34
36
  end
35
37
 
@@ -4,7 +4,7 @@ Gem::Specification.new do |s|
4
4
  s.name = 'jar-dependencies'
5
5
 
6
6
  path = File.expand_path('lib/jars/version.rb', File.dirname(__FILE__))
7
- s.version = File.read(path).match( /.*VERSION\s*=\s*['"](.*)['"]/m )[1]
7
+ s.version = File.read(path).match( /\s*VERSION\s*=\s*['"](.*)['"]/ )[1]
8
8
 
9
9
  s.author = 'christian meier'
10
10
  s.email = [ 'mkristian@web.de' ]
@@ -12,7 +12,8 @@ Gem::Specification.new do |s|
12
12
  s.homepage = 'https://github.com/mkristian/jar-dependencies'
13
13
 
14
14
  s.bindir = "bin"
15
- s.executables = ['lock_jars']
15
+ LOCK_JARS = 'lock_jars'
16
+ s.executables = [LOCK_JARS]
16
17
 
17
18
  s.license = 'MIT'
18
19
 
@@ -26,8 +27,20 @@ Gem::Specification.new do |s|
26
27
 
27
28
  s.add_development_dependency 'minitest', '~> 5.3'
28
29
  s.add_development_dependency 'rake', '~> 10.2'
29
- s.add_development_dependency 'ruby-maven', '~> 3.3.0'
30
- s.add_development_dependency 'ruby-maven-libs', '~> 3.3.0'
30
+ RUBY_MAVEN_VERSION = '~> 3.3.3'
31
+ s.add_development_dependency 'ruby-maven', RUBY_MAVEN_VERSION
32
+
33
+ s.post_install_message = <<EOF
34
+
35
+ if you want to use the executable #{LOCK_JARS} then install ruby-maven gem before using #{LOCK_JARS}
36
+
37
+ $ gem install ruby-maven #{RUBY_MAVEN_VERSION}
38
+
39
+ or add it as deveopment dependency to your Gemfile
40
+
41
+ gem 'ruby-maven', #{RUBY_MAVEN_VERSION}
42
+
43
+ EOF
31
44
  end
32
45
 
33
46
  # vim: syntax=Ruby
@@ -42,15 +42,13 @@ module Jars
42
42
  DEBUG = 'JARS_DEBUG'.freeze
43
43
  # vendor jars inside gem when installing gem
44
44
  VENDOR = 'JARS_VENDOR'.freeze
45
- # resolve jars from Jars.lock
46
- RESOLVE = 'JARS_RESOLVE'.freeze
47
45
  end
48
46
 
49
47
  class << self
50
48
 
51
49
  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 )
50
+ require 'jars/lock_down' # do this lazy to keep things clean
51
+ Jars::LockDown.new( debug, verbose ).lock_down( options )
54
52
  end
55
53
 
56
54
  if defined? JRUBY_VERSION
@@ -92,7 +90,7 @@ module Jars
92
90
  ( @silent ||= false ) || to_boolean( QUIET )
93
91
  end
94
92
 
95
- def self.jarfile
93
+ def jarfile
96
94
  ENV[ 'JARFILE' ] || ENV_JAVA[ 'jarfile' ] || ENV[ 'JBUNDLER_JARFILE' ] || ENV_JAVA[ 'jbundler.jarfile' ] || 'Jarfile'
97
95
  end
98
96
 
@@ -111,10 +109,6 @@ module Jars
111
109
  to_boolean( VENDOR )
112
110
  end
113
111
 
114
- def resolve?
115
- to_boolean( RESOLVE )
116
- end
117
-
118
112
  def no_more_warnings
119
113
  @silent = true
120
114
  end
@@ -130,8 +124,12 @@ module Jars
130
124
  def lock_path( basedir = nil )
131
125
  deps = self.lock
132
126
  return deps if File.exists?( deps )
133
- deps = File.join( basedir || '.', self.lock )
134
- deps if File.exists?( deps )
127
+ basedir ||= '.'
128
+ [ '.', 'jars', 'vendor/jars' ].each do |dir|
129
+ file = File.join( basedir, dir, self.lock )
130
+ return file if File.exists?( file )
131
+ end
132
+ nil
135
133
  end
136
134
 
137
135
  def local_maven_repo
@@ -198,6 +196,19 @@ module Jars
198
196
  end
199
197
  end
200
198
 
199
+ def setup( options = nil )
200
+ case options
201
+ when Symbol
202
+ require_jars_lock!( options )
203
+ when Hash
204
+ @_jars_home = options[:jars_home]
205
+ @_jars_lock = options[:jars_lock]
206
+ require_jars_lock!( options[:scope] || :runtime )
207
+ else
208
+ require_jars_lock!
209
+ end
210
+ end
211
+
201
212
  def require_jars_lock
202
213
  @@jars_lock ||= false
203
214
  unless @@jars_lock
@@ -295,7 +306,7 @@ module Jars
295
306
  require jar
296
307
  end
297
308
  rescue LoadError => e
298
- raise "\n\n\tyou might need to reinstall the gem which depends on the missing jar or in case there is Jars.lock then JARS_RESOLVE=true will install the missing jars\n\n" + e.message + " (LoadError)"
309
+ raise "\n\n\tyou might need to reinstall the gem which depends on the missing jar or in case there is Jars.lock then resolve the jars with `lock_jars` command\n\n" + e.message + " (LoadError)"
299
310
  end
300
311
 
301
312
  end # class << self
@@ -22,7 +22,6 @@ module Jars
22
22
 
23
23
  def dependencies_list
24
24
  if @deps ||= Jars.lock_path( mvn.basedir )
25
- mvn.resolve_dependencies( @deps ) if Jars.resolve?
26
25
  @deps
27
26
  else
28
27
  resolve_dependencies
@@ -0,0 +1,208 @@
1
+ module Jars
2
+
3
+ class MavenVersion < String
4
+ def self.new(*args)
5
+ if args.size == 0 || (args.size == 1 && args[0].nil?)
6
+ nil
7
+ else
8
+ low, high = convert(args[0])
9
+ low, high = convert(args[1], low, high) if args[1] =~ /[=~><]/
10
+ if low == high
11
+ low
12
+ else
13
+ super "#{low || '[0'},#{high || ')'}"
14
+ end
15
+ end
16
+ end
17
+
18
+ private
19
+
20
+ def self.convert(arg, low = nil, high = nil)
21
+ if arg =~ /~>/
22
+ val = arg.sub(/~>\s*/, '')
23
+ last = val=~/\./ ? val.sub(/\.[0-9]*[a-z]+.*$/, '').sub(/\.[^.]+$/, '.99999') : '99999'
24
+ ["[#{snapshot_version(val)}", "#{snapshot_version(last)}]"]
25
+ elsif arg =~ />=/
26
+ val = arg.sub(/>=\s*/, '')
27
+ ["[#{snapshot_version(val)}", (nil || high)]
28
+ elsif arg =~ /<=/
29
+ val = arg.sub(/<=\s*/, '')
30
+ [(nil || low), "#{snapshot_version(val)}]"]
31
+ # treat '!' the same way as '>' since maven can not describe such range
32
+ elsif arg =~ /[!>]/
33
+ val = arg.sub(/[!>]\s*/, '')
34
+ ["(#{snapshot_version(val)}", (nil || high)]
35
+ elsif arg =~ /</
36
+ val = arg.sub(/<\s*/, '')
37
+ [(nil || low), "#{snapshot_version(val)})"]
38
+ elsif arg =~ /\=/
39
+ val = arg.sub(/=\s*/, '')
40
+ # for prereleased version pick the maven version (no version range)
41
+ if val.match /[a-z]|[A-Z]/
42
+ [ val, val ]
43
+ else
44
+ ["[#{val}", "#{val}.0.0.0.0.1)"]
45
+ end
46
+ else
47
+ # no conversion here, i.e. assume maven version
48
+ [arg, arg]
49
+ end
50
+ end
51
+
52
+ def self.snapshot_version( val )
53
+ if val.match(/[a-z]|[A-Z]/) && !val.match(/-SNAPSHOT|[${}]/)
54
+ val + '-SNAPSHOT'
55
+ else
56
+ val
57
+ end
58
+ end
59
+ end
60
+
61
+ class GemspecArtifacts
62
+
63
+ class Exclusion
64
+ attr_reader :group_id, :artifact_id
65
+
66
+ def initialize(line)
67
+ @group_id, @artifact_id = line.gsub(/['"]/, '').strip.split( ':' )
68
+ @artifact_id.strip!
69
+ end
70
+
71
+ def to_s
72
+ "#{@group_id}:#{@artifact_id}"
73
+ end
74
+ end
75
+
76
+ class Exclusions < Array
77
+
78
+ def to_s
79
+ "[#{join(', ')}]"
80
+ end
81
+
82
+ def initialize( line )
83
+ super()
84
+ line.gsub(/'"|^\s*\[|\]\s*$/, '').split( /,\s*/ ).each do |exclusion|
85
+ self.<< Exclusion.new( exclusion )
86
+ end
87
+ freeze
88
+ end
89
+ end
90
+
91
+ class Artifact
92
+
93
+ attr_reader :type, :group_id, :artifact_id, :classifier, :version, :scope, :exclusions
94
+
95
+ ALLOWED_TYPES = ['jar', 'pom']
96
+
97
+ def initialize( options, *args )
98
+ @type, @group_id, @artifact_id, @classifier, @version, @exclusions = *args
99
+ options.each do |k,v|
100
+ instance_variable_set( "@#{k}", v )
101
+ end
102
+ end
103
+
104
+ def self.new( line )
105
+ line = line.strip
106
+ index = line.index( /\s/ )
107
+ if index.nil?
108
+ return nil
109
+ end
110
+ type = line[0..index].strip
111
+ unless ALLOWED_TYPES.member?( type )
112
+ return nil
113
+ end
114
+ line = line[index..-1]
115
+ line.gsub!(/['"]/, '')
116
+ line.strip!
117
+
118
+ options = {}
119
+ line.sub!(/,\s*:exclusions\s*(:|=>)\s*(\[[a-zA-Z0-9_:,]+\])/) do
120
+ options[ :exclusions ] = Exclusions.new( $2.strip )
121
+ ''
122
+ end
123
+ line.sub!(/,\s*:([a-z]+)\s*(:|=>)\s*(:?[a-zA-Z0-9_]+)/) do
124
+ options[ $1.to_sym ] = $3.sub(/^:/, '')
125
+ ''
126
+ end
127
+
128
+ exclusions = nil
129
+ line.sub!(/[,:]\s*\[(.+:.+,?\s*)+\]$/) do |a|
130
+ exclusions = Exclusions.new( a[1..-1].strip )
131
+ ''
132
+ end
133
+
134
+ line.strip!
135
+ line.gsub!(/,\s*/, ':')
136
+
137
+ if line.match(/[\[\(\)\]]/)
138
+ index = line.index(/[\[\(].+$/)
139
+ version = line[index..-1].sub(/:/, ', ')
140
+ line = line[0..index - 1].strip.sub(/:$/, '')
141
+ else
142
+ index = line.index(/[:][^:]+$/)
143
+ version = line[index + 1..-1]
144
+ line = line[0..index - 1].strip
145
+ end
146
+
147
+ case line.count(':')
148
+ when 2
149
+ group_id, artifact_id, classifier = line.split(':')
150
+ when 1
151
+ group_id, artifact_id = line.split(':')
152
+ classifier = nil
153
+ else
154
+ warn line
155
+ return nil
156
+ end
157
+ super( options, type, group_id, artifact_id, classifier, version, exclusions )
158
+ end
159
+
160
+ def to_s
161
+ args = [@group_id, @artifact_id]
162
+ args << @classifier if @classifier
163
+ args << @version
164
+ args << @exclusions.to_s if @exclusions
165
+ "#{@type} #{group_id}:#{args[1..-1].join(', ')}"
166
+ end
167
+
168
+ def to_gacv
169
+ args = [@group_id, @artifact_id]
170
+ args << @classifier if @classifier
171
+ args << @version
172
+ args.join(':')
173
+ end
174
+
175
+ def to_coord
176
+ args = [@group_id, @artifact_id]
177
+ args << @classifier if @classifier
178
+ args << @type
179
+ args << MavenVersion.new( @version )
180
+ args.join(':')
181
+ end
182
+
183
+ def key
184
+ args = [@group_id, @artifact_id]
185
+ args << @classifier if @classifier
186
+ args.join(':')
187
+ end
188
+ end
189
+
190
+ attr_reader :artifacts
191
+
192
+ def initialize( spec )
193
+ @artifacts = []
194
+ spec.requirements.each do |req|
195
+ req.split( /\n/ ).each do |line|
196
+ if ( a = Artifact.new( line ) )
197
+ @artifacts << a
198
+ end
199
+ end
200
+ end
201
+ @artifacts.freeze
202
+ end
203
+
204
+ def [](index)
205
+ @artifacts[index]
206
+ end
207
+ end
208
+ end
@@ -1,6 +1,6 @@
1
1
  # this file is maven DSL and used by maven via jars/maven_exec.rb
2
2
 
3
- specfile = java.lang.System.getProperty('jars.specfile')
3
+ specfile = ENV_JAVA[ 'jars.specfile' ]
4
4
 
5
5
  # needed since the gemspec does not allow absolute files
6
6
  basedir( File.dirname( specfile ) )
@@ -1,33 +1,29 @@
1
- require 'maven/ruby/maven'
2
- require 'maven/tools/artifact'
3
- require 'maven/tools/gemspec_dependencies'
4
1
  require 'fileutils'
5
2
  require 'jar_dependencies'
3
+ require 'jars/version'
4
+ require 'jars/maven_factory'
5
+ require 'jars/gemspec_artifacts'
6
+
6
7
  module Jars
7
-
8
- class Executor
8
+ class LockDown
9
9
 
10
10
  attr_reader :debug, :verbose
11
11
 
12
- def initialize( debug = false, verbose = false )
12
+ def initialize( debug, verbose )
13
13
  @debug = debug
14
14
  @verbose = verbose
15
15
  end
16
16
 
17
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 )
18
+ factory = MavenFactory.new( {}, @debug, @verbose )
19
+ pom = File.expand_path( '../lock_down_pom.rb', __FILE__ )
20
+ m = factory.maven_new( pom )
21
+ m[ 'jruby.plugins.version' ] = Jars::JRUBY_PLUGINS_VERSION
22
+ m[ 'dependency.plugin.version' ] = Jars::DEPENDENCY_PLUGIN_VERSION
23
+ m[ 'jars.basedir' ] = File.expand_path( basedir )
24
+ jarfile = File.expand_path( Jars.jarfile )
25
+ m[ 'jars.jarfile' ] = jarfile if File.exists?( jarfile )
26
+ attach_jar_coordinates_from_bundler_dependencies( m )
31
27
  m
32
28
  end
33
29
  private :maven_new
@@ -40,29 +36,35 @@ module Jars
40
36
  File.expand_path( '.' )
41
37
  end
42
38
 
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 )
39
+ def attach_jar_coordinates_from_bundler_dependencies( maven )
49
40
  load_path = $LOAD_PATH.dup
50
41
  require 'bundler/setup'
51
42
  done = []
52
43
  index = 0
53
44
  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|
45
+ deps = GemspecArtifacts.new( spec )
46
+ deps.artifacts.each do |a|
57
47
  unless done.include? a.key
58
- maven.property( "jars.#{index}", a.to_s )
48
+ maven.property( "jars.#{index}", a.to_coord )
49
+ if a.exclusions
50
+ jndex = 0
51
+ a.exclusions.each do |ex|
52
+ maven.property( "jars.#{index}.exclusions.#{jndex}", ex.to_s )
53
+ end
54
+ end
55
+ maven.property( "jars.#{index}.scope", a.scope ) if a.scope
59
56
  index += 1
60
57
  done << a.key
61
58
  end
62
59
  end
63
60
  end
64
- rescue LoadError
65
- warn "no bundler found - ignore Gemfile if exists"
61
+ rescue LoadError => e
62
+ if Jars.verbose?
63
+ warn e.message
64
+ warn "no bundler found - ignore Gemfile if exists"
65
+ end
66
+ rescue SystemExit
67
+ # we want to continue
66
68
  ensure
67
69
  $LOAD_PATH.replace( load_path )
68
70
  end
@@ -74,7 +76,6 @@ module Jars
74
76
  maven.property( 'jars.outputFile', out )
75
77
  maven.property( 'maven.repo.local', Jars.home )
76
78
  maven.property( 'jars.home', vendor_dir ) if vendor_dir
77
- # TODO move into jar-dependencies
78
79
  maven.property( 'jars.lock', File.expand_path( Jars.lock ) )
79
80
  maven.property( 'jars.force', options[ :force ] == true )
80
81
  maven.property( 'jars.update', options[ :update ] ) if options[ :update ]
@@ -87,7 +88,7 @@ module Jars
87
88
  puts
88
89
  puts '-- jar root dependencies --'
89
90
  puts
90
- status = exec( *args )
91
+ status = maven.exec( *args )
91
92
  exit 1 unless status
92
93
  if File.exists?( tree )
93
94
  puts
@@ -1,5 +1,6 @@
1
- bdir = java.lang.System.getProperty( "jars.basedir" )
2
- jfile = java.lang.System.getProperty( "jars.jarfile" )
1
+ # this file is maven DSL and used by maven via jars/executor.rb
2
+
3
+ bdir = ENV_JAVA[ "jars.basedir" ]
3
4
 
4
5
  basedir( bdir )
5
6
  if basedir != bdir
@@ -8,28 +9,37 @@ if basedir != bdir
8
9
  end
9
10
 
10
11
  ( 0..10000 ).each do |i|
11
- coord = java.lang.System.getProperty( "jars.#{i}" )
12
+ coord = ENV_JAVA[ "jars.#{i}" ]
12
13
  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 /,/
14
+ artifact = Maven::Tools::Artifact.from_coordinate( coord )
15
+ exclusions = []
16
+ ( 0..10000 ).each do |j|
17
+ exclusion = ENV_JAVA[ "jars.#{i}.exclusions.#{j}" ]
18
+ break unless exclusion
19
+ exclusions << exclusion
20
+ end
21
+ scope = ENV_JAVA[ "jars.#{i}.scope" ]
22
+ artifact.scope = scope if scope
23
+ dependency_artifact( artifact ) do
24
+ exclusions.each do |ex|
25
+ exclusion ex
26
+ end
19
27
  end
20
- dependency_artifact( artifact )
21
28
  end
22
29
 
23
- jarfile( jfile )
30
+ jruby_plugin :gem, ENV_JAVA[ "jruby.plugins.version" ]
24
31
 
25
- properties( 'project.build.sourceEncoding' => 'utf-8' )
32
+ jfile = ENV_JAVA[ "jars.jarfile" ]
33
+ jarfile( jfile ) if jfile
26
34
 
27
- plugin_repository :id => 'sonatype-snapshots', :url => 'https://oss.sonatype.org/content/repositories/snapshots'
28
- jruby_plugin :gem, '1.0.10-SNAPSHOT'
35
+ gemspec rescue nil
36
+
37
+ properties( 'project.build.sourceEncoding' => 'utf-8' )
29
38
 
30
- plugin :dependency, '2.8'
39
+ plugin :dependency, ENV_JAVA[ "dependency.plugin.version" ]
31
40
 
32
41
  # some output
33
42
  model.dependencies.each do |d|
34
43
  puts " " + d.group_id + ':' + d.artifact_id + (d.classifier ? ":" + d.classifier : "" ) + ":" + d.version + ':' + (d.scope || 'compile')
44
+ puts " exclusions: " + d.exclusions.collect{ |e| e.group_id + ':' + e.artifact_id }.join unless d.exclusions.empty?
35
45
  end
@@ -1,4 +1,5 @@
1
1
  require 'jar_dependencies'
2
+ require 'jars/maven_factory'
2
3
 
3
4
  module Jars
4
5
  class MavenExec
@@ -19,6 +20,7 @@ module Jars
19
20
  attr_reader :basedir, :spec, :specfile
20
21
 
21
22
  def initialize( spec = nil )
23
+ @options = {}
22
24
  setup( spec )
23
25
  rescue StandardError, LoadError => e
24
26
  # If spec load fails, skip looking for jar-dependencies
@@ -56,104 +58,22 @@ module Jars
56
58
  end
57
59
 
58
60
  def ruby_maven_install_options=( options )
59
- @options = options.dup
60
- @options.delete( :ignore_dependencies )
61
+ @options = options
61
62
  end
62
63
 
63
64
  def resolve_dependencies_list( file )
64
- do_resolve_dependencies( *setup_arguments( 'jar_pom.rb', 'dependency:copy-dependencies', 'dependency:list', "-DoutputFile=#{file}" ) )
65
- end
66
-
67
- def resolve_dependencies( file )
68
- do_resolve_dependencies( *setup_arguments( 'jars_lock_pom.rb', 'dependency:copy-dependencies', '-DexcludeTransitive=true' , "-Djars.lock=#{file}") )
69
- end
70
-
71
- private
72
-
73
- def do_resolve_dependencies( *args )
74
- lazy_load_maven
75
-
76
- maven = Maven::Ruby::Maven.new
77
- maven.verbose = Jars.verbose?
78
- maven.exec( *args )
79
- end
80
-
81
- def setup_arguments( pom, *goals )
82
- args = goals.dup
83
- args << '-DoutputAbsoluteArtifactFilename=true'
84
- args << '-DincludeTypes=jar'
85
- args << '-DoutputScope=true'
86
- args << '-DuseRepositoryLayout=true'
87
- args << "-DoutputDirectory=#{Jars.home}"
88
- # TODO copy pom to tmp dir in case it is not a real file
89
- args << '-f' << "#{File.dirname( __FILE__ )}/#{pom}"
90
- args << "-Djars.specfile=#{@specfile}"
91
-
92
- if Jars.debug?
93
- args << '-X'
94
- elsif not Jars.verbose?
95
- args << '--quiet'
96
- end
97
-
98
- # TODO what todo with https proxy ?
99
- # FIX this proxy settings seems not to work
100
- if (proxy = Gem.configuration[ :http_proxy ]).is_a?( String )
101
- require 'uri'; uri = URI.parse( proxy )
102
- args << "-DproxySet=true"
103
- args << "-DproxyHost=#{uri.host}"
104
- args << "-DproxyPort=#{uri.port}"
105
- end
106
-
107
- if Jars.maven_settings
108
- args << '-s'
109
- args << Jars.maven_settings
110
- end
111
-
112
- args << "-Dmaven.repo.local=#{java.io.File.new( Jars.local_maven_repo ).absolute_path}"
113
-
114
- args
115
- end
116
-
117
- def lazy_load_maven
118
- add_gem_to_load_path( 'ruby-maven-libs' )
119
- add_gem_to_load_path( 'ruby-maven' )
120
- require 'maven/ruby/maven'
121
- end
122
-
123
- def find_spec_via_rubygems( name )
124
- require 'rubygems/dependency'
125
- dep = Gem::Dependency.new( name )
126
- dep.matching_specs( true ).last
127
- end
128
-
129
- def add_gem_to_load_path( name )
130
- # if the gem is already activated => good
131
- return if Gem.loaded_specs[ name ]
132
- # just install gem if needed and add it to the load_path
133
- # and leave activated gems as they are
134
- unless spec = find_spec_via_rubygems( name )
135
- spec = install_gem( name )
136
- end
137
- unless spec
138
- raise "failed to resolve gem '#{name}' if you're using Bundler add it as a dependency"
139
- end
140
- $LOAD_PATH << File.join( spec.full_gem_path, spec.require_path )
141
- end
142
-
143
- def install_gem( name )
144
- puts "Installing gem '#{name}' . . ."
145
- require 'rubygems/dependency_installer'
146
- jars = Gem.loaded_specs[ 'jar-dependencies' ]
147
- dep = jars.dependencies.detect { |d| d.name == name }
148
- req = dep.nil? ? Gem::Requirement.create( '>0' ) : dep.requirement
149
- inst = Gem::DependencyInstaller.new( @options ||= {} )
150
- inst.install( name, req ).first
151
- rescue => e
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}"
65
+ factory = MavenFactory.new( @options )
66
+ maven = factory.maven_new( File.expand_path( '../gemspec_pom.rb', __FILE__ ) )
67
+
68
+ maven[ 'outputAbsoluteArtifactFilename' ] = 'true'
69
+ maven[ 'includeTypes' ] = 'jar'
70
+ maven[ 'outputScope' ] = 'true'
71
+ maven[ 'useRepositoryLayout' ] = 'true'
72
+ maven[ 'outputDirectory' ] = "#{Jars.home}"
73
+ maven[ 'jars.specfile' ] = "#{@specfile}"
74
+ maven[ 'outputFile' ] = "#{file}"
75
+
76
+ maven.exec( 'dependency:copy-dependencies', 'dependency:list' )
157
77
  end
158
78
  end
159
79
  end
@@ -0,0 +1,100 @@
1
+ require 'jar_dependencies'
2
+
3
+ module Jars
4
+ class MavenFactory
5
+
6
+ attr_reader :debug, :verbose
7
+
8
+ def initialize( options = nil, debug = Jars.debug?, verbose = Jars.verbose? )
9
+ @options = (options || {}).dup
10
+ @options.delete( :ignore_dependencies )
11
+ @debug = debug
12
+ @verbose = verbose
13
+ end
14
+
15
+ def maven_new( pom )
16
+ lazy_load_maven
17
+ maven = setup( Maven::Ruby::Maven.new )
18
+
19
+ # TODO copy pom to tmp dir in case it is not a real file
20
+ maven.options[ '-f' ] = pom
21
+ maven
22
+ end
23
+
24
+ private
25
+
26
+ def setup( maven )
27
+ maven.verbose = @verbose
28
+ if @debug
29
+ maven.options[ '-X' ] = nil
30
+ end
31
+ if @verbose
32
+ maven.options[ '-e' ] = nil
33
+ elsif not @debug
34
+ maven.options[ '--quiet' ] = nil
35
+ end
36
+ maven[ 'verbose' ] = (@debug || @verbose) == true
37
+
38
+ # TODO what todo with https proxy ?
39
+ # FIX this proxy settings seems not to work
40
+ if (proxy = Gem.configuration[ :http_proxy ]).is_a?( String )
41
+ require 'uri'; uri = URI.parse( proxy )
42
+ maven['proxySet'] = 'true'
43
+ maven['proxyHost'] = "#{uri.host}"
44
+ maven['proxyPort'] = "#{uri.port}"
45
+ end
46
+
47
+ if Jars.maven_settings
48
+ maven.options[ '-s' ] = Jars.maven_settings
49
+ end
50
+
51
+ maven[ 'maven.repo.local' ] = "#{java.io.File.new( Jars.local_maven_repo ).absolute_path}"
52
+
53
+ maven
54
+ end
55
+
56
+ private
57
+
58
+ def lazy_load_maven
59
+ add_gem_to_load_path( 'ruby-maven-libs' )
60
+ add_gem_to_load_path( 'ruby-maven' )
61
+ require 'maven/ruby/maven'
62
+ end
63
+
64
+ def find_spec_via_rubygems( name )
65
+ require 'rubygems/dependency'
66
+ dep = Gem::Dependency.new( name )
67
+ dep.matching_specs( true ).last
68
+ end
69
+
70
+ def add_gem_to_load_path( name )
71
+ # if the gem is already activated => good
72
+ return if Gem.loaded_specs[ name ]
73
+ # just install gem if needed and add it to the load_path
74
+ # and leave activated gems as they are
75
+ unless spec = find_spec_via_rubygems( name )
76
+ spec = install_gem( name )
77
+ end
78
+ unless spec
79
+ raise "failed to resolve gem '#{name}' if you're using Bundler add it as a dependency"
80
+ end
81
+ $LOAD_PATH << File.join( spec.full_gem_path, spec.require_path )
82
+ end
83
+
84
+ def install_gem( name )
85
+ puts "Installing gem '#{name}' . . ."
86
+ require 'rubygems/dependency_installer'
87
+ jars = Gem.loaded_specs[ 'jar-dependencies' ]
88
+ dep = jars.dependencies.detect { |d| d.name == name }
89
+ req = dep.nil? ? Gem::Requirement.create( '>0' ) : dep.requirement
90
+ inst = Gem::DependencyInstaller.new( @options ||= {} )
91
+ inst.install( name, req ).first
92
+ rescue => e
93
+ if Jars.verbose?
94
+ warn "#{e.inspect}"
95
+ warn e.backtrace.join( "\n" )
96
+ end
97
+ raise "there was an error installing '#{name} (#{req})' #{@option[:domain]}. please install it manually: #{e.inspect}"
98
+ end
99
+ end
100
+ end
data/lib/jars/setup.rb CHANGED
@@ -4,4 +4,4 @@
4
4
 
5
5
  require 'jar_dependencies'
6
6
 
7
- Jars.require_jars_lock!
7
+ Jars.setup
data/lib/jars/version.rb CHANGED
@@ -1,3 +1,5 @@
1
1
  module Jars
2
- VERSION = '0.1.16.pre'.freeze
2
+ VERSION = '0.2.1'.freeze
3
+ JRUBY_PLUGINS_VERSION = '1.0.10'.freeze
4
+ DEPENDENCY_PLUGIN_VERSION = '2.8'.freeze
3
5
  end
metadata CHANGED
@@ -1,71 +1,57 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jar-dependencies
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.16.pre
4
+ version: 0.2.1
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-07-10 00:00:00.000000000 Z
11
+ date: 2015-09-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: minitest
15
- version_requirements: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - ~>
18
- - !ruby/object:Gem::Version
19
- version: '5.3'
20
14
  requirement: !ruby/object:Gem::Requirement
21
15
  requirements:
22
16
  - - ~>
23
17
  - !ruby/object:Gem::Version
24
18
  version: '5.3'
19
+ name: minitest
25
20
  prerelease: false
26
21
  type: :development
27
- - !ruby/object:Gem::Dependency
28
- name: rake
29
22
  version_requirements: !ruby/object:Gem::Requirement
30
23
  requirements:
31
24
  - - ~>
32
25
  - !ruby/object:Gem::Version
33
- version: '10.2'
26
+ version: '5.3'
27
+ - !ruby/object:Gem::Dependency
34
28
  requirement: !ruby/object:Gem::Requirement
35
29
  requirements:
36
30
  - - ~>
37
31
  - !ruby/object:Gem::Version
38
32
  version: '10.2'
33
+ name: rake
39
34
  prerelease: false
40
35
  type: :development
41
- - !ruby/object:Gem::Dependency
42
- name: ruby-maven
43
36
  version_requirements: !ruby/object:Gem::Requirement
44
37
  requirements:
45
38
  - - ~>
46
39
  - !ruby/object:Gem::Version
47
- version: 3.3.0
40
+ version: '10.2'
41
+ - !ruby/object:Gem::Dependency
48
42
  requirement: !ruby/object:Gem::Requirement
49
43
  requirements:
50
44
  - - ~>
51
45
  - !ruby/object:Gem::Version
52
- version: 3.3.0
46
+ version: 3.3.3
47
+ name: ruby-maven
53
48
  prerelease: false
54
49
  type: :development
55
- - !ruby/object:Gem::Dependency
56
- name: ruby-maven-libs
57
50
  version_requirements: !ruby/object:Gem::Requirement
58
51
  requirements:
59
52
  - - ~>
60
53
  - !ruby/object:Gem::Version
61
- version: 3.3.0
62
- requirement: !ruby/object:Gem::Requirement
63
- requirements:
64
- - - ~>
65
- - !ruby/object:Gem::Version
66
- version: 3.3.0
67
- prerelease: false
68
- type: :development
54
+ version: 3.3.3
69
55
  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
56
  email:
71
57
  - mkristian@web.de
@@ -85,13 +71,14 @@ files:
85
71
  - lib/jar_install_post_install_hook.rb
86
72
  - lib/jar_installer.rb
87
73
  - lib/jars/classpath.rb
88
- - lib/jars/executor.rb
74
+ - lib/jars/gemspec_artifacts.rb
75
+ - lib/jars/gemspec_pom.rb
89
76
  - lib/jars/installer.rb
90
- - lib/jars/jar_pom.rb
91
- - lib/jars/jars_lock_pom.rb
92
77
  - lib/jars/lock.rb
78
+ - lib/jars/lock_down.rb
93
79
  - lib/jars/lock_down_pom.rb
94
80
  - lib/jars/maven_exec.rb
81
+ - lib/jars/maven_factory.rb
95
82
  - lib/jars/post_install_hook.rb
96
83
  - lib/jars/setup.rb
97
84
  - lib/jars/version.rb
@@ -100,7 +87,10 @@ homepage: https://github.com/mkristian/jar-dependencies
100
87
  licenses:
101
88
  - MIT
102
89
  metadata: {}
103
- post_install_message:
90
+ post_install_message: "\nif you want to use the executable lock_jars then install\
91
+ \ ruby-maven gem before using lock_jars \n\n $ gem install ruby-maven ~> 3.3.3\n\
92
+ \nor add it as deveopment dependency to your Gemfile\n\n gem 'ruby-maven', ~>\
93
+ \ 3.3.3\n\n"
104
94
  rdoc_options: []
105
95
  require_paths:
106
96
  - lib
@@ -111,12 +101,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
111
101
  version: '0'
112
102
  required_rubygems_version: !ruby/object:Gem::Requirement
113
103
  requirements:
114
- - - '>'
104
+ - - '>='
115
105
  - !ruby/object:Gem::Version
116
- version: 1.3.1
106
+ version: '0'
117
107
  requirements: []
118
108
  rubyforge_project:
119
- rubygems_version: 2.4.6
109
+ rubygems_version: 2.4.8
120
110
  signing_key:
121
111
  specification_version: 4
122
112
  summary: manage jar dependencies for gems
@@ -1,16 +0,0 @@
1
- # this file is maven DSL and used by maven via jars/maven_exec.rb
2
-
3
- require_relative 'lock'
4
- require_relative '../jar_dependencies'
5
-
6
- lock = Jars::Lock.new( ENV_JAVA['jars.lock'] )
7
-
8
- lock.process( :all ) do |coord|
9
-
10
- options = { :scope => coord.scope }
11
- options[ :systemPath ] = coord[ -1 ] if coord.scope == :system
12
- options[ :classifier ] = coord.classifier
13
-
14
- jar coord.group_id, coord.artifact_id, coord.version, options
15
-
16
- end