com.intellij.openapi.projectRoots.Sdk Java Examples

The following examples show how to use com.intellij.openapi.projectRoots.Sdk. 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: SdkUtil.java    From intellij with Apache License 2.0 6 votes vote down vote up
public static boolean containsJarAndRes(Sdk sdk) {
  VirtualFile[] classes = sdk.getRootProvider().getFiles(OrderRootType.CLASSES);
  // A valid sdk must contains path to android.jar and res
  if (classes.length < 2) {
    return false;
  }
  boolean hasJar = false;
  boolean hasRes = false;
  for (VirtualFile file : classes) {
    if (FN_FRAMEWORK_LIBRARY.equals(file.getName())) {
      hasJar = true;
    }
    if (RES_FOLDER.equals(file.getName())) {
      hasRes = true;
    }
  }
  return hasJar && hasRes;
}
 
Example #2
Source File: BlazeJavaSyncPlugin.java    From intellij with Apache License 2.0 6 votes vote down vote up
private static void updateJdk(
    Project project,
    BlazeContext context,
    ProjectViewSet projectViewSet,
    BlazeProjectData blazeProjectData) {

  LanguageLevel javaLanguageLevel =
      JavaLanguageLevelHelper.getJavaLanguageLevel(
          projectViewSet, blazeProjectData, LanguageLevel.JDK_1_8);

  final Sdk sdk = Jdks.chooseOrCreateJavaSdk(javaLanguageLevel);
  if (sdk == null) {
    String msg =
        String.format(
            "Unable to find a JDK %1$s installed.\n", javaLanguageLevel.getPresentableText());
    msg +=
        "After configuring a suitable JDK in the \"Project Structure\" dialog, "
            + "sync the project again.";
    IssueOutput.error(msg).submit(context);
    return;
  }
  setProjectSdkAndLanguageLevel(project, sdk, javaLanguageLevel);
}
 
Example #3
Source File: CamelLightCodeInsightFixtureTestCaseIT.java    From camel-idea-plugin with Apache License 2.0 6 votes vote down vote up
@NotNull
@Override
protected LightProjectDescriptor getProjectDescriptor() {
    LanguageLevel languageLevel = LanguageLevel.JDK_1_8;
    return new DefaultLightProjectDescriptor() {
        @Override
        public Sdk getSdk() {
            String compilerOption = JpsJavaSdkType.complianceOption(languageLevel.toJavaVersion());
            return JavaSdk.getInstance().createJdk( "java " + compilerOption, BUILD_MOCK_JDK_DIRECTORY + compilerOption, false );
        }

        @Override
        public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
            model.getModuleExtension( LanguageLevelModuleExtension.class ).setLanguageLevel( languageLevel );
        }
    };
}
 
Example #4
Source File: PantsProjectComponentImpl.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
private void applyProjectSdk(Project project) {
  Optional<VirtualFile> pantsExecutable = PantsUtil.findPantsExecutable(project);
  if (!pantsExecutable.isPresent()) {
    return;
  }

  Optional<Sdk> sdk = PantsSdkUtil.getDefaultJavaSdk(pantsExecutable.get().getPath(), project);
  if (!sdk.isPresent()) {
    return;
  }

  ApplicationManager.getApplication().runWriteAction(() -> {
    NewProjectUtil.applyJdkToProject(project, sdk.get());
  });

  ApplicationManager.getApplication().executeOnPooledThread(() -> {
    DumbService.getInstance(project).smartInvokeLater(() -> {
      Runnable fix = MagicConstantInspection.getAttachAnnotationsJarFix(project);
      Optional.ofNullable(fix).ifPresent(Runnable::run);
    });
  });
}
 
Example #5
Source File: BaseStructureConfigurableNoDaemon.java    From consulo with Apache License 2.0 6 votes vote down vote up
protected boolean removeObject(final Object editableObject) {
  // todo keep only removeModule() and removeFacet() here because other removeXXX() are empty here and overridden in subclasses? Override removeObject() instead?
  if (editableObject instanceof Sdk) {
    removeSdk((Sdk)editableObject);
  }
  else if (editableObject instanceof Module) {
    if (!removeModule((Module)editableObject)) return false;
  }
  else if (editableObject instanceof Library) {
    if (!removeLibrary((Library)editableObject)) return false;
  }
  else if (editableObject instanceof Artifact) {
    removeArtifact((Artifact)editableObject);
  }
  return true;
}
 
