Search in sources :

Example 1 with SimpleJavaParameters

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

the class XsltCommandLineState method createJavaParameters.

protected SimpleJavaParameters createJavaParameters() throws ExecutionException {
    final Sdk jdk = myXsltRunConfiguration.getEffectiveJDK();
    if (jdk == null) {
        throw CantRunException.noJdkConfigured();
    }
    final SimpleJavaParameters parameters = new SimpleJavaParameters();
    parameters.setJdk(jdk);
    if (myXsltRunConfiguration.getJdkChoice() == XsltRunConfiguration.JdkChoice.FROM_MODULE) {
        final Module module = myXsltRunConfiguration.getEffectiveModule();
        // OK to run as if just a JDK has been selected (a missing JDK would already have been complained about above)
        if (module != null) {
            OrderEnumerator.orderEntries(module).productionOnly().recursively().classes().collectPaths(parameters.getClassPath());
        }
    }
    final ParametersList vmParameters = parameters.getVMParametersList();
    vmParameters.addParametersString(myXsltRunConfiguration.myVmArguments);
    if (isEmpty(myXsltRunConfiguration.getXsltFile())) {
        throw new CantRunException("No XSLT file selected");
    }
    vmParameters.defineProperty("xslt.file", myXsltRunConfiguration.getXsltFile());
    if (isEmpty(myXsltRunConfiguration.getXmlInputFile())) {
        throw new CantRunException("No XML input file selected");
    }
    vmParameters.defineProperty("xslt.input", myXsltRunConfiguration.getXmlInputFile());
    final XsltRunConfiguration.OutputType outputType = myXsltRunConfiguration.getOutputType();
    if (outputType == XsltRunConfiguration.OutputType.CONSOLE) {
        //noinspection deprecation
        myPort = NetUtils.tryToFindAvailableSocketPort(myXsltRunConfiguration.myRunnerPort);
        vmParameters.defineProperty("xslt.listen-port", String.valueOf(myPort));
    }
    if (myXsltRunConfiguration.isSaveToFile()) {
        vmParameters.defineProperty("xslt.output", myXsltRunConfiguration.myOutputFile);
    }
    for (Pair<String, String> pair : myXsltRunConfiguration.getParameters()) {
        final String name = pair.getFirst();
        final String value = pair.getSecond();
        if (isEmpty(name) || value == null)
            continue;
        vmParameters.defineProperty("xslt.param." + name, value);
    }
    vmParameters.defineProperty("xslt.smart-error-handling", String.valueOf(myXsltRunConfiguration.mySmartErrorHandling));
    final PluginId pluginId = PluginManagerCore.getPluginByClassName(getClass().getName());
    assert pluginId != null || System.getProperty("xslt.plugin.path") != null : "PluginId not found - development builds need to specify -Dxslt.plugin.path=../out/classes/production/xslt-rt";
    final File pluginPath;
    if (pluginId != null) {
        final IdeaPluginDescriptor descriptor = PluginManager.getPlugin(pluginId);
        assert descriptor != null;
        pluginPath = descriptor.getPath();
    } else {
        // -Dxslt.plugin.path=C:\work\java\intellij/ultimate\out\classes\production\xslt-rt
        pluginPath = new File(System.getProperty("xslt.plugin.path"));
    }
    LOG.debug("Plugin Path = " + pluginPath.getAbsolutePath());
    final char c = File.separatorChar;
    File rtClasspath = new File(pluginPath, "lib" + c + "rt" + c + "xslt-rt.jar");
    //        File rtClasspath = new File("C:/Demetra/plugins/xpath/lib/rt/xslt-rt.jar");
    if (!rtClasspath.exists()) {
        LOG.warn("Plugin's Runtime classes not found in " + rtClasspath.getAbsolutePath());
        if (!(rtClasspath = new File(pluginPath, "classes")).exists()) {
            if (ApplicationManagerEx.getApplicationEx().isInternal() && new File(pluginPath, "org").exists()) {
                rtClasspath = pluginPath;
            } else {
                throw new CantRunException("Runtime classes not found");
            }
        }
        parameters.getVMParametersList().prepend("-ea");
    }
    parameters.getClassPath().addTail(rtClasspath.getAbsolutePath());
    parameters.setMainClass("org.intellij.plugins.xslt.run.rt.XSLTRunner");
    if (isEmpty(myXsltRunConfiguration.myWorkingDirectory)) {
        parameters.setWorkingDirectory(new File(myXsltRunConfiguration.getXsltFile()).getParentFile().getAbsolutePath());
    } else {
        parameters.setWorkingDirectory(expandPath(myXsltRunConfiguration.myWorkingDirectory, myXsltRunConfiguration.getEffectiveModule(), myXsltRunConfiguration.getProject()));
    }
    myExtensionData = new UserDataHolderBase();
    final List<XsltRunnerExtension> extensions = XsltRunnerExtension.getExtensions(myXsltRunConfiguration, myIsDebugger);
    for (XsltRunnerExtension extension : extensions) {
        extension.patchParameters(parameters, myXsltRunConfiguration, myExtensionData);
    }
    parameters.setUseDynamicClasspath(JdkUtil.useDynamicClasspath(myXsltRunConfiguration.getProject()));
    return parameters;
}
Also used : UserDataHolderBase(com.intellij.openapi.util.UserDataHolderBase) SimpleJavaParameters(com.intellij.execution.configurations.SimpleJavaParameters) IdeaPluginDescriptor(com.intellij.ide.plugins.IdeaPluginDescriptor) PluginId(com.intellij.openapi.extensions.PluginId) CantRunException(com.intellij.execution.CantRunException) ParametersList(com.intellij.execution.configurations.ParametersList) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 2 with SimpleJavaParameters

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

