Search in sources :

Example 11 with SdkAdditionalData

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

the class PythonGenerateProjectCallback method consume.

@Override
public void consume(@Nullable ProjectSettingsStepBase step) {
    if (!(step instanceof ProjectSpecificSettingsStep))
        return;
    final ProjectSpecificSettingsStep settingsStep = (ProjectSpecificSettingsStep) step;
    final DirectoryProjectGenerator generator = settingsStep.getProjectGenerator();
    Sdk sdk = settingsStep.getSdk();
    if (sdk instanceof PyDetectedSdk) {
        sdk = addDetectedSdk(settingsStep, sdk);
    }
    if (generator instanceof PythonProjectGenerator) {
        final BooleanFunction<PythonProjectGenerator> beforeProjectGenerated = ((PythonProjectGenerator) generator).beforeProjectGenerated(sdk);
        if (beforeProjectGenerated != null) {
            final boolean result = beforeProjectGenerated.fun((PythonProjectGenerator) generator);
            if (!result) {
                Messages.showWarningDialog("Project can not be generated", "Error in Project Generation");
                return;
            }
        }
    }
    final Project newProject = generateProject(settingsStep);
    if (generator instanceof PythonProjectGenerator && sdk == null && newProject != null) {
        final PyNewProjectSettings settings = (PyNewProjectSettings) ((PythonProjectGenerator) generator).getProjectSettings();
        ((PythonProjectGenerator) generator).createAndAddVirtualEnv(newProject, settings);
        sdk = settings.getSdk();
    }
    if (newProject != null && generator instanceof PythonProjectGenerator) {
        SdkConfigurationUtil.setDirectoryProjectSdk(newProject, sdk);
        final List<Sdk> sdks = PythonSdkType.getAllSdks();
        for (Sdk s : sdks) {
            final SdkAdditionalData additionalData = s.getSdkAdditionalData();
            if (additionalData instanceof PythonSdkAdditionalData) {
                ((PythonSdkAdditionalData) additionalData).reassociateWithCreatedProject(newProject);
            }
        }
    }
}
Also used : Project(com.intellij.openapi.project.Project) PyNewProjectSettings(com.jetbrains.python.newProject.PyNewProjectSettings) PythonProjectGenerator(com.jetbrains.python.newProject.PythonProjectGenerator) DirectoryProjectGenerator(com.intellij.platform.DirectoryProjectGenerator) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) PyDetectedSdk(com.jetbrains.python.sdk.PyDetectedSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) PyDetectedSdk(com.jetbrains.python.sdk.PyDetectedSdk) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData)

Example 12 with SdkAdditionalData

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

the class PyRemotePackageManagerImpl method getHelperPath.

@Nullable
@Override
protected String getHelperPath(String helper) throws ExecutionException {
    final Sdk sdk = getSdk();
    final SdkAdditionalData sdkData = sdk.getSdkAdditionalData();
    if (sdkData instanceof PyRemoteSdkAdditionalDataBase) {
        final PyRemoteSdkAdditionalDataBase remoteSdkData = (PyRemoteSdkAdditionalDataBase) sdkData;
        try {
            String helpersPath;
            if (CaseCollector.useRemoteCredentials(remoteSdkData)) {
                final RemoteSdkCredentials remoteSdkCredentials = remoteSdkData.getRemoteSdkCredentials(false);
                helpersPath = remoteSdkCredentials.getHelpersPath();
            } else {
                helpersPath = remoteSdkData.getHelpersPath();
            }
            if (!StringUtil.isEmpty(helpersPath)) {
                return new RemoteFile(helpersPath, helper).getPath();
            } else {
                return null;
            }
        } catch (InterruptedException e) {
            LOG.error(e);
        } catch (ExecutionException e) {
            throw analyzeException(e, helper, Collections.<String>emptyList());
        }
    }
    return null;
}
Also used : PyRemoteSdkAdditionalDataBase(com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) RemoteFile(com.intellij.remote.RemoteFile) RemoteSdkAdditionalData(com.intellij.remote.RemoteSdkAdditionalData) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData) RemoteSdkCredentials(com.intellij.remote.RemoteSdkCredentials) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with SdkAdditionalData

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

the class PyRemoteProcessStarter method doStartRemoteProcess.

protected PyRemoteProcessHandlerBase doStartRemoteProcess(@NotNull Sdk sdk, @NotNull final GeneralCommandLine commandLine, @NotNull final PythonRemoteInterpreterManager manager, @Nullable final Project project, @Nullable PyRemotePathMapper pathMapper) throws ExecutionException {
    SdkAdditionalData data = sdk.getSdkAdditionalData();
    assert data instanceof PyRemoteSdkAdditionalDataBase;
    final PyRemoteSdkAdditionalDataBase pyRemoteSdkAdditionalDataBase = (PyRemoteSdkAdditionalDataBase) data;
    final PyRemotePathMapper extendedPathMapper = manager.setupMappings(project, pyRemoteSdkAdditionalDataBase, pathMapper);
    try {
        return PyRemoteProcessStarterManagerUtil.getManager(pyRemoteSdkAdditionalDataBase).startRemoteProcess(project, commandLine, manager, pyRemoteSdkAdditionalDataBase, extendedPathMapper);
    } catch (InterruptedException e) {
        throw new ExecutionException(e);
    }
}
Also used : PyRemotePathMapper(com.jetbrains.python.remote.PyRemotePathMapper) PyRemoteSdkAdditionalDataBase(com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase) ExecutionException(com.intellij.execution.ExecutionException) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData)

