Class: Buildr::Javadoc::JavadocTask

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

Overview

A convenient task for creating Javadocs from the project’s compile task. Minimizes all the hard work to calling #from and #using.

For example:

javadoc.from(projects('myapp:foo', 'myapp:bar')).using(:windowtitle=>'My App')

Or, short and sweet:

desc 'My App'
define 'myapp' do
  . . .
  javadoc projects('myapp:foo', 'myapp:bar')
end

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods inherited from Rake::Task

#invoke, #invoke_with_call_chain

Constructor Details

#initialize(*args) ⇒ JavadocTask

:nodoc:



112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/buildr/java/compiler.rb', line 112

def initialize(*args) #:nodoc:
  super
  @options = {}
  @classpath = []
  @sourcepath = []
  @files = FileList[]
  enhance do |task|
    rm_rf target.to_s, :verbose=>false
    generate source_files, File.expand_path(target.to_s), options.merge(:classpath=>classpath, :sourcepath=>sourcepath)
    touch target.to_s, :verbose=>false
  end
end

Instance Attribute Details

#classpathObject

Classpath dependencies.



161
162
163
# File 'lib/buildr/java/compiler.rb', line 161

def classpath
  @classpath
end

#optionsObject (readonly)

Returns the Javadoc options.



176
177
178
# File 'lib/buildr/java/compiler.rb', line 176

def options
  @options
end

#sourcepathObject

Additional sourcepaths that are not part of the documented files.



173
174
175
# File 'lib/buildr/java/compiler.rb', line 173

def sourcepath
  @sourcepath
end

#targetObject (readonly)

The target directory for the generated Javadoc files.



126
127
128
# File 'lib/buildr/java/compiler.rb', line 126

def target
  @target
end

Instance Method Details

#exclude(*files) ⇒ Object

:call-seq:

exclude(*files) => self

Excludes source files and directories from generating the documentation.



155
156
157
158
# File 'lib/buildr/java/compiler.rb', line 155

def exclude(*files)
  @files.exclude *files
  self
end

#from(*sources) ⇒ Object

:call-seq:

from(*sources) => self

Includes files, directories and projects in the Javadoc documentation and returns self.

You can call this method with Java source files and directories containing Java source files to include these files in the Javadoc documentation, similar to #include. You can also call this method with projects. When called with a project, it includes all the source files compiled by that project and classpath dependencies used when compiling.

For example:

javadoc.from projects('myapp:foo', 'myapp:bar')


203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
# File 'lib/buildr/java/compiler.rb', line 203

def from(*sources)
  sources.flatten.each do |source|
    case source
    when Project
      self.enhance source.prerequisites
      self.include source.compile.sources
      self.with source.compile.dependencies 
    when Rake::Task, String
      self.include source
    else
      fail "Don't know how to generate Javadocs from #{source || 'nil'}"
    end
  end
  self
end

#include(*files) ⇒ Object

:call-seq:

include(*files) => self

Includes additional source files and directories when generating the documentation and returns self. When specifying a directory, includes all .java files in that directory.



146
147
148
149
# File 'lib/buildr/java/compiler.rb', line 146

def include(*files)
  @files.include *files.flatten.compact
  self
end

#into(path) ⇒ Object

:call-seq:

into(path) => self

Sets the target directory and returns self. This will also set the Javadoc task as a prerequisite to a file task on the target directory.

For example:

package :zip, :classifier=>'docs', :include=>javadoc.target


136
137
138
139
# File 'lib/buildr/java/compiler.rb', line 136

def into(path)
  @target = file(path.to_s).enhance([self]) unless @target && @target.to_s == path.to_s
  self
end

#needed?Boolean

:nodoc:

Returns:

  • (Boolean)


229
230
231
232
233
# File 'lib/buildr/java/compiler.rb', line 229

def needed?() #:nodoc:
  return false if source_files.empty?
  return true unless File.exist?(target.to_s)
  source_files.map { |src| File.stat(src.to_s).mtime }.max > File.stat(target.to_s).mtime
end

#prerequisitesObject

:nodoc:



219
220
221
# File 'lib/buildr/java/compiler.rb', line 219

def prerequisites() #:nodoc:
  super + @files + classpath + sourcepath
end

#source_filesObject

:nodoc:



223
224
225
226
227
# File 'lib/buildr/java/compiler.rb', line 223

def source_files() #:nodoc:
  @source_files ||= @files.map(&:to_s).
    map { |file| File.directory?(file) ? FileList[File.join(file, "**/*.java")] : file }.
    flatten.reject { |file| @files.exclude?(file) }
end

#using(*args) ⇒ Object

:call-seq:

using(options) => self

Sets the Javadoc options from a hash and returns self.

For example:

javadoc.using :windowtitle=>'My application'


185
186
187
188
189
# File 'lib/buildr/java/compiler.rb', line 185

def using(*args)
  args.pop.each { |key, value| @options[key.to_sym] = value } if Hash === args.last
  args.each { |key| @options[key.to_sym] = true }
  self
end

#with(*specs) ⇒ Object

:call-seq:

with(*artifacts) => self

Adds files and artifacts as classpath dependencies, and returns self.



167
168
169
170
# File 'lib/buildr/java/compiler.rb', line 167

def with(*specs)
  @classpath |= Buildr.artifacts(specs.flatten).uniq
  self
end