Example #6
Source File: HaxeProjectConfigurationUpdater.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
private List<LibraryData> collectLibraries(Project project) {
  List<HaxeProjectConfigurationUpdater.LibraryData> result = new ArrayList<>();
  Sdk sdk = HaxelibSdkUtils.lookupSdk(project);
  String[] libNames = myLibraries.toArray(new String[0]);
  Set<String> cpList = HaxelibClasspathUtils.getHaxelibLibrariesClasspaths(sdk, libNames);
  for(String cp:cpList) {
    VirtualFile current = LocalFileSystem.getInstance().findFileByPath(cp);
    //"haxelib path" returns something like "/path/to/repo/libname/1,0,0/src"
    //we need to traverse up along this path until we reach a directory which contains haxelib.json
    while(current != null) {
      HaxelibMetadata meta = HaxelibMetadata.load(current);
      if(meta == HaxelibMetadata.EMPTY_METADATA) {
        try {
          current = current.getParent();
        } catch(Exception e) {
          current = null;
        }
      } else {
        result.add(new HaxeProjectConfigurationUpdater.LibraryData(meta.getName(), cp));
        break;
      }
    }
  }
  return result;
}
 
Example #7
Source File: BundleBox.java    From consulo with Apache License 2.0 6 votes vote down vote up
@RequiredUIAccess
@SuppressWarnings("unchecked")
public <T extends MutableModuleExtension<?>> void addModuleExtensionItems(@Nonnull T moduleExtension, @Nonnull Function<T, MutableModuleInheritableNamedPointer<Sdk>> sdkPointerFunction) {
  MutableListModel<BundleBoxItem> listModel = (MutableListModel<BundleBoxItem>)myOriginalComboBox.getListModel();

  for (Module module : ModuleManager.getInstance(moduleExtension.getModule().getProject()).getModules()) {
    // dont add self module
    if (module == moduleExtension.getModule()) {
      continue;
    }

    ModuleExtension extension = ModuleUtilCore.getExtension(module, moduleExtension.getId());
    if (extension == null) {
      continue;
    }
    MutableModuleInheritableNamedPointer<Sdk> sdkPointer = sdkPointerFunction.apply((T)extension);
    if (sdkPointer != null) {
      // recursive depend
      if (sdkPointer.getModule() == moduleExtension.getModule()) {
        continue;
      }

      listModel.add(new ModuleExtensionBundleBoxItem(extension, sdkPointer));
    }
  }
}
 
Example #8
Source File: PantsUtilTest.java    From intellij-pants-plugin with Apache License 2.0 6 votes vote down vote up
public void testFindJdk() {
  final File executable = PantsUtil.findPantsExecutable(getProjectFolder()).get();
  assertEquals(Lists.newArrayList(), getAllJdks().collect(Collectors.toList()));

  final Sdk sdkA = getDefaultJavaSdk(executable.getPath()).get();
  assertEquals(Lists.newArrayList(sdkA), getSameJdks(sdkA));

  final List<Sdk> singleSdkInTable = getSameJdks(sdkA);
  assertTrue(singleSdkInTable.get(0).getName().contains("pants"));

  final List<Sdk> twoEntriesSameSdk = Lists.newArrayList(sdkA, sdkA);
  // manually adding the same jdk to the table should result in two identical
  // entries
  ApplicationManager.getApplication().runWriteAction(() -> {
    // no need to use disposable here, because this should not add a new jdk
    ProjectJdkTable.getInstance().addJdk(sdkA);
  });
  assertEquals(twoEntriesSameSdk, getSameJdks(sdkA));

  // calling getDefaultJavaSdk should only add a new entry to the table if it
  // needs to make one
  final Sdk sdkB = getDefaultJavaSdk(executable.getPath()).get();
  // Make sure they are identical, meaning that no new JDK was created on the 2nd find.
  assertTrue(sdkA == sdkB);
  assertEquals(twoEntriesSameSdk, getSameJdks(sdkA));
}
 
