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