Module: Buildr::XMLBeans

Defined in:
lib/java/xmlbeans.rb

Defined Under Namespace

Classes: CompileTask

Constant Summary collapse

REQUIRES =
[ "xmlbeans:xbean:jar:2.2.0", "stax:stax-api:jar:1.0" ]

Class Method Summary collapse

Class Method Details

.compile(*args) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/java/xmlbeans.rb', line 7

def self.compile(*args)
  options = Hash === args.last ? args.pop : {}
  options[:verbose] ||= Rake.application.options.trace || false
  fu_check_options options, :verbose, :noop, :javasource, :jar, :classes, :output

  # Options for SchemaCompiler.
  cmd_args = [ options[:verbose] ? "-verbose" : "-quiet" ]
  cmd_args << "-javasource" << options[:javasource].collect.join(File::PATH_SEPARATOR) if options[:javasource]
  cmd_args << "-out" << options[:jar] if options[:jar]
  cmd_args << "-d" << options[:classes] if options[:classes]
  cmd_args << "-src" << options[:output] if options[:output]
  cmd_args += args
  cmd_args << { :verbose=>options[:verbose] }

  unless options[:noop]
    verbose { puts "Running XMLBeans schema compiler" }
    mkpath options[:classes], :verbose=>false rescue nil if options[:classes]
    mkpath options[:output], :verbose=>false rescue nil if options[:output]
    sh(Java.path_to_bin("java"), "-Xmx256m", "-cp", requires.join(File::PATH_SEPARATOR),
      "org.apache.xmlbeans.impl.tool.SchemaCompiler", *cmd_args) { |ok, res|
      fail "Failed to compile schemas, see errors above" unless ok }
    # Touch paths to let other tasks know there's an update.
    touch options[:classes], :verbose=>false if options[:classes]
    touch options[:output], :verbose=>false if options[:output]
  end
end

.compile_task(args) ⇒ Object



58
59
60
61
62
# File 'lib/java/xmlbeans.rb', line 58

def self.compile_task(args)
  output = args.keys.first
  files = args.values.first.collect { |f| File.directory?(f) ? FileList[f + "/**/*"] : f }.flatten
  CompileTask.define_task(output=>files)  
end

.requiresObject



34
35
36
# File 'lib/java/xmlbeans.rb', line 34

def self.requires()
  @requires ||= artifacts(REQUIRES).each { |artifact| artifact.invoke }.map(&:to_s)
end