From 027dda9f9c0d381819d1e857421f14e22eaa45fe Mon Sep 17 00:00:00 2001 From: Roman Shevchenko Date: Tue, 6 Nov 2018 18:05:02 +0100 Subject: [PATCH] [tests] extracts helper method --- .../NotNullVerifyingInstrumenterTest.java | 26 +++++-------------- .../intellij/testFramework/IdeaTestUtil.java | 18 +++++++++++++ 2 files changed, 25 insertions(+), 19 deletions(-) diff --git a/java/java-tests/testSrc/com/intellij/java/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java b/java/java-tests/testSrc/com/intellij/java/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java index ee2c71351ccd..6d6b41830ef8 100644 --- a/java/java-tests/testSrc/com/intellij/java/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java +++ b/java/java-tests/testSrc/com/intellij/java/compiler/notNullVerification/NotNullVerifyingInstrumenterTest.java @@ -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 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 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); diff --git a/java/testFramework/src/com/intellij/testFramework/IdeaTestUtil.java b/java/testFramework/src/com/intellij/testFramework/IdeaTestUtil.java index 022a856a9e5a..f168d3580464 100644 --- a/java/testFramework/src/com/intellij/testFramework/IdeaTestUtil.java +++ b/java/testFramework/src/com/intellij/testFramework/IdeaTestUtil.java @@ -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 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)); + } + } } \ No newline at end of file