com.intellij.openapi.projectRoots.SdkType Java Examples

The following examples show how to use com.intellij.openapi.projectRoots.SdkType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SdkListConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean addSdkNode(final Sdk sdk, final boolean selectInTree) {
  if (!myUiDisposed) {
    MyNode newSdkNode = new MyNode(new SdkConfigurable((SdkImpl)sdk, mySdksModel, TREE_UPDATER, myHistory, true));

    final MyNode groupNode = MasterDetailsComponent.findNodeByObject(myRoot, sdk.getSdkType());
    if (groupNode != null) {
      addNode(newSdkNode, groupNode);
    }
    else {
      final MyNode sdkGroupNode = createSdkGroupNode((SdkType)sdk.getSdkType());

      addNode(sdkGroupNode, myRoot);
      addNode(newSdkNode, sdkGroupNode);
    }

    if (selectInTree) {
      selectNodeInTree(newSdkNode);
    }
    return true;
  }
  return false;
}
 
Example #2
Source File: SdkListConfigurable.java    From consulo with Apache License 2.0 6 votes vote down vote up
public boolean addSdkNode(final Sdk sdk, final boolean selectInTree) {
  if (!myUiDisposed) {
    myContext.getDaemonAnalyzer().queueUpdate(new SdkProjectStructureElement(myContext, sdk));

    MyNode newSdkNode = new MyNode(new SdkConfigurable((SdkImpl)sdk, mySdksModel, TREE_UPDATER, myHistory, myProject));

    final MyNode groupNode = MasterDetailsComponent.findNodeByObject(myRoot, sdk.getSdkType());
    if (groupNode != null) {
      addNode(newSdkNode, groupNode);
    }
    else {
      final MyNode sdkGroupNode = createSdkGroupNode((SdkType)sdk.getSdkType());

      addNode(sdkGroupNode, myRoot);
      addNode(newSdkNode, sdkGroupNode);
    }

    if (selectInTree) {
      selectNodeInTree(newSdkNode);
    }
    return true;
  }
  return false;
}
 
Example #3
Source File: SdkConfigurationUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
private static FileChooserDescriptor createCompositeDescriptor(final SdkType... sdkTypes) {
  FileChooserDescriptor descriptor0 = sdkTypes[0].getHomeChooserDescriptor();
  FileChooserDescriptor descriptor =
    new FileChooserDescriptor(descriptor0.isChooseFiles(), descriptor0.isChooseFolders(), descriptor0.isChooseJars(),
                              descriptor0.isChooseJarsAsFiles(), descriptor0.isChooseJarContents(), descriptor0.isChooseMultiple()) {

      @Override
      public void validateSelectedFiles(final VirtualFile[] files) throws Exception {
        if (files.length > 0) {
          for (SdkType type : sdkTypes) {
            if (type.isValidSdkHome(files[0].getPath())) {
              return;
            }
          }
        }
        String message = files.length > 0 && files[0].isDirectory()
                         ? ProjectBundle.message("sdk.configure.home.invalid.error", sdkTypes[0].getPresentableName())
                         : ProjectBundle.message("sdk.configure.home.file.invalid.error", sdkTypes[0].getPresentableName());
        throw new Exception(message);
      }
    };
  descriptor.setTitle(descriptor0.getTitle());
  return descriptor;
}
 
Example #4
Source File: SdkConfigurationUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
/**
 * Tries to create an SDK identified by path; if successful, add the SDK to the global SDK table.
 *
 * @param path    identifies the SDK
 * @param sdkType
 * @param predefined
 * @return newly created SDK, or null.
 */
@Nullable
public static Sdk createAndAddSDK(final String path, SdkType sdkType, boolean predefined) {
  VirtualFile sdkHome = ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {
    @Override
    public VirtualFile compute() {
      return LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
    }
  });
  if (sdkHome != null) {
    final Sdk newSdk = setupSdk(SdkTable.getInstance().getAllSdks(), sdkHome, sdkType, true, predefined, null, null);
    if (newSdk != null) {
      addSdk(newSdk);
    }
    return newSdk;
  }
  return null;
}
 
