Search in sources :

Example 26 with JavaParameters

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

the class MavenClasspathsAndSearchScopesTest method assertClasspath.

private void assertClasspath(String moduleName, Scope scope, Type type, String... expectedPaths) throws Exception {
    createOutputDirectories();
    PathsList actualPathsList;
    Module module = getModule(moduleName);
    if (scope == Scope.RUNTIME) {
        JavaParameters params = new JavaParameters();
        params.configureByModule(module, type == Type.TESTS ? JavaParameters.CLASSES_AND_TESTS : JavaParameters.CLASSES_ONLY);
        actualPathsList = params.getClassPath();
    } else {
        OrderEnumerator en = OrderEnumerator.orderEntries(module).recursively().withoutSdk().compileOnly();
        if (type == Type.PRODUCTION)
            en.productionOnly();
        actualPathsList = en.classes().getPathsList();
    }
    assertPaths(expectedPaths, actualPathsList.getPathList());
}
Also used : JavaParameters(com.intellij.execution.configurations.JavaParameters) Module(com.intellij.openapi.module.Module)

Example 27 with JavaParameters

use of com.intellij.execution.configurations.JavaParameters 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 28 with JavaParameters

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

the class KotlinDebuggerTestCase method createJavaParameters.

@Override
protected JavaParameters createJavaParameters(String mainClass) {
    JavaParameters parameters = super.createJavaParameters(mainClass);
    parameters.getClassPath().add(ForTestCompileRuntime.runtimeJarForTests());
    parameters.getClassPath().add(CUSTOM_LIBRARY_JAR);
    return parameters;
}
Also used : JavaParameters(com.intellij.execution.configurations.JavaParameters)

Example 29 with JavaParameters

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

the class AbstractFrameworkRunner method createJavaParameters.

@Override
public JavaParameters createJavaParameters(@NotNull OsgiRunConfiguration runConfiguration, @NotNull List<SelectedBundle> bundles) throws ExecutionException {
    myRunConfiguration = runConfiguration;
    myInstance = myRunConfiguration.getInstanceToUse();
    assert myInstance != null : myRunConfiguration;
    myIntegrator = FrameworkIntegratorRegistry.getInstance().findIntegratorByInstanceDefinition(myInstance);
    assert myIntegrator != null : myInstance;
    myInstanceManager = myIntegrator.getFrameworkInstanceManager();
    myAdditionalProperties = myRunConfiguration.getAdditionalProperties();
    myBundles = bundles;
    JavaParameters params = new JavaParameters();
    if (myRunConfiguration.isGenerateWorkingDir()) {
        myWorkingDir = new File(PathManager.getSystemPath(), "osmorc/run." + System.currentTimeMillis());
    } else {
        myWorkingDir = new File(myRunConfiguration.getWorkingDir());
    }
    if (!myWorkingDir.isDirectory() && !myWorkingDir.mkdirs()) {
        throw new CantRunException("Cannot create work directory '" + myWorkingDir.getPath() + "'");
    }
    params.setWorkingDirectory(myWorkingDir);
    // only add JDK classes to the classpath, the rest is to be provided by bundles
    String jreHome = myRunConfiguration.isUseAlternativeJre() ? myRunConfiguration.getAlternativeJrePath() : null;
    JavaParametersUtil.configureProject(myRunConfiguration.getProject(), params, JavaParameters.JDK_ONLY, jreHome);
    // class path
    Collection<SelectedBundle> systemBundles = myInstanceManager.getFrameworkBundles(myInstance, FrameworkBundleType.SYSTEM);
    if (systemBundles.isEmpty()) {
        throw new CantRunException("Libraries required to start the framework not found - please check the installation");
    }
    for (SelectedBundle bundle : systemBundles) {
        String path = bundle.getBundlePath();
        assert path != null : bundle;
        params.getClassPath().add(path);
    }
    if (GenericRunProperties.isStartConsole(myAdditionalProperties)) {
        Collection<SelectedBundle> shellBundles = myInstanceManager.getFrameworkBundles(myInstance, FrameworkBundleType.SHELL);
        if (shellBundles.isEmpty()) {
            throw new CantRunException("Console requested but no shell bundles can be found - please check the installation");
        }
        List<SelectedBundle> allBundles = ContainerUtil.newArrayList(shellBundles);
        allBundles.addAll(myBundles);
        myBundles = allBundles;
    }
    if (myRunConfiguration.isIncludeAllBundlesInClassPath()) {
        for (SelectedBundle bundle : myBundles) {
            String path = bundle.getBundlePath();
            if (path != null) {
                params.getClassPath().add(path);
            }
        }
    }
    // runner options
    params.setUseDynamicVMOptions(!myBundles.isEmpty());
    params.setUseDynamicParameters(!myBundles.isEmpty());
    HttpConfigurable.getInstance().getJvmProperties(false, null).forEach(p -> params.getVMParametersList().addProperty(p.first, p.second));
    params.getVMParametersList().addParametersString(myRunConfiguration.getVmParameters());
    String additionalProgramParams = myRunConfiguration.getProgramParameters();
    if (!StringUtil.isEmptyOrSpaces(additionalProgramParams)) {
        params.getProgramParametersList().addParametersString(additionalProgramParams);
    }
    String bootDelegation = GenericRunProperties.getBootDelegation(myAdditionalProperties);
    if (!StringUtil.isEmptyOrSpaces(bootDelegation)) {
        params.getVMParametersList().addProperty("org.osgi.framework.bootdelegation", bootDelegation);
    }
    String systemPackages = GenericRunProperties.getSystemPackages(myAdditionalProperties);
    if (!StringUtil.isEmptyOrSpaces(systemPackages)) {
        params.getVMParametersList().addProperty("org.osgi.framework.system.packages.extra", systemPackages);
    }
    // framework-specific options
    setupParameters(params);
    return params;
}
Also used : CantRunException(com.intellij.execution.CantRunException) SelectedBundle(org.osmorc.run.ui.SelectedBundle) JavaParameters(com.intellij.execution.configurations.JavaParameters) File(java.io.File)

Example 30 with JavaParameters

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

the class BndLaunchUtil method createJavaParameters.

@NotNull
public static JavaParameters createJavaParameters(@NotNull BndRunConfigurationBase configuration, @NotNull ProjectLauncher launcher) throws CantRunException {
    Project project = configuration.getProject();
    JavaParameters parameters = new JavaParameters();
    File launcherDir = launcher.getCwd();
    parameters.setWorkingDirectory(launcherDir != null ? launcherDir.getPath() : project.getBasePath());
    String jreHome = configuration.useAlternativeJre ? configuration.alternativeJrePath : null;
    JavaParametersUtil.configureProject(project, parameters, JavaParameters.JDK_ONLY, jreHome);
    parameters.getEnv().putAll(launcher.getRunEnv());
    parameters.getVMParametersList().addAll(asList(launcher.getRunVM()));
    parameters.getClassPath().addAll(asList(launcher.getClasspath()));
    parameters.setMainClass(launcher.getMainTypeName());
    parameters.getProgramParametersList().addAll(asList(launcher.getRunProgramArgs()));
    return parameters;
}
Also used : Project(com.intellij.openapi.project.Project) JavaParameters(com.intellij.execution.configurations.JavaParameters) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

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