lib/ruby/maven/ruby/pom_magic.rb in ruby-maven-3.0.4.1 vs lib/ruby/maven/ruby/pom_magic.rb in ruby-maven-3.0.4.1.1
- old
+ new
@@ -16,49 +16,53 @@
def pom_xml(dir = '.')
File.join(dir, @pom)
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')
if force || !File.exists?(file)
FileUtils.cp(generate_pom(dir), file)