Search in sources :

Example 16 with PerlCommandLine

use of com.perl5.lang.perl.idea.execution.PerlCommandLine in project Perl5-IDEA by Camelcade.

the class PerlFormatWithPerlTidyAction method getPerlTidyCommandLine.

@Nullable
private PerlCommandLine getPerlTidyCommandLine(@NotNull Project project) {
    PerlSharedSettings sharedSettings = PerlSharedSettings.getInstance(project);
    VirtualFile perlTidyScript = ReadAction.compute(() -> PerlRunUtil.findLibraryScriptWithNotification(project, SCRIPT_NAME, PERL_TIDY_PACKAGE_NAME));
    if (perlTidyScript == null) {
        return null;
    }
    PerlCommandLine commandLine = PerlRunUtil.getPerlCommandLine(project, perlTidyScript);
    if (commandLine == null) {
        return null;
    }
    commandLine.withParameters("-st", "-se").withWorkDirectory(project.getBasePath());
    if (StringUtil.isNotEmpty(sharedSettings.PERL_TIDY_ARGS)) {
        commandLine.addParameters(StringUtil.split(sharedSettings.PERL_TIDY_ARGS, " "));
    }
    return commandLine;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) PerlCommandLine(com.perl5.lang.perl.idea.execution.PerlCommandLine) PerlSharedSettings(com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings) Nullable(org.jetbrains.annotations.Nullable)

Example 17 with PerlCommandLine

use of com.perl5.lang.perl.idea.execution.PerlCommandLine in project Perl5-IDEA by Camelcade.

the class GenericPerlRunConfiguration method createBaseCommandLine.

@NotNull
protected PerlCommandLine createBaseCommandLine(@NotNull PerlRunProfileState perlRunProfileState) throws ExecutionException {
    ExecutionEnvironment executionEnvironment = perlRunProfileState.getEnvironment();
    Project project = executionEnvironment.getProject();
    List<String> additionalPerlParameters = perlRunProfileState.getAdditionalPerlParameters(this);
    Map<String, String> additionalEnvironmentVariables = perlRunProfileState.getAdditionalEnvironmentVariables();
    PerlCommandLine commandLine = PerlRunUtil.getPerlCommandLine(project, getEffectiveSdk(), computeNonNullScriptFile(), ContainerUtil.concat(getPerlParametersList(), additionalPerlParameters), getScriptParameters());
    if (commandLine == null) {
        throw new ExecutionException(PerlBundle.message("perl.run.error.sdk.corrupted", getEffectiveSdk()));
    }
    Map<String, String> environment = new HashMap<>(getEnvs());
    environment.putAll(additionalEnvironmentVariables);
    commandLine.withEnvironment(environment);
    return commandLine;
}
Also used : Project(com.intellij.openapi.project.Project) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) PerlCommandLine(com.perl5.lang.perl.idea.execution.PerlCommandLine) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull)

Example 18 with PerlCommandLine

use of com.perl5.lang.perl.idea.execution.PerlCommandLine in project Perl5-IDEA by Camelcade.

the class GenericPerlRunConfiguration method createCommandLine.

@NotNull
public PerlCommandLine createCommandLine(@NotNull PerlRunProfileState perlRunProfileState) throws ExecutionException {
    PerlCommandLine commandLine = createBaseCommandLine(perlRunProfileState);
    commandLine.withParentEnvironmentType(isPassParentEnvs() ? CONSOLE : NONE);
    commandLine.withWorkDirectory(computeWorkingDirectory(perlRunProfileState.getEnvironment().getProject()));
    commandLine.withCharset(computeCharset());
    return commandLine.withPty(isUsePty());
}
Also used : PerlCommandLine(com.perl5.lang.perl.idea.execution.PerlCommandLine) NotNull(org.jetbrains.annotations.NotNull)

Example 19 with PerlCommandLine

use of com.perl5.lang.perl.idea.execution.PerlCommandLine in project Perl5-IDEA by Camelcade.

the class PerlTestRunConfiguration method createBaseCommandLine.

