Search in sources :

Example 6 with GaugeService

use of com.thoughtworks.gauge.core.GaugeService in project Intellij-Plugin by getgauge.

the class GaugeRefactorHandler method refactor.

private void refactor(String currentStepText, String newStepText, TransactionId contextTransaction, CompileContext context, RefactorStatusCallback refactorStatusCallback) {
    refactorStatusCallback.onStatusChange("Refactoring...");
    Module module = GaugeUtil.moduleForPsiElement(file);
    TransactionGuard.getInstance().submitTransaction(() -> {
    }, contextTransaction, () -> {
        Api.PerformRefactoringResponse response = null;
        FileDocumentManager.getInstance().saveAllDocuments();
        FileDocumentManager.getInstance().saveDocumentAsIs(editor.getDocument());
        GaugeService gaugeService = Gauge.getGaugeService(module, true);
        try {
            response = gaugeService.getGaugeConnection().sendPerformRefactoringRequest(currentStepText, newStepText);
        } catch (Exception e) {
            refactorStatusCallback.onFinish(new RefactoringStatus(false, String.format("Could not execute refactor command: %s", e.toString())));
            return;
        }
        new UndoHandler(response.getFilesChangedList(), module.getProject(), "Refactoring").handle();
        if (!response.getSuccess()) {
            showMessage(response, context, refactorStatusCallback);
            return;
        }
        refactorStatusCallback.onFinish(new RefactoringStatus(true));
    });
}
Also used : GaugeService(com.thoughtworks.gauge.core.GaugeService) UndoHandler(com.thoughtworks.gauge.undo.UndoHandler) Api(gauge.messages.Api) Module(com.intellij.openapi.module.Module)

Example 7 with GaugeService

use of com.thoughtworks.gauge.core.GaugeService in project Intellij-Plugin by getgauge.

the class GaugeLibHelper method gaugeLib.

private ProjectLib gaugeLib(Module module) {
    String libRoot;
    try {
        GaugeService gaugeService = Gauge.getGaugeService(module, true);
        if (gaugeService == null) {
            gaugeService = GaugeModuleComponent.createGaugeService(module);
        }
        GaugeConnection gaugeConnection = gaugeService.getGaugeConnection();
        if (gaugeConnection == null) {
            throw new IOException("Gauge api connection not established");
        }
        libRoot = gaugeConnection.getLibPath("java");
    } catch (IOException e) {
        System.err.println("Could not add gauge lib, add it manually: " + e.getMessage());
        LOG.debug("Could not add gauge lib, add it manually: " + e.getMessage());
        return null;
    } catch (PluginNotInstalledException e) {
        throw new RuntimeException("Gauge " + JAVA + " plugin is not installed.");
    }
    return new ProjectLib(GAUGE_LIB, new File(libRoot));
}
Also used : GaugeService(com.thoughtworks.gauge.core.GaugeService) GaugeConnection(com.thoughtworks.gauge.connection.GaugeConnection) IOException(java.io.IOException) PluginNotInstalledException(com.thoughtworks.gauge.PluginNotInstalledException) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File)

Example 8 with GaugeService

use of com.thoughtworks.gauge.core.GaugeService in project Intellij-Plugin by getgauge.

the class StepCompletionProvider method getStepsInModule.

private Collection<Type> getStepsInModule(Module module) {
    Map<String, Type> steps = getImplementedSteps(module);
    try {
        GaugeService gaugeService = Gauge.getGaugeService(module, true);
        if (gaugeService == null)
            return steps.values();
        GaugeConnection gaugeConnection = gaugeService.getGaugeConnection();
        if (gaugeConnection != null) {
            gaugeConnection.fetchAllSteps().forEach(s -> addStep(steps, s, STEP));
            gaugeConnection.fetchAllConcepts().forEach(concept -> addStep(steps, concept.getStepValue(), CONCEPT));
        }
    } catch (IOException ignored) {
        LOG.debug(ignored);
    }
    return steps.values();
}
Also used : GaugeService(com.thoughtworks.gauge.core.GaugeService) GaugeConnection(com.thoughtworks.gauge.connection.GaugeConnection) IOException(java.io.IOException)

Example 9 with GaugeService

use of com.thoughtworks.gauge.core.GaugeService in project Intellij-Plugin by getgauge.

the class GaugeModuleComponent method createGaugeService.

/**
 * Creates a gauge service for the particular module. GaugeService is used to make api calls to the gauge daemon process.
 *
 * @param module
 * @return
 */
public static GaugeService createGaugeService(Module module) {
    int freePortForApi = SocketUtils.findFreePortForApi();
    Process gaugeProcess = initializeGaugeProcess(freePortForApi, module);
    GaugeConnection gaugeConnection = initializeGaugeConnection(freePortForApi);
    GaugeService gaugeService = new GaugeService(gaugeProcess, gaugeConnection);
    Gauge.addModule(module, gaugeService);
    return gaugeService;
}
Also used : GaugeService(com.thoughtworks.gauge.core.GaugeService) GaugeConnection(com.thoughtworks.gauge.connection.GaugeConnection)

Aggregations

GaugeService (com.thoughtworks.gauge.core.GaugeService)9 StepValue (com.thoughtworks.gauge.StepValue)4 GaugeConnection (com.thoughtworks.gauge.connection.GaugeConnection)4 TextRange (com.intellij.openapi.util.TextRange)2 IOException (java.io.IOException)2 Module (com.intellij.openapi.module.Module)1 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 PluginNotInstalledException (com.thoughtworks.gauge.PluginNotInstalledException)1 UndoHandler (com.thoughtworks.gauge.undo.UndoHandler)1 Api (gauge.messages.Api)1 File (java.io.File)1