jar-dependencies 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 2f27be364d8c8f32d577aef905556c4cd660fe8e
4
+ data.tar.gz: 3e7a4d1af9b4156354f47be93a4b03f7c333a6f2
5
+ SHA512:
6
+ metadata.gz: 6d1c68ce4acf5dfb0e95c919761ba653cb1bf24088744cba40a3801395b80f9db27091bbe922f4edef80367e8f37252349a276f4883895b4fd9d6d34fe26d074
7
+ data.tar.gz: 031880f018fe453260aaa5f8e852c93a512d22adbb613df1e1176368527b58c69db2167c2663c5474b383c124ff43bc3dd612088466e12604b64805351243439
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Christian Meier
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Readme.md ADDED
@@ -0,0 +1,36 @@
1
+ # jar-dependencies #
2
+
3
+ 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.
4
+
5
+ via environment variable or system properties the jar loading can be switched of completely, allowing the servlet container or jbundler or any other container to take care of the jar loading.
6
+
7
+ in case the jars are vendored using the following path convention
8
+
9
+ **{group\_id}/{artifact\_id}-{version}.jar**
10
+
11
+ it will be loaded in case the local maven repository does not have it (maybe the preference should be the other way around ?).
12
+
13
+ the gem is tiny on purpose since the all gems with jar dependencies should use and funny double loaded jars can be avoided in future. also java project using the jruby ScriptingContainer can manage their jar dependencies including those coming from the gem files.
14
+
15
+ # create a gem with jar dependencies #
16
+
17
+ see add you jar dependency declaration in gemspec via the **requirements**, see [example.gemspec](example/example.gemspec). create an extension **ext/extconf.rb** and use the **setup** from [ruby-maven](http://rubygems.org/gem/ruby-maven) to install the jar dependencies on installation of the gem - see [ext/extconf.rb](example/ext/extconf.rb). this setup will create **{gem.name}\_jars.rb** inside the lib directory (**require_path** of the gemspec) of your gem .
18
+
19
+ note: you need ruby-maven-3.1.1.0.3.dev or newer for the GemSetup class
20
+
21
+ your gem just need require this **{gem.name}_jars.rb** in your code whenever you want to load these jars (see [lib/example.rb](example/lib/example.rb)).
22
+
23
+ the gem itself also needs the **jar-dependencies** gem as runtime-dependency since that is used to load the jar or let [jbundler](http://rubygems.org/gem/jbundler) or similar frameworks deal with the jar dependencies.
24
+
25
+ # motivation #
26
+
27
+ just today I tumbled across [https://github.com/arrigonialberto86/ruby-band](https://github.com/arrigonialberto86/ruby-band) which usees jbundler to manage their jar dependencies which happens on the first 'require "ruby-band"'. their is no easy or formal way to find out which jars are added to jruby-classloader.
28
+
29
+ another issue was brought to my notice yesterday [https://github.com/hqmq/derelicte/issues/1](https://github.com/hqmq/derelicte/issues/1)
30
+
31
+ or the question of how to manage jruby projects with maven [http://ruby.11.x6.nabble.com/Maven-dependency-management-td4996934.html](http://ruby.11.x6.nabble.com/Maven-dependency-management-td4996934.html)
32
+
33
+ or a few days ago an issue for the rake-compile [https://github.com/luislavena/rake-compiler/issues/87](https://github.com/luislavena/rake-compiler/issues/87)
34
+
35
+ with jruby-9000 coming it is the right time to get the jar dependencies right - the current situation is like the time before bundler for gems.
36
+
@@ -0,0 +1,22 @@
1
+ #-*- mode: ruby -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'jar-dependencies'
5
+ s.version = "0.0.2"
6
+ s.author = 'christian meier'
7
+ s.email = [ 'mkristian@web.de' ]
8
+ s.summary = 'manage jar dependencies for gems'
9
+ s.homepage = 'https://github.com/mkristian/jar-dependencies'
10
+
11
+ s.license = 'MIT'
12
+
13
+ s.files = Dir[ 'lib/*rb' ]
14
+ s.files += [ 'Readme.md', 'jar-dependencies.gemspec', 'MIT-LICENSE' ]
15
+
16
+ s.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.'
17
+
18
+ s.add_runtime_dependency 'rake', '~> 10.2.2'
19
+ s.add_runtime_dependency 'ruby-maven', '~> 3.1.1.0'
20
+ end
21
+
22
+ # vim: syntax=Ruby
@@ -0,0 +1,22 @@
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
+
22
+ require 'jar_dependencies'
@@ -0,0 +1,57 @@
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
+
22
+ def require_jar( group_id, artifact_id, *classifier_version )
23
+ require_jarfile( nil, group_id, artifact_id, *classifier_version )
24
+ end
25
+
26
+ def require_jarfile( file, group_id, artifact_id, *classifier_version )
27
+ skip = java.lang.System.get_property( 'jruby.jars.skip' ) || ENV[ 'JRUBY_JARS_SKIP' ] || java.lang.System.get_property( 'jbundler.skip' ) || ENV[ 'JBUNDLER_SKIP' ]
28
+ return false if skip == 'true'
29
+
30
+ version = classifier_version[ -1 ]
31
+ classifier = classifier_version[ -2 ]
32
+
33
+ # if no file given than it is vendored
34
+ # if the file does not exists we assume it is vendored
35
+ if file.nil? || !File.exists?( file )
36
+ file = "#{group_id.gsub( /\./, '/' )}/#{artifact_id}/#{version}/#{artifact_id}-#{version}"
37
+ file += "-#{classifier}" if classifier
38
+ file += '.jar'
39
+ end
40
+
41
+ @@jars ||= {}
42
+ coordinate = "#{group_id}:#{artifact_id}"
43
+ coordinate += ":#{classifier}" if classifier
44
+ if @@jars.key? coordinate
45
+ if @@jars[ coordinate ] != version
46
+ warn "coordinate #{coordinate} already loaded with version #{@@jars[ coordinate ]}"
47
+ end
48
+ false
49
+ else
50
+ require file
51
+ @@jars[ coordinate ] = version
52
+ true
53
+ end
54
+ rescue LoadError => e
55
+ warn 'you might need to reinstall the gem which depends on the missing jar'
56
+ raise e
57
+ end
@@ -0,0 +1,153 @@
1
+ class JarInstaller
2
+
3
+ class Dependency
4
+
5
+ attr_reader :path, :file, :gav, :scope, :type, :coord
6
+
7
+ def self.new( line )
8
+ if line.match /:jar:|:pom:/
9
+ super
10
+ end
11
+ end
12
+
13
+ def initialize( line )
14
+ if line.match /:pom:/
15
+ @type = :pom
16
+ elsif line.match /:jar:/
17
+ @type = :jar
18
+ end
19
+ line.sub!( /^\s+/, '' )
20
+ @coord = line.sub( /:[^:]+:[^:]+$/, '' )
21
+ first, second = line.sub( /:[^:]+:[^:]+$/, '' ).split( /:#{type}:/ )
22
+ group_id, artifact_id = first.split( /:/ )
23
+ parts = group_id.split( '.' )
24
+ parts << artifact_id
25
+ parts << second.split( /:/ )[ -1 ]
26
+ parts << File.basename( line.sub /.:/, '' )
27
+ @path = File.join( parts ).strip
28
+
29
+ @scope =
30
+ case line
31
+ when /:provided:/
32
+ :provided
33
+ when /:test:/
34
+ :test
35
+ else
36
+ :runtime
37
+ end
38
+ line.gsub!( /:jar:|:pom:|:test:|:compile:|:runtime:|:provided:/, ':' )
39
+ @file = line.sub( /^.*:/, '' ).strip
40
+ @gav = line.sub( /:[^:]+$/, '' )
41
+ end
42
+ end
43
+
44
+ def self.install_jars
45
+ new.install_jars
46
+ end
47
+
48
+ def self.load_from_maven( file )
49
+ result = []
50
+ File.read( file ).each_line do |line|
51
+ dep = Dependency.new( line )
52
+ result << dep if dep
53
+ end
54
+ result
55
+ end
56
+
57
+ def self.install_deps( deps, dir, require_filename, vendor )
58
+ FileUtils.mkdir_p( File.dirname( require_filename ) )
59
+ File.open( require_filename, 'w' ) do |f|
60
+ f.puts "require 'jar_dependencies'"
61
+ f.puts
62
+ deps.each do |dep|
63
+ next if dep.type != :jar || dep.scope != :runtime
64
+ args = dep.gav.gsub( /:/, "', '" )
65
+ if vendor
66
+ vendored = File.join( dir, dep.path )
67
+ FileUtils.mkdir_p( File.dirname( vendored ) )
68
+ FileUtils.cp( dep.file, vendored )
69
+ f.puts( "require_jar( '#{args}' )" )
70
+ else
71
+ f.puts( "require_jarfile( '#{dep.file}', '#{args}' )" )
72
+ end
73
+ end
74
+ end
75
+ end
76
+
77
+ def initialize( spec = nil )
78
+ if spec.nil?
79
+ specs = Dir[ '*.gemspec' ]
80
+ case specs.size
81
+ when 0
82
+ raise 'no gemspec found'
83
+ when 1
84
+ spec = specs.first
85
+ else
86
+ raise 'more then one gemspec found. please specify a specfile'
87
+ end
88
+ end
89
+ if spec.is_a? String
90
+ @basedir = File.dirname( File.expand_path( spec ) )
91
+ @specfile = spec
92
+ spec = eval( File.read( spec ) )
93
+ else
94
+ @basedir = spec.gem_dir
95
+ @specfile = spec.spec_file
96
+ end
97
+ @spec = spec
98
+ end
99
+
100
+ def vendor_jars
101
+ return if @spec.requirements.empty?
102
+ really_vendor = java.lang.System.get_property( 'jruby.jars.vendor' ) || ENV[ 'JRUBY_JARS_VENDOR' ] || 'true'
103
+ do_install( really_vendor == 'true' )
104
+ end
105
+
106
+ def install_jars
107
+ return if @spec.requirements.empty?
108
+ do_install( false )
109
+ end
110
+
111
+ private
112
+
113
+ def do_install( vendor )
114
+ vendor_dir = File.join( @basedir, @spec.require_path )
115
+ jars_file = File.join( vendor_dir, "#{@spec.name}_jars.rb" )
116
+
117
+ return if File.exists?( jars_file ) &&
118
+ File.mtime( @specfile ) < File.mtime( jars_file )
119
+
120
+ self.class.install_deps( install_dependencies, vendor_dir,
121
+ jars_file, vendor )
122
+ end
123
+
124
+ def install_dependencies
125
+ deps = File.join( @basedir, 'deps.lst' )
126
+
127
+ # lazy load ruby-maven
128
+ begin
129
+
130
+ require 'maven/ruby/maven'
131
+
132
+ rescue LoadError
133
+ raise 'please install ruby-maven gem so the jar dependencies can be installed'
134
+ end
135
+
136
+ # monkey patch to NOT include gem dependencies
137
+ require 'maven/tools/gemspec_dependencies'
138
+ eval <<EOF
139
+ class ::Maven::Tools::GemspecDependencies
140
+ def runtime; []; end
141
+ def development; []; end
142
+ end
143
+ EOF
144
+
145
+ maven = Maven::Ruby::Maven.new
146
+ maven.exec 'dependency:list', "-DoutputFile=#{deps}", '-DincludeScope=runtime', '-DoutputAbsoluteArtifactFilename=true', '-DincludeTypes=jar', '-DoutputScope=true', '-f', @specfile, '--quiet'
147
+
148
+ self.class.load_from_maven( deps )
149
+ ensure
150
+ FileUtils.rm_f( deps ) if deps
151
+ end
152
+ end
153
+
@@ -0,0 +1,27 @@
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
+
22
+ if defined?( JRUBY_VERSION ) && Gem.post_install_hooks.empty?
23
+ Gem.post_install do |gem_installer|
24
+ require 'jar_installer'
25
+ ::JarInstaller.new( gem_installer.spec ).vendor_jars
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,79 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jar-dependencies
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - christian meier
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2014-04-10 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ version_requirements: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ~>
18
+ - !ruby/object:Gem::Version
19
+ version: 10.2.2
20
+ requirement: !ruby/object:Gem::Requirement
21
+ requirements:
22
+ - - ~>
23
+ - !ruby/object:Gem::Version
24
+ version: 10.2.2
25
+ prerelease: false
26
+ type: :runtime
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-maven
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ~>
32
+ - !ruby/object:Gem::Version
33
+ version: 3.1.1.0
34
+ requirement: !ruby/object:Gem::Requirement
35
+ requirements:
36
+ - - ~>
37
+ - !ruby/object:Gem::Version
38
+ version: 3.1.1.0
39
+ prerelease: false
40
+ type: :runtime
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
+ email:
43
+ - mkristian@web.de
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/jar_dependencies.rb
49
+ - lib/jar_installer.rb
50
+ - lib/jar-dependencies.rb
51
+ - lib/rubygems_plugin.rb
52
+ - Readme.md
53
+ - jar-dependencies.gemspec
54
+ - MIT-LICENSE
55
+ homepage: https://github.com/mkristian/jar-dependencies
56
+ licenses:
57
+ - MIT
58
+ metadata: {}
59
+ post_install_message:
60
+ rdoc_options: []
61
+ require_paths:
62
+ - lib
63
+ required_ruby_version: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '>='
66
+ - !ruby/object:Gem::Version
67
+ version: '0'
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ requirements: []
74
+ rubyforge_project:
75
+ rubygems_version: 2.1.9
76
+ signing_key:
77
+ specification_version: 4
78
+ summary: manage jar dependencies for gems
79
+ test_files: []