Java 类com.intellij.openapi.projectRoots.SdkTable 实例源码

项目:consulo-apache-ant    文件:AntDomProject.java   
@Nullable
public final Sdk getTargetJdk() {
  final XmlTag tag = getXmlTag();
  final PsiFile containingFile = tag.getContainingFile();
  final AntBuildFileImpl buildFile = (AntBuildFileImpl)AntConfigurationBase.getInstance(containingFile.getProject()).getAntBuildFile(containingFile);
  if (buildFile != null) {
    String jdkName = AntBuildFileImpl.CUSTOM_JDK_NAME.get(buildFile.getAllOptions());
    if (jdkName == null || jdkName.length() == 0) {
      jdkName = AntConfigurationImpl.DEFAULT_JDK_NAME.get(buildFile.getAllOptions());
    }
    if (jdkName != null && jdkName.length() > 0) {
      return SdkTable.getInstance().findSdk(jdkName);
    }
  }
  return AntJavaSdkUtil.getBundleSdk();
}
项目:consulo-apache-ant    文件:GlobalAntConfiguration.java   
@NotNull
public Map<AntReference, Sdk> getConfiguredAnts()
{
    List<Sdk> sdksOfType = SdkTable.getInstance().getSdksOfType(AntSdkType.getInstance());
    Map<AntReference, Sdk> map = new LinkedHashMap<AntReference, Sdk>();
    for(Sdk sdk : sdksOfType)
    {
        if(sdk.isPredefined())
        {
            map.put(AntReference.BUNDLED_ANT, sdk);
        }
        else
        {
            map.put(new AntReference.BindedReference(sdk), sdk);
        }
    }
    return map;
}
项目:consulo-javaee    文件:JavaEEConfigurationFactoryImpl.java   
@Override
public void onNewConfigurationCreated(@NotNull RunConfiguration configuration)
{
    super.onNewConfigurationCreated(configuration);

    JavaEEConfigurationImpl javaEEConfiguration = (JavaEEConfigurationImpl) configuration;

    JavaeeServerModel serverModel = (JavaeeServerModel) javaEEConfiguration.getServerModel();

    Sdk sdk = SdkTable.getInstance().findMostRecentSdkOfType(myBundleType);
    if(sdk != null)
    {
        javaEEConfiguration.APPLICATION_SERVER_NAME = sdk.getName();
    }

    serverModel.onNewConfigurationCreated();
}
项目:consulo    文件:LightPlatformTestCase.java   
@RequiredWriteAction
public static synchronized void closeAndDeleteProject() {
  if (ourProject != null) {
    ApplicationManager.getApplication().assertWriteAccessAllowed();
    for (Sdk registeredSdk : ourRegisteredSdks) {
      SdkTable.getInstance().removeSdk(registeredSdk);
    }
    ((ProjectImpl)ourProject).setTemporarilyDisposed(false);
    final VirtualFile projFile = ((ProjectEx)ourProject).getStateStore().getProjectFile();
    final File projectFile = projFile == null ? null : VfsUtilCore.virtualToIoFile(projFile);
    if (!ourProject.isDisposed()) Disposer.dispose(ourProject);

    if (projectFile != null) {
      FileUtil.delete(projectFile);
    }
    ourProject = null;
  }
}
项目:consulo    文件:PredefinedBundlesLoader.java   
@Override
public void initComponent() {
  if (SystemProperties.is("consulo.disable.predefined.bundles")) {
    return;
  }

  Consumer<SdkImpl> consumer = new Consumer<SdkImpl>() {
    @Override
    @RequiredDispatchThread
    public void consume(final SdkImpl sdk) {
      ApplicationManager.getApplication().runWriteAction(() -> {
        sdk.setPredefined(true);
        SdkTable.getInstance().addSdk(sdk);
      });
    }
  };

  for (PredefinedBundlesProvider predefinedBundlesProvider : PredefinedBundlesProvider.EP_NAME.getExtensions()) {
    try {
      predefinedBundlesProvider.createBundles(consumer);
    }
    catch (Throwable e) {
      LOGGER.error(e);
    }
  }
}
项目:consulo    文件:SdkConfigurationUtil.java   
/**
 * 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;
}
项目:consulo    文件:SdkConfigurationUtil.java   
public static void selectSdkHome(final SdkType sdkType, @Nonnull 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), new Consumer<List<VirtualFile>>() {
    @Override
    public void consume(final List<VirtualFile> chosen) {
      final String path = chosen.get(0).getPath();
      if (sdkType.isValidSdkHome(path)) {
        consumer.consume(path);
        return;
      }

      final String adjustedPath = sdkType.adjustSelectedSdkHome(path);
      if (sdkType.isValidSdkHome(adjustedPath)) {
        consumer.consume(adjustedPath);
      }
    }
  });
}
项目:consulo-java    文件:JavaProjectDataService.java   
@Nullable
private static Sdk findJdk(@NotNull JavaSdkVersion version)
{
    JavaSdk javaSdk = JavaSdk.getInstance();
    List<Sdk> javaSdks = SdkTable.getInstance().getSdksOfType(javaSdk);
    Sdk candidate = null;
    for(Sdk sdk : javaSdks)
    {
        JavaSdkVersion v = javaSdk.getVersion(sdk);
        if(v == version)
        {
            return sdk;
        }
        else if(candidate == null && v != null && version.getMaxLanguageLevel().isAtLeast(version.getMaxLanguageLevel()))
        {
            candidate = sdk;
        }
    }
    return candidate;
}
项目:consulo-java    文件:ShortenCommandLineModeCombo.java   
@Nullable
private static String getJdkRoot(JrePathEditor pathEditor, Module module)
{
    if(!pathEditor.isAlternativeJreSelected() && module != null)
    {
        Sdk sdk = ModuleUtilCore.getSdk(module, JavaModuleExtension.class);
        return sdk != null ? sdk.getHomePath() : null;
    }
    String jrePathOrName = pathEditor.getJrePathOrName();
    if(jrePathOrName != null)
    {
        Sdk configuredJdk = SdkTable.getInstance().findSdk(jrePathOrName);
        if(configuredJdk != null)
        {
            return configuredJdk.getHomePath();
        }
        else
        {
            return jrePathOrName;
        }
    }
    return null;
}
项目:consulo-java    文件:JavaParametersUtil.java   
private static Sdk createAlternativeJdk(@NotNull String jreHome) throws CantRunException
{
    final Sdk configuredJdk = SdkTable.getInstance().findSdk(jreHome);
    if(configuredJdk != null)
    {
        return configuredJdk;
    }

    if(!OwnJdkUtil.checkForJre(jreHome))
    {
        throw new CantRunException(JavaExecutionBundle.message("jre.path.is.not.valid.jre.home.error.message", jreHome));
    }

    final JavaSdk javaSdk = JavaSdk.getInstance();
    return javaSdk.createJdk(ObjectUtil.notNull(javaSdk.getVersionString(jreHome), ""), jreHome);
}
项目:consulo-java    文件:DebugProcessImpl.java   
private void checkVirtualMachineVersion(VirtualMachine vm)
{
    final String version = vm.version();
    if("1.4.0".equals(version))
    {
        DebuggerInvocationUtil.swingInvokeLater(myProject, () -> Messages.showMessageDialog(myProject, DebuggerBundle.message("warning.jdk140.unstable"), DebuggerBundle.message("title.jdk140" +
                ".unstable"), Messages.getWarningIcon()));
    }

    if(getSession().getAlternativeJre() == null)
    {
        Sdk runjre = getSession().getRunJre();
        if((runjre == null || runjre.getSdkType() instanceof JavaSdkType) && !versionMatch(runjre, version))
        {
            SdkTable.getInstance().getSdksOfType(JavaSdk.getInstance()).stream().filter(sdk -> versionMatch(sdk, version)).findFirst().ifPresent(sdk ->
            {
                XDebugSessionImpl.NOTIFICATION_GROUP.createNotification(DebuggerBundle.message("message.remote.jre.version.mismatch", version, runjre != null ? runjre.getVersionString() :
                        "unknown", sdk.getName()), MessageType.INFO).notify(myProject);
                getSession().setAlternativeJre(sdk);
            });
        }
    }
}
项目:consulo-nodejs    文件:NodeJSConfigurationBase.java   
@Nullable
@Override
public RunProfileState getState(@NotNull Executor executor, @NotNull final ExecutionEnvironment executionEnvironment) throws ExecutionException
{
    Module module = getConfigurationModule().getModule();
    if(module == null)
    {
        throw new ExecutionException("Module is not set for run configuration");
    }

    Sdk targetSdk;
    if(myUseAlternativeBundle)
    {
        if(StringUtil.isEmpty(myAlternativeBundleName))
        {
            throw new ExecutionException("NodeJS alternative bundle is empty");
        }

        targetSdk = SdkTable.getInstance().findSdk(myAlternativeBundleName);
        if(targetSdk == null)
        {
            throw new ExecutionException("NodeJS alternative bundle '" + myAlternativeBundleName + "' is not found");
        }
    }
    else
    {
        targetSdk = ModuleUtilCore.getSdk(module, NodeJSModuleExtension.class);
        if(targetSdk == null)
        {
            throw new ExecutionException("NodeJS bundle is undefined in module '" + module.getName() + "'");
        }
    }

    return createRunState(module, targetSdk, executor, executionEnvironment);
}
项目:consulo-apache-ant    文件:BuildFilePropertiesPanel.java   
public ExecutionTab(final GlobalAntConfiguration antConfiguration, @NotNull final Project project)
{
    myAntGlobalConfiguration = antConfiguration;
    myAntCommandLine.attachLabel(myAntCmdLineLabel);
    myAntCommandLine.setDialogCaption(AntBundle.message("run.execution.tab.ant.command.line.dialog.title"));
    setLabelFor(myJDKLabel, myJDKs);

    myJDKsController = new ChooseAndEditComboBoxController<Sdk, String>(myJDKs, new Convertor<Sdk, String>()
    {
        @Override
        public String convert(Sdk jdk)
        {
            return jdk != null ? jdk.getName() : "";
        }
    }, String.CASE_INSENSITIVE_ORDER)
    {
        @Override
        public Iterator<Sdk> getAllListItems()
        {
            List<Sdk> sdksOfType = SdkTable.getInstance().getSdksOfType(JavaSdk.getInstance());
            List<Sdk> controller = new ArrayList<Sdk>(sdksOfType);
            controller.add(0, null);
            return controller.iterator();
        }

        @Override
        public Sdk openConfigureDialog(Sdk jdk, JComponent parent)
        {
            SingleSdkEditor editor = new SingleSdkEditor(jdk, myJDKs.getComboBox());
            editor.show();
            return editor.getSelectedSdk();
        }
    };

    UIPropertyBinding.Composite binding = getBinding();
    binding.bindString(myAntCommandLine.getTextField(), AntBuildFileImpl.ANT_COMMAND_LINE_PARAMETERS);
    binding.bindString(myJDKs.getComboBox(), AntBuildFileImpl.CUSTOM_JDK_NAME);
    binding.addBinding(new RunWithAntBinding(myUseDefaultAnt, myUseCastomAnt, myAnts, myAntGlobalConfiguration));
}
项目:consulo    文件:SdkConfigurationUtil.java   
public static void addSdk(@Nonnull final Sdk sdk) {
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      SdkTable.getInstance().addSdk(sdk);
    }
  });
}
项目:consulo    文件:SdkConfigurationUtil.java   
public static void removeSdk(final Sdk sdk) {
  ApplicationManager.getApplication().runWriteAction(new Runnable() {
    @Override
    public void run() {
      SdkTable.getInstance().removeSdk(sdk);
    }
  });
}
项目:consulo-xslt    文件:XsltRunConfiguration.java   
private static synchronized Sdk getDefaultSdk()
{
    if(ourDefaultSdk == null)
    {
        final String jdkHome = SystemProperties.getJavaHome();
        final String versionName = ProjectBundle.message("sdk.java.name.template", SystemProperties.getJavaVersion());
        Sdk sdk = SdkTable.getInstance().createSdk(versionName, new SimpleJavaSdkType());
        SdkModificator modificator = sdk.getSdkModificator();
        modificator.setHomePath(jdkHome);
        modificator.commitChanges();
        ourDefaultSdk = sdk;
    }

    return ourDefaultSdk;
}
项目:consulo-xslt    文件:XsltRunConfiguration.java   
@Nullable
public Sdk getEffectiveJDK()
{
    if(!XsltRunSettingsEditor.ALLOW_CHOOSING_SDK)
    {
        return getDefaultSdk();
    }
    if(myJdkChoice == JdkChoice.JDK)
    {
        return myJdk != null ? SdkTable.getInstance().findSdk(myJdk) : null;
    }
    Sdk jdk = null;
    final Module module = getEffectiveModule();
    if(module != null)
    {
        ModuleRootManager moduleRootManager = ModuleRootManager.getInstance(module);
        ModuleExtension maybeJavaExtension = moduleRootManager.getExtension("java");
        if(maybeJavaExtension instanceof ModuleExtensionWithSdk)
        {
            jdk = ((ModuleExtensionWithSdk) maybeJavaExtension).getSdk();
        }
    }

    // EA-33419
    if(jdk == null || !(jdk.getSdkType() instanceof JavaSdkType))
    {
        return getDefaultSdk();
    }
    return jdk;
}
项目:consulo-javascript    文件:ClientJavaScriptModuleExtension.java   
public ClientJavaScriptModuleExtension(@NotNull String id, @NotNull ModuleRootLayer rootLayer)
{
    super(id, rootLayer);
    myPointer = new ModuleInheritableNamedPointerImpl<Sdk>(rootLayer, id)
    {
        @Nullable
        @Override
        public String getItemNameFromModule(@NotNull Module module)
        {
            ClientJavaScriptModuleExtension extension = ModuleUtilCore.getExtension(module, ClientJavaScriptModuleExtension.class);
            if(extension == null)
            {
                return null;
            }
            return extension.getSdkName();
        }

        @Nullable
        @Override
        public Sdk getItemFromModule(@NotNull Module module)
        {
            ClientJavaScriptModuleExtension extension = ModuleUtilCore.getExtension(module, ClientJavaScriptModuleExtension.class);
            if(extension == null)
            {
                return null;
            }
            return extension.getSdk();
        }

        @NotNull
        @Override
        public NamedPointer<Sdk> getPointer(@NotNull ModuleRootLayer moduleRootLayer, @NotNull String name)
        {
            return ((ModuleRootLayerImpl)moduleRootLayer).getRootModel().getConfigurationAccessor().getSdkPointer(name);
        }
    };

    Sdk sdkByType = SdkTable.getInstance().findPredefinedSdkByType(ClientJavaScriptSdkType.getInstance());
    myPointer.set(null, sdkByType);
}
项目:consulo-java    文件:JavaTestUtil.java   
public static Sdk getTestJdk() {
  SdkTable sdkTable = SdkTable.getInstance();
  for (Sdk sdk : sdkTable.getAllSdks()) {
    if (sdk.isPredefined() && sdk.getSdkType() instanceof JavaSdk) {
      return sdk;
    }
  }
  return null;
}
项目:consulo-java    文件:AlternativeJREPanel.java   
public AlternativeJREPanel() {
  myCbEnabled = new JBCheckBox(ExecutionBundle.message("run.configuration.use.alternate.jre.checkbox"));

  myFieldWithHistory = new TextFieldWithHistory();
  final ArrayList<String> foundJDKs = new ArrayList<String>();
  final Sdk[] allJDKs = SdkTable.getInstance().getAllSdks();
  for (Sdk jdk : allJDKs) {
    foundJDKs.add(jdk.getHomePath());
  }
  myFieldWithHistory.setHistory(foundJDKs);
  myPathField = new ComponentWithBrowseButton<TextFieldWithHistory>(myFieldWithHistory, null);
  myPathField.addBrowseFolderListener(ExecutionBundle.message("run.configuration.select.alternate.jre.label"),
                                      ExecutionBundle.message("run.configuration.select.jre.dir.label"),
                                      null, BrowseFilesListener.SINGLE_DIRECTORY_DESCRIPTOR,
                                      TextComponentAccessor.TEXT_FIELD_WITH_HISTORY_WHOLE_TEXT);

  setLayout(new MigLayout("ins 0, gap 10, fill, flowx"));
  add(myCbEnabled, "shrinkx");
  add(myPathField, "growx, pushx");

  InsertPathAction.addTo(myFieldWithHistory.getTextEditor());

  myCbEnabled.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
      enabledChanged();
    }
  });
  enabledChanged();

  setAnchor(myCbEnabled);

  updateUI();
}
项目:consulo-java    文件:JavaParametersUtil.java   
public static void checkAlternativeJRE(@Nullable String jrePath) throws RuntimeConfigurationWarning
{
    if(StringUtil.isEmptyOrSpaces(jrePath) || SdkTable.getInstance().findSdk(jrePath) == null && !OwnJdkUtil.checkForJre(jrePath))
    {
        throw new RuntimeConfigurationWarning(JavaExecutionBundle.message("jre.path.is.not.valid.jre.home.error.message", jrePath));
    }
}
项目:consulo-java    文件:AlternativeJreClassFinder.java   
@Nullable
public static Sdk getAlternativeJre(RunProfile profile)
{
    if(profile instanceof ConfigurationWithAlternativeJre)
    {
        ConfigurationWithAlternativeJre appConfig = (ConfigurationWithAlternativeJre) profile;
        if(appConfig.isAlternativeJrePathEnabled())
        {
            return SdkTable.getInstance().findSdk(appConfig.getAlternativeJrePath());
        }
    }
    return null;
}
项目:consulo-apache-ant    文件:AntJavaSdkUtil.java   
public static Sdk getBundleSdk()
{
    return SdkTable.getInstance().findPredefinedSdkByType(JavaSdk.getInstance());
}
项目:consulo-apache-ant    文件:GlobalAntConfiguration.java   
@Nullable
public Sdk findBundleAntBundle()
{
    return SdkTable.getInstance().findPredefinedSdkByType(AntSdkType.getInstance());
}
项目:consulo-apache-ant    文件:GlobalAntConfiguration.java   
public static Sdk findJdk(final String jdkName)
{
    return SdkTable.getInstance().findSdk(jdkName);
}
项目:consulo-javaee    文件:JavaEEConfigurationImpl.java   
@Nullable
@Override
public Sdk getServerBundle()
{
    return APPLICATION_SERVER_NAME == null ? null : SdkTable.getInstance().findSdk(APPLICATION_SERVER_NAME);
}
项目:consulo    文件:SdkPointerManagerImpl.java   
@Nullable
@Override
public Sdk findByName(@Nonnull String name) {
  return SdkTable.getInstance().findSdk(name);
}
项目:consulo    文件:PredefinedBundlesProvider.java   
@Nonnull
public SdkImpl createSdkWithName(@Nonnull SdkType sdkType, @Nonnull String suggestName) {
  String uniqueSdkName = SdkConfigurationUtil.createUniqueSdkName(suggestName + SdkConfigurationUtil.PREDEFINED_PREFIX, SdkTable.getInstance().getAllSdks());

  return new SdkImpl(uniqueSdkName, sdkType);
}
项目:consulo-xslt    文件:XsltRunConfiguration.java   
@Nullable
public Sdk getJdk()
{
    return myJdk != null ? SdkTable.getInstance().findSdk(myJdk) : null;
}