Example 14 with SdkAdditionalData

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

the class PyStudyDirectoryProjectGenerator method createAndAddVirtualEnv.

public void createAndAddVirtualEnv(Project project, PyNewProjectSettings settings) {
    final ProjectSdksModel model = PyConfigurableInterpreterList.getInstance(project).getModel();
    final String baseSdk = getBaseSdk(project);
    if (baseSdk != null) {
        final PyPackageManager packageManager = PyPackageManager.getInstance(new PyDetectedSdk(baseSdk));
        try {
            final String path = packageManager.createVirtualEnv(project.getBasePath() + "/.idea/VirtualEnvironment", false);
            AbstractCreateVirtualEnvDialog.setupVirtualEnvSdk(path, true, new AbstractCreateVirtualEnvDialog.VirtualEnvCallback() {

                @Override
                public void virtualEnvCreated(Sdk createdSdk, boolean associateWithProject) {
                    settings.setSdk(createdSdk);
                    model.addSdk(createdSdk);
                    try {
                        model.apply();
                    } catch (ConfigurationException exception) {
                        LOG.error("Error adding created virtual env " + exception.getMessage());
                    }
                    if (associateWithProject) {
                        SdkAdditionalData additionalData = createdSdk.getSdkAdditionalData();
                        if (additionalData == null) {
                            additionalData = new PythonSdkAdditionalData(PythonSdkFlavor.getFlavor(createdSdk.getHomePath()));
                            ((ProjectJdkImpl) createdSdk).setSdkAdditionalData(additionalData);
                        }
                        ((PythonSdkAdditionalData) additionalData).associateWithNewProject();
                    }
                }
            });
        } catch (ExecutionException e) {
            LOG.warn("Failed to create virtual env " + e.getMessage());
        }
    }
}
Also used : ProjectSdksModel(com.intellij.openapi.roots.ui.configuration.projectRoot.ProjectSdksModel) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) AbstractCreateVirtualEnvDialog(com.jetbrains.python.sdk.AbstractCreateVirtualEnvDialog) PyPackageManager(com.jetbrains.python.packaging.PyPackageManager) ConfigurationException(com.intellij.openapi.options.ConfigurationException) PyDetectedSdk(com.jetbrains.python.sdk.PyDetectedSdk) PyDetectedSdk(com.jetbrains.python.sdk.PyDetectedSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData)

Example 15 with SdkAdditionalData

use of com.intellij.openapi.projectRoots.SdkAdditionalData in project intellij-plugins by JetBrains.

the class Flexmojos3ImporterTest method checkFlexmojosSdkClasspath.

private static void checkFlexmojosSdkClasspath(final String sdkVersion, final String[] expectedPaths) {
    final Sdk sdk = ProjectJdkTable.getInstance().findJdk("Flexmojos SDK " + sdkVersion);
    assertNotNull(sdk);
    assertInstanceOf(sdk.getSdkType(), FlexmojosSdkType.class);
    final SdkAdditionalData additionalData = sdk.getSdkAdditionalData();
    assertInstanceOf(additionalData, FlexmojosSdkAdditionalData.class);
    final Collection<String> classpath = ((FlexmojosSdkAdditionalData) additionalData).getFlexCompilerClasspath();
    assertSameElements(classpath, expectedPaths);
}
Also used : FlexmojosSdkAdditionalData(com.intellij.lang.javascript.flex.sdk.FlexmojosSdkAdditionalData) Sdk(com.intellij.openapi.projectRoots.Sdk) FlexmojosSdkAdditionalData(com.intellij.lang.javascript.flex.sdk.FlexmojosSdkAdditionalData) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData)

Aggregations

SdkAdditionalData (com.intellij.openapi.projectRoots.SdkAdditionalData)15 Sdk (com.intellij.openapi.projectRoots.Sdk)11 ExecutionException (com.intellij.execution.ExecutionException)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 PyRemoteSdkAdditionalDataBase (com.jetbrains.python.remote.PyRemoteSdkAdditionalDataBase)4 PythonSdkAdditionalData (com.jetbrains.python.sdk.PythonSdkAdditionalData)4 NotNull (org.jetbrains.annotations.NotNull)4 File (java.io.File)3 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)3 Nullable (org.jetbrains.annotations.Nullable)3 Project (com.intellij.openapi.project.Project)2 ProjectJdkImpl (com.intellij.openapi.projectRoots.impl.ProjectJdkImpl)2 RemoteSdkAdditionalData (com.intellij.remote.RemoteSdkAdditionalData)2 RemoteSdkCredentials (com.intellij.remote.RemoteSdkCredentials)2 PyRemotePathMapper (com.jetbrains.python.remote.PyRemotePathMapper)2 PyDetectedSdk (com.jetbrains.python.sdk.PyDetectedSdk)2 ArrayList (java.util.ArrayList)2 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)2 IAndroidTarget (com.android.sdklib.IAndroidTarget)1 GradleBuildFile (com.android.tools.idea.gradle.parser.GradleBuildFile)1