jar-dependencies 0.0.8 → 0.0.9

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: 73555c8c6ef8f730df4791d6ee4efc0e21b900f5
4
- data.tar.gz: e933d33225e437640c4e76679ee8e238f1c79500
3
+ metadata.gz: d0805ace25b23e9fa213795dbbef51d8a65be0d1
4
+ data.tar.gz: 3f3bed86bbb59f4cc4e42ae3b1374e1aeb75f1a8
5
5
  SHA512:
6
- metadata.gz: 9100d709b4460f00f1e286eb758f4f6f46ffbf180caf147e381b4860c225904c713ffe0458d421d218b7f4b73a4ef550c15a002f798f4aa55b80060e3305db85
7
- data.tar.gz: f99bd349315a539846b5baeb4c9fe58d64f40a420c6e37138679c5a9c236264bd122ee99f79a89af9d7dc5901426552e1e59f42a5d92952adca7c129683f8f3f
6
+ metadata.gz: 9755c23928d304ae90ade5143ab5df6932c06df2129d648cb932c1a79409dc3a38d05593afcda7b9942b3b1f02ca153f9b991290848a96bcfa89696649b1f2de
7
+ data.tar.gz: 2c5905be4e5a004463beaa23d00144476c57a47521e09fb17fff6ee4425ecd6ac9ac07e051b90364bd6ccdaecc3c3d32ddb486cfae5bda8e72ae9323baf1a0ec
@@ -2,7 +2,7 @@
2
2
 
3
3
  Gem::Specification.new do |s|
4
4
  s.name = 'jar-dependencies'
5
- s.version = "0.0.8"
5
+ s.version = "0.0.9"
6
6
  s.author = 'christian meier'
7
7
  s.email = [ 'mkristian@web.de' ]
8
8
  s.summary = 'manage jar dependencies for gems'
@@ -20,146 +20,190 @@
20
20
  #
21
21
 
22
22
  module Jars
23
- HOME = 'JARS_HOME'
24
- MAVEN_SETTINGS = 'JARS_MAVEN_SETTINGS'
25
- SKIP = 'JARS_SKIP'
26
- NO_REQUIRE = 'JARS_NO_REQUIRE'
27
- QUIET = 'JARS_QUIET'
28
- VERBOSE = 'JARS_VERBOSE'
29
- DEBUG = 'JARS_DEBUG'
30
- VENDOR = 'JARS_VENDOR'
31
-
32
- if defined? JRUBY_VERSION
33
- def self.to_prop( key )
34
- java.lang.System.getProperty( key.downcase.gsub( /_/, '.' ) ) ||
35
- ENV[key.upcase.gsub( /[.]/, '_' ) ]
36
- end
37
- else
38
- def self.to_prop( key )
39
- ENV[ key.upcase.gsub( /[.]/, '_' ) ]
23
+ HOME = 'JARS_HOME'.freeze
24
+ MAVEN_SETTINGS = 'JARS_MAVEN_SETTINGS'.freeze
25
+ SKIP = 'JARS_SKIP'.freeze
26
+ NO_REQUIRE = 'JARS_NO_REQUIRE'.freeze
27
+ QUIET = 'JARS_QUIET'.freeze
28
+ VERBOSE = 'JARS_VERBOSE'.freeze
29
+ DEBUG = 'JARS_DEBUG'.freeze
30
+ VENDOR = 'JARS_VENDOR'.freeze
31
+
32
+ class << self
33
+
34
+ if defined? JRUBY_VERSION
35
+ def to_prop( key )
36
+ java.lang.System.getProperty( key.downcase.gsub( /_/, '.' ) ) ||
37
+ ENV[ key.upcase.gsub( /[.]/, '_' ) ]
38
+ end
39
+ else
40
+ def to_prop( key )
41
+ ENV[ key.upcase.gsub( /[.]/, '_' ) ]
42
+ end
40
43
  end
41
- end
42
44
 
43
- def self.to_boolean( key )
44
- prop = to_prop( key )
45
- # prop == nil => false
46
- # prop == 'false' => false
47
- # anything else => true
48
- prop == '' or prop == 'true'
49
- end
45
+ def to_boolean( key )
46
+ prop = to_prop( key )
47
+ # prop == nil => false
48
+ # prop == 'false' => false
49
+ # anything else => true
50
+ prop == '' or prop == 'true'
51
+ end
50
52
 
