Class: JavaTools::Javac
- Inherits:
-
Object
- Object
- JavaTools::Javac
- Defined in:
- lib/java_tools/javac.rb
Instance Attribute Summary collapse
-
#class_path ⇒ Object
array.
-
#deprecation_warnings ⇒ Object
array.
-
#destination ⇒ Object
array.
-
#encoding ⇒ Object
array.
-
#source_files ⇒ Object
array.
-
#source_path ⇒ Object
array.
-
#verbose ⇒ Object
array.
-
#warnings ⇒ Object
array.
Instance Method Summary collapse
- #command_args ⇒ Object
- #command_string ⇒ Object
- #execute(io = $stderr) ⇒ Object
-
#initialize(*source_files) ⇒ Javac
constructor
A new instance of Javac.
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_path ⇒ Object
array
13 14 15 |
# File 'lib/java_tools/javac.rb', line 13 def class_path @class_path end |
#deprecation_warnings ⇒ Object
array
13 14 15 |
# File 'lib/java_tools/javac.rb', line 13 def deprecation_warnings @deprecation_warnings end |
#destination ⇒ Object
array
13 14 15 |
# File 'lib/java_tools/javac.rb', line 13 def destination @destination end |
#encoding ⇒ Object
array
13 14 15 |
# File 'lib/java_tools/javac.rb', line 13 def encoding @encoding end |
#source_files ⇒ Object
array
13 14 15 |
# File 'lib/java_tools/javac.rb', line 13 def source_files @source_files end |
#source_path ⇒ Object
array
13 14 15 |
# File 'lib/java_tools/javac.rb', line 13 def source_path @source_path end |
#verbose ⇒ Object
array
13 14 15 |
# File 'lib/java_tools/javac.rb', line 13 def verbose @verbose end |
#warnings ⇒ Object
array
13 14 15 |
# File 'lib/java_tools/javac.rb', line 13 def warnings @warnings end |
Instance Method Details
#command_args ⇒ Object
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_string ⇒ Object
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 |