Skip to content

Commit

Permalink
8297455: Use the official ToolProvider API to call javac
Browse files Browse the repository at this point in the history
Reviewed-by: erikj
  • Loading branch information
magicus committed Dec 2, 2022
1 parent 257aa15 commit b035056
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions make/langtools/tools/javacserver/server/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,6 @@

package javacserver.server;

import com.sun.tools.javac.Main;
import java.io.BufferedReader;
import java.io.FileNotFoundException;
import java.io.IOException;
Expand All @@ -39,8 +38,10 @@
import java.net.Socket;
import java.net.SocketException;
import java.nio.file.Path;
import java.util.Optional;
import java.util.Random;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.spi.ToolProvider;
import javacserver.shared.PortFile;
import javacserver.shared.Protocol;
import javacserver.shared.Result;
Expand Down Expand Up @@ -225,7 +226,6 @@ private void handleRequest(Socket socket) {
}
}

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

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

// Compile
int exitcode = Main.compile(args, printWriter);
Optional<ToolProvider> tool = ToolProvider.findFirst("javac");
if (tool.isEmpty()) {
Log.error("Can't find tool javac");
return Result.ERROR.exitCode;
}
int exitcode = tool.get().run(printWriter, printWriter, args);

// Process compiler output (which is always errors)
printWriter.flush();
Expand Down

1 comment on commit b035056

@openjdk-notifier
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.