51
- def self.skip?
52
- to_boolean( SKIP )
53
- end
53
+ def skip?
54
+ to_boolean( SKIP )
55
+ end
54
56
 
55
- def self.no_require?
56
- to_boolean( NO_REQUIRE )
57
- end
57
+ def no_require?
58
+ to_boolean( NO_REQUIRE )
59
+ end
58
60
 
59
- def self.quiet?
60
- to_boolean( QUIET )
61
- end
61
+ def quiet?
62
+ to_boolean( QUIET )
63
+ end
62
64
 
63
- def self.verbose?
64
- to_boolean( VERBOSE )
65
- end
65
+ def verbose?
66
+ to_boolean( VERBOSE )
67
+ end
66
68
 
67
- def self.debug?
68
- to_boolean( DEBUG )
69
- end
69
+ def debug?
70
+ to_boolean( DEBUG )
71
+ end
70
72
 
71
- def self.vendor?
72
- to_boolean( VENDOR )
73
- end
73
+ def vendor?
74
+ to_boolean( VENDOR )
75
+ end
74
76
 
75
- def self.absolute( file )
76
- File.expand_path( file ) if file
77
- end
77
+ def freeze_loading
78
+ ENV[ NO_REQUIRE ] = 'true'
79
+ end
78
80
 
79
- def self.reset
80
- @_jars_maven_settings_ = nil
81
- @_jars_home_ = nil
82
- @@jars ||= {}
83
- @@jars.clear
84
- end
81
+ def reset
82
+ instance_variables.each { |var| instance_variable_set(var, nil) }
83
+ ( @@jars ||= {} ).clear
84
+ end
85
85
 
86
- def self.maven_settings
87
- if @_jars_maven_settings_.nil?
88
- unless @_jars_maven_settings_ = absolute( to_prop( MAVEN_SETTINGS ) )
89
- # use maven default settings
90
- @_jars_maven_settings_ = File.join( ENV[ 'HOME' ],
91
- '.m2', 'settings.xml' )
86
+ def maven_user_settings
87
+ if @_jars_maven_user_settings_.nil?
88
+ if settings = absolute( to_prop( MAVEN_SETTINGS ) )
89
+ settings = File.expand_path(settings)
90
+ unless File.exists?(settings)
91
+ warn "configured ENV['#{MAVEN_SETTINGS}'] = '#{settings}' not found" unless quiet?
92
+ settings = false
93
+ end
94
+ else # use maven default (user) settings
95
+ settings = File.join( user_home, '.m2', 'settings.xml' )
96
+ settings = false unless File.exists?(settings)
97
+ end
98
+ @_jars_maven_user_settings_ = settings
92
99
  end
100
+ @_jars_maven_user_settings_ || nil
101
+ end
102
+ alias maven_settings maven_user_settings
103
+
104
+ def maven_global_settings
105
+ if @_jars_maven_global_settings_.nil?
106
+ if mvn_home = ENV[ 'M2_HOME' ] || ENV[ 'MAVEN_HOME' ]
107
+ settings = File.join( mvn_home, 'conf/settings.xml' )
108
+ settings = false unless File.exists?(settings)
109
+ else
110
+ settings = false
111
+ end
112
+ @_jars_maven_global_settings_ = settings
113
+ end
114
+ @_jars_maven_global_settings_ || nil
93
115
  end
94
- @_jars_maven_settings_
95
- end
96
116
 
97
- def self.home
98
- if @_jars_home_.nil?
99
- unless @_jars_home_ = absolute( to_prop( HOME ) )
100
- begin
101
- require 'rexml/document'
102
- doc = REXML::Document.new( File.read( maven_settings ) )
103
- REXML::XPath.first( doc, "//settings/localRepository").tap do |e|
104
- @_jars_home_ = e.text.sub( /\\/, '/') if e
117
+ def home
118
+ if @_jars_home_.nil?
119
+ unless @_jars_home_ = absolute( to_prop( HOME ) )
120
+ begin
121
+ if user_settings = maven_user_settings
122
+ @_jars_home_ = detect_local_repository(user_settings)
123
+ end
124
+ if ! @_jars_home_ && global_settings = maven_global_settings
125
+ @_jars_home_ = detect_local_repository(global_settings)
126
+ end
127
+ rescue # ignore
105
128
  end
