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.
@@ -1,107 +0,0 @@
1
- require 'maven/ruby/maven'
2
- require 'maven/tools/artifact'
3
- require 'maven/tools/gemspec_dependencies'
4
- require 'fileutils'
5
- require 'jar_dependencies'
6
- module JBundler
7
-
8
- class Executor
9
-
10
- attr_reader :debug, :verbose
11
-
12
- def initialize( debug = false, verbose = false )
13
- @debug = debug
14
- @verbose = verbose
15
- end
16
-
17
- def maven_new
18
- m = Maven::Ruby::Maven.new
19
- m.property( 'jbundler.basedir', File.expand_path( basedir ) )
20
- m.property( 'jbundler.jarfile', File.expand_path( JBundler.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 )
31
- m
32
- end
33
- private :maven_new
34
-
35
- def maven
36
- @maven ||= maven_new
37
- end
38
-
39
- def basedir
40
- File.expand_path( '.' )
41
- end
42
-
43
- def exec( *args )
44
- maven.options[ '-f' ] = File.expand_path( '../pom.rb', __FILE__ )
45
- maven.exec( *args )
46
- end
47
-
48
- def attach_jar_coordinates( maven )
49
- load_path = $LOAD_PATH.dup
50
- require 'bundler/setup'
51
- done = []
52
- index = 0
53
- 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|
57
- unless done.include? a.key
58
- maven.property( "jbundler.jars.#{index}", a.to_s )
59
- index += 1
60
- done << a.key
61
- end
62
- end
63
- end
64
- rescue LoadError
65
- warn "no bundler found - ignore Gemfile if exists"
66
- ensure
67
- $LOAD_PATH.replace( load_path )
68
- end
69
-
70
- def lock_down( options = {} )
71
- vendor_dir = File.expand_path( options[ :vendor_dir ] ) if options[ :vendor_dir ]
72
- out = File.expand_path( '.jbundler.output' )
73
- tree = File.expand_path( '.jbundler.tree' )
74
- maven.property( 'jars.outputFile', out )
75
- maven.property( 'maven.repo.local', Jars.home )
76
- maven.property( 'jars.home', vendor_dir ) if vendor_dir
77
- # TODO move into jar-dependencies
78
- maven.property( 'jars.lock', File.expand_path( Jars.lock ) )
79
- maven.property( 'jars.force', options[ :force ] == true )
80
- maven.property( 'jars.update', options[ :update ] ) if options[ :update ]
81
-
82
- args = [ 'gem:jars-lock' ]
83
- if options[ :tree ]
84
- args += [ 'dependency:tree', '-P -gemfile.lock', '-DoutputFile=' + tree ]
85
- end
86
-
87
- puts
88
- puts '-- jar root dependencies --'
89
- puts
90
- status = exec( *args )
91
- exit 1 unless status
92
- if File.exists?( tree )
93
- puts
94
- puts '-- jar dependency tree --'
95
- puts
96
- puts File.read( tree )
97
- puts
98
- end
99
- puts
100
- puts File.read( out ).gsub( /#{File.dirname(out)}\//, '' )
101
- puts
102
- ensure
103
- FileUtils.rm_f out
104
- FileUtils.rm_f tree
105
- end
106
- end
107
- end