module Buildr::XMLBeans
Provides XMLBeans
schema compiler. Require explicitly using require "buildr/xmlbeans"
.
require 'buildr/xmlbeans' define 'some_proj' do compile_xml_beans _(:source, :main, :xsd) # the directory with *.xsd end
Constants
- REQUIRES
You can use
ArtifactNamespace
to customize the versions of:xmlbeans
or:stax
used by this module:require 'buildr/xmlbeans' Buildr::XMLBeans::REQUIRES.xmlbeans = '2.2.0'
Public Class Methods
compile(*args)
click to toggle source
# File addon/buildr/xmlbeans.rb, line 38 def compile(*args) options = Hash === args.last ? args.pop : {} options[:verbose] ||= trace?(:xmlbeans) rake_check_options options, :verbose, :noop, :javasource, :jar, :compile, :output, :xsb puts "Running XMLBeans schema compiler" if verbose 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| 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
requires()
click to toggle source
# File addon/buildr/xmlbeans.rb, line 55 def requires() @requires ||= REQUIRES.artifacts end
Public Instance Methods
compile_xml_beans(*args)
click to toggle source
# File addon/buildr/xmlbeans.rb, line 60 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)=>files) do |task| XMLBeans.compile args.flatten, :output=>task.name, :javasource=>compile.options.source, :xsb=>compile.target end compile.using(:javac).from(generated).with(*XMLBeans.requires) # Once compiled, we need to copy the generated XSB/XSD and one (magical?) class file # into the target directory, or the rest is useless. compile do |task| verbose(false) do base = generated.to_s FileList["#{base}/**/*.{class,xsb,xsd}"].each do |file| target = File.join(compile.target.to_s, Util.relative_path(file, base)) mkpath File.dirname(target) ; cp file, target end end end end