Search in sources :

Example 11 with Sdk

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

the class RunPythonConsoleAction method update.

@Override
public void update(final AnActionEvent e) {
    e.getPresentation().setVisible(true);
    e.getPresentation().setEnabled(false);
    final Project project = e.getData(CommonDataKeys.PROJECT);
    if (project != null) {
        Pair<Sdk, Module> sdkAndModule = PydevConsoleRunner.findPythonSdkAndModule(project, e.getData(LangDataKeys.MODULE));
        if (sdkAndModule.first != null) {
            e.getPresentation().setEnabled(true);
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module)

Example 12 with Sdk

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

the class PydevConsoleRunner method findPythonSdkAndModule.

@NotNull
static Pair<Sdk, Module> findPythonSdkAndModule(@NotNull Project project, @Nullable Module contextModule) {
    Sdk sdk = null;
    Module module = null;
    PyConsoleOptions.PyConsoleSettings settings = PyConsoleOptions.getInstance(project).getPythonConsoleSettings();
    String sdkHome = settings.getSdkHome();
    if (sdkHome != null) {
        sdk = PythonSdkType.findSdkByPath(sdkHome);
        if (settings.getModuleName() != null) {
            module = ModuleManager.getInstance(project).findModuleByName(settings.getModuleName());
        } else {
            module = contextModule;
            if (module == null && ModuleManager.getInstance(project).getModules().length > 0) {
                module = ModuleManager.getInstance(project).getModules()[0];
            }
        }
    }
    if (sdk == null && settings.isUseModuleSdk()) {
        if (contextModule != null) {
            module = contextModule;
        } else if (settings.getModuleName() != null) {
            module = ModuleManager.getInstance(project).findModuleByName(settings.getModuleName());
        }
        if (module != null) {
            if (PythonSdkType.findPythonSdk(module) != null) {
                sdk = PythonSdkType.findPythonSdk(module);
            }
        }
    } else if (contextModule != null) {
        if (module == null) {
            module = contextModule;
        }
        if (sdk == null) {
            sdk = PythonSdkType.findPythonSdk(module);
        }
    }
    if (sdk == null) {
        for (Module m : ModuleManager.getInstance(project).getModules()) {
            if (PythonSdkType.findPythonSdk(m) != null) {
                sdk = PythonSdkType.findPythonSdk(m);
                module = m;
                break;
            }
        }
    }
    if (sdk == null) {
        if (PythonSdkType.getAllSdks().size() > 0) {
            //noinspection UnusedAssignment
            //take any python sdk
            sdk = PythonSdkType.getAllSdks().get(0);
        }
    }
    return Pair.create(sdk, module);
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Example 13 with Sdk

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

the class PyDebugRunner method addSdkRootsToEnv.

private static void addSdkRootsToEnv(@NotNull Project project, @NotNull Map<String, String> environment) {
    final RunManager runManager = RunManager.getInstance(project);
    final RunnerAndConfigurationSettings selectedConfiguration = runManager.getSelectedConfiguration();
    if (selectedConfiguration != null) {
        final RunConfiguration configuration = selectedConfiguration.getConfiguration();
        if (configuration instanceof AbstractPythonRunConfiguration) {
            AbstractPythonRunConfiguration runConfiguration = (AbstractPythonRunConfiguration) configuration;
            final Sdk sdk = runConfiguration.getSdk();
            if (sdk != null) {
                List<String> roots = Lists.newArrayList();
                for (VirtualFile contentRoot : sdk.getSdkModificator().getRoots(OrderRootType.CLASSES)) {
                    roots.add(contentRoot.getPath());
                }
                environment.put(LIBRARY_ROOTS, StringUtil.join(roots, File.pathSeparator));
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) AbstractPythonRunConfiguration(com.jetbrains.python.run.AbstractPythonRunConfiguration) AbstractPythonRunConfiguration(com.jetbrains.python.run.AbstractPythonRunConfiguration) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 14 with Sdk

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

the class PyDebugRunner method createSession.

protected XDebugSession createSession(@NotNull RunProfileState state, @NotNull final ExecutionEnvironment environment) throws ExecutionException {
    FileDocumentManager.getInstance().saveAllDocuments();
    final PythonCommandLineState pyState = (PythonCommandLineState) state;
    Sdk sdk = pyState.getSdk();
    PyDebugSessionFactory sessionCreator = PyDebugSessionFactory.findExtension(sdk);
    if (sessionCreator != null) {
        return sessionCreator.createSession(pyState, environment);
    }
    final ServerSocket serverSocket = PythonCommandLineState.createServerSocket();
    final int serverLocalPort = serverSocket.getLocalPort();
    RunProfile profile = environment.getRunProfile();
    final ExecutionResult result = pyState.execute(environment.getExecutor(), createCommandLinePatchers(environment.getProject(), pyState, profile, serverLocalPort));
    return XDebuggerManager.getInstance(environment.getProject()).startSession(environment, new XDebugProcessStarter() {

        @Override
        @NotNull
        public XDebugProcess start(@NotNull final XDebugSession session) {
            PyDebugProcess pyDebugProcess = createDebugProcess(session, serverSocket, result, pyState);
            createConsoleCommunicationAndSetupActions(environment.getProject(), result, pyDebugProcess, session);
            return pyDebugProcess;
        }
    });
}
Also used : XDebugSession(com.intellij.xdebugger.XDebugSession) XDebugProcess(com.intellij.xdebugger.XDebugProcess) PythonCommandLineState(com.jetbrains.python.run.PythonCommandLineState) ServerSocket(java.net.ServerSocket) NotNull(org.jetbrains.annotations.NotNull) XDebugProcessStarter(com.intellij.xdebugger.XDebugProcessStarter) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 15 with Sdk

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

the class MavenExternalParameters method getJdk.

@NotNull
private static Sdk getJdk(@Nullable Project project, MavenRunnerSettings runnerSettings, boolean isGlobalRunnerSettings) throws ExecutionException {
    String name = runnerSettings.getJreName();
    if (name.equals(MavenRunnerSettings.USE_INTERNAL_JAVA)) {
        return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
    }
    if (name.equals(MavenRunnerSettings.USE_PROJECT_JDK)) {
        if (project != null) {
            Sdk res = ProjectRootManager.getInstance(project).getProjectSdk();
            if (res != null) {
                return res;
            }
            Module[] modules = ModuleManager.getInstance(project).getModules();
            for (Module module : modules) {
                Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
                if (sdk != null && sdk.getSdkType() instanceof JavaSdkType) {
                    return sdk;
                }
            }
        }
        if (project == null) {
            Sdk recent = ProjectJdkTable.getInstance().findMostRecentSdkOfType(JavaSdk.getInstance());
            if (recent != null)
                return recent;
            return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
        }
        throw new ProjectJdkSettingsOpenerExecutionException("Project JDK is not specified. <a href=''>Configure</a>", project);
    }
    if (name.equals(MavenRunnerSettings.USE_JAVA_HOME)) {
        final String javaHome = System.getenv("JAVA_HOME");
        if (StringUtil.isEmptyOrSpaces(javaHome)) {
            throw new ExecutionException(RunnerBundle.message("maven.java.home.undefined"));
        }
        final Sdk jdk = JavaSdk.getInstance().createJdk("", javaHome);
        if (jdk == null) {
            throw new ExecutionException(RunnerBundle.message("maven.java.home.invalid", javaHome));
        }
        return jdk;
    }
    for (Sdk projectJdk : ProjectJdkTable.getInstance().getAllJdks()) {
        if (projectJdk.getName().equals(name)) {
            return projectJdk;
        }
    }
    if (isGlobalRunnerSettings) {
        throw new ExecutionException(RunnerBundle.message("maven.java.not.found.default.config", name));
    } else {
        throw new ExecutionException(RunnerBundle.message("maven.java.not.found", name));
    }
}
Also used : JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

Sdk (com.intellij.openapi.projectRoots.Sdk)437 VirtualFile (com.intellij.openapi.vfs.VirtualFile)105 Module (com.intellij.openapi.module.Module)85 Nullable (org.jetbrains.annotations.Nullable)63 File (java.io.File)56 Project (com.intellij.openapi.project.Project)49 NotNull (org.jetbrains.annotations.NotNull)43 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)37 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)34 ExecutionException (com.intellij.execution.ExecutionException)20 ModifiableFlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.ModifiableFlexBuildConfiguration)19 ArrayList (java.util.ArrayList)18 ProjectJdkTable (com.intellij.openapi.projectRoots.ProjectJdkTable)17 IOException (java.io.IOException)16 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)16 IAndroidTarget (com.android.sdklib.IAndroidTarget)14 JavaSdkType (com.intellij.openapi.projectRoots.JavaSdkType)14 Library (com.intellij.openapi.roots.libraries.Library)14 JavaSdkVersion (com.intellij.openapi.projectRoots.JavaSdkVersion)13 BuildConfigurationNature (com.intellij.flex.model.bc.BuildConfigurationNature)11