Class: Buildr::Compiler::Javac
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
Constant Summary collapse
- OPTIONS =
[:warnings, :debug, :deprecation, :source, :target, :lint, :other]
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
-
#compile(sources, target, dependencies) ⇒ Object
:nodoc:.
-
#compile_map(sources, target) ⇒ Object
Filter out source files that are known to not produce any corresponding .class output file.
-
#initialize(project, options) ⇒ Javac
constructor
:nodoc:.
Methods inherited from Base
applies_to?, #dependencies, dependencies, #needed?, specify, to_sym
Constructor Details
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: , 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.(target) cmd_args += javac_args cmd_args += files_from_sources(sources) unless Buildr.application..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 |