Skip to content

Commit

Permalink
reworked pom_magic to allow it to be reused by jetty-run/gwt-run and …
Browse files Browse the repository at this point in the history
…others
  • Loading branch information
mkristian committed Mar 1, 2013
1 parent 823f724 commit c737360
Show file tree
Hide file tree
Showing 4 changed files with 80 additions and 49 deletions.
2 changes: 0 additions & 2 deletions bin/rmvn
Original file line number Diff line number Diff line change
@@ -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
Expand Down
7 changes: 7 additions & 0 deletions lib/ruby/maven/ruby/Mavenfile
Original file line number Diff line number Diff line change
@@ -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
8 changes: 3 additions & 5 deletions lib/ruby/maven/ruby/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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
Expand All @@ -160,4 +158,4 @@ def exec_in(launchdirectory, *args)
end
end
end
end
end
112 changes: 70 additions & 42 deletions lib/ruby/maven/ruby/pom_magic.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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.