use of com.intellij.execution.configurations.RunConfiguration 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.intellij.execution.configurations.RunConfiguration in project intellij-community by JetBrains.
the class SearchEverywhereAction method findExecutor.
@Nullable
public Executor findExecutor(@NotNull RunnerAndConfigurationSettings settings) {
final Executor runExecutor = DefaultRunExecutor.getRunExecutorInstance();
final Executor debugExecutor = ExecutorRegistry.getInstance().getExecutorById(ToolWindowId.DEBUG);
Executor executor = ourShiftIsPressed.get() ? runExecutor : debugExecutor;
RunConfiguration runConf = settings.getConfiguration();
if (executor == null || runConf == null) {
return null;
}
ProgramRunner runner = RunnerRegistry.getInstance().getRunner(executor.getId(), runConf);
if (runner == null) {
executor = runExecutor == executor ? debugExecutor : runExecutor;
}
return executor;
}
use of com.intellij.execution.configurations.RunConfiguration in project intellij-community by JetBrains.
the class JavaScratchCompilationSupport method execute.
@Override
public boolean execute(CompileContext context) {
final Project project = context.getProject();
final RunConfiguration configuration = CompileStepBeforeRun.getRunConfiguration(context);
if (!(configuration instanceof JavaScratchConfiguration)) {
return true;
}
final JavaScratchConfiguration scratchConfig = (JavaScratchConfiguration) configuration;
final String scratchUrl = scratchConfig.getScratchFileUrl();
if (scratchUrl == null) {
context.addMessage(CompilerMessageCategory.ERROR, "Associated scratch file not found", null, -1, -1);
return false;
}
@Nullable final Module module = scratchConfig.getConfigurationModule().getModule();
final Sdk targetSdk = module != null ? ModuleRootManager.getInstance(module).getSdk() : ProjectRootManager.getInstance(project).getProjectSdk();
if (targetSdk == null) {
final String message = module != null ? "Cannot find associated SDK for run configuration module \"" + module.getName() + "\".\nPlease check project settings." : "Cannot find associated project SDK for the run configuration.\nPlease check project settings.";
context.addMessage(CompilerMessageCategory.ERROR, message, scratchUrl, -1, -1);
return true;
}
if (!(targetSdk.getSdkType() instanceof JavaSdkType)) {
final String message = module != null ? "Expected Java SDK for run configuration module \"" + module.getName() + "\".\nPlease check project settings." : "Expected Java SDK for project \"" + project.getName() + "\".\nPlease check project settings.";
context.addMessage(CompilerMessageCategory.ERROR, message, scratchUrl, -1, -1);
return true;
}
final File outputDir = getScratchOutputDirectory(project);
if (outputDir == null) {
// should not happen for normal projects
return true;
}
// perform cleanup
FileUtil.delete(outputDir);
try {
final File scratchFile = new File(VirtualFileManager.extractPath(scratchUrl));
File srcFile = scratchFile;
if (!StringUtil.endsWith(srcFile.getName(), ".java")) {
final File srcDir = getScratchTempDirectory(project);
if (srcDir == null) {
// should not happen for normal projects
return true;
}
// perform cleanup
FileUtil.delete(srcDir);
final String srcFileName = ApplicationManager.getApplication().runReadAction(new Computable<String>() {
@Override
public String compute() {
final VirtualFile vFile = VirtualFileManager.getInstance().findFileByUrl(scratchUrl);
if (vFile != null) {
final PsiFile psiFile = PsiManager.getInstance(project).findFile(vFile);
if (psiFile instanceof PsiJavaFile) {
String name = null;
// take the name of the first found public top-level class, otherwise the name of any available top-level class
for (PsiClass aClass : ((PsiJavaFile) psiFile).getClasses()) {
if (name == null) {
name = aClass.getName();
if (isPublic(aClass)) {
break;
}
} else if (isPublic(aClass)) {
name = aClass.getName();
break;
}
}
if (name != null) {
return name;
}
}
}
return FileUtil.getNameWithoutExtension(scratchFile);
}
});
srcFile = new File(srcDir, srcFileName + ".java");
FileUtil.copy(scratchFile, srcFile);
}
final Collection<File> files = Collections.singleton(srcFile);
final Set<File> cp = new LinkedHashSet<>();
final List<File> platformCp = new ArrayList<>();
final Computable<OrderEnumerator> orderEnumerator = module != null ? (Computable<OrderEnumerator>) () -> ModuleRootManager.getInstance(module).orderEntries() : (Computable<OrderEnumerator>) () -> ProjectRootManager.getInstance(project).orderEntries();
ApplicationManager.getApplication().runReadAction(() -> {
for (String s : orderEnumerator.compute().compileOnly().recursively().exportedOnly().withoutSdk().getPathsList().getPathList()) {
cp.add(new File(s));
}
for (String s : orderEnumerator.compute().compileOnly().sdkOnly().getPathsList().getPathList()) {
platformCp.add(new File(s));
}
});
final List<String> options = new ArrayList<>();
// always compile with debug info
options.add("-g");
final JavaSdkVersion sdkVersion = JavaSdk.getInstance().getVersion(targetSdk);
if (sdkVersion != null) {
final String langLevel = "1." + Integer.valueOf(3 + sdkVersion.getMaxLanguageLevel().ordinal());
options.add("-source");
options.add(langLevel);
options.add("-target");
options.add(langLevel);
}
// disable annotation processing
options.add("-proc:none");
final Collection<ClassObject> result = CompilerManager.getInstance(project).compileJavaCode(options, platformCp, cp, Collections.emptyList(), Collections.emptyList(), files, outputDir);
for (ClassObject classObject : result) {
final byte[] bytes = classObject.getContent();
if (bytes != null) {
FileUtil.writeToFile(new File(classObject.getPath()), bytes);
}
}
} catch (CompilationException e) {
for (CompilationException.Message m : e.getMessages()) {
context.addMessage(m.getCategory(), m.getText(), scratchUrl, m.getLine(), m.getColumn());
}
} catch (IOException e) {
context.addMessage(CompilerMessageCategory.ERROR, e.getMessage(), scratchUrl, -1, -1);
}
return true;
}
use of com.intellij.execution.configurations.RunConfiguration in project intellij-community by JetBrains.
the class AbstractJavaTestConfigurationProducer method isConfigurationFromContext.
@Override
public boolean isConfigurationFromContext(T configuration, ConfigurationContext context) {
if (isMultipleElementsSelected(context)) {
return false;
}
final RunConfiguration predefinedConfiguration = context.getOriginalConfiguration(getConfigurationType());
final Location contextLocation = context.getLocation();
if (contextLocation == null) {
return false;
}
Location location = JavaExecutionUtil.stepIntoSingleClass(contextLocation);
if (location == null) {
return false;
}
final PsiElement element = location.getPsiElement();
RunnerAndConfigurationSettings template = RunManager.getInstance(location.getProject()).getConfigurationTemplate(getConfigurationFactory());
final Module predefinedModule = ((T) template.getConfiguration()).getConfigurationModule().getModule();
final String vmParameters = predefinedConfiguration instanceof CommonJavaRunConfigurationParameters ? ((CommonJavaRunConfigurationParameters) predefinedConfiguration).getVMParameters() : null;
if (vmParameters != null && !Comparing.strEqual(vmParameters, configuration.getVMParameters()))
return false;
String paramSetName = contextLocation instanceof PsiMemberParameterizedLocation ? configuration.prepareParameterizedParameter(((PsiMemberParameterizedLocation) contextLocation).getParamSetName()) : null;
if (paramSetName != null && !Comparing.strEqual(paramSetName, configuration.getProgramParameters()))
return false;
if (configuration.isConfiguredByElement(element)) {
final Module configurationModule = configuration.getConfigurationModule().getModule();
if (Comparing.equal(location.getModule(), configurationModule))
return true;
if (Comparing.equal(predefinedModule, configurationModule))
return true;
}
return false;
}
use of com.intellij.execution.configurations.RunConfiguration in project intellij-community by JetBrains.
the class RunConfigurationRefactoringElementListenerProvider method getListener.
@Override
public RefactoringElementListener getListener(final PsiElement element) {
RefactoringElementListenerComposite composite = null;
final List<RunConfiguration> configurations = RunManager.getInstance(element.getProject()).getAllConfigurationsList();
for (RunConfiguration configuration : configurations) {
if (configuration instanceof RefactoringListenerProvider) {
// todo: perhaps better way to handle listeners?
RefactoringElementListener listener;
try {
listener = ((RefactoringListenerProvider) configuration).getRefactoringElementListener(element);
} catch (Exception e) {
LOG.error(e);
continue;
}
if (listener != null) {
if (configuration instanceof LocatableConfiguration) {
listener = new NameGeneratingListenerDecorator((LocatableConfiguration) configuration, listener);
}
if (composite == null) {
composite = new RefactoringElementListenerComposite();
}
composite.addListener(listener);
}
}
}
return composite;
}
Aggregations