Example #1
0
 public String getPresentableName() {
   if (myJdk != null) {
     return "< " + myJdk.getName() + " >";
   } else {
     return "< " + getJdkName() + " >";
   }
 }
 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));
   }
 }
  private void addCreatedSdk(@Nullable final Sdk sdk, boolean newVirtualEnv) {
    if (sdk != null) {
      final PySdkService sdkService = PySdkService.getInstance();
      sdkService.restoreSdk(sdk);

      boolean isVirtualEnv = PythonSdkType.isVirtualEnv(sdk);
      if (isVirtualEnv && !newVirtualEnv) {
        AddVEnvOptionsDialog dialog = new AddVEnvOptionsDialog(myMainPanel);
        dialog.show();
        if (dialog.getExitCode() != DialogWrapper.OK_EXIT_CODE) {
          return;
        }
        SdkModificator modificator = myModificators.get(sdk);
        setSdkAssociated(modificator, !dialog.makeAvailableToAll());
        myModifiedModificators.add(modificator);
      }
      final Sdk oldSdk = myProjectSdksModel.findSdk(sdk);
      if (oldSdk == null) {
        myProjectSdksModel.addSdk(sdk);
      }
      refreshSdkList();
      mySdkList.setSelectedValue(myProjectSdksModel.findSdk(sdk.getName()), true);
      mySdkListChanged = true;
    }
  }
Example #4
0
 public void jdkAdded(Sdk jdk) {
   if (myJdk == null && getJdkName().equals(jdk.getName())) {
     myJdk = jdk;
     setJdkName(null);
     setJdkType(null);
     updateFromRootProviderAndSubscribe(getRootProvider());
   }
 }
  public void rebuildSdksListAndSelectSdk(final Sdk selectedSdk) {
    final List<Sdk> sdks =
        ProjectJdkTable.getInstance().getSdksOfType(AndroidSdkType.getInstance());

    final JComboBox sdksComboBox = getComboBox();
    sdksComboBox.setModel(new DefaultComboBoxModel(sdks.toArray()));

    if (selectedSdk != null) {
      for (Sdk candidateSdk : sdks) {
        if (candidateSdk != null && candidateSdk.getName().equals(selectedSdk.getName())) {
          sdksComboBox.setSelectedItem(candidateSdk);
          return;
        }
      }
    }
    sdksComboBox.setSelectedItem(null);
  }
Example #6
0
 public void jdkNameChanged(Sdk jdk, String previousName) {
   if (myJdk == null && getJdkName().equals(jdk.getName())) {
     myJdk = jdk;
     setJdkName(null);
     setJdkType(null);
     updateFromRootProviderAndSubscribe(getRootProvider());
   }
 }
Example #7
0
 public void jdkRemoved(Sdk jdk) {
   if (jdk == myJdk) {
     setJdkName(myJdk.getName());
     setJdkType(myJdk.getSdkType().getName());
     myJdk = null;
     updateFromRootProviderAndSubscribe(getRootProvider());
   }
 }
