Search in sources :

Example 11 with ApplicationConfiguration

use of com.intellij.execution.application.ApplicationConfiguration in project intellij-community by JetBrains.

the class ConfigurationsTest method testCreateInnerPackageLocalApplication.

public void testCreateInnerPackageLocalApplication() throws ExecutionException {
    PsiClass psiClass = findClass(getModule1(), "test2.NotATest.InnerApplication");
    assertNotNull(psiClass);
    ApplicationConfiguration configuration = createConfiguration(psiClass);
    assertEquals("test2.NotATest$InnerApplication", configuration.MAIN_CLASS_NAME);
    checkCanRun(configuration);
}
Also used : ApplicationConfiguration(com.intellij.execution.application.ApplicationConfiguration)

Example 12 with ApplicationConfiguration

use of com.intellij.execution.application.ApplicationConfiguration in project intellij-community by JetBrains.

the class ConfigurationsTest method testTestClassPathWhenRunningConfigurations.

public void testTestClassPathWhenRunningConfigurations() throws IOException, ExecutionException {
    addModule("module4", false);
    Module module4 = getModule4();
    assignJdk(module4);
    addSourcePath(module4, "testSrc", true);
    addSourcePath(module4, "src", false);
    String output = setCompilerOutput(module4, "classes", false);
    String testOuput = setCompilerOutput(module4, "testClasses", true);
    ApplicationConfiguration applicationConfiguration = createConfiguration(findClass(module4, "Application"));
    JavaParameters parameters = checkCanRun(applicationConfiguration);
    String classPath = parameters.getClassPath().getPathsString();
    checkDoesNotContain(classPath, testOuput);
    checkContains(classPath, output);
    JUnitConfiguration junitConfiguration = createJUnitConfiguration(findClass(module4, "TestApplication"), TestInClassConfigurationProducer.class, new MapDataContext());
    parameters = checkCanRun(junitConfiguration);
    classPath = parameters.getClassPath().getPathsString();
    checkContains(classPath, testOuput);
    checkContains(classPath, output);
    applicationConfiguration.MAIN_CLASS_NAME = junitConfiguration.getPersistentData().getMainClassName();
    classPath = checkCanRun(applicationConfiguration).getClassPath().getPathsString();
    checkContains(classPath, testOuput);
    checkContains(classPath, output);
}
Also used : MapDataContext(com.intellij.testFramework.MapDataContext) Module(com.intellij.openapi.module.Module) ApplicationConfiguration(com.intellij.execution.application.ApplicationConfiguration)

Example 13 with ApplicationConfiguration

use of com.intellij.execution.application.ApplicationConfiguration in project intellij-community by JetBrains.

the class GradleApplicationEnvironmentProvider method createExecutionEnvironment.