Example #5
Source File: SdkConfigurationUtil.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
public static void selectSdkHome(final SdkType sdkType, @Nonnull @RequiredUIAccess final Consumer<String> consumer) {
  final FileChooserDescriptor descriptor = sdkType.getHomeChooserDescriptor();
  if (ApplicationManager.getApplication().isUnitTestMode()) {
    Sdk sdk = SdkTable.getInstance().findMostRecentSdkOfType(sdkType);
    if (sdk == null) throw new RuntimeException("No SDK of type " + sdkType + " found");
    consumer.consume(sdk.getHomePath());
    return;
  }

  FileChooser.chooseFiles(descriptor, null, getSuggestedSdkPath(sdkType)).doWhenDone(virtualFiles -> {
    final String path = virtualFiles[0].getPath();
    if (sdkType.isValidSdkHome(path)) {
      consumer.consume(path);
      return;
    }

    final String adjustedPath = sdkType.adjustSelectedSdkHome(path);
    if (sdkType.isValidSdkHome(adjustedPath)) {
      consumer.consume(adjustedPath);
    }
  });
}
 
Example #6
Source File: BaseSdkCompat.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** #api193: SdkConfigurationUtil changed in 2020.1. */
public static ProjectJdkImpl createSdk(
    Collection<? extends Sdk> allSdks,
    VirtualFile homeDir,
    SdkType sdkType,
    @Nullable SdkAdditionalData additionalData,
    @Nullable String customSdkSuggestedName) {
  return SdkConfigurationUtil.createSdk(
      allSdks.toArray(new Sdk[0]), homeDir, sdkType, additionalData, customSdkSuggestedName);
}
 
Example #7
Source File: DefaultPredefinedBundlesProvider.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void createBundles(@Nonnull Context context) {
  for (SdkType sdkType : SdkType.EP_NAME.getExtensionList()) {
    try {
      if (sdkType.canCreatePredefinedSdks()) {
        Collection<String> paths = sdkType.suggestHomePaths();

        for (String path : paths) {
          path = sdkType.adjustSelectedSdkHome(path);

          if (sdkType.isValidSdkHome(path)) {
            VirtualFile dirPath = LocalFileSystem.getInstance().findFileByPath(path);
            if (dirPath == null) {
              continue;
            }

            String sdkPath = sdkType.sdkPath(dirPath);

            Sdk sdk = context.createSdk(sdkType, sdkPath);
            SdkModificator sdkModificator = sdk.getSdkModificator();
            sdkModificator.setHomePath(sdkPath);
            sdkModificator.setVersionString(sdkType.getVersionString(sdkPath));
            sdkModificator.commitChanges();

            sdkType.setupSdkPaths(sdk);
          }
        }
      }
    }
    catch (Error e) {
      LOG.error(e);
    }
  }
}
 
Example #8
Source File: PredefinedBundlesLoader.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
@Nonnull
public Sdk createSdkWithName(@Nonnull SdkType sdkType, @Nonnull String suggestName) {
  Sdk[] sdks = ArrayUtil.mergeArrayAndCollection(mySdkTable.getAllSdks(), myBundles, Sdk.ARRAY_FACTORY);
  String uniqueSdkName = SdkConfigurationUtil.createUniqueSdkName(suggestName + SdkConfigurationUtil.PREDEFINED_PREFIX, sdks);
  Sdk sdk = mySdkTable.createSdk(uniqueSdkName, sdkType);
  myBundles.add(sdk);
  return sdk;
}
 
Example #9
Source File: SdkUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
public static Image getIcon(@Nullable Sdk sdk) {
  if (sdk == null) {
    return AllIcons.Toolbar.Unknown;
  }
  SdkType sdkType = (SdkType)sdk.getSdkType();
  Image icon = ObjectUtil.notNull(sdkType.getIcon(), AllIcons.Toolbar.Unknown);
  if(sdk.isPredefined()) {
    return ImageEffects.layered(icon, AllIcons.Nodes.Locked);
  }
  else {
    return icon;
  }
}
 
