From fb3a28f9e5340d06a8d1e1abfc527418f94441bf Mon Sep 17 00:00:00 2001 From: nik Date: Tue, 25 Sep 2012 10:45:49 +0400 Subject: [PATCH] external compiler: fixed warnings on plugin project rebuild --- .../compiler/BaseCompilerTestCase.java | 40 ++++++++++++++----- .../jps/incremental/IncProjectBuilder.java | 3 +- .../build/PluginModuleCompilationTest.java | 18 +++++++-- 3 files changed, 46 insertions(+), 15 deletions(-) diff --git a/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java b/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java index 0f865598d0a5..f480ceb7aedc 100644 --- a/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java +++ b/java/compiler/impl/testSrc/com/intellij/compiler/BaseCompilerTestCase.java @@ -186,8 +186,8 @@ public abstract class BaseCompilerTestCase extends ModuleTestCase { }); } - protected void rebuild() { - compile(false, new ParameterizedRunnable() { + protected CompilationLog rebuild() { + return compile(false, new ParameterizedRunnable() { @Override public void run(CompileStatusNotification compileStatusNotification) { getCompilerManager().rebuild(compileStatusNotification); @@ -196,6 +196,17 @@ public abstract class BaseCompilerTestCase extends ModuleTestCase { } protected CompilationLog compile(final boolean errorsExpected, final ParameterizedRunnable action) { + CompilationLog log = compile(action); + if (errorsExpected && log.myErrors.length == 0) { + Assert.fail("compilation finished without errors"); + } + else if (!errorsExpected && log.myErrors.length > 0) { + Assert.fail("compilation finished with errors: " + Arrays.toString(log.myErrors)); + } + return log; + } + + private CompilationLog compile(final ParameterizedRunnable action) { final Ref result = Ref.create(null); final Semaphore semaphore = new Semaphore(); UIUtil.invokeAndWaitIfNeeded(new Runnable() { @@ -211,14 +222,9 @@ public abstract class BaseCompilerTestCase extends ModuleTestCase { if (aborted) { Assert.fail("compilation aborted"); } - if (errorsExpected && errors == 0) { - Assert.fail("compilation finished without errors"); - } - else if (!errorsExpected && errors > 0) { - Assert - .fail("compilation finished with errors: " + Arrays.toString(compileContext.getMessages(CompilerMessageCategory.ERROR))); - } - result.set(new CompilationLog(CompilerManagerImpl.getPathsToRecompile(), CompilerManagerImpl.getPathsToDelete())); + result.set(new CompilationLog(CompilerManagerImpl.getPathsToRecompile(), CompilerManagerImpl.getPathsToDelete(), + compileContext.getMessages(CompilerMessageCategory.ERROR), + compileContext.getMessages(CompilerMessageCategory.WARNING))); } finally { semaphore.up(); @@ -349,8 +355,12 @@ public abstract class BaseCompilerTestCase extends ModuleTestCase { protected class CompilationLog { private final Set myRecompiledPaths; private final Set myDeletedPaths; + private final CompilerMessage[] myErrors; + private final CompilerMessage[] myWarnings; - public CompilationLog(String[] recompiledPaths, String[] deletedPaths) { + public CompilationLog(String[] recompiledPaths, String[] deletedPaths, CompilerMessage[] errors, CompilerMessage[] warnings) { + myErrors = errors; + myWarnings = warnings; myRecompiledPaths = getRelativePaths(recompiledPaths); myDeletedPaths = getRelativePaths(deletedPaths); } @@ -383,6 +393,14 @@ public abstract class BaseCompilerTestCase extends ModuleTestCase { assertSet("deleted", myDeletedPaths, expected); } + public CompilerMessage[] getErrors() { + return myErrors; + } + + public CompilerMessage[] getWarnings() { + return myWarnings; + } + private void assertSet(String name, Set actual, String[] expected) { if (useExternalCompiler()) return; for (String path : expected) { diff --git a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java index a95ae8231115..cdbfd5d27f56 100644 --- a/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java +++ b/jps/jps-builders/src/org/jetbrains/jps/incremental/IncProjectBuilder.java @@ -24,6 +24,7 @@ import org.jetbrains.jps.api.RequestFuture; import org.jetbrains.jps.builders.BuildRootDescriptor; import org.jetbrains.jps.builders.BuildTarget; import org.jetbrains.jps.builders.BuildTargetType; +import org.jetbrains.jps.builders.java.JavaModuleBuildTargetType; import org.jetbrains.jps.builders.java.dependencyView.Callbacks; import org.jetbrains.jps.cmdline.BuildRunner; import org.jetbrains.jps.cmdline.ProjectDescriptor; @@ -340,7 +341,7 @@ public class IncProjectBuilder { } ProjectDescriptor projectDescriptor = context.getProjectDescriptor(); - for (BuildTargetType type : BuilderRegistry.getInstance().getTargetTypes()) { + for (BuildTargetType type : JavaModuleBuildTargetType.ALL_TYPES) { for (BuildTarget target : projectDescriptor.getBuildTargetIndex().getAllTargets(type)) { for (BuildRootDescriptor descriptor : projectDescriptor.getBuildRootIndex().getTargetRoots(target, context)) { allSourceRoots.add(descriptor.getRootFile()); diff --git a/plugins/devkit/testSources/build/PluginModuleCompilationTest.java b/plugins/devkit/testSources/build/PluginModuleCompilationTest.java index fedae6eff720..6053792ddd78 100644 --- a/plugins/devkit/testSources/build/PluginModuleCompilationTest.java +++ b/plugins/devkit/testSources/build/PluginModuleCompilationTest.java @@ -33,6 +33,7 @@ import org.jetbrains.idea.devkit.projectRoots.IdeaJdk; import org.jetbrains.idea.devkit.projectRoots.Sandbox; import java.io.File; +import java.util.Arrays; import static com.intellij.util.io.TestFileSystemBuilder.fs; @@ -80,9 +81,7 @@ public class PluginModuleCompilationTest extends BaseCompilerTestCase { } public void testMakeModule() { - copyToProject("plugins/devkit/testData/build/simple"); - Module module = loadModule(getProjectBasePath() + "/pluginProject.iml"); - readJdomExternalizables((ModuleImpl)module); + Module module = setupPluginProject(); make(module); assertOutput(module, fs().dir("xxx").file("MyAction.class")); @@ -95,4 +94,17 @@ public class PluginModuleCompilationTest extends BaseCompilerTestCase { .dir("xxx").file("MyAction.class") .build().assertDirectoryEqual(sandbox); } + + public void testRebuild() { + setupPluginProject(); + CompilationLog log = rebuild(); + assertTrue("Rebuild finished with warnings: " + Arrays.toString(log.getWarnings()), log.getWarnings().length == 0); + } + + private Module setupPluginProject() { + copyToProject("plugins/devkit/testData/build/simple"); + Module module = loadModule(getProjectBasePath() + "/pluginProject.iml"); + readJdomExternalizables((ModuleImpl)module); + return module; + } }