@Override
@NotNull
protected PerlCommandLine createBaseCommandLine(@NotNull PerlRunProfileState perlRunProfileState) throws ExecutionException {
    ExecutionEnvironment executionEnvironment = perlRunProfileState.getEnvironment();
    Project project = executionEnvironment.getProject();
    List<String> additionalPerlParameters = perlRunProfileState.getAdditionalPerlParameters(this);
    Map<String, String> additionalEnvironmentVariables = perlRunProfileState.getAdditionalEnvironmentVariables();
    Sdk perlSdk = getEffectiveSdk();
    VirtualFile proveScript = PerlRunUtil.findLibraryScriptWithNotification(perlSdk, getProject(), PROVE, TEST_HARNESS);
    if (proveScript == null) {
        throw new ExecutionException(PerlBundle.message("perl.run.error.prove.missing", perlSdk.getName()));
    }
    PerlHostData<?, ?> perlHostData = PerlHostData.notNullFrom(perlSdk);
    Set<String> proveParameters = new LinkedHashSet<>(PROVE_DEFAULT_PARAMETERS);
    proveParameters.addAll(getScriptParameters());
    proveParameters.add(PROVE_JOBS_PARAMETER);
    proveParameters.add(Integer.toString(perlRunProfileState.isParallelRunAllowed() ? getJobsNumber() : 1));
    VirtualFile workingDirectory = computeExplicitWorkingDirectory();
    List<String> testsPaths = new ArrayList<>();
    for (VirtualFile testVirtualFile : computeTargetFiles()) {
        if (testVirtualFile == null) {
            continue;
        }
        String virtualFilePath = testVirtualFile.getPath();
        if (workingDirectory != null && VfsUtil.isAncestor(workingDirectory, testVirtualFile, true)) {
            testsPaths.add(VfsUtil.getRelativePath(testVirtualFile, workingDirectory));
        } else {
            testsPaths.add(perlHostData.getRemotePath(virtualFilePath));
        }
    }
    String remotePath = perlHostData.getRemotePath(proveScript.getPath());
    if (StringUtil.isEmpty(remotePath)) {
        throw new ExecutionException("Unable to map remote path: " + remotePath + " for " + perlHostData);
    }
    PerlCommandLine commandLine = new PerlCommandLine(getEffectiveInterpreterPath()).withParameters(remotePath).withParameters(proveParameters).withParameters(testsPaths).withProject(project).withSdk(perlSdk);
    List<String> testScriptParametersList = getTestScriptParametersList();
    if (!testScriptParametersList.isEmpty()) {
        commandLine.withParameters("::");
        commandLine.withParameters(testScriptParametersList);
    }
    ArrayList<String> perlParametersList = new ArrayList<>(getPerlParametersList());
    perlParametersList.addAll(additionalPerlParameters);
    for (VirtualFile libRoot : PerlProjectManager.getInstance(project).getModulesLibraryRoots()) {
        perlParametersList.add(PERL_I + perlHostData.getRemotePath(libRoot.getCanonicalPath()));
    }
    // environment
    Map<String, String> environment = new HashMap<>(getEnvs());
    environment.putAll(additionalEnvironmentVariables);
    if (!perlParametersList.isEmpty()) {
        String currentOpt = environment.get(PerlRunUtil.PERL5OPT);
        if (StringUtil.isNotEmpty(currentOpt)) {
            perlParametersList.addAll(0, StringUtil.split(currentOpt, " "));
        }
        environment.put(PerlRunUtil.PERL5OPT, StringUtil.join(perlParametersList, " "));
    }
    environment.forEach((key, val) -> commandLine.withEnvironment(PROVE_PASS_PREFIX + key, val));
    commandLine.withParentEnvironmentType(isPassParentEnvs() ? CONSOLE : NONE);
    return commandLine;
}
Also used : VirtualFile(com.intellij.openapi.vfs.VirtualFile) ExecutionEnvironment(com.intellij.execution.runners.ExecutionEnvironment) Project(com.intellij.openapi.project.Project) PerlCommandLine(com.perl5.lang.perl.idea.execution.PerlCommandLine) Sdk(com.intellij.openapi.projectRoots.Sdk) ExecutionException(com.intellij.execution.ExecutionException) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with PerlCommandLine

use of com.perl5.lang.perl.idea.execution.PerlCommandLine in project Perl5-IDEA by Camelcade.

the class PerlRunUtil method runInConsole.

