build process: temporary workaround for IDEA-169747

Add JavacTool to classpath and create its instance explicitly if it wasn't found automatically.
This commit is contained in:
nik
2017-03-22 10:08:41 +03:00
parent 3c350945b8
commit ac88f4a36e
3 changed files with 33 additions and 15 deletions
@@ -1035,7 +1035,7 @@ public class BuildManager implements Disposable {
}
private OSProcessHandler launchBuildProcess(Project project, final int port, final UUID sessionId, boolean requestProjectPreload) throws ExecutionException {
final String compilerPath;
String compilerPath;
final String vmExecutablePath;
JavaSdkVersion sdkVersion = null;
@@ -1055,9 +1055,21 @@ public class BuildManager implements Disposable {
// this is the most universal way to obtain tools.jar path in this particular case
final JavaCompiler systemCompiler = ToolProvider.getSystemJavaCompiler();
if (systemCompiler == null) {
throw new ExecutionException("No system java compiler is provided by the JRE. Make sure tools.jar is present in IntelliJ IDEA classpath.");
//temporary workaround for IDEA-169747
try {
compilerPath = ClasspathBootstrap.getResourcePath(Class.forName("com.sun.tools.javac.api.JavacTool", false, BuildManager.class.getClassLoader()));
}
catch (Throwable t) {
LOG.info(t);
compilerPath = null;
}
if (compilerPath == null) {
throw new ExecutionException("No system java compiler is provided by the JRE. Make sure tools.jar is present in IntelliJ IDEA classpath.");
}
}
else {
compilerPath = ClasspathBootstrap.getResourcePath(systemCompiler.getClass());
}
compilerPath = ClasspathBootstrap.getResourcePath(systemCompiler.getClass());
}
else {
compilerPath = projectJdkType.getToolsPath(projectJdk);
@@ -63,14 +63,15 @@ public class JavacCompilerTool extends JavaCompilingTool {
return compiler;
}
String message = "System Java Compiler was not found in classpath";
String message;
// trying to obtain additional diagnostic for the case when compiler.jar is present, but there were problems with compiler class loading:
try {
Class.forName("com.sun.tools.javac.api.JavacTool", false, JavacMain.class.getClassLoader());
//temporary workaround for IDEA-169747: try to create the instance by hand if it was found
return (JavaCompiler)Class.forName("com.sun.tools.javac.api.JavacTool", true, JavacMain.class.getClassLoader()).newInstance();
}
catch (Throwable ex) {
StringWriter stringWriter = new StringWriter();
stringWriter.write(message);
stringWriter.write("System Java Compiler was not found in classpath");
stringWriter.write(":\n");
ex.printStackTrace(new PrintWriter(stringWriter));
message = stringWriter.getBuffer().toString();
@@ -138,17 +138,22 @@ public class ClasspathBootstrap {
else {
// last resort
final JavaCompiler systemCompiler = ToolProvider.getSystemJavaCompiler();
Class compilerClass;
if (systemCompiler != null) {
final String localJarPath = FileUtil.toSystemIndependentName(getResourceFile(systemCompiler.getClass()).getPath());
String relPath = FileUtil.getRelativePath(localJavaHome, localJarPath, '/');
compilerClass = systemCompiler.getClass();
}
else {
compilerClass = Class.forName("com.sun.tools.javac.api.JavacTool", false, ClasspathBootstrap.class.getClassLoader());
}
String localJarPath = FileUtil.toSystemIndependentName(getResourceFile(compilerClass).getPath());
String relPath = FileUtil.getRelativePath(localJavaHome, localJarPath, '/');
if (relPath != null) {
if (relPath.contains("..")) {
relPath = FileUtil.getRelativePath(FileUtil.toSystemIndependentName(new File(localJavaHome).getParent()), localJarPath, '/');
}
if (relPath != null) {
if (relPath.contains("..")) {
relPath = FileUtil.getRelativePath(FileUtil.toSystemIndependentName(new File(localJavaHome).getParent()), localJarPath, '/');
}
if (relPath != null) {
final File targetFile = new File(sdkHome, relPath);
cp.add(targetFile); // tools.jar
}
final File targetFile = new File(sdkHome, relPath);
cp.add(targetFile); // tools.jar
}
}
}