Search in sources :

Example 1 with SdkModificator

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

the class PythonSdkUpdater method commitSdkPathsIfChanged.

/**
   * Commits new SDK paths using an SDK modificator if the paths have been changed.
   *
   * You may invoke it from any thread. Blocks until the commit is done in the AWT thread.
   */
private static void commitSdkPathsIfChanged(@NotNull Sdk sdk, @Nullable final SdkModificator sdkModificator, @NotNull final List<VirtualFile> sdkPaths, boolean forceCommit) {
    final String key = PythonSdkType.getSdkKey(sdk);
    final SdkModificator modificatorToGetRoots = sdkModificator != null ? sdkModificator : sdk.getSdkModificator();
    final List<VirtualFile> currentSdkPaths = Arrays.asList(modificatorToGetRoots.getRoots(OrderRootType.CLASSES));
    if (forceCommit || !Sets.newHashSet(sdkPaths).equals(Sets.newHashSet(currentSdkPaths))) {
        TransactionGuard.getInstance().assertWriteSafeContext(ModalityState.defaultModalityState());
        ApplicationManager.getApplication().invokeAndWait(() -> {
            final Sdk sdkInsideInvoke = PythonSdkType.findSdkByKey(key);
            final SdkModificator modificatorToCommit = sdkModificator != null ? sdkModificator : sdkInsideInvoke != null ? sdkInsideInvoke.getSdkModificator() : modificatorToGetRoots;
            modificatorToCommit.removeAllRoots();
            for (VirtualFile sdkPath : sdkPaths) {
                modificatorToCommit.addRoot(PythonSdkType.getSdkRootVirtualFile(sdkPath), OrderRootType.CLASSES);
            }
            modificatorToCommit.commitChanges();
        });
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator)

Example 2 with SdkModificator

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

the class PythonSdkDetailsDialog method addCreatedSdk.

private void addCreatedSdk(@Nullable final Sdk sdk, boolean newVirtualEnv) {
    if (sdk != null) {
        boolean isVirtualEnv = PythonSdkType.isVirtualEnv(sdk);
        if (isVirtualEnv && !newVirtualEnv) {
            AddVEnvOptionsDialog dialog = new AddVEnvOptionsDialog(myMainPanel);
            dialog.show();
            if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
                return;
            }
            SdkModificator modificator = myModificators.get(sdk);
            setSdkAssociated(modificator, !dialog.makeAvailableToAll());
            myModifiedModificators.add(modificator);
        }
        final Sdk oldSdk = myProjectSdksModel.findSdk(sdk);
        if (oldSdk == null) {
            myProjectSdksModel.addSdk(sdk);
        }
        refreshSdkList();
        mySdkList.setSelectedValue(myProjectSdksModel.findSdk(sdk.getName()), true);
        mySdkListChanged = true;
    }
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator)

Example 3 with SdkModificator

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

the class PythonSdkDetailsDialog method editRemoteSdk.

private void editRemoteSdk(Sdk currentSdk) {
    PythonRemoteInterpreterManager remoteInterpreterManager = PythonRemoteInterpreterManager.getInstance();
    if (remoteInterpreterManager != null) {
        final SdkModificator modificator = myModificators.get(currentSdk);
        Set<Sdk> existingSdks = Sets.newHashSet(myProjectSdksModel.getSdks());
        existingSdks.remove(currentSdk);
        if (remoteInterpreterManager.editSdk(myProject, modificator, existingSdks)) {
            myModifiedModificators.add(modificator);
        }
    }
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) PythonRemoteInterpreterManager(com.jetbrains.python.remote.PythonRemoteInterpreterManager)

Example 4 with SdkModificator

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

the class PythonSdkDetailsDialog method apply.

public void apply() throws ConfigurationException {
    if (!myModifiedModificators.isEmpty()) {
        mySdkSettingsWereModified.run();
    }
    for (SdkModificator modificator : myModifiedModificators) {
        /* This should always be true barring bug elsewhere, log error on else? */
        if (modificator.isWritable()) {
            modificator.commitChanges();
        }
    }
    myModificators.clear();
    myModifiedModificators.clear();
    mySdkListChanged = false;
    final Sdk sdk = getSelectedSdk();
    myShowMoreCallback.consume(sdk);
    PyPackageManagers.getInstance().clearCache(sdk);
    Disposer.dispose(getDisposable());
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator)

Example 5 with SdkModificator

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

the class RootsChangedTest method testEditLibraryForModuleLoadFromXml.

public void testEditLibraryForModuleLoadFromXml() throws IOException {
    final File tempDirectory = createTempDirectory();
    ApplicationManager.getApplication().runWriteAction(() -> {
        Module a = loadModule(PathManagerEx.getHomePath(getClass()) + "/java/java-tests/testData/moduleRootManager/rootsChanged/emptyModule/a.iml");
        assertEventsCount(1);
        final Sdk jdk;
        try {
            jdk = (Sdk) IdeaTestUtil.getMockJdk17().clone();
        } catch (CloneNotSupportedException e) {
            throw new RuntimeException(e);
        }
        ProjectJdkTable.getInstance().addJdk(jdk);
        assertEventsCount(0);
        ModuleRootModificationUtil.setModuleSdk(a, jdk);
        assertEventsCount(1);
        final SdkModificator sdkModificator = jdk.getSdkModificator();
        sdkModificator.addRoot(getVirtualFile(tempDirectory), OrderRootType.CLASSES);
        sdkModificator.commitChanges();
    });
    assertEventsCount(1);
}
Also used : Sdk(com.intellij.openapi.projectRoots.Sdk) Module(com.intellij.openapi.module.Module) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Aggregations

SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)51 Sdk (com.intellij.openapi.projectRoots.Sdk)32 VirtualFile (com.intellij.openapi.vfs.VirtualFile)30 File (java.io.File)8 Module (com.intellij.openapi.module.Module)7 IAndroidTarget (com.android.sdklib.IAndroidTarget)6 AndroidSdkAdditionalData (org.jetbrains.android.sdk.AndroidSdkAdditionalData)5 NotNull (org.jetbrains.annotations.NotNull)5 ProjectJdkTable (com.intellij.openapi.projectRoots.ProjectJdkTable)4 Library (com.intellij.openapi.roots.libraries.Library)4 Nullable (org.jetbrains.annotations.Nullable)4 JSTestOptions (com.intellij.lang.javascript.JSTestOptions)3 Project (com.intellij.openapi.project.Project)3 ProjectJdkImpl (com.intellij.openapi.projectRoots.impl.ProjectJdkImpl)3 FirstRunWizardMode (com.android.tools.idea.welcome.config.FirstRunWizardMode)2 FlexSdkType2 (com.intellij.lang.javascript.flex.sdk.FlexSdkType2)2 OrderRoot (com.intellij.openapi.roots.libraries.ui.OrderRoot)2 IOException (java.io.IOException)2 AndroidSdkData (org.jetbrains.android.sdk.AndroidSdkData)2 Contract (org.jetbrains.annotations.Contract)2