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’])

Direct Known Subclasses

Ecj, ExternalJavac

Constant Summary collapse

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

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
# 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
end

Instance Method Details

#compile(sources, target, dependencies) ⇒ Object

:nodoc:



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/buildr/java/compiler.rb', line 48

def compile(sources, target, dependencies) #:nodoc:
  check_options options, OPTIONS
  cmd_args = []
  # tools.jar contains the Java compiler.
  dependencies << Java.tools_jar if Java.tools_jar
  cmd_args << '-classpath' << dependencies.join(File::PATH_SEPARATOR) unless dependencies.empty?
  source_paths = sources.select { |source| File.directory?(source) }
  cmd_args << '-sourcepath' << source_paths.join(File::PATH_SEPARATOR) unless source_paths.empty?
  cmd_args << '-d' << File.expand_path(target)
  cmd_args += javac_args
  cmd_args += files_from_sources(sources)
  unless Buildr.application.options.dryrun
    trace((['javac'] + cmd_args).join(' '))
    Java.load
    Java.com.sun.tools.javac.Main.compile(cmd_args.to_java(Java.java.lang.String)) == 0 or
      fail 'Failed to compile, see errors above'
  end
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.



69
70
71
72
# File 'lib/buildr/java/compiler.rb', line 69

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