@Nullable
public ExecutionEnvironment createExecutionEnvironment(@NotNull Project project, @NotNull ExecuteRunConfigurationTask executeRunConfigurationTask, @Nullable Executor executor) {
    if (!isApplicable(executeRunConfigurationTask))
        return null;
    ApplicationConfiguration applicationConfiguration = (ApplicationConfiguration) executeRunConfigurationTask.getRunProfile();
    PsiClass mainClass = applicationConfiguration.getMainClass();
    if (mainClass == null)
        return null;
    VirtualFile virtualFile = mainClass.getContainingFile().getVirtualFile();
    Module module = ProjectFileIndex.SERVICE.getInstance(project).getModuleForFile(virtualFile);
    if (module == null)
        return null;
    final JavaParameters params = new JavaParameters();
    JavaParametersUtil.configureConfiguration(params, applicationConfiguration);
    params.getVMParametersList().addParametersString(applicationConfiguration.getVMParameters());
    String javaExePath = null;
    try {
        final Sdk jdk = JavaParametersUtil.createProjectJdk(project, applicationConfiguration.getAlternativeJrePath());
        if (jdk == null)
            throw new RuntimeException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
        final SdkTypeId type = jdk.getSdkType();
        if (!(type instanceof JavaSdkType))
            throw new RuntimeException(ExecutionBundle.message("run.configuration.error.no.jdk.specified"));
        javaExePath = ((JavaSdkType) type).getVMExecutablePath(jdk);
        if (javaExePath == null)
            throw new RuntimeException(ExecutionBundle.message("run.configuration.cannot.find.vm.executable"));
        javaExePath = FileUtil.toSystemIndependentName(javaExePath);
    } catch (CantRunException e) {
        ExecutionErrorDialog.show(e, "Cannot use specified JRE", project);
    }
    StringBuilder parametersString = new StringBuilder();
    for (String parameter : params.getProgramParametersList().getParameters()) {
        parametersString.append("args '").append(parameter).append("'\n");
    }
    StringBuilder vmParametersString = new StringBuilder();
    for (String parameter : params.getVMParametersList().getParameters()) {
        vmParametersString.append("jvmArgs '").append(parameter).append("'\n");
    }
    ExternalSystemTaskExecutionSettings taskSettings = new ExternalSystemTaskExecutionSettings();
    taskSettings.setExternalSystemIdString(GradleConstants.SYSTEM_ID.getId());
    taskSettings.setExternalProjectPath(ExternalSystemApiUtil.getExternalProjectPath(module));
    final String runAppTaskName = "run " + mainClass.getName();
    taskSettings.setTaskNames(Collections.singletonList(runAppTaskName));
    String executorId = executor == null ? DefaultRunExecutor.EXECUTOR_ID : executor.getId();
    ExecutionEnvironment environment = ExternalSystemUtil.createExecutionEnvironment(project, GradleConstants.SYSTEM_ID, taskSettings, executorId);
    if (environment != null) {
        RunnerAndConfigurationSettings runnerAndConfigurationSettings = environment.getRunnerAndConfigurationSettings();
        assert runnerAndConfigurationSettings != null;
        ExternalSystemRunConfiguration runConfiguration = (ExternalSystemRunConfiguration) runnerAndConfigurationSettings.getConfiguration();
        final String gradlePath = GradleProjectResolverUtil.getGradlePath(module);
        if (gradlePath == null)
            return null;
        final String sourceSetName;
        if (GradleConstants.GRADLE_SOURCE_SET_MODULE_TYPE_KEY.equals(ExternalSystemApiUtil.getExternalModuleType(module))) {
            sourceSetName = GradleProjectResolverUtil.getSourceSetName(module);
        } else {
            sourceSetName = ModuleRootManager.getInstance(module).getFileIndex().isInTestSourceContent(virtualFile) ? "test" : "main";
        }
        if (sourceSetName == null)
            return null;
        @Language("Groovy") String initScript = "projectsEvaluated {\n" + "  rootProject.allprojects {\n" + "    if(project.path == '" + gradlePath + "' && project.sourceSets) {\n" + "      project.tasks.create(name: '" + runAppTaskName + "', overwrite: true, type: JavaExec) {\n" + (javaExePath != null ? "        executable = '" + javaExePath + "'\n" : "") + "        classpath = project.sourceSets.'" + sourceSetName + "'.runtimeClasspath\n" + "        main = '" + mainClass.getQualifiedName() + "'\n" + parametersString.toString() + vmParametersString.toString() + "      }\n" + "    }\n" + "  }\n" + "}\n";
        runConfiguration.putUserData(GradleTaskManager.INIT_SCRIPT_KEY, initScript);
        return environment;
    } else {
        return null;
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) PsiClass(com.intellij.psi.PsiClass) ExternalSystemRunConfiguration(com.intellij.openapi.externalSystem.service.execution.ExternalSystemRunConfiguration) JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) CantRunException(com.intellij.execution.CantRunException) Language(org.intellij.lang.annotations.Language) JavaParameters(com.intellij.execution.configurations.JavaParameters) RunnerAndConfigurationSettings(com.intellij.execution.RunnerAndConfigurationSettings) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkTypeId(com.intellij.openapi.projectRoots.SdkTypeId) Module(com.intellij.openapi.module.Module) ApplicationConfiguration(com.intellij.execution.application.ApplicationConfiguration) ExternalSystemTaskExecutionSettings(com.intellij.openapi.externalSystem.model.execution.ExternalSystemTaskExecutionSettings) Nullable(org.jetbrains.annotations.Nullable)

Example 14 with ApplicationConfiguration

use of com.intellij.execution.application.ApplicationConfiguration in project intellij-community by JetBrains.

the class SnapShooterConfigurationExtension method updateJavaParameters.

