mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
external build: supporting eclipse compiler for "javac server" mode
This commit is contained in:
@@ -131,7 +131,7 @@ public class ClasspathBootstrap {
|
||||
return ContainerUtil.newArrayList(cp);
|
||||
}
|
||||
|
||||
public static List<File> getJavacServerClasspath(String sdkHome) {
|
||||
public static List<File> getJavacServerClasspath(String sdkHome, boolean useEclipseCompiler) {
|
||||
final Set<File> cp = new LinkedHashSet<File>();
|
||||
cp.add(getResourceFile(JavacServer.class)); // self
|
||||
// util
|
||||
@@ -190,6 +190,17 @@ public class ClasspathBootstrap {
|
||||
}
|
||||
}
|
||||
|
||||
if (useEclipseCompiler) {
|
||||
// eclipse compiler
|
||||
for (JavaCompiler javaCompiler : ServiceLoader.load(JavaCompiler.class)) { // Eclipse compiler
|
||||
final File compilerResource = getResourceFile(javaCompiler.getClass());
|
||||
final String name = compilerResource.getName();
|
||||
if (name.startsWith("ecj-") && name.endsWith(".jar")) {
|
||||
cp.add(compilerResource);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
final Class<JavaSourceTransformer> transformerClass = JavaSourceTransformer.class;
|
||||
final ServiceLoader<JavaSourceTransformer> loader = ServiceLoader.load(transformerClass, transformerClass.getClassLoader());
|
||||
for (JavaSourceTransformer t : loader) {
|
||||
|
||||
@@ -378,9 +378,6 @@ public class JavaBuilder extends ModuleLevelBuilder {
|
||||
}
|
||||
|
||||
private static boolean useEclipseCompiler(CompileContext context) {
|
||||
if (!USE_EMBEDDED_JAVAC) {
|
||||
return false;
|
||||
}
|
||||
JpsProject project = context.getProjectDescriptor().getProject();
|
||||
final JpsJavaCompilerConfiguration configuration = JpsJavaExtensionService.getInstance().getCompilerConfiguration(project);
|
||||
final String compilerId = configuration != null? configuration.getJavaCompilerId() : null;
|
||||
@@ -418,7 +415,7 @@ public class JavaBuilder extends ModuleLevelBuilder {
|
||||
final String javaHome = SystemProperties.getJavaHome();
|
||||
|
||||
final BaseOSProcessHandler processHandler = JavacServerBootstrap.launchJavacServer(
|
||||
javaHome, heapSize, port, Utils.getSystemRoot(), getCompilationVMOptions(context)
|
||||
javaHome, heapSize, port, Utils.getSystemRoot(), getCompilationVMOptions(context), useEclipseCompiler(context)
|
||||
);
|
||||
final JavacServerClient client = new JavacServerClient();
|
||||
try {
|
||||
|
||||
@@ -42,6 +42,7 @@ public class JavacServer {
|
||||
public static final int DEFAULT_SERVER_PORT = 7878;
|
||||
public static final String SERVER_SUCCESS_START_MESSAGE = "Javac server started successfully. Listening on port: ";
|
||||
public static final String SERVER_ERROR_START_MESSAGE = "Error starting Javac Server: ";
|
||||
public static final String USE_ECLIPSE_COMPILER_PROPERTY = "use.eclipse.compiler";
|
||||
|
||||
private final ChannelGroup myAllOpenChannels = new DefaultChannelGroup("javac-server");
|
||||
private final ChannelFactory myChannelFactory;
|
||||
@@ -149,7 +150,7 @@ public class JavacServer {
|
||||
};
|
||||
|
||||
try {
|
||||
final boolean rc = JavacMain.compile(options, files, classpath, platformCp, sourcePath, outs, diagnostic, outputSink, canceledStatus, false);
|
||||
final boolean rc = JavacMain.compile(options, files, classpath, platformCp, sourcePath, outs, diagnostic, outputSink, canceledStatus, System.getProperty(USE_ECLIPSE_COMPILER_PROPERTY) != null);
|
||||
return JavacProtoUtil.toMessage(sessionId, JavacProtoUtil.createBuildCompletedResponse(rc));
|
||||
}
|
||||
catch (Throwable e) {
|
||||
|
||||
@@ -39,7 +39,12 @@ import java.util.concurrent.Future;
|
||||
*/
|
||||
public class JavacServerBootstrap {
|
||||
|
||||
public static BaseOSProcessHandler launchJavacServer(String sdkHomePath, int heapSize, int port, File workingDir, List<String> vmOptions) throws Exception {
|
||||
public static BaseOSProcessHandler launchJavacServer(String sdkHomePath,
|
||||
int heapSize,
|
||||
int port,
|
||||
File workingDir,
|
||||
List<String> vmOptions,
|
||||
boolean useEclipseCompiler) throws Exception {
|
||||
final List<String> cmdLine = new ArrayList<String>();
|
||||
appendParam(cmdLine, getVMExecutablePath(sdkHomePath));
|
||||
appendParam(cmdLine, "-XX:MaxPermSize=150m");
|
||||
@@ -77,13 +82,17 @@ public class JavacServerBootstrap {
|
||||
appendParam(cmdLine, "-Duser.region=" + region);
|
||||
}
|
||||
|
||||
if (useEclipseCompiler) {
|
||||
appendParam(cmdLine, "-D" + JavacServer.USE_ECLIPSE_COMPILER_PROPERTY);
|
||||
}
|
||||
|
||||
for (String option : vmOptions) {
|
||||
appendParam(cmdLine, option);
|
||||
}
|
||||
|
||||
appendParam(cmdLine, "-classpath");
|
||||
|
||||
final List<File> cp = ClasspathBootstrap.getJavacServerClasspath(sdkHomePath);
|
||||
final List<File> cp = ClasspathBootstrap.getJavacServerClasspath(sdkHomePath, useEclipseCompiler);
|
||||
final StringBuilder classpath = new StringBuilder();
|
||||
for (File file : cp) {
|
||||
if (classpath.length() > 0) {
|
||||
|
||||
Reference in New Issue
Block a user