jbundler 0.8.0.pre → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,115 @@
1
+ #
2
+ # Copyright (C) 2013 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
+ module JBundler
22
+
23
+ class ClasspathFile
24
+
25
+ def initialize(classpathfile = '.jbundler/classpath.rb')
26
+ @classpathfile = classpathfile
27
+ end
28
+
29
+ def file
30
+ @classpathfile
31
+ end
32
+
33
+ def load_classpath
34
+ load File.expand_path @classpathfile
35
+ end
36
+
37
+ def require_classpath
38
+ load_classpath
39
+ JBUNDLER_CLASSPATH.each { |c| require c }
40
+ end
41
+
42
+ def require_test_classpath
43
+ load_classpath
44
+ JBUNDLER_TEST_CLASSPATH.each { |c| require c }
45
+ end
46
+
47
+ def mtime
48
+ File.mtime(@classpathfile)
49
+ end
50
+
51
+ def exists?
52
+ File.exists?(@classpathfile)
53
+ end
54
+
55
+ def missing?( jarfile )
56
+ !exists? || !jarfile.exists_lock?
57
+ end
58
+
59
+ def jarfile_newer?( jarfile )
60
+ jarfile.exists? && (jarfile.mtime > mtime)
61
+ end
62
+
63
+ def jarlock_newer?( jarfile )
64
+ jarfile.exists_lock? && (jarfile.mtime_lock > mtime)
65
+ end
66
+
67
+ def needs_update?(jarfile, gemfile_lock)
68
+ if ( jarfile.exists? || gemfile_lock.exists? || jarfile.exists_lock? )
69
+ missing?( jarfile ) || jarfile_newer?( jarfile ) || jarlock_newer?( jarfile ) || gemfile_lock.newer?( mtime )
70
+ else
71
+ false
72
+ end
73
+ end
74
+
75
+ def generate( classpath_array, test_array = [], jruby_array = [], local_repo = nil )
76
+ FileUtils.mkdir_p(File.dirname(@classpathfile))
77
+ File.open(@classpathfile, 'w') do |f|
78
+ if local_repo
79
+ local_repo = File.expand_path( local_repo )
80
+ f.puts "require 'jar_dependencies'"
81
+ f.puts "JBUNDLER_LOCAL_REPO = Jars.home"
82
+ end
83
+ dump_array( f, jruby_array || [], 'JRUBY_', local_repo )
84
+ dump_array( f, test_array || [], 'TEST_', local_repo )
85
+ dump_array( f, classpath_array || [], '', local_repo )
86
+ f.close
87
+ end
88
+ end
89
+
90
+ private
91
+ def dump_array( file, array, prefix, local_repo )
92
+ file.puts "JBUNDLER_#{prefix}CLASSPATH = []"
93
+ array.each do |path|
94
+ dump_jar( file, path, prefix, local_repo )
95
+ end
96
+ file.puts "JBUNDLER_#{prefix}CLASSPATH.freeze"
97
+ end
98
+
99
+ def dump_jar( file, path, prefix, local_repo )
100
+ return if path =~ /pom$/
101
+ if local_repo
102
+ path.sub!( /#{local_repo}/, '' )
103
+ unless File.exists?( path )
104
+ file.puts "JBUNDLER_#{prefix}CLASSPATH << (JBUNDLER_LOCAL_REPO + '#{path}')"
105
+ path = nil
106
+ end
107
+ end
108
+ if path
109
+ # either we do not have a local_repo or the path is a absolute
110
+ # path from system artifact
111
+ file.puts "JBUNDLER_#{prefix}CLASSPATH << '#{path}'"
112
+ end
113
+ end
114
+ end
115
+ end
@@ -0,0 +1,146 @@
1
+ #
2
+ # Copyright (C) 2013 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
+ require 'bundler/vendored_thor'
22
+ require 'jbundler/config'
23
+ require 'jbundler/tree'
24
+ require 'jbundler/lock_down'
25
+ require 'jbundler/jruby_complete'
26
+ module JBundler
27
+ # As of v1.9.0, bundler's vendored version of thor is namespaced
28
+ Thor = Bundler::Thor if Gem.loaded_specs['bundler'].version >= Gem::Version.new('1.9.0')
29
+
30
+ class Cli < Thor
31
+ no_tasks do
32
+ def config
33
+ @config ||= JBundler::Config.new
34
+ end
35
+
36
+ def unvendor
37
+ vendor = JBundler::Vendor.new( config.vendor_dir )
38
+ vendor.clear
39
+ end
40
+
41
+ def vendor
42
+ vendor = JBundler::Vendor.new( config.vendor_dir )
43
+ if vendor.vendored?
44
+ raise "already vendored. please 'jbundle install --no-deployment before."
45
+ else
46
+ vendor.setup( JBundler::ClasspathFile.new( config.classpath_file ) )
47
+ end
48
+ end
49
+
50
+ def say_bundle_complete
51
+ puts ''
52
+ puts 'Your jbundle is complete! Use `jbundle show` to see where the bundled jars are installed.'
53
+ end
54
+ end
55
+
56
+ desc 'tree', 'display a graphical representation of the dependency tree'
57
+ #method_option :details, :type => :boolean, :default => false
58
+ def tree
59
+ JBundler::Tree.new( config ).show_it
60
+ end
61
+
62
+ desc 'install', "first `bundle install` is called and then the jar dependencies will be installed. for more details see `bundle help install`, jbundler will ignore most options. the install command is also the default when no command is given."
63
+ method_option :vendor, :type => :boolean, :default => false, :desc => 'vendor jars into vendor directory (jbundler only).'
64
+ method_option :debug, :type => :boolean, :default => false, :desc => 'enable maven debug output (jbundler only).'
65
+ method_option :verbose, :type => :boolean, :default => false, :desc => 'enable maven output (jbundler only).'
66
+ method_option :deployment, :type => :boolean, :default => false, :desc => "copy the jars into the vendor/jars directory (or as configured). these vendored jars have preference before the classpath jars !"
67
+ method_option :no_deployment, :type => :boolean, :default => false, :desc => 'clears the vendored jars'
68
+ method_option :path, :type => :string
69
+ method_option :without, :type => :array
70
+ method_option :system, :type => :boolean
71
+ method_option :local, :type => :boolean
72
+ method_option :binstubs, :type => :string
73
+ method_option :trust_policy, :type => :string
74
+ method_option :gemfile, :type => :string
75
+ method_option :jobs, :type => :string
76
+ method_option :retry, :type => :string
77
+ method_option :no_cache, :type => :boolean
78
+ method_option :quiet, :type => :boolean
79
+ def install
80
+ msg = JBundler::LockDown.new( config ).lock_down( options[ :vendor ],
81
+ options[ :debug ] ,
82
+ options[ :verbose ] )
83
+ config.verbose = ! options[ :quiet ]
84
+ Show.new( config ).show_classpath
85
+ unless options[ :quiet ]
86
+ puts 'jbundle complete !'
87
+ puts
88
+ end
89
+ puts msg if msg
90
+ end
91
+
92
+ desc 'console', 'irb session with gems and/or jars and with lazy jar loading.'
93
+ def console
94
+ # dummy - never executed !!!
95
+ end
96
+
97
+ desc 'lock_down', "first `bundle install` is called and then the jar dependencies will be installed. for more details see `bundle help install`, jbundler will ignore all options. the install command is also the default when no command is given. that is kept as fall back in cases where the new install does not work as before."
98
+ method_option :deployment, :type => :boolean, :default => false, :desc => "copy the jars into the vendor/jars directory (or as configured). these vendored jars have preference before the classpath jars !"
99
+ method_option :no_deployment, :type => :boolean, :default => false, :desc => 'clears the vendored jars'
100
+ method_option :path, :type => :string
101
+ method_option :without, :type => :array
102
+ method_option :system, :type => :boolean
103
+ method_option :local, :type => :boolean
104
+ method_option :binstubs, :type => :string
105
+ method_option :trust_policy, :type => :string
106
+ method_option :gemfile, :type => :string
107
+ method_option :jobs, :type => :string
108
+ method_option :retry, :type => :string
109
+ method_option :no_cache, :type => :boolean
110
+ method_option :quiet, :type => :boolean
111
+ def lock_down
112
+ require 'jbundler'
113
+
114
+ unvendor if options[ :no_deployment ]
115
+
116
+ vendor if options[ :deployment ]
117
+
118
+ config.verbose = ! options[ :quiet ]
119
+
120
+ Show.new( config ).show_classpath
121
+
122
+ say_bundle_complete unless options[ :quiet ]
123
+ end
124
+
125
+ desc 'update', "first `bundle update` is called and if there are no options then the jar dependencies will be updated. for more details see `bundle help update`."
126
+ method_option :debug, :type => :boolean, :default => false, :desc => 'enable maven debug output (jbundler only).'
127
+ method_option :verbose, :type => :boolean, :default => false, :desc => 'enable maven output (jbundler only).'
128
+ def update
129
+ return unless ARGV.size == 1
130
+
131
+ JBundler::LockDown.new( config ).update( options[ :debug ] ,
132
+ options[ :verbose ] )
133
+
134
+ config.verbose = ! options[ :quiet ]
135
+ Show.new( config ).show_classpath
136
+ puts ''
137
+ puts 'Your jbundle is updated! Use `jbundle show` to see where the bundled jars are installed.'
138
+ end
139
+
140
+ desc 'show', "first `bundle show` is called and if there are no options then the jar dependencies will be displayed. for more details see `bundle help show`."
141
+ def show
142
+ config.verbose = true
143
+ Show.new( config ).show_classpath
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,191 @@
1
+ #
2
+ # Copyright (C) 2013 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
+ require 'yaml'
22
+ require 'jar_dependencies'
23
+
24
+ module JBundler
25
+
26
+ # allow yaml config in $HOME/.jbundlerrc and $PWD/.jbundlerrc
27
+ class Config
28
+
29
+ RC_FILE = '.jbundlerrc'
30
+
31
+ attr_accessor :verbose, :local_repository, :jarfile, :gemfile, :skip, :settings, :offline, :work_dir, :vendor_dir, :basedir
32
+
33
+ def initialize
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 )
44
+ pwd_config = YAML.load_file(file) if File.exists?(file)
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( /[.]/, '_' ) ]
80
+ end
81
+ private :_jbundler_env
82
+
83
+ if defined? JRUBY_VERSION
84
+ def jbundler_env( key )
85
+ java.lang.System.getProperty( key.downcase.gsub( /_/, '.' ) ) ||
86
+ _jbundler_env( key )
87
+ end
88
+ else
89
+ alias :jbundler_env :_jbundler_env
90
+ end
91
+ private :jbundler_env
92
+
93
+ def skip
94
+ skip = jbundler_env('JBUNDLE_SKIP')
95
+ # defaults to false
96
+ @skip ||= skip && skip != 'false'
97
+ end
98
+
99
+ def verbose
100
+ verbose = jbundler_env('JBUNDLE_VERBOSE')
101
+ # defaults to false
102
+ @verbose ||= verbose && verbose != 'false'
103
+ end
104
+
105
+ def jarfile
106
+ @jarfile ||= absolute( _jarfile )
107
+ end
108
+
109
+ def _jarfile
110
+ jbundler_env('JBUNDLE_JARFILE') || 'Jarfile'
111
+ end
112
+ private :_jarfile
113
+
114
+ def jarfile_lock
115
+ "#{jarfile}.lock"
116
+ end
117
+
118
+ def gemfile
119
+ @gemfile ||= absolute( _gemfile )
120
+ end
121
+
122
+ def _gemfile
123
+ jbundler_env('BUNDLE_GEMFILE') || 'Gemfile'
124
+ end
125
+ private :_gemfile
126
+
127
+ def gemfile_lock
128
+ "#{gemfile}.lock"
129
+ end
130
+
131
+ def classpath_file
132
+ absolute( jbundler_env('JBUNDLE_CLASSPATH_FILE') ||
133
+ '.jbundler/classpath.rb' )
134
+ end
135
+
136
+ def local_repository
137
+ # use maven default local repo as default
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
+ # first load the right settings
144
+ self.settings
145
+ Jars.home
146
+ end
147
+ end
148
+
149
+ def settings
150
+ settings = absolute( jbundler_env('JBUNDLE_SETTINGS') )
151
+ if settings
152
+ warn "JBUNDLE_SETTINGS environment or jbundle.settings' system property is deprecated use JARS_MAVEN_SETTINGS or jars.maven.settings instead"
153
+ ENV[ Jars::MAVEN_SETTINGS ] ||= settings
154
+ end
155
+ Jars.maven_settings
156
+ end
157
+
158
+ def offline
159
+ @offline ||= jbundler_env('JBUNDLE_OFFLINE')
160
+ @offline == 'true' || @offline == true
161
+ end
162
+
163
+ def proxy
164
+ @proxy ||= jbundler_env('JBUNDLE_PROXY')
165
+ if @proxy
166
+ warn 'proxy config is deprecated, use settings.xml instead'
167
+ end
168
+ @proxy
169
+ end
170
+
171
+ def mirror
172
+ @mirror ||= jbundler_env('JBUNDLE_MIRROR')
173
+ # nice to have no leading slash
174
+ @mirror = @mirror.sub( /\/$/, '' ) if @mirror
175
+ if @mirror
176
+ warn 'mirror config is deprecated, use settings.xml instead'
177
+ end
178
+ @mirror
179
+ end
180
+
181
+ def work_dir
182
+ @work_dir ||= absolute( jbundler_env('JBUNDLE_WORK_DIR') || 'pkg' )
183
+ end
184
+
185
+ def vendor_dir
186
+ @vendor_dir ||= absolute( jbundler_env('JBUNDLE_VENDOR_DIR') ||
187
+ File.join( 'vendor', 'jars' ) )
188
+ end
189
+
190
+ end
191
+ end