use of com.intellij.openapi.projectRoots.impl.ProjectJdkImpl in project intellij-community by JetBrains.
the class JavaModuleFixtureBuilderImpl method initModule.
@Override
protected void initModule(final Module module) {
super.initModule(module);
ModuleRootModificationUtil.updateModel(module, model -> {
LibraryTable libraryTable = model.getModuleLibraryTable();
for (Lib lib : myLibraries) {
Library library = libraryTable.createLibrary(lib.getName());
Library.ModifiableModel libraryModel = library.getModifiableModel();
boolean success = false;
try {
for (OrderRootType rootType : OrderRootType.getAllTypes()) {
for (String root : lib.getRoots(rootType)) {
VirtualFile vRoot = LocalFileSystem.getInstance().refreshAndFindFileByPath(root);
if (vRoot != null && OrderRootType.CLASSES.equals(rootType) && !vRoot.isDirectory()) {
VirtualFile jar = JarFileSystem.getInstance().refreshAndFindFileByPath(root + "!/");
if (jar != null) {
vRoot = jar;
}
}
if (vRoot != null) {
libraryModel.addRoot(vRoot, rootType);
}
}
}
success = true;
} finally {
if (!success) {
Disposer.dispose(libraryModel);
}
}
libraryModel.commit();
}
final Sdk jdk;
if (myJdk != null) {
VfsRootAccess.allowRootAccess(module, myJdk);
jdk = JavaSdk.getInstance().createJdk(module.getName() + "_jdk", myJdk, false);
((ProjectJdkImpl) jdk).setVersionString(StringUtil.notNullize(IdeaTestUtil.getMockJdkVersion(myJdk), "java 1.5"));
} else {
jdk = IdeaTestUtil.getMockJdk17();
}
model.setSdk(new MockJdkWrapper(CompilerConfigurationImpl.getTestsExternalCompilerHome(), jdk));
if (myLanguageLevel != null) {
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(myLanguageLevel);
} else if (myMockJdkLevel == MockJdkLevel.jdk15) {
model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_5);
}
});
for (OrderEntry entry : ModuleRootManager.getInstance(module).getOrderEntries()) {
if (entry instanceof LibraryOrderEntry) {
Library library = ((LibraryOrderEntry) entry).getLibrary();
libraryCreated(library, module);
}
}
}
use of com.intellij.openapi.projectRoots.impl.ProjectJdkImpl in project intellij-community by JetBrains.
the class ProjectJdksConfigurable method createActions.
@Override
@Nullable
protected ArrayList<AnAction> createActions(final boolean fromPopup) {
if (myProjectJdksModel == null) {
return null;
}
final ArrayList<AnAction> actions = new ArrayList<>();
DefaultActionGroup group = new DefaultActionGroup(ProjectBundle.message("add.new.jdk.text"), true);
group.getTemplatePresentation().setIcon(IconUtil.getAddIcon());
myProjectJdksModel.createAddActions(group, myTree, projectJdk -> {
addNode(new MyNode(new JdkConfigurable(((ProjectJdkImpl) projectJdk), myProjectJdksModel, TREE_UPDATER, myHistory, myProject), false), myRoot);
selectNodeInTree(findNodeByObject(myRoot, projectJdk));
});
actions.add(new MyActionGroupWrapper(group));
actions.add(new MyDeleteAction(Conditions.<Object[]>alwaysTrue()));
return actions;
}
use of com.intellij.openapi.projectRoots.impl.ProjectJdkImpl in project intellij-community by JetBrains.
the class JavaTestUtil method getTestJdk.
public static Sdk getTestJdk() {
try {
ProjectJdkImpl jdk = (ProjectJdkImpl) JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk().clone();
jdk.setName(TEST_JDK_NAME);
return jdk;
} catch (CloneNotSupportedException e) {
throw new RuntimeException(e);
}
}
use of com.intellij.openapi.projectRoots.impl.ProjectJdkImpl in project intellij-community by JetBrains.
the class IdeaTestUtil method setTestVersion.
@TestOnly
public static void setTestVersion(@NotNull final JavaSdkVersion testVersion, @NotNull Module module, @NotNull Disposable parentDisposable) {
ModuleRootManager rootManager = ModuleRootManager.getInstance(module);
final Sdk sdk = rootManager.getSdk();
final String oldVersionString = sdk.getVersionString();
((ProjectJdkImpl) sdk).setVersionString(testVersion.getDescription());
assert JavaSdk.getInstance().getVersion(sdk) == testVersion;
Disposer.register(parentDisposable, () -> ((ProjectJdkImpl) sdk).setVersionString(oldVersionString));
}
use of com.intellij.openapi.projectRoots.impl.ProjectJdkImpl in project intellij-community by JetBrains.
the class PyPackageManagerImpl method createVirtualEnv.
@Override
@NotNull
public String createVirtualEnv(@NotNull String destinationDir, boolean useGlobalSite) throws ExecutionException {
final List<String> args = new ArrayList<>();
final Sdk sdk = getSdk();
final LanguageLevel languageLevel = PythonSdkType.getLanguageLevelForSdk(sdk);
final boolean usePyVenv = languageLevel.isAtLeast(LanguageLevel.PYTHON33);
if (usePyVenv) {
args.add("pyvenv");
if (useGlobalSite) {
args.add("--system-site-packages");
}
args.add(destinationDir);
getHelperResult(PACKAGING_TOOL, args, false, true, null);
} else {
if (useGlobalSite) {
args.add("--system-site-packages");
}
args.add(destinationDir);
final boolean pre26 = languageLevel.isOlderThan(LanguageLevel.PYTHON26);
final String name = "virtualenv-" + (pre26 ? VIRTUALENV_PRE_26_VERSION : VIRTUALENV_VERSION);
final String dirName = extractHelper(name + ".tar.gz");
try {
final String fileName = dirName + name + File.separatorChar + "virtualenv.py";
getPythonProcessResult(fileName, args, false, true, dirName + name);
} finally {
FileUtil.delete(new File(dirName));
}
}
final String binary = PythonSdkType.getPythonExecutable(destinationDir);
final String binaryFallback = destinationDir + File.separator + "bin" + File.separator + "python";
final String path = (binary != null) ? binary : binaryFallback;
if (usePyVenv) {
// Still no 'packaging' and 'pysetup3' for Python 3.3rc1, see PEP 405
final VirtualFile binaryFile = LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
if (binaryFile != null) {
final ProjectJdkImpl tmpSdk = new ProjectJdkImpl("", PythonSdkType.getInstance());
tmpSdk.setHomePath(path);
final PyPackageManager manager = PyPackageManager.getInstance(tmpSdk);
manager.installManagement();
}
}
return path;
}
Aggregations