예제 #1
0
 /** Adds new CLASSES entries found in sys.path. */
 private static boolean addNewSysPathEntries(
     @NotNull Sdk sdk, @NotNull SdkModificator modificator, @NotNull List<String> sysPath) {
   final List<VirtualFile> oldRoots =
       Arrays.asList(sdk.getRootProvider().getFiles(OrderRootType.CLASSES));
   PythonSdkAdditionalData additionalData =
       sdk.getSdkAdditionalData() instanceof PythonSdkAdditionalData
           ? (PythonSdkAdditionalData) sdk.getSdkAdditionalData()
           : null;
   List<String> newRoots = new ArrayList<String>();
   for (String root : sysPath) {
     if (new File(root).exists()
         && !FileUtilRt.extensionEquals(root, "egg-info")
         && (additionalData == null || !wasOldRoot(root, additionalData.getExcludedPathFiles()))
         && !wasOldRoot(root, oldRoots)) {
       newRoots.add(root);
     }
   }
   if (!newRoots.isEmpty()) {
     for (String root : newRoots) {
       PythonSdkType.addSdkRoot(modificator, root);
     }
     return true;
   }
   return false;
 }
예제 #2
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));
   }
 }
  @Nullable
  @Override
  protected String getHelperPath(String helper) throws ExecutionException {
    final Sdk sdk = getSdk();

    final SdkAdditionalData sdkData = sdk.getSdkAdditionalData();
    if (sdkData instanceof PyRemoteSdkAdditionalDataBase) {
      final PyRemoteSdkAdditionalDataBase remoteSdkData = (PyRemoteSdkAdditionalDataBase) sdkData;
      try {
        String helpersPath;
        if (CaseCollector.useRemoteCredentials(remoteSdkData)) {
          final RemoteSdkCredentials remoteSdkCredentials =
              remoteSdkData.getRemoteSdkCredentials(false);
          helpersPath = remoteSdkCredentials.getHelpersPath();
        } else {
          helpersPath = remoteSdkData.getHelpersPath();
        }
        if (!StringUtil.isEmpty(helpersPath)) {
          return new RemoteFile(helpersPath, helper).getPath();
        } else {
          return null;
        }
      } catch (InterruptedException e) {
        LOG.error(e);
      } catch (ExecutionException e) {
        throw analyzeException(e, helper, Collections.<String>emptyList());
      }
    }
    return null;
  }
 @Override
 protected PyConsoleProcessHandler createProcessHandler(final Process process) {
   if (PySdkUtil.isRemote(mySdk)) {
     PythonRemoteInterpreterManager manager = PythonRemoteInterpreterManager.getInstance();
     if (manager != null) {
       PyRemoteSdkAdditionalDataBase data =
           (PyRemoteSdkAdditionalDataBase) mySdk.getSdkAdditionalData();
       assert data != null;
       myProcessHandler =
           manager.createConsoleProcessHandler(
               process,
               myRemoteCredentials,
               getConsoleView(),
               myPydevConsoleCommunication,
               myCommandLine,
               CharsetToolkit.UTF8_CHARSET,
               manager.setupMappings(getProject(), data, null));
     } else {
       LOG.error("Can't create remote console process handler");
     }
   } else {
     myProcessHandler =
         new PyConsoleProcessHandler(
             process,
             getConsoleView(),
             myPydevConsoleCommunication,
             myCommandLine,
             CharsetToolkit.UTF8_CHARSET);
   }
   return myProcessHandler;
 }
 public void apply() throws ConfigurationException {
   final FlexmojosSdkAdditionalData data =
       (FlexmojosSdkAdditionalData) mySdk.getSdkAdditionalData();
   if (data != null) {
     data.setAdlPath(myFlexmojosSdkForm.getAdlPath());
     data.setAirRuntimePath(myFlexmojosSdkForm.getAirRuntimePath());
   }
 }
 public PyRemotePathEditor(Sdk sdk) {
   super(
       "Classes",
       OrderRootType.CLASSES,
       FileChooserDescriptorFactory.createAllButJarContentsDescriptor());
   mySdk = sdk;
   myRemoteSdkData = (PyRemoteSdkAdditionalDataBase) mySdk.getSdkAdditionalData();
 }
 @Nullable
 private static Sdk getInternalJavaSdk(Sdk sdk) {
   final SdkAdditionalData data = sdk.getSdkAdditionalData();
   if (data instanceof AndroidSdkAdditionalData) {
     return ((AndroidSdkAdditionalData) data).getJavaSdk();
   }
   return null;
 }
 public void reset() {
   final FlexmojosSdkAdditionalData data =
       (FlexmojosSdkAdditionalData) mySdk.getSdkAdditionalData();
   myFlexmojosSdkForm.setFlexCompilerClasspath(
       data == null ? Collections.<String>emptyList() : data.getFlexCompilerClasspath());
   myFlexmojosSdkForm.setAdlPath(data == null ? "" : data.getAdlPath());
   myFlexmojosSdkForm.setAirRuntimePath(data == null ? "" : data.getAirRuntimePath());
 }
 public boolean isModified() {
   final FlexmojosSdkAdditionalData data =
       (FlexmojosSdkAdditionalData) mySdk.getSdkAdditionalData();
   if (data != null) {
     if (!myFlexmojosSdkForm.getAdlPath().equals(data.getAdlPath())) return true;
     if (!myFlexmojosSdkForm.getAirRuntimePath().equals(data.getAirRuntimePath())) return true;
   }
   return false;
 }
 private void editSdk() {
   final Sdk currentSdk = getSelectedSdk();
   if (currentSdk != null) {
     if (currentSdk.getSdkAdditionalData() instanceof RemoteSdkAdditionalData) {
       editRemoteSdk(currentSdk);
     } else {
       editSdk(currentSdk);
     }
   }
 }
 public void internalJdkUpdate(@NotNull final Sdk sdk) {
   GosuSdkAdditionalData data = (GosuSdkAdditionalData) sdk.getSdkAdditionalData();
   if (data == null) return;
   final Sdk javaSdk = data.getJavaSdk();
   if (_jdksModel.getIndexOf(javaSdk) == -1) {
     _jdksModel.addElement(javaSdk);
   } else {
     _jdksModel.setSelectedItem(javaSdk);
   }
 }
 public static List<String> getAddedPaths(Sdk pythonSdk) {
   List<String> pathList = new ArrayList<String>();
   final SdkAdditionalData sdkAdditionalData = pythonSdk.getSdkAdditionalData();
   if (sdkAdditionalData instanceof PythonSdkAdditionalData) {
     final Set<VirtualFile> addedPaths =
         ((PythonSdkAdditionalData) sdkAdditionalData).getAddedPathFiles();
     for (VirtualFile file : addedPaths) {
       addToPythonPath(file, pathList);
     }
   }
   return pathList;
 }
  @Nullable
  private static File getSandboxPath(final Sdk jdk) {
    SdkAdditionalData additionalData = jdk.getSdkAdditionalData();
    if (additionalData instanceof Sandbox) {
      String sandboxHome = ((Sandbox) additionalData).getSandboxHome();
      if (sandboxHome != null) {
        return new File(FileUtil.toCanonicalPath(sandboxHome));
      }
    }

    return null;
  }
 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();
 }
  @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);
        }
      }
    }
  }