Example #8
0
 public String getJdkName() {
   if (myJdkName != null) return myJdkName;
   Sdk jdk = getJdk();
   if (jdk != null) {
     return jdk.getName();
   }
   return null;
 }
 public boolean isModified() {
   Sdk projectSdk = getSdk();
   if (projectSdk != null) {
     projectSdk = myProjectSdksModel.findSdk(projectSdk.getName());
   }
   return getSelectedSdk() != projectSdk
       || mySdkListChanged
       || myProjectSdksModel.isModified()
       || !myModifiedModificators.isEmpty();
 }
  @NotNull
  private static Sdk getJdk(
      @Nullable Project project, MavenRunnerSettings runnerSettings, boolean isGlobalRunnerSettings)
      throws ExecutionException {
    String name = runnerSettings.getJreName();
    if (name.equals(MavenRunnerSettings.USE_INTERNAL_JAVA)) {
      return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
    }

    if (name.equals(MavenRunnerSettings.USE_PROJECT_JDK)) {
      if (project != null) {
        Sdk res = ProjectRootManager.getInstance(project).getProjectSdk();
        if (res != null) {
          return res;
        }
      }

      if (project == null) {
        Sdk recent = ProjectJdkTable.getInstance().findMostRecentSdkOfType(JavaSdk.getInstance());
        if (recent != null) return recent;
        return JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
      }

      throw new ProjectJdkSettingsOpenerExecutionException(
          "Project JDK is not specified. <a href='#'>Configure</a>", project);
    }

    if (name.equals(MavenRunnerSettings.USE_JAVA_HOME)) {
      final String javaHome = System.getenv(JAVA_HOME);
      if (StringUtil.isEmptyOrSpaces(javaHome)) {
        throw new ExecutionException(RunnerBundle.message("maven.java.home.undefined"));
      }
      final Sdk jdk = JavaSdk.getInstance().createJdk("", javaHome);
      if (jdk == null) {
        throw new ExecutionException(RunnerBundle.message("maven.java.home.invalid", javaHome));
      }
      return jdk;
    }

    for (Sdk projectJdk : ProjectJdkTable.getInstance().getAllJdks()) {
      if (projectJdk.getName().equals(name)) {
        return projectJdk;
      }
    }

    if (isGlobalRunnerSettings) {
      throw new ExecutionException(
          RunnerBundle.message("maven.java.not.found.default.config", name));
    } else {
      throw new ExecutionException(RunnerBundle.message("maven.java.not.found", name));
    }
  }
  @Override
  public void consume(@Nullable AbstractProjectSettingsStep settingsStep) {
    if (myRunnable != null) {
      myRunnable.run();
    }
    if (settingsStep == null) return;

    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.setupSdk(
              ProjectJdkTable.getInstance().getAllJdks(),
              sdkHome,
              PythonSdkType.getInstance(),
              true,
              null,
              null);
      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);
        }
      }
    }
  }
 public void updateJdks(Sdk sdk, String previousName) {
   final Sdk[] sdks = _sdkModel.getSdks();
   for (Sdk currentSdk : sdks) {
     if (currentSdk.getSdkType().equals(GosuSdkType.getInstance())) {
       final GosuSdkAdditionalData data =
           (GosuSdkAdditionalData) currentSdk.getSdkAdditionalData();
       final Sdk internalJava = data != null ? data.getJavaSdk() : null;
       if (internalJava != null && Comparing.equal(internalJava.getName(), previousName)) {
         data.setJavaSdk(sdk);
       }
     }
   }
   updateJdks();
 }
 @NotNull
 public static String createUniqueSdkName(
     @NotNull String suggestedName, @NotNull Collection<Sdk> sdks) {
   final Set<String> names = new HashSet<>();
   for (Sdk jdk : sdks) {
     names.add(jdk.getName());
   }
   String newSdkName = suggestedName;
   int i = 0;
   while (names.contains(newSdkName)) {
     newSdkName = suggestedName + " (" + (++i) + ")";
   }
   return newSdkName;
 }
  private void refreshSdkList() {
    final List<Sdk> pythonSdks = myInterpreterList.getAllPythonSdks(myProject);
    Sdk projectSdk = getSdk();
    if (!myShowOtherProjectVirtualenvs) {
      VirtualEnvProjectFilter.removeNotMatching(myProject, pythonSdks);
    }
    //noinspection unchecked
    mySdkList.setModel(new CollectionListModel<Sdk>(pythonSdks));

    mySdkListChanged = false;
    if (projectSdk != null) {
      projectSdk = myProjectSdksModel.findSdk(projectSdk.getName());
      mySdkList.clearSelection();
      mySdkList.setSelectedValue(projectSdk, true);
      mySdkList.updateUI();
    }
  }
 private boolean isDuplicateSdkName(String s, Sdk sdk) {
   for (Sdk existingSdk : myProjectSdksModel.getSdks()) {
     if (existingSdk == sdk) {
       continue;
     }
     String existingName;
     if (myModificators.containsKey(existingSdk)) {
       existingName = myModificators.get(existingSdk).getName();
     } else {
       existingName = existingSdk.getName();
     }
     if (existingName.equals(s)) {
       return true;
     }
   }
   return false;
 }
  public boolean isModified() {
    Sdk sdk = myCompilationServerSdk.getSelectedJdk();
    String sdkName = sdk == null ? null : sdk.getName();

    if (showTypeInfoOnCheckBox.isSelected() != mySettings.SHOW_TYPE_TOOLTIP_ON_MOUSE_HOVER)
      return true;
    if (!delaySpinner.getValue().equals(mySettings.SHOW_TYPE_TOOLTIP_DELAY)) return true;

    return !(myEnableCompileServer.isSelected() == mySettings.COMPILE_SERVER_ENABLED
        && myCompilationServerPort.getText().equals(mySettings.COMPILE_SERVER_PORT)
        && ComparatorUtil.equalsNullable(sdkName, mySettings.COMPILE_SERVER_SDK)
        && myCompilationServerMaximumHeapSize
            .getText()
            .equals(mySettings.COMPILE_SERVER_MAXIMUM_HEAP_SIZE)
        && myCompilationServerJvmParameters
            .getText()
            .equals(mySettings.COMPILE_SERVER_JVM_PARAMETERS)
        && myIncrementalTypeCmb.getModel().getSelectedItem().equals(mySettings.INCREMENTAL_TYPE)
        && myCompileOrderCmb.getModel().getSelectedItem().equals(mySettings.COMPILE_ORDER));
  }
  @Override
  public void customize(JList list, Object item, int index, boolean selected, boolean hasFocus) {
    if (item instanceof Sdk) {
      Sdk sdk = (Sdk) item;
      final PythonSdkFlavor flavor =
          PythonSdkFlavor.getPlatformIndependentFlavor(sdk.getHomePath());
      final Icon icon = flavor != null ? flavor.getIcon() : ((SdkType) sdk.getSdkType()).getIcon();

      String name;
      if (mySdkModifiers != null && mySdkModifiers.containsKey(sdk)) {
        name = mySdkModifiers.get(sdk).getName();
      } else {
        name = sdk.getName();
      }
      if (name.startsWith("Remote")) {
        final String trimmedRemote = StringUtil.trim(name.substring("Remote".length()));
        if (!trimmedRemote.isEmpty()) name = trimmedRemote;
      }
      final String flavorName = flavor == null ? "Python" : flavor.getName();
      if (name.startsWith(flavorName)) name = StringUtil.trim(name.substring(flavorName.length()));

      if (isShortVersion) {
        name = shortenName(name);
      }

      if (PythonSdkType.isInvalid(sdk)) {
        setText("[invalid] " + name);
        setIcon(wrapIconWithWarningDecorator(icon));
      } else if (PythonSdkType.isIncompleteRemote(sdk)) {
        setText("[incomplete] " + name);
        setIcon(wrapIconWithWarningDecorator(icon));
      } else if (sdk instanceof PyDetectedSdk) {
        setText(name);
        setIcon(IconLoader.getTransparentIcon(icon));
      } else {
        setText(name);
        setIcon(icon);
      }
    } else if (SEPARATOR.equals(item)) setSeparator();
    else if (item == null) setText(myNullText);
  }
 @Override
 protected void doCustomize(
     final JList list,
     final Sdk sdk,
     final int index,
     final boolean selected,
     final boolean hasFocus) {
   if (sdk != null) {
     // icon
     setIcon(getSdkIcon(sdk));
     // text
     append(sdk.getName());
     if (myShowHomePath) {
       append(
           " (" + FileUtil.toSystemDependentName(sdk.getHomePath()) + ")",
           selected
               ? SimpleTextAttributes.REGULAR_ATTRIBUTES
               : SimpleTextAttributes.GRAYED_ATTRIBUTES);
     }
   } else {
     append(myNullText);
   }
 }
  public void apply() throws ConfigurationException {
    mySettings.INCREMENTAL_TYPE = (String) myIncrementalTypeCmb.getModel().getSelectedItem();
    mySettings.COMPILE_ORDER = (String) myCompileOrderCmb.getModel().getSelectedItem();
    mySettings.COMPILE_SERVER_ENABLED = myEnableCompileServer.isSelected();
    mySettings.COMPILE_SERVER_PORT = myCompilationServerPort.getText();

    Sdk sdk = myCompilationServerSdk.getSelectedJdk();
    mySettings.COMPILE_SERVER_SDK = sdk == null ? null : sdk.getName();

    mySettings.COMPILE_SERVER_MAXIMUM_HEAP_SIZE = myCompilationServerMaximumHeapSize.getText();
    mySettings.COMPILE_SERVER_JVM_PARAMETERS = myCompilationServerJvmParameters.getText();
    mySettings.SHOW_TYPE_TOOLTIP_ON_MOUSE_HOVER = showTypeInfoOnCheckBox.isSelected();
    mySettings.SHOW_TYPE_TOOLTIP_DELAY = (Integer) delaySpinner.getValue();

    // TODO
    //    boolean externalCompiler =
    // CompilerWorkspaceConfiguration.getInstance(myProject).USE_COMPILE_SERVER;
    //
    //    if (!externalCompiler || !myEnableCompileServer.isSelected()) {
    //      myProject.getComponent(CompileServerLauncher.class).stop();
    //    }
    //    myProject.getComponent(CompileServerManager.class).configureWidget();
  }