106
- rescue
107
- # ignore
108
129
  end
130
+ # use maven default repository
131
+ @_jars_home_ ||= File.join( user_home, '.m2', 'repository' )
109
132
  end
110
- # use maven default repository
111
- @_jars_home_ ||= File.join( ENV[ 'HOME' ], '.m2', 'repository' )
133
+ @_jars_home_
112
134
  end
113
- @_jars_home_
114
- end
115
-
116
- def self.require_jar( group_id, artifact_id, *classifier_version )
117
- version = classifier_version[ -1 ]
118
- classifier = classifier_version[ -2 ]
119
135
 
120
- @@jars ||= {}
121
- coordinate = "#{group_id}:#{artifact_id}"
122
- coordinate += ":#{classifier}" if classifier
123
- if @@jars.key? coordinate
124
- if @@jars[ coordinate ] == version
125
- false
136
+ def require_jar( group_id, artifact_id, *classifier_version )
137
+ version = classifier_version[ -1 ]
138
+ classifier = classifier_version[ -2 ]
139
+
140
+ @@jars ||= {}
141
+ coordinate = "#{group_id}:#{artifact_id}"
142
+ coordinate += ":#{classifier}" if classifier
143
+ if @@jars.key? coordinate
144
+ if @@jars[ coordinate ] == version
145
+ false
146
+ else
147
+ # version of already registered jar
148
+ @@jars[ coordinate ]
149
+ end
126
150
  else
127
- # version of already registered jar
128
- @@jars[ coordinate ]
151
+ do_require( group_id, artifact_id, version, classifier )
152
+ @@jars[ coordinate ] = version
153
+ return true
129
154
  end
130
- else
131
- do_require( group_id, artifact_id, version, classifier )
132
- @@jars[ coordinate ] = version
133
- return true
134
155
  end
135
- end
136
156
 
137
- private
157
+ private
138
158
 
139
- def self.to_jar( group_id, artifact_id, version, classifier )
140
- file = "#{group_id.gsub( /\./, '/' )}/#{artifact_id}/#{version}/#{artifact_id}-#{version}"
141
- file += "-#{classifier}" if classifier
142
- file += '.jar'
143
- file
144
- end
159
+ def absolute( file )
160
+ File.expand_path( file ) if file
161
+ end
145
162
 
146
- def self.do_require( *args )
147
- jar = to_jar( *args )
148
- file = File.join( home, jar )
149
- # use jar from local repository if exists
150
- if File.exists?( file )
151
- require file
152
- else
153
- # otherwise try to find it on the load path
154
- require jar
163
+ def user_home
164
+ ENV[ 'HOME' ] || begin
165
+ user_home = Dir.home if Dir.respond_to?(:home)
166
+ unless user_home
167
+ user_home = ENV_JAVA[ 'user.home' ] if Object.const_defined?(:ENV_JAVA)
168
+ end
169
+ user_home
170
+ end
155
171
  end
156
- rescue LoadError => e
157
- raise "\n\n\tyou might need to reinstall the gem which depends on the missing jar\n\n" + e.message + " (LoadError)"
158
- end
159
172
 
160
- def self.freeze_loading
161
- ENV[ NO_REQUIRE ] = 'true'
162
- end
173
+ def detect_local_repository(settings); require 'rexml/document'
174
+ doc = REXML::Document.new( File.read( settings ) )
175
+ if local_repo = doc.root.elements['localRepository']
176
+ if ( local_repo = local_repo.first )
177
+ local_repo = local_repo.value
178
+ local_repo = nil if local_repo.empty?
179
+ end
180
+ end
181
+ local_repo
182
+ end
183
+
184
+ def to_jar( group_id, artifact_id, version, classifier )
185
+ file = "#{group_id.gsub( /\./, '/' )}/#{artifact_id}/#{version}/#{artifact_id}-#{version}"
186
+ file << "-#{classifier}" if classifier
187
+ file << '.jar'
188
+ file
189
+ end
190
+
191
+ def do_require( *args )
192
+ jar = to_jar( *args )
193
+ file = File.join( home, jar )
194
+ # use jar from local repository if exists
195
+ if File.exists?( file )
196
+ require file
197
+ else
198
+ # otherwise try to find it on the load path
199
+ require jar
200
+ end
201
+ rescue LoadError => e
202
+ raise "\n\n\tyou might need to reinstall the gem which depends on the missing jar\n\n" + e.message + " (LoadError)"
203
+ end
204
+
205
+ end # class << self
206
+
163
207
  end
