Search in sources :

Example 1 with SdkType

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

the class SdkConfigurationUtil method findOrCreateSdk.

@Nullable
public static Sdk findOrCreateSdk(@Nullable Comparator<Sdk> comparator, final SdkType... sdkTypes) {
    final Project defaultProject = ProjectManager.getInstance().getDefaultProject();
    final Sdk sdk = ProjectRootManager.getInstance(defaultProject).getProjectSdk();
    if (sdk != null) {
        for (SdkType type : sdkTypes) {
            if (sdk.getSdkType() == type) {
                return sdk;
            }
        }
    }
    for (SdkType type : sdkTypes) {
        List<Sdk> sdks = ProjectJdkTable.getInstance().getSdksOfType(type);
        if (!sdks.isEmpty()) {
            if (comparator != null) {
                Collections.sort(sdks, comparator);
            }
            return sdks.get(0);
        }
    }
    for (SdkType sdkType : sdkTypes) {
        final String suggestedHomePath = sdkType.suggestHomePath();
        if (suggestedHomePath != null && sdkType.isValidSdkHome(suggestedHomePath)) {
            Sdk an_sdk = createAndAddSDK(suggestedHomePath, sdkType);
            if (an_sdk != null)
                return an_sdk;
        }
    }
    return null;
}
Also used : Project(com.intellij.openapi.project.Project) SdkType(com.intellij.openapi.projectRoots.SdkType) Sdk(com.intellij.openapi.projectRoots.Sdk) Nullable(org.jetbrains.annotations.Nullable)

Example 2 with SdkType

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

the class SdkSettingsStep method validate.

@Override
public boolean validate() throws ConfigurationException {
    JdkComboBox.JdkComboBoxItem item = myJdkComboBox.getSelectedItem();
    if (myJdkComboBox.getSelectedJdk() == null && !(item instanceof JdkComboBox.ProjectJdkComboBoxItem) && !(item instanceof JdkComboBox.SuggestedJdkItem)) {
        if (Messages.showDialog(getNoSdkMessage(), IdeBundle.message("title.no.jdk.specified"), new String[] { CommonBundle.getYesButtonText(), CommonBundle.getNoButtonText() }, 1, Messages.getWarningIcon()) != Messages.YES) {
            return false;
        }
    }
    try {
        if (item instanceof JdkComboBox.SuggestedJdkItem) {
            SdkType type = ((JdkComboBox.SuggestedJdkItem) item).getSdkType();
            String path = ((JdkComboBox.SuggestedJdkItem) item).getPath();
            myModel.addSdk(type, path, sdk -> {
                myJdkComboBox.reloadModel(new JdkComboBox.ActualJdkComboBoxItem(sdk), myWizardContext.getProject());
                myJdkComboBox.setSelectedJdk(sdk);
            });
        }
        myModel.apply(null, true);
    } catch (ConfigurationException e) {
        //IDEA-98382 We should allow Next step if user has wrong SDK
        if (Messages.showDialog(e.getMessage() + "/nDo you want to proceed?", e.getTitle(), new String[] { CommonBundle.getYesButtonText(), CommonBundle.getNoButtonText() }, 1, Messages.getWarningIcon()) != Messages.YES) {
            return false;
        }
    }
    return true;
}
Also used : SdkType(com.intellij.openapi.projectRoots.SdkType) ConfigurationException(com.intellij.openapi.options.ConfigurationException) JdkComboBox(com.intellij.openapi.roots.ui.configuration.JdkComboBox)

Example 3 with SdkType

use of com.intellij.openapi.projectRoots.SdkType in project intellij-plugins by JetBrains.

the class LibraryCollector method collect.

/**
   * We don't use BuildConfigurationEntry as source of libraries. If reference to component declared in such build configuration is resolved, so, we register such bc's module
   */
