Search in sources :

Example 1 with SimpleJavaSdkType

use of com.intellij.openapi.projectRoots.SimpleJavaSdkType 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 2 with SimpleJavaSdkType

use of com.intellij.openapi.projectRoots.SimpleJavaSdkType 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)

Example 3 with SimpleJavaSdkType

use of com.intellij.openapi.projectRoots.SimpleJavaSdkType in project intellij-community by JetBrains.

the class GroovyScriptRunConfiguration method createJavaParametersWithSdk.

public static JavaParameters createJavaParametersWithSdk(@Nullable Module module) {
    JavaParameters params = new JavaParameters();
    params.setCharset(null);
    if (module != null) {
        final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
        if (sdk != null && sdk.getSdkType() instanceof JavaSdkType) {
            params.setJdk(sdk);
        }
    }
    if (params.getJdk() == null) {
        params.setJdk(new SimpleJavaSdkType().createJdk("tmp", SystemProperties.getJavaHome()));
    }
    return params;
}
Also used : JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) SimpleJavaSdkType(com.intellij.openapi.projectRoots.SimpleJavaSdkType) SimpleJavaSdkType(com.intellij.openapi.projectRoots.SimpleJavaSdkType) Sdk(com.intellij.openapi.projectRoots.Sdk)

Aggregations

SimpleJavaSdkType (com.intellij.openapi.projectRoots.SimpleJavaSdkType)3 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)2 SimpleJavaParameters (com.intellij.execution.configurations.SimpleJavaParameters)2 StorageUtilKt (com.intellij.configurationStore.StorageUtilKt)1 DebuggerView (com.intellij.debugger.ui.DebuggerView)1 DefaultExecutionResult (com.intellij.execution.DefaultExecutionResult)1 Executor (com.intellij.execution.Executor)1 CommandLineState (com.intellij.execution.configurations.CommandLineState)1 ParametersList (com.intellij.execution.configurations.ParametersList)1 OSProcessHandler (com.intellij.execution.process.OSProcessHandler)1 ProcessHandler (com.intellij.execution.process.ProcessHandler)1 ProgramRunner (com.intellij.execution.runners.ProgramRunner)1 ExtensionPointName (com.intellij.openapi.extensions.ExtensionPointName)1 ExternalSystemException (com.intellij.openapi.externalSystem.model.ExternalSystemException)1 ProjectSystemId (com.intellij.openapi.externalSystem.model.ProjectSystemId)1 ExternalSystemTaskNotificationListener (com.intellij.openapi.externalSystem.model.task.ExternalSystemTaskNotificationListener)1 EmptyModuleType (com.intellij.openapi.module.EmptyModuleType)1 JavaModuleType (com.intellij.openapi.module.JavaModuleType)1 ModuleType (com.intellij.openapi.module.ModuleType)1 StdModuleTypes (com.intellij.openapi.module.StdModuleTypes)1