Search in sources :

Example 16 with ProjectJdkImpl

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

the class PythonMockSdk method create.

public static Sdk create(final String version, @NotNull final VirtualFile... additionalRoots) {
    final String mock_path = PythonTestUtil.getTestDataPath() + "/MockSdk" + version + "/";
    String sdkHome = new File(mock_path, "bin/python" + version).getPath();
    SdkType sdkType = PythonSdkType.getInstance();
    final Sdk sdk = new ProjectJdkImpl(MOCK_SDK_NAME + " " + version, sdkType) {

        @Override
        public String getVersionString() {
            return "Python " + version + " Mock SDK";
        }
    };
    final SdkModificator sdkModificator = sdk.getSdkModificator();
    sdkModificator.setHomePath(sdkHome);
    File libPath = new File(mock_path, "Lib");
    if (libPath.exists()) {
        sdkModificator.addRoot(LocalFileSystem.getInstance().refreshAndFindFileByIoFile(libPath), OrderRootType.CLASSES);
    }
    sdkModificator.addRoot(PyUserSkeletonsUtil.getUserSkeletonsDirectory(), OrderRootType.CLASSES);
    final LanguageLevel level = LanguageLevel.fromPythonVersion(version);
    final VirtualFile typeShedDir = PyTypeShed.INSTANCE.getDirectory();
    PyTypeShed.INSTANCE.findRootsForLanguageLevel(level).forEach(path -> {
        final VirtualFile file = typeShedDir.findFileByRelativePath(path);
        if (file != null) {
            sdkModificator.addRoot(file, OrderRootType.CLASSES);
        }
    });
    String mock_stubs_path = mock_path + PythonSdkType.SKELETON_DIR_NAME;
    sdkModificator.addRoot(LocalFileSystem.getInstance().refreshAndFindFileByPath(mock_stubs_path), PythonSdkType.BUILTIN_ROOT_TYPE);
    for (final VirtualFile root : additionalRoots) {
        sdkModificator.addRoot(root, OrderRootType.CLASSES);
    }
    sdkModificator.commitChanges();
    final FileBasedIndex index = FileBasedIndex.getInstance();
    index.requestRebuild(StubUpdatingIndex.INDEX_ID);
    index.requestRebuild(PyModuleNameIndex.NAME);
    return sdk;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PythonSdkType(com.jetbrains.python.sdk.PythonSdkType) SdkType(com.intellij.openapi.projectRoots.SdkType) LanguageLevel(com.jetbrains.python.psi.LanguageLevel) ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) Sdk(com.intellij.openapi.projectRoots.Sdk) SdkModificator(com.intellij.openapi.projectRoots.SdkModificator) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) FileBasedIndex(com.intellij.util.indexing.FileBasedIndex)

Example 17 with ProjectJdkImpl

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

the class PythonSdkConfigurator method configureProject.

