diff --git a/java/java-tests/testSrc/com/intellij/java/execution/RunConfigurationJavaExtensionManagerTestCase.kt b/java/java-tests/testSrc/com/intellij/java/execution/RunConfigurationJavaExtensionManagerTestCase.kt index 2a3129554376..f0736712fb30 100644 --- a/java/java-tests/testSrc/com/intellij/java/execution/RunConfigurationJavaExtensionManagerTestCase.kt +++ b/java/java-tests/testSrc/com/intellij/java/execution/RunConfigurationJavaExtensionManagerTestCase.kt @@ -18,7 +18,7 @@ import com.intellij.testFramework.runInEdtAndWait import com.intellij.util.concurrency.Semaphore abstract class RunConfigurationJavaExtensionManagerTestCase : ExecutionTestCase() { - override fun initOutputChecker(): OutputChecker = OutputChecker("", "") + override fun initOutputChecker(): OutputChecker = OutputChecker({ "" }, { "" }) protected fun doTestOnlyApplicableConfigurationExtensionsShouldBeProcessed(configuration: RunConfiguration, expectedOutput: String? = null) { diff --git a/java/testFramework/src/com/intellij/debugger/impl/OutputChecker.java b/java/testFramework/src/com/intellij/debugger/impl/OutputChecker.java index 36ef012dc946..38008f18c2bd 100644 --- a/java/testFramework/src/com/intellij/debugger/impl/OutputChecker.java +++ b/java/testFramework/src/com/intellij/debugger/impl/OutputChecker.java @@ -23,6 +23,7 @@ import com.intellij.openapi.vfs.CharsetToolkit; import com.intellij.openapi.vfs.VirtualFile; import com.intellij.project.IntelliJProjectConfiguration; import com.intellij.util.PathUtil; +import com.intellij.util.Producer; import org.jetbrains.annotations.Nullable; import java.io.File; @@ -47,8 +48,8 @@ public class OutputChecker { private static final String[] IGNORED_PATTERNS_IN_STDERR = {"Picked up _JAVA_OPTIONS:", "Picked up JAVA_TOOL_OPTIONS:"}; - private final String myAppPath; - private final String myOutputPath; + private final Producer myAppPath; + private final Producer myOutputPath; private Map myBuffers; private String myTestName; @@ -65,7 +66,7 @@ public class OutputChecker { } } - public OutputChecker(String appPath, String outputPath) { + public OutputChecker(Producer appPath, Producer outputPath) { myAppPath = appPath; myOutputPath = outputPath; } @@ -126,7 +127,7 @@ public class OutputChecker { String actual = preprocessBuffer(buildOutputString(), sortClassPath); - File outs = new File(myAppPath + File.separator + "outs"); + File outs = new File(myAppPath.produce() + File.separator + "outs"); assert outs.exists() || outs.mkdirs() : outs; File outFile = getOutFile(outs, jdk, null, ""); @@ -194,8 +195,8 @@ public class OutputChecker { result = StringUtil.replace(result, "\r\n", "\n"); result = StringUtil.replace(result, "\r", "\n"); result = replaceAdditionalInOutput(result); - result = replacePath(result, myAppPath, "!APP_PATH!"); - result = replacePath(result, myOutputPath, "!OUTPUT_PATH!"); + result = replacePath(result, myAppPath.produce(), "!APP_PATH!"); + result = replacePath(result, myOutputPath.produce(), "!OUTPUT_PATH!"); result = replacePath(result, JavaSdkUtil.getIdeaRtJarPath(), "!RT_JAR!"); if (PluginManagerCore.isRunningFromSources()) { result = replacePath(result, DebuggerUtilsImpl.getIdeaRtPath(), "!RT_JAR!"); diff --git a/java/testFramework/src/com/intellij/execution/ExecutionTestCase.java b/java/testFramework/src/com/intellij/execution/ExecutionTestCase.java index af2c530dc027..fd1e0d3929bc 100644 --- a/java/testFramework/src/com/intellij/execution/ExecutionTestCase.java +++ b/java/testFramework/src/com/intellij/execution/ExecutionTestCase.java @@ -57,26 +57,42 @@ public abstract class ExecutionTestCase extends JavaProjectTestCase { ourOutputRoot = getTempDir().newPath(); } - myModuleOutputDir = ourOutputRoot.resolve(PathUtil.getFileName(getTestAppPath())); myChecker = initOutputChecker(); EdtTestUtil.runInEdtAndWait(() -> super.setUp()); + myModuleOutputDir = getModuleOutputDir(); if (!Files.exists(myModuleOutputDir)) { Files.createDirectories(myModuleOutputDir); - VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByNioFile(ourOutputRoot); - assertNotNull(ourOutputRoot.toString(), vDir); + if (FileUtil.isAncestor(ourOutputRoot.toFile(), myModuleOutputDir.toFile(), false)) { + VirtualFile vDir = LocalFileSystem.getInstance().refreshAndFindFileByNioFile(ourOutputRoot); + assertNotNull(ourOutputRoot.toString(), vDir); + } - // JDK added by compilerTester is used after compilation, so, we don't dispose compilerTester after rebuild - CompilerTester compilerTester = new CompilerTester(myProject, Arrays.asList(ModuleManager.getInstance(myProject).getModules()), getTestRootDisposable()); - List messages = compilerTester.rebuild(); - for (CompilerMessage message : messages) { - if (message.getCategory() == CompilerMessageCategory.ERROR) { - FileUtil.delete(myModuleOutputDir); - fail("Compilation failed: " + message + " " + message.getVirtualFile()); - } + compileProject(); + } + } + + protected void compileProject() throws Exception { + // JDK added by compilerTester is used after compilation, so, we don't dispose compilerTester after rebuild + CompilerTester compilerTester = new CompilerTester(myProject, Arrays.asList(ModuleManager.getInstance(myProject).getModules()), + getTestRootDisposable(), overrideCompileJdkAndOutput()); + List messages = compilerTester.rebuild(); + for (CompilerMessage message : messages) { + if (message.getCategory() == CompilerMessageCategory.ERROR) { + FileUtil.delete(myModuleOutputDir); + fail("Compilation failed: " + message + " " + message.getVirtualFile()); } } } + @NotNull + protected Path getModuleOutputDir() { + return ourOutputRoot.resolve(PathUtil.getFileName(getTestAppPath())); + } + + protected boolean overrideCompileJdkAndOutput() { + return true; + } + @Override protected void setUpModule() { super.setUpModule(); @@ -91,7 +107,9 @@ public abstract class ExecutionTestCase extends JavaProjectTestCase { PsiTestUtil.addContentRoot(myModule, moduleDir); PsiTestUtil.addSourceRoot(myModule, srcDir); IdeaTestUtil.setModuleLanguageLevel(myModule, LanguageLevel.JDK_1_8); - PsiTestUtil.setCompilerOutputPath(myModule, VfsUtilCore.pathToUrl(myModuleOutputDir.toString()), false); + + Path outputDir = getModuleOutputDir(); + PsiTestUtil.setCompilerOutputPath(myModule, VfsUtilCore.pathToUrl(outputDir.toString()), false); }); } @@ -153,7 +171,7 @@ public abstract class ExecutionTestCase extends JavaProjectTestCase { } protected String getAppOutputPath() { - return myModuleOutputDir.toString(); + return getModuleOutputDir().toString(); } public void waitProcess(@NotNull final ProcessHandler processHandler) { diff --git a/java/testFramework/src/com/intellij/testFramework/CompilerTester.java b/java/testFramework/src/com/intellij/testFramework/CompilerTester.java index 39cac0fc47df..b302c8fe0d6d 100644 --- a/java/testFramework/src/com/intellij/testFramework/CompilerTester.java +++ b/java/testFramework/src/com/intellij/testFramework/CompilerTester.java @@ -73,7 +73,16 @@ public final class CompilerTester { this(fixture.getProject(), modules, fixture.getTestRootDisposable()); } - public CompilerTester(@NotNull Project project, @NotNull List modules, @Nullable Disposable disposable) throws Exception { + public CompilerTester(@NotNull Project project, + @NotNull List modules, + @Nullable Disposable disposable) throws Exception { + this(project, modules, disposable, true); + } + + public CompilerTester(@NotNull Project project, + @NotNull List modules, + @Nullable Disposable disposable, + boolean overrideJdkAndOutput) throws Exception { myProject = project; myModules = modules; myMainOutput = new TempDirTestFixtureImpl(); @@ -89,15 +98,17 @@ public final class CompilerTester { } CompilerTestUtil.enableExternalCompiler(); - WriteCommandAction.writeCommandAction(getProject()).run(() -> { - Objects.requireNonNull(CompilerProjectExtension.getInstance(getProject())).setCompilerOutputUrl(myMainOutput.findOrCreateDir("out").getUrl()); - if (!myModules.isEmpty()) { - JavaAwareProjectJdkTableImpl projectJdkTable = JavaAwareProjectJdkTableImpl.getInstanceEx(); - for (Module module : myModules) { - ModuleRootModificationUtil.setModuleSdk(module, projectJdkTable.getInternalJdk()); + if (overrideJdkAndOutput) { + WriteCommandAction.writeCommandAction(getProject()).run(() -> { + Objects.requireNonNull(CompilerProjectExtension.getInstance(getProject())).setCompilerOutputUrl(myMainOutput.findOrCreateDir("out").getUrl()); + if (!myModules.isEmpty()) { + JavaAwareProjectJdkTableImpl projectJdkTable = JavaAwareProjectJdkTableImpl.getInstanceEx(); + for (Module module : myModules) { + ModuleRootModificationUtil.setModuleSdk(module, projectJdkTable.getInternalJdk()); + } } - } - }); + }); + } } public void tearDown() { diff --git a/platform/remote-servers/target-integration-tests/testSrc/com/intellij/tests/targets/java/JavaTargetTestBase.kt b/platform/remote-servers/target-integration-tests/testSrc/com/intellij/tests/targets/java/JavaTargetTestBase.kt index e359043e1c30..09f0e2b1f0fe 100644 --- a/platform/remote-servers/target-integration-tests/testSrc/com/intellij/tests/targets/java/JavaTargetTestBase.kt +++ b/platform/remote-servers/target-integration-tests/testSrc/com/intellij/tests/targets/java/JavaTargetTestBase.kt @@ -44,6 +44,7 @@ import com.intellij.psi.JavaPsiFacade import com.intellij.psi.PsiClass import com.intellij.psi.search.GlobalSearchScope import com.intellij.testFramework.TestModeFlags +import com.intellij.testFramework.fixtures.MavenDependencyUtil import kotlinx.coroutines.* import org.assertj.core.api.Assertions.assertThat import org.jdom.Content @@ -77,7 +78,7 @@ abstract class JavaTargetTestBase(protected val executionMode: ExecutionMode) : /** Expected contents of [targetFilePath]. */ abstract val targetFileContent: String - override fun initOutputChecker(): OutputChecker = OutputChecker(testAppPath, appOutputPath) + override fun initOutputChecker(): OutputChecker = OutputChecker({ testAppPath }, { appOutputPath }) override fun getTestAppPath(): String = "${PathManager.getCommunityHomePath()}/platform/remote-servers/target-integration-tests/targetApp" @@ -108,12 +109,9 @@ abstract class JavaTargetTestBase(protected val executionMode: ExecutionMode) : override fun setUpModule() { super.setUpModule() - val libraryDescriptor = JpsMavenRepositoryLibraryDescriptor("org.junit.jupiter", "junit-jupiter-api", "5.3.0") - AbstractTestFrameworkIntegrationTest.addMavenLibs(module, libraryDescriptor) - - val contentRoot = LocalFileSystem.getInstance().findFileByPath( - "${PathManagerEx.getCommunityHomePath()}/platform/remote-servers/target-integration-tests/targetApp")!! + val contentRoot = LocalFileSystem.getInstance().findFileByPath(testAppPath)!! ModuleRootModificationUtil.updateModel(module) { model: ModifiableRootModel -> + MavenDependencyUtil.addFromMaven(model, "org.junit.jupiter:junit-jupiter-api:5.3.0", true) val contentEntry = model.addContentEntry(contentRoot) contentEntry.addSourceFolder(contentRoot.url + "/src", false) contentEntry.addSourceFolder(contentRoot.url + "/tests", true) diff --git a/plugins/stream-debugger/src/com/intellij/debugger/streams/test/TraceExecutionTestCase.java b/plugins/stream-debugger/src/com/intellij/debugger/streams/test/TraceExecutionTestCase.java index d9f3a5601de0..7b9b252e859b 100644 --- a/plugins/stream-debugger/src/com/intellij/debugger/streams/test/TraceExecutionTestCase.java +++ b/plugins/stream-debugger/src/com/intellij/debugger/streams/test/TraceExecutionTestCase.java @@ -47,7 +47,7 @@ public abstract class TraceExecutionTestCase extends DebuggerTestCase { @Override protected OutputChecker initOutputChecker() { - return new OutputChecker(getTestAppPath(), getAppOutputPath()) { + return new OutputChecker(() -> getTestAppPath(), () -> getAppOutputPath()) { @Override protected String replaceAdditionalInOutput(String str) { return TraceExecutionTestCase.this.replaceAdditionalInOutput(super.replaceAdditionalInOutput(str));