Example #20
0
  @Override
  public void projectOpened() {
    for (Module module : ModuleManager.getInstance(myProject).getModules()) {
      MPSFacet moduleMPSFacet = FacetManager.getInstance(module).getFacetByType(MPSFacetType.ID);
      if (moduleMPSFacet == null) continue;
      final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
      if (sdk == null) continue;

      // HACK temporary
      if (sdk.getName().equals("1.6")) continue;

      if (mySdkSolutions.get(sdk) == null) {
        ModelAccess.instance()
            .runWriteAction(
                new Runnable() {
                  @Override
                  public void run() {
                    Solution solution = addSolution(sdk);
                    mySdkSolutions.put(sdk, solution);
                  }
                });
      }
    }
  }
  public void init(@NotNull Sdk jdk, @Nullable Sdk androidSdk) {
    updateJdks();

    //    if (androidSdk != null) {
    //      for (int i = 0; i < myJdksModel.getSize(); i++) {
    //        if (Comparing.strEqual(((Sdk) myJdksModel.getElementAt(i)).getName(), jdk.getName()))
    // {
    //          myInternalJdkComboBox.setSelectedIndex(i);
    //          break;
    //        }
    //      }
    //    }

    String strSdkLocation = androidSdk != null ? androidSdk.getHomePath() : null;
    this._sdk = jdk;
    _editCurrentJdk.setText(jdk.getName() + " (" + jdk.getHomePath() + ")");

    SdkAdditionalData sdkAdditionalData =
        androidSdk == null ? null : androidSdk.getSdkAdditionalData();
    if (sdkAdditionalData instanceof GosuSdkAdditionalData) {
      GosuSdkAdditionalData gosuSdkData = (GosuSdkAdditionalData) sdkAdditionalData;
      GosuVersion version = gosuSdkData.getGosuVersion();
      _fieldGosuVersion.setText(version != null ? version.toString() : "");
    }

    //    updateBuildTargets(androidSdkObject);
    //    if (buildTarget != null) {
    //      for (int i = 0; i < myBuildTargetsModel.getSize(); i++) {
    //        IGosuTarget target = (IGosuTarget) myBuildTargetsModel.getElementAt(i);
    //        if (buildTarget.hashString().equals(target.hashString())) {
    //          myBuildTargetComboBox.setSelectedIndex(i);
    //          break;
    //        }
    //      }
    //    }
  }
  @Override
  public boolean setupSdkPaths(@NotNull Sdk sdk, @NotNull SdkModel sdkModel) {
    final List<String> javaSdks = Lists.newArrayList();
    final Sdk[] sdks = sdkModel.getSdks();
    for (Sdk jdk : sdks) {
      if (Jdks.isApplicableJdk(jdk)) {
        javaSdks.add(jdk.getName());
      }
    }

    if (javaSdks.isEmpty()) {
      Messages.showErrorDialog(
          AndroidBundle.message("no.jdk.for.android.found.error"), "No Java SDK Found");
      return false;
    }

    MessageBuildingSdkLog log = new MessageBuildingSdkLog();
    AndroidSdkData sdkData = getSdkData(sdk);

    if (sdkData == null) {
      String errorMessage =
          !log.getErrorMessage().isEmpty()
              ? log.getErrorMessage()
              : AndroidBundle.message("cannot.parse.sdk.error");
      Messages.showErrorDialog(errorMessage, "SDK Parsing Error");
      return false;
    }

    IAndroidTarget[] targets = sdkData.getTargets();

    if (targets.length == 0) {
      if (Messages.showOkCancelDialog(
              AndroidBundle.message("no.android.targets.error"),
              CommonBundle.getErrorTitle(),
              "Open SDK Manager",
              Messages.CANCEL_BUTTON,
              Messages.getErrorIcon())
          == Messages.OK) {
        RunAndroidSdkManagerAction.runSpecificSdkManager(null, sdkData.getLocation());
      }
      return false;
    }

    String[] targetNames = new String[targets.length];

    String newestPlatform = null;
    AndroidVersion version = null;

    for (int i = 0; i < targets.length; i++) {
      IAndroidTarget target = targets[i];
      String targetName = getTargetPresentableName(target);
      targetNames[i] = targetName;
      if (target.isPlatform() && (version == null || target.getVersion().compareTo(version) > 0)) {
        newestPlatform = targetName;
        version = target.getVersion();
      }
    }

    AndroidNewSdkDialog dialog =
        new AndroidNewSdkDialog(
            null,
            javaSdks,
            javaSdks.get(0),
            Arrays.asList(targetNames),
            newestPlatform != null ? newestPlatform : targetNames[0]);
    if (!dialog.showAndGet()) {
      return false;
    }
    String name = javaSdks.get(dialog.getSelectedJavaSdkIndex());
    Sdk jdk = sdkModel.findSdk(name);
    IAndroidTarget target = targets[dialog.getSelectedTargetIndex()];
    String sdkName = chooseNameForNewLibrary(target);
    setUpSdk(sdk, sdkName, sdks, target, jdk, true);

    return true;
  }
 public String getName() {
   return myDelegate.getName();
 }
  @Override
  public boolean setupSdkPaths(Sdk sdk, SdkModel sdkModel) {
    final List<String> javaSdks = new ArrayList<String>();
    final Sdk[] sdks = sdkModel.getSdks();
    for (Sdk jdk : sdks) {
      if (AndroidSdkUtils.isApplicableJdk(jdk)) {
        javaSdks.add(jdk.getName());
      }
    }

    if (javaSdks.isEmpty()) {
      Messages.showErrorDialog(
          AndroidBundle.message("no.jdk.for.android.found.error"), "No Java SDK Found");
      return false;
    }

    int choice =
        Messages.showChooseDialog(
            "Please select Java SDK",
            "Select Internal Java Platform",
            ArrayUtil.toStringArray(javaSdks),
            javaSdks.get(0),
            Messages.getQuestionIcon());

    if (choice == -1) {
      return false;
    }

    final String name = javaSdks.get(choice);
    final Sdk jdk = sdkModel.findSdk(name);

    MessageBuildingSdkLog log = new MessageBuildingSdkLog();
    AndroidSdkData sdkData = AndroidSdkData.parse(sdk.getHomePath(), log);

    if (sdkData == null) {
      String errorMessage =
          log.getErrorMessage().length() > 0
              ? log.getErrorMessage()
              : AndroidBundle.message("cannot.parse.sdk.error");
      Messages.showErrorDialog(errorMessage, "SDK Parsing Error");
      return false;
    }

    IAndroidTarget[] targets = sdkData.getTargets();

    if (targets.length == 0) {
      Messages.showErrorDialog(
          AndroidBundle.message("no.android.targets.error"), CommonBundle.getErrorTitle());
      return false;
    }

    String[] targetNames = new String[targets.length];

    String newestPlatform = null;
    AndroidVersion version = null;

    for (int i = 0; i < targets.length; i++) {
      IAndroidTarget target = targets[i];
      String targetName = AndroidSdkUtils.getTargetPresentableName(target);
      targetNames[i] = targetName;
      if (target.isPlatform() && (version == null || target.getVersion().compareTo(version) > 0)) {
        newestPlatform = targetName;
        version = target.getVersion();
      }
    }

    choice =
        Messages.showChooseDialog(
            "Select build target",
            "Create New Android SDK",
            targetNames,
            newestPlatform != null ? newestPlatform : targetNames[0],
            Messages.getQuestionIcon());

    if (choice == -1) {
      return false;
    }

    AndroidSdkUtils.setUpSdk(sdk, jdk, sdks, targets[choice], true);

    return true;
  }
