Search in sources :

Example 1 with GoRunConfigurationBase

use of com.goide.runconfig.GoRunConfigurationBase 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 GoRunConfigurationBase

use of com.goide.runconfig.GoRunConfigurationBase in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoBeforeRunTaskProvider method configureTask.

@Override
public boolean configureTask(RunConfiguration configuration, GoCommandBeforeRunTask task) {
    Project project = configuration.getProject();
    if (!(configuration instanceof GoRunConfigurationBase)) {
        showAddingTaskErrorMessage(project, "Go Command task supports only Go Run Configurations");
        return false;
    }
    Module module = ((GoRunConfigurationBase) configuration).getConfigurationModule().getModule();
    if (!GoSdkService.getInstance(project).isGoModule(module)) {
        showAddingTaskErrorMessage(project, "Go Command task supports only Go Modules");
        return false;
    }
    GoCommandConfigureDialog dialog = new GoCommandConfigureDialog(project);
    if (dialog.showAndGet()) {
        task.setCommand(dialog.getCommand());
        return true;
    }
    return false;
}
Also used : Project(com.intellij.openapi.project.Project) GoRunConfigurationBase(com.goide.runconfig.GoRunConfigurationBase) Module(com.intellij.openapi.module.Module)

Example 3 with GoRunConfigurationBase

use of com.goide.runconfig.GoRunConfigurationBase 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)

Example 4 with GoRunConfigurationBase

use of com.goide.runconfig.GoRunConfigurationBase in project go-lang-idea-plugin by go-lang-plugin-org.

the class GoTestConsoleProperties method initScope.

@NotNull
@Override
protected GlobalSearchScope initScope() {
    RunProfile configuration = getConfiguration();
    if (configuration instanceof GoTestRunConfiguration) {
        Project project = ((GoTestRunConfiguration) configuration).getProject();
        Module module = ((GoTestRunConfiguration) configuration).getConfigurationModule().getModule();
        switch(((GoTestRunConfiguration) configuration).getKind()) {
            case DIRECTORY:
                String directoryUrl = VfsUtilCore.pathToUrl(((GoTestRunConfiguration) configuration).getDirectoryPath());
                VirtualFile directory = VirtualFileManager.getInstance().findFileByUrl(directoryUrl);
                if (directory != null) {
                    return GlobalSearchScopesCore.directoryScope(project, directory, true);
                }
                break;
            case PACKAGE:
                VirtualFile packageDir = GoPackageUtil.findByImportPath(((GoTestRunConfiguration) configuration).getPackage(), project, module);
                PsiDirectory psiDirectory = packageDir != null ? PsiManager.getInstance(project).findDirectory(packageDir) : null;
                if (psiDirectory != null) {
                    return GoPackageUtil.packageScope(psiDirectory, null);
                }
                break;
            case FILE:
                String fileUrl = VfsUtilCore.pathToUrl(((GoTestRunConfiguration) configuration).getFilePath());
                VirtualFile file = VirtualFileManager.getInstance().findFileByUrl(fileUrl);
                if (file != null) {
                    return GlobalSearchScope.fileScope(project, file);
                }
                break;
        }
    }
    if (configuration instanceof GoRunConfigurationBase) {
        GlobalSearchScope scope = GlobalSearchScope.EMPTY_SCOPE;
        for (Module module : ((GoRunConfigurationBase) configuration).getModules()) {
            scope = new GoUtil.TestsScope(GoUtil.goPathResolveScope(module, null));
        }
        return scope;
    }
    return super.initScope();
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) Project(com.intellij.openapi.project.Project) GoRunConfigurationBase(com.goide.runconfig.GoRunConfigurationBase) GlobalSearchScope(com.intellij.psi.search.GlobalSearchScope) PsiDirectory(com.intellij.psi.PsiDirectory) GoUtil(com.goide.util.GoUtil) RunProfile(com.intellij.execution.configurations.RunProfile) Module(com.intellij.openapi.module.Module) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

GoRunConfigurationBase (com.goide.runconfig.GoRunConfigurationBase)4 Module (com.intellij.openapi.module.Module)4 Project (com.intellij.openapi.project.Project)3 GoSdkService (com.goide.sdk.GoSdkService)2 GoIcons (com.goide.GoIcons)1 GoExecutor (com.goide.util.GoExecutor)1 GoUtil (com.goide.util.GoUtil)1 BeforeRunTaskProvider (com.intellij.execution.BeforeRunTaskProvider)1 RunConfiguration (com.intellij.execution.configurations.RunConfiguration)1 RunProfile (com.intellij.execution.configurations.RunProfile)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 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 VirtualFile (com.intellij.openapi.vfs.VirtualFile)1 VirtualFileManager (com.intellij.openapi.vfs.VirtualFileManager)1