Search in sources :

Example 21 with JavaParameters

use of com.intellij.execution.configurations.JavaParameters in project intellij-community by JetBrains.

the class TestNGRunnableState method createJavaParameters.

@Override
protected JavaParameters createJavaParameters() throws ExecutionException {
    final JavaParameters javaParameters = super.createJavaParameters();
    javaParameters.setMainClass("org.testng.RemoteTestNGStarter");
    try {
        port = NetUtils.findAvailableSocketPort();
    } catch (IOException e) {
        throw new ExecutionException("Unable to bind to port " + port, e);
    }
    final TestData data = getConfiguration().getPersistantData();
    if (data.getOutputDirectory() != null && !data.getOutputDirectory().isEmpty()) {
        javaParameters.getProgramParametersList().add(CommandLineArgs.OUTPUT_DIRECTORY, data.getOutputDirectory());
    }
    javaParameters.getProgramParametersList().add(CommandLineArgs.USE_DEFAULT_LISTENERS, String.valueOf(data.USE_DEFAULT_REPORTERS));
    @NonNls final StringBuilder buf = new StringBuilder();
    if (data.TEST_LISTENERS != null && !data.TEST_LISTENERS.isEmpty()) {
        buf.append(StringUtil.join(data.TEST_LISTENERS, ";"));
    }
    collectListeners(javaParameters, buf, IDEATestNGListener.EP_NAME, ";");
    if (buf.length() > 0)
        javaParameters.getProgramParametersList().add(CommandLineArgs.LISTENER, buf.toString());
    createServerSocket(javaParameters);
    createTempFiles(javaParameters);
    return javaParameters;
}
Also used : NonNls(org.jetbrains.annotations.NonNls) TestData(com.theoryinpractice.testng.model.TestData) JavaParameters(com.intellij.execution.configurations.JavaParameters) IOException(java.io.IOException) ExecutionException(com.intellij.execution.ExecutionException)

Example 22 with JavaParameters

use of com.intellij.execution.configurations.JavaParameters in project intellij-community by JetBrains.

the class TestMethods method createJavaParameters.

@Override
protected JavaParameters createJavaParameters() throws ExecutionException {
    final JavaParameters javaParameters = super.createDefaultJavaParameters();
    final JUnitConfiguration.Data data = getConfiguration().getPersistentData();
    final RunConfigurationModule configurationModule = getConfiguration().getConfigurationModule();
    final Project project = configurationModule.getProject();
    final Module module = configurationModule.getModule();
    final GlobalSearchScope searchScope = module != null ? module.getModuleRuntimeScope(true) : GlobalSearchScope.allScope(project);
    addClassesListToJavaParameters(myFailedTests, testInfo -> testInfo != null ? getTestPresentation(testInfo, project, searchScope) : null, data.getPackageName(), true, javaParameters);
    return javaParameters;
}
Also used : Project(com.intellij.openapi.project.Project) RunConfigurationModule(com.intellij.execution.configurations.RunConfigurationModule) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JavaParameters(com.intellij.execution.configurations.JavaParameters) RunConfigurationModule(com.intellij.execution.configurations.RunConfigurationModule) Module(com.intellij.openapi.module.Module)

Example 23 with JavaParameters

use of com.intellij.execution.configurations.JavaParameters in project intellij-community by JetBrains.

the class TestObject method createJavaParameters.