Example #9
Source File: HaxeProjectSdkSetupValidator.java    From intellij-haxe with Apache License 2.0 6 votes vote down vote up
private SdkValidationResult validateSdk(Project project, VirtualFile file) {
  final Module module = ModuleUtilCore.findModuleForFile(file, project);
  if (module != null && !module.isDisposed()) {
    final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
    if (sdk == null) {
      if (ModuleRootManager.getInstance(module).isSdkInherited()) {
        return PROJECT_SDK_NOT_DEFINED;
      }
      else {
        return MODULE_SDK_NOT_DEFINED;
      }
    }
    else {
      return validateSdkRoots(sdk);
    }
  }
  return null;
}
 
Example #10
Source File: ModuleExtensionWithSdkOrderEntryImpl.java    From consulo with Apache License 2.0 6 votes vote down vote up
@Override
@Nonnull
public String getPresentableName() {
  StringBuilder builder = new StringBuilder();

  ModuleExtensionWithSdk<?> moduleExtension = getModuleExtension();
  if (moduleExtension != null) {
    final Sdk sdk = moduleExtension.getSdk();
    if (sdk == null) {
      builder.append(moduleExtension.getSdkName());
    }
    else {
      builder.append(sdk.getName());
    }
  }
  else {
    builder.append(myModuleExtensionId);
  }

  return builder.toString();
}
 
Example #11
Source File: XQueryRunProfileState.java    From intellij-xquery with Apache License 2.0 6 votes vote down vote up
private Sdk getValidJdkToRunModule(final Module module) throws CantRunException {
    Sdk jdk = getJdkToRunModule(module);
    String currentRunningJavaHome = getCurrentRunningJavaHome();
    if (jdk == null) {
        if (currentRunningJavaHome != null) {
            jdk = createAlternativeJdk(currentRunningJavaHome);
        } else {
            throw CantRunException.noJdkForModule(module);
        }
    }
    final VirtualFile homeDirectory = jdk.getHomeDirectory();
    if (homeDirectory == null || !homeDirectory.isValid()) {
        throw CantRunException.jdkMisconfigured(jdk, module);
    }
    return jdk;
}
 
Example #12
Source File: SdkConfigurationUtil.java    From consulo with Apache License 2.0 5 votes vote down vote up
public static String createUniqueSdkName(final String suggestedName, final Sdk[] sdks) {
  final Set<String> names = new HashSet<String>();
  for (Sdk jdk : sdks) {
    names.add(jdk.getName());
  }
  String newSdkName = suggestedName;
  int i = 0;
  while (names.contains(newSdkName)) {
    newSdkName = suggestedName + " (" + (++i) + ")";
  }
  return newSdkName;
}
 
Example #13
Source File: ProjectStructureConfigurable.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Nonnull
@Override
public AsyncResult<Void> select(@Nonnull Sdk sdk, final boolean requestFocus) {
  Place place = createPlaceFor(mySdkListConfigurable);
  place.putPath(BaseStructureConfigurable.TREE_NAME, sdk.getName());
  return navigateTo(place, requestFocus);
}
 
Example #14
Source File: NamedLibraryElementNode.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public void update(PresentationData presentation) {
  presentation.setPresentableText(getValue().getName());
  final OrderEntry orderEntry = getValue().getOrderEntry();

  if (orderEntry instanceof ModuleExtensionWithSdkOrderEntry) {
    final ModuleExtensionWithSdkOrderEntry sdkOrderEntry = (ModuleExtensionWithSdkOrderEntry)orderEntry;
    final Sdk sdk = sdkOrderEntry.getSdk();
    presentation.setIcon(SdkUtil.getIcon(((ModuleExtensionWithSdkOrderEntry)orderEntry).getSdk()));
    if (sdk != null) { //jdk not specified
      final String path = sdk.getHomePath();
      if (path != null) {
        presentation.setLocationString(FileUtil.toSystemDependentName(path));
      }
    }
    presentation.setTooltip(null);
  }
  else if (orderEntry instanceof LibraryOrderEntry) {
    presentation.setIcon(getIconForLibrary(orderEntry));
    presentation.setTooltip(StringUtil.capitalize(IdeBundle.message("node.projectview.library", ((LibraryOrderEntry)orderEntry).getLibraryLevel())));
  }
  else if(orderEntry instanceof OrderEntryWithTracking) {
    Image icon = null;
    CellAppearanceEx cellAppearance = OrderEntryAppearanceService.getInstance().forOrderEntry(orderEntry);
    if(cellAppearance instanceof ModifiableCellAppearanceEx) {
      icon = ((ModifiableCellAppearanceEx)cellAppearance).getIcon();
    }
    presentation.setIcon(icon == null ? AllIcons.Toolbar.Unknown : icon);
  }
}
 
