ruby-maven 3.0.4.0.29.0 → 3.0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,70 @@
1
+ require 'fileutils'
2
+ require 'maven/tools/rails_project'
3
+
4
+ module Maven
5
+ module Ruby
6
+ class PomMagic
7
+
8
+ def initialize(pom = '.pom.xml')
9
+ @pom = pom
10
+ end
11
+
12
+ def new_rails_project
13
+ ::Maven::Tools::RailsProject.new
14
+ end
15
+
16
+ def pom_xml(dir = '.')
17
+ File.join(dir, @pom)
18
+ end
19
+
20
+ def generate_pom(dir = '.', *args)
21
+ if index = (args.index("-f") || args.index("--file"))
22
+ filename = args[index + 1]
23
+ if filename =~ /.gemspec$/
24
+ proj = ::Maven::Tools::GemProject.new
25
+ proj.load_gemspec(filename)
26
+ elsif filename =~ /Gemfile/
27
+ proj = ::Maven::Tools::GemProject.new
28
+ proj.load_gemfile(filename)
29
+ end
30
+ else
31
+ gemfiles = Dir[File.join(dir, "*Gemfile")]
32
+ gemfiles.delete_if {|g| g =~ /.pom/}
33
+ if gemfiles.size > 0
34
+ proj =
35
+ if File.exists? File.join( dir, 'config', 'application.rb' )
36
+ new_rails_project
37
+ else
38
+ ::Maven::Tools::GemProject.new
39
+ end
40
+ filename = gemfiles[0]
41
+ proj.load_gemfile(filename)
42
+ else
43
+ gemspecs = Dir[File.join(dir, "*.gemspec")]
44
+ gemspecs.delete_if {|g| g =~ /.pom/}
45
+ if gemspecs.size > 0
46
+ proj = ::Maven::Tools::GemProject.new
47
+ filename = gemspecs[0]
48
+ proj.load_gemspec(filename)
49
+ end
50
+ end
51
+ end
52
+ if proj
53
+ proj.load_jarfile(File.join(File.dirname(filename), 'Jarfile'))
54
+ proj.load_gemfile(File.join(File.dirname(filename), 'Mavenfile'))
55
+ proj.add_defaults
56
+ File.open(pom_xml(dir), 'w') do |f|
57
+ f.puts proj.to_xml
58
+ end
59
+ pom_xml(dir)
60
+ end
61
+ end
62
+
63
+ def dump_pom(dir = '.', force = false, file = 'pom.xml')
64
+ if force || !File.exists?(file)
65
+ FileUtils.cp(generate_pom(dir), file)
66
+ end
67
+ end
68
+ end
69
+ end
70
+ end
@@ -0,0 +1,56 @@
1
+ require 'fileutils'
2
+ require 'maven/tools/rails_project'
3
+ require 'java' if defined? JRUBY_VERSION
4
+
5
+ module Maven
6
+ class PomMagic
7
+
8
+ def new_rails_project
9
+ Maven::Tools::RailsProject.new
10
+ end
11
+
12
+ def generate_pom(*args)
13
+ unless args.member?("-f") || args.member?("--file")
14
+ gemfiles = Dir["*Gemfile"]
15
+ gemfiles.delete_if {|g| g =~ /.pom/}
16
+ if gemfiles.size > 0
17
+ proj =
18
+ if File.exists? File.join( 'config', 'application.rb' )
19
+ new_rails_project
20
+ else
21
+ Maven::Tools::GemProject.new
22
+ end
23
+ filename = gemfiles[0]
24
+ proj.load_gemfile(filename)
25
+ else
26
+ gemspecs = Dir["*.gemspec"]
27
+ gemspecs.delete_if {|g| g =~ /.pom/}
28
+ if gemspecs.size > 0
29
+ proj = Maven::Tools::GemProject.new
30
+ filename = gemspecs[0]
31
+ proj.load_gemspec(filename)
32
+ end
33
+ end
34
+ if proc
35
+ proj.load_jarfile(File.join(File.dirname(filename), 'Jarfile'))
36
+ proj.load_gemfile(File.join(File.dirname(filename), 'Mavenfile'))
37
+ proj.add_defaults
38
+ pom = ".pom.xml"
39
+ File.open(pom, 'w') do |f|
40
+ f.puts proj.to_xml
41
+ end
42
+ args << '-f'
43
+ args << pom
44
+ end
45
+ end
46
+ args
47
+ end
48
+
49
+ def dump_pom(force = false, file = 'pom.xml')
50
+ if force || !File.exists?(file)
51
+ generate_pom
52
+ FileUtils.cp(".pom.xml", file)
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,5 @@
1
+ module Maven
2
+ module Ruby
3
+ VERSION = '3.0.4.1'
4
+ end
5
+ end
@@ -0,0 +1,6 @@
1
+ module Maven
2
+ module Ruby
3
+ class Version
4
+ end
5
+ end
6
+ end
@@ -0,0 +1,131 @@
1
+ require 'fileutils'
2
+ require 'maven/tools/rails_project'
3
+ require 'java' if defined? JRUBY_VERSION
4
+
5
+ module Maven
6
+ class RubyCli
7
+
8
+ private
9
+
10
+ # make the command line for the goals of the jruby-maven-plugins nicer
11
+ PLUGINS = {
12
+ :rake => [:rake],
13
+ :jruby => [:jruby, :compile],
14
+ :gem => [:package, :install, :push, :exec, :pom, :initialize, :irb],
15
+ :rails3 => [:new, :generate, :rake, :server, :console, :dbconsole, :pom, :initialize],
16
+ :cucumber => [:test],
17
+ :rspec => [:test],
18
+ :runit => [:test],
19
+ :mini => [:test,:spec],
20
+ :bundler => [:install, :update]
21
+ }
22
+ ALIASES = {
23
+ :ruby => :jruby,
24
+ :spec => :rspec,
25
+ :rails => :rails3,
26
+ :bundle => :bundler
27
+ }
28
+
29
+ def prepare(args)
30
+ if args.size > 0
31
+ name = args[0].to_sym
32
+ name = ALIASES[name] || name
33
+ if PLUGINS.member?(name)
34
+ start = 1
35
+ if args.size > 1
36
+ if PLUGINS[name].member? args[1].to_sym
37
+ goal = args[1].to_sym
38
+ start = 2
39
+ else
40
+ goal = PLUGINS[name][0]
41
+ end
42
+ else
43
+ goal = PLUGINS[name][0]
44
+ end
45
+ # determine the version and delete from args if given
46
+ version = args.detect do |a|
47
+ a =~ /^-Dplugin.version=/
48
+ end
49
+ version ||= options['-Dplugin.version']
50
+
51
+ if version
52
+ args.delete(version)
53
+ version = ":" + version.sub(/^-Dplugin.version=/, '')
54
+ end
55
+ aa = if index = args.index("--")
56
+ args[(index + 1)..-1]
57
+ else
58
+ []
59
+ end
60
+ ruby_args = (args[start, (index || 1000) - start] || []).join(' ')
61
+
62
+ aa << "de.saumya.mojo:#{name}-maven-plugin#{version}:#{goal}"
63
+ aa << "-Dargs=\"#{ruby_args}\"" if ruby_args.size > 0
64
+ args.replace(aa)
65
+ else
66
+ args.delete("--")
67
+ end
68
+ end
69
+ args
70
+ end
71
+
72
+ def log(args)
73
+ log = File.join('log', 'rmvn.log')
74
+ if File.exists? File.dirname(log)
75
+ File.open(log, 'a') do |f|
76
+ f.puts "#{$0.sub(/.*\//, '')} #{args.join ' '}"
77
+ end
78
+ end
79
+ end
80
+
81
+ def maybe_print_help(args)
82
+ if args.size == 0 || args[0] == "--help"
83
+ puts "usage: rmvn [<plugin-name> [<args>] [-- <maven-options>]] | [<maven-goal>|<maven-phase> <maven-options>] | --help"
84
+ PLUGINS.each do |name, goals|
85
+ puts
86
+ print "plugin #{name}"
87
+ print " - alias: #{ALIASES.invert[name]}" if ALIASES.invert[name]
88
+ puts
89
+ if goals.size > 1
90
+ print "\tgoals : #{goals.join(',')}"
91
+ puts
92
+ end
93
+ print "\tdefault goal: #{goals[0]}"
94
+ puts
95
+ end
96
+ puts
97
+ ["--help"]
98
+ else
99
+ args
100
+ end
101
+ end
102
+
103
+ def command_line(args)
104
+ args = prepare(args)
105
+ args = maybe_print_help(args)
106
+ args
107
+ end
108
+
109
+ def setup(*args)
110
+ log(args)
111
+ command_line(args.dup.flatten)
112
+ end
113
+
114
+ public
115
+
116
+ attr_accessors :verbose
117
+
118
+ def exec(*args)
119
+ mvn = RubyMaven.new
120
+ mvn.verbose = verbose
121
+ mvn.exec(setup(args))
122
+ end
123
+
124
+ def exec_in(launchdirectory, *args)
125
+ mvn = RubyMaven.new
126
+ mvn.verbose = verbose
127
+ mvn.exec(launchdirectory, setup(args))
128
+ end
129
+
130
+ end
131
+ end
@@ -0,0 +1,227 @@
1
+ require 'fileutils'
2
+ require 'maven/tools/rails_project'
3
+ require 'java' if defined? JRUBY_VERSION
4
+
5
+ module Maven
6
+ class RubyMaven
7
+
8
+ # make the command line for the goals of the jruby-maven-plugins nicer
9
+ PLUGINS = {
10
+ :rake => [:rake],
11
+ :jruby => [:jruby, :compile],
12
+ :gem => [:package, :install, :push, :exec, :pom, :initialize, :irb],
13
+ :rails3 => [:new, :generate, :rake, :server, :console, :dbconsole, :pom, :initialize],
14
+ :cucumber => [:test],
15
+ :rspec => [:test],
16
+ :runit => [:test],
17
+ :mini => [:test,:spec],
18
+ :bundler => [:install, :update]
19
+ }
20
+ ALIASES = {
21
+ :ruby => :jruby,
22
+ :spec => :rspec,
23
+ :rails => :rails3,
24
+ :bundle => :bundler
25
+ }
26
+
27
+ def initialize
28
+ @maven_home = File.expand_path(File.join(File.dirname(__FILE__),'..','..'))
29
+ end
30
+
31
+ def launch_jruby(args)
32
+ classpath_array.each do |path|
33
+ require path
34
+ end
35
+
36
+ java.lang.System.setProperty("classworlds.conf",
37
+ File.join(@maven_home, 'bin', "m2.conf"))
38
+
39
+ java.lang.System.setProperty("maven.home", @maven_home)
40
+
41
+ org.codehaus.plexus.classworlds.launcher.Launcher.main(args)
42
+ end
43
+
44
+ def classpath_array
45
+ Dir.glob(File.join(@maven_home, "boot", "*jar")) +
46
+ Dir.glob(File.join(@maven_home, "ext", "ruby-tools*jar"))
47
+ end
48
+
49
+ def launch_java(*args)
50
+ system "java -cp #{classpath_array.join(':')} -Dmaven.home=#{File.expand_path(@maven_home)} -Dclassworlds.conf=#{File.expand_path(File.join(@maven_home, 'bin', 'm2.conf'))} org.codehaus.plexus.classworlds.launcher.Launcher #{args.join ' '}"
51
+ end
52
+
53
+ def prepare(args)
54
+ if args.size > 0
55
+ name = args[0].to_sym
56
+ name = ALIASES[name] || name
57
+ if PLUGINS.member?(name)
58
+ start = 1
59
+ if args.size > 1
60
+ if PLUGINS[name].member? args[1].to_sym
61
+ goal = args[1].to_sym
62
+ start = 2
63
+ else
64
+ goal = PLUGINS[name][0]
65
+ end
66
+ else
67
+ goal = PLUGINS[name][0]
68
+ end
69
+ # determine the version and delete from args if given
70
+ version = args.detect do |a|
71
+ a =~ /^-Dplugin.version=/
72
+ end
73
+ version ||= options['-Dplugin.version']
74
+
75
+ if version
76
+ args.delete(version)
77
+ version = ":" + version.sub(/^-Dplugin.version=/, '')
78
+ end
79
+ aa = if index = args.index("--")
80
+ args[(index + 1)..-1]
81
+ else
82
+ []
83
+ end
84
+ ruby_args = (args[start, (index || 1000) - start] || []).join(' ')
85
+
86
+ aa << "de.saumya.mojo:#{name}-maven-plugin#{version}:#{goal}"
87
+ aa << "-Dargs=\"#{ruby_args}\"" if ruby_args.size > 0
88
+ args.replace(aa)
89
+ else
90
+ args.delete("--")
91
+ end
92
+ end
93
+ args
94
+ end
95
+
96
+ def log(args)
97
+ log = File.join('log', 'rmvn.log')
98
+ if File.exists? File.dirname(log)
99
+ File.open(log, 'a') do |f|
100
+ f.puts "#{$0.sub(/.*\//, '')} #{args.join ' '}"
101
+ end
102
+ end
103
+ end
104
+
105
+ def maybe_print_help(args)
106
+ if args.size == 0 || args[0] == "--help"
107
+ puts "usage: rmvn [<plugin-name> [<args>] [-- <maven-options>]] | [<maven-goal>|<maven-phase> <maven-options>] | --help"
108
+ PLUGINS.each do |name, goals|
109
+ puts
110
+ print "plugin #{name}"
111
+ print " - alias: #{ALIASES.invert[name]}" if ALIASES.invert[name]
112
+ puts
113
+ if goals.size > 1
114
+ print "\tgoals : #{goals.join(',')}"
115
+ puts
116
+ end
117
+ print "\tdefault goal: #{goals[0]}"
118
+ puts
119
+ end
120
+ puts
121
+ ["--help"]
122
+ else
123
+ args
124
+ end
125
+ end
126
+
127
+ def options
128
+ @options ||= {}
129
+ end
130
+
131
+ def options_string
132
+ options_array.join ' '
133
+ end
134
+
135
+ def options_array
136
+ options.collect do |k,v|
137
+ if k =~ /^-D/
138
+ v = "=#{v}" unless v.nil?
139
+ else
140
+ v = " #{v}" unless v.nil?
141
+ end
142
+ "#{k}#{v}"
143
+ end
144
+ end
145
+
146
+ def command_line(args)
147
+ args = prepare(args)
148
+ args = maybe_print_help(args)
149
+ args
150
+ end
151
+
152
+ def new_rails_project
153
+ Maven::Tools::RailsProject.new
154
+ end
155
+
156
+ def generate_pom(*args)
157
+ unless args.member?("-f") || args.member?("--file")
158
+ gemfiles = Dir["*Gemfile"]
159
+ gemfiles.delete_if {|g| g =~ /.pom/}
160
+ if gemfiles.size > 0
161
+ proj =
162
+ if File.exists? File.join( 'config', 'application.rb' )
163
+ new_rails_project
164
+ else
165
+ Maven::Tools::GemProject.new
166
+ end
167
+ filename = gemfiles[0]
168
+ proj.load_gemfile(filename)
169
+ else
170
+ gemspecs = Dir["*.gemspec"]
171
+ gemspecs.delete_if {|g| g =~ /.pom/}
172
+ if gemspecs.size > 0
173
+ proj = Maven::Tools::GemProject.new
174
+ filename = gemspecs[0]
175
+ proj.load_gemspec(filename)
176
+ end
177
+ end
178
+ if filename
179
+ proj.load_jarfile(File.join(File.dirname(filename), 'Jarfile'))
180
+ proj.load_gemfile(File.join(File.dirname(filename), 'Mavenfile'))
181
+ proj.add_defaults
182
+ #target = File.join(File.dirname(filename), 'target')
183
+ #FileUtils.mkdir_p target
184
+ pom = ".pom.xml"
185
+ File.open(pom, 'w') do |f|
186
+ f.puts proj.to_xml
187
+ end
188
+ args << '-f'
189
+ args << pom
190
+ end
191
+ end
192
+ args
193
+ end
194
+
195
+ def exec(*args)
196
+ log(args)
197
+ a = command_line(args.dup.flatten)
198
+ verbose = options.delete('--verbose')
199
+ no_pom = options.delete('--no-pom')
200
+ a << options_array
201
+ a.flatten!
202
+ a = generate_pom(*a) unless no_pom
203
+ puts "mvn #{a.join(' ')}" if verbose
204
+ if defined? JRUBY_VERSION
205
+ # TODO use a setup like maven_gemify from jruby to launch maven
206
+ launch_java(a)
207
+ else
208
+ launch_java(a)
209
+ end
210
+ end
211
+
212
+ def exec_in(launchdirectory, *args)
213
+ succeeded = nil
214
+ FileUtils.cd(launchdirectory) do
215
+ succeeded = exec(args)
216
+ end
217
+ succeeded
218
+ end
219
+
220
+ def dump_pom(force = false, file = 'pom.xml')
221
+ if force || !File.exists?(file)
222
+ generate_pom
223
+ FileUtils.cp(".pom.xml", file)
224
+ end
225
+ end
226
+ end
227
+ end