<commit_before>package com.phrase.intellij;

import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.process.CapturingProcessHandler;
import com.intellij.execution.process.ProcessEvent;
import com.intellij.execution.process.ProcessListener;
import com.intellij.ide.plugins.IdeaPluginDescriptor;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.extensions.PluginId;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.phrase.intellij.ui.ColorTextPane;
import org.jetbrains.annotations.NotNull;

import java.awt.*;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by kolja on 15.10.15.
 */
public class PushPullAdapter {
    private String clientPath;
    private String projectPath;
    private ToolWindowHelper outputWindowHelper;
    private SimpleDateFormat sdf;

    public PushPullAdapter(final String path, Project project) {
        clientPath = path;
        projectPath = project.getBasePath();
        outputWindowHelper = new ToolWindowHelper(project);
        sdf = new SimpleDateFormat("HH:mm:ss");
    }

    public void run(final String clientAction) {

        if (outputWindowHelper.getOutputWindow().isActive()) {
            final ColorTextPane finalArea = outputWindowHelper.getColorTextPane();
            outputWindowHelper.getOutputWindow().show(new Runnable() {
                @Override
                public void run() {
                    runCommand(clientAction, finalArea);
                }
            });
        } else {
            outputWindowHelper.getOutputWindow().activate(new Runnable() {
                @Override
                public void run() {
                    runCommand(clientAction, outputWindowHelper.getColorTextPane());
                }
            });
        }
    }

    private void runCommand(final String clientAction, final ColorTextPane finalArea) {
        try {
            GeneralCommandLine gcl = new GeneralCommandLine(clientPath,
                    clientAction);
            gcl.withWorkDirectory(projectPath);

            PluginId pluginId = com.intellij.ide.plugins.PluginManager.getPluginByClassName(getClass().getName());

            final CapturingProcessHandler processHandler = new CapturingProcessHandler(gcl.createProcess(), Charset.defaultCharset(), gcl.getCommandLineString());
            processHandler.addProcessListener(new ProcessListener() {
                @Override
                public void startNotified(ProcessEvent event) {<commit_msg>Add Android Studio user agent<commit_after>package com.phrase.intellij;

import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.process.CapturingProcessHandler;
import com.intellij.execution.process.ProcessEvent;
import com.intellij.execution.process.ProcessListener;
import com.intellij.notification.Notification;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.application.ApplicationManager;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.Key;
import com.phrase.intellij.ui.ColorTextPane;
import org.jetbrains.annotations.NotNull;

import java.awt.*;
import java.nio.charset.Charset;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.HashMap;
import java.util.Map;

/**
 * Created by kolja on 15.10.15.
 */
public class PushPullAdapter {
    private String clientPath;
    private String projectPath;
    private ToolWindowHelper outputWindowHelper;
    private SimpleDateFormat sdf;

    public PushPullAdapter(final String path, Project project) {
        clientPath = path;
        projectPath = project.getBasePath();
        outputWindowHelper = new ToolWindowHelper(project);
        sdf = new SimpleDateFormat("HH:mm:ss");
    }

    public void run(final String clientAction) {

        if (outputWindowHelper.getOutputWindow().isActive()) {
            final ColorTextPane finalArea = outputWindowHelper.getColorTextPane();
            outputWindowHelper.getOutputWindow().show(new Runnable() {
                @Override
                public void run() {
                    runCommand(clientAction, finalArea);
                }
            });
        } else {
            outputWindowHelper.getOutputWindow().activate(new Runnable() {
                @Override
                public void run() {
                    runCommand(clientAction, outputWindowHelper.getColorTextPane());
                }
            });
        }
    }

    private void runCommand(final String clientAction, final ColorTextPane finalArea) {
        try {
            GeneralCommandLine gcl = new GeneralCommandLine(clientPath,
                    clientAction);
            gcl.withWorkDirectory(projectPath);

            Map env = new HashMap<String, String>();
            env.put("PHRASE_USER_AGENT", "AndroidStudio");
            gcl.withEnvironment(env);

            final CapturingProcessHandler processHandler = new CapturingProcessHandler(gcl.createProcess(), Charset.defaultCharset(), gcl.getCommandLineString());
            processHandler.addProcessListener(new ProcessListener() {
                @Override
                public void startNotified(ProcessEvent event) {
{'fraction_non_alphanumeric': 0.08757062146892655, 'fraction_numerical': 0.00211864406779661, 'mean_word_length': 3.0814121037463975, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '968019', 'n_tokens_mistral': 1497, 'n_tokens_neox': 1430, 'n_words': 285}