use of com.intellij.openapi.projectRoots.SdkModificator in project intellij-community by JetBrains.
the class PyOptimizeImportsTest method testLibraryRootInsideProject.
// PY-18970
public void testLibraryRootInsideProject() {
final String testName = getTestName(true);
myFixture.copyDirectoryToProject(testName, "");
final VirtualFile libDir = myFixture.findFileInTempDir("lib");
assertNotNull(libDir);
final Sdk sdk = PythonSdkType.findPythonSdk(myFixture.getModule());
assertNotNull(sdk);
WriteAction.run(() -> {
final SdkModificator modificator = sdk.getSdkModificator();
assertNotNull(modificator);
modificator.addRoot(libDir, OrderRootType.CLASSES);
modificator.commitChanges();
});
try {
myFixture.configureByFile("main.py");
OptimizeImportsAction.actionPerformedImpl(DataManager.getInstance().getDataContext(myFixture.getEditor().getContentComponent()));
myFixture.checkResultByFile(testName + "/main.after.py");
} finally {
//noinspection ThrowFromFinallyBlock
WriteAction.run(() -> {
final SdkModificator modificator = sdk.getSdkModificator();
assertNotNull(modificator);
modificator.removeRoot(libDir, OrderRootType.CLASSES);
modificator.commitChanges();
});
}
}
use of com.intellij.openapi.projectRoots.SdkModificator in project kotlin by JetBrains.
the class KotlinAndroidTestCaseBase method createAndroidSdk.
public Sdk createAndroidSdk(String sdkPath, String platformDir) {
Sdk sdk = ProjectJdkTable.getInstance().createSdk("android_test_sdk", AndroidSdkType.getInstance());
SdkModificator sdkModificator = sdk.getSdkModificator();
sdkModificator.setHomePath(sdkPath);
if (platformDir.equals(getDefaultPlatformDir())) {
// Compatibility: the unit tests were using android.jar outside the sdk1.5 install;
// we need to use that one, rather than the real one in sdk1.5, in order for the
// tests to pass. Longer term, we should switch the unit tests over to all using
// a valid SDK.
String androidJarPath = sdkPath + "/../android.jar!/";
androidJar = VirtualFileManager.getInstance().findFileByUrl("jar://" + androidJarPath);
} else {
androidJar = VirtualFileManager.getInstance().findFileByUrl("jar://" + sdkPath + "/platforms/" + platformDir + "/android.jar!/");
}
sdkModificator.addRoot(androidJar, OrderRootType.CLASSES);
VirtualFile resFolder = LocalFileSystem.getInstance().findFileByPath(sdkPath + "/platforms/" + platformDir + "/data/res");
sdkModificator.addRoot(resFolder, OrderRootType.CLASSES);
VirtualFile docsFolder = LocalFileSystem.getInstance().findFileByPath(sdkPath + "/docs/reference");
if (docsFolder != null) {
sdkModificator.addRoot(docsFolder, JavadocOrderRootType.getInstance());
}
AndroidSdkAdditionalData data = new AndroidSdkAdditionalData(sdk);
AndroidSdkData sdkData = AndroidSdkData.getSdkData(sdkPath);
assertNotNull(sdkData);
// TODO: Get rid of this hardcoded version number
IAndroidTarget target = sdkData.findTargetByName("Android 5.0");
if (target == null) {
IAndroidTarget[] targets = sdkData.getTargets();
for (IAndroidTarget t : targets) {
if (t.getLocation().contains(platformDir)) {
target = t;
break;
}
}
if (target == null && targets.length > 0) {
target = targets[targets.length - 1];
}
}
assertNotNull(target);
data.setBuildTarget(target);
sdkModificator.setSdkAdditionalData(data);
sdkModificator.commitChanges();
return sdk;
}
use of com.intellij.openapi.projectRoots.SdkModificator in project intellij-community by JetBrains.
the class PythonSdkDetailsDialog method removeSdk.
private void removeSdk() {
final Sdk currentSdk = getSelectedSdk();
if (currentSdk != null) {
final Sdk sdk = myProjectSdksModel.findSdk(currentSdk);
SdkConfigurationUtil.removeSdk(sdk);
myProjectSdksModel.removeSdk(sdk);
myProjectSdksModel.removeSdk(currentSdk);
if (myModificators.containsKey(currentSdk)) {
SdkModificator modificator = myModificators.get(currentSdk);
myModifiedModificators.remove(modificator);
myModificators.remove(currentSdk);
}
refreshSdkList();
mySdkListChanged = true;
// TODO select initially selected SDK
if (mySdkList.getSelectedIndex() < 0) {
mySdkList.setSelectedIndex(0);
}
}
}
use of com.intellij.openapi.projectRoots.SdkModificator in project intellij-community by JetBrains.
the class PythonSdkDetailsDialog method editSdk.
private void editSdk(final Sdk currentSdk) {
final SdkModificator modificator = myModificators.get(currentSdk);
final EditSdkDialog dialog = new EditSdkDialog(myProject, modificator, s -> {
if (isDuplicateSdkName(s, currentSdk)) {
return PyBundle.message("sdk.details.dialog.error.duplicate.name");
}
return null;
});
if (dialog.showAndGet()) {
mySdkList.repaint();
final boolean pathChanged = !Comparing.equal(currentSdk.getHomePath(), dialog.getHomePath());
if (!modificator.getName().equals(dialog.getName()) || pathChanged || dialog.isAssociateChanged()) {
myModifiedModificators.add(modificator);
modificator.setName(dialog.getName());
modificator.setHomePath(dialog.getHomePath());
if (dialog.isAssociateChanged()) {
setSdkAssociated(modificator, dialog.associateWithProject());
}
if (pathChanged) {
reloadSdk(currentSdk);
}
}
}
}
use of com.intellij.openapi.projectRoots.SdkModificator in project intellij-community by JetBrains.
the class PyTestSdkTools method generateTempSkeletonsOrPackages.
/**
* Adds installed eggs to SDK, generates skeletons (optionally) and associates it with module.
*
* @param sdk sdk to process
* @param addSkeletons add skeletons or only packages
* @param module module to associate with (if provided)
* @throws InvalidSdkException bas sdk
* @throws IOException failed to read eggs
*/
public static void generateTempSkeletonsOrPackages(@NotNull final Sdk sdk, final boolean addSkeletons, @Nullable final Module module) throws InvalidSdkException, IOException {
Project project = null;
if (module != null) {
project = module.getProject();
final Project finalProject = project;
// Associate with module
ModuleRootModificationUtil.setModuleSdk(module, sdk);
EdtTestUtil.runInEdtAndWait(() -> ApplicationManager.getApplication().runWriteAction(() -> ProjectRootManager.getInstance(finalProject).setProjectSdk(sdk)));
}
final SdkModificator modificator = sdk.getSdkModificator();
modificator.removeRoots(OrderRootType.CLASSES);
modificator.setSdkAdditionalData(new PythonSdkAdditionalData(PythonSdkFlavor.getFlavor(sdk)));
for (final String path : PythonSdkType.getSysPathsFromScript(sdk.getHomePath())) {
addTestSdkRoot(modificator, path);
}
if (!addSkeletons) {
EdtTestUtil.runInEdtAndWait(modificator::commitChanges);
return;
}
final String skeletonsPath = PythonSdkType.getSkeletonsPath(PathManager.getSystemPath(), sdk.getHomePath());
addTestSdkRoot(modificator, skeletonsPath);
EdtTestUtil.runInEdtAndWait(modificator::commitChanges);
PySkeletonRefresher.refreshSkeletonsOfSdk(project, null, skeletonsPath, sdk);
}
Aggregations