Permalink
Browse files

reworked pom_magic to allow it to be reused by jetty-run/gwt-run and …

…others
  • Loading branch information...
1 parent 823f724 commit c737360d14dbcdf21478157332bc8decf2e1d04c @mkristian committed Mar 1, 2013
Showing with 80 additions and 49 deletions.
  1. +0 −2 bin/rmvn
  2. +7 −0 lib/ruby/maven/ruby/Mavenfile
  3. +3 −5 lib/ruby/maven/ruby/cli.rb
  4. +70 −42 lib/ruby/maven/ruby/pom_magic.rb
View
@@ -1,9 +1,7 @@
#!/usr/bin/env ruby
require 'maven/ruby/cli'
-require 'maven/ruby/pom_magic'
mvn = Maven::Ruby::Cli.new
-magic = Maven::Ruby::PomMagic.new
args = ARGV.dup
ARGV.clear # clean up in case another script gets executed it gets clear ARGV
@@ -0,0 +1,7 @@
+#-*- mode: ruby -*-
+
+# lock down versions
+properties['jruby.version'] = '1.7.3'
+properties['jruby.plugins.version'] = '0.29.4'
+
+# vim: syntax=Ruby
@@ -129,7 +129,7 @@ def command_line(args)
def setup(dir = '.', *args)
log(args)
args = command_line(args.dup.flatten)
- args = magic_pom(dir, *args) unless options.delete('--no-pom')
+ args = magic_pom(dir, *args)
args
end
@@ -140,9 +140,7 @@ def mvn
protected
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
+ PomMagic.new.generate_pom(File.expand_path(dir), *args)
end
public
@@ -160,4 +158,4 @@ def exec_in(launchdirectory, *args)
end
end
end
-end
+end
@@ -26,71 +26,99 @@ module Maven
module Ruby
class PomMagic
- def initialize(pom = '.pom.xml')
- @pom = pom
- end
-
- def new_rails_project
- ::Maven::Tools::RailsProject.new
- end
-
- def pom_xml(dir = '.')
- File.join(dir, @pom)
+ def dump_pom( dir = '.', force = false, file = 'pom.xml' )
+ if force || !File.exists?( file )
+ generate_pom( dir, '--pom', file )
+ end
end
- def generate_pom(dir = '.', *args)
- pom = nil
+ def generate_pom( dir = '.', *args )
dir = File.expand_path( dir )
Dir.chdir(dir) do
+ skip_some_files = false
if index = (args.index("-f") || args.index("--file"))
filename = args[index + 1]
if filename =~ /.gemspec$/
+ skip_some_files = true
proj = ::Maven::Tools::GemProject.new
proj.load_gemspec(filename)
elsif filename =~ /Gemfile/
+ skip_some_files = true
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)
+ proj =
+ if File.exists? File.join( 'config', 'application.rb' )
+ ::Maven::Tools::RailsProject.new
+ else
+ ::Maven::Tools::GemProject.new
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( :jruby_plugins => JRUBY_MAVEN_PLUGINS_VERSION )
- pom = pom_xml(dir)
- File.open(pom, 'w') do |f|
- f.puts proj.to_xml
+
+ ensure_mavenfile( dir )
+
+ load_standard_files( dir, proj, skip_some_files )
+
+ pom_xml( dir, proj, args )
+
+ end
+ end
+ end
+
+ protected
+
+ def load_standard_files( dir, proj, skip_some_files = false )
+ gemspec = first_gemspec( dir ) unless skip_some_files
+ proj.load_gemspec( gemspec ) if gemspec
+ proj.load_gemfile( file( 'Gemfile', dir ) ) unless skip_some_files
+ proj.load_jarfile( file( 'Jarfile', dir ) )
+ proj.load_mavenfile( file( 'Mavenfile', dir ) )
+ proj.add_defaults
+ end
+
+ def ensure_mavenfile( dir, source = File.dirname( __FILE__ ), filter_map = {} )
+ mavenfile = File.join( dir, 'Mavenfile' )
+ unless File.exists?( mavenfile )
+ content = File.read( File.join( source, 'Mavenfile' ) )
+ File.open( mavenfile, 'w' ) do |f|
+ filter_map.each do |k,v|
+ content.gsub!( /#{k}/, v )
end
+ f.puts content
end
+ warn "created Mavenfile with some locked down versions."
+ end
+ end
+
+ def file( name, dir = '.' )
+ File.expand_path( File.join( dir, name ) )
+ end
+
+ def pom_xml( dir = '.', proj, args )
+ index = args.index( '-f' ) || args.index( '--file' )
+ index ||= args.index( '--pom' )
+ name = args[ index + 1 ] if index
+ pom = File.join( dir, name || '.pom.xml' )
+ File.open(pom, 'w') do |f|
+ f.puts proj.to_xml
+ end
+ if index
+ args[ index ] = '-f'
+ else
+ args += ['-f', pom]
end
- pom
+ args
end
- def dump_pom(dir = '.', force = false, file = 'pom.xml')
- if force || !File.exists?(file)
- FileUtils.cp(generate_pom(dir), file)
+ def first_gemspec( dir = '.' )
+ gemspecs = Dir[ File.join( dir, "*.gemspec" ) ]
+ if gemspecs.size > 0
+ File.expand_path( gemspecs[ 0 ] )
end
end
+
end
end
-end
+end

0 comments on commit c737360

Please sign in to comment.