From 552a56a6bbc4746df1f168b380548628edf11208 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Sat, 6 Jul 2013 13:26:05 +0400 Subject: [PATCH] revert to resolving against compiled classes (need for IDEA-110165 Sources produced by annotation processor are not implicitly compiled) --- .../markDirty/recompileTwinDependencies.log | 6 --- .../jps/incremental/java/JavaBuilder.java | 44 +++---------------- .../org/jetbrains/jps/javac/JavacMain.java | 14 ++---- .../org/jetbrains/ether/MarkDirtyTest.java | 2 +- 4 files changed, 10 insertions(+), 56 deletions(-) diff --git a/java/java-tests/testData/compileServer/incremental/markDirty/recompileTwinDependencies.log b/java/java-tests/testData/compileServer/incremental/markDirty/recompileTwinDependencies.log index 1c40adc4f7fb..4badc88cf13a 100644 --- a/java/java-tests/testData/compileServer/incremental/markDirty/recompileTwinDependencies.log +++ b/java/java-tests/testData/compileServer/incremental/markDirty/recompileTwinDependencies.log @@ -8,9 +8,3 @@ Compiling files: src/package2/A.java src/package2/C.java End of files -Cleaning output files: -out/production/RecompileTwinDependencies/com/B.class -End of files -Compiling files: -src/com/B.java -End of files diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java index 3ed05da75c0b..776c3a800834 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/java/JavaBuilder.java @@ -58,7 +58,6 @@ import org.jetbrains.jps.model.library.sdk.JpsSdk; import org.jetbrains.jps.model.module.JpsModule; import org.jetbrains.jps.model.module.JpsModuleType; import org.jetbrains.jps.service.JpsServiceManager; -import org.jetbrains.jps.util.JpsPathUtil; import javax.tools.*; import java.io.*; @@ -247,29 +246,19 @@ public class JavaBuilder extends ModuleLevelBuilder { exitCode = ExitCode.OK; final Set srcPath = new HashSet(); - Set tempRoots = null; - final BuildRootIndex index = pd.getBuildRootIndex(); for (ModuleBuildTarget target : chunk.getTargets()) { - for (JavaSourceRootDescriptor rd : index.getTargetRoots(target, context)) { + for (JavaSourceRootDescriptor rd : index.getTempTargetRoots(target, context)) { srcPath.add(rd.root); - if (rd.isTemp) { - if (tempRoots == null) { - tempRoots = new THashSet(FileUtil.FILE_HASHING_STRATEGY); - } - tempRoots.add(rd.root); - } } } - final DiagnosticSink diagnosticSink = new DiagnosticSink(context, tempRoots == null? Collections.emptySet() : tempRoots); + final DiagnosticSink diagnosticSink = new DiagnosticSink(context); final String chunkName = chunk.getName(); context.processMessage(new ProgressMessage("Parsing java... [" + chunkName + "]")); final int filesCount = files.size(); boolean compiledOk = true; - int tempRootsErrorCount = 0; - int tempRootsWarningCount = 0; if (filesCount > 0) { LOG.info("Compiling " + filesCount + " java files; module: " + chunkName + (chunk.containsTests() ? " (tests)" : "")); if (LOG.isDebugEnabled()) { @@ -287,16 +276,6 @@ public class JavaBuilder extends ModuleLevelBuilder { } try { compiledOk = compileJava(context, chunk, files, classpath, platformCp, srcPath, diagnosticSink, outputSink); - if (compiledOk) { - final Collection loadedTempFiles = diagnosticSink.getLoadedTempSources(); - if (!loadedTempFiles.isEmpty()) { - // compile all implicitly loaded sources from temporary roots - final DiagnosticSink tempRootsSink = new DiagnosticSink(context, Collections.emptySet()); - compiledOk = compileJava(context, chunk, loadedTempFiles, classpath, platformCp, tempRoots, tempRootsSink, outputSink); - tempRootsErrorCount = tempRootsSink.getErrorCount(); - tempRootsWarningCount = tempRootsSink.getWarningCount(); - } - } } finally { // heuristic: incorrect paths data recovery, so that the next make should not contain non-existing sources in 'recompile' list @@ -310,16 +289,15 @@ public class JavaBuilder extends ModuleLevelBuilder { context.checkCanceled(); - if (!compiledOk && (diagnosticSink.getErrorCount() + tempRootsErrorCount) == 0) { + if (!compiledOk && diagnosticSink.getErrorCount() == 0) { diagnosticSink.report(new PlainMessageDiagnostic(Diagnostic.Kind.ERROR, "Compilation failed: internal java compiler error")); } - final int totalErrorCount = diagnosticSink.getErrorCount() + tempRootsErrorCount; - if (!Utils.PROCEED_ON_ERROR_KEY.get(context, Boolean.FALSE) && totalErrorCount > 0) { + if (!Utils.PROCEED_ON_ERROR_KEY.get(context, Boolean.FALSE) && diagnosticSink.getErrorCount() > 0) { if (!compiledOk) { diagnosticSink.report(new PlainMessageDiagnostic(Diagnostic.Kind.OTHER, "Errors occurred while compiling module '" + chunkName + "'")); } throw new StopBuildException( - "Compilation failed: errors: " + totalErrorCount + "; warnings: " + (diagnosticSink.getWarningCount() + tempRootsWarningCount) + "Compilation failed: errors: " + diagnosticSink.getErrorCount() + "; warnings: " + diagnosticSink.getWarningCount() ); } } @@ -804,26 +782,16 @@ public class JavaBuilder extends ModuleLevelBuilder { private static class DiagnosticSink implements DiagnosticOutputConsumer { private final CompileContext myContext; - private final Set myTempRoots; private volatile int myErrorCount = 0; private volatile int myWarningCount = 0; - private final Set myLoadedTempSources = new THashSet(FileUtil.FILE_HASHING_STRATEGY); private final Set myFilesWithErrors = new HashSet(); - public DiagnosticSink(CompileContext context, Set tempRoots) { + public DiagnosticSink(CompileContext context) { myContext = context; - myTempRoots = tempRoots; } @Override public void javaFileLoaded(File file) { - if (JpsPathUtil.isUnder(myTempRoots, file)) { - myLoadedTempSources.add(file); - } - } - - public Collection getLoadedTempSources() { - return myLoadedTempSources; } public void registerImports(final String className, final Collection imports, final Collection staticImports) { diff --git a/jps/jps-builders/src/org/jetbrains/jps/javac/JavacMain.java b/jps/jps-builders/src/org/jetbrains/jps/javac/JavacMain.java index 5e6c820ff79a..fdf99efcd70f 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/javac/JavacMain.java +++ b/jps/jps-builders/src/org/jetbrains/jps/javac/JavacMain.java @@ -16,6 +16,7 @@ package org.jetbrains.jps.javac; import com.intellij.openapi.util.SystemInfo; +import com.intellij.util.SmartList; import org.jetbrains.annotations.NotNull; import org.jetbrains.jps.api.CanceledStatus; import org.jetbrains.jps.builders.java.JavaSourceTransformer; @@ -83,14 +84,6 @@ public class JavacMain { } final List transformers = getSourceTransformers(); - transformers.add(new JavaSourceTransformer() { - // dummy transformer to notify about sources that were accessed during compilation - @Override - public CharSequence transform(File sourceFile, CharSequence content) throws TransformError { - diagnosticConsumer.javaFileLoaded(sourceFile); - return content; - } - }); final JavacFileManager fileManager = new JavacFileManager(new ContextImpl(compiler, diagnosticConsumer, outputSink, canceledStatus, nowUsingJavac), transformers); @@ -191,7 +184,7 @@ public class JavacMain { private static List getSourceTransformers() { final Class transformerClass = JavaSourceTransformer.class; final ServiceLoader loader = ServiceLoader.load(transformerClass, transformerClass.getClassLoader()); - final List transformers = new ArrayList(); + final List transformers = new SmartList(); for (JavaSourceTransformer t : loader) { transformers.add(t); } @@ -219,8 +212,7 @@ public class JavacMain { private static Collection prepareOptions(final Collection options, boolean usingJavac) { final List result = new ArrayList(); if (usingJavac) { - result.add("-Xprefer:source"); - result.add("-implicit:none"); // the option supported by javac only + result.add("-implicit:class"); // the option supported by javac only } else { // is Eclipse result.add("-noExit"); diff --git a/jps/jps-builders/testSrc/org/jetbrains/ether/MarkDirtyTest.java b/jps/jps-builders/testSrc/org/jetbrains/ether/MarkDirtyTest.java index 6e605db97203..4fe9694cf447 100644 --- a/jps/jps-builders/testSrc/org/jetbrains/ether/MarkDirtyTest.java +++ b/jps/jps-builders/testSrc/org/jetbrains/ether/MarkDirtyTest.java @@ -54,6 +54,6 @@ public class MarkDirtyTest extends IncrementalTestCase { } public void testRecompileTwinDependencies() { - doTest().assertSuccessful(); + doTest().assertFailed(); } }