private void buildOutputItemsList( final String outputDir, final Module module, VirtualFile from, final FileTypeManager typeManager, final VirtualFile sourceRoot, final String packagePrefix, final List<File> filesToRefresh, final Map<String, Collection<TranslatingCompiler.OutputItem>> results) throws CacheCorruptedException { final Ref<CacheCorruptedException> exRef = new Ref<CacheCorruptedException>(null); final ModuleFileIndex fileIndex = ModuleRootManager.getInstance(module).getFileIndex(); final GlobalSearchScope srcRootScope = GlobalSearchScope.moduleScope(module) .intersectWith(GlobalSearchScopes.directoryScope(myProject, sourceRoot, true)); final Collection<FileType> registeredInputTypes = CompilerManager.getInstance(myProject).getRegisteredInputTypes(myTranslatingCompiler); final ContentIterator contentIterator = new ContentIterator() { public boolean processFile(final VirtualFile child) { try { if (child.isValid()) { if (!child.isDirectory() && registeredInputTypes.contains(child.getFileType())) { updateOutputItemsList( outputDir, child, sourceRoot, packagePrefix, filesToRefresh, results, srcRootScope); } } return true; } catch (CacheCorruptedException e) { exRef.set(e); return false; } } }; if (fileIndex.isInContent(from)) { // use file index for iteration to handle 'inner modules' and excludes properly fileIndex.iterateContentUnderDirectory(from, contentIterator); } else { // seems to be a root for generated sources VfsUtilCore.visitChildrenRecursively( from, new VirtualFileVisitor() { @Override public boolean visitFile(@NotNull VirtualFile file) { if (!file.isDirectory()) { contentIterator.processFile(file); } return true; } }); } final CacheCorruptedException exc = exRef.get(); if (exc != null) { throw exc; } }
private void runTransformingCompilers(final ModuleChunk chunk) { final JavaSourceTransformingCompiler[] transformers = CompilerManager.getInstance(myProject).getCompilers(JavaSourceTransformingCompiler.class); if (transformers.length == 0) { return; } if (LOG.isDebugEnabled()) { LOG.debug("Running transforming compilers..."); } final Module[] modules = chunk.getModules(); for (final JavaSourceTransformingCompiler transformer : transformers) { final Map<VirtualFile, VirtualFile> originalToCopyFileMap = new HashMap<VirtualFile, VirtualFile>(); final Application application = ApplicationManager.getApplication(); application.invokeAndWait( new Runnable() { public void run() { for (final Module module : modules) { for (final VirtualFile file : chunk.getFilesToCompile(module)) { final VirtualFile untransformed = chunk.getOriginalFile(file); if (transformer.isTransformable(untransformed)) { application.runWriteAction( new Runnable() { public void run() { try { // if untransformed != file, the file is already a (possibly // transformed) copy of the original 'untransformed' file. // If this is the case, just use already created copy and do not copy // file content once again final VirtualFile fileCopy = untransformed.equals(file) ? createFileCopy(getTempDir(module), file) : file; originalToCopyFileMap.put(file, fileCopy); } catch (IOException e) { // skip it } } }); } } } } }, myCompileContext.getProgressIndicator().getModalityState()); // do actual transform for (final Module module : modules) { final List<VirtualFile> filesToCompile = chunk.getFilesToCompile(module); for (int j = 0; j < filesToCompile.size(); j++) { final VirtualFile file = filesToCompile.get(j); final VirtualFile fileCopy = originalToCopyFileMap.get(file); if (fileCopy != null) { final boolean ok = transformer.transform(myCompileContext, fileCopy, chunk.getOriginalFile(file)); if (ok) { chunk.substituteWithTransformedVersion(module, j, fileCopy); } } } } } }