module Buildr module OpenJPA VERSION = "0.9.7-incubating-SNAPSHOT" REQUIRES = [ "org.apache.openjpa:openjpa-all:jar:#{VERSION}", "commons-collections:commons-collections:jar:3.1", "commons-dbcp:commons-dbcp:jar:1.2.1", "commons-lang:commons-lang:jar:2.1", "commons-pool:commons-pool:jar:1.2", "javax.persistence:persistence-api:jar:1.0", "org.apache.geronimo.specs:geronimo-j2ee-connector_1.5_spec:jar:1.0", "org.apache.geronimo.specs:geronimo-jta_1.0.1B_spec:jar:1.0", "net.sourceforge.serp:serp:jar:1.11.0" ] OPTIONS = [ :verbose, :noop, :cp, :classpath, :properties ] def self.enhance(options) options[:verbose] ||= Rake.application.options.trace || false fu_check_options options, *OPTIONS + [:output] runtool options.merge(:class=>"org.apache.openjpa.enhance.PCEnhancer", :name=>"Enhancer", :args=>{ "-p"=>options[:properties], "-d"=>options[:output] }, :classpath=>options[:classpath] + [options[:output]]) end def self.mapping_tool(options) options[:verbose] ||= Rake.application.options.trace || false fu_check_options options, *OPTIONS + [:action, :sql] runtool options.merge(:class=>"org.apache.openjpa.jdbc.meta.MappingTool", :name=>"Mapping Tool", :args=>{ "-p"=>options[:properties], "-sql"=>options[:sql], "-sa"=>options[:action] }) end protected def self.runtool(options) classpath = REQUIRES + (options[:classpath] || []).collect | (options[:cp] || []).collect classpath = artifacts(classpath).each { |t| t.invoke if t.respond_to?(:invoke) }.map(&:to_s) cmd_args = ["-cp", classpath.join(File::PATH_SEPARATOR)] cmd_args << options[:class] cmd_args += options[:args].select { |n, v| v }.map { |n, v| [ n, v ] }.flatten cmd_args << { :verbose=>options[:verbose] } unless options[:noop] verbose { puts "Running OpenJPA #{options[:name]}" } sh(Java.path_to_bin("java"), *cmd_args) { |ok, res| fail "Failed to execute OpenJPA #{options[:name]}, see errors above" unless ok } end end end end