Search in sources :

Example 1 with GoSdkService

use of com.goide.sdk.GoSdkService in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoBeforeRunTaskProvider method canExecuteTask.

@Override
public boolean canExecuteTask(RunConfiguration configuration, GoCommandBeforeRunTask task) {
    if (configuration instanceof GoRunConfigurationBase) {
        Module module = ((GoRunConfigurationBase) configuration).getConfigurationModule().getModule();
        GoSdkService sdkService = GoSdkService.getInstance(configuration.getProject());
        if (sdkService.isGoModule(module)) {
            return StringUtil.isNotEmpty(sdkService.getSdkHomePath(module)) && StringUtil.isNotEmpty(task.getCommand());
        }
    }
    return false;
}
Also used : GoSdkService(com.goide.sdk.GoSdkService) GoRunConfigurationBase(com.goide.runconfig.GoRunConfigurationBase) Module(com.intellij.openapi.module.Module)

Example 2 with GoSdkService

use of com.goide.sdk.GoSdkService in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoBeforeRunTaskProvider method executeTask.

@Override
public boolean executeTask(DataContext context, RunConfiguration configuration, ExecutionEnvironment env, GoCommandBeforeRunTask task) {
    Semaphore done = new Semaphore();
    Ref<Boolean> result = Ref.create(false);
    GoRunConfigurationBase goRunConfiguration = (GoRunConfigurationBase) configuration;
    Module module = goRunConfiguration.getConfigurationModule().getModule();
    Project project = configuration.getProject();
    String workingDirectory = goRunConfiguration.getWorkingDirectory();
    UIUtil.invokeAndWaitIfNeeded(new Runnable() {

        @Override
        public void run() {
            if (StringUtil.isEmpty(task.getCommand()))
                return;
            if (project == null || project.isDisposed())
                return;
            GoSdkService sdkService = GoSdkService.getInstance(project);
            if (!sdkService.isGoModule(module))
                return;
            done.down();
            GoExecutor.in(module).withParameterString(task.getCommand()).withWorkDirectory(workingDirectory).showOutputOnError().showNotifications(false, true).withPresentableName("Executing `" + task + "`").withProcessListener(new ProcessAdapter() {

                @Override
                public void processTerminated(ProcessEvent event) {
                    done.up();
                    result.set(event.getExitCode() == 0);
                }
            }).executeWithProgress(false, result1 -> VirtualFileManager.getInstance().asyncRefresh(null));
        }
    });
    done.waitFor();
    return result.get();
}
Also used : UIUtil(com.intellij.util.ui.UIUtil) GoRunConfigurationBase(com.goide.runconfig.GoRunConfigurationBase) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) DataContext(com.intellij.openapi.actionSystem.DataContext) GoIcons(com.goide.GoIcons) StringUtil(com.intellij.openapi.util.text.StringUtil) GoExecutor(com.goide.util.GoExecutor) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) Key(com.intellij.openapi.util.Key) VirtualFileManager(com.intellij.openapi.vfs.VirtualFileManager) GoSdkService(com.goide.sdk.GoSdkService) Nullable(org.jetbrains.annotations.Nullable) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Semaphore(com.intellij.util.concurrency.Semaphore) BeforeRunTaskProvider(com.intellij.execution.BeforeRunTaskProvider) Project(com.intellij.openapi.project.Project) ProcessEvent(com.intellij.execution.process.ProcessEvent) Messages(com.intellij.openapi.ui.Messages) Module(com.intellij.openapi.module.Module) Ref(com.intellij.openapi.util.Ref) javax.swing(javax.swing) ProcessAdapter(com.intellij.execution.process.ProcessAdapter) ProcessEvent(com.intellij.execution.process.ProcessEvent) Semaphore(com.intellij.util.concurrency.Semaphore) GoSdkService(com.goide.sdk.GoSdkService) GoRunConfigurationBase(com.goide.runconfig.GoRunConfigurationBase) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module)

Aggregations

GoRunConfigurationBase (com.goide.runconfig.GoRunConfigurationBase)2 GoSdkService (com.goide.sdk.GoSdkService)2 Module (com.intellij.openapi.module.Module)2 GoIcons (com.goide.GoIcons)1 GoExecutor (com.goide.util.GoExecutor)1 BeforeRunTaskProvider (com.intellij.execution.BeforeRunTaskProvider)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)1 ProcessEvent (com.intellij.execution.process.ProcessEvent)1 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)1 DataContext (com.intellij.openapi.actionSystem.DataContext)1 Project (com.intellij.openapi.project.Project)1 Messages (com.intellij.openapi.ui.Messages)1 Key (com.intellij.openapi.util.Key)1 Ref (com.intellij.openapi.util.Ref)1 StringUtil (com.intellij.openapi.util.text.StringUtil)1 VirtualFileManager (com.intellij.openapi.vfs.VirtualFileManager)1 Semaphore (com.intellij.util.concurrency.Semaphore)1 UIUtil (com.intellij.util.ui.UIUtil)1 javax.swing (javax.swing)1