Skip to content

Commit b035056

Browse files
committedDec 2, 2022
8297455: Use the official ToolProvider API to call javac
Reviewed-by: erikj
1 parent 257aa15 commit b035056

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed
 

‎make/langtools/tools/javacserver/server/Server.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
package javacserver.server;
2727

28-
import com.sun.tools.javac.Main;
2928
import java.io.BufferedReader;
3029
import java.io.FileNotFoundException;
3130
import java.io.IOException;
@@ -39,8 +38,10 @@
3938
import java.net.Socket;
4039
import java.net.SocketException;
4140
import java.nio.file.Path;
41+
import java.util.Optional;
4242
import java.util.Random;
4343
import java.util.concurrent.atomic.AtomicBoolean;
44+
import java.util.spi.ToolProvider;
4445
import javacserver.shared.PortFile;
4546
import javacserver.shared.Protocol;
4647
import javacserver.shared.Result;
@@ -225,7 +226,6 @@ private void handleRequest(Socket socket) {
225226
}
226227
}
227228

228-
@SuppressWarnings("deprecated")
229229
public static int runCompiler(Log log, String[] args) {
230230
Log.setLogForCurrentThread(log);
231231

@@ -234,7 +234,12 @@ public static int runCompiler(Log log, String[] args) {
234234
PrintWriter printWriter = new PrintWriter(strWriter);
235235

236236
// Compile
237-
int exitcode = Main.compile(args, printWriter);
237+
Optional<ToolProvider> tool = ToolProvider.findFirst("javac");
238+
if (tool.isEmpty()) {
239+
Log.error("Can't find tool javac");
240+
return Result.ERROR.exitCode;
241+
}
242+
int exitcode = tool.get().run(printWriter, printWriter, args);
238243

239244
// Process compiler output (which is always errors)
240245
printWriter.flush();

0 commit comments

Comments
 (0)
Please sign in to comment.