mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-02-04 23:39:07 +07:00
Initial version of test for building and running JPS projects in WSL with WSL JDK
GitOrigin-RevId: 5200d2b02d9df5bf83e2ed5ae189d6005044f8cb
This commit is contained in:
committed by
intellij-monorepo-bot
parent
fad6b164d0
commit
f1168cec42
@@ -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) {
|
||||
|
||||
@@ -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<String> myAppPath;
|
||||
private final Producer<String> myOutputPath;
|
||||
private Map<Key, StringBuffer> myBuffers;
|
||||
private String myTestName;
|
||||
|
||||
@@ -65,7 +66,7 @@ public class OutputChecker {
|
||||
}
|
||||
}
|
||||
|
||||
public OutputChecker(String appPath, String outputPath) {
|
||||
public OutputChecker(Producer<String> appPath, Producer<String> 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!");
|
||||
|
||||
@@ -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<CompilerMessage> 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<CompilerMessage> 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) {
|
||||
|
||||
@@ -73,7 +73,16 @@ public final class CompilerTester {
|
||||
this(fixture.getProject(), modules, fixture.getTestRootDisposable());
|
||||
}
|
||||
|
||||
public CompilerTester(@NotNull Project project, @NotNull List<? extends Module> modules, @Nullable Disposable disposable) throws Exception {
|
||||
public CompilerTester(@NotNull Project project,
|
||||
@NotNull List<? extends Module> modules,
|
||||
@Nullable Disposable disposable) throws Exception {
|
||||
this(project, modules, disposable, true);
|
||||
}
|
||||
|
||||
public CompilerTester(@NotNull Project project,
|
||||
@NotNull List<? extends Module> 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() {
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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));
|
||||
|
||||
Reference in New Issue
Block a user