Пример #1
0
 public static void logFile(String file, boolean isWrite) {
   ArrayList<String> cmds = new ArrayList<String>();
   cmds.add(Dependencies.getPythonLocation());
   cmds.add(Dependencies.getCLILocation());
   cmds.add("--file");
   cmds.add(file);
   String project = WakaTime.getProjectName();
   if (project != null) {
     cmds.add("--project");
     cmds.add(project);
   }
   cmds.add("--plugin");
   cmds.add(IDE_NAME + "/" + IDE_VERSION + " " + IDE_NAME + "-wakatime/" + VERSION);
   if (isWrite) cmds.add("--write");
   try {
     log.debug("Executing CLI: " + Arrays.toString(cmds.toArray()));
     Process proc = Runtime.getRuntime().exec(cmds.toArray(new String[cmds.size()]));
     if (WakaTime.DEBUG) {
       BufferedReader stdInput = new BufferedReader(new InputStreamReader(proc.getInputStream()));
       BufferedReader stdError = new BufferedReader(new InputStreamReader(proc.getErrorStream()));
       proc.waitFor();
       String s;
       while ((s = stdInput.readLine()) != null) {
         log.debug(s);
       }
       while ((s = stdError.readLine()) != null) {
         log.debug(s);
       }
       log.debug("Command finished with return value: " + proc.exitValue());
     }
   } catch (Exception e) {
     log.error(e);
   }
 }
Пример #2
0
  public void initComponent() {
    log.info("Initializing WakaTime plugin v" + VERSION + " (https://wakatime.com/)");
    // System.out.println("Initializing WakaTime plugin v" + VERSION + " (https://wakatime.com/)");

    // Set runtime constants
    IDE_NAME = PlatformUtils.getPlatformPrefix();
    IDE_VERSION = ApplicationInfo.getInstance().getFullVersion();

    if (!Dependencies.isCLIInstalled()) {
      log.info("Downloading and installing wakatime-cli ...");
      Dependencies.installCLI();
    } else if (Dependencies.isCLIOld()) {
      log.info("Upgrading wakatime-cli ...");
      Dependencies.upgradeCLI();
    }

    if (Dependencies.isPythonInstalled()) {

      WakaTime.DEBUG = WakaTime.isDebugEnabled();
      if (WakaTime.DEBUG) {
        log.setLevel(Level.DEBUG);
        log.debug("Logging level set to DEBUG");
      }

      log.debug("Python location: " + Dependencies.getPythonLocation());
      log.debug("CLI location: " + Dependencies.getCLILocation());

      // prompt for apiKey if it does not already exist
      if (ApiKey.getApiKey().equals("")) {
        Project project = ProjectManager.getInstance().getDefaultProject();
        ApiKey apiKey = new ApiKey(project);
        apiKey.promptForApiKey();
      }
      log.debug("Api Key: " + ApiKey.getApiKey());

      // add WakaTime item to File menu
      ActionManager am = ActionManager.getInstance();
      PluginMenu action = new PluginMenu();
      am.registerAction("WakaTimeApiKey", action);
      DefaultActionGroup fileMenu = (DefaultActionGroup) am.getAction("FileMenu");
      fileMenu.addSeparator();
      fileMenu.add(action);

      // Setup message listeners
      MessageBus bus = ApplicationManager.getApplication().getMessageBus();
      connection = bus.connect();
      connection.subscribe(AppTopics.FILE_DOCUMENT_SYNC, new CustomSaveListener());
      EditorFactory.getInstance()
          .getEventMulticaster()
          .addDocumentListener(new CustomDocumentListener());

      log.debug("Finished initializing WakaTime plugin");

    } else {
      Messages.showErrorDialog(
          "WakaTime requires Python to be installed.\nYou can install it from https://www.python.org/downloads/\nAfter installing Python, restart your IDE.",
          "Error");
    }
  }