public static void runInConsole(@NotNull PerlCommandLine perlCommandLine) {
    ApplicationManager.getApplication().assertIsDispatchThread();
    Executor runExecutor = DefaultRunExecutor.getRunExecutorInstance();
    Project project = perlCommandLine.getNonNullEffectiveProject();
    boolean isUnitTestMode = ApplicationManager.getApplication().isUnitTestMode();
    PerlConsoleView consoleView = isUnitTestMode ? new PerlRunConsole(project) : new PerlTerminalExecutionConsole(project);
    consoleView.withHostData(perlCommandLine.getEffectiveHostData());
    ProcessHandler processHandler = null;
    try {
        processHandler = PerlHostData.createConsoleProcessHandler(perlCommandLine.withPty(!isUnitTestMode));
        if (isUnitTestMode) {
            processHandler.addProcessListener(new ProcessAdapter() {

                @Override
                public void onTextAvailable(@NotNull ProcessEvent event, @NotNull Key outputType) {
                    LOG.info(outputType + ": " + event.getText());
                }
            });
        }
    } catch (ExecutionException e) {
        consoleView.print(e.getMessage(), ConsoleViewContentType.ERROR_OUTPUT);
        LOG.warn(e);
    }
    RunContentDescriptor runContentDescriptor = new RunContentDescriptor(consoleView, processHandler, consoleView.getComponent(), ObjectUtils.notNull(perlCommandLine.getConsoleTitle(), perlCommandLine.getCommandLineString()), ObjectUtils.notNull(perlCommandLine.getConsoleIcon(), PerlIcons.PERL_LANGUAGE_ICON));
    RunContentManager.getInstance(project).showRunContent(runExecutor, runContentDescriptor);
    if (processHandler != null) {
        consoleView.attachToProcess(processHandler);
        processHandler.startNotify();
        if (ApplicationManager.getApplication().isUnitTestMode()) {
            LOG.assertTrue(ourTestDisposable != null);
            TEST_CONSOLE_DESCRIPTORS.add(runContentDescriptor);
            Disposer.register(ourTestDisposable, runContentDescriptor.getExecutionConsole());
        }
    }
}
Also used : ProcessAdapter(com.intellij.execution.process.ProcessAdapter) RunContentDescriptor(com.intellij.execution.ui.RunContentDescriptor) ProcessEvent(com.intellij.execution.process.ProcessEvent) PerlTerminalExecutionConsole(com.perl5.lang.perl.idea.execution.PerlTerminalExecutionConsole) PerlRunConsole(com.perl5.lang.perl.idea.run.PerlRunConsole) Project(com.intellij.openapi.project.Project) DefaultRunExecutor(com.intellij.execution.executors.DefaultRunExecutor) Executor(com.intellij.execution.Executor) PerlConsoleView(com.perl5.lang.perl.idea.sdk.host.PerlConsoleView) ProcessHandler(com.intellij.execution.process.ProcessHandler) ExecutionException(com.intellij.execution.ExecutionException) Key(com.intellij.openapi.util.Key)

Aggregations

PerlCommandLine (com.perl5.lang.perl.idea.execution.PerlCommandLine)19 VirtualFile (com.intellij.openapi.vfs.VirtualFile)12 ExecutionException (com.intellij.execution.ExecutionException)11 Project (com.intellij.openapi.project.Project)8 NotNull (org.jetbrains.annotations.NotNull)7 Nullable (org.jetbrains.annotations.Nullable)6 ProcessOutput (com.intellij.execution.process.ProcessOutput)5 ProcessAdapter (com.intellij.execution.process.ProcessAdapter)3 ProcessEvent (com.intellij.execution.process.ProcessEvent)3 Notification (com.intellij.notification.Notification)3 ProgressIndicator (com.intellij.openapi.progress.ProgressIndicator)3 Task (com.intellij.openapi.progress.Task)3 PerlSharedSettings (com.perl5.lang.perl.idea.configuration.settings.PerlSharedSettings)3 IOException (java.io.IOException)3 OutputStream (java.io.OutputStream)3 ExecutionEnvironment (com.intellij.execution.runners.ExecutionEnvironment)2 Document (com.intellij.openapi.editor.Document)2 Sdk (com.intellij.openapi.projectRoots.Sdk)2 PsiFile (com.intellij.psi.PsiFile)2 LightVirtualFile (com.intellij.testFramework.LightVirtualFile)2