Example #25
0
 public ActionCallback select(@NotNull Sdk sdk, final boolean requestFocus) {
   Place place = createPlaceFor(myJdkListConfig);
   place.putPath(BaseStructureConfigurable.TREE_NAME, sdk.getName());
   return navigateTo(place, requestFocus);
 }
  @NotNull
  @Override
  protected ProcessOutput getPythonProcessOutput(
      @NotNull String helperPath,
      @NotNull List<String> args,
      boolean askForSudo,
      boolean showProgress,
      @Nullable final String workingDir)
      throws ExecutionException {
    final Sdk sdk = getSdk();
    final String homePath = sdk.getHomePath();
    if (homePath == null) {
      throw new ExecutionException("Cannot find Python interpreter for SDK " + sdk.getName());
    }
    final SdkAdditionalData sdkData = sdk.getSdkAdditionalData();
    if (sdkData instanceof PyRemoteSdkAdditionalDataBase) { // remote interpreter
      final PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();

      RemoteSdkCredentials remoteSdkCredentials;
      if (CaseCollector.useRemoteCredentials((PyRemoteSdkAdditionalDataBase) sdkData)) {
        try {
          remoteSdkCredentials = ((RemoteSdkAdditionalData) sdkData).getRemoteSdkCredentials(false);
        } catch (InterruptedException e) {
          LOG.error(e);
          remoteSdkCredentials = null;
        } catch (ExecutionException e) {
          throw analyzeException(e, helperPath, args);
        }
        if (manager != null && remoteSdkCredentials != null) {
          if (askForSudo) {
            askForSudo =
                !manager.ensureCanWrite(
                    null, remoteSdkCredentials, remoteSdkCredentials.getInterpreterPath());
          }
        } else {
          throw new PyExecutionException(
              PythonRemoteInterpreterManager.WEB_DEPLOYMENT_PLUGIN_IS_DISABLED, helperPath, args);
        }
      }

      if (manager != null) {
        final List<String> cmdline = new ArrayList<String>();
        cmdline.add(homePath);
        cmdline.add(RemoteFile.detectSystemByPath(homePath).createRemoteFile(helperPath).getPath());
        cmdline.addAll(
            Collections2.transform(
                args,
                new Function<String, String>() {
                  @Override
                  public String apply(@Nullable String input) {
                    return quoteIfNeeded(input);
                  }
                }));
        ProcessOutput processOutput;
        do {
          final PyRemoteSdkAdditionalDataBase remoteSdkAdditionalData =
              (PyRemoteSdkAdditionalDataBase) sdkData;
          final PyRemotePathMapper pathMapper =
              manager.setupMappings(null, remoteSdkAdditionalData, null);
          try {
            processOutput =
                PyRemoteProcessStarterManagerUtil.getManager(remoteSdkAdditionalData)
                    .executeRemoteProcess(
                        null,
                        ArrayUtil.toStringArray(cmdline),
                        workingDir,
                        manager,
                        remoteSdkAdditionalData,
                        pathMapper,
                        askForSudo,
                        true);
          } catch (InterruptedException e) {
            throw new ExecutionException(e);
          }
          if (askForSudo
              && processOutput.getStderr().contains("sudo: 3 incorrect password attempts")) {
            continue;
          }
          break;
        } while (true);
        return processOutput;
      } else {
        throw new PyExecutionException(
            PythonRemoteInterpreterManager.WEB_DEPLOYMENT_PLUGIN_IS_DISABLED, helperPath, args);
      }
    } else {
      throw new PyExecutionException("Invalid remote SDK", helperPath, args);
    }
  }
