Search in sources :

Example 1 with GaugeSettingsModel

use of com.thoughtworks.gauge.settings.GaugeSettingsModel in project Intellij-Plugin by getgauge.

the class GaugeModuleComponent method initializeGaugeProcess.

private static Process initializeGaugeProcess(int apiPort, Module module) {
    try {
        GaugeSettingsModel settings = getGaugeSettings();
        String port = String.valueOf(apiPort);
        ProcessBuilder gauge = new ProcessBuilder(settings.getGaugePath(), Constants.DAEMON, port);
        GaugeUtil.setGaugeEnvironmentsTo(gauge, settings);
        String cp = classpathForModule(module);
        LOG.info(String.format("Setting `%s` to `%s`", Constants.GAUGE_CUSTOM_CLASSPATH, cp));
        gauge.environment().put(Constants.GAUGE_CUSTOM_CLASSPATH, cp);
        File dir = moduleDir(module);
        LOG.info(String.format("Using `%s` as api port to connect to gauge API for project %s", port, dir));
        gauge.directory(dir);
        Process process = gauge.start();
        new GaugeExceptionHandler(process, module.getProject()).start();
        return process;
    } catch (IOException | GaugeNotFoundException e) {
        LOG.error("An error occurred while starting gauge api. \n" + e);
    }
    return null;
}
Also used : GaugeNotFoundException(com.thoughtworks.gauge.exception.GaugeNotFoundException) GaugeExceptionHandler(com.thoughtworks.gauge.core.GaugeExceptionHandler) IOException(java.io.IOException) File(java.io.File) GaugeSettingsModel(com.thoughtworks.gauge.settings.GaugeSettingsModel)

Example 2 with GaugeSettingsModel

use of com.thoughtworks.gauge.settings.GaugeSettingsModel in project Intellij-Plugin by getgauge.

the class GaugeCommandLine method getInstance.

public static GeneralCommandLine getInstance(Module module, Project project) {
    GeneralCommandLine commandLine = new GeneralCommandLine();
    try {
        GaugeSettingsModel settings = GaugeUtil.getGaugeSettings();
        commandLine.setExePath(settings.getGaugePath());
        Map<String, String> environment = commandLine.getEnvironment();
        environment.put(Constants.GAUGE_HOME, settings.getHomePath());
    } catch (GaugeNotFoundException e) {
        commandLine.setExePath(Constants.GAUGE);
    } finally {
        commandLine.setWorkDirectory(project.getBasePath());
        if (module != null)
            commandLine.setWorkDirectory(GaugeUtil.moduleDir(module));
        return commandLine;
    }
}
Also used : GaugeNotFoundException(com.thoughtworks.gauge.exception.GaugeNotFoundException) GeneralCommandLine(com.intellij.execution.configurations.GeneralCommandLine) GaugeSettingsModel(com.thoughtworks.gauge.settings.GaugeSettingsModel)

Example 3 with GaugeSettingsModel

use of com.thoughtworks.gauge.settings.GaugeSettingsModel in project Intellij-Plugin by getgauge.

the class GaugeUtil method getGaugeSettings.

public static GaugeSettingsModel getGaugeSettings() throws GaugeNotFoundException {
    GaugeSettingsModel settings = GaugeSettingsService.getSettings();
    LOG.info(settings.toString());
    if (settings.isGaugePathSet()) {
        LOG.info("Using Gauge plugin settings to get Gauge executable path.");
        return settings;
    }
    if (gaugeSettings == null)
        gaugeSettings = getSettingsFromPATH(settings);
    return gaugeSettings;
}
Also used : GaugeSettingsModel(com.thoughtworks.gauge.settings.GaugeSettingsModel)

Example 4 with GaugeSettingsModel

use of com.thoughtworks.gauge.settings.GaugeSettingsModel in project Intellij-Plugin by getgauge.

the class GaugeVersion method getVersion.

