cleanup javac cache hack to work only in "emdebbed javac" mode
authorEugene Zhuravlev <jeka@intellij.com>
Fri, 27 Jan 2012 17:07:40 +0000 (18:07 +0100)
committerEugene Zhuravlev <jeka@intellij.com>
Fri, 27 Jan 2012 17:09:05 +0000 (18:09 +0100)
jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java
jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java

index ccfa9e42dc4bb611031d2873c5d13eaee82003d1..de2a9db7a4082e434291f4fc14e6dd3282025b32 100644 (file)
@@ -1,11 +1,13 @@
 package org.jetbrains.jps.incremental;
 
+import com.intellij.openapi.diagnostic.Logger;
 import com.intellij.openapi.util.io.FileUtil;
 import com.intellij.util.io.PersistentEnumerator;
 import org.jetbrains.jps.*;
 import org.jetbrains.jps.api.CanceledStatus;
 import org.jetbrains.jps.api.RequestFuture;
 import org.jetbrains.jps.incremental.java.ExternalJavacDescriptor;
+import org.jetbrains.jps.incremental.java.JavaBuilder;
 import org.jetbrains.jps.incremental.messages.BuildMessage;
 import org.jetbrains.jps.incremental.messages.CompilerMessage;
 import org.jetbrains.jps.incremental.messages.ProgressMessage;
@@ -26,6 +28,7 @@ import java.util.concurrent.ExecutionException;
  *         Date: 9/17/11
  */
 public class IncProjectBuilder {
+  private static final Logger LOG = Logger.getInstance("#org.jetbrains.jps.incremental.IncProjectBuilder");
   public static final String JPS_SERVER_NAME = "JPS BUILD";
   private static final String CANCELED_MESSAGE = "The build has been canceled";
 
@@ -121,14 +124,18 @@ public class IncProjectBuilder {
     cleanupJavacNameTable();
   }
 
+  private static boolean ourClenupFailed = false;
   private static void cleanupJavacNameTable() {
     try {
-      final Field freelistField = Class.forName("com.sun.tools.javac.util.Name$Table").getDeclaredField("freelist");
-      freelistField.setAccessible(true);
-      freelistField.set(null, com.sun.tools.javac.util.List.nil());
+      if (JavaBuilder.USE_EMBEDDED_JAVAC && !ourClenupFailed) {
+        final Field freelistField = Class.forName("com.sun.tools.javac.util.Name$Table").getDeclaredField("freelist");
+        freelistField.setAccessible(true);
+        freelistField.set(null, com.sun.tools.javac.util.List.nil());
+      }
     }
     catch (Throwable e) {
-      e.printStackTrace();
+      ourClenupFailed = true;
+      LOG.info(e);
     }
   }
 
index 2269278c3908141d999e835d9f8d7fd6e6116e52..13544a88a8683dc86b729e22124727356864f6eb 100644 (file)
@@ -34,8 +34,7 @@ import org.objectweb.asm.ClassWriter;
 import org.objectweb.asm.Opcodes;
 import org.objectweb.asm.commons.EmptyVisitor;
 
-import javax.tools.Diagnostic;
-import javax.tools.JavaFileObject;
+import javax.tools.*;
 import java.io.*;
 import java.net.MalformedURLException;
 import java.net.ServerSocket;
@@ -53,7 +52,7 @@ public class JavaBuilder extends ModuleLevelBuilder {
   public static final String BUILDER_NAME = "java";
   private static final String JAVA_EXTENSION = ".java";
   private static final String FORM_EXTENSION = ".form";
-  private static final boolean USE_EMBEDDED_JAVAC = System.getProperty(GlobalOptions.USE_EXTERNAL_JAVAC_OPTION) == null;
+  public static final boolean USE_EMBEDDED_JAVAC = System.getProperty(GlobalOptions.USE_EXTERNAL_JAVAC_OPTION) == null;
 
   private static final FileFilter JAVA_SOURCES_FILTER = new FileFilter() {
     public boolean accept(File file) {