@Override
protected JavaParameters createJavaParameters() throws ExecutionException {
    JavaParameters javaParameters = super.createJavaParameters();
    javaParameters.setMainClass(JUnitConfiguration.JUNIT_START_CLASS);
    javaParameters.getProgramParametersList().add(JUnitStarter.IDE_VERSION + JUnitStarter.VERSION);
    final StringBuilder buf = new StringBuilder();
    collectListeners(javaParameters, buf, IDEAJUnitListener.EP_NAME, "\n");
    if (buf.length() > 0) {
        try {
            myListenersFile = FileUtil.createTempFile("junit_listeners_", "", true);
            javaParameters.getProgramParametersList().add("@@" + myListenersFile.getPath());
            FileUtil.writeToFile(myListenersFile, buf.toString().getBytes(CharsetToolkit.UTF8_CHARSET));
        } catch (IOException e) {
            LOG.error(e);
        }
    }
    final Project project = getConfiguration().getProject();
    final SourceScope sourceScope = getSourceScope();
    if (isJUnit5(getConfiguration().getConfigurationModule().getModule(), sourceScope, project)) {
        javaParameters.getProgramParametersList().add(JUnitStarter.JUNIT5_PARAMETER);
        javaParameters.getClassPath().add(PathUtil.getJarPathForClass(JUnit5IdeaTestRunner.class));
        final PathsList classPath = javaParameters.getClassPath();
        classPath.add(PathUtil.getJarPathForClass(TestExecutionListener.class));
        classPath.add(PathUtil.getJarPathForClass(JupiterTestEngine.class));
        classPath.add(PathUtil.getJarPathForClass(JUnitException.class));
        classPath.add(PathUtil.getJarPathForClass(TestEngine.class));
        classPath.add(PathUtil.getJarPathForClass(JUnitPlatform.class));
        try {
            JUnitUtil.getTestCaseClass(sourceScope);
            classPath.add(PathUtil.getJarPathForClass(VintageTestEngine.class));
        } catch (JUnitUtil.NoJUnitException ignore) {
        }
    }
    return javaParameters;
}
Also used : JupiterTestEngine(org.junit.jupiter.engine.JupiterTestEngine) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) JUnitException(org.junit.platform.commons.JUnitException) JUnit5IdeaTestRunner(com.intellij.junit5.JUnit5IdeaTestRunner) IOException(java.io.IOException) VintageTestEngine(org.junit.vintage.engine.VintageTestEngine) Project(com.intellij.openapi.project.Project) SourceScope(com.intellij.execution.testframework.SourceScope) PathsList(com.intellij.util.PathsList) JavaParameters(com.intellij.execution.configurations.JavaParameters) TestEngine(org.junit.platform.engine.TestEngine) JupiterTestEngine(org.junit.jupiter.engine.JupiterTestEngine) VintageTestEngine(org.junit.vintage.engine.VintageTestEngine) JUnitPlatform(org.junit.platform.runner.JUnitPlatform)

Example 24 with JavaParameters

use of com.intellij.execution.configurations.JavaParameters in project intellij-community by JetBrains.

the class TestObject method addClassesListToJavaParameters.

protected <T> void addClassesListToJavaParameters(Collection<? extends T> elements, Function<T, String> nameFunction, String packageName, boolean createTempFile, JavaParameters javaParameters) throws CantRunException {
    try {
        if (createTempFile) {
            createTempFiles(javaParameters);
        }
        final Map<Module, List<String>> perModule = forkPerModule() ? new TreeMap<>((o1, o2) -> StringUtil.compare(o1.getName(), o2.getName(), true)) : null;
        final List<String> testNames = new ArrayList<>();
        for (final T element : elements) {
            final String name = nameFunction.fun(element);
            if (name == null) {
                continue;
            }
            final PsiElement psiElement = retrievePsiElement(element);
            if (perModule != null && psiElement != null) {
                final Module module = ModuleUtilCore.findModuleForPsiElement(psiElement);
                if (module != null) {
                    List<String> list = perModule.get(module);
                    if (list == null) {
                        list = new ArrayList<>();
                        perModule.put(module, list);
                    }
                    list.add(name);
                }
            } else {
                testNames.add(name);
            }
        }
        final JUnitConfiguration.Data data = getConfiguration().getPersistentData();
        if (perModule != null) {
            for (List<String> perModuleClasses : perModule.values()) {
                Collections.sort(perModuleClasses);
                testNames.addAll(perModuleClasses);
            }
        } else if (JUnitConfiguration.TEST_PACKAGE.equals(data.TEST_OBJECT)) {
            //sort tests in FQN order
            Collections.sort(testNames);
        }
        final String category = JUnitConfiguration.TEST_CATEGORY.equals(data.TEST_OBJECT) ? data.getCategory() : "";
        JUnitStarter.printClassesList(testNames, packageName, category, myTempFile);
        writeClassesPerModule(packageName, javaParameters, perModule);
    } catch (IOException e) {
        LOG.error(e);
    }
}
Also used : java.util(java.util) CharsetToolkit(com.intellij.openapi.vfs.CharsetToolkit) PathsList(com.intellij.util.PathsList) RuntimeConfigurationException(com.intellij.execution.configurations.RuntimeConfigurationException) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) RefactoringElementListener(com.intellij.refactoring.listeners.RefactoringElementListener) TestEngine(org.junit.platform.engine.TestEngine) NonNls(org.jetbrains.annotations.NonNls) JupiterTestEngine(org.junit.jupiter.engine.JupiterTestEngine) TestBySource(com.intellij.execution.junit.testDiscovery.TestBySource) ProgramParametersUtil(com.intellij.execution.util.ProgramParametersUtil) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ParametersList(com.intellij.execution.configurations.ParametersList) SourceScope(com.intellij.execution.testframework.SourceScope) RepeatCount(com.intellij.rt.execution.junit.RepeatCount) SearchForTestsTask(com.intellij.execution.testframework.SearchForTestsTask) JUnit5IdeaTestRunner(com.intellij.junit5.JUnit5IdeaTestRunner) Project(com.intellij.openapi.project.Project) FileUtil(com.intellij.openapi.util.io.FileUtil) Logger(com.intellij.openapi.diagnostic.Logger) Module(com.intellij.openapi.module.Module) IDEAJUnitListener(com.intellij.rt.execution.junit.IDEAJUnitListener) ProcessTerminatedListener(com.intellij.execution.process.ProcessTerminatedListener) ModuleUtilCore(com.intellij.openapi.module.ModuleUtilCore) TestsByChanges(com.intellij.execution.junit.testDiscovery.TestsByChanges) KillableColoredProcessHandler(com.intellij.execution.process.KillableColoredProcessHandler) StringUtil(com.intellij.openapi.util.text.StringUtil) ForkedDebuggerHelper(com.intellij.rt.execution.testFrameworks.ForkedDebuggerHelper) JUnitException(org.junit.platform.commons.JUnitException) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) JavaParametersUtil(com.intellij.execution.util.JavaParametersUtil) IOException(java.io.IOException) File(java.io.File) VintageTestEngine(org.junit.vintage.engine.VintageTestEngine) com.intellij.execution(com.intellij.execution) Nullable(org.jetbrains.annotations.Nullable) Function(com.intellij.util.Function) JavaParameters(com.intellij.execution.configurations.JavaParameters) TestSearchScope(com.intellij.execution.testframework.TestSearchScope) com.intellij.psi(com.intellij.psi) PathUtil(com.intellij.util.PathUtil) JUnitPlatform(org.junit.platform.runner.JUnitPlatform) NotNull(org.jetbrains.annotations.NotNull) JUnitStarter(com.intellij.rt.execution.junit.JUnitStarter) TestExecutionListener(org.junit.platform.launcher.TestExecutionListener) IOException(java.io.IOException) PathsList(com.intellij.util.PathsList) ParametersList(com.intellij.execution.configurations.ParametersList) Module(com.intellij.openapi.module.Module)