the class RemoteExternalSystemCommunicationManager method createRunProfileState.

private RunProfileState createRunProfileState(final String configuration) {
    return new CommandLineState(null) {

        private SimpleJavaParameters createJavaParameters() throws ExecutionException {
            final SimpleJavaParameters params = new SimpleJavaParameters();
            params.setJdk(new SimpleJavaSdkType().createJdk("tmp", SystemProperties.getJavaHome()));
            File myWorkingDirectory = new File(configuration);
            params.setWorkingDirectory(myWorkingDirectory.isDirectory() ? myWorkingDirectory.getPath() : PathManager.getBinPath());
            final List<String> classPath = ContainerUtilRt.newArrayList();
            // IDE jars.
            classPath.addAll(PathManager.getUtilClassPath());
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ProjectBundle.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(PlaceHolder.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(DebuggerView.class));
            ExternalSystemApiUtil.addBundle(params.getClassPath(), "messages.ProjectBundle", ProjectBundle.class);
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(PsiBundle.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(Alarm.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(DependencyScope.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ExtensionPointName.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(StorageUtilKt.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ExternalSystemTaskNotificationListener.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(StdModuleTypes.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(JavaModuleType.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ModuleType.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(EmptyModuleType.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(LanguageLevel.class));
            // add Kotlin runtime
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(Unit.class));
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(KotlinReflectionInternalError.class));
            // External system module jars
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(getClass()));
            // external-system-rt.jar
            ContainerUtil.addIfNotNull(classPath, PathUtil.getJarPathForClass(ExternalSystemException.class));
            ExternalSystemApiUtil.addBundle(params.getClassPath(), "messages.CommonBundle", CommonBundle.class);
            params.getClassPath().addAll(classPath);
            params.setMainClass(MAIN_CLASS_NAME);
            params.getVMParametersList().addParametersString("-Djava.awt.headless=true");
            // It may take a while for external system api to resolve external dependencies. Default RMI timeout
            // is 15 seconds (http://download.oracle.com/javase/6/docs/technotes/guides/rmi/sunrmiproperties.html#connectionTimeout),
            // we don't want to get EOFException because of that.
            params.getVMParametersList().addParametersString("-Dsun.rmi.transport.connectionTimeout=" + String.valueOf(TimeUnit.HOURS.toMillis(1)));
            final String debugPort = System.getProperty(ExternalSystemConstants.EXTERNAL_SYSTEM_REMOTE_COMMUNICATION_MANAGER_DEBUG_PORT);
            if (debugPort != null) {
                params.getVMParametersList().addParametersString("-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=" + debugPort);
            }
            ProjectSystemId externalSystemId = myTargetExternalSystemId.get();
            if (externalSystemId != null) {
                ExternalSystemManager<?, ?, ?, ?, ?> manager = ExternalSystemApiUtil.getManager(externalSystemId);
                if (manager != null) {
                    params.getClassPath().add(PathUtil.getJarPathForClass(manager.getProjectResolverClass()));
                    params.getProgramParametersList().add(manager.getProjectResolverClass().getName());
                    params.getProgramParametersList().add(manager.getTaskManagerClass().getName());
                    manager.enhanceRemoteProcessing(params);
                }
            }
            return params;
        }

        @Override
        @NotNull
        public ExecutionResult execute(@NotNull Executor executor, @NotNull ProgramRunner runner) throws ExecutionException {
            ProcessHandler processHandler = startProcess();
            return new DefaultExecutionResult(processHandler);
        }

        @Override
        @NotNull
        protected OSProcessHandler startProcess() throws ExecutionException {
            SimpleJavaParameters params = createJavaParameters();
            GeneralCommandLine commandLine = params.toCommandLine();
            OSProcessHandler processHandler = new OSProcessHandler(commandLine);
            ProcessTerminatedListener.attach(processHandler);
            return processHandler;
        }
    };
}
Also used : KotlinReflectionInternalError(kotlin.reflect.KotlinReflectionInternalError) DependencyScope(com.intellij.openapi.roots.DependencyScope) DefaultExecutionResult(com.intellij.execution.DefaultExecutionResult) PlaceHolder(com.intellij.ui.PlaceHolder) SimpleJavaParameters(com.intellij.execution.configurations.SimpleJavaParameters) Unit(kotlin.Unit) TimeUnit(java.util.concurrent.TimeUnit) NotNull(org.jetbrains.annotations.NotNull) ProjectBundle(com.intellij.openapi.project.ProjectBundle) StorageUtilKt(com.intellij.configurationStore.StorageUtilKt) EmptyModuleType(com.intellij.openapi.module.EmptyModuleType) ModuleType(com.intellij.openapi.module.ModuleType) JavaModuleType(com.intellij.openapi.module.JavaModuleType) Executor(com.intellij.execution.Executor) ExtensionPointName(com.intellij.openapi.extensions.ExtensionPointName) LanguageLevel(com.intellij.pom.java.LanguageLevel) DebuggerView(com.intellij.debugger.ui.DebuggerView) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) CommandLineState(com.intellij.execution.configurations.CommandLineState) ProgramRunner(com.intellij.execution.runners.ProgramRunner) EmptyModuleType(com.intellij.openapi.module.EmptyModuleType) JavaModuleType(com.intellij.openapi.module.JavaModuleType) StdModuleTypes(com.intellij.openapi.module.StdModuleTypes) ExternalSystemTaskNotificationListener(com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener) PsiBundle(com.intellij.psi.PsiBundle) ExternalSystemException(com.intellij.openapi.externalSystem.model.ExternalSystemException) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) Alarm(com.intellij.util.Alarm) OSProcessHandler(com.intellij.execution.process.OSProcessHandler) ProcessHandler(com.intellij.execution.process.ProcessHandler) SimpleJavaSdkType(com.intellij.openapi.projectRoots.SimpleJavaSdkType) ProjectSystemId(com.intellij.openapi.externalSystem.model.ProjectSystemId) File(java.io.File)

Example 3 with SimpleJavaParameters

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

the class Flexmojos4GenerateConfigTask method runGeneratorServer.

private void runGeneratorServer(MavenProjectsManager mavenProjectsManager, Project project) throws IOException, ExecutionException, MavenProcessCanceledException {
    final SimpleJavaParameters params = new SimpleJavaParameters();
    params.setJdk(new SimpleJavaSdkType().createJdk("tmp", SystemProperties.getJavaHome()));
    final MavenGeneralSettings mavenGeneralSettings = mavenProjectsManager.getGeneralSettings();
    final ParametersList programParametersList = params.getProgramParametersList();
    programParametersList.add(getSettingsFilePath(mavenGeneralSettings.getEffectiveGlobalSettingsIoFile()));
    programParametersList.add(getSettingsFilePath(mavenGeneralSettings.getEffectiveUserSettingsIoFile()));
    programParametersList.add(mavenGeneralSettings.getEffectiveLocalRepository().getAbsolutePath());
    programParametersList.add(mavenGeneralSettings.isWorkOffline() ? "t" : "f");
    //noinspection ConstantConditions
    programParametersList.add(project.getBaseDir().getPath() + "/.idea/flexmojos");
    configureMavenClassPath(mavenGeneralSettings, params.getClassPath());
    final File userVmP = new File(SystemProperties.getUserHome(), "fcg-vmp");
    if (userVmP.exists()) {
        params.getVMParametersList().addParametersString(FileUtil.loadFile(userVmP));
    }
    params.setMainClass("com.intellij.flex.maven.GeneratorServer");
    final GeneralCommandLine commandLine = params.toCommandLine();
    commandLine.setRedirectErrorStream(true);
    LOG.info("Generate Flex Configs Task:" + commandLine.getCommandLineString());
    indicator.checkCanceled();
    process = commandLine.createProcess();
    ApplicationManager.getApplication().executeOnPooledThread(new OutputReader(project));
    //noinspection IOResourceOpenedButNotSafelyClosed
    out = new DataOutputStream(new BufferedOutputStream(process.getOutputStream()));
    writeExplicitProfiles(mavenProjectsManager.getExplicitProfiles().getEnabledProfiles());
    writeWorkspaceMap(myTree.getProjects());
    out.writeUTF(FlexCommonUtils.getPathToBundledJar("flexmojos-idea-configurator.jar"));
    out.writeUTF(getIdeaConfiguratorClassName());
}
Also used : ParametersList(com.intellij.execution.configurations.ParametersList) SimpleJavaParameters(com.intellij.execution.configurations.SimpleJavaParameters) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) SimpleJavaSdkType(com.intellij.openapi.projectRoots.SimpleJavaSdkType) VirtualFile(com.intellij.openapi.vfs.VirtualFile)

Aggregations

SimpleJavaParameters (com.intellij.execution.configurations.SimpleJavaParameters)3 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)2 ParametersList (com.intellij.execution.configurations.ParametersList)2 SimpleJavaSdkType (com.intellij.openapi.projectRoots.SimpleJavaSdkType)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 File (java.io.File)2 StorageUtilKt (com.intellij.configurationStore.StorageUtilKt)1 DebuggerView (com.intellij.debugger.ui.DebuggerView)1 CantRunException (com.intellij.execution.CantRunException)1 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)1 Executor (com.intellij.execution.Executor)1 CommandLineState (com.intellij.execution.configurations.CommandLineState)1 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)1 ProcessHandler (com.intellij.execution.process.ProcessHandler)1 ProgramRunner (com.intellij.execution.runners.ProgramRunner)1 IdeaPluginDescriptor (com.intellij.ide.plugins.IdeaPluginDescriptor)1 ExtensionPointName (com.intellij.openapi.extensions.ExtensionPointName)1 PluginId (com.intellij.openapi.extensions.PluginId)1 ExternalSystemException (com.intellij.openapi.externalSystem.model.ExternalSystemException)1 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)1