Ejemplo n.º 1
0
 private static void fillSdks(List<GlobalLibrary> globals) {
   for (Sdk sdk : ProjectJdkTable.getInstance().getAllJdks()) {
     final String name = sdk.getName();
     final String homePath = sdk.getHomePath();
     if (homePath == null) {
       continue;
     }
     final SdkAdditionalData data = sdk.getSdkAdditionalData();
     final String additionalDataXml;
     final SdkType sdkType = (SdkType) sdk.getSdkType();
     if (data == null) {
       additionalDataXml = null;
     } else {
       final Element element = new Element("additional");
       sdkType.saveAdditionalData(data, element);
       additionalDataXml = JDOMUtil.writeElement(element, "\n");
     }
     final List<String> paths =
         convertToLocalPaths(sdk.getRootProvider().getFiles(OrderRootType.CLASSES));
     String versionString = sdk.getVersionString();
     if (versionString != null && sdkType instanceof JavaSdk) {
       final JavaSdkVersion version = ((JavaSdk) sdkType).getVersion(versionString);
       if (version != null) {
         versionString = version.getDescription();
       }
     }
     globals.add(
         new SdkLibrary(
             name, sdkType.getName(), versionString, homePath, paths, additionalDataXml));
   }
 }
  public static void selectSdkHome(
      @NotNull final SdkType sdkType, @NotNull final Consumer<String> consumer) {
    final FileChooserDescriptor descriptor = sdkType.getHomeChooserDescriptor();
    if (ApplicationManager.getApplication().isUnitTestMode()) {
      Sdk sdk = ProjectJdkTable.getInstance().findMostRecentSdkOfType(sdkType);
      if (sdk == null) throw new RuntimeException("No SDK of type " + sdkType + " found");
      consumer.consume(sdk.getHomePath());
      return;
    }
    FileChooser.chooseFiles(
        descriptor,
        null,
        getSuggestedSdkRoot(sdkType),
        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);
          }
        });
  }
 @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;
 }
  @Override
  public ModuleWizardStep[] createWizardSteps(
      WizardContext wizardContext, GoModuleBuilder moduleBuilder, ModulesProvider modulesProvider) {
    List<ModuleWizardStep> steps = new ArrayList<ModuleWizardStep>();

    ProjectWizardStepFactory factory = ProjectWizardStepFactory.getInstance();

    //        steps.add(factory.createSourcePathsStep(wizardContext, moduleBuilder, null,
    // "reference.dialogs.new.project.fromScratch.source"));
    //        steps.add(factory.createProjectJdkStep(wizardContext));
    //        steps.add(new AndroidModuleWizardStep(moduleBuilder, wizardContext.getProject()));
    steps.add(
        factory.createSourcePathsStep(
            wizardContext,
            moduleBuilder,
            null,
            "reference.dialogs.new.project.fromScratch.source"));
    steps.add(
        factory.createProjectJdkStep(
            wizardContext,
            SdkType.findInstance(GoSdkType.class),
            moduleBuilder,
            new Computable.PredefinedValueComputable<Boolean>(true),
            null,
            ""));
    //        steps.add(new GoModuleWizardStep(moduleBuilder, wizardContext.getProject()));
    return steps.toArray(new ModuleWizardStep[steps.size()]);
  }
  @NotNull
  public static ProjectJdkImpl createSdk(
      @NotNull Sdk[] allSdks,
      @NotNull VirtualFile homeDir,
      SdkType sdkType,
      @Nullable SdkAdditionalData additionalData,
      @Nullable String customSdkSuggestedName) {
    final List<Sdk> sdksList = Arrays.asList(allSdks);

    String sdkPath = sdkType.sdkPath(homeDir);

    final String sdkName =
        customSdkSuggestedName == null
            ? createUniqueSdkName(sdkType, sdkPath, sdksList)
            : createUniqueSdkName(customSdkSuggestedName, sdksList);

    ProjectJdkImpl sdk = new ProjectJdkImpl(sdkName, sdkType);

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

    sdk.setHomePath(sdkPath);
    return sdk;
  }
  @Nullable
  public static Sdk setupSdk(
      @NotNull Sdk[] allSdks,
      @NotNull VirtualFile homeDir,
      final SdkType sdkType,
      final boolean silent,
      @Nullable final SdkAdditionalData additionalData,
      @Nullable final String customSdkSuggestedName) {
    final ProjectJdkImpl sdk;
    try {
      sdk = createSdk(allSdks, homeDir, sdkType, additionalData, customSdkSuggestedName);

      sdkType.setupSdkPaths(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;
  }
Ejemplo n.º 7
0
  @Override
  public void setupSdkPaths(Sdk sdk) {
    final SdkModificator modificator = sdk.getSdkModificator();

    SdkAdditionalData data = sdk.getSdkAdditionalData();
    if (data == null) {
      data = DartSdkUtil.testDartSdk(sdk.getHomePath());
      modificator.setSdkAdditionalData(data);
    }

    DartSdkUtil.setupSdkPaths(sdk.getHomeDirectory(), modificator);

    modificator.commitChanges();
    super.setupSdkPaths(sdk);
  }
 public static GoSdkType getInstance() {
   return SdkType.findInstance(GoSdkType.class);
 }
Ejemplo n.º 9
0
 public static DartSdkType getInstance() {
   return SdkType.findInstance(DartSdkType.class);
 }
 @Nullable
 public static VirtualFile getSuggestedSdkRoot(@NotNull SdkType sdkType) {
   final String homePath = sdkType.suggestHomePath();
   return homePath == null ? null : LocalFileSystem.getInstance().findFileByPath(homePath);
 }
 @NotNull
 public static String createUniqueSdkName(
     @NotNull SdkType type, String home, final Collection<Sdk> sdks) {
   return createUniqueSdkName(type.suggestSdkName(null, home), sdks);
 }
Ejemplo n.º 12
0
 public static AndroidSdkType getInstance() {
   return SdkType.findInstance(AndroidSdkType.class);
 }