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 @@
1
+ require 'maven/ruby/maven'
@@ -0,0 +1,134 @@
1
+ require 'maven/ruby/maven'
2
+ module Maven
3
+ module Ruby
4
+ class Cli
5
+
6
+ private
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 prepare(args)
28
+ if args.size > 0
29
+ name = args[0].to_sym
30
+ name = ALIASES[name] || name
31
+ if PLUGINS.member?(name)
32
+ start = 1
33
+ if args.size > 1
34
+ if PLUGINS[name].member? args[1].to_sym
35
+ goal = args[1].to_sym
36
+ start = 2
37
+ else
38
+ goal = PLUGINS[name][0]
39
+ end
40
+ else
41
+ goal = PLUGINS[name][0]
42
+ end
43
+ # determine the version and delete from args if given
44
+ version = args.detect do |a|
45
+ a =~ /^-Dplugin.version=/
46
+ end
47
+ version ||= options['-Dplugin.version']
48
+
49
+ if version
50
+ args.delete(version)
51
+ version = ":" + version.sub(/^-Dplugin.version=/, '')
52
+ end
53
+ aa = if index = args.index("--")
54
+ args[(index + 1)..-1]
55
+ else
56
+ []
57
+ end
58
+ ruby_args = (args[start, (index || 1000) - start] || []).join(' ')
59
+
60
+ aa << "de.saumya.mojo:#{name}-maven-plugin#{version}:#{goal}"
61
+ aa << "-Dargs=\"#{ruby_args}\"" if ruby_args.size > 0
62
+ args.replace(aa)
63
+ else
64
+ args.delete("--")
65
+ end
66
+ end
67
+ args
68
+ end
69
+
70
+ def log(args)
71
+ log = File.join('log', 'rmvn.log')
72
+ if File.exists? File.dirname(log)
73
+ File.open(log, 'a') do |f|
74
+ f.puts "#{$0.sub(/.*\//, '')} #{args.join ' '}"
75
+ end
76
+ end
77
+ end
78
+
79
+ def maybe_print_help(args)
80
+ if args.size == 0 || args[0] == "--help"
81
+ puts "usage: rmvn [<plugin-name> [<args>] [-- <maven-options>]] | [<maven-goal>|<maven-phase> <maven-options>] | --help"
82
+ PLUGINS.each do |name, goals|
83
+ puts
84
+ print "plugin #{name}"
85
+ print " - alias: #{ALIASES.invert[name]}" if ALIASES.invert[name]
86
+ puts
87
+ if goals.size > 1
88
+ print "\tgoals : #{goals.join(',')}"
89
+ puts
90
+ end
91
+ print "\tdefault goal: #{goals[0]}"
92
+ puts
93
+ end
94
+ puts
95
+ ["--help"]
96
+ else
97
+ args
98
+ end
99
+ end
100
+
101
+ def command_line(args)
102
+ args = prepare(args)
103
+ args = maybe_print_help(args)
104
+ args
105
+ end
106
+
107
+ def setup(*args)
108
+ args = magic_pom(args)
109
+ log(args)
110
+ command_line(args.dup.flatten)
111
+ end
112
+
113
+ protected
114
+
115
+ def magic_pom(*args)
116
+ file = PomMagic.new.generate_pom(args)
117
+ args += ['-f', file] if file && !(args.member?("-f") || args.member?("--file"))
118
+ args
119
+ end
120
+
121
+ public
122
+
123
+ def exec(*args)
124
+ mvn = Maven.new
125
+ mvn.exec(setup(args))
126
+ end
127
+
128
+ def exec_in(launchdirectory, *args)
129
+ mvn = Maven.new
130
+ mvn.exec_in(launchdirectory, setup(args))
131
+ end
132
+ end
133
+ end
134
+ end
@@ -0,0 +1,127 @@
1
+ module Maven
2
+ class RubyCli
3
+
4
+ private
5
+
6
+ # make the command line for the goals of the jruby-maven-plugins nicer
7
+ PLUGINS = {
8
+ :rake => [:rake],
9
+ :jruby => [:jruby, :compile],
10
+ :gem => [:package, :install, :push, :exec, :pom, :initialize, :irb],
11
+ :rails3 => [:new, :generate, :rake, :server, :console, :dbconsole, :pom, :initialize],
12
+ :cucumber => [:test],
13
+ :rspec => [:test],
14
+ :runit => [:test],
15
+ :mini => [:test,:spec],
16
+ :bundler => [:install, :update]
17
+ }
18
+ ALIASES = {
19
+ :ruby => :jruby,
20
+ :spec => :rspec,
21
+ :rails => :rails3,
22
+ :bundle => :bundler
23
+ }
24
+
25
+ def prepare(args)
26
+ if args.size > 0
27
+ name = args[0].to_sym
28
+ name = ALIASES[name] || name
29
+ if PLUGINS.member?(name)
30
+ start = 1
31
+ if args.size > 1
32
+ if PLUGINS[name].member? args[1].to_sym
33
+ goal = args[1].to_sym
34
+ start = 2
35
+ else
36
+ goal = PLUGINS[name][0]
37
+ end
38
+ else
39
+ goal = PLUGINS[name][0]
40
+ end
41
+ # determine the version and delete from args if given
42
+ version = args.detect do |a|
43
+ a =~ /^-Dplugin.version=/
44
+ end
45
+ version ||= options['-Dplugin.version']
46
+
47
+ if version
48
+ args.delete(version)
49
+ version = ":" + version.sub(/^-Dplugin.version=/, '')
50
+ end
51
+ aa = if index = args.index("--")
52
+ args[(index + 1)..-1]
53
+ else
54
+ []
55
+ end
56
+ ruby_args = (args[start, (index || 1000) - start] || []).join(' ')
57
+
58
+ aa << "de.saumya.mojo:#{name}-maven-plugin#{version}:#{goal}"
59
+ aa << "-Dargs=\"#{ruby_args}\"" if ruby_args.size > 0
60
+ args.replace(aa)
61
+ else
62
+ args.delete("--")
63
+ end
64
+ end
65
+ args
66
+ end
67
+
68
+ def log(args)
69
+ log = File.join('log', 'rmvn.log')
70
+ if File.exists? File.dirname(log)
71
+ File.open(log, 'a') do |f|
72
+ f.puts "#{$0.sub(/.*\//, '')} #{args.join ' '}"
73
+ end
74
+ end
75
+ end
76
+
77
+ def maybe_print_help(args)
78
+ if args.size == 0 || args[0] == "--help"
79
+ puts "usage: rmvn [<plugin-name> [<args>] [-- <maven-options>]] | [<maven-goal>|<maven-phase> <maven-options>] | --help"
80
+ PLUGINS.each do |name, goals|
81
+ puts
82
+ print "plugin #{name}"
83
+ print " - alias: #{ALIASES.invert[name]}" if ALIASES.invert[name]
84
+ puts
85
+ if goals.size > 1
86
+ print "\tgoals : #{goals.join(',')}"
87
+ puts
88
+ end
89
+ print "\tdefault goal: #{goals[0]}"
90
+ puts
91
+ end
92
+ puts
93
+ ["--help"]
94
+ else
95
+ args
96
+ end
97
+ end
98
+
99
+ def command_line(args)
100
+ args = prepare(args)
101
+ args = maybe_print_help(args)
102
+ args
103
+ end
104
+
105
+ def setup(*args)
106
+ log(args)
107
+ command_line(args.dup.flatten)
108
+ end
109
+
110
+ public
111
+
112
+ attr_accessors :verbose
113
+
114
+ def exec(*args)
115
+ mvn = RubyMaven.new
116
+ mvn.verbose = verbose
117
+ mvn.exec(setup(args))
118
+ end
119
+
120
+ def exec_in(launchdirectory, *args)
121
+ mvn = RubyMaven.new
122
+ mvn.verbose = verbose
123
+ mvn.exec(launchdirectory, setup(args))
124
+ end
125
+
126
+ end
127
+ end
@@ -0,0 +1,108 @@
1
+ require 'fileutils'
2
+ require 'java' if defined? JRUBY_VERSION
3
+
4
+ module Maven
5
+ module Ruby
6
+ class Maven
7
+
8
+ private
9
+
10
+ def launch_jruby(args)
11
+ java.lang.System.setProperty("classworlds.conf",
12
+ File.join(self.class.maven_home, 'bin', "m2.conf"))
13
+
14
+ java.lang.System.setProperty("maven.home", self.class.maven_home)
15
+
16
+ cw = self.class.class_world
17
+ org.apache.maven.cli.MavenCli.doMain( args, cw ) == 0
18
+ end
19
+
20
+ def self.class_world
21
+ @class_world ||= class_world!
22
+ end
23
+
24
+ def self.class_world!
25
+ (classpath_array + classpath_array('lib')).each do |path|
26
+ require path
27
+ end
28
+ org.codehaus.plexus.classworlds.ClassWorld.new("plexus.core", java.lang.Thread.currentThread().getContextClassLoader())
29
+ end
30
+
31
+ def self.classpath_array(dir = 'boot')
32
+ Dir.glob(File.join(maven_home, dir, "*jar"))
33
+ end
34
+
35
+ def launch_java(*args)
36
+ system "java -cp #{self.class.classpath_array.join(':')} -Dmaven.home=#{File.expand_path(self.class.maven_home)} -Dclassworlds.conf=#{File.expand_path(File.join(self.class.maven_home, 'bin', 'm2.conf'))} org.codehaus.plexus.classworlds.launcher.Launcher #{args.join ' '}"
37
+ end
38
+
39
+ def options_string
40
+ options_array.join ' '
41
+ end
42
+
43
+ def options_array
44
+ options.collect do |k,v|
45
+ if k =~ /^-D/
46
+ v = "=#{v}" unless v.nil?
47
+ else
48
+ v = " #{v}" unless v.nil?
49
+ end
50
+ "#{k}#{v}"
51
+ end
52
+ end
53
+
54
+ public
55
+
56
+ def self.class_world
57
+ @class_world ||= class_world!
58
+ end
59
+
60
+ def self.maven_home
61
+ @maven_home = File.expand_path(File.join(File.dirname(__FILE__),
62
+ '..',
63
+ '..',
64
+ '..',
65
+ '..'))
66
+ end
67
+
68
+ def options
69
+ @options ||= {}
70
+ end
71
+
72
+ def verbose= v
73
+ @verbose = v
74
+ end
75
+
76
+ def property(key, value = nil)
77
+ options["-D#{key}"] = value
78
+ end
79
+
80
+ def verbose
81
+ if @verbose.nil?
82
+ options.delete('-Dverbose').to_s == 'true'
83
+ else
84
+ @verbose
85
+ end
86
+ end
87
+
88
+ def exec(*args)
89
+ a = args.dup + options_array
90
+ a.flatten!
91
+ puts "mvn #{a.join(' ')}" if verbose
92
+ if defined? JRUBY_VERSION
93
+ launch_jruby(a)
94
+ else
95
+ launch_java(a)
96
+ end
97
+ end
98
+
99
+ def exec_in(launchdirectory, *args)
100
+ succeeded = nil
101
+ FileUtils.cd(launchdirectory) do
102
+ succeeded = exec(args)
103
+ end
104
+ succeeded
105
+ end
106
+ end
107
+ end
108
+ end
@@ -0,0 +1,93 @@
1
+ require 'fileutils'
2
+ require 'java' if defined? JRUBY_VERSION
3
+
4
+ module Maven
5
+ class RubyMaven
6
+
7
+ private
8
+
9
+ def launch_jruby(args)
10
+ classpath_array.each do |path|
11
+ require path
12
+ end
13
+
14
+ java.lang.System.setProperty("classworlds.conf",
15
+ File.join(@maven_home, 'bin', "m2.conf"))
16
+
17
+ java.lang.System.setProperty("maven.home", @maven_home)
18
+
19
+ org.codehaus.plexus.classworlds.launcher.Launcher.main(args)
20
+ end
21
+
22
+ def classpath_array
23
+ Dir.glob(File.join(@maven_home, "boot", "*jar"))
24
+ end
25
+
26
+ def launch_java(*args)
27
+ 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 ' '}"
28
+ end
29
+
30
+ def options_string
31
+ options_array.join ' '
32
+ end
33
+
34
+ def options_array
35
+ options.collect do |k,v|
36
+ if k =~ /^-D/
37
+ v = "=#{v}" unless v.nil?
38
+ else
39
+ v = " #{v}" unless v.nil?
40
+ end
41
+ "#{k}#{v}"
42
+ end
43
+ end
44
+
45
+ public
46
+
47
+ def maven_home
48
+ @maven_home = File.expand_path(File.join(File.dirname(__FILE__),
49
+ '..',
50
+ '..',
51
+ '..'))
52
+ end
53
+
54
+ def options
55
+ @options ||= {}
56
+ end
57
+
58
+ def verbose= v
59
+ @verbose = v
60
+ end
61
+
62
+ def property(key, value = nil)
63
+ options["-D#{key}"] = value
64
+ end
65
+
66
+ def verbose
67
+ if @verbose.nil?
68
+ options.delete('--verbose').to_s == 'true'
69
+ else
70
+ @verbose
71
+ end
72
+ end
73
+
74
+ def exec(*args)
75
+ a = args.dup + options_array
76
+ a.flatten!
77
+ puts "mvn #{a.join(' ')}" if verbose
78
+ if defined? JRUBY_VERSION
79
+ launch_jruby(a)
80
+ else
81
+ launch_java(a)
82
+ end
83
+ end
84
+
85
+ def exec_in(launchdirectory, *args)
86
+ succeeded = nil
87
+ FileUtils.cd(launchdirectory) do
88
+ succeeded = exec(args)
89
+ end
90
+ succeeded
91
+ end
92
+ end
93
+ end