164
208
 
165
209
  def require_jar( *args )
@@ -3,7 +3,7 @@ module Jars
3
3
  class JarInstaller
4
4
 
5
5
  class Dependency
6
-
6
+
7
7
  attr_reader :path, :file, :gav, :scope, :type, :coord
8
8
 
9
9
  def self.new( line )
@@ -22,7 +22,7 @@ module Jars
22
22
  private :setup_type
23
23
 
24
24
  def setup_scope( line )
25
- @scope =
25
+ @scope =
26
26
  case line
27
27
  when /:provided:/
28
28
  :provided
@@ -40,13 +40,13 @@ module Jars
40
40
  line.sub!( /^\s+/, '' )
41
41
  @coord = line.sub( /:[^:]+:[^:]+$/, '' )
42
42
  first, second = line.sub( /:[^:]+:[^:]+$/, '' ).split( /:#{type}:/ )
43
- group_id, artifact_id = first.split( /:/ )
44
- parts = group_id.split( '.' )
43
+ group_id, artifact_id = first.split( /:/ )
44
+ parts = group_id.split( '.' )
45
45
  parts << artifact_id
46
46
  parts << second.split( /:/ )[ -1 ]
47
- parts << File.basename( line.sub /.:/, '' )
47
+ parts << File.basename( line.sub /.:/, '' )
48
48
  @path = File.join( parts ).strip
49
-
49
+
50
50
  setup_scope( line )
51
51
 
52
52
  line.gsub!( /:jar:|:pom:|:test:|:compile:|:runtime:|:provided:/, ':' )
@@ -111,7 +111,7 @@ module Jars
111
111
  when 1
112
112
  specs.first
113
113
  else
114
- raise 'more then one gemspec found. please specify a specfile'
114
+ raise 'more then one gemspec found. please specify a specfile'
115
115
  end
116
116
  end
117
117
  private :find_spec
@@ -175,11 +175,11 @@ module Jars
175
175
  vendor_dir = File.join( @basedir, @spec.require_path )
176
176
  jars_file = File.join( vendor_dir, "#{@spec.name}_jars.rb" )
177
177
 
178
- # write out new jars_file it write_require_file is true or
179
- # check timestamps:
178
+ # write out new jars_file it write_require_file is true or
179
+ # check timestamps:
180
180
  # do not generate file if specfile is older then the generated file
181
181
  if ! write_require_file &&
182
- File.exists?( jars_file ) &&
182
+ File.exists?( jars_file ) &&
183
183
  File.mtime( @specfile ) < File.mtime( jars_file )
184
184
  # leave jars_file as is
185
185
  jars_file = nil
@@ -190,7 +190,7 @@ module Jars
190
190
 
191
191
  def setup_arguments( deps )
192
192
  args = [ 'dependency:list', "-DoutputFile=#{deps}", '-DincludeScope=runtime', '-DoutputAbsoluteArtifactFilename=true', '-DincludeTypes=jar', '-DoutputScope=true', '-f', @specfile ]
193
-
193
+
194
194
  if Jars.debug?
195
195
  args << '-X'
196
196
  elsif not Jars.verbose?
@@ -222,7 +222,7 @@ module Jars
222
222
  inst.install 'ruby-maven', req
223
223
  rescue => e
224
224
  warn e.backtrace.join( "\n" ) if Jars.verbose?
225
- raise "there was an error installing 'ruby-maven'. please install it manually: " + e.message
225
+ raise "there was an error installing 'ruby-maven'. please install it manually: #{e.inspect}"
226
226
  end
227
227
 
228
228
  def monkey_path_gem_dependencies
@@ -238,7 +238,7 @@ EOF
238
238
 
239
239
  def install_dependencies
240
240
  lazy_load_maven
241
-
241
+
242
242
  monkey_path_gem_dependencies
243
243
 
244
244
  deps = File.join( @basedir, 'deps.lst' )
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: jar-dependencies
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 0.0.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - christian meier
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-16 00:00:00.000000000 Z
11
+ date: 2014-08-28 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
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ~>
39
+ - !ruby/object:Gem::Version
40
+ version: '10.2'
41
41
  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.
42
42
  email:
43
43
  - mkristian@web.de