public void configureProject(final Project project, @NotNull final VirtualFile baseDir, Ref<Module> moduleRef) {
    // it it a virtualenv?
    final List<VirtualFile> children = VfsUtil.getChildren(baseDir, new VirtualFileFilter() {

        @Override
        public boolean accept(VirtualFile file) {
            return !Project.DIRECTORY_STORE_FOLDER.equals(file.getName());
        }
    });
    if (children.isEmpty())
        return;
    final PythonSdkType sdkType = PythonSdkType.getInstance();
    //find virtualEnv in project directory
    final List<String> candidates = new ArrayList<>();
    if (project == null)
        return;
    final VirtualFile rootDir = project.getBaseDir();
    if (rootDir != null)
        candidates.addAll(VirtualEnvSdkFlavor.findInDirectory(rootDir));
    if (!candidates.isEmpty()) {
        String filePath = candidates.get(0);
        if (StringUtil.startsWithChar(filePath, '~')) {
            final String home = SystemProperties.getUserHome();
            filePath = home + filePath.substring(1);
        }
        final Sdk virtualEnvSdk = SdkConfigurationUtil.createAndAddSDK(filePath, sdkType);
        if (virtualEnvSdk != null) {
            SdkConfigurationUtil.setDirectoryProjectSdk(project, virtualEnvSdk);
            SdkAdditionalData additionalData = virtualEnvSdk.getSdkAdditionalData();
            if (additionalData == null) {
                additionalData = new PythonSdkAdditionalData(PythonSdkFlavor.getFlavor(virtualEnvSdk.getHomePath()));
                ((ProjectJdkImpl) virtualEnvSdk).setSdkAdditionalData(additionalData);
            }
            ((PythonSdkAdditionalData) additionalData).associateWithProject(project);
            return;
        }
        return;
    }
    final Sdk existingSdk = ProjectRootManager.getInstance(project).getProjectSdk();
    // SdkConfigurationUtil does the same
    if (existingSdk != null && existingSdk.getSdkType() == sdkType)
        return;
    final File executableFile = PythonSdkType.findExecutableFile(new File(project.getBasePath(), "bin"), "python");
    if (executableFile != null) {
        final File virtualEnvRoot = PythonSdkType.getVirtualEnvRoot(executableFile.getPath());
        if (virtualEnvRoot != null) {
            // yes, an unknown virtualenv; set it up as SDK
            final Sdk sdk = SdkConfigurationUtil.createAndAddSDK(executableFile.getPath(), sdkType);
            if (sdk != null) {
                SdkConfigurationUtil.setDirectoryProjectSdk(project, sdk);
                return;
            }
        }
    }
    // default
    SdkConfigurationUtil.configureDirectoryProjectSdk(project, new PreferredSdkComparator(), sdkType);
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PreferredSdkComparator(com.jetbrains.python.sdk.PreferredSdkComparator) ArrayList(java.util.ArrayList) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) VirtualFileFilter(com.intellij.openapi.vfs.VirtualFileFilter) PythonSdkType(com.jetbrains.python.sdk.PythonSdkType) Sdk(com.intellij.openapi.projectRoots.Sdk) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) PythonSdkAdditionalData(com.jetbrains.python.sdk.PythonSdkAdditionalData) SdkAdditionalData(com.intellij.openapi.projectRoots.SdkAdditionalData)

Example 18 with ProjectJdkImpl

use of com.intellij.openapi.projectRoots.impl.ProjectJdkImpl in project Perl5-IDEA by Camelcade.

the class Perl5SdkConfigurable method addSdk.

private void addSdk(@NotNull String home) {
    PerlSdkType sdkType = PerlSdkType.INSTANCE;
    String newSdkName = SdkConfigurationUtil.createUniqueSdkName(sdkType, home, Arrays.asList(PerlSdkTable.getInstance().getAllJdks()));
    final ProjectJdkImpl newSdk = new ProjectJdkImpl(newSdkName, sdkType);
    newSdk.setHomePath(home);
    sdkType.setupSdkPaths(newSdk);
    // should we check for version string?
    myChange = true;
    PerlSdkTable.getInstance().addJdk(newSdk);
}
Also used : ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) PerlSdkType(com.perl5.lang.perl.idea.sdk.PerlSdkType)

Example 19 with ProjectJdkImpl

use of com.intellij.openapi.projectRoots.impl.ProjectJdkImpl in project Perl5-IDEA by Camelcade.

the class PerlLightTestCase method setUpLibrary.

protected void setUpLibrary() {
    Application application = ApplicationManager.getApplication();
    application.invokeAndWait(() -> application.runWriteAction(() -> {
        VirtualFile libdir = LocalFileSystem.getInstance().refreshAndFindFileByPath("testData/testlib");
        assert libdir != null;
        PerlProjectManager perlProjectManager = PerlProjectManager.getInstance(getProject());
        perlProjectManager.setProjectSdk(new ProjectJdkImpl("test", PerlSdkType.INSTANCE));
        perlProjectManager.addExternalLibrary(libdir);
        CodeInsightTestFixtureImpl.ensureIndexesUpToDate(getProject());
    }));
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) Application(com.intellij.openapi.application.Application) PerlProjectManager(com.perl5.lang.perl.idea.project.PerlProjectManager)

Example 20 with ProjectJdkImpl

use of com.intellij.openapi.projectRoots.impl.ProjectJdkImpl in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoCodeInsightFixtureTestCase method createMockSdk.

@NotNull
private static Sdk createMockSdk(@NotNull String version) {
    String homePath = new File("testData/mockSdk-" + version + "/").getAbsolutePath();
    GoSdkType sdkType = GoSdkType.getInstance();
    ProjectJdkImpl sdk = new ProjectJdkImpl("Go " + version, sdkType, homePath, version);
    sdkType.setupSdkPaths(sdk);
    sdk.setVersionString(version);
    return sdk;
}
Also used : ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) VirtualFile(com.intellij.openapi.vfs.VirtualFile) PsiFile(com.intellij.psi.PsiFile) File(java.io.File) GoSdkType(com.goide.sdk.GoSdkType) 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