Search in sources :

Example 21 with CantRunException

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

the class JdkUtil method setupCommandLine.

private static void setupCommandLine(GeneralCommandLine commandLine, SimpleJavaParameters javaParameters) throws CantRunException {
    final ParametersList vmParameters = javaParameters.getVMParametersList();
    commandLine.withEnvironment(javaParameters.getEnv());
    commandLine.withParentEnvironmentType(javaParameters.isPassParentEnvs() ? ParentEnvironmentType.CONSOLE : ParentEnvironmentType.NONE);
    final Class commandLineWrapper;
    boolean dynamicParameters = false;
    if (javaParameters.isDynamicClasspath() && !explicitClassPath(vmParameters) && javaParameters.getModulePath().isEmpty() && (commandLineWrapper = getCommandLineWrapperClass()) != null) {
        if (isClassPathJarEnabled(javaParameters, PathUtil.getJarPathForClass(ClassPath.class))) {
            dynamicParameters = setClasspathJarParams(javaParameters, commandLine, vmParameters, commandLineWrapper);
        } else {
            dynamicParameters = setCommandLineWrapperParams(javaParameters, commandLine, vmParameters, commandLineWrapper);
        }
    } else {
        appendParamsEncodingClasspath(javaParameters, commandLine, vmParameters);
    }
    final String mainClass = javaParameters.getMainClass();
    final String moduleName = javaParameters.getModuleName();
    final String jarPath = javaParameters.getJarPath();
    if (moduleName != null && mainClass != null) {
        commandLine.addParameter("-m");
        commandLine.addParameter(moduleName + '/' + mainClass);
    } else if (mainClass != null) {
        commandLine.addParameter(mainClass);
    } else if (jarPath != null) {
        commandLine.addParameter("-jar");
        commandLine.addParameter(jarPath);
    } else {
        throw new CantRunException(ExecutionBundle.message("main.class.is.not.specified.error.message"));
    }
    if (!dynamicParameters) {
        commandLine.addParameters(javaParameters.getProgramParametersList().getList());
    }
    commandLine.withWorkDirectory(javaParameters.getWorkingDirectory());
}
Also used : ClassPath(com.intellij.util.lang.ClassPath) CantRunException(com.intellij.execution.CantRunException) ParametersList(com.intellij.execution.configurations.ParametersList)

Example 22 with CantRunException

use of com.intellij.execution.CantRunException 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)

Aggregations

CantRunException (com.intellij.execution.CantRunException)22 VirtualFile (com.intellij.openapi.vfs.VirtualFile)10 Sdk (com.intellij.openapi.projectRoots.Sdk)7 Module (com.intellij.openapi.module.Module)5 File (java.io.File)5 Nullable (org.jetbrains.annotations.Nullable)5 ExecutionException (com.intellij.execution.ExecutionException)4 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)4 JavaParameters (com.intellij.execution.configurations.JavaParameters)4 IOException (java.io.IOException)4 ParametersList (com.intellij.execution.configurations.ParametersList)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Task (com.intellij.openapi.progress.Task)3 SourceScope (com.intellij.execution.testframework.SourceScope)2 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)2 PluginId (com.intellij.openapi.extensions.PluginId)2 Project (com.intellij.openapi.project.Project)2 JavaSdkType (com.intellij.openapi.projectRoots.JavaSdkType)2 SdkTypeId (com.intellij.openapi.projectRoots.SdkTypeId)2 PsiClass (com.intellij.psi.PsiClass)2