Example #15
Source File: BlazeAndroidSyncPlugin.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
public void updateProjectSdk(
    Project project,
    BlazeContext context,
    ProjectViewSet projectViewSet,
    BlazeVersionData blazeVersionData,
    BlazeProjectData blazeProjectData) {
  if (!isAndroidWorkspace(blazeProjectData.getWorkspaceLanguageSettings())) {
    return;
  }
  AndroidSdkPlatform androidSdkPlatform = null;
  BlazeAndroidSyncData syncData = blazeProjectData.getSyncState().get(BlazeAndroidSyncData.class);
  if (syncData != null) {
    androidSdkPlatform = syncData.androidSdkPlatform;
  } else if (ProjectRootManagerEx.getInstanceEx(project).getProjectSdk() == null) {
    // If syncData is null then this could have been a directory only sync.  In this case,
    // calculate
    // the androidSdkPlatform directly from project view if the project SDK is not yet set.
    // This ensures the android SDK is available even if the initial project sync fails or simply
    // takes too long.
    androidSdkPlatform = AndroidSdkFromProjectView.getAndroidSdkPlatform(context, projectViewSet);
  }
  if (androidSdkPlatform == null) {
    return;
  }
  Sdk sdk = BlazeSdkProvider.getInstance().findSdk(androidSdkPlatform.androidSdk);
  if (sdk == null) {
    IssueOutput.error(
            String.format("Android platform '%s' not found.", androidSdkPlatform.androidSdk))
        .submit(context);
    return;
  }

  LanguageLevel javaLanguageLevel =
      JavaLanguageLevelHelper.getJavaLanguageLevel(
          projectViewSet, blazeProjectData, LanguageLevel.JDK_1_8);
  setProjectSdkAndLanguageLevel(project, sdk, javaLanguageLevel);
}
 
Example #16
Source File: Unity3dProjectImportUtil.java    From consulo-unity3d with Apache License 2.0 5 votes vote down vote up
private static Module createAssemblyCSharpModuleFirstPass(Project project,
														  ModifiableModuleModel newModel,
														  Sdk unityBundle,
														  MultiMap<Module, VirtualFile> virtualFilesByModule,
														  ProgressIndicator progressIndicator,
														  UnityProjectImportContext context)
{
	return createAndSetupModule("Assembly-CSharp-firstpass", project, newModel, FIRST_PASS_PATHS, unityBundle, null, "unity3d-csharp-child", CSharpFileType.INSTANCE, virtualFilesByModule,
			progressIndicator, context);
}
 
Example #17
Source File: BaseStructureConfigurableNoDaemon.java    From consulo with Apache License 2.0 5 votes vote down vote up
private static boolean canObjectBeRemoved(Object editableObject) {
  if (editableObject instanceof Sdk || editableObject instanceof Module || editableObject instanceof Artifact) {
    return true;
  }
  if (editableObject instanceof Library) {
    final LibraryTable table = ((Library)editableObject).getTable();
    return table == null || table.isEditable();
  }
  return false;
}
 
Example #18
Source File: RoboVmPlugin.java    From robovm-idea with GNU General Public License v2.0 5 votes vote down vote up
public static File getBestAndroidSdkDir() {
    Sdk bestSdk = null;
    for (Sdk sdk : ProjectJdkTable.getInstance().getAllJdks()) {
        if (sdk.getSdkType().getName().equals("Android SDK")) {
            if(sdk.getHomePath().contains("/Library/RoboVM/")) {
                return new File(sdk.getHomePath());
            } else {
                bestSdk = sdk;
            }
        }
    }
    return new File(bestSdk.getHomePath());
}
 
