jbundler 0.8.0.pre → 0.8.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,27 @@
1
+ require 'jbundler/configurator'
2
+ module JBundler
3
+ class Configurator
4
+
5
+ attr_accessor :groups, :bootstrap, :verbose, :compile, :work_dir
6
+
7
+ def initialize( config )
8
+ @config = config
9
+ end
10
+
11
+ def configure( maven )
12
+ maven.property( 'jbundler.basedir', @config.basedir )
13
+ maven.property( 'jbundler.jarfile', @config.jarfile )
14
+ maven.property( 'jbundler.gemfile', @config.gemfile )
15
+ maven.property( 'jbundler.workdir', work_dir )
16
+ maven.property( 'jbundler.groups', @groups )
17
+ maven.property( 'jbundler.bootstrap', @bootstrap )
18
+ maven.property( 'maven.repo.local', @config.local_repository ) if @config.local_repository
19
+ maven.options[ '-s' ] = @config.settings if @config.settings
20
+ maven.options[ '-o' ] = nil if @config.offline
21
+ end
22
+
23
+ def work_dir
24
+ @work_dir ||= File.expand_path( @config.work_dir )
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,34 @@
1
+ require 'maven/tools/jarfile'
2
+ require 'jbundler/classpath_file'
3
+ require 'jbundler/vendor'
4
+ require 'jbundler/gemfile_lock'
5
+ require 'jbundler/aether'
6
+
7
+ module JBundler
8
+
9
+ class Context
10
+
11
+ attr_reader :config
12
+
13
+ def initialize
14
+ @config = JBundler::Config.new
15
+ end
16
+
17
+ def jarfile
18
+ @jarfile ||= Maven::Tools::Jarfile.new( @config.jarfile )
19
+ end
20
+
21
+ def vendor
22
+ @vendor ||= JBundler::Vendor.new( @config.vendor_dir )
23
+ end
24
+
25
+ def classpath
26
+ @classpath ||= JBundler::ClasspathFile.new( @config.classpath_file )
27
+ end
28
+
29
+ def gemfile_lock
30
+ @gemfile_lock ||= JBundler::GemfileLock.new( jarfile,
31
+ @config.gemfile_lock )
32
+ end
33
+ end
34
+ end
@@ -0,0 +1,30 @@
1
+ bdir = java.lang.System.getProperty( "jbundler.basedir" )
2
+ jfile = java.lang.System.getProperty( "jbundler.jarfile" )
3
+ gfile = java.lang.System.getProperty( "jbundler.gemfile" )
4
+ jworkdir = java.lang.System.getProperty( "jbundler.workdir" )
5
+
6
+ basedir( bdir )
7
+ if basedir != bdir
8
+ # older maven-tools needs this
9
+ self.instance_variable_set( :@basedir, bdir )
10
+ end
11
+
12
+ ( 0..(java.lang.System.getProperty( "jbundler.jars.size" ).to_i - 1) ).each do |i|
13
+ coord = java.lang.System.getProperty( "jbundler.jars.#{i}" )
14
+ dependency_artifact( Maven::Tools::Artifact.from_coordinate( coord.to_s ) )
15
+ end
16
+
17
+ jarfile( jfile )
18
+
19
+ build do
20
+ directory = jworkdir
21
+ end
22
+
23
+ properties( 'project.build.sourceEncoding' => 'utf-8',
24
+ 'tesla.dump.readOnly' => true,
25
+ 'tesla.dump.pom' => 'tree.pom.xml' )
26
+
27
+ plugin( :dependency, '2.8',
28
+ :includeTypes => 'jar',
29
+ :outputAbsoluteArtifactFilename => true,
30
+ :outputFile => java.lang.System.getProperty( "jbundler.outputFile" ) )
@@ -0,0 +1,69 @@
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 'rubygems'
22
+ require 'jbundler/pom'
23
+ require 'bundler'
24
+
25
+ module JBundler
26
+
27
+ class GemfileLock
28
+
29
+ def initialize(jarfile, lockfile = 'Gemfile.lock')
30
+ @jarfile = jarfile
31
+ @lockfile = lockfile if File.exists?(lockfile)
32
+ end
33
+
34
+ def exists?
35
+ !@lockfile.nil?
36
+ end
37
+
38
+ def newer?( mtime )
39
+ exists? && ( self.mtime > mtime )
40
+ end
41
+
42
+ def mtime
43
+ File.mtime(@lockfile) if @lockfile
44
+ end
45
+
46
+ def populate_dependencies(aether)
47
+ if @lockfile
48
+ # assuming we run in Bundler context here
49
+ # since we have a Gemfile.lock :)
50
+ Bundler.load.specs.each do |spec|
51
+ jars = []
52
+ spec.requirements.each do |rr|
53
+ rr.split(/\n/).each do |r|
54
+ jars << r if r =~ /^\s*(jar|pom)\s/
55
+ end
56
+ end
57
+ unless jars.empty?
58
+ pom = Pom.new(spec.name, spec.version, jars, "pom")
59
+ aether.install(pom.coordinate, pom.file)
60
+ unless @jarfile.locked?(pom.coordinate)
61
+ aether.add_artifact(pom.coordinate)
62
+ end
63
+ end
64
+ end
65
+ end
66
+ end
67
+ end
68
+
69
+ end
@@ -0,0 +1,67 @@
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
+ require 'jar_dependencies'
22
+ require 'maven/tools/dsl/jarfile_lock'
23
+ module JBundler
24
+ class JarfileLock < Maven::Tools::DSL::JarfileLock
25
+
26
+ def require( scope = :runtime )
27
+ coordinates( scope ).each do |coord|
28
+ Jars.require_jar( coord.split( /:/ ) )
29
+ end
30
+ end
31
+
32
+ def classpath( scope = :runtime )
33
+ coordinates( scope ).collect do |coord|
34
+ path_to_jar( coord.split( /:/ ) )
35
+ end
36
+ end
37
+
38
+ def downloaded?
39
+ classpath.member?( nil ) == false &&
40
+ classpath( :test ).member?( nil ) == false
41
+ end
42
+
43
+ private
44
+
45
+ # TODO should move into jar-dependencies
46
+ def to_path( group_id, artifact_id, *classifier_version )
47
+ version = classifier_version[ -1 ]
48
+ classifier = classifier_version[ -2 ]
49
+
50
+ jar = to_jar( group_id, artifact_id, version, classifier )
51
+ ( [ Jars.home ] + $LOAD_PATH ).each do |path|
52
+ if File.exists?( f = File.join( path, jar ) )
53
+ return f
54
+ end
55
+ end
56
+ nil
57
+ end
58
+
59
+ # TODO this is copy and paste from jar-dependncies
60
+ def to_jar( group_id, artifact_id, version, classifier )
61
+ file = "#{group_id.gsub( /\./, '/' )}/#{artifact_id}/#{version}/#{artifact_id}-#{version}"
62
+ file << "-#{classifier}" if classifier
63
+ file << '.jar'
64
+ file
65
+ end
66
+ end
67
+ end
@@ -0,0 +1,44 @@
1
+ require 'jbundler/pom_runner'
2
+ require 'fileutils'
3
+ module JBundler
4
+ class JRubyComplete < PomRunner
5
+
6
+ def initialize( config, options )
7
+ super options
8
+ work_dir = File.expand_path( config.work_dir )
9
+ maven.property( 'jbundler.workdir', work_dir )
10
+ maven.property( 'jbundler.basedir', config.basedir )
11
+ maven.property( 'jbundler.jarfile', config.jarfile )
12
+ maven.property( 'jbundler.gemfile', config.gemfile )
13
+ @tree = File.join( work_dir, 'tree.txt' )
14
+ maven.property( 'jbundler.outputFile', @tree )
15
+ end
16
+
17
+ def pom_file
18
+ File.join( File.dirname( __FILE__ ), 'jruby_complete_pom.rb' )
19
+ end
20
+
21
+ def show_versions
22
+ puts '...'
23
+
24
+ FileUtils.rm_f( @tree )
25
+
26
+ exec( 'dependency:tree' )
27
+
28
+ if File.exists?( @tree )
29
+ puts File.read( @tree )
30
+ end
31
+ end
32
+
33
+ def packit
34
+ puts '...'
35
+ exec( :package )
36
+
37
+ puts
38
+ puts 'now you can use jruby like this'
39
+ puts
40
+ puts "\tjava -jar jruby_complete_custom.jar"
41
+ puts
42
+ end
43
+ end
44
+ end
@@ -0,0 +1,31 @@
1
+ jfile = ::Maven::Tools::Jarfile.new( java.lang.System.getProperty( "jbundler.jarfile" ) )
2
+ workdir = java.lang.System.getProperty( "jbundler.workdir" )
3
+ jworkdir = File.join( workdir, 'jruby_complete' )
4
+ FileUtils.mkdir_p( jworkdir )
5
+
6
+ build.directory = jworkdir
7
+
8
+ properties( 'maven.test.skip' => true,
9
+ 'project.build.sourceEncoding' => 'utf-8' )
10
+
11
+ jfile.populate_unlocked do |dsl|
12
+ setup_jruby( dsl.jruby || JRUBY_VERSION, :compile )
13
+ dsl.artifacts.select do |a|
14
+ a[ :scope ] == :provided
15
+ end.each do |a|
16
+ a[ :scope ] = :compile
17
+ artifact( a )
18
+ end
19
+ end
20
+
21
+ plugin( :shade, '2.1',
22
+ :outputFile => "${user.dir}/jruby-complete-custom.jar",
23
+ :transformers => [ { '@implementation' => 'org.apache.maven.plugins.shade.resource.ManifestResourceTransformer',
24
+ :mainClass => 'org.jruby.Main' } ] ) do
25
+ execute_goals( 'shade', :phase => 'package' )
26
+ end
27
+
28
+ plugin( :dependency, '2.8',
29
+ :includeTypes => 'jar',
30
+ :outputAbsoluteArtifactFilename => true,
31
+ :outputFile => java.lang.System.getProperty( "jbundler.outputFile" ) )
@@ -0,0 +1,166 @@
1
+ require 'jbundler/configurator'
2
+ require 'jbundler/classpath_file'
3
+ require 'jbundler/vendor'
4
+ require 'jbundler/gemfile_lock'
5
+ require 'jbundler/show'
6
+ require 'maven/tools/gemspec_dependencies'
7
+ require 'maven/tools/jarfile'
8
+ require 'maven/ruby/maven'
9
+ require 'fileutils'
10
+ require 'jar_installer'
11
+
12
+ module JBundler
13
+ class LockDown
14
+
15
+ def initialize( config )
16
+ @config = config
17
+ @configurator = Configurator.new( config )
18
+ end
19
+
20
+ def vendor
21
+ @vendor ||= JBundler::Vendor.new( @config.vendor_dir )
22
+ end
23
+
24
+ def update( debug = false, verbose = false )
25
+ if vendor.vendored?
26
+ raise 'can not update vendored jars'
27
+ end
28
+
29
+ FileUtils.rm_f( @config.jarfile_lock )
30
+
31
+ lock_down( false, debug, verbose )
32
+ end
33
+
34
+ def lock_down( needs_vendor = false, debug = false, verbose = false )
35
+ jarfile = Maven::Tools::Jarfile.new( @config.jarfile )
36
+ classpath = JBundler::ClasspathFile.new( @config.classpath_file )
37
+ if jarfile.exists_lock? && classpath.exists?
38
+ needs_update = false
39
+ else
40
+ needs_update = needs_update?( jarfile, classpath )
41
+ end
42
+ if ( ! needs_update && ! needs_vendor ) || vendor.vendored?
43
+
44
+ puts 'Jar dependencies are up to date !'
45
+
46
+ if needs_update?( jarfile, classpath )
47
+ f = classpath.file.sub(/#{Dir.pwd}#{File::SEPARATOR}/, '' )
48
+ "the #{f} is stale, i.e. Gemfile or Jarfile is newer. `jbundle update` will update it"
49
+ end
50
+ else
51
+
52
+ puts '...'
53
+
54
+ deps = install_dependencies( debug, verbose, jarfile.exists_lock? )
55
+
56
+ update_files( classpath, collect_jars( deps ) ) if needs_update
57
+
58
+ vendor_it( vendor, deps ) if needs_vendor
59
+
60
+ end
61
+ end
62
+
63
+ private
64
+
65
+ def needs_update?( jarfile, classpath )
66
+ gemfile_lock = JBundler::GemfileLock.new( jarfile,
67
+ @config.gemfile_lock )
68
+ classpath.needs_update?( jarfile, gemfile_lock )
69
+ end
70
+
71
+ def vendor_it( vendor, deps )
72
+ puts "vendor directory: #{@config.vendor_dir}"
73
+ vendor.vendor_dependencies( deps )
74
+ puts
75
+ end
76
+
77
+ def collect_jars( deps )
78
+ jars = {}
79
+ deps.each do |d|
80
+ case d.scope
81
+ when :provided
82
+ ( jars[ :jruby ] ||= [] ) << d
83
+ when :test
84
+ ( jars[ :test ] ||= [] ) << d
85
+ else
86
+ ( jars[ :runtime ] ||= [] ) << d
87
+ end
88
+ end
89
+ jars
90
+ end
91
+
92
+ def update_files( classpath_file, jars )
93
+ if jars.values.flatten.size == 0
94
+ FileUtils.rm_f @config.jarfile_lock
95
+ else
96
+ lock = Maven::Tools::DSL::JarfileLock.new( @config.jarfile )
97
+ lock.replace( jars )
98
+ lock.dump
99
+ end
100
+ classpath_file.generate( (jars[ :runtime ] || []).collect { |j| j.file },
101
+ (jars[ :test ] || []).collect { |j| j.file },
102
+ (jars[ :jruby ] || []).collect { |j| j.file },
103
+ @config.local_repository )
104
+ end
105
+
106
+ def install_dependencies( debug, verbose, exclude_transitive = false )
107
+ deps_file = File.join( File.expand_path( @config.work_dir ),
108
+ 'dependencies.txt' )
109
+
110
+ exec_maven( debug, verbose, deps_file, exclude_transitive )
111
+
112
+ result = []
113
+ File.read( deps_file ).each_line do |line|
114
+ dep = Jars::JarInstaller::Dependency.new( line )
115
+ result << dep if dep
116
+ end
117
+ result
118
+ ensure
119
+ FileUtils.rm_f( deps_file ) if deps_file
120
+ end
121
+
122
+ def exec_maven( debug, verbose, output, exclude_transitive = false )
123
+ m = Maven::Ruby::Maven.new
124
+ m.options[ '-f' ] = File.join( File.dirname( __FILE__ ),
125
+ 'dependency_pom.rb' )
126
+ m.property( 'verbose', debug || verbose )
127
+ m.options[ '-q' ] = nil if !debug and !verbose
128
+ m.options[ '-e' ] = nil if !debug and verbose
129
+ m.options[ '-X' ] = nil if debug
130
+ m.options[ '-DexcludeTransitive' ] = exclude_transitive
131
+ m.verbose = debug
132
+ m.property( 'jbundler.outputFile', output )
133
+
134
+ @configurator.configure( m )
135
+
136
+ attach_jar_coordinates( m )
137
+
138
+ m.exec( 'dependency:list' )
139
+ end
140
+
141
+ private
142
+
143
+ def attach_jar_coordinates( maven )
144
+ load_path = $LOAD_PATH.dup
145
+ require 'bundler/setup'
146
+ done = []
147
+ index = 0
148
+ Gem.loaded_specs.each do |name, spec|
149
+ # TODO get rid of this somehow
150
+ deps = Maven::Tools::GemspecDependencies.new( spec )
151
+ deps.java_dependency_artifacts.each do |a|
152
+ unless done.include? a.key
153
+ maven.property( "jbundler.jars.#{index}", a.to_s )
154
+ index += 1
155
+ done << a.key
156
+ end
157
+ end
158
+ end
159
+ if index > 0
160
+ maven.property( "jbundler.jars.size", index )
161
+ end
162
+ ensure
163
+ $LOAD_PATH.replace( load_path )
164
+ end
165
+ end
166
+ end