Class: Buildr::Java::CompileTask
- Inherits:
-
Rake::Task
- Object
- Rake::Task
- Buildr::Java::CompileTask
- Defined in:
- lib/java/compile.rb
Defined Under Namespace
Classes: Options
Instance Attribute Summary collapse
-
#target ⇒ Object
The target directory for the generated class files.
Instance Method Summary collapse
-
#classpath ⇒ Object
Array of classpath dependencies: files, file tasks, artifacts specs.
- #classpath=(paths) ⇒ Object
-
#compiled? ⇒ Boolean
Returns true if any classes were compiled.
-
#initialize(*args) ⇒ CompileTask
constructor
A new instance of CompileTask.
-
#into(dir) ⇒ Object
Sets the target directory and returns self.
- #needed? ⇒ Boolean
-
#options ⇒ Object
Returns the compiler options.
-
#options=(arg) ⇒ Object
Sets the compile options based on a hash of values, or reset to the default by passing nil.
-
#sources ⇒ Object
An array of source directories and files.
- #sources=(paths) ⇒ Object
- #timestamp ⇒ Object
-
#using(hash) ⇒ Object
Sets the compiler options and returns self.
-
#with(*args) ⇒ Object
Adds files and artifacts to the classpath and returns self.
Constructor Details
#initialize(*args) ⇒ CompileTask
Returns a new instance of CompileTask.
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 |
# File 'lib/java/compile.rb', line 89 def initialize(*args) super if name[":"] # Only if in namespace parent = Rake::Task["^compile"] if parent && parent.respond_to?(:options) @options = Options.new(parent.) end end enhance do |task| # Do we have any files to compile? if target && files.empty? puts "All source files are up to date" if Rake.application..trace && !sources.empty? elsif target mkpath target, :verbose=>false Java.javac files, :sourcepath=>sourcepath, :classpath=>real_classpath, :output=>target, :javac_args=>.javac_args, :name=>task.name # By touching the target we let other tasks know we did something, # and also prevent recompiling again for classpath dependencies. touch target, :verbose=>false @compiled = true end end end |
Instance Attribute Details
#target ⇒ Object
The target directory for the generated class files.
87 88 89 |
# File 'lib/java/compile.rb', line 87 def target @target end |
Instance Method Details
#classpath ⇒ Object
Array of classpath dependencies: files, file tasks, artifacts specs.
124 125 126 |
# File 'lib/java/compile.rb', line 124 def classpath() @classpath ||= [] end |
#classpath=(paths) ⇒ Object
128 129 130 |
# File 'lib/java/compile.rb', line 128 def classpath=(paths) @classpath = paths.flatten end |
#compiled? ⇒ Boolean
Returns true if any classes were compiled.
183 184 185 |
# File 'lib/java/compile.rb', line 183 def compiled?() @compiled || false end |
#into(dir) ⇒ Object
156 157 158 159 |
# File 'lib/java/compile.rb', line 156 def into(dir) self.target = dir self end |
#needed? ⇒ Boolean
191 192 193 194 195 196 |
# File 'lib/java/compile.rb', line 191 def needed?() return false unless target return true unless File.exist?(target) real_classpath.any? { |f| File.stat(f).mtime > } || files.any? { |f| File.stat(f).mtime > } end |
#options ⇒ Object
Returns the compiler options.
133 134 135 |
# File 'lib/java/compile.rb', line 133 def () @options ||= Options.new end |
#options=(arg) ⇒ Object
Sets the compile options based on a hash of values, or reset to the default by passing nil.
139 140 141 142 143 144 145 146 147 148 149 150 151 152 |
# File 'lib/java/compile.rb', line 139 def (arg) case arg when Options @options = arg when Hash .clear arg.each { |k,v| .send "#{k}=", v } when nil .clear else raise ArgumentError, "Expecting Options, hash or nil (to reset)" end @options end |
#sources ⇒ Object
An array of source directories and files.
115 116 117 |
# File 'lib/java/compile.rb', line 115 def sources() @sources ||= [] end |
#sources=(paths) ⇒ Object
119 120 121 |
# File 'lib/java/compile.rb', line 119 def sources=(paths) @sources = paths.flatten end |
#timestamp ⇒ Object
187 188 189 |
# File 'lib/java/compile.rb', line 187 def () @timestamp ||= File.exist?(target) ? File.stat(target).mtime : Rake::EARLY end |
#using(hash) ⇒ Object
Sets the compiler options and returns self. For example:
compile(src_dir).using(:warnings=>true, :verbose=>true)
177 178 179 180 |
# File 'lib/java/compile.rb', line 177 def using(hash) self. = hash self end |