Java 类com.intellij.openapi.projectRoots.impl.SdkConfigurationUtil 实例源码

项目:educational-plugin    文件:PyStudyDirectoryProjectGenerator.java   
private static Sdk addDetectedSdk(@NotNull Sdk sdk, @NotNull Project project) {
  final ProjectSdksModel model = PyConfigurableInterpreterList.getInstance(project).getModel();
  final String name = sdk.getName();
  VirtualFile sdkHome = WriteAction.compute(() -> LocalFileSystem.getInstance().refreshAndFindFileByPath(name));
  sdk = SdkConfigurationUtil.createAndAddSDK(sdkHome.getPath(), PythonSdkType.getInstance());
  if (sdk != null) {
    PythonSdkUpdater.updateOrShowError(sdk, null, project, null);
  }

  model.addSdk(sdk);
  try {
    model.apply();
  }
  catch (ConfigurationException exception) {
    LOG.error("Error adding detected python interpreter " + exception.getMessage());
  }
  return sdk;
}
项目:intellij-ce-playground    文件:ProjectSdksModel.java   
public void doAdd(JComponent parent, final SdkType type, final Consumer<Sdk> callback) {
  myModified = true;
  if (type.supportsCustomCreateUI()) {
    type.showCustomCreateUI(this, parent, new Consumer<Sdk>() {
      @Override
      public void consume(Sdk sdk) {
        setupSdk(sdk, callback);
      }
    });
  }
  else {
    SdkConfigurationUtil.selectSdkHome(type, new Consumer<String>() {
      @Override
      public void consume(final String home) {
        String newSdkName = SdkConfigurationUtil.createUniqueSdkName(type, home, myProjectSdks.values());
        final ProjectJdkImpl newJdk = new ProjectJdkImpl(newSdkName, type);
        newJdk.setHomePath(home);
        setupSdk(newJdk, callback);
      }
    });
  }
}
项目:intellij-ce-playground    文件:PyConfigurableInterpreterList.java   
private void addDetectedSdks(@NotNull final List<Sdk> result) {
  final PySdkService sdkService = PySdkService.getInstance();
  final List<String> sdkHomes = new ArrayList<String>();
  sdkHomes.addAll(VirtualEnvSdkFlavor.INSTANCE.suggestHomePaths());
  for (PythonSdkFlavor flavor : PythonSdkFlavor.getApplicableFlavors()) {
    if (flavor instanceof VirtualEnvSdkFlavor) continue;
    sdkHomes.addAll(flavor.suggestHomePaths());
  }
  Collections.sort(sdkHomes);
  sdkHomes.addAll(sdkService.getAddedSdks());
  for (String sdkHome : SdkConfigurationUtil.filterExistingPaths(PythonSdkType.getInstance(), sdkHomes, getModel().getSdks())) {
    result.add(new PyDetectedSdk(sdkHome));
  }
  Iterables.removeIf(result, new Predicate<Sdk>() {
    @Override
    public boolean apply(@Nullable Sdk input) {
      return input != null && sdkService.isRemoved(input);
    }
  });
}
项目:intellij-ce-playground    文件:AndroidTestCaseHelper.java   
@NotNull
public static Sdk createAndSetJdk(@NotNull final Project project) {
  String[] names = {"JAVA6_HOME", "JAVA_HOME"};
  String jdkHomePath = AndroidTestCaseHelper.getSystemPropertyOrEnvironmentVariable(names);
  assertNotNull("Please set one of the following env vars (or system properties) to point to the JDK: " + Joiner.on(",").join(names),
                jdkHomePath);
  final Sdk jdk = SdkConfigurationUtil.createAndAddSDK(jdkHomePath, JavaSdk.getInstance());
  assertNotNull(jdk);

  ExternalSystemApiUtil.executeProjectChangeAction(true, new DisposeAwareProjectChange(project) {
    @Override
    public void execute() {
      NewProjectUtil.applyJdkToProject(project, jdk);
    }
  });
  return jdk;
}
项目:intellij-ce-playground    文件:GradleImportingTestCase.java   
@Override
public void setUp() throws Exception {
  myJdkHome = IdeaTestUtil.requireRealJdkHome();
  super.setUp();
  assumeThat(gradleVersion, versionMatcherRule.getMatcher());
  new WriteAction() {
    @Override
    protected void run(@NotNull Result result) throws Throwable {
      Sdk oldJdk = ProjectJdkTable.getInstance().findJdk(GRADLE_JDK_NAME);
      if (oldJdk != null) {
        ProjectJdkTable.getInstance().removeJdk(oldJdk);
      }
      VirtualFile jdkHomeDir = LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(myJdkHome));
      Sdk jdk = SdkConfigurationUtil.setupSdk(new Sdk[0], jdkHomeDir, JavaSdk.getInstance(), true, null, GRADLE_JDK_NAME);
      assertNotNull("Cannot create JDK for " + myJdkHome, jdk);
      ProjectJdkTable.getInstance().addJdk(jdk);
    }
  }.execute();
  myProjectSettings = new GradleProjectSettings();
  GradleSettings.getInstance(myProject).setGradleVmOptions("-Xmx64m -XX:MaxPermSize=64m");
  System.setProperty(ExternalSystemExecutionSettings.REMOTE_PROCESS_IDLE_TTL_IN_MS_KEY, String.valueOf(GRADLE_DAEMON_TTL_MS));
  configureWrapper();
}
项目:intellij-ce-playground    文件:GradleImportingTestCase.java   
@Override
public void tearDown() throws Exception {
  if (myJdkHome == null) {
    //super.setUp() wasn't called
    return;
  }

  try {
    new WriteAction() {
      @Override
      protected void run(@NotNull Result result) throws Throwable {
        Sdk old = ProjectJdkTable.getInstance().findJdk(GRADLE_JDK_NAME);
        if (old != null) {
          SdkConfigurationUtil.removeSdk(old);
        }
      }
    }.execute();
    Messages.setTestDialog(TestDialog.DEFAULT);
    FileUtil.delete(BuildManager.getInstance().getBuildSystemDirectory());
  }
  finally {
    super.tearDown();
  }
}
项目:tools-idea    文件:ProjectSdksModel.java   
public void doAdd(JComponent parent, final SdkType type, final Consumer<Sdk> callback) {
  myModified = true;
  if (type.supportsCustomCreateUI()) {
    type.showCustomCreateUI(this, parent, new Consumer<Sdk>() {
      @Override
      public void consume(Sdk sdk) {
        setupSdk(sdk, callback);
      }
    });
  }
  else {
    SdkConfigurationUtil.selectSdkHome(type, new Consumer<String>() {
      @Override
      public void consume(final String home) {
        String newSdkName = SdkConfigurationUtil.createUniqueSdkName(type, home, myProjectSdks.values());
        final ProjectJdkImpl newJdk = new ProjectJdkImpl(newSdkName, type);
        newJdk.setHomePath(home);
        setupSdk(newJdk, callback);
      }
    });
  }
}
项目:consulo    文件:ProjectSdksModel.java   
public void doAdd(JComponent parent, final SdkType type, final Consumer<Sdk> callback) {
  myModified = true;
  if (type.supportsCustomCreateUI()) {
    type.showCustomCreateUI(this, parent, new Consumer<Sdk>() {
      @Override
      public void consume(Sdk sdk) {
        setupSdk(sdk, callback);
      }
    });
  }
  else {
    SdkConfigurationUtil.selectSdkHome(type, new Consumer<String>() {
      @Override
      public void consume(final String home) {
        String newSdkName = SdkConfigurationUtil.createUniqueSdkName(type, home, getSdks());
        final SdkImpl newSdk = new SdkImpl(newSdkName, type);
        newSdk.setHomePath(home);
        setupSdk(newSdk, callback);
      }
    });
  }
}
项目:educational-plugin    文件:PyStudyDirectoryProjectGenerator.java   
@Override
public void afterProjectGenerated(@NotNull Project project) {
  Sdk sdk = mySettings.getSdk();

  if (sdk == PLACEHOLDER_SDK) {
    createAndAddVirtualEnv(project, mySettings);
    sdk = mySettings.getSdk();
  }
  if (sdk instanceof PyDetectedSdk) {
    sdk = addDetectedSdk(sdk, project);
  }
  SdkConfigurationUtil.setDirectoryProjectSdk(project, sdk);
}
项目:intellij-ce-playground    文件:SdkEditor.java   
private void doSelectHomePath(){
  final SdkType sdkType = (SdkType)mySdk.getSdkType();
  SdkConfigurationUtil.selectSdkHome(sdkType, new Consumer<String>() {
    @Override
    public void consume(final String path) {
      doSetHomePath(path, sdkType);
    }
  });

}
项目:intellij-ce-playground    文件:AbstractCreateVirtualEnvDialog.java   
protected static void setupVirtualEnvSdk(final String path,
                                         boolean associateWithProject,
                                         VirtualEnvCallback callback) {
  final VirtualFile sdkHome =
    ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {
      @Nullable
      public VirtualFile compute() {
        return LocalFileSystem.getInstance().refreshAndFindFileByPath(path);
      }
    });
  if (sdkHome != null) {
    final Sdk sdk = SdkConfigurationUtil.createAndAddSDK(FileUtil.toSystemDependentName(sdkHome.getPath()), PythonSdkType.getInstance());
    callback.virtualEnvCreated(sdk, associateWithProject);
  }
}
项目:intellij-ce-playground    文件:PythonSdkDetailsStep.java   
private void createLocalSdk() {
  ApplicationManager.getApplication().invokeLater(new Runnable() {
    @Override
    public void run() {
    SdkConfigurationUtil.createSdk(myProject, myExistingSdks, mySdkAddedCallback, false, PythonSdkType.getInstance());
    }
  }, ModalityState.any());
}
项目:intellij-ce-playground    文件:PythonSdkDetailsDialog.java   
private void removeSdk() {
  final Sdk currentSdk = getSelectedSdk();
  if (currentSdk != null) {
    final Sdk sdk = myProjectSdksModel.findSdk(currentSdk);
    final PySdkService sdkService = PySdkService.getInstance();
    sdkService.removeSdk(currentSdk);
    DumbService.allowStartingDumbModeInside(DumbModePermission.MAY_START_MODAL, new Runnable() {
      @Override
      public void run() {
        SdkConfigurationUtil.removeSdk(sdk);
      }
    });

    myProjectSdksModel.removeSdk(sdk);
    myProjectSdksModel.removeSdk(currentSdk);

    if (myModificators.containsKey(currentSdk)) {
      SdkModificator modificator = myModificators.get(currentSdk);
      myModifiedModificators.remove(modificator);
      myModificators.remove(currentSdk);
    }
    refreshSdkList();
    mySdkListChanged = true;
    // TODO select initially selected SDK
    if (mySdkList.getSelectedIndex() < 0) {
      mySdkList.setSelectedIndex(0);
    }
  }
}
项目:intellij-ce-playground    文件:AndroidSdkUtilsTest.java   
private static void createAndroidSdk(@NotNull String androidHomePath, @NotNull String targetHashString, @NotNull Sdk javaSdk) {
  Sdk sdk = SdkConfigurationUtil.createAndAddSDK(androidHomePath, AndroidSdkType.getInstance());
  assertNotNull(sdk);
  AndroidSdkData sdkData = AndroidSdkData.getSdkData(androidHomePath);
  assertNotNull(sdkData);
  IAndroidTarget target = sdkData.findTargetByHashString(targetHashString);
  assertNotNull(target);
  AndroidSdkUtils.setUpSdk(sdk, target.getName(), new Sdk[]{javaSdk}, target, javaSdk, true);
}
项目:intellij    文件:Jdks.java   
@Nullable
private static Sdk createJdk(String jdkHomePath) {
  Sdk jdk = SdkConfigurationUtil.createAndAddSDK(jdkHomePath, JavaSdk.getInstance());
  if (jdk == null) {
    logger.error(String.format("Unable to create JDK from path '%1$s'", jdkHomePath));
  }
  return jdk;
}
项目:intellij    文件:BlazePythonSyncPlugin.java   
@Nullable
private static Sdk getOrCreatePythonSdk() {
  List<Sdk> sdk = PythonSdkType.getAllSdks();
  if (!sdk.isEmpty()) {
    return sdk.get(0);
  }
  return SdkConfigurationUtil.createAndAddSDK("/usr/bin/python2.7", PythonSdkType.getInstance());
}
项目:defrac-plugin-intellij    文件:DefracSdkUtil.java   
public static void setupSdk(@NotNull final Sdk defracSdk,
                            @NotNull final String sdkName,
                            @NotNull final Sdk[] allSdks,
                            @NotNull final DefracVersion defracVersion,
                            @Nullable final Sdk javaSdk,
                            final boolean addRoots) {
  final DefracSdkAdditionalData data = new DefracSdkAdditionalData(defracSdk, javaSdk);
  final String name = SdkConfigurationUtil.createUniqueSdkName(sdkName, Arrays.asList(allSdks));
  final SdkModificator sdkModificator = defracSdk.getSdkModificator();

  data.setDefracVersion(defracVersion);
  sdkModificator.setName(name);

  if(javaSdk != null) {
    sdkModificator.setVersionString(javaSdk.getVersionString());
  }

  sdkModificator.setSdkAdditionalData(data);

  if(addRoots) {
    sdkModificator.removeAllRoots();

    attachLibraries(defracVersion, sdkModificator);
    attachAnnotations(defracVersion, sdkModificator);
  }

  sdkModificator.commitChanges();
}
项目:tools-idea    文件:SdkEditor.java   
private void doSelectHomePath(){
  final SdkType sdkType = (SdkType)mySdk.getSdkType();
  SdkConfigurationUtil.selectSdkHome(sdkType, new Consumer<String>() {
    @Override
    public void consume(final String path) {
      doSetHomePath(path, sdkType);
    }
  });

}
项目:consulo    文件:BaseSdkEditor.java   
private void doSelectHomePath() {
  final SdkType sdkType = (SdkType)mySdk.getSdkType();
  SdkConfigurationUtil.selectSdkHome(sdkType, new Consumer<String>() {
    @Override
    public void consume(final String path) {
      doSetHomePath(path, sdkType);
    }
  });

}
项目:intellij-ce-playground    文件:PythonSdkConfigurator.java   
public void configureProject(final Project project, @NotNull final VirtualFile baseDir, Ref<Module> moduleRef) {
  // it it a virtualenv?
  final PythonSdkType sdkType = PythonSdkType.getInstance();
  //find virtualEnv in project directory
  final List<String> candidates = new ArrayList<String>();
  if (project == null) return;
  final VirtualFile rootDir = project.getBaseDir();
  if (rootDir != null)
    candidates.addAll(VirtualEnvSdkFlavor.findInDirectory(rootDir));
  if (!candidates.isEmpty()) {
    String filePath = candidates.get(0);
    if (StringUtil.startsWithChar(filePath, '~')) {
      final String home = SystemProperties.getUserHome();
      filePath = home + filePath.substring(1);
    }
    final Sdk virtualEnvSdk = SdkConfigurationUtil.createAndAddSDK(filePath, sdkType);
    if (virtualEnvSdk != null) {
      SdkConfigurationUtil.setDirectoryProjectSdk(project, virtualEnvSdk);
      SdkAdditionalData additionalData = virtualEnvSdk.getSdkAdditionalData();
      if (additionalData == null) {
        additionalData = new PythonSdkAdditionalData(PythonSdkFlavor.getFlavor(virtualEnvSdk.getHomePath()));
        ((ProjectJdkImpl)virtualEnvSdk).setSdkAdditionalData(additionalData);
      }
      ((PythonSdkAdditionalData) additionalData).associateWithProject(project);
      return;
    }
    return;
  }


  final Sdk existingSdk = ProjectRootManager.getInstance(project).getProjectSdk();
  if (existingSdk != null && existingSdk.getSdkType() == sdkType) return; // SdkConfigurationUtil does the same
  final File executableFile = PythonSdkType.findExecutableFile(new File(project.getBasePath(), "bin"), "python");
  if (executableFile != null) {
    final File virtualEnvRoot = PythonSdkType.getVirtualEnvRoot(executableFile.getPath());
    if (virtualEnvRoot != null) {
      // yes, an unknown virtualenv; set it up as SDK
      final Sdk sdk = SdkConfigurationUtil.createAndAddSDK(executableFile.getPath(), sdkType);
      if (sdk != null) {
        SdkConfigurationUtil.setDirectoryProjectSdk(project, sdk);
        return;
      }
    }
  }
  // default
  SdkConfigurationUtil.configureDirectoryProjectSdk(project, new PreferredSdkComparator(), sdkType);
}
项目:intellij-ce-playground    文件:GenerateProjectCallback.java   
@Override
public void consume(@Nullable ProjectSettingsStepBase step) {
  if (!(step instanceof ProjectSpecificSettingsStep)) return;

  final ProjectSpecificSettingsStep settingsStep = (ProjectSpecificSettingsStep)step;

  Sdk sdk = settingsStep.getSdk();
  final Project project = ProjectManager.getInstance().getDefaultProject();
  final ProjectSdksModel model = PyConfigurableInterpreterList.getInstance(project).getModel();
  if (sdk instanceof PyDetectedSdk) {
    final String name = sdk.getName();
    VirtualFile sdkHome = ApplicationManager.getApplication().runWriteAction(new Computable<VirtualFile>() {
      @Override
      public VirtualFile compute() {
        return LocalFileSystem.getInstance().refreshAndFindFileByPath(name);
      }
    });
    PySdkService.getInstance().solidifySdk(sdk);
    sdk = SdkConfigurationUtil.createAndAddSDK(sdkHome.getPath(), PythonSdkType.getInstance());
    if (sdk != null) {
      PythonSdkType.getInstance().setupSdkPathsImmediately(sdk, project);
    }

    model.addSdk(sdk);
    settingsStep.setSdk(sdk);
    try {
      model.apply();
    }
    catch (ConfigurationException exception) {
      LOG.error("Error adding detected python interpreter " + exception.getMessage());
    }
  }
  Project newProject = generateProject(project, settingsStep);
  if (newProject != null) {
    SdkConfigurationUtil.setDirectoryProjectSdk(newProject, sdk);
    final List<Sdk> sdks = PythonSdkType.getAllSdks();
    for (Sdk s : sdks) {
      final SdkAdditionalData additionalData = s.getSdkAdditionalData();
      if (additionalData instanceof PythonSdkAdditionalData) {
        ((PythonSdkAdditionalData)additionalData).reassociateWithCreatedProject(newProject);
      }
    }
  }
}
项目:defrac-plugin-intellij    文件:DefracSdkType.java   
@Override
public void showCustomCreateUI(final SdkModel sdkModel,
                               final JComponent parentComponent,
                               final Consumer<Sdk> sdkCreatedCallback) {
  customImpl: {
    final Collection<String> homePaths = suggestHomePaths();

    if(homePaths.isEmpty()) {
      break customImpl;
    }

    final String home = homePaths.iterator().next();
    final File homePath = new File(home);

    if(!homePath.isDirectory()) {
      break customImpl;
    }

    if(!checkDependency(sdkModel)) {
      if(Messages.showOkCancelDialog(parentComponent,
          getUnsatisfiedDependencyMessage(), "Cannot Create SDK",
          Messages.getWarningIcon()) != Messages.OK) {
        return;
      }

      if(fixDependency(sdkModel, sdkCreatedCallback) == null) {
        return;
      }
    }

    final String newSdkName = SdkConfigurationUtil.createUniqueSdkName(this, home, Arrays.asList(sdkModel.getSdks()));
    final ProjectJdkImpl newJdk = new ProjectJdkImpl(newSdkName, this);

    newJdk.setHomePath(home);
    sdkCreatedCallback.consume(newJdk);

    return;
  }

  super.showCustomCreateUI(sdkModel, parentComponent, sdkCreatedCallback);
}
项目: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);
}