Module: Buildr::Java

Defined in:
lib/java/java.rb,
lib/java/compile.rb,
lib/java/packaging.rb

Defined Under Namespace

Modules: Packaging Classes: AptTask, CompileTask

Constant Summary collapse

JAVA_OPTIONS =
[ :verbose, :noop, :cp, :classpath, :name, :java_args ]

Class Method Summary collapse

Class Method Details

.apt(*args) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/java/java.rb', line 24

def self.apt(*args)
  options = Hash === args.last ? args.pop : {}
  options[:verbose] ||= Rake.application.options.trace || false
  fu_check_options options, :verbose, :noop, :compile, :source, :output, :cp, :classpath

  files = args.collect { |arg| File.directory?(arg) ? FileList[File.join(arg, "**", "*.java")] : arg }.flatten
  args = [ options[:verbose] ? "-verbose" : "-nowarn" ]
  if options[:compile]
    args << "-d" << options[:output]
  else
    args << "-nocompile" << "-s" << options[:output]
  end
  args << "-source" << options[:source] if options[:source]
  classpath = classpath_from(options)
  args << "-cp" << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
  args += files
  args << { :verbose=>options[:verbose] }
  unless options[:noop]
    puts "Running apt" if verbose
    sh(path_to_bin("apt"), *args) { |ok, res| fail "Failed to execute apt, see errors above" unless ok }
  end
end

.apt_task(args) ⇒ Object



67
68
69
70
71
# File 'lib/java/java.rb', line 67

def self.apt_task(args)
  output = args.keys.first
  files = args.values.first.collect { |f| File.directory?(f) ? FileList[f + "/**/*.java"] : f }.flatten
  AptTask.define_task(output=>files)  
end

.java(*args) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/java/java.rb', line 6

def self.java(*args)
  options = Hash === args.last ? args.pop : {}
  options[:verbose] ||= Rake.application.options.trace || false
  fu_check_options options, *JAVA_OPTIONS

  name = options[:name] || "java #{args.first}"
  cmd_args = []
  classpath = classpath_from(options)
  cmd_args << "-cp" << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
  cmd_args += options[:java_args].flatten if options[:java_args]
  cmd_args += args.flatten.compact
  cmd_args << { :verbose=>options[:verbose] }
  unless options[:noop]
    puts "Running #{name}" if verbose
    sh(path_to_bin("java"), *cmd_args) { |ok, res| fail "Failed to execute #{name}, see errors above" unless ok }
  end
end

.javac(*args) ⇒ Object



73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/java/java.rb', line 73

def self.javac(*args)
  options = Hash === args.last ? args.pop : {}
  options[:verbose] ||= Rake.application.options.trace || false
  fu_check_options options, :verbose, :noop, :cp, :classpath, :sourcepath, :output, :javac_args, :name

  files = args.flatten.each { |f| f.invoke if f.respond_to?(:invoke) }.map(&:to_s).
    collect { |arg| File.directory?(arg) ? FileList[File.join(arg, "**", "*.java")] : arg }.flatten
  name = options[:name] || Dir.pwd

  cmd_args = []
  classpath = classpath_from(options)
  #classpath += options[:output] if options[:output]
  cmd_args << "-cp" << classpath.join(File::PATH_SEPARATOR) unless classpath.empty?
  cmd_args << "-sourcepath" << options[:sourcepath].join(File::PATH_SEPARATOR) if options[:sourcepath]
  cmd_args << "-d" << options[:output] if options[:output]
  cmd_args += options[:javac_args].flatten if options[:javac_args]
  cmd_args += files
  cmd_args << { :verbose=>options[:verbose] }
  unless options[:noop] || files.empty?
    puts "Compiling #{files.size} source files in #{name}" if verbose
    sh(path_to_bin("javac"), *cmd_args) { |ok, res| fail "Failed to compile, see errors above" unless ok }
  end
end