Description:
fix java to show error when compile error
Commit status:
[Not Reviewed]
References:
Comments:
0 Commit comments 0 Inline Comments
Unresolved TODOs:
There are no unresolved TODOs
Add another comment

r151:dc2e8f82e9df - - 1 file changed: 5 inserted, 3 deleted

@@ -89,52 +89,54
89
89
90 when "c"
90 when "c"
91 command = "#{C_COMPILER} #{params[:source_file]} -o #{params[:output_file]} #{C_OPTIONS} 2> #{params[:message_file]}"
91 command = "#{C_COMPILER} #{params[:source_file]} -o #{params[:output_file]} #{C_OPTIONS} 2> #{params[:message_file]}"
92 system(command)
92 system(command)
93
93
94 when "c++"
94 when "c++"
95 command = "#{CPLUSPLUS_COMPILER} #{params[:source_file]} -o #{params[:output_file]} #{CPLUSPLUS_OPTIONS} 2> #{params[:message_file]}"
95 command = "#{CPLUSPLUS_COMPILER} #{params[:source_file]} -o #{params[:output_file]} #{CPLUSPLUS_OPTIONS} 2> #{params[:message_file]}"
96 system(command)
96 system(command)
97
97
98 when "pas"
98 when "pas"
99 command = "#{PASCAL_COMPILER} #{params[:source_file]} -ooutpas #{PASCAL_OPTIONS} > #{params[:message_file]}"
99 command = "#{PASCAL_COMPILER} #{params[:source_file]} -ooutpas #{PASCAL_OPTIONS} > #{params[:message_file]}"
100 system(command)
100 system(command)
101 FileUtils.mv("output", params[:output_file])
101 FileUtils.mv("output", params[:output_file])
102
102
103 when "java"
103 when "java"
104 #rename the file to the public class name
104 #rename the file to the public class name
105
105
106 #get the class name
106 #get the class name
107 classname = 'DUMMY'
107 classname = 'DUMMY'
108 File.foreach(params[:source_file]) do |line|
108 File.foreach(params[:source_file]) do |line|
109 md = /\s*public\s*class\s*(\w*)/.match(line)
109 md = /\s*public\s*class\s*(\w*)/.match(line)
110 classname=md[1] if md
110 classname=md[1] if md
111 end
111 end
112 system("cp #{params[:source_file]} #{classname}.java")
112 system("cp #{params[:source_file]} #{classname}.java")
113 - command = "#{JAVA_COMPILER} #{classname}.java > #{params[:message_file]}"
113 + command = "#{JAVA_COMPILER} #{classname}.java 2> #{params[:message_file]}"
114 system(command)
114 system(command)
115 - File.open(params[:output_file],"w") {|file| file.write("#!/bin/sh\n/usr/bin/java #{classname}\n")}
115 + if File.exists?(classname + ".class") begin
116 - File.chmod(0755, params[:output_file])
116 + File.open(params[:output_file],"w") {|file| file.write("#!/bin/sh\n/usr/bin/java #{classname}\n")}
117 + File.chmod(0755, params[:output_file])
118 + end
117
119
118 when "ruby"
120 when "ruby"
119 command = "#{RUBY_INTEPRETER} -c #{params[:source_file]} > #{params[:message_file]}"
121 command = "#{RUBY_INTEPRETER} -c #{params[:source_file]} > #{params[:message_file]}"
120 system(command)
122 system(command)
121 File.open(params[:output_file],"w") do |out_file|
123 File.open(params[:output_file],"w") do |out_file|
122 out_file.puts "#!#{RUBY_INTEPRETER}"
124 out_file.puts "#!#{RUBY_INTEPRETER}"
123 File.open(params[:source_file],"r").each do |line|
125 File.open(params[:source_file],"r").each do |line|
124 out_file.print line
126 out_file.print line
125 end
127 end
126 end
128 end
127 File.chmod(0755, params[:output_file])
129 File.chmod(0755, params[:output_file])
128
130
129 else
131 else
130 talk("ERROR: Invalid language specified!")
132 talk("ERROR: Invalid language specified!")
131 open(params[:message_file],"w") do |f|
133 open(params[:message_file],"w") do |f|
132 f.puts "ERROR: Invalid language specified!"
134 f.puts "ERROR: Invalid language specified!"
133 end
135 end
134 exit(127)
136 exit(127)
135 end
137 end
136
138
137 # Report success or failure.
139 # Report success or failure.
138 if FileTest.exists? params[:output_file]
140 if FileTest.exists? params[:output_file]
139 talk "Compilation was successful!"
141 talk "Compilation was successful!"
140 else
142 else
You need to be logged in to leave comments. Login now