Class: Buildr::Compiler::Javac

Inherits:
Base show all
Defined in:
lib/buildr/java/compiler.rb

Overview

Javac compiler:

compile.using(:javac)

Used by default if .java files are found in the src/main/java directory (or src/test/java) and sets the target directory to target/classes (or target/test/classes).

Accepts the following options:

  • :warnings – Issue warnings when compiling. True when running in verbose mode.

  • :debug – Generates bytecode with debugging information. Set from the debug

environment variable/global option.

  • :deprecation – If true, shows deprecation messages. False by default.

  • :source – Source code compatibility.

  • :target – Bytecode compatibility.

  • :lint – Lint option is one of true, false (default), name (e.g. ‘cast’) or array.

  • :other – Array of options passed to the compiler

(e.g. [‘-implicit:none’, ‘-encoding’, ‘iso-8859-1’])

Constant Summary collapse

OPTIONS =
[:warnings, :debug, :deprecation, :source, :target, :lint, :other, :processor_path, :processor_options, :processor]

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

applies_to?, #dependencies, dependencies, #needed?, specify, to_sym

Constructor Details

#initialize(project, options) ⇒ Javac

:nodoc:



40
41
42
43
44
45
46
47
48
49
# File 'lib/buildr/java/compiler.rb', line 40

def initialize(project, options) #:nodoc:
  super
  options[:debug] = Buildr.options.debug if options[:debug].nil?
  options[:warnings] ||= false
  options[:deprecation] ||= false
  options[:lint] ||= false
  options[:processor] ||= nil
  options[:processor_path] ||= []
  options[:processor_options] ||= {}
end

Instance Method Details

#compile(sources, target, dependencies) ⇒ Object

:nodoc:



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/buildr/java/compiler.rb', line 51

def compile(sources, target, dependencies) #:nodoc:
  check_options options, OPTIONS
  processor = !!options[:processor] || options[:processor].nil?
  Java::Commands.javac(files_from_sources(sources),
                       :classpath => dependencies,
                       :sourcepath => sources.select { |source| File.directory?(source) },
                       :output => target,
                       :processor => processor,
                       :processor_path => (processor ? options[:processor_path] : []),
                       :javac_args => javac_args)
end

#compile_map(sources, target) ⇒ Object

Filter out source files that are known to not produce any corresponding .class output file. If we leave this type of file in the generated compile map the compiler will always be run due to missing output files.



65
66
67
68
# File 'lib/buildr/java/compiler.rb', line 65

def compile_map(sources, target)
  map = super
  map.reject! { |key,_| File.basename(key) == 'package-info.java' } || map
end