Example #19
Source File: CppCompiler.java    From CppTools with Apache License 2.0 5 votes vote down vote up
public boolean validateConfiguration(CompileScope compileScope) {
  EnvironmentFacade facade = EnvironmentFacade.getInstance();

  for(Module module:compileScope.getAffectedModules()) {
    if (ModuleType.get(module) == CppModuleType.getInstance()) {
      Sdk sdk = ModuleRootManager.getInstance(module).getSdk();

      if (!(sdk.getSdkType() == CppSdkType.getInstance())) {
        Messages.showMessageDialog(module.getProject(), "C/Cpp module type is not configured", "C/C++ compiler problem", Messages.getErrorIcon());
        return false;
      }
    }
  }
  return true;
}
 
Example #20
Source File: OCamlModuleWizardStep.java    From reasonml-idea-plugin with MIT License 5 votes vote down vote up
public boolean validate() {
    Sdk odk = c_sdk.getSelectedJdk();
    if (odk == null && !ApplicationManager.getApplication().isUnitTestMode()) {
        int result = Messages.showOkCancelDialog(
                "Do you want to create a project with no SDK assigned?\\nAn SDK is required for compiling as well as for the standard SDK modules resolution and type inference.",
                IdeBundle.message("title.no.jdk.specified"), Messages.OK_BUTTON, Messages.CANCEL_BUTTON, Messages.getWarningIcon());
        return result == Messages.OK;
    }
    return true;
}
 
Example #21
Source File: BlazePyRunConfigurationRunner.java    From intellij with Apache License 2.0 5 votes vote down vote up
private static TextConsoleBuilder createConsoleBuilder(Project project, Sdk sdk) {
  return new PyDebugConsoleBuilder(project, sdk) {
    @Override
    protected ConsoleView createConsole() {
      PythonDebugLanguageConsoleView consoleView =
          new PythonDebugLanguageConsoleView(project, sdk);
      for (Filter filter : getFilters()) {
        consoleView.addMessageFilter(filter);
      }
      return consoleView;
    }
  };
}
 
Example #22
Source File: MockBlazeSdkProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Override
@Nullable
public String getSdkTargetHash(Sdk sdk) {
  return sdks.entrySet()
      .stream()
      .filter(entry -> entry.getValue() == sdk)
      .map(Entry::getKey)
      .findFirst()
      .orElse(null);
}
 
Example #23
Source File: LombokTestUtil.java    From lombok-intellij-plugin with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
public static LightProjectDescriptor getProjectDescriptor() {
  return new DefaultLightProjectDescriptor() {
    @Override
    public Sdk getSdk() {
      return JavaSdk.getInstance().createJdk("java 1.8", "lib/mockJDK-1.8", false);
    }

    @Override
    public void configureModule(@NotNull Module module, @NotNull ModifiableRootModel model, @NotNull ContentEntry contentEntry) {
      model.getModuleExtension(LanguageLevelModuleExtension.class).setLanguageLevel(LanguageLevel.JDK_1_8);
    }
  };
}
 
Example #24
Source File: HaxelibProjectUpdater.java    From intellij-haxe with Apache License 2.0 5 votes vote down vote up
/**
 * Removes old unneeded libraries and adds new dependencies to the project classpath.
 * Queues an update to the Project.
 *
 * @param tracker for the project being updated.
 */
@NotNull
private void syncProjectClasspath(@NotNull ProjectTracker tracker) {
  Sdk sdk = HaxelibSdkUtils.lookupSdk(tracker.getProject());
  boolean isHaxeSDK = sdk.getSdkType().equals(HaxeSdkType.getInstance());

  if (!isHaxeSDK) {
    return;
  }

  HaxeDebugTimeLog timeLog = new HaxeDebugTimeLog("syncProjectClasspath");
  timeLog.stamp("Start synchronizing project " + tracker.getProject().getName());

  HaxeLibraryList toAdd = new HaxeLibraryList(sdk);
  HaxeLibraryList toRemove = new HaxeLibraryList(sdk);
  syncLibraryLists(sdk,
                   HaxelibUtil.getProjectLibraries(tracker.getProject(),false, false),
                   new HaxeLibraryList(sdk),
      /*modifies*/ toAdd,
      /*modifies*/ toRemove );

  if (!toAdd.isEmpty() && !toRemove.isEmpty()) {
    timeLog.stamp("Add/Remove calculations finished.  Queuing write task.");
    updateProject(tracker, toRemove, toAdd);
  }

  timeLog.stamp("Finished synchronizing.");
  timeLog.print();

  // And update the cache.
  tracker.getCache().setPropertiesList(HaxelibUtil.getProjectLibraries(tracker.getProject(), false, false));
}
 
