Search in sources :

Example 1 with JavaParameters

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

the class GroovyConsole method createProcessHandler.

private static ProcessHandler createProcessHandler(Module module) {
    try {
        final JavaParameters javaParameters = createJavaParameters(module);
        final GeneralCommandLine commandLine = javaParameters.toCommandLine();
        return new OSProcessHandler(commandLine) {

            @Override
            public boolean isSilentlyDestroyOnClose() {
                return true;
            }
        };
    } catch (ExecutionException e) {
        LOG.warn(e);
        return null;
    }
}
Also used : GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) JavaParameters(com.intellij.execution.configurations.JavaParameters) ExecutionException(com.intellij.execution.ExecutionException)

Example 2 with JavaParameters

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

the class GroovyConsole method createJavaParameters.

private static JavaParameters createJavaParameters(@NotNull Module module) throws ExecutionException {
    JavaParameters res = GroovyScriptRunConfiguration.createJavaParametersWithSdk(module);
    DefaultGroovyScriptRunner.configureGenericGroovyRunner(res, module, "groovy.ui.GroovyMain", !GroovyConsoleUtil.hasGroovyAll(module), true);
    PathsList list = GroovyScriptRunner.getClassPathFromRootModel(module, true, res, true, res.getClassPath());
    if (list != null) {
        res.getClassPath().addAll(list.getPathList());
    }
    res.getProgramParametersList().addAll("-p", GroovyScriptRunner.getPathInConf("console.txt"));
    res.setWorkingDirectory(ModuleRootManager.getInstance(module).getContentRoots()[0].getPath());
    res.setUseDynamicClasspath(true);
    return res;
}
Also used : PathsList(com.intellij.util.PathsList) JavaParameters(com.intellij.execution.configurations.JavaParameters)

Example 3 with JavaParameters

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

the class DefaultGroovyShellRunner method createJavaParameters.

@NotNull
@Override
public JavaParameters createJavaParameters(@NotNull Module module) throws ExecutionException {
    JavaParameters res = GroovyScriptRunConfiguration.createJavaParametersWithSdk(module);
    DefaultGroovyScriptRunner.configureGenericGroovyRunner(res, module, "org.codehaus.groovy.tools.shell.Main", false, true);
    res.setWorkingDirectory(getWorkingDirectory(module));
    return res;
}
Also used : JavaParameters(com.intellij.execution.configurations.JavaParameters) NotNull(org.jetbrains.annotations.NotNull)

Example 4 with JavaParameters

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

the class JUnit4IntegrationTest method ignoredTestMethod.

@Test
public void ignoredTestMethod() throws Throwable {
    EdtTestUtil.runInEdtAndWait(() -> {
        PsiClass psiClass = findClass(getModule1(), CLASS_NAME);
        assertNotNull(psiClass);
        PsiMethod testMethod = psiClass.findMethodsByName(METHOD_NAME, false)[0];
        JUnitConfiguration configuration = createConfiguration(testMethod);
        Executor executor = DefaultRunExecutor.getRunExecutorInstance();
        RunnerAndConfigurationSettingsImpl settings = new RunnerAndConfigurationSettingsImpl(RunManagerImpl.getInstanceImpl(getProject()), configuration, false);
        ExecutionEnvironment environment = new ExecutionEnvironment(executor, ProgramRunnerUtil.getRunner(DefaultRunExecutor.EXECUTOR_ID, settings), settings, getProject());
        TestObject state = configuration.getState(executor, environment);
        JavaParameters parameters = state.getJavaParameters();
        parameters.setUseDynamicClasspath(getProject());
        GeneralCommandLine commandLine = parameters.toCommandLine();
        StringBuffer buf = new StringBuffer();
        StringBuffer err = new StringBuffer();
        OSProcessHandler process = new OSProcessHandler(commandLine);
        process.addProcessListener(new ProcessAdapter() {

            @Override
            public void onTextAvailable(ProcessEvent event, Key outputType) {
                String text = event.getText();
                try {
                    if (outputType == ProcessOutputTypes.STDOUT && !text.isEmpty() && ServiceMessage.parse(text.trim()) == null) {
                        buf.append(text);
                    }
                    if (outputType == ProcessOutputTypes.STDERR) {
                        err.append(text);
                    }
                } catch (ParseException e) {
                    e.printStackTrace();
                }
            }
        });
        process.startNotify();
        process.waitFor();
        process.destroyProcess();
        String testOutput = buf.toString();
        assertEmpty(err.toString());
        switch(myJUnitVersion) {
            //shouldn't work for old versions
            case "4.4":
            //shouldn't work for old versions
            case "4.5":
                break;
            default:
                assertTrue(testOutput, testOutput.contains("Test1"));
        }
    });
}
Also used : ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) PsiMethod(com.intellij.psi.PsiMethod) ProcessEvent(com.intellij.execution.process.ProcessEvent) JUnitConfiguration(com.intellij.execution.junit.JUnitConfiguration) PsiClass(com.intellij.psi.PsiClass) TestObject(com.intellij.execution.junit.TestObject) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) RunnerAndConfigurationSettingsImpl(com.intellij.execution.impl.RunnerAndConfigurationSettingsImpl) JavaParameters(com.intellij.execution.configurations.JavaParameters) ParseException(java.text.ParseException) Key(com.intellij.openapi.util.Key) Test(org.junit.Test)

Example 5 with JavaParameters

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

the class MavenJUnitPatcherTest method testVmPropertiesResolve.

public void testVmPropertiesResolve() 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\" ${argLineApx}</argLine>" + "    </configuration>" + "  </plugin>" + "</plugins></build>");
    importProjects(m1);
    Module module = getModule("m1");
    MavenJUnitPatcher mavenJUnitPatcher = new MavenJUnitPatcher();
    JavaParameters javaParameters = new JavaParameters();
    javaParameters.getVMParametersList().addProperty("argLineApx", "-DsomeKey=someValue");
    mavenJUnitPatcher.patchJavaParameters(module, javaParameters);
    assertEquals(asList("-DargLineApx=-DsomeKey=someValue", "-Xmx2048M", "-XX:MaxPermSize=512M", "-Dargs=can have spaces", "-DsomeKey=someValue"), 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