24 */ |
24 */ |
25 |
25 |
26 package com.sun.tools.sjavac.client; |
26 package com.sun.tools.sjavac.client; |
27 |
27 |
28 import java.io.BufferedReader; |
28 import java.io.BufferedReader; |
29 import java.io.File; |
|
30 import java.io.IOException; |
29 import java.io.IOException; |
31 import java.io.InputStreamReader; |
30 import java.io.InputStreamReader; |
32 import java.io.OutputStreamWriter; |
31 import java.io.OutputStreamWriter; |
33 import java.io.PrintStream; |
|
34 import java.io.PrintWriter; |
32 import java.io.PrintWriter; |
35 import java.io.Reader; |
33 import java.io.Reader; |
36 import java.io.Writer; |
|
37 import java.net.InetAddress; |
34 import java.net.InetAddress; |
38 import java.net.InetSocketAddress; |
35 import java.net.InetSocketAddress; |
39 import java.net.Socket; |
36 import java.net.Socket; |
40 import java.util.ArrayList; |
37 import java.util.ArrayList; |
41 import java.util.Arrays; |
38 import java.util.Arrays; |
42 import java.util.List; |
39 import java.util.List; |
43 import java.util.Scanner; |
40 |
44 import java.util.stream.Stream; |
41 import com.sun.tools.javac.main.Main; |
45 |
42 import com.sun.tools.javac.main.Main.Result; |
46 import com.sun.tools.sjavac.Log; |
43 import com.sun.tools.sjavac.Log; |
47 import com.sun.tools.sjavac.Util; |
44 import com.sun.tools.sjavac.Util; |
48 import com.sun.tools.sjavac.options.OptionHelper; |
45 import com.sun.tools.sjavac.options.OptionHelper; |
49 import com.sun.tools.sjavac.options.Options; |
46 import com.sun.tools.sjavac.options.Options; |
50 import com.sun.tools.sjavac.server.CompilationSubResult; |
47 import com.sun.tools.sjavac.server.CompilationSubResult; |
114 public String serverSettings() { |
111 public String serverSettings() { |
115 return settings; |
112 return settings; |
116 } |
113 } |
117 |
114 |
118 @Override |
115 @Override |
119 public int compile(String[] args) { |
116 public Result compile(String[] args) { |
120 int result = -1; |
117 Result result = null; |
121 try (Socket socket = tryConnect()) { |
118 try (Socket socket = tryConnect()) { |
122 PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream())); |
119 PrintWriter out = new PrintWriter(new OutputStreamWriter(socket.getOutputStream())); |
123 BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); |
120 BufferedReader in = new BufferedReader(new InputStreamReader(socket.getInputStream())); |
124 |
121 |
125 // Send args array to server |
122 // Send args array to server |
148 } catch (IllegalArgumentException e) { |
145 } catch (IllegalArgumentException e) { |
149 // Parsing of 'type' as log level failed. |
146 // Parsing of 'type' as log level failed. |
150 } |
147 } |
151 |
148 |
152 if (type.equals(SjavacServer.LINE_TYPE_RC)) { |
149 if (type.equals(SjavacServer.LINE_TYPE_RC)) { |
153 result = Integer.parseInt(content); |
150 result = Main.Result.valueOf(content); |
154 } |
151 } |
155 } |
152 } |
156 } catch (PortFileInaccessibleException e) { |
153 } catch (PortFileInaccessibleException e) { |
157 Log.error("Port file inaccessible."); |
154 Log.error("Port file inaccessible."); |
158 result = CompilationSubResult.ERROR_FATAL; |
155 result = Result.ERROR; |
159 } catch (IOException ioe) { |
156 } catch (IOException ioe) { |
160 Log.error("IOException caught during compilation: " + ioe.getMessage()); |
157 Log.error("IOException caught during compilation: " + ioe.getMessage()); |
161 Log.debug(ioe); |
158 Log.debug(ioe); |
162 result = CompilationSubResult.ERROR_FATAL; |
159 result = Result.ERROR; |
163 } catch (InterruptedException ie) { |
160 } catch (InterruptedException ie) { |
164 Thread.currentThread().interrupt(); // Restore interrupt |
161 Thread.currentThread().interrupt(); // Restore interrupt |
165 Log.error("Compilation interrupted."); |
162 Log.error("Compilation interrupted."); |
166 Log.debug(ie); |
163 Log.debug(ie); |
167 result = CompilationSubResult.ERROR_FATAL; |
164 result = Result.ERROR; |
168 } |
165 } |
|
166 |
|
167 if (result == null) { |
|
168 // No LINE_TYPE_RC was found. |
|
169 result = Result.ERROR; |
|
170 } |
|
171 |
169 return result; |
172 return result; |
170 } |
173 } |
171 |
174 |
172 /* |
175 /* |
173 * Makes MAX_CONNECT_ATTEMPTS attepmts to connect to server. |
176 * Makes MAX_CONNECT_ATTEMPTS attepmts to connect to server. |