Method: Java::Commands.apt

Defined in:
lib/buildr/java/commands.rb

.apt(*args) ⇒ Object

:call-seq:

apt(*files, options)

Runs Apt with the specified arguments.

The last argument may be a Hash with additional options:

  • :compile – If true, compile source files to class files.

  • :source – Specifies source compatibility with a given JVM release.

  • :output – Directory where to place the generated source files, or the generated class files when compiling.

  • :classpath – One or more file names, tasks or artifact specifications. These are all expanded into artifacts, and all tasks are invoked.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
# File 'lib/buildr/java/commands.rb', line 72

def apt(*args)
  options = Hash === args.last ? args.pop : {}
  rake_check_options options, :compile, :source, :output, :classpath

  files = args.flatten.map(&:to_s).
    collect { |arg| File.directory?(arg) ? FileList["#{arg}/**/*.java"] : arg }.flatten
  cmd_args = [ Buildr.application.options.trace ? '-verbose' : '-nowarn' ]
  if options[:compile]
    cmd_args << '-d' << options[:output].to_s
  else
    cmd_args << '-nocompile' << '-s' << options[:output].to_s
  end
  cmd_args << '-source' << options[:source] if options[:source]
  classpath = classpath_from(options)
  tools = Java.tools_jar
  classpath << tools if tools
  cmd_args << '-classpath' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
  cmd_args += files
  unless Buildr.application.options.dryrun
    info 'Running apt'
    trace (['apt'] + cmd_args).join(' ')
    Java.load
    Java.com.sun.tools.apt.Main.process(cmd_args.to_java(Java.java.lang.String)) == 0 or
      fail 'Failed to process annotations, see errors above'
  end
end