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.
data/bin/rmvn CHANGED
@@ -1,7 +1,9 @@
1
1
  #!/usr/bin/env ruby
2
- require 'ruby_maven'
2
+ require 'maven/ruby/cli'
3
+ require 'maven/ruby/pom_magic'
3
4
 
4
- mvn = Maven::RubyMaven.new
5
+ mvn = Maven::Ruby::Cli.new
6
+ magic = Maven::Ruby::PomMagic.new
5
7
 
6
8
  args = ARGV.dup
7
9
  ARGV.clear # clean up in case another script gets executed it gets clear ARGV
@@ -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
@@ -17,22 +17,13 @@ module Maven
17
17
  def copy_tests(tests)
18
18
  FileUtils.mkdir_p(@app_directory)
19
19
  FileUtils.cp_r(File.join('templates', "tests-#{tests}", "."),
20
- File.join(@app_directory, 'test'),
21
- :remove_destination => true)
20
+ File.join(@app_directory, 'test'))
22
21
  end
23
22
 
24
23
  def copy_specs(specs)
25
24
  FileUtils.mkdir_p(@app_directory)
26
25
  FileUtils.cp_r(File.join('templates', "specs-#{specs}", "."),
27
- File.join(@app_directory, 'spec'),
28
- :remove_destination => true)
29
- end
30
-
31
- def copy_files(files)
32
- FileUtils.mkdir_p(@app_directory)
33
- FileUtils.cp_r(File.join('templates', "files-#{files}", "."),
34
- @app_directory,
35
- :remove_destination => true)
26
+ File.join(@app_directory, 'spec'))
36
27
  end
37
28
 
38
29
  def create_rails_application(template)
@@ -75,11 +66,6 @@ module Maven
75
66
  copy_specs(specs)
76
67
  end
77
68
 
78
- def given_template_and_files(template, files)
79
- create_rails_application(template)
80
- copy_files(files)
81
- end
82
-
83
69
  def given_application(name)
84
70
  @app_directory = File.join('target', name)
85
71
  end
@@ -94,11 +80,6 @@ module Maven
94
80
  copy_specs(specs)
95
81
  end
96
82
 
97
- def given_application_and_files(name, files)
98
- @app_directory = File.join('target', name)
99
- copy_files(files)
100
- end
101
-
102
83
  def execute(args)
103
84
  rmvn.options['-l'] = "output.log"
104
85
  rmvn.exec_in(@app_directory, args.split(' '))
@@ -129,10 +110,6 @@ Given /^I create new rails application with template "(.*)" and "(.*)" specs$/ d
129
110
  steps.given_template_and_specs(template, specs)
130
111
  end
131
112
 
132
- Given /^I create new rails application with template "(.*)" and "(.*)" files$/ do |template, files|
133
- steps.given_template_and_files(template, files)
134
- end
135
-
136
113
  Given /^me an existing rails application "(.*)"$/ do |name|
137
114
  steps.given_application(name)
138
115
  end
@@ -145,10 +122,6 @@ Given /^me an existing rails application "(.*)" and "(.*)" specs$/ do |name, spe
145
122
  steps.given_application_and_specs(name, specs)
146
123
  end
147
124
 
148
- Given /^me an existing rails application "(.*)" and "(.*)" files$/ do |name, files|
149
- steps.given_application_and_files(name, files)
150
- end
151
-
152
125
  And /^I execute \"(.*)\"$/ do |args|
153
126
  steps.execute(args)
154
127
  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