Example #10
Source File: ModuleChunk.java    From consulo with Apache License 2.0 5 votes vote down vote up
public OrderedSet<VirtualFile> getCompilationBootClasspathFiles(SdkType sdkType, final boolean exportedOnly) {
  final Set<Module> modules = getNodes();
  final OrderedSet<VirtualFile> cpFiles = new OrderedSet<VirtualFile>();
  final OrderedSet<VirtualFile> jdkFiles = new OrderedSet<VirtualFile>();
  for (final Module module : modules) {
    Collections.addAll(cpFiles, orderEnumerator(module, exportedOnly, new BeforeSdkOrderEntryCondition(sdkType, module)).getClassesRoots());
    Collections.addAll(jdkFiles, OrderEnumerator.orderEntries(module).sdkOnly().getClassesRoots());
  }
  cpFiles.addAll(jdkFiles);
  return cpFiles;
}
 
Example #11
Source File: ModuleChunk.java    From consulo with Apache License 2.0 5 votes vote down vote up
public OrderedSet<VirtualFile> getCompilationClasspathFiles(SdkType sdkType, final boolean exportedOnly) {
  final Set<Module> modules = getNodes();

  OrderedSet<VirtualFile> cpFiles = new OrderedSet<VirtualFile>();
  for (final Module module : modules) {
    Collections.addAll(cpFiles, orderEnumerator(module, exportedOnly, new AfterSdkOrderEntryCondition(sdkType)).getClassesRoots());
  }
  return cpFiles;
}
 
Example #12
Source File: SdkConfigurationUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nullable
public static VirtualFile getSuggestedSdkPath(SdkType sdkType) {
  Collection<String> paths = sdkType.suggestHomePaths();
  if(paths.isEmpty()) {
    return null;
  }

  for (String path : paths) {
    VirtualFile maybeSdkHomePath = LocalFileSystem.getInstance().findFileByPath(path);
    if(maybeSdkHomePath != null) {
      return maybeSdkHomePath;
    }
  }
  return null;
}
 
Example #13
Source File: OrderEntryAppearanceServiceImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public CellAppearanceEx forSdk(@Nullable final Sdk jdk, final boolean isInComboBox, final boolean selected, final boolean showVersion) {
  if (jdk == null) {
    return SimpleTextCellAppearance.invalid(ProjectBundle.message("unknown.sdk"), AllIcons.Toolbar.Unknown);
  }

  String name = jdk.getName();
  CompositeAppearance appearance = new CompositeAppearance();
  SdkType sdkType = (SdkType)jdk.getSdkType();
  appearance.setIcon(SdkUtil.getIcon(jdk));
  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();
}
 
Example #14
Source File: DocumentationOrderRootTypeUIFactory.java    From consulo with Apache License 2.0 5 votes vote down vote up
private void onSpecifyUrlButtonClicked() {
  final String defaultDocsUrl = mySdk == null ? "" : StringUtil.notNullize(((SdkType)mySdk.getSdkType()).getDefaultDocumentationUrl(mySdk), "");
  VirtualFile virtualFile = Util.showSpecifyJavadocUrlDialog(myComponent, defaultDocsUrl);
  if (virtualFile != null) {
    addElement(virtualFile);
    setModified(true);
    requestDefaultFocus();
    setSelectedRoots(new Object[]{virtualFile});
  }
}
 
Example #15
Source File: BaseSdkCompat.java    From intellij with Apache License 2.0 5 votes vote down vote up
/** #api193: SdkConfigurationUtil changed in 2020.1. */
public static ProjectJdkImpl createSdk(
    Collection<? extends Sdk> allSdks,
    VirtualFile homeDir,
    SdkType sdkType,
    @Nullable SdkAdditionalData additionalData,
    @Nullable String customSdkSuggestedName) {
  return SdkConfigurationUtil.createSdk(
      allSdks, homeDir, sdkType, additionalData, customSdkSuggestedName);
}
 
Example #16
Source File: SdkConfigurationUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
public static String createUniqueSdkName(SdkType type, String home, final Sdk[] sdks) {
  return createUniqueSdkName(type.suggestSdkName(null, home), sdks);
}
 
Example #17
Source File: SdkConfigurable.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
public String getBannerSlogan() {
  return ProjectBundle.message("sdk.banner.text", ((SdkType)mySdk.getSdkType()).getPresentableName(), mySdk.getName());
}
 
