Module: Buildr::Apt
- Included in:
- Project
- Defined in:
- lib/buildr/java/compiler.rb
Overview
Methods added to Project to support the Java Annotation Processor.
Instance Method Summary collapse
-
#apt(*sources) ⇒ Object
:call-seq: apt(*sources) => task.
Instance Method Details
#apt(*sources) ⇒ Object
:call-seq:
apt(*sources) => task
Returns a task that will use Java#apt to generate source files in target/generated/apt, from all the source directories passed as arguments. Uses the compile.sources list if on arguments supplied.
For example:
322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 |
# File 'lib/buildr/java/compiler.rb', line 322 def apt(*sources) sources = compile.sources if sources.empty? file(path_to(:target, 'generated/apt')=>sources) do |task| cmd_args = [ Buildr.application..trace ? '-verbose' : '-nowarn' ] cmd_args << '-nocompile' << '-s' << task.name cmd_args << '-source' << compile..source if compile..source classpath = Buildr.artifacts(compile.dependencies).map(&:to_s).each { |t| task(t).invoke } cmd_args << '-classpath' << classpath.join(File::PATH_SEPARATOR) unless classpath.empty? cmd_args += (sources.map(&:to_s) - [task.name]). map { |file| File.directory?(file) ? FileList["#{file}/**/*.java"] : file }.flatten unless Buildr.application..dryrun info 'Running apt' trace (['apt'] + cmd_args).join(' ') 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 end |