From ac88f4a36e47066a6d18f8ee45fc48fa23374264 Mon Sep 17 00:00:00 2001 From: nik Date: Wed, 22 Mar 2017 10:08:04 +0300 Subject: [PATCH] build process: temporary workaround for IDEA-169747 Add JavacTool to classpath and create its instance explicitly if it wasn't found automatically. --- .../compiler/server/BuildManager.java | 18 ++++++++++++--- .../builders/impl/java/JavacCompilerTool.java | 7 +++--- .../jps/cmdline/ClasspathBootstrap.java | 23 +++++++++++-------- 3 files changed, 33 insertions(+), 15 deletions(-) diff --git a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java index 2ccfc4450c8a..b1b0c24ac8c5 100644 --- a/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java +++ b/java/compiler/impl/src/com/intellij/compiler/server/BuildManager.java @@ -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); diff --git a/jps/jps-builders-6/src/org/jetbrains/jps/builders/impl/java/JavacCompilerTool.java b/jps/jps-builders-6/src/org/jetbrains/jps/builders/impl/java/JavacCompilerTool.java index 6299a34247b2..730eba9f9405 100644 --- a/jps/jps-builders-6/src/org/jetbrains/jps/builders/impl/java/JavacCompilerTool.java +++ b/jps/jps-builders-6/src/org/jetbrains/jps/builders/impl/java/JavacCompilerTool.java @@ -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(); diff --git a/jps/jps-builders/src/org/jetbrains/jps/cmdline/ClasspathBootstrap.java b/jps/jps-builders/src/org/jetbrains/jps/cmdline/ClasspathBootstrap.java index 8e752f0431f8..220f76421a41 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/cmdline/ClasspathBootstrap.java +++ b/jps/jps-builders/src/org/jetbrains/jps/cmdline/ClasspathBootstrap.java @@ -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 } } }