Search in sources :

Example 6 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 7 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)

Example 8 with JavaParameters

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

the class MavenResolveToWorkspaceTest method testIgnoredProject.

public void testIgnoredProject() throws Exception {
    createProjectPom("<groupId>test</groupId>" + "<artifactId>project</artifactId>" + "<version>1</version>" + "<modules>" + "  <module>moduleA</module>" + "  <module>moduleIgnored</module>" + "  <module>moduleB</module>" + "</modules>");
    VirtualFile moduleA = createModulePom("moduleA", "<groupId>test</groupId>" + "<artifactId>moduleA</artifactId>" + "<version>1</version>");
    VirtualFile moduleIgnored = createModulePom("moduleIgnored", "<groupId>test</groupId>" + "<artifactId>moduleIgnored</artifactId>" + "<version>1</version>");
    VirtualFile moduleB = createModulePom("moduleB", "<groupId>test</groupId>" + "<artifactId>moduleB</artifactId>" + "<version>1</version>" + "<dependencies>" + "  <dependency>" + "    <groupId>test</groupId>" + "    <artifactId>moduleA</artifactId>" + "    <version>1</version>" + "  </dependency>" + "  <dependency>" + "    <groupId>test</groupId>" + "    <artifactId>moduleIgnored</artifactId>" + "    <version>1</version>" + "  </dependency>" + "</dependencies>");
    MavenProjectsManager.getInstance(myProject).setIgnoredFilesPaths(Collections.singletonList(moduleIgnored.getPath()));
    importProject();
    MavenProjectsManager.getInstance(myProject).setIgnoredFilesPaths(Collections.singletonList(moduleIgnored.getPath()));
    //assertModules("project", "moduleA", "moduleB");
    WriteAction.run(() -> ProjectRootManager.getInstance(myProject).setProjectSdk(createJdk("Java 1.5")));
    MavenRunnerParameters runnerParameters = new MavenRunnerParameters(moduleB.getParent().getPath(), false, Collections.singletonList("jetty:run"), Collections.<String, Boolean>emptyMap());
    runnerParameters.setResolveToWorkspace(true);
    MavenRunnerSettings runnerSettings = MavenRunner.getInstance(myProject).getSettings().clone();
    runnerSettings.setJreName(MavenRunnerSettings.USE_INTERNAL_JAVA);
    JavaParameters parameters = MavenExternalParameters.createJavaParameters(myProject, runnerParameters, MavenProjectsManager.getInstance(myProject).getGeneralSettings(), runnerSettings);
    String resolveMapFile = null;
    String prefix = "-D" + MavenModuleMap.PATHS_FILE_PROPERTY + "=";
    for (String param : parameters.getVMParametersList().getParameters()) {
        if (param.startsWith(prefix)) {
            resolveMapFile = param.substring(prefix.length());
            break;
        }
    }
    assertNotNull(resolveMapFile);
    Properties properties = readProperties(resolveMapFile);
    assertEquals(moduleA.getPath(), properties.getProperty("test:moduleA:pom:1"));
    assert properties.getProperty("test:moduleA:jar:1").endsWith("/moduleA/target/classes");
    assertNull(properties.getProperty("test:moduleIgnored:pom:1"));
    assertNull(properties.getProperty("test:moduleIgnored:jar:1"));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JavaParameters(com.intellij.execution.configurations.JavaParameters) Properties(java.util.Properties)

Example 9 with JavaParameters

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

the class ExecutionTestCase method createJavaParameters.

protected JavaParameters createJavaParameters(String mainClass) {
    JavaParameters parameters = new JavaParameters();
    parameters.getClassPath().add(getAppOutputPath());
    parameters.setMainClass(mainClass);
    parameters.setJdk(JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk());
    parameters.setWorkingDirectory(getTestAppPath());
    return parameters;
}
Also used : JavaParameters(com.intellij.execution.configurations.JavaParameters)

Example 10 with JavaParameters

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

the class AndroidJunitPatcherTest method setUp.

@Override
public void setUp() throws Exception {
    super.setUp();
    setUpIdeaAndroidProject();
    myPatcher = new AndroidJunitPatcher();
    myJavaParameters = new JavaParameters();
    myJavaParameters.getClassPath().addAll(getExampleClasspath());
    // Adding the facet makes Projects#isBuildWithGradle return 'true'.
    createAndAddGradleFacet(myModule);
}
Also used : JavaParameters(com.intellij.execution.configurations.JavaParameters)

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