예제 #16
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);
  }
  private Process createRemoteConsoleProcess(
      PythonRemoteInterpreterManager manager, String[] command, Map<String, String> env)
      throws ExecutionException {
    PyRemoteSdkAdditionalDataBase data =
        (PyRemoteSdkAdditionalDataBase) mySdk.getSdkAdditionalData();
    assert data != null;

    GeneralCommandLine commandLine = new GeneralCommandLine(command);

    commandLine.getEnvironment().putAll(env);

    commandLine
        .getParametersList()
        .set(
            1,
            PythonRemoteInterpreterManager.toSystemDependent(
                new File(data.getHelpersPath(), PYDEV_PYDEVCONSOLE_PY).getPath(),
                PySourcePosition.isWindowsPath(data.getInterpreterPath())));
    commandLine.getParametersList().set(2, "0");
    commandLine.getParametersList().set(3, "0");

    myCommandLine = commandLine.getCommandLineString();

    try {
      myRemoteCredentials = data.getRemoteSdkCredentials(true);
      PathMappingSettings mappings = manager.setupMappings(getProject(), data, null);

      RemoteSshProcess remoteProcess =
          manager.createRemoteProcess(
              getProject(), myRemoteCredentials, mappings, commandLine, true);

      Couple<Integer> remotePorts = getRemotePortsFromProcess(remoteProcess);

      remoteProcess.addLocalTunnel(myPorts[0], myRemoteCredentials.getHost(), remotePorts.first);
      remoteProcess.addRemoteTunnel(remotePorts.second, "localhost", myPorts[1]);

      myPydevConsoleCommunication =
          new PydevRemoteConsoleCommunication(getProject(), myPorts[0], remoteProcess, myPorts[1]);
      return remoteProcess;
    } catch (Exception e) {
      throw new ExecutionException(e.getMessage());
    }
  }
    @Override
    protected VirtualFile[] doAddItems() {
      Project project =
          CommonDataKeys.PROJECT.getData(DataManager.getInstance().getDataContext(myPanel));
      try {
        String[] files =
            PythonRemoteInterpreterManager.getInstance()
                .chooseRemoteFiles(
                    project, (PyRemoteSdkAdditionalDataBase) mySdk.getSdkAdditionalData(), false);

        final String sourcesLocalPath = PySdkUtil.getRemoteSourcesLocalPath(mySdk.getHomePath());

        VirtualFile[] vFiles = new VirtualFile[files.length];

        int i = 0;
        for (String file : files) {
          String localRoot = PyRemoteSourceItem.localPathForRemoteRoot(sourcesLocalPath, file);

          myNewMappings.add(new PathMappingSettings.PathMapping(localRoot, file));
          myRemoteSdkData.getPathMappings().addMappingCheckUnique(localRoot, file);

          if (!new File(localRoot).exists()) {
            new File(localRoot).mkdirs();
          }
          vFiles[i++] =
              LocalFileSystem.getInstance().refreshAndFindFileByIoFile(new File(localRoot));
        }

        vFiles = adjustAddedFileSet(myPanel, vFiles);
        List<VirtualFile> added = new ArrayList<VirtualFile>(vFiles.length);
        for (VirtualFile vFile : vFiles) {
          if (addElement(vFile)) {
            added.add(vFile);
          }
        }
        return VfsUtilCore.toVirtualFileArray(added);
      } catch (Exception e) {
        LOG.error(e);
      }
      return new VirtualFile[0];
    }
  public boolean validateConfiguration(CompileScope scope) {

    // Check for project sdk only if experimental make system is enabled (for now)
    Sdk projectSdk = ProjectRootManager.getInstance(project).getProjectSdk();
    if (projectSdk == null) {
      Messages.showErrorDialog(
          project,
          GoBundle.message("cannot.compile.no.go.project.sdk", project.getName()),
          GoBundle.message("cannot.compile"));
      return false;

    } else if (!(projectSdk.getSdkAdditionalData() instanceof GoSdkData)) {
      Messages.showErrorDialog(
          project,
          GoBundle.message("cannot.compile.invalid.project.sdk", project.getName()),
          GoBundle.message("cannot.compile"));
      return false;
    }

    return true;
  }
  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;
    //        }
    //      }
    //    }
  }
  @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);
    }
  }
 private GoSdkData goSdkData(Sdk sdk) {
   return (GoSdkData) sdk.getSdkAdditionalData();
 }
  @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();
  }