Example #18
Source File: SdkConfigurationUtil.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nullable
public static Sdk setupSdk(final Sdk[] allSdks,
                           final VirtualFile homeDir,
                           final SdkType sdkType,
                           final boolean silent,
                           boolean predefined,
                           @Nullable final SdkAdditionalData additionalData,
                           @Nullable final String customSdkSuggestedName) {
  final SdkImpl sdk;
  try {
    String sdkPath = sdkType.sdkPath(homeDir);

    String sdkName = null;
    if (predefined) {
      sdkName = sdkType.getName() + PREDEFINED_PREFIX;
    }
    else {
      sdkName = customSdkSuggestedName == null
                ? createUniqueSdkName(sdkType, sdkPath, allSdks)
                : createUniqueSdkName(customSdkSuggestedName, allSdks);
    }

    sdk = new SdkImpl(SdkTable.getInstance(), sdkName, sdkType);
    sdk.setPredefined(predefined);

    if (additionalData != null) {
      // additional initialization.
      // E.g. some ruby sdks must be initialized before
      // setupSdkPaths() method invocation
      sdk.setSdkAdditionalData(additionalData);
    }

    sdk.setHomePath(sdkPath);
    sdkType.setupSdkPaths((Sdk)sdk);
  }
  catch (Exception e) {
    if (!silent) {
      Messages.showErrorDialog("Error configuring SDK: " +
                               e.getMessage() +
                               ".\nPlease make sure that " +
                               FileUtil.toSystemDependentName(homeDir.getPath()) +
                               " is a valid home path for this SDK type.", "Error Configuring SDK");
    }
    return null;
  }
  return sdk;
}
 
Example #19
Source File: SdkConfigurable.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nullable
@NonNls
public String getHelpTopic() {
  return ((SdkType) mySdk.getSdkType()).getHelpTopic();
}
 
Example #20
Source File: SdkListConfigurable.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
private static MyNode createSdkGroupNode(SdkType key) {
  return new MyNode(new TextConfigurable<>(key, key.getPresentableName(), "", "", key.getGroupIcon()), true);
}
 
Example #21
Source File: PredefinedBundlesLoader.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Override
@Nonnull
public Sdk createSdk(@Nonnull SdkType sdkType, @Nonnull String sdkHome) {
  return createSdkWithName(sdkType, sdkType.suggestSdkName(null, sdkHome));
}
 
Example #22
Source File: OCamlSdkType.java    From reasonml-idea-plugin with MIT License 4 votes vote down vote up
@NotNull
public static SdkType getInstance() {
    return SdkType.findInstance(OCamlSdkType.class);
}
 
Example #23
Source File: BundleBoxBuilder.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
public BundleBoxBuilder withSdkTypeFilterByType(@Nonnull final SdkType sdkType) {
  return withSdkTypeFilterBySet(Collections.singleton(sdkType));
}
 
Example #24
Source File: SandModuleExtension.java    From consulo with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Class<? extends SdkType> getSdkTypeClass() {
  return SandBundleType.class;
}
 
Example #25
Source File: ModuleChunk.java    From consulo with Apache License 2.0 4 votes vote down vote up
public String getCompilationClasspath(SdkType sdkType) {
  final OrderedSet<VirtualFile> cpFiles = getCompilationClasspathFiles(sdkType);
  return convertToStringPath(cpFiles);

}
 
Example #26
Source File: RoboVmProjectComponent.java    From robovm-idea with GNU General Public License v2.0 4 votes vote down vote up
public void initComponent() {
    SdkType.findInstance(org.jetbrains.android.sdk.AndroidSdkType.class);
}
 
Example #27
Source File: Unity3dRootModuleExtension.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Class<? extends SdkType> getSdkTypeClass()
{
	return Unity3dBundleType.class;
}
 
Example #28
Source File: Unity3dChildModuleExtension.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Class<? extends SdkType> getSdkTypeClass()
{
	throw new UnsupportedOperationException("Use root module extension");
}
 
Example #29
Source File: Unity3dScriptModuleExtension.java    From consulo-unity3d with Apache License 2.0 4 votes vote down vote up
@Nonnull
@Override
public Class<? extends SdkType> getSdkTypeClass()
{
	throw new UnsupportedOperationException("Use root module extension");
}
 
Example #30
Source File: CSharpCompilerProvider.java    From consulo-csharp with Apache License 2.0 4 votes vote down vote up
@Nullable
public abstract SdkType getBundleType(@Nonnull DotNetSimpleModuleExtension<?> moduleExtension);