public void collect(Module module) {
    final FlexBuildConfiguration bc = FlexBuildConfigurationManager.getInstance(module).getActiveConfiguration();
    final Sdk sdk = bc.getSdk();
    assert sdk != null;
    final SdkType sdkType;
    try {
        sdkType = (SdkType) sdk.getClass().getMethod("getSdkType").invoke(sdk);
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    final boolean isFlexmojosSdk = sdkType instanceof FlexmojosSdkType;
    if (!isFlexmojosSdk) {
        collectSdkLibraries(bc, sdk);
    } else {
        final String sdkHomePath = sdk.getHomePath();
        LogMessageUtil.LOG.assertTrue(sdkHomePath != null && sdkHomePath.contains("flex"), sdkHomePath + " must be path to maven repo and contains 'flex'");
        flexmojosSdkHomePath = sdkHomePath.substring(0, sdkHomePath.indexOf("flex"));
    }
    flexSdkVersion = sdk.getVersionString();
    assert flexSdkVersion != null;
    if (StringUtil.compareVersionNumbers(flexSdkVersion, "4.5.1") >= 0) {
        flexSdkVersion = "4.6";
    } else {
        flexSdkVersion = flexSdkVersion.substring(0, 3);
    }
    globalCatalogForTests(bc);
    final ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
    for (DependencyEntry entry : bc.getDependencies().getEntries()) {
        if (entry instanceof ModuleLibraryEntry) {
            LibraryOrderEntry orderEntry = FlexProjectRootsUtil.findOrderEntry((ModuleLibraryEntry) entry, moduleRootManager);
            if (orderEntry != null) {
                collectFromLibraryOrderEntry(orderEntry.getRootFiles(OrderRootType.CLASSES));
            }
        } else if (entry instanceof SharedLibraryEntry) {
            com.intellij.openapi.roots.libraries.Library library = FlexProjectRootsUtil.findOrderEntry(module.getProject(), (SharedLibraryEntry) entry);
            if (library != null) {
                collectFromLibraryOrderEntry(library.getFiles(OrderRootType.CLASSES));
            }
        }
    }
    // IDEA-71055
    // todo css-based themes
    final List<String> themes = BCUtils.getThemes(module, bc);
    for (String theme : themes) {
        if (theme.endsWith(DOT_SWC)) {
            final VirtualFile file = LocalFileSystem.getInstance().findFileByPath(theme);
            if (file != null && uniqueGuard.add(file)) {
                final VirtualFile jarFile = JarFileSystem.getInstance().getJarRootForLocalFile(file);
                if (jarFile != null) {
                    addLibrary(jarFile, true);
                }
            }
        }
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) FlexmojosSdkType(com.intellij.lang.javascript.flex.sdk.FlexmojosSdkType) SdkType(com.intellij.openapi.projectRoots.SdkType) ModuleRootManager(com.intellij.openapi.roots.ModuleRootManager) LibraryOrderEntry(com.intellij.openapi.roots.LibraryOrderEntry) Sdk(com.intellij.openapi.projectRoots.Sdk) FlexmojosSdkType(com.intellij.lang.javascript.flex.sdk.FlexmojosSdkType)

Example 4 with SdkType

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

the class OrderEntryAppearanceServiceImpl method forJdk.

@NotNull
@Override
public CellAppearanceEx forJdk(@Nullable final Sdk jdk, final boolean isInComboBox, final boolean selected, final boolean showVersion) {
    if (jdk == null) {
        return FileAppearanceService.getInstance().forInvalidUrl(NO_JDK);
    }
    String name = jdk.getName();
    CompositeAppearance appearance = new CompositeAppearance();
    SdkType sdkType = (SdkType) jdk.getSdkType();
    appearance.setIcon(sdkType.getIcon());
    SimpleTextAttributes attributes = getTextAttributes(sdkType.sdkHasValidPath(jdk), selected);
    CompositeAppearance.DequeEnd ending = appearance.getEnding();
    ending.addText(name, attributes);
    if (showVersion) {
        String versionString = jdk.getVersionString();
        if (versionString != null && !versionString.equals(name)) {
            SimpleTextAttributes textAttributes = isInComboBox && !selected ? SimpleTextAttributes.SYNTHETIC_ATTRIBUTES : SystemInfo.isMac && selected ? new SimpleTextAttributes(SimpleTextAttributes.STYLE_PLAIN, Color.WHITE) : SimpleTextAttributes.GRAY_ATTRIBUTES;
            ending.addComment(versionString, textAttributes);
        }
    }
    return ending.getAppearance();
}
Also used : SdkType(com.intellij.openapi.projectRoots.SdkType) SimpleTextAttributes(com.intellij.ui.SimpleTextAttributes) CompositeAppearance(com.intellij.openapi.roots.ui.util.CompositeAppearance) NotNull(org.jetbrains.annotations.NotNull)

Example 5 with SdkType

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

the class SdkConfigurationUtil method createSdk.

public static void createSdk(@Nullable final Project project, final Sdk[] existingSdks, final NullableConsumer<Sdk> onSdkCreatedCallBack, final boolean createIfExists, final boolean followSymLinks, final SdkType... sdkTypes) {
    if (sdkTypes.length == 0) {
        onSdkCreatedCallBack.consume(null);
        return;
    }
    FileChooserDescriptor descriptor = createCompositeDescriptor(sdkTypes);
    // XXX: Workaround for PY-21787 since the native macOS dialog always follows symlinks
    if (!followSymLinks) {
        descriptor.setForcedToUseIdeaFileChooser(true);
    }
    VirtualFile suggestedDir = getSuggestedSdkRoot(sdkTypes[0]);
    FileChooser.chooseFiles(descriptor, project, suggestedDir, new FileChooser.FileChooserConsumer() {

        @Override
        public void consume(List<VirtualFile> selectedFiles) {
            for (SdkType sdkType : sdkTypes) {
                final String path = selectedFiles.get(0).getPath();
                if (sdkType.isValidSdkHome(path)) {
                    Sdk newSdk = null;
                    if (!createIfExists) {
                        for (Sdk sdk : existingSdks) {
                            if (path.equals(sdk.getHomePath())) {
                                newSdk = sdk;
                                break;
                            }
                        }
                    }
                    if (newSdk == null) {
                        newSdk = setupSdk(existingSdks, selectedFiles.get(0), sdkType, false, null, null);
                    }
                    onSdkCreatedCallBack.consume(newSdk);
                    return;
                }
            }
            onSdkCreatedCallBack.consume(null);
        }

        @Override
        public void cancelled() {
            onSdkCreatedCallBack.consume(null);
        }
    });
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) SdkType(com.intellij.openapi.projectRoots.SdkType) FileChooserDescriptor(com.intellij.openapi.fileChooser.FileChooserDescriptor) FileChooser(com.intellij.openapi.fileChooser.FileChooser) Sdk(com.intellij.openapi.projectRoots.Sdk)

Aggregations

SdkType (com.intellij.openapi.projectRoots.SdkType)7 Sdk (com.intellij.openapi.projectRoots.Sdk)5 VirtualFile (com.intellij.openapi.vfs.VirtualFile)3 FlexmojosSdkType (com.intellij.lang.javascript.flex.sdk.FlexmojosSdkType)1 FileChooser (com.intellij.openapi.fileChooser.FileChooser)1 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)1 ConfigurationException (com.intellij.openapi.options.ConfigurationException)1 Project (com.intellij.openapi.project.Project)1 SdkModificator (com.intellij.openapi.projectRoots.SdkModificator)1 ProjectJdkImpl (com.intellij.openapi.projectRoots.impl.ProjectJdkImpl)1 LibraryOrderEntry (com.intellij.openapi.roots.LibraryOrderEntry)1 ModuleRootManager (com.intellij.openapi.roots.ModuleRootManager)1 JdkComboBox (com.intellij.openapi.roots.ui.configuration.JdkComboBox)1 CompositeAppearance (com.intellij.openapi.roots.ui.util.CompositeAppearance)1 SimpleTextAttributes (com.intellij.ui.SimpleTextAttributes)1 FileBasedIndex (com.intellij.util.indexing.FileBasedIndex)1 LanguageLevel (com.jetbrains.python.psi.LanguageLevel)1 PythonSdkType (com.jetbrains.python.sdk.PythonSdkType)1 File (java.io.File)1 NotNull (org.jetbrains.annotations.NotNull)1