Example 25 with JavaParameters

use of com.intellij.execution.configurations.JavaParameters in project intellij-community by JetBrains.

the class MavenJUnitPatcherTest method testArgList.

public void testArgList() throws Exception {
    VirtualFile m1 = createModulePom("m1", "<groupId>test</groupId>" + "<artifactId>m1</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency>" + "    <groupId>test</groupId>" + "    <artifactId>m2</artifactId>" + "    <version>1</version>" + "  </dependency>" + "</dependencies>" + "<build><plugins>" + "  <plugin>" + "    <groupId>org.apache.maven.plugins</groupId>" + "    <artifactId>maven-surefire-plugin</artifactId>" + "    <version>2.16</version>" + "    <configuration>" + "      <argLine>-Xmx2048M -XX:MaxPermSize=512M \"-Dargs=can have spaces\"</argLine>" + "    </configuration>" + "  </plugin>" + "</plugins></build>");
    importProjects(m1);
    Module module = getModule("m1");
    MavenJUnitPatcher mavenJUnitPatcher = new MavenJUnitPatcher();
    JavaParameters javaParameters = new JavaParameters();
    mavenJUnitPatcher.patchJavaParameters(module, javaParameters);
    assertEquals(asList("-Xmx2048M", "-XX:MaxPermSize=512M", "-Dargs=can have spaces"), javaParameters.getVMParametersList().getList());
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JavaParameters(com.intellij.execution.configurations.JavaParameters) Module(com.intellij.openapi.module.Module)

Aggregations

JavaParameters (com.intellij.execution.configurations.JavaParameters)30 Module (com.intellij.openapi.module.Module)9 VirtualFile (com.intellij.openapi.vfs.VirtualFile)8 ExecutionException (com.intellij.execution.ExecutionException)7 Project (com.intellij.openapi.project.Project)6 File (java.io.File)5 Nullable (org.jetbrains.annotations.Nullable)5 CantRunException (com.intellij.execution.CantRunException)4 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)4 NotNull (org.jetbrains.annotations.NotNull)4 ParametersList (com.intellij.execution.configurations.ParametersList)3 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)3 SourceScope (com.intellij.execution.testframework.SourceScope)3 Sdk (com.intellij.openapi.projectRoots.Sdk)3 PathsList (com.intellij.util.PathsList)3 IOException (java.io.IOException)3 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)2 JUnit5IdeaTestRunner (com.intellij.junit5.JUnit5IdeaTestRunner)2 GlobalSearchScope (com.intellij.psi.search.GlobalSearchScope)2 NonNls (org.jetbrains.annotations.NonNls)2