package com.reason.bs;

import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.process.KillableColoredProcessHandler;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.process.ProcessListener;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.vfs.VirtualFile;
import com.reason.ide.RmlNotification;
import org.jetbrains.annotations.Nullable;

public class BsCompiler {

    private KillableColoredProcessHandler m_bsb;
    private GeneralCommandLine m_commandLine;
    private ProcessListener m_outputListener;

    BsCompiler(VirtualFile baseDir, String bsbPath) {
        m_commandLine = new GeneralCommandLine(bsbPath, "-color", "-make-world").
                withWorkDirectory(baseDir.getCanonicalPath());
        recreate();
    }

    @Nullable
    public ProcessHandler getHandler() {
        return m_bsb;
    }

    // Wait for the tool window to be ready before starting the process
    public void startNotify() {
        if (m_bsb != null && !m_bsb.isStartNotified()) {
            try {
                m_bsb.startNotify();
            } catch (Throwable e) {
                // already done ?
            }
        }
    }

    @Nullable
    public ProcessHandler recreate() {
        try {
            killIt();
            m_bsb = new KillableColoredProcessHandler(m_commandLine);
            if (m_outputListener != null) {
                m_bsb.addProcessListener(m_outputListener);
            }
            return m_bsb;
        } catch (ExecutionException e) {
            Notifications.Bus.notify(new RmlNotification("Bsb", "Can't run bsb\n" + e.getMessage(), NotificationType.ERROR));
        }

        return null;
    }

    void killIt() {
        if (m_bsb != null) {
            m_bsb.killProcess();
            m_bsb = null;
        }
    }

    public void addListener(ProcessListener outputListener) {
        m_outputListener = outputListener;
        if (m_bsb != null) {
            m_bsb.addProcessListener(outputListener);
        }
    }
}

package com.reason.bs;

import com.intellij.execution.ExecutionException;
import com.intellij.execution.configurations.GeneralCommandLine;
import com.intellij.execution.process.KillableColoredProcessHandler;
import com.intellij.execution.process.ProcessHandler;
import com.intellij.execution.process.ProcessListener;
import com.intellij.notification.NotificationType;
import com.intellij.notification.Notifications;
import com.intellij.openapi.vfs.VirtualFile;
import com.reason.ide.RmlNotification;
import org.jetbrains.annotations.Nullable;

public class BsCompiler {

    private KillableColoredProcessHandler m_bsb;
    private GeneralCommandLine m_fullCommandLine;
    private GeneralCommandLine m_standardCommandLine;
    private ProcessListener m_outputListener;
    private boolean m_firstRun = true;

    BsCompiler(VirtualFile baseDir, String bsbPath) {
        String canonicalPath = baseDir.getCanonicalPath();
        m_fullCommandLine = new GeneralCommandLine(bsbPath, "-clean-world", "-make-world").withWorkDirectory(canonicalPath);
        m_standardCommandLine = new GeneralCommandLine(bsbPath).withWorkDirectory(canonicalPath);
        recreate();
    }

    @Nullable
    public ProcessHandler getHandler() {
        return m_bsb;
    }

    // Wait for the tool window to be ready before starting the process
    public void startNotify() {
        if (m_bsb != null && !m_bsb.isStartNotified()) {
            try {
                m_bsb.startNotify();
            } catch (Throwable e) {
                // already done ?
            }
        }
    }

    @Nullable
    public ProcessHandler recreate() {
        try {
            killIt();
            m_bsb = new KillableColoredProcessHandler(m_firstRun ? m_fullCommandLine : m_standardCommandLine);
            if (m_outputListener != null) {
                m_bsb.addProcessListener(m_outputListener);
            }
            m_firstRun = false;
            return m_bsb;
        } catch (ExecutionException e) {
            Notifications.Bus.notify(new RmlNotification("Bsb", "Can't run bsb\n" + e.getMessage(), NotificationType.ERROR));
        }

        return null;
    }

    void killIt() {
        if (m_bsb != null) {
            m_bsb.killProcess();
            m_bsb = null;
        }
    }

    public void addListener(ProcessListener outputListener) {
        m_outputListener = outputListener;
        if (m_bsb != null) {
            m_bsb.addProcessListener(outputListener);
        }
    }
}

use full and standard cli