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;
}
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;
}
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();
}
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();
}
Aggregations