Example #27
0
 public static CantRunException jdkMisconfigured(
     @NotNull final Sdk jdk, @NotNull final Module module) {
   return new CantRunException(
       ExecutionBundle.message("jdk.is.bad.configured.error.message", jdk.getName()));
 }
  @Override
  public void initComponent() {
    ProjectJdkTable jdkTable = ProjectJdkTable.getInstance();
    List<Sdk> sdkList = new ArrayList<Sdk>();

    sdkList.addAll(GoSdkUtil.getSdkOfType(GoSdkType.getInstance(), jdkTable));

    for (Sdk sdk : sdkList) {
      GoSdkData sdkData = (GoSdkData) sdk.getSdkAdditionalData();

      boolean needsUpgrade = sdkData == null;
      try {
        if (!needsUpgrade) {
          sdkData.checkValid();
        }
      } catch (ConfigurationException ex) {
        needsUpgrade = true;
      }

      if (!needsUpgrade) continue;

      needsUpgrade = false;
      GoSdkData data = GoSdkUtil.testGoogleGoSdk(sdk.getHomePath());

      if (data == null) needsUpgrade = true;

      try {
        if (data != null) {
          data.checkValid();
        }
      } catch (ConfigurationException ex) {
        needsUpgrade = true;
      }

      if (needsUpgrade) {
        Notifications.Bus.notify(
            new Notification(
                "Go SDK validator",
                "Corrupt Go SDK",
                getContent("Go", sdk.getName()),
                NotificationType.WARNING),
            myProject);
      }

      SdkModificator sdkModificator = sdk.getSdkModificator();
      sdkModificator.setSdkAdditionalData(data);
      sdkModificator.commitChanges();
    }

    sdkList.clear();
    sdkList.addAll(GoSdkUtil.getSdkOfType(GoAppEngineSdkType.getInstance(), jdkTable));

    Boolean hasGAESdk = sdkList.size() > 0;

    for (Sdk sdk : sdkList) {
      GoAppEngineSdkData sdkData = (GoAppEngineSdkData) sdk.getSdkAdditionalData();

      if (sdkData == null || sdkData.TARGET_ARCH == null || sdkData.TARGET_OS == null) {
        Notifications.Bus.notify(
            new Notification(
                "Go AppEngine SDK validator",
                "Corrupt Go App Engine SDK",
                getContent("Go App Engine", sdk.getName()),
                NotificationType.WARNING),
            myProject);

        continue;
      }

      boolean needsUpgrade = false;
      try {
        sdkData.checkValid();
      } catch (ConfigurationException ex) {
        needsUpgrade = true;
      }

      if (!needsUpgrade) continue;

      needsUpgrade = false;
      GoAppEngineSdkData data = GoSdkUtil.testGoAppEngineSdk(sdk.getHomePath());

      if (data == null) needsUpgrade = true;

      try {
        if (data != null) {
          data.checkValid();
        }
      } catch (ConfigurationException ex) {
        needsUpgrade = true;
      }

      // GAE SDK auto-update needs a bit more love
      if (data != null && !(new File(data.GOAPP_BIN_PATH)).exists()) {
        needsUpgrade = true;
      }

      if (needsUpgrade) {
        Notifications.Bus.notify(
            new Notification(
                "Go AppEngine SDK validator",
                "Corrupt Go App Engine SDK",
                getContent("Go AppEngine", sdk.getName()),
                NotificationType.WARNING),
            myProject);
      }

      SdkModificator sdkModificator = sdk.getSdkModificator();
      sdkModificator.setSdkAdditionalData(data);
      sdkModificator.commitChanges();
    }

    if (hasGAESdk) {
      String sysAppEngineDevServerPath = GoSdkUtil.getAppEngineDevServer();
      if (sysAppEngineDevServerPath.isEmpty())
        Notifications.Bus.notify(
            new Notification(
                "Go AppEngine SDK validator",
                "Problem with env variables",
                getInvalidAPPENGINE_DEV_APPSERVEREnvMessage(),
                NotificationType.WARNING,
                NotificationListener.URL_OPENING_LISTENER),
            myProject);
    }

    PluginDescriptor pluginDescriptor =
        PluginManager.getPlugin(PluginId.getId("ro.redeul.google.go"));
    if (pluginDescriptor != null) {
      String version = ((IdeaPluginDescriptorImpl) pluginDescriptor).getVersion();

      if (version.endsWith("-dev")
          && !System.getProperty("go.skip.dev.warn", "false").equals("true")) {
        Notifications.Bus.notify(
            new Notification(
                "Go plugin notice",
                "Development version detected",
                getDevVersionMessage(),
                NotificationType.WARNING,
                null),
            myProject);
      }
    }

    super.initComponent();
  }
  private Process launchBuildProcess(Project project, final int port, final UUID sessionId)
      throws ExecutionException {
    // choosing sdk with which the build process should be run
    final Sdk internalJdk = JavaAwareProjectJdkTableImpl.getInstanceEx().getInternalJdk();
    Sdk projectJdk = internalJdk;
    final String versionString = projectJdk.getVersionString();
    JavaSdkVersion sdkVersion =
        versionString != null
            ? ((JavaSdk) projectJdk.getSdkType()).getVersion(versionString)
            : null;
    if (sdkVersion != null) {
      final Set<Sdk> candidates = new HashSet<Sdk>();
      for (Module module : ModuleManager.getInstance(project).getModules()) {
        final Sdk sdk = ModuleRootManager.getInstance(module).getSdk();
        if (sdk != null && sdk.getSdkType() instanceof JavaSdk) {
          candidates.add(sdk);
        }
      }
      // now select the latest version from the sdks that are used in the project, but not older
      // than the internal sdk version
      for (Sdk candidate : candidates) {
        final String vs = candidate.getVersionString();
        if (vs != null) {
          final JavaSdkVersion candidateVersion = ((JavaSdk) candidate.getSdkType()).getVersion(vs);
          if (candidateVersion != null) {
            if (candidateVersion.compareTo(sdkVersion) > 0) {
              sdkVersion = candidateVersion;
              projectJdk = candidate;
            }
          }
        }
      }
    }

    // validate tools.jar presence
    final File compilerPath;
    if (projectJdk.equals(internalJdk)) {
      final JavaCompiler systemCompiler = ToolProvider.getSystemJavaCompiler();
      if (systemCompiler == null) {
        throw new ExecutionException(
            "No system java compiler is provided by the JRE. Make sure tools.jar is present in IntelliJ IDEA classpath.");
      }
      compilerPath = ClasspathBootstrap.getResourcePath(systemCompiler.getClass());
    } else {
      final String path = ((JavaSdk) projectJdk.getSdkType()).getToolsPath(projectJdk);
      if (path == null) {
        throw new ExecutionException(
            "Cannot determine path to 'tools.jar' library for "
                + projectJdk.getName()
                + " ("
                + projectJdk.getHomePath()
                + ")");
      }
      compilerPath = new File(path);
    }

    final GeneralCommandLine cmdLine = new GeneralCommandLine();
    final String vmExecutablePath =
        ((JavaSdkType) projectJdk.getSdkType()).getVMExecutablePath(projectJdk);
    cmdLine.setExePath(vmExecutablePath);
    cmdLine.addParameter("-XX:MaxPermSize=150m");
    cmdLine.addParameter("-XX:ReservedCodeCacheSize=64m");
    final int heapSize = Registry.intValue("compiler.process.heap.size");
    final int xms = heapSize / 2;
    if (xms > 32) {
      cmdLine.addParameter("-Xms" + xms + "m");
    }
    cmdLine.addParameter("-Xmx" + heapSize + "m");

    if (SystemInfo.isMac
        && sdkVersion != null
        && JavaSdkVersion.JDK_1_6.equals(sdkVersion)
        && Registry.is("compiler.process.32bit.vm.on.mac")) {
      // unfortunately -d32 is supported on jdk 1.6 only
      cmdLine.addParameter("-d32");
    }

    cmdLine.addParameter("-Djava.awt.headless=true");

    final String shouldGenerateIndex =
        System.getProperty(GlobalOptions.GENERATE_CLASSPATH_INDEX_OPTION);
    if (shouldGenerateIndex != null) {
      cmdLine.addParameter(
          "-D" + GlobalOptions.GENERATE_CLASSPATH_INDEX_OPTION + "=" + shouldGenerateIndex);
    }

    final String additionalOptions = Registry.stringValue("compiler.process.vm.options");
    if (!StringUtil.isEmpty(additionalOptions)) {
      final StringTokenizer tokenizer = new StringTokenizer(additionalOptions, " ", false);
      while (tokenizer.hasMoreTokens()) {
        cmdLine.addParameter(tokenizer.nextToken());
      }
    }

    // debugging
    final int debugPort = Registry.intValue("compiler.process.debug.port");
    if (debugPort > 0) {
      cmdLine.addParameter("-XX:+HeapDumpOnOutOfMemoryError");
      cmdLine.addParameter(
          "-agentlib:jdwp=transport=dt_socket,server=y,suspend=y,address=" + debugPort);
    }

    if (Registry.is("compiler.process.use.memory.temp.cache")) {
      cmdLine.addParameter("-D" + GlobalOptions.USE_MEMORY_TEMP_CACHE_OPTION);
    }
    if (Registry.is("compiler.process.use.external.javac")) {
      cmdLine.addParameter("-D" + GlobalOptions.USE_EXTERNAL_JAVAC_OPTION);
    }
    final String host = NetUtils.getLocalHostString();
    cmdLine.addParameter("-D" + GlobalOptions.HOSTNAME_OPTION + "=" + host);

    // javac's VM should use the same default locale that IDEA uses in order for javac to print
    // messages in 'correct' language
    final String lang = System.getProperty("user.language");
    if (lang != null) {
      //noinspection HardCodedStringLiteral
      cmdLine.addParameter("-Duser.language=" + lang);
    }
    final String country = System.getProperty("user.country");
    if (country != null) {
      //noinspection HardCodedStringLiteral
      cmdLine.addParameter("-Duser.country=" + country);
    }
    //noinspection HardCodedStringLiteral
    final String region = System.getProperty("user.region");
    if (region != null) {
      //noinspection HardCodedStringLiteral
      cmdLine.addParameter("-Duser.region=" + region);
    }

    cmdLine.addParameter("-classpath");

    final List<File> cp = ClasspathBootstrap.getBuildProcessApplicationClasspath();
    cp.add(compilerPath);
    cp.addAll(myClasspathManager.getCompileServerPluginsClasspath());

    cmdLine.addParameter(classpathToString(cp));

    cmdLine.addParameter(BuildMain.class.getName());
    cmdLine.addParameter(host);
    cmdLine.addParameter(Integer.toString(port));
    cmdLine.addParameter(sessionId.toString());

    final File workDirectory = new File(mySystemDirectory, SYSTEM_ROOT);
    workDirectory.mkdirs();
    ensureLogConfigExists(workDirectory);

    cmdLine.addParameter(FileUtil.toSystemIndependentName(workDirectory.getPath()));

    cmdLine.setWorkDirectory(workDirectory);

    return cmdLine.createProcess();
  }