lib/buildr/xmlbeans.rb in buildr-1.1.3 vs lib/buildr/xmlbeans.rb in buildr-1.2.0
- old
+ new
@@ -1,9 +1,11 @@
require "java/java"
require "java/ant"
module Buildr
+
+ # Provides XMLBeans schema compiler. Require explicitly using <code>require "buildr/xmlbeans"</code>.
module XMLBeans
REQUIRES = [ "xmlbeans:xbean:jar:2.2.0", "stax:stax-api:jar:1.0" ]
class << self
@@ -11,16 +13,16 @@
def compile(*args)
options = Hash === args.last ? args.pop : {}
options[:verbose] ||= Rake.application.options.trace || false
rake_check_options options, :verbose, :noop, :javasource, :jar, :compile, :output, :xsb
puts "Running XMLBeans schema compiler" if verbose
- Ant.executable("xmlbeans") do |ant|
+ Buildr.ant "xmlbeans" do |ant|
ant.taskdef :name=>"xmlbeans", :classname=>"org.apache.xmlbeans.impl.tool.XMLBean",
:classpath=>requires.join(File::PATH_SEPARATOR)
ant.xmlbeans :srconly=>"true", :srcgendir=>options[:output].to_s, :classgendir=>options[:output].to_s,
:javasource=>options[:javasource] do
- args.flatten.each { |file| fileset File.directory?(file) ? { :dir=>file } : { :file=>file } }
+ args.flatten.each { |file| ant.fileset File.directory?(file) ? { :dir=>file } : { :file=>file } }
end
end
# Touch paths to let other tasks know there's an update.
touch options[:output].to_s, :verbose=>false
end
@@ -32,12 +34,15 @@
end
end
def compile_xml_beans(*args)
+ # Run whenever XSD file changes, but typically we're given an directory of XSD files, or even file patterns
+ # (the last FileList is there to deal with things like *.xsdconfig).
+ files = args.flatten.map { |file| File.directory?(file) ? FileList["#{file}/*.xsd"] : FileList[file] }.flatten
# Generate sources and add them to the compile task.
- generated = file(path_to(:target, "generated/xmlbeans")=>FileList[args.flatten]) do |task|
- XMLBeans.compile task.prerequisites, :output=>task.name,
+ generated = file(path_to(:target, "generated/xmlbeans")=>files) do |task|
+ XMLBeans.compile args.flatten, :output=>task.name,
:javasource=>compile.options.source, :xsb=>compile.target
end
compile.from(generated).with(JAVAX.stream, XMLBEANS)
# Once compiled, we need to copy the generated XSB/XSD and one (magical?) class file
# into the target directory, or the rest is useless.