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();
});
}
}
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;
}
}
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);
}
}
}
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());
}
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);
}
Aggregations