Example #25
Source File: PantsSdkUtil.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
private static void updateJdk(Sdk original, Sdk modified) {
  ApplicationManager.getApplication().invokeAndWait(() -> {
    ApplicationManager.getApplication().runWriteAction(() -> {
      ProjectJdkTable.getInstance().updateJdk(original, modified);
    });
  });
}
 
Example #26
Source File: AndroidModuleLibraryManager.java    From flutter-intellij with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
private void addAndroidLibraryDependencies(@NotNull Project androidProject,
                                           @NotNull Module androidModule,
                                           @NotNull Module flutterModule) {
  AndroidSdkUtils.setupAndroidPlatformIfNecessary(androidModule, true);
  Sdk currentSdk = ModuleRootManager.getInstance(androidModule).getSdk();
  if (currentSdk != null) {
    // TODO(messick) Add sdk dependency on currentSdk if not already set
  }
  LibraryTable androidProjectLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(androidProject);
  Library[] androidProjectLibraries = androidProjectLibraryTable.getLibraries();
  LibraryTable flutterProjectLibraryTable = LibraryTablesRegistrar.getInstance().getLibraryTable(getProject());
  Library[] flutterProjectLibraries = flutterProjectLibraryTable.getLibraries();
  Set<String> knownLibraryNames = new HashSet<>(flutterProjectLibraries.length);
  for (Library lib : flutterProjectLibraries) {
    if (lib.getName() != null) {
      knownLibraryNames.add(lib.getName());
    }
  }
  for (Library library : androidProjectLibraries) {
    if (library.getName() != null && !knownLibraryNames.contains(library.getName())) {

      List<String> roots = Arrays.asList(library.getRootProvider().getUrls(OrderRootType.CLASSES));
      Set<String> filteredRoots = roots.stream().filter(s -> shouldIncludeRoot(s)).collect(Collectors.toSet());
      if (filteredRoots.isEmpty()) continue;

      HashSet<String> sources = new HashSet<>(Arrays.asList(library.getRootProvider().getUrls(OrderRootType.SOURCES)));

      updateLibraryContent(library.getName(), filteredRoots, sources);
      updateAndroidModuleLibraryDependencies(flutterModule);
    }
  }
}
 
Example #27
Source File: ModuleChunk.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean value(OrderEntry orderEntry) {
  if (orderEntry instanceof ModuleExtensionWithSdkOrderEntry) {
    final Sdk sdk = ((ModuleExtensionWithSdkOrderEntry)orderEntry).getSdk();
    if(sdk == null || sdk.getSdkType() != mySdkType) {
      return true;
    }

    mySdkFound = true;
    return false;
  }
  return mySdkFound;
}
 
Example #28
Source File: PyIssueParserProvider.java    From intellij with Apache License 2.0 5 votes vote down vote up
@Nullable
private static PsiFile findFileFromName(Project project, String fileName) {
  GlobalSearchScope projectScope = GlobalSearchScope.projectScope(project);
  Sdk sdk = PySdkUtils.getPythonSdk(project);
  return Arrays.stream(
          FilenameIndex.getFilesByName(project, fileName, GlobalSearchScope.allScope(project)))
      .min(Comparator.comparingInt((psi) -> rankResult(psi, projectScope, sdk)))
      .orElse(null);
}
 
Example #29
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 #30
Source File: PantsUtil.java    From intellij-pants-plugin with Apache License 2.0 5 votes vote down vote up
/**
 * @return Path to IDEA Project JDK if exists, else null
 */
@Nullable
public static String getJdkPathFromIntelliJCore() {
  // Followed example in com.twitter.intellij.pants.testFramework.PantsIntegrationTestCase.setUpInWriteAction()
  final Sdk sdk = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
  String javaHome = null;
  if (sdk.getHomeDirectory() != null) {
    javaHome = sdk.getHomeDirectory().getParent().getPath();
  }
  return javaHome;
}