Search in sources :

Example 1 with GoSdkType

use of com.goide.sdk.GoSdkType in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoProjectModelConverterProvider method convertSdks.

private static void convertSdks() {
    ProjectJdkTable sdkTable = ProjectJdkTable.getInstance();
    Collection<String> globalGoPathUrls = ContainerUtil.newLinkedHashSet();
    Collection<Sdk> sdksToDelete = ContainerUtil.newArrayList();
    Collection<Sdk> sdksToAdd = ContainerUtil.newArrayList();
    GoSdkType sdkType = GoSdkType.getInstance();
    for (Sdk sdk : sdkTable.getAllJdks()) {
        String sdkTypeName = sdk.getSdkType().getName();
        if (isGoSdkType(sdkTypeName)) {
            sdksToDelete.add(sdk);
            String sdkHome = sdkType.adjustSelectedSdkHome(sdk.getHomePath());
            if (sdkType.isValidSdkHome(sdkHome)) {
                ProjectJdkImpl newSdk = new ProjectJdkImpl(sdk.getName(), sdkType, sdkHome, sdkType.getVersionString(sdkHome));
                sdkType.setupSdkPaths(newSdk);
                sdksToAdd.add(newSdk);
                for (String classesRoot : sdk.getRootProvider().getUrls(OrderRootType.CLASSES)) {
                    if (!classesRoot.equals(sdk.getHomePath())) {
                        globalGoPathUrls.add(classesRoot);
                    }
                }
            }
        }
    }
    for (VirtualFile file : GoSdkUtil.getGoPathsRootsFromEnvironment()) {
        globalGoPathUrls.remove(file.getUrl());
    }
    AccessToken l = WriteAction.start();
    try {
        for (Sdk sdk : sdksToDelete) {
            sdkTable.removeJdk(sdk);
        }
        for (Sdk sdk : sdksToAdd) {
            sdkTable.addJdk(sdk);
        }
        globalGoPathUrls.addAll(GoApplicationLibrariesService.getInstance().getLibraryRootUrls());
        GoApplicationLibrariesService.getInstance().setLibraryRootUrls(globalGoPathUrls);
    } finally {
        l.finish();
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ProjectJdkTable(com.intellij.openapi.projectRoots.ProjectJdkTable) AccessToken(com.intellij.openapi.application.AccessToken) ProjectJdkImpl(com.intellij.openapi.projectRoots.impl.ProjectJdkImpl) Sdk(com.intellij.openapi.projectRoots.Sdk) GoSdkType(com.goide.sdk.GoSdkType)

Example 2 with GoSdkType

use of com.goide.sdk.GoSdkType 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

GoSdkType (com.goide.sdk.GoSdkType)2 ProjectJdkImpl (com.intellij.openapi.projectRoots.impl.ProjectJdkImpl)2 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 AccessToken (com.intellij.openapi.application.AccessToken)1 ProjectJdkTable (com.intellij.openapi.projectRoots.ProjectJdkTable)1 Sdk (com.intellij.openapi.projectRoots.Sdk)1 PsiFile (com.intellij.psi.PsiFile)1 File (java.io.File)1 NotNull (org.jetbrains.annotations.NotNull)1