mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
[tests] extracts helper method
This commit is contained in:
+7
-19
@@ -7,6 +7,7 @@ import com.intellij.compiler.instrumentation.FailSafeClassReader;
|
||||
import com.intellij.compiler.notNullVerification.NotNullVerifyingInstrumenter;
|
||||
import com.intellij.openapi.util.io.FileUtil;
|
||||
import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.testFramework.IdeaTestUtil;
|
||||
import com.intellij.testFramework.PlatformTestUtil;
|
||||
import com.intellij.testFramework.rules.TempDirectory;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
@@ -286,26 +287,13 @@ public class NotNullVerifyingInstrumenterTest {
|
||||
private Class<?> prepareTest(boolean withDebugInfo, String... notNullAnnotations) throws IOException {
|
||||
String testDir = JavaTestUtil.getJavaTestDataPath() + "/compiler/notNullVerification";
|
||||
String testName = PlatformTestUtil.getTestName(this.testName.getMethodName(), false);
|
||||
File classesDir = tempDir.newFolder("output");
|
||||
|
||||
List<String> cmdLine = ContainerUtil.newArrayList("-d", classesDir.getAbsolutePath(), "-classpath", testDir + "/annotations.jar");
|
||||
if (withDebugInfo) cmdLine.add("-g");
|
||||
|
||||
File testFile = new File(testDir, testName + ".java");
|
||||
if (testFile.exists()) {
|
||||
cmdLine.add(testFile.getPath());
|
||||
com.sun.tools.javac.Main.compile(ArrayUtil.toStringArray(cmdLine));
|
||||
}
|
||||
else {
|
||||
testFile = new File(testDir, testName + ".groovy");
|
||||
if (testFile.exists()) {
|
||||
cmdLine.add(testFile.getPath());
|
||||
org.codehaus.groovy.tools.FileSystemCompiler.main(ArrayUtil.toStringArray(cmdLine));
|
||||
}
|
||||
else {
|
||||
throw new FileNotFoundException("No test source for " + testName);
|
||||
}
|
||||
}
|
||||
if (!testFile.exists()) testFile = new File(testDir, testName + ".groovy");
|
||||
if (!testFile.exists()) throw new FileNotFoundException("No test source for " + testName);
|
||||
File classesDir = tempDir.newFolder("output");
|
||||
List<String> args = ContainerUtil.newArrayList("-classpath", testDir + "/annotations.jar");
|
||||
if (withDebugInfo) args.add("-g");
|
||||
IdeaTestUtil.compileFile(testFile, classesDir, ArrayUtil.toStringArray(args));
|
||||
|
||||
File[] files = classesDir.listFiles();
|
||||
assertNotNull(files);
|
||||
|
||||
@@ -15,6 +15,7 @@ import com.intellij.openapi.util.text.StringUtil;
|
||||
import com.intellij.openapi.vfs.JarFileSystem;
|
||||
import com.intellij.openapi.vfs.VirtualFile;
|
||||
import com.intellij.pom.java.LanguageLevel;
|
||||
import com.intellij.util.ArrayUtil;
|
||||
import com.intellij.util.PathUtil;
|
||||
import com.intellij.util.SystemProperties;
|
||||
import com.intellij.util.containers.ContainerUtil;
|
||||
@@ -26,6 +27,7 @@ import org.junit.Assert;
|
||||
import org.junit.Assume;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@TestOnly
|
||||
@@ -182,4 +184,20 @@ public class IdeaTestUtil extends PlatformTestUtil {
|
||||
Assume.assumeTrue("Cannot find JDK, checked paths: " + paths, false);
|
||||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("UnnecessaryFullyQualifiedName")
|
||||
public static void compileFile(File source, File out, String... options) {
|
||||
Assert.assertTrue("source does not exist: " + source.getPath(), source.isFile());
|
||||
List<String> args = new ArrayList<>();
|
||||
args.add("-d");
|
||||
args.add(out.getAbsolutePath());
|
||||
ContainerUtil.addAll(args, options);
|
||||
args.add(source.getAbsolutePath());
|
||||
if (source.getName().endsWith(".groovy")) {
|
||||
org.codehaus.groovy.tools.FileSystemCompiler.main(ArrayUtil.toStringArray(args));
|
||||
}
|
||||
else {
|
||||
com.sun.tools.javac.Main.compile(ArrayUtil.toStringArray(args));
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user