Search in sources :

Example 21 with RunConfiguration

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();
}
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 22 with RunConfiguration

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;
}
Also used : DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) ProgramRunner(com.intellij.execution.runners.ProgramRunner) Nullable(org.jetbrains.annotations.Nullable)

Example 23 with RunConfiguration

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;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) JavaSdkVersion(com.intellij.openapi.projectRoots.JavaSdkVersion) JavaSdkType(com.intellij.openapi.projectRoots.JavaSdkType) RunConfiguration(com.intellij.execution.configurations.RunConfiguration) OrderEnumerator(com.intellij.openapi.roots.OrderEnumerator) JavaSdk(com.intellij.openapi.projectRoots.JavaSdk) Sdk(com.intellij.openapi.projectRoots.Sdk) IOException(java.io.IOException) Project(com.intellij.openapi.project.Project) Module(com.intellij.openapi.module.Module) VirtualFile(com.intellij.openapi.vfs.VirtualFile) File(java.io.File) Nullable(org.jetbrains.annotations.Nullable)

Example 24 with RunConfiguration

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;
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) Module(com.intellij.openapi.module.Module) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation) MethodLocation(com.intellij.execution.junit2.info.MethodLocation) PsiMemberParameterizedLocation(com.intellij.execution.junit2.PsiMemberParameterizedLocation)

Example 25 with RunConfiguration

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;
}
Also used : RunConfiguration(com.intellij.execution.configurations.RunConfiguration) LocatableConfiguration(com.intellij.execution.configurations.LocatableConfiguration) RefactoringElementListener(com.intellij.refactoring.listeners.RefactoringElementListener) RefactoringElementListenerComposite(com.intellij.refactoring.listeners.RefactoringElementListenerComposite) RefactoringListenerProvider(com.intellij.execution.configurations.RefactoringListenerProvider)

Aggregations

RunConfiguration (com.intellij.execution.configurations.RunConfiguration)59 RunnerAndConfigurationSettings (com.intellij.execution.RunnerAndConfigurationSettings)16 Module (com.intellij.openapi.module.Module)13 Nullable (org.jetbrains.annotations.Nullable)12 Project (com.intellij.openapi.project.Project)10 PsiElement (com.intellij.psi.PsiElement)7 ConfigurationFactory (com.intellij.execution.configurations.ConfigurationFactory)6 ConfigurationType (com.intellij.execution.configurations.ConfigurationType)6 Pair (com.intellij.openapi.util.Pair)6 NotNull (org.jetbrains.annotations.NotNull)6 AndroidTestRunConfiguration (com.android.tools.idea.testartifacts.instrumented.AndroidTestRunConfiguration)5 FlexBuildConfiguration (com.intellij.lang.javascript.flex.projectStructure.model.FlexBuildConfiguration)5 BeforeRunTask (com.intellij.execution.BeforeRunTask)4 FlashRunConfiguration (com.intellij.lang.javascript.flex.run.FlashRunConfiguration)4 VirtualFile (com.intellij.openapi.vfs.VirtualFile)4 ArrayList (java.util.ArrayList)4 AndroidJUnitConfiguration (com.android.tools.idea.testartifacts.junit.AndroidJUnitConfiguration)3 BeforeRunTaskProvider (com.intellij.execution.BeforeRunTaskProvider)3 Location (com.intellij.execution.Location)3 RunManager (com.intellij.execution.RunManager)3