From b3ad42ab1edd4bc350ce27ebb8cb489aaeee0773 Mon Sep 17 00:00:00 2001 From: Eugene Zhuravlev Date: Tue, 16 Nov 2010 18:55:17 +0300 Subject: [PATCH] more cases when index rebuild should be scheduled --- .../intellij/compiler/impl/CompileDriver.java | 322 +++++++++--------- .../com/intellij/psi/stubs/StubIndexImpl.java | 2 +- 2 files changed, 165 insertions(+), 159 deletions(-) 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 a83e0cf79c4b..dbdb99cf8bcf 100644 --- a/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java +++ b/java/compiler/impl/src/com/intellij/compiler/impl/CompileDriver.java @@ -2047,183 +2047,189 @@ public class CompileDriver { } private boolean validateCompilerConfiguration(final CompileScope scope, boolean checkOutputAndSourceIntersection) { - final Module[] scopeModules = scope.getAffectedModules()/*ModuleManager.getInstance(myProject).getModules()*/; - final List modulesWithoutOutputPathSpecified = new ArrayList(); - boolean isProjectCompilePathSpecified = true; - final List modulesWithoutJdkAssigned = new ArrayList(); - final Set nonExistingOutputPaths = new HashSet(); - final CompilerConfiguration config = CompilerConfiguration.getInstance(myProject); + try { + final Module[] scopeModules = scope.getAffectedModules()/*ModuleManager.getInstance(myProject).getModules()*/; + final List modulesWithoutOutputPathSpecified = new ArrayList(); + boolean isProjectCompilePathSpecified = true; + final List modulesWithoutJdkAssigned = new ArrayList(); + final Set nonExistingOutputPaths = new HashSet(); + final CompilerConfiguration config = CompilerConfiguration.getInstance(myProject); - for (final Module module : scopeModules) { - final boolean hasSources = hasSources(module, false); - final boolean hasTestSources = hasSources(module, true); - if (!hasSources && !hasTestSources) { - // If module contains no sources, shouldn't have to select JDK or output directory (SCR #19333) - // todo still there may be problems with this approach if some generated files are attributed by this module - continue; - } - final Sdk jdk = ModuleRootManager.getInstance(module).getSdk(); - if (jdk == null) { - modulesWithoutJdkAssigned.add(module.getName()); - } - final String outputPath = getModuleOutputPath(module, false); - final String testsOutputPath = getModuleOutputPath(module, true); - if (outputPath == null && testsOutputPath == null) { - modulesWithoutOutputPathSpecified.add(module.getName()); - } - else { - if (outputPath != null) { - final File file = new File(outputPath.replace('/', File.separatorChar)); - if (!file.exists()) { - nonExistingOutputPaths.add(file); - } + for (final Module module : scopeModules) { + final boolean hasSources = hasSources(module, false); + final boolean hasTestSources = hasSources(module, true); + if (!hasSources && !hasTestSources) { + // If module contains no sources, shouldn't have to select JDK or output directory (SCR #19333) + // todo still there may be problems with this approach if some generated files are attributed by this module + continue; + } + final Sdk jdk = ModuleRootManager.getInstance(module).getSdk(); + if (jdk == null) { + modulesWithoutJdkAssigned.add(module.getName()); + } + final String outputPath = getModuleOutputPath(module, false); + final String testsOutputPath = getModuleOutputPath(module, true); + if (outputPath == null && testsOutputPath == null) { + modulesWithoutOutputPathSpecified.add(module.getName()); } else { - if (hasSources) { - modulesWithoutOutputPathSpecified.add(module.getName()); - } - } - if (testsOutputPath != null) { - final File f = new File(testsOutputPath.replace('/', File.separatorChar)); - if (!f.exists()) { - nonExistingOutputPaths.add(f); - } - } - else { - if (hasTestSources) { - modulesWithoutOutputPathSpecified.add(module.getName()); - } - } - if (config.isAnnotationProcessorsEnabled() && config.isAnnotationProcessingEnabled(module)) { - final String path = CompilerPaths.getAnnotationProcessorsGenerationPath(module); - if (path == null) { - final CompilerProjectExtension extension = CompilerProjectExtension.getInstance(module.getProject()); - if (extension == null || extension.getCompilerOutputUrl() == null) { - isProjectCompilePathSpecified = false; - } - else { - modulesWithoutOutputPathSpecified.add(module.getName()); - } - } - else { - final File file = new File(path); + if (outputPath != null) { + final File file = new File(outputPath.replace('/', File.separatorChar)); if (!file.exists()) { nonExistingOutputPaths.add(file); } } - } - } - } - if (!modulesWithoutJdkAssigned.isEmpty()) { - showNotSpecifiedError("error.jdk.not.specified", modulesWithoutJdkAssigned, ProjectBundle.message("modules.classpath.title")); - return false; - } - - if (!isProjectCompilePathSpecified) { - final String message = CompilerBundle.message("error.project.output.not.specified"); - if (ApplicationManager.getApplication().isUnitTestMode()) { - LOG.error(message); - } - - Messages.showMessageDialog(myProject, message, CommonBundle.getErrorTitle(), Messages.getErrorIcon()); - ProjectSettingsService.getInstance(myProject).openProjectSettings(); - return false; - } - - if (!modulesWithoutOutputPathSpecified.isEmpty()) { - showNotSpecifiedError("error.output.not.specified", modulesWithoutOutputPathSpecified, CommonContentEntriesEditor.NAME); - return false; - } - - if (!nonExistingOutputPaths.isEmpty()) { - for (File file : nonExistingOutputPaths) { - final boolean succeeded = file.mkdirs(); - if (!succeeded) { - if (file.exists()) { - // for overlapping paths, this one might have been created as an intermediate path on a previous iteration - continue; + else { + if (hasSources) { + modulesWithoutOutputPathSpecified.add(module.getName()); + } } - Messages.showMessageDialog(myProject, CompilerBundle.message("error.failed.to.create.directory", file.getPath()), - CommonBundle.getErrorTitle(), Messages.getErrorIcon()); - return false; - } - } - final Boolean refreshSuccess = - new WriteAction() { - @Override - protected void run(Result result) throws Throwable { - LocalFileSystem.getInstance().refreshIoFiles(nonExistingOutputPaths); - Boolean res = Boolean.TRUE; - for (File file : nonExistingOutputPaths) { - if (LocalFileSystem.getInstance().findFileByIoFile(file) == null) { - res = Boolean.FALSE; - break; + if (testsOutputPath != null) { + final File f = new File(testsOutputPath.replace('/', File.separatorChar)); + if (!f.exists()) { + nonExistingOutputPaths.add(f); + } + } + else { + if (hasTestSources) { + modulesWithoutOutputPathSpecified.add(module.getName()); + } + } + if (config.isAnnotationProcessorsEnabled() && config.isAnnotationProcessingEnabled(module)) { + final String path = CompilerPaths.getAnnotationProcessorsGenerationPath(module); + if (path == null) { + final CompilerProjectExtension extension = CompilerProjectExtension.getInstance(module.getProject()); + if (extension == null || extension.getCompilerOutputUrl() == null) { + isProjectCompilePathSpecified = false; + } + else { + modulesWithoutOutputPathSpecified.add(module.getName()); + } + } + else { + final File file = new File(path); + if (!file.exists()) { + nonExistingOutputPaths.add(file); } } - result.setResult(res); } - }.execute().getResultObject(); - - if (!refreshSuccess.booleanValue()) { + } + } + if (!modulesWithoutJdkAssigned.isEmpty()) { + showNotSpecifiedError("error.jdk.not.specified", modulesWithoutJdkAssigned, ProjectBundle.message("modules.classpath.title")); return false; } - dropScopesCaches(); - } - if (checkOutputAndSourceIntersection) { - if (myShouldClearOutputDirectory) { - if (!validateOutputAndSourcePathsIntersection()) { + if (!isProjectCompilePathSpecified) { + final String message = CompilerBundle.message("error.project.output.not.specified"); + if (ApplicationManager.getApplication().isUnitTestMode()) { + LOG.error(message); + } + + Messages.showMessageDialog(myProject, message, CommonBundle.getErrorTitle(), Messages.getErrorIcon()); + ProjectSettingsService.getInstance(myProject).openProjectSettings(); + return false; + } + + if (!modulesWithoutOutputPathSpecified.isEmpty()) { + showNotSpecifiedError("error.output.not.specified", modulesWithoutOutputPathSpecified, CommonContentEntriesEditor.NAME); + return false; + } + + if (!nonExistingOutputPaths.isEmpty()) { + for (File file : nonExistingOutputPaths) { + final boolean succeeded = file.mkdirs(); + if (!succeeded) { + if (file.exists()) { + // for overlapping paths, this one might have been created as an intermediate path on a previous iteration + continue; + } + Messages.showMessageDialog(myProject, CompilerBundle.message("error.failed.to.create.directory", file.getPath()), + CommonBundle.getErrorTitle(), Messages.getErrorIcon()); + return false; + } + } + final Boolean refreshSuccess = + new WriteAction() { + @Override + protected void run(Result result) throws Throwable { + LocalFileSystem.getInstance().refreshIoFiles(nonExistingOutputPaths); + Boolean res = Boolean.TRUE; + for (File file : nonExistingOutputPaths) { + if (LocalFileSystem.getInstance().findFileByIoFile(file) == null) { + res = Boolean.FALSE; + break; + } + } + result.setResult(res); + } + }.execute().getResultObject(); + + if (!refreshSuccess.booleanValue()) { + return false; + } + dropScopesCaches(); + } + + if (checkOutputAndSourceIntersection) { + if (myShouldClearOutputDirectory) { + if (!validateOutputAndSourcePathsIntersection()) { + return false; + } + } + } + final List> chunks = ModuleCompilerUtil.getSortedModuleChunks(myProject, Arrays.asList(scopeModules)); + for (final Chunk chunk : chunks) { + final Set chunkModules = chunk.getNodes(); + if (chunkModules.size() <= 1) { + continue; // no need to check one-module chunks + } + if (config.isAnnotationProcessorsEnabled()) { + for (Module chunkModule : chunkModules) { + if (config.isAnnotationProcessingEnabled(chunkModule)) { + showCyclesNotSupportedForAnnotationProcessors(chunkModules.toArray(new Module[chunkModules.size()])); + return false; + } + } + } + Sdk jdk = null; + LanguageLevel languageLevel = null; + for (final Module module : chunkModules) { + final Sdk moduleJdk = ModuleRootManager.getInstance(module).getSdk(); + if (jdk == null) { + jdk = moduleJdk; + } + else { + if (!jdk.equals(moduleJdk)) { + showCyclicModulesHaveDifferentJdksError(chunkModules.toArray(new Module[chunkModules.size()])); + return false; + } + } + + LanguageLevel moduleLanguageLevel = LanguageLevelUtil.getEffectiveLanguageLevel(module); + if (languageLevel == null) { + languageLevel = moduleLanguageLevel; + } + else { + if (!languageLevel.equals(moduleLanguageLevel)) { + showCyclicModulesHaveDifferentLanguageLevel(chunkModules.toArray(new Module[chunkModules.size()])); + return false; + } + } + } + } + final Compiler[] allCompilers = CompilerManager.getInstance(myProject).getCompilers(Compiler.class); + for (Compiler compiler : allCompilers) { + if (!compiler.validateConfiguration(scope)) { return false; } } + return true; } - final List> chunks = ModuleCompilerUtil.getSortedModuleChunks(myProject, Arrays.asList(scopeModules)); - for (final Chunk chunk : chunks) { - final Set chunkModules = chunk.getNodes(); - if (chunkModules.size() <= 1) { - continue; // no need to check one-module chunks - } - if (config.isAnnotationProcessorsEnabled()) { - for (Module chunkModule : chunkModules) { - if (config.isAnnotationProcessingEnabled(chunkModule)) { - showCyclesNotSupportedForAnnotationProcessors(chunkModules.toArray(new Module[chunkModules.size()])); - return false; - } - } - } - Sdk jdk = null; - LanguageLevel languageLevel = null; - for (final Module module : chunkModules) { - final Sdk moduleJdk = ModuleRootManager.getInstance(module).getSdk(); - if (jdk == null) { - jdk = moduleJdk; - } - else { - if (!jdk.equals(moduleJdk)) { - showCyclicModulesHaveDifferentJdksError(chunkModules.toArray(new Module[chunkModules.size()])); - return false; - } - } - - LanguageLevel moduleLanguageLevel = LanguageLevelUtil.getEffectiveLanguageLevel(module); - if (languageLevel == null) { - languageLevel = moduleLanguageLevel; - } - else { - if (!languageLevel.equals(moduleLanguageLevel)) { - showCyclicModulesHaveDifferentLanguageLevel(chunkModules.toArray(new Module[chunkModules.size()])); - return false; - } - } - } + catch (Throwable e) { + LOG.info(e); + return false; } - final Compiler[] allCompilers = CompilerManager.getInstance(myProject).getCompilers(Compiler.class); - for (Compiler compiler : allCompilers) { - if (!compiler.validateConfiguration(scope)) { - return false; - } - } - return true; } private void showCyclicModulesHaveDifferentLanguageLevel(Module[] modulesInChunk) { diff --git a/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java b/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java index 5b103ac8fd88..f83c8b14ed28 100644 --- a/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java +++ b/platform/lang-impl/src/com/intellij/psi/stubs/StubIndexImpl.java @@ -256,7 +256,7 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponent, Pe } catch (RuntimeException e) { final Throwable cause = e.getCause(); - if (cause instanceof IOException || cause instanceof StorageException) { + if (cause instanceof IOException || cause instanceof StorageException || cause instanceof IllegalArgumentException) { forceRebuild(e); } else {