@Override
public void updateJavaParameters(RunConfigurationBase configuration, JavaParameters params, RunnerSettings runnerSettings) {
    if (!isApplicableFor(configuration)) {
        return;
    }
    ApplicationConfiguration appConfiguration = (ApplicationConfiguration) configuration;
    SnapShooterConfigurationSettings settings = appConfiguration.getUserData(SnapShooterConfigurationSettings.SNAP_SHOOTER_KEY);
    if (settings == null) {
        settings = new SnapShooterConfigurationSettings();
        appConfiguration.putUserData(SnapShooterConfigurationSettings.SNAP_SHOOTER_KEY, settings);
    }
    if (appConfiguration.ENABLE_SWING_INSPECTOR) {
        settings.setLastPort(NetUtils.tryToFindAvailableSocketPort());
    }
    if (appConfiguration.ENABLE_SWING_INSPECTOR && settings.getLastPort() != -1) {
        params.getProgramParametersList().prepend(appConfiguration.MAIN_CLASS_NAME);
        params.getProgramParametersList().prepend(Integer.toString(settings.getLastPort()));
        // add +1 because idea_rt.jar will be added as the last entry to the classpath
        params.getProgramParametersList().prepend(Integer.toString(params.getClassPath().getPathList().size() + 1));
        Set<String> paths = new TreeSet<>();
        // ui-designer-impl
        paths.add(PathUtil.getJarPathForClass(SnapShooter.class));
        // appcore-api
        paths.add(PathUtil.getJarPathForClass(BaseComponent.class));
        // openapi
        paths.add(PathUtil.getJarPathForClass(ProjectComponent.class));
        // platform-impl
        paths.add(PathUtil.getJarPathForClass(DesignerEditorPanelFacade.class));
        // UIDesignerCore
        paths.add(PathUtil.getJarPathForClass(LwComponent.class));
        // forms_rt
        paths.add(PathUtil.getJarPathForClass(GridConstraints.class));
        // openapi
        paths.add(PathUtil.getJarPathForClass(PaletteGroup.class));
        // ui-impl
        paths.add(PathUtil.getJarPathForClass(LafManagerListener.class));
        // action-system-openapi
        paths.add(PathUtil.getJarPathForClass(DataProvider.class));
        // idea
        paths.add(PathUtil.getJarPathForClass(XmlStringUtil.class));
        // pom
        paths.add(PathUtil.getJarPathForClass(Navigatable.class));
        // extensions
        paths.add(PathUtil.getJarPathForClass(AreaInstance.class));
        // jgoodies
        paths.add(PathUtil.getJarPathForClass(FormLayout.class));
        paths.addAll(PathManager.getUtilClassPath());
        for (String path : paths) {
            params.getClassPath().addFirst(path);
        }
        params.setMainClass("com.intellij.uiDesigner.snapShooter.SnapShooter");
    }
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) ProjectComponent(com.intellij.openapi.components.ProjectComponent) BaseComponent(com.intellij.openapi.components.BaseComponent) AreaInstance(com.intellij.openapi.extensions.AreaInstance) LafManagerListener(com.intellij.ide.ui.LafManagerListener) DesignerEditorPanelFacade(com.intellij.designer.DesignerEditorPanelFacade) Navigatable(com.intellij.pom.Navigatable) DataProvider(com.intellij.openapi.actionSystem.DataProvider) XmlStringUtil(com.intellij.xml.util.XmlStringUtil) GridConstraints(com.intellij.uiDesigner.core.GridConstraints) TreeSet(java.util.TreeSet) LwComponent(com.intellij.uiDesigner.lw.LwComponent) ApplicationConfiguration(com.intellij.execution.application.ApplicationConfiguration) PaletteGroup(com.intellij.ide.palette.PaletteGroup)

Aggregations

ApplicationConfiguration (com.intellij.execution.application.ApplicationConfiguration)14 Module (com.intellij.openapi.module.Module)4 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)3 RuntimeConfigurationException (com.intellij.execution.configurations.RuntimeConfigurationException)2 PsiClass (com.intellij.psi.PsiClass)2 MapDataContext (com.intellij.testFramework.MapDataContext)2 Nullable (org.jetbrains.annotations.Nullable)2 DesignerEditorPanelFacade (com.intellij.designer.DesignerEditorPanelFacade)1 CantRunException (com.intellij.execution.CantRunException)1 ExecutionException (com.intellij.execution.ExecutionException)1 ApplicationConfigurable (com.intellij.execution.application.ApplicationConfigurable)1 ApplicationConfigurationType (com.intellij.execution.application.ApplicationConfigurationType)1 JavaParameters (com.intellij.execution.configurations.JavaParameters)1 JUnitConfigurable (com.intellij.execution.junit2.configuration.JUnitConfigurable)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 CommonJavaParametersPanel (com.intellij.execution.ui.CommonJavaParametersPanel)1 JreVersionDetector (com.intellij.execution.util.JreVersionDetector)1 IdeView (com.intellij.ide.IdeView)1 PaletteGroup (com.intellij.ide.palette.PaletteGroup)1 LafManagerListener (com.intellij.ide.ui.LafManagerListener)1