diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java index ace9d8dac9c7..38a99a7acbd2 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java @@ -25,6 +25,7 @@ import com.intellij.CommonBundle; import com.intellij.analysis.AnalysisScope; import com.intellij.compiler.*; import com.intellij.compiler.make.CacheCorruptedException; +import com.intellij.compiler.make.CacheUtils; import com.intellij.compiler.make.DependencyCache; import com.intellij.compiler.progress.CompilerTask; import com.intellij.diagnostic.IdeErrorsDialog; @@ -47,6 +48,7 @@ import com.intellij.openapi.module.Module; import com.intellij.openapi.module.ModuleManager; import com.intellij.openapi.progress.ProcessCanceledException; import com.intellij.openapi.progress.ProgressIndicator; +import com.intellij.openapi.progress.ProgressManager; import com.intellij.openapi.project.DumbService; import com.intellij.openapi.project.Project; import com.intellij.openapi.project.ProjectBundle; @@ -840,67 +842,121 @@ public class CompileDriver { final TranslatingCompiler[] translators = compilerManager.getCompilers(TranslatingCompiler.class, myCompilerFilter); - final Set generatedTypes = new HashSet(); - VirtualFile[] snapshot = null; + final List> sortedChunks = Collections.unmodifiableList(ApplicationManager.getApplication().runReadAction(new Computable>>() { + public List> compute() { + final ModuleManager moduleManager = ModuleManager.getInstance(myProject); + return ModuleCompilerUtil.getSortedModuleChunks(myProject, Arrays.asList(moduleManager.getModules())); + } + })); - final TranslatorsOutputSink sink = new TranslatorsOutputSink(context, translators); try { - for (int currentCompiler = 0, translatorsLength = translators.length; currentCompiler < translatorsLength; currentCompiler++) { - sink.setCurrentCompilerIndex(currentCompiler); - final TranslatingCompiler translator = translators[currentCompiler]; - if (context.getProgressIndicator().isCanceled()) { - throw new ExitException(ExitStatus.CANCELLED); - } - - DumbService.getInstance(myProject).waitForSmartMode(); - - if (snapshot == null || ContainerUtil.intersects(generatedTypes, compilerManager.getRegisteredInputTypes(translator))) { - // rescan snapshot if previously generated files can influence the input of this compiler - snapshot = ApplicationManager.getApplication().runReadAction(new Computable() { - public VirtualFile[] compute() { - return context.getCompileScope().getFiles(null, true); - } - }); - } - - final CompileContextEx _context; - if (translator instanceof IntermediateOutputCompiler) { - // wrap compile context so that output goes into intermediate directories - final IntermediateOutputCompiler _translator = (IntermediateOutputCompiler)translator; - _context = new CompileContextExProxy(context) { - public VirtualFile getModuleOutputDirectory(final Module module) { - return getGenerationOutputDir(_translator, module, false); + VirtualFile[] snapshot = null; + final Map, Collection> chunkMap = new HashMap, Collection>(); + int total = 0; + int processed = 0; + for (final Chunk currentChunk : sortedChunks) { + final TranslatorsOutputSink sink = new TranslatorsOutputSink(context, translators); + final Set generatedTypes = new HashSet(); + Collection chunkFiles = chunkMap.get(currentChunk); + try { + for (int currentCompiler = 0, translatorsLength = translators.length; currentCompiler < translatorsLength; currentCompiler++) { + sink.setCurrentCompilerIndex(currentCompiler); + final TranslatingCompiler compiler = translators[currentCompiler]; + if (context.getProgressIndicator().isCanceled()) { + throw new ExitException(ExitStatus.CANCELLED); } - public VirtualFile getModuleOutputDirectoryForTests(final Module module) { - return getGenerationOutputDir(_translator, module, true); + DumbService.getInstance(myProject).waitForSmartMode(); + + if (snapshot == null || ContainerUtil.intersects(generatedTypes, compilerManager.getRegisteredInputTypes(compiler))) { + // rescan snapshot if previously generated files may influence the input of this compiler + snapshot = ApplicationManager.getApplication().runReadAction(new Computable() { + public VirtualFile[] compute() { + return context.getCompileScope().getFiles(null, true); + } + }); + final Map> moduleToFilesMap = CompilerUtil.buildModuleToFilesMap(context, snapshot); + for (Chunk moduleChunk : sortedChunks) { + List files = Collections.emptyList(); + for (Module module : moduleChunk.getNodes()) { + final List moduleFiles = moduleToFilesMap.get(module); + if (moduleFiles != null) { + files = ContainerUtil.concat(files, moduleFiles); + } + } + chunkMap.put(moduleChunk, files); + } + total = snapshot.length * translatorsLength; + chunkFiles = chunkMap.get(currentChunk); } - }; - } - else { - _context = context; - } - final boolean compiledSomething = - compileSources(_context, translators, currentCompiler, snapshot, forceCompile, isRebuild, trackDependencies, onlyCheckStatus, sink); - if (compiledSomething) { - generatedTypes.addAll(compilerManager.getRegisteredOutputTypes(translator)); - } + final CompileContextEx _context; + if (compiler instanceof IntermediateOutputCompiler) { + // wrap compile context so that output goes into intermediate directories + final IntermediateOutputCompiler _compiler = (IntermediateOutputCompiler)compiler; + _context = new CompileContextExProxy(context) { + public VirtualFile getModuleOutputDirectory(final Module module) { + return getGenerationOutputDir(_compiler, module, false); + } - if (_context.getMessageCount(CompilerMessageCategory.ERROR) > 0) { - throw new ExitException(ExitStatus.ERRORS); - } + public VirtualFile getModuleOutputDirectoryForTests(final Module module) { + return getGenerationOutputDir(_compiler, module, true); + } + }; + } + else { + _context = context; + } + final boolean compiledSomething = + compileSources(_context, currentChunk, compiler, chunkFiles, forceCompile, isRebuild, trackDependencies, onlyCheckStatus, sink); - didSomething |= compiledSomething; + processed += chunkFiles.size(); + _context.getProgressIndicator().setFraction(((double)processed) / total); + + if (compiledSomething) { + generatedTypes.addAll(compilerManager.getRegisteredOutputTypes(compiler)); + } + + if (_context.getMessageCount(CompilerMessageCategory.ERROR) > 0) { + throw new ExitException(ExitStatus.ERRORS); + } + + didSomething |= compiledSomething; + } + } + finally { + if (context.getMessageCount(CompilerMessageCategory.ERROR) == 0) { + // perform update only if there were no errors, so it is guaranteed that the file was processd by all neccesary compilers + sink.flushPostponedItems(); + } + } } } + catch (ProcessCanceledException e) { + ProgressManager.getInstance().executeNonCancelableSection(new Runnable() { + public void run() { + try { + final Collection deps = CacheUtils.findDependentFiles(context, Collections.emptySet(), null, null); + if (deps.size() > 0) { + TranslatingCompilerFilesMonitor.getInstance().update(context, null, Collections.emptyList(), deps.toArray(new VirtualFile[deps.size()])); + } + } + catch (IOException ignored) { + LOG.info(ignored); + } + catch (CacheCorruptedException ignored) { + LOG.info(ignored); + } + } + }); + throw e; + } finally { - if (context.getMessageCount(CompilerMessageCategory.ERROR) == 0) { - // perform update only if there were no errors, so it is guaranteed that the file was processd by all neccesary compilers - sink.flushPostponedItems(); - } dropDependencyCache(context); + if (didSomething) { + TranslatingCompilerFilesMonitor.getInstance().updateOutputRootsLayout(myProject); + } } return didSomething; } @@ -1353,15 +1409,13 @@ public class CompileDriver { }; } - private boolean compileSources(final CompileContextEx context, TranslatingCompiler[] compilers, int currentCompiler, final VirtualFile[] sources, + private boolean compileSources(final CompileContextEx context, final Chunk moduleChunk, final TranslatingCompiler compiler, final Collection srcSnapshot, final boolean forceCompile, final boolean isRebuild, final boolean trackDependencies, final boolean onlyCheckStatus, TranslatingCompiler.OutputSink sink) throws ExitException { - final TranslatingCompiler compiler = compilers[currentCompiler]; - final Set toCompile = new HashSet(); final List> toDelete = new ArrayList>(); context.getProgressIndicator().pushState(); @@ -1372,13 +1426,13 @@ public class CompileDriver { public void run() { TranslatingCompilerFilesMonitor.getInstance().collectFiles( - context, compiler, Arrays.asList(sources).iterator(), forceCompile, isRebuild, toCompile, toDelete + context, compiler, srcSnapshot.iterator(), forceCompile, isRebuild, toCompile, toDelete ); if (trackDependencies && !toCompile.isEmpty()) { // should add dependent files + // todo: drop this? final FileTypeManager fileTypeManager = FileTypeManager.getInstance(); final PsiManager psiManager = PsiManager.getInstance(myProject); - final VirtualFile[] filesToCompile = toCompile.toArray(new VirtualFile[toCompile.size()]); - for (final VirtualFile file : filesToCompile) { + for (final VirtualFile file : toCompile.toArray(new VirtualFile[toCompile.size()])) { if (fileTypeManager.getFileTypeByFile(file) == StdFileTypes.JAVA) { final PsiFile psiFile = psiManager.findFile(file); if (psiFile != null) { @@ -1414,9 +1468,9 @@ public class CompileDriver { context.requestRebuildNextTime(e.getMessage()); } } - + if ((wereFilesDeleted[0] || !toCompile.isEmpty()) && context.getMessageCount(CompilerMessageCategory.ERROR) == 0) { - compiler.compile(context, toCompile.toArray(new VirtualFile[toCompile.size()]), sink); + compiler.compile(context, moduleChunk, toCompile.toArray(new VirtualFile[toCompile.size()]), sink); } } finally { @@ -1729,7 +1783,6 @@ public class CompileDriver { return true; } - // todo: add validation for module chunks: all modules that form a chunk must have the same JDK private boolean validateCompilerConfiguration(final CompileScope scope, boolean checkOutputAndSourceIntersection) { final Module[] scopeModules = scope.getAffectedModules()/*ModuleManager.getInstance(myProject).getModules()*/; final List modulesWithoutOutputPathSpecified = new ArrayList(); @@ -2188,9 +2241,6 @@ public class CompileDriver { LOG.info(e); myContext.requestRebuildNextTime(e.getMessage()); } - finally { - filesMonitor.updateOutputRootsLayout(myContext.getProject()); - } } } } diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/AnnotationProcessingCompiler.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/AnnotationProcessingCompiler.java index 70407ba1eb40..c8fa49fc14cb 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/AnnotationProcessingCompiler.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/AnnotationProcessingCompiler.java @@ -34,6 +34,7 @@ import com.intellij.openapi.fileTypes.StdFileTypes; import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.Chunk; import org.jetbrains.annotations.NotNull; import java.io.DataInput; @@ -90,7 +91,8 @@ public class AnnotationProcessingCompiler implements SourceProcessingCompiler{ private void compile(final CompileContext context, final VirtualFile[] files) { final JavacCompiler javacCompiler = getBackEndCompiler(); final boolean processorMode = javacCompiler.setAnnotationProcessorMode(true); - final BackendCompilerWrapper wrapper = new BackendCompilerWrapper(myProject, Arrays.asList(files), (CompileContextEx)context, javacCompiler, DummySink.INSTANCE); + final Chunk dummyChunk = new Chunk(Collections.emptySet()); // TODO! + final BackendCompilerWrapper wrapper = new BackendCompilerWrapper(dummyChunk, myProject, Arrays.asList(files), (CompileContextEx)context, javacCompiler, DummySink.INSTANCE); try { wrapper.compile(); } diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java index b9586b133bec..137b51e7d445 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/BackendCompilerWrapper.java @@ -51,12 +51,13 @@ import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.Chunk; +import com.intellij.util.Function; import com.intellij.util.cls.ClsFormatException; -import com.intellij.util.containers.ContainerUtil; import gnu.trove.THashMap; import gnu.trove.TIntHashSet; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; import org.objectweb.asm.ClassReader; import org.objectweb.asm.ClassWriter; @@ -78,6 +79,7 @@ public class BackendCompilerWrapper { private final CompileContextEx myCompileContext; private final List myFilesToCompile; private final TranslatingCompiler.OutputSink mySink; + private final Chunk myChunk; private final Project myProject; private final Set myFilesToRecompile; private final Map myModuleToTempDirMap = new THashMap(); @@ -88,10 +90,11 @@ public class BackendCompilerWrapper { public final Map> myFileNameToSourceMap= new THashMap>(); - public BackendCompilerWrapper(@NotNull final Project project, + public BackendCompilerWrapper(Chunk chunk, @NotNull final Project project, @NotNull List filesToCompile, @NotNull CompileContextEx compileContext, @NotNull BackendCompiler compiler, TranslatingCompiler.OutputSink sink) { + myChunk = chunk; myProject = project; myCompiler = compiler; myCompileContext = compileContext; @@ -102,7 +105,7 @@ public class BackendCompilerWrapper { mySuccesfullyCompiledJavaFiles = new HashSet(filesToCompile.size()); } - public List compile() throws CompilerException, CacheCorruptedException { + public void compile() throws CompilerException, CacheCorruptedException { Application application = ApplicationManager.getApplication(); final Set allDependent = new HashSet(); COMPILE: @@ -112,13 +115,12 @@ public class BackendCompilerWrapper { saveTestData(); } - final Map> moduleToFilesMap = CompilerUtil.buildModuleToFilesMap(myCompileContext, myFilesToCompile); - compileModules(moduleToFilesMap); + compileModules(buildModuleToFilesMap(myFilesToCompile)); } Collection dependentFiles; do { - dependentFiles = findDependentFiles(); + dependentFiles = CacheUtils.findDependentFiles(myCompileContext, mySuccesfullyCompiledJavaFiles, myCompiler.getDependencyProcessor(), DEPENDENCY_FILTER); if (!dependentFiles.isEmpty()) { myFilesToRecompile.addAll(dependentFiles); @@ -130,9 +132,8 @@ public class BackendCompilerWrapper { if (filesInScope.isEmpty()) { break; } - final Map> moduleToFilesMap = CompilerUtil.buildModuleToFilesMap(myCompileContext, filesInScope); myCompileContext.getDependencyCache().clearTraverseRoots(); - compileModules(moduleToFilesMap); + compileModules(buildModuleToFilesMap(filesInScope)); } } while (!dependentFiles.isEmpty() && myCompileContext.getMessageCount(CompilerMessageCategory.ERROR) == 0); @@ -154,26 +155,24 @@ public class BackendCompilerWrapper { myModuleToTempDirMap.clear(); } - if (myCompileContext.getProgressIndicator().isCanceled()) { - myFilesToRecompile.clear(); - // when cancelled pretend nothing was compiled and next compile will compile everything from the scratch - return Collections.emptyList(); - } - // do not update caches if cancelled because there is a chance that they will be incomplete if (CompilerConfiguration.MAKE_ENABLED) { - ProgressIndicator indicator = myCompileContext.getProgressIndicator(); - final DependencyCache cache = myCompileContext.getDependencyCache(); + if (!myCompileContext.getProgressIndicator().isCanceled()) { + // when cancelled pretend nothing was compiled and next compile will compile everything from the scratch + final ProgressIndicator indicator = myCompileContext.getProgressIndicator(); + final DependencyCache cache = myCompileContext.getDependencyCache(); - indicator.setText(CompilerBundle.message("progress.updating.caches")); - indicator.setText2(""); + indicator.pushState(); + indicator.setText(CompilerBundle.message("progress.updating.caches")); + indicator.setText2(""); - cache.update(indicator); + cache.update(); - indicator.setText(CompilerBundle.message("progress.saving.caches")); - cache.resetState(); + indicator.setText(CompilerBundle.message("progress.saving.caches")); + cache.resetState(); - indicator.setText(""); + indicator.popState(); + } } myFilesToRecompile.removeAll(mySuccesfullyCompiledJavaFiles); @@ -184,13 +183,19 @@ public class BackendCompilerWrapper { if (myFilesToRecompile.size() > 0 || outputs.size() > 0) { mySink.add(null, outputs, myFilesToRecompile.toArray(new VirtualFile[myFilesToRecompile.size()])); } - return null; + } + + private Map> buildModuleToFilesMap(final List filesToCompile) { + if (myChunk.getNodes().size() == 1) { + return Collections.singletonMap(myChunk.getNodes().iterator().next(), Collections.unmodifiableList(filesToCompile)); + } + return CompilerUtil.buildModuleToFilesMap(myCompileContext, filesToCompile); } // package-info.java hack private List processPackageInfoFiles() { if (myFilesToRecompile.isEmpty()) { - return Collections.EMPTY_LIST; + return Collections.emptyList(); } final List outputs = new ArrayList(); ApplicationManager.getApplication().runReadAction(new Runnable() { @@ -215,13 +220,16 @@ public class BackendCompilerWrapper { return outputs; } - private List getFilesInScope(final Collection dependentFiles) { - final List filesInScope = new ArrayList(dependentFiles.size()); + private List getFilesInScope(final Collection files) { + final List filesInScope = new ArrayList(files.size()); ApplicationManager.getApplication().runReadAction(new Runnable() { public void run() { - for (VirtualFile dependentFile : dependentFiles) { - if (myCompileContext.getCompileScope().belongs(dependentFile.getUrl())) { - filesInScope.add(dependentFile); + for (VirtualFile file : files) { + if (myCompileContext.getCompileScope().belongs(file.getUrl())) { + final Module module = myCompileContext.getModuleByFile(file); + if (myChunk.getNodes().contains(module)) { + filesInScope.add(file); + } } } } @@ -230,25 +238,21 @@ public class BackendCompilerWrapper { } private void compileModules(final Map> moduleToFilesMap) throws CompilerException { - final List chunks = getModuleChunks(moduleToFilesMap); - List files = ContainerUtil.concat(moduleToFilesMap.values()); myProcessedFilesCount = 0; - myTotalFilesToCompile = files.size(); + //myTotalFilesToCompile = 0; + //for (List list : moduleToFilesMap.values()) { + // myTotalFilesToCompile += list.size(); + //} - for (final ModuleChunk chunk : chunks) { - try { - boolean success = compileChunk(chunk); - if (!success) { - return; - } - } - catch (IOException e) { - throw new CompilerException(e.getMessage(), e); - } + try { + compileChunk(new ModuleChunk(myCompileContext, myChunk, moduleToFilesMap)); + } + catch (IOException e) { + throw new CompilerException(e.getMessage(), e); } } - private boolean compileChunk(ModuleChunk chunk) throws IOException { + private void compileChunk(ModuleChunk chunk) throws IOException { runTransformingCompilers(chunk); setPresentableNameFor(chunk); @@ -259,9 +263,6 @@ public class BackendCompilerWrapper { try { for (final OutputDir outputDir : outs) { doCompile(chunk, outputDir.getPath(), outputDir.getKind()); - if (myCompileContext.getMessageCount(CompilerMessageCategory.ERROR) > 0) { - return false; - } } } finally { @@ -269,8 +270,6 @@ public class BackendCompilerWrapper { FileUtil.asyncDelete(fileToDelete); } } - - return true; } @@ -295,6 +294,7 @@ public class BackendCompilerWrapper { }); } + @Nullable private File getOutputDirsToCompileTo(ModuleChunk chunk, final List pairs) throws IOException { File fileToDelete = null; if (chunk.getModuleCount() == 1) { // optimization @@ -333,19 +333,6 @@ public class BackendCompilerWrapper { return fileToDelete; } - private List getModuleChunks(final Map> moduleToFilesMap) { - final List modules = new ArrayList(moduleToFilesMap.keySet()); - final List> chunks = ApplicationManager.getApplication().runReadAction(new Computable>>() { - public List> compute() { - return ModuleCompilerUtil.getSortedModuleChunks(myProject, modules); - } - }); - final List moduleChunks = new ArrayList(chunks.size()); - for (final Chunk chunk : chunks) { - moduleChunks.add(new ModuleChunk(myCompileContext, chunk, moduleToFilesMap)); - } - return moduleChunks; - } private boolean shouldCompileTestsSeparately(Module module) { final String moduleTestOutputDirectory = getTestsOutputDir(module); @@ -368,77 +355,18 @@ public class BackendCompilerWrapper { private final TIntHashSet myProcessedNames = new TIntHashSet(); private final Set myProcessedFiles = new HashSet(); + private final Function>, Pair>> DEPENDENCY_FILTER = new Function>, Pair>>() { + public Pair> fun(Pair> deps) { + final TIntHashSet currentDeps = new TIntHashSet(deps.getFirst()); + currentDeps.removeAll(myProcessedNames.toArray()); + myProcessedNames.addAll(deps.getFirst()); - private Collection findDependentFiles() throws CacheCorruptedException { - if (!CompilerConfiguration.MAKE_ENABLED) { - return Collections.emptyList(); + final Set depFiles = new HashSet(deps.getSecond()); + depFiles.removeAll(myProcessedFiles); + myProcessedFiles.addAll(deps.getSecond()); + return new Pair>(currentDeps.toArray(), depFiles); } - myCompileContext.getProgressIndicator().setText(CompilerBundle.message("progress.checking.dependencies")); - - final DependencyCache dependencyCache = myCompileContext.getDependencyCache(); - - final long start = System.currentTimeMillis(); - - final Pair> deps = - dependencyCache.findDependentClasses(myCompileContext, myProject, mySuccesfullyCompiledJavaFiles, myCompiler.getDependencyProcessor()); - - final TIntHashSet currentDeps = new TIntHashSet(deps.getFirst()); - currentDeps.removeAll(myProcessedNames.toArray()); - final int[] depQNames = currentDeps.toArray(); - myProcessedNames.addAll(deps.getFirst()); - - final Set depFiles = new HashSet(deps.getSecond()); - depFiles.removeAll(myProcessedFiles); - myProcessedFiles.addAll(deps.getSecond()); - - final Set dependentFiles = new HashSet(); - final CacheCorruptedException[] _ex = {null}; - ApplicationManager.getApplication().runReadAction(new Runnable() { - public void run() { - try { - CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(myProject); - SourceFileFinder sourceFileFinder = new SourceFileFinder(myProject, myCompileContext); - final Cache cache = dependencyCache.getCache(); - for (final int infoQName : depQNames) { - final String qualifiedName = dependencyCache.resolve(infoQName); - final String sourceFileName = cache.getSourceFileName(infoQName); - final VirtualFile file = sourceFileFinder.findSourceFile(qualifiedName, sourceFileName); - if (file != null) { - if (!compilerConfiguration.isExcludedFromCompilation(file)) { - dependentFiles.add(file); - if (ApplicationManager.getApplication().isUnitTestMode()) { - LOG.assertTrue(file.isValid()); - CompilerManagerImpl.addRecompiledPath(file.getPath()); - } - } - } - else { - LOG.info("No source file for " + dependencyCache.resolve(infoQName) + " found; source file name=" + sourceFileName); - } - } - for (final VirtualFile file : depFiles) { - if (!compilerConfiguration.isExcludedFromCompilation(file)) { - dependentFiles.add(file); - if (ApplicationManager.getApplication().isUnitTestMode()) { - LOG.assertTrue(file.isValid()); - CompilerManagerImpl.addRecompiledPath(file.getPath()); - } - } - } - } - catch (CacheCorruptedException e) { - _ex[0] = e; - } - } - }); - if (_ex[0] != null) { - throw _ex[0]; - } - myCompileContext.getProgressIndicator().setText(CompilerBundle.message("progress.found.dependent.files", dependentFiles.size())); - - CompilerUtil.logDuration("Finding dependencies", System.currentTimeMillis() - start); - return dependentFiles; - } + }; private final Object lock = new Object(); @@ -736,11 +664,11 @@ public class BackendCompilerWrapper { return compiledWithErrors; } - private void buildOutputItemsList(final String outputDir, Module module, VirtualFile from, - final FileTypeManager typeManager, - final Set compiledWithErrors, - final VirtualFile sourceRoot, - final String packagePrefix, final List filesToRefresh, final Map> results) throws CacheCorruptedException { + private void buildOutputItemsList(final String outputDir, Module module, VirtualFile from, + final FileTypeManager typeManager, + final Set compiledWithErrors, + final VirtualFile sourceRoot, + final String packagePrefix, final List filesToRefresh, final Map> results) throws CacheCorruptedException { final Ref exRef = new Ref(null); final ModuleFileIndex fileIndex = ModuleRootManager.getInstance(module).getFileIndex(); final ContentIterator contentIterator = new ContentIterator() { @@ -777,8 +705,9 @@ public class BackendCompilerWrapper { } }.iterateContent(from); } - if (exRef.get() != null) { - throw exRef.get(); + final CacheCorruptedException exc = exRef.get(); + if (exc != null) { + throw exc; } } @@ -843,6 +772,7 @@ public class BackendCompilerWrapper { } } + @Nullable private Pair moveToRealLocation(String tempOutputDir, String pathToClass, VirtualFile sourceFile, final List filesToRefresh) { final Module module = myCompileContext.getModuleByFile(sourceFile); if (module == null) { @@ -873,11 +803,9 @@ public class BackendCompilerWrapper { boolean success = fromFile.renameTo(toFile); if (!success) { // assuming cause of the fail: intermediate dirs do not exist - final File parentFile = toFile.getParentFile(); - if (parentFile != null) { - parentFile.mkdirs(); - success = fromFile.renameTo(toFile); // retry after making non-existent dirs - } + FileUtil.createParentDirs(toFile); + // retry after making non-existent dirs + success = fromFile.renameTo(toFile); } if (!success) { // failed to move the file: e.g. because source and destination reside on different mountpoints. try { @@ -921,9 +849,8 @@ public class BackendCompilerWrapper { return out; } - private int myProcessedFilesCount = 0; - private int myTotalFilesToCompile = 0; - private int myClassesCount = 0; + private volatile int myProcessedFilesCount = 0; + private volatile int myClassesCount = 0; private volatile String myModuleName = null; private void sourceFileProcessed() { @@ -941,7 +868,7 @@ public class BackendCompilerWrapper { msg = CompilerBundle.message("statistics.files.classes", myProcessedFilesCount, myClassesCount); } myCompileContext.getProgressIndicator().setText2(msg); - myCompileContext.getProgressIndicator().setFraction(1.0* myProcessedFilesCount /myTotalFilesToCompile); + //myCompileContext.getProgressIndicator().setFraction(1.0* myProcessedFilesCount /myTotalFilesToCompile); } private class ClassParsingThread implements Runnable { diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/DummyTranslatingCompiler.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/DummyTranslatingCompiler.java index 2d0dae2da064..573b7e02323d 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/DummyTranslatingCompiler.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/DummyTranslatingCompiler.java @@ -21,6 +21,7 @@ import com.intellij.openapi.compiler.*; import com.intellij.openapi.module.Module; import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.Chunk; import org.jetbrains.annotations.NonNls; import org.jetbrains.annotations.NotNull; @@ -40,7 +41,7 @@ public class DummyTranslatingCompiler implements TranslatingCompiler, Intermedia return file.getName().endsWith(FILETYPE_EXTENSION); } - public void compile(final CompileContext context, final VirtualFile[] files, OutputSink sink) { + public void compile(final CompileContext context, Chunk moduleChunk, final VirtualFile[] files, OutputSink sink) { final List filesToRefresh = new ArrayList(); final Map> outputs = new HashMap>(); ApplicationManager.getApplication().runReadAction(new Runnable() { diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/JavaCompiler.java b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/JavaCompiler.java index 3f910231e624..60043afb6524 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/JavaCompiler.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/javaCompiler/JavaCompiler.java @@ -30,8 +30,10 @@ import com.intellij.openapi.compiler.ex.CompileContextEx; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.fileTypes.FileTypeManager; import com.intellij.openapi.fileTypes.StdFileTypes; +import com.intellij.openapi.module.Module; import com.intellij.openapi.project.Project; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.Chunk; import org.jetbrains.annotations.NotNull; import java.util.Arrays; @@ -54,10 +56,9 @@ public class JavaCompiler implements TranslatingCompiler { return FILE_TYPE_MANAGER.getFileTypeByFile(file).equals(StdFileTypes.JAVA); } - public void compile(CompileContext context, VirtualFile[] files, OutputSink sink) { + public void compile(CompileContext context, Chunk moduleChunk, VirtualFile[] files, OutputSink sink) { final BackendCompiler backEndCompiler = getBackEndCompiler(); - final BackendCompilerWrapper wrapper = new BackendCompilerWrapper(myProject, Arrays.asList(files), (CompileContextEx)context, backEndCompiler, - sink); + final BackendCompilerWrapper wrapper = new BackendCompilerWrapper(moduleChunk, myProject, Arrays.asList(files), (CompileContextEx)context, backEndCompiler, sink); try { wrapper.compile(); } diff --git a/java/compiler/impl/src/com/intellij/compiler/impl/resourceCompiler/ResourceCompiler.java b/java/compiler/impl/src/com/intellij/compiler/impl/resourceCompiler/ResourceCompiler.java index f2bac34c2ebb..468618c3b296 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/resourceCompiler/ResourceCompiler.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/resourceCompiler/ResourceCompiler.java @@ -39,6 +39,7 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.openapi.vfs.VirtualFileManager; +import com.intellij.util.Chunk; import org.jetbrains.annotations.NotNull; import java.io.File; @@ -70,12 +71,13 @@ public class ResourceCompiler implements TranslatingCompiler { return !StdFileTypes.JAVA.equals(FILE_TYPE_MANAGER.getFileTypeByFile(file)) && myConfiguration.isResourceFile(file); } - public void compile(final CompileContext context, final VirtualFile[] files, OutputSink sink) { + public void compile(final CompileContext context, Chunk moduleChunk, final VirtualFile[] files, OutputSink sink) { context.getProgressIndicator().pushState(); context.getProgressIndicator().setText(CompilerBundle.message("progress.copying.resources")); final Map> processed = new HashMap>(); final LinkedList copyCommands = new LinkedList(); + final Module singleChunkModule = moduleChunk.getNodes().size() == 1? moduleChunk.getNodes().iterator().next() : null; final long start = System.currentTimeMillis(); ApplicationManager.getApplication().runReadAction(new Runnable() { public void run() { @@ -84,7 +86,7 @@ public class ResourceCompiler implements TranslatingCompiler { if (context.getProgressIndicator().isCanceled()) { break; } - final Module module = context.getModuleByFile(file); + final Module module = singleChunkModule != null? singleChunkModule : context.getModuleByFile(file); if (module == null) { continue; // looks like file invalidated } @@ -94,17 +96,20 @@ public class ResourceCompiler implements TranslatingCompiler { } final String sourcePath = file.getPath(); final String relativePath = VfsUtil.getRelativePath(file, fileRoot, '/'); - final String outputPath = CompilerPaths.getModuleOutputPath(module, ((CompileContextEx)context).isInTestSourceContent(file)); - if (outputPath == null) { + final boolean inTests = ((CompileContextEx)context).isInTestSourceContent(file); + final VirtualFile outputDir = inTests? context.getModuleOutputDirectoryForTests(module) : context.getModuleOutputDirectory(module); + if (outputDir == null) { continue; } + final String outputPath = outputDir.getPath(); + final String packagePrefix = fileIndex.getPackageNameByDirectory(fileRoot); final String targetPath; if (packagePrefix != null && packagePrefix.length() > 0) { - targetPath = outputPath+"/"+packagePrefix.replace('.', '/')+"/"+relativePath; + targetPath = outputPath + "/" + packagePrefix.replace('.', '/') + "/" + relativePath; } else { - targetPath = outputPath+"/"+relativePath; + targetPath = outputPath + "/" + relativePath; } if (sourcePath.equals(targetPath)) { addToMap(processed, outputPath, new MyOutputItem(targetPath, file)); @@ -126,7 +131,7 @@ public class ResourceCompiler implements TranslatingCompiler { if (context.getProgressIndicator().isCanceled()) { break; } - context.getProgressIndicator().setFraction((idx++) * 1.0 / total); + //context.getProgressIndicator().setFraction((idx++) * 1.0 / total); context.getProgressIndicator().setText2("Copying " + command.getFromPath() + "..."); try { rootsToRefresh.add(command.getOutputPath()); diff --git a/java/compiler/impl/src/com/intellij/compiler/make/CacheUtils.java b/java/compiler/impl/src/com/intellij/compiler/make/CacheUtils.java index 7405710468a8..f0faf4e19683 100644 --- a/java/compiler/impl/src/com/intellij/compiler/make/CacheUtils.java +++ b/java/compiler/impl/src/com/intellij/compiler/make/CacheUtils.java @@ -15,16 +15,26 @@ */ package com.intellij.compiler.make; +import com.intellij.compiler.CompilerConfiguration; +import com.intellij.compiler.CompilerManagerImpl; import com.intellij.compiler.SymbolTable; import com.intellij.compiler.classParsing.MethodInfo; +import com.intellij.compiler.impl.CompilerUtil; +import com.intellij.compiler.impl.javaCompiler.DependencyProcessor; +import com.intellij.openapi.application.ApplicationManager; +import com.intellij.openapi.compiler.CompilerBundle; +import com.intellij.openapi.compiler.ex.CompileContextEx; import com.intellij.openapi.diagnostic.Logger; +import com.intellij.openapi.util.Pair; import com.intellij.openapi.util.text.StringUtil; +import com.intellij.openapi.vfs.VirtualFile; import com.intellij.util.ArrayUtil; +import com.intellij.util.Function; import com.intellij.util.StringBuilderSpinAllocator; import gnu.trove.TIntHashSet; import org.jetbrains.annotations.Nullable; -import java.util.ArrayList; +import java.util.*; /** * @author Eugene Zhuravlev @@ -116,4 +126,69 @@ public class CacheUtils { } return true; } + + public static Collection findDependentFiles(final CompileContextEx context, final Set succesfullyCompiledJavaFiles, + final @Nullable DependencyProcessor additionalDependencyProcessor, + final @Nullable Function>, Pair>> filter) throws CacheCorruptedException { + if (!CompilerConfiguration.MAKE_ENABLED) { + return Collections.emptyList(); + } + context.getProgressIndicator().setText(CompilerBundle.message("progress.checking.dependencies")); + + final DependencyCache dependencyCache = context.getDependencyCache(); + + final long start = System.currentTimeMillis(); + + final Pair> deps = + dependencyCache.findDependentClasses(context, context.getProject(), succesfullyCompiledJavaFiles, additionalDependencyProcessor); + final Pair> filteredDeps = filter != null? filter.fun(deps) : deps; + + final Set dependentFiles = new HashSet(); + final CacheCorruptedException[] _ex = {null}; + ApplicationManager.getApplication().runReadAction(new Runnable() { + public void run() { + try { + CompilerConfiguration compilerConfiguration = CompilerConfiguration.getInstance(context.getProject()); + SourceFileFinder sourceFileFinder = new SourceFileFinder(context.getProject(), context); + final Cache cache = dependencyCache.getCache(); + for (final int infoQName : filteredDeps.getFirst()) { + final String qualifiedName = dependencyCache.resolve(infoQName); + final String sourceFileName = cache.getSourceFileName(infoQName); + final VirtualFile file = sourceFileFinder.findSourceFile(qualifiedName, sourceFileName); + if (file != null) { + if (!compilerConfiguration.isExcludedFromCompilation(file)) { + dependentFiles.add(file); + if (ApplicationManager.getApplication().isUnitTestMode()) { + LOG.assertTrue(file.isValid()); + CompilerManagerImpl.addRecompiledPath(file.getPath()); + } + } + } + else { + LOG.info("No source file for " + dependencyCache.resolve(infoQName) + " found; source file name=" + sourceFileName); + } + } + for (final VirtualFile file : filteredDeps.getSecond()) { + if (!compilerConfiguration.isExcludedFromCompilation(file)) { + dependentFiles.add(file); + if (ApplicationManager.getApplication().isUnitTestMode()) { + LOG.assertTrue(file.isValid()); + CompilerManagerImpl.addRecompiledPath(file.getPath()); + } + } + } + } + catch (CacheCorruptedException e) { + _ex[0] = e; + } + } + }); + if (_ex[0] != null) { + throw _ex[0]; + } + context.getProgressIndicator().setText(CompilerBundle.message("progress.found.dependent.files", dependentFiles.size())); + + CompilerUtil.logDuration("Finding dependencies", System.currentTimeMillis() - start); + return dependentFiles; + } } diff --git a/java/compiler/impl/src/com/intellij/compiler/make/DependencyCache.java b/java/compiler/impl/src/com/intellij/compiler/make/DependencyCache.java index b1d2ce8a0131..7e9270ba30eb 100644 --- a/java/compiler/impl/src/com/intellij/compiler/make/DependencyCache.java +++ b/java/compiler/impl/src/com/intellij/compiler/make/DependencyCache.java @@ -28,7 +28,6 @@ import com.intellij.openapi.application.ApplicationManager; import com.intellij.openapi.compiler.CompileContext; import com.intellij.openapi.diagnostic.Logger; import com.intellij.openapi.progress.ProcessCanceledException; -import com.intellij.openapi.progress.ProgressIndicator; import com.intellij.openapi.project.Project; import com.intellij.openapi.util.Computable; import com.intellij.openapi.util.Pair; @@ -150,7 +149,7 @@ public class DependencyCache { } */ - public void update(ProgressIndicator indicator) throws CacheCorruptedException { + public void update() throws CacheCorruptedException { if (myToUpdate.isEmpty()) { return; // optimization } @@ -163,10 +162,8 @@ public class DependencyCache { final Cache newCache = getNewClassesCache(); final DependencyCacheNavigator navigator = getCacheNavigator(); - int i = 0; // remove unnecesary dependencies for (final int qName : namesToUpdate) { - indicator.setFraction(i++*1.0/namesToUpdate.length/4); // process use-dependencies for (int referencedClassQName : cache.getReferencedClasses(qName)) { if (!cache.containsClass(referencedClassQName)) { @@ -186,7 +183,6 @@ public class DependencyCache { // do update of classInfos for (final int qName : namesToUpdate) { - indicator.setFraction(i++*1.0/namesToUpdate.length/4); cache.importClassInfo(newCache, qName); } @@ -195,7 +191,6 @@ public class DependencyCache { final SymbolTable symbolTable = getSymbolTable(); for (final int qName : namesToUpdate) { - indicator.setFraction(i++*1.0/namesToUpdate.length/4); if (!newCache.containsClass(qName)) { continue; } @@ -223,9 +218,7 @@ public class DependencyCache { // building subclass dependencies for (final int qName : namesToUpdate) { - indicator.setFraction(i++*1.0/namesToUpdate.length/4); - final int classId = qName; - buildSubclassDependencies(getCache(), qName, classId); + buildSubclassDependencies(getCache(), qName, qName); } for (final int qName : myClassesWithSourceRemoved.toArray()) { @@ -410,11 +403,11 @@ public class DependencyCache { LOG.debug("====================Marking dependent files====================="); } // myToUpdate can be modified during the mark procedure, so use toArray() to iterate it - int[] qNamesToUpdate = myTraverseRoots.toArray(); + final int[] traverseRoots = myTraverseRoots.toArray(); final SourceFileFinder sourceFileFinder = new SourceFileFinder(project, context); final CachingSearcher searcher = new CachingSearcher(project); final ChangedRetentionPolicyDependencyProcessor changedRetentionPolicyDependencyProcessor = new ChangedRetentionPolicyDependencyProcessor(project, searcher, this); - for (final int qName : qNamesToUpdate) { + for (final int qName : traverseRoots) { if (!getCache().containsClass(qName)) { continue; } diff --git a/java/compiler/impl/src/com/intellij/compiler/make/StorageClassId.java b/java/compiler/impl/src/com/intellij/compiler/make/StorageClassId.java deleted file mode 100644 index e71d24021160..000000000000 --- a/java/compiler/impl/src/com/intellij/compiler/make/StorageClassId.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.compiler.make; - -/** - * @author Eugene Zhuravlev - * Date: Dec 1, 2008 - */ -public class StorageClassId { - private final int myQName; - - public StorageClassId(int QName) { - myQName = QName; - } - - public int getClassQName() { - return myQName; - } - - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof StorageClassId)) return false; - - if (myQName != ((StorageClassId)o).myQName) return false; - - return true; - } - - public int hashCode() { - return myQName; - } - -} diff --git a/java/compiler/impl/src/com/intellij/compiler/make/StorageFieldId.java b/java/compiler/impl/src/com/intellij/compiler/make/StorageFieldId.java deleted file mode 100644 index a15d04613be2..000000000000 --- a/java/compiler/impl/src/com/intellij/compiler/make/StorageFieldId.java +++ /dev/null @@ -1,47 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.compiler.make; - -/** - * @author Eugene Zhuravlev - * Date: Dec 1, 2008 - */ -public final class StorageFieldId extends StorageClassId{ - private final int myFieldName; - - public StorageFieldId(int QName, int fieldName) { - super(QName); - myFieldName = fieldName; - } - - public int getFieldName() { - return myFieldName; - } - - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof StorageFieldId)) return false; - - final StorageFieldId that = (StorageFieldId)o; - return myFieldName == that.myFieldName && getClassQName() == that.getClassQName(); - } - - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + myFieldName; - return result; - } -} diff --git a/java/compiler/impl/src/com/intellij/compiler/make/StorageMethodId.java b/java/compiler/impl/src/com/intellij/compiler/make/StorageMethodId.java deleted file mode 100644 index fb5efff27045..000000000000 --- a/java/compiler/impl/src/com/intellij/compiler/make/StorageMethodId.java +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright 2000-2009 JetBrains s.r.o. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package com.intellij.compiler.make; - -/** - * @author Eugene Zhuravlev - * Date: Dec 1, 2008 - */ -public final class StorageMethodId extends StorageClassId{ - private final int myMethodName; - private final int myMethodDescriptor; - - public StorageMethodId(int QName, int methodName, int methodDescriptor) { - super(QName); - myMethodName = methodName; - myMethodDescriptor = methodDescriptor; - } - - public int getMethodName() { - return myMethodName; - } - - public int getMethodDescriptor() { - return myMethodDescriptor; - } - - public boolean equals(Object o) { - if (this == o) return true; - if (!(o instanceof StorageMethodId)) return false; - - StorageMethodId that = (StorageMethodId)o; - return myMethodDescriptor == that.myMethodDescriptor && myMethodName == that.myMethodName && getClassQName() == that.getClassQName(); - } - - public int hashCode() { - int result = super.hashCode(); - result = 31 * result + myMethodName; - result = 31 * result + myMethodDescriptor; - return result; - } -} \ No newline at end of file diff --git a/java/compiler/openapi/src/com/intellij/openapi/compiler/TranslatingCompiler.java b/java/compiler/openapi/src/com/intellij/openapi/compiler/TranslatingCompiler.java index 019021a73096..3c56f8d9f67d 100644 --- a/java/compiler/openapi/src/com/intellij/openapi/compiler/TranslatingCompiler.java +++ b/java/compiler/openapi/src/com/intellij/openapi/compiler/TranslatingCompiler.java @@ -15,7 +15,9 @@ */ package com.intellij.openapi.compiler; +import com.intellij.openapi.module.Module; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.Chunk; import java.util.Collection; @@ -63,7 +65,7 @@ public interface TranslatingCompiler extends Compiler { * @param file the file to check. * @param context the context for the current compile operation. * @return true if can compile the file, false otherwise. If the method returns false, file - * will not be included in the list of files passed to {@link #compile(CompileContext,com.intellij.openapi.vfs.VirtualFile[], com.intellij.openapi.compiler.TranslatingCompiler.OutputSink)}. + * will not be included in the list of files passed to {@link #compile(CompileContext,Chunk,com.intellij.openapi.vfs.VirtualFile[], com.intellij.openapi.compiler.TranslatingCompiler.OutputSink)}. */ boolean isCompilableFile(VirtualFile file, CompileContext context); @@ -71,8 +73,9 @@ public interface TranslatingCompiler extends Compiler { * Compiles the specified files. * * @param context the context for the current compile operation. - * @param files the source files to compile. + * @param moduleChunk contains modules that form a cycle. If project module graph has no cycles, a chunk corresponds to a single module + * @param files the source files to compile that correspond to the module chunk * @param sink storage that accepts compiler output results */ - void compile(CompileContext context, VirtualFile[] files, OutputSink sink); + void compile(CompileContext context, Chunk moduleChunk, VirtualFile[] files, OutputSink sink); } diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java index afb713c505cb..7c23640f104c 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/GroovyCompilerBase.java @@ -17,7 +17,6 @@ package org.jetbrains.plugins.groovy.compiler; import com.intellij.compiler.CompilerConfiguration; -import com.intellij.compiler.ModuleCompilerUtil; import com.intellij.compiler.impl.CompilerUtil; import com.intellij.compiler.impl.FileSetCompileScope; import com.intellij.compiler.impl.javaCompiler.ModuleChunk; @@ -290,42 +289,45 @@ public abstract class GroovyCompilerBase implements TranslatingCompiler { return new ModuleChunk((CompileContextEx)context, new Chunk(module), Collections.>emptyMap()); } - public void compile(final CompileContext compileContext, final VirtualFile[] virtualFiles, OutputSink sink) { - Map> mapModulesToVirtualFiles = CompilerUtil.buildModuleToFilesMap(compileContext, virtualFiles); - final List> chunks = - ModuleCompilerUtil.getSortedModuleChunks(myProject, new ArrayList(mapModulesToVirtualFiles.keySet())); - for (final Chunk chunk : chunks) { - for (final Module module : chunk.getNodes()) { - final List moduleFiles = mapModulesToVirtualFiles.get(module); - if (moduleFiles == null) { - continue; - } + public void compile(final CompileContext compileContext, Chunk moduleChunk, final VirtualFile[] virtualFiles, OutputSink sink) { + Map> mapModulesToVirtualFiles; + if (moduleChunk.getNodes().size() == 1) { + mapModulesToVirtualFiles = Collections.singletonMap(moduleChunk.getNodes().iterator().next(), Arrays.asList(virtualFiles)); + } + else { + mapModulesToVirtualFiles = CompilerUtil.buildModuleToFilesMap(compileContext, virtualFiles); + } + for (final Module module : moduleChunk.getNodes()) { + final List moduleFiles = mapModulesToVirtualFiles.get(module); + if (moduleFiles == null) { + continue; + } - final ModuleFileIndex index = ModuleRootManager.getInstance(module).getFileIndex(); - final List toCompile = new ArrayList(); - final List toCompileTests = new ArrayList(); - final CompilerConfiguration configuration = CompilerConfiguration.getInstance(myProject); + final ModuleFileIndex index = ModuleRootManager.getInstance(module).getFileIndex(); + final List toCompile = new ArrayList(); + final List toCompileTests = new ArrayList(); + final CompilerConfiguration configuration = CompilerConfiguration.getInstance(myProject); - if (module.getModuleType() instanceof JavaModuleType) { - for (final VirtualFile file : moduleFiles) { - final boolean shouldCompile = !configuration.isResourceFile(file) && - (file.getFileType() == GroovyFileType.GROOVY_FILE_TYPE || - file.getFileType() == StdFileTypes.JAVA); - if (shouldCompile) { - (index.isInTestSourceContent(file) ? toCompileTests : toCompile).add(file); - } + if (module.getModuleType() instanceof JavaModuleType) { + for (final VirtualFile file : moduleFiles) { + final boolean shouldCompile = !configuration.isResourceFile(file) && + (file.getFileType() == GroovyFileType.GROOVY_FILE_TYPE || + file.getFileType() == StdFileTypes.JAVA); + if (shouldCompile) { + (index.isInTestSourceContent(file) ? toCompileTests : toCompile).add(file); } } - - if (!toCompile.isEmpty()) { - compileFiles(compileContext, module, toCompile, sink, false); - } - if (!toCompileTests.isEmpty()) { - compileFiles(compileContext, module, toCompileTests, sink, true); - } - } + + if (!toCompile.isEmpty()) { + compileFiles(compileContext, module, toCompile, sink, false); + } + if (!toCompileTests.isEmpty()) { + compileFiles(compileContext, module, toCompileTests, sink, true); + } + } + } protected abstract void compileFiles(CompileContext compileContext, Module module, diff --git a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovycStubGenerator.java b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovycStubGenerator.java index dcb5a25cfd33..b44e9462b2d8 100644 --- a/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovycStubGenerator.java +++ b/plugins/groovy/src/org/jetbrains/plugins/groovy/compiler/generator/GroovycStubGenerator.java @@ -32,6 +32,7 @@ import com.intellij.openapi.util.io.FileUtil; import com.intellij.openapi.vfs.LocalFileSystem; import com.intellij.openapi.vfs.VfsUtil; import com.intellij.openapi.vfs.VirtualFile; +import com.intellij.util.Chunk; import org.jetbrains.annotations.NotNull; import org.jetbrains.plugins.groovy.GroovyFileType; import org.jetbrains.plugins.groovy.compiler.GroovyCompilerBase; @@ -53,7 +54,7 @@ public class GroovycStubGenerator extends GroovyCompilerBase { } @Override - public void compile(CompileContext compileContext, VirtualFile[] virtualFiles, OutputSink sink) { + public void compile(CompileContext compileContext, Chunk moduleChunk, VirtualFile[] virtualFiles, OutputSink sink) { final CompileScope scope = compileContext.getCompileScope(); if (scope.getFiles(StdFileTypes.JAVA, true).length == 0) { return; @@ -75,7 +76,7 @@ public class GroovycStubGenerator extends GroovyCompilerBase { return; } - super.compile(compileContext, total.toArray(new VirtualFile[total.size()]), sink); + super.compile(compileContext, moduleChunk, total.toArray(new VirtualFile[total.size()]), sink); } @Override diff --git a/plugins/ui-designer/src/com/intellij/uiDesigner/make/Form2ByteCodeCompiler.java b/plugins/ui-designer/src/com/intellij/uiDesigner/make/Form2ByteCodeCompiler.java index d49afd6db9d3..3b2165b16c56 100644 --- a/plugins/ui-designer/src/com/intellij/uiDesigner/make/Form2ByteCodeCompiler.java +++ b/plugins/ui-designer/src/com/intellij/uiDesigner/make/Form2ByteCodeCompiler.java @@ -297,7 +297,7 @@ public final class Form2ByteCodeCompiler implements ClassInstrumentingCompiler { final ArrayList list = module2itemsList.get(module); for (final MyInstrumentationItem item : list) { - context.getProgressIndicator().setFraction((double)++formsProcessed / (double)items.length); + //context.getProgressIndicator().setFraction((double)++formsProcessed / (double)items.length); final VirtualFile formFile = item.getFormFile(); context.getProgressIndicator().setText2(formFile.getPresentableUrl());