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

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:



46
47
48
49
50
51
52
# File 'lib/buildr/java/compiler.rb', line 46

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

Instance Method Details

#compile(sources, target, dependencies) ⇒ Object

:nodoc:



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/buildr/java/compiler.rb', line 54

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