Class: JavaTools::Javac

Inherits:
Object
  • Object
show all
Defined in:
lib/java_tools/javac.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*source_files) ⇒ Javac

Returns a new instance of Javac.



22
23
24
25
26
27
28
29
30
31
32
# File 'lib/java_tools/javac.rb', line 22

def initialize( *source_files )
  @source_files = source_files || [ ]
  
  @source_path          = [ ]
  @destination          = 'build'
  @class_path           = [ ]
  @deprecation_warnings = true
  @warnings             = true
  @encoding             = nil
  @verbose              = false
end

Instance Attribute Details

#class_pathObject

array



13
14
15
# File 'lib/java_tools/javac.rb', line 13

def class_path
  @class_path
end

#deprecation_warningsObject

array



13
14
15
# File 'lib/java_tools/javac.rb', line 13

def deprecation_warnings
  @deprecation_warnings
end

#destinationObject

array



13
14
15
# File 'lib/java_tools/javac.rb', line 13

def destination
  @destination
end

#encodingObject

array



13
14
15
# File 'lib/java_tools/javac.rb', line 13

def encoding
  @encoding
end

#source_filesObject

array



13
14
15
# File 'lib/java_tools/javac.rb', line 13

def source_files
  @source_files
end

#source_pathObject

array



13
14
15
# File 'lib/java_tools/javac.rb', line 13

def source_path
  @source_path
end

#verboseObject

array



13
14
15
# File 'lib/java_tools/javac.rb', line 13

def verbose
  @verbose
end

#warningsObject

array



13
14
15
# File 'lib/java_tools/javac.rb', line 13

def warnings
  @warnings
end

Instance Method Details

#command_argsObject



34
35
36
37
38
39
40
41
42
43
# File 'lib/java_tools/javac.rb', line 34

def command_args
  args = [ ]
  args << '-sourcepath' << @source_path.join(':') unless @source_path.empty?
  args << '-d' << @destination unless (@destination.nil? || @destination =~ /^\s*$/)
  args << '-classpath' << @class_path.join(':') unless @class_path.empty?
  args << '-deprecation' unless @deprecation_warnings
  args << '-nowarn' unless @warnings
  args << '-encoding' << @encoding if @encoding
  args + @source_files
end

#command_stringObject



45
46
47
48
49
50
51
52
53
54
55
# File 'lib/java_tools/javac.rb', line 45

def command_string
  args = [ ]
  args << '-sourcepath' << @source_path.join(':') unless @source_path.empty?
  args << '-d' << @destination unless (@destination.nil? || @destination =~ /^\s*$/)
  args << '-classpath' << @class_path.join(':') unless @class_path.empty?
  args << '-deprecation' unless @deprecation_warnings
  args << '-nowarn' unless @warnings
  args << '-encoding' << @encoding if @encoding

  "javac #{args.join(' ')}"
end

#execute(io = $stderr) ⇒ Object



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/java_tools/javac.rb', line 57

def execute( io = $stderr )
  output_writer = StringWriter.new
  
  args = command_args.to_java(java.lang.String)
  
  result = com.sun.tools.javac.Main.compile(args, PrintWriter.new(output_writer))
  
  io.puts command_string if @verbose
  
  output_str = output_writer.to_s
  
  io.puts output_str if output_str !~ /^\s*$/
  
  if 0 == result
    true
  else
    false
  end
end