Search in sources :

Example 11 with ProjectJdkImpl

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);
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) LibraryTable(com.intellij.openapi.roots.libraries.LibraryTable) MockJdkWrapper(com.intellij.openapi.projectRoots.impl.MockJdkWrapper) Library(com.intellij.openapi.roots.libraries.Library) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk)

Example 12 with ProjectJdkImpl

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;
}
Also used : ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) JdkConfigurable(com.intellij.openapi.roots.ui.configuration.projectRoot.JdkConfigurable) AnAction(com.intellij.openapi.actionSystem.AnAction) DefaultActionGroup(com.intellij.openapi.actionSystem.DefaultActionGroup) Nullable(org.jetbrains.annotations.Nullable)

Example 13 with ProjectJdkImpl

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);
    }
}
Also used : ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl)

Example 14 with ProjectJdkImpl

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));
}
Also used : ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) TestOnly(org.jetbrains.annotations.TestOnly)

Example 15 with ProjectJdkImpl

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;
}
Also used : LanguageLevel(com.jetbrains.python.psi.LanguageLevel) ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) Sdk(com.intellij.openapi.projectRoots.Sdk) File(java.io.File) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

ProjectJdkImpl (com.intellij.openapi.projectRoots.impl.ProjectJdkImpl)20 Sdk (com.intellij.openapi.projectRoots.Sdk)10 VirtualFile (com.intellij.openapi.vfs.VirtualFile)6 ProjectJdkTable (com.intellij.openapi.projectRoots.ProjectJdkTable)5 File (java.io.File)5 NotNull (org.jetbrains.annotations.NotNull)5 FlexSdkType2 (com.intellij.lang.javascript.flex.sdk.FlexSdkType2)3 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)3 GoSdkType (com.goide.sdk.GoSdkType)2 SdkAdditionalData (com.intellij.openapi.projectRoots.SdkAdditionalData)2 LanguageLevel (com.jetbrains.python.psi.LanguageLevel)2 PythonSdkAdditionalData (com.jetbrains.python.sdk.PythonSdkAdditionalData)2 PythonSdkType (com.jetbrains.python.sdk.PythonSdkType)2 BuildConfigurationNature (com.intellij.flex.model.bc.BuildConfigurationNature)1 Disposable (com.intellij.openapi.Disposable)1 AnAction (com.intellij.openapi.actionSystem.AnAction)1 DefaultActionGroup (com.intellij.openapi.actionSystem.DefaultActionGroup)1 AccessToken (com.intellij.openapi.application.AccessToken)1 Application (com.intellij.openapi.application.Application)1 JavaSdk (com.intellij.openapi.projectRoots.JavaSdk)1