public static GaugeVersionInfo getVersion(Boolean update) {
    if (!update)
        return versionInfo;
    GaugeVersionInfo gaugeVersionInfo = new GaugeVersionInfo();
    try {
        GaugeSettingsModel settings = getGaugeSettings();
        ProcessBuilder processBuilder = new ProcessBuilder(settings.getGaugePath(), Constants.VERSION, Constants.MACHINE_READABLE);
        GaugeUtil.setGaugeEnvironmentsTo(processBuilder, settings);
        Process process = processBuilder.start();
        int exitCode = process.waitFor();
        if (exitCode == 0) {
            String output = GaugeUtil.getOutput(process.getInputStream(), "\n");
            GsonBuilder builder = new GsonBuilder();
            Gson gson = builder.create();
            gaugeVersionInfo = gson.fromJson(output, GaugeVersionInfo.class);
        }
    } catch (Exception ignored) {
    }
    versionInfo = gaugeVersionInfo;
    return gaugeVersionInfo;
}
Also used : GsonBuilder(com.google.gson.GsonBuilder) Gson(com.google.gson.Gson) GaugeSettingsModel(com.thoughtworks.gauge.settings.GaugeSettingsModel)

Example 5 with GaugeSettingsModel

use of com.thoughtworks.gauge.settings.GaugeSettingsModel in project Intellij-Plugin by getgauge.

the class SpecFormatter method actionPerformed.

@Override
public void actionPerformed(AnActionEvent anActionEvent) {
    final Project project = anActionEvent.getData(LangDataKeys.PROJECT);
    if (project == null) {
        return;
    }
    String projectDir = project.getBasePath();
    if (projectDir == null) {
        return;
    }
    FileEditorManager fileEditorManager = FileEditorManager.getInstance(project);
    VirtualFile selectedFile = fileEditorManager.getSelectedFiles()[0];
    String fileName = selectedFile.getCanonicalPath();
    Document doc = FileDocumentManager.getInstance().getDocument(selectedFile);
    if (doc != null) {
        FileDocumentManager.getInstance().saveDocument(doc);
    }
    try {
        GaugeSettingsModel settings = getGaugeSettings();
        ProcessBuilder processBuilder = new ProcessBuilder(settings.getGaugePath(), Constants.FORMAT, fileName);
        GaugeUtil.setGaugeEnvironmentsTo(processBuilder, settings);
        processBuilder.directory(new File(projectDir));
        Process process = processBuilder.start();
        int exitCode = process.waitFor();
        if (exitCode != 0) {
            String output = String.format("<pre>%s</pre>", GaugeUtil.getOutput(process.getInputStream(), "\n").replace("<", "&lt;").replace(">", "&gt;"));
            Notifications.Bus.notify(new Notification("Spec Formatting", "Error: Spec Formatting", output, NotificationType.ERROR));
            return;
        }
        VirtualFileManager.getInstance().syncRefresh();
        selectedFile.refresh(false, false);
    } catch (Exception e) {
        e.printStackTrace();
        Messages.showErrorDialog("Error on formatting spec", "Format Error");
    }
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) FileEditorManager(com.intellij.openapi.fileEditor.FileEditorManager) Document(com.intellij.openapi.editor.Document) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Notification(com.intellij.notification.Notification) GaugeSettingsModel(com.thoughtworks.gauge.settings.GaugeSettingsModel)

Aggregations

GaugeSettingsModel (com.thoughtworks.gauge.settings.GaugeSettingsModel)8 GaugeNotFoundException (com.thoughtworks.gauge.exception.GaugeNotFoundException)4 File (java.io.File)3 IOException (java.io.IOException)3 VirtualFile (com.intellij.openapi.vfs.VirtualFile)2 Gson (com.google.gson.Gson)1 GsonBuilder (com.google.gson.GsonBuilder)1 GeneralCommandLine (com.intellij.execution.configurations.GeneralCommandLine)1 Notification (com.intellij.notification.Notification)1 Document (com.intellij.openapi.editor.Document)1 FileEditorManager (com.intellij.openapi.fileEditor.FileEditorManager)1 Project (com.intellij.openapi.project.Project)1 PsiFile (com.intellij.psi.PsiFile)1 GaugeExceptionHandler (com.thoughtworks.gauge.core.GaugeExceptionHandler)1 SpecFile (com.thoughtworks.gauge.language.SpecFile)1 ArrayList (java.util.ArrayList)1 NotNull (org.jetbrains.annotations.NotNull)1 Nullable (org.jetbrains.annotations.Nullable)1