Permalink
Browse files

* use backward compatible class to be Cli

* go to right directory on generating pom
* add verbose flag for ruby-maven
* fix some argument parsing and creating
  • Loading branch information...
1 parent ab07c97 commit e64598532c174bd6b08f2b65a3782d0658506661 @mkristian committed Oct 12, 2012
Showing with 80 additions and 61 deletions.
  1. +20 −12 lib/ruby/maven/ruby/cli.rb
  2. +21 −14 lib/ruby/maven/ruby/maven.rb
  3. +38 −34 lib/ruby/maven/ruby/pom_magic.rb
  4. +1 −1 lib/ruby/maven/ruby/version.rb
View
@@ -1,4 +1,5 @@
require 'maven/ruby/maven'
+require 'maven/ruby/pom_magic'
module Maven
module Ruby
class Cli
@@ -58,7 +59,7 @@ def prepare(args)
ruby_args = (args[start, (index || 1000) - start] || []).join(' ')
aa << "de.saumya.mojo:#{name}-maven-plugin#{version}:#{goal}"
- aa << "-Dargs=\"#{ruby_args}\"" if ruby_args.size > 0
+ aa << "\"-Dargs=#{ruby_args}\"" if ruby_args.size > 0
args.replace(aa)
else
args.delete("--")
@@ -104,30 +105,37 @@ def command_line(args)
args
end
- def setup(*args)
- args = magic_pom(args)
+ def setup(dir = '.', *args)
log(args)
- command_line(args.dup.flatten)
+ args = command_line(args.dup.flatten)
+ args = magic_pom(dir, *args) unless options.delete('--no-pom')
+ args
+ end
+
+ def mvn
+ @mvn ||= Maven.new
end
protected
- def magic_pom(*args)
- file = PomMagic.new.generate_pom(args)
- args += ['-f', file] if file && !(args.member?("-f") || args.member?("--file"))
- args
+ def magic_pom(dir = '.', *args)
+ file = PomMagic.new.generate_pom(File.expand_path(dir), *args)
+ args += ['-f', file] if file && !(args.member?("-f") || args.member?("--file"))
+ args.flatten
end
public
+ def options
+ mvn.options
+ end
+
def exec(*args)
- mvn = Maven.new
- mvn.exec(setup(args))
+ mvn.exec(setup('.', *args))
end
def exec_in(launchdirectory, *args)
- mvn = Maven.new
- mvn.exec_in(launchdirectory, setup(args))
+ mvn.exec_in(launchdirectory, setup(launchdirectory, *args))
end
end
end
@@ -2,6 +2,15 @@
require 'java' if defined? JRUBY_VERSION
module Maven
+
+ class RubyMaven
+
+ def self.new(*args)
+ warn "deprecated: use Maven::Ruby::Cli or Maven::Ruby::Maven instead"
+ ::Maven::Ruby::Cli.new(*args)
+ end
+ end
+
module Ruby
class Maven
@@ -12,7 +21,6 @@ def launch_jruby(args)
File.join(self.class.maven_home, 'bin', "m2.conf"))
java.lang.System.setProperty("maven.home", self.class.maven_home)
-
cw = self.class.class_world
org.apache.maven.cli.MavenCli.doMain( args, cw ) == 0
end
@@ -44,11 +52,15 @@ def options_array
options.collect do |k,v|
if k =~ /^-D/
v = "=#{v}" unless v.nil?
+ "#{k}#{v}"
else
- v = " #{v}" unless v.nil?
+ if v.nil?
+ "#{k}"
+ else
+ ["#{k}", "#{v}"]
+ end
end
- "#{k}#{v}"
- end
+ end.flatten
end
public
@@ -79,39 +91,34 @@ def property(key, value = nil)
def verbose
if @verbose.nil?
- options.delete('-Dverbose').to_s == 'true'
+ @verbose = options.delete('-Dverbose').to_s == 'true'
else
@verbose
end
end
def exec(*args)
+ puts "PWD: #{File.expand_path('.')}" if verbose
a = args.dup + options_array
a.flatten!
puts "mvn #{a.join(' ')}" if verbose
if defined? JRUBY_VERSION
+ puts "using jruby #{JRUBY_VERSION}" if verbose
launch_jruby(a)
else
+ puts "using java" if verbose
launch_java(a)
end
end
def exec_in(launchdirectory, *args)
succeeded = nil
- FileUtils.cd(launchdirectory) do
+ Dir.chdir(launchdirectory) do
succeeded = exec(args)
end
succeeded
end
end
end
- class RubyMaven
-
- def self.new(*args)
- warn "deprecated: use Maven::Ruby::Maven instead"
- Maven::Ruby::Maven.new(*args)
- end
- end
-
end
@@ -18,46 +18,50 @@ def pom_xml(dir = '.')
end
def generate_pom(dir = '.', *args)
- if index = (args.index("-f") || args.index("--file"))
- filename = args[index + 1]
- if filename =~ /.gemspec$/
- proj = ::Maven::Tools::GemProject.new
- proj.load_gemspec(filename)
- elsif filename =~ /Gemfile/
- proj = ::Maven::Tools::GemProject.new
- proj.load_gemfile(filename)
- end
- else
- gemfiles = Dir[File.join(dir, "*Gemfile")]
- gemfiles.delete_if {|g| g =~ /.pom/}
- if gemfiles.size > 0
- proj =
- if File.exists? File.join( dir, 'config', 'application.rb' )
- new_rails_project
- else
- ::Maven::Tools::GemProject.new
- end
- filename = gemfiles[0]
- proj.load_gemfile(filename)
- else
- gemspecs = Dir[File.join(dir, "*.gemspec")]
- gemspecs.delete_if {|g| g =~ /.pom/}
- if gemspecs.size > 0
+ pom = nil
+ Dir.chdir(dir) do
+ if index = (args.index("-f") || args.index("--file"))
+ filename = args[index + 1]
+ if filename =~ /.gemspec$/
proj = ::Maven::Tools::GemProject.new
- filename = gemspecs[0]
proj.load_gemspec(filename)
+ elsif filename =~ /Gemfile/
+ proj = ::Maven::Tools::GemProject.new
+ proj.load_gemfile(filename)
+ end
+ else
+ gemfiles = Dir[File.join('.', "*Gemfile")]
+ gemfiles.delete_if {|g| g =~ /.pom/}
+ if gemfiles.size > 0
+ proj =
+ if File.exists? File.join( 'config', 'application.rb' )
+ new_rails_project
+ else
+ ::Maven::Tools::GemProject.new
+ end
+ filename = gemfiles[0]
+ proj.load_gemfile(filename)
+ else
+ gemspecs = Dir[File.join('.', "*.gemspec")]
+ gemspecs.delete_if {|g| g =~ /.pom/}
+ if gemspecs.size > 0
+ proj = ::Maven::Tools::GemProject.new
+ filename = File.basename(gemspecs[0])
+ proj.load_gemspec(filename)
+ end
end
end
- end
- if proj
- proj.load_jarfile(File.join(File.dirname(filename), 'Jarfile'))
- proj.load_gemfile(File.join(File.dirname(filename), 'Mavenfile'))
- proj.add_defaults
- File.open(pom_xml(dir), 'w') do |f|
- f.puts proj.to_xml
+ if proj
+ proj.load_jarfile(File.join(File.dirname(filename), 'Jarfile'))
+ proj.load_gemfile(File.join(File.dirname(filename), 'Mavenfile'))
+ proj.add_defaults
+ pom = pom_xml(dir)
+ File.open(pom, 'w') do |f|
+ f.puts proj.to_xml
+ end
end
- pom_xml(dir)
end
+ pom
end
def dump_pom(dir = '.', force = false, file = 'pom.xml')
@@ -1,5 +1,5 @@
module Maven
module Ruby
- VERSION = '3.0.4.2'
+ VERSION = '3.0.4.1'
end
end

0 comments on commit e645985

Please sign in to comment.