use of com.intellij.execution.configurations.GeneralCommandLine in project Perl5-IDEA by Camelcade.
the class PerlRunProfileState method startProcess.
@NotNull
@Override
protected ProcessHandler startProcess() throws ExecutionException {
PerlRunConfiguration runProfile = (PerlRunConfiguration) getEnvironment().getRunProfile();
VirtualFile scriptFile = runProfile.getScriptFile();
if (scriptFile == null) {
throw new ExecutionException("Script file: " + runProfile.getScriptPath() + " is not exists");
}
Project project = getEnvironment().getProject();
String perlSdkPath = PerlProjectManager.getSdkPath(project, scriptFile);
String alternativeSdkPath = runProfile.getAlternativeSdkPath();
if (runProfile.isUseAlternativeSdk() && !StringUtil.isEmpty(alternativeSdkPath)) {
Sdk sdk = PerlSdkTable.getInstance().findJdk(alternativeSdkPath);
if (sdk != null) {
perlSdkPath = sdk.getHomePath();
} else {
perlSdkPath = alternativeSdkPath;
}
}
if (perlSdkPath == null) {
throw new ExecutionException("Unable to locate Perl Interpreter");
}
String homePath = runProfile.getWorkingDirectory();
if (StringUtil.isEmpty(homePath)) {
Module moduleForFile = ModuleUtilCore.findModuleForFile(scriptFile, project);
if (moduleForFile != null) {
homePath = PathMacroUtil.getModuleDir(moduleForFile.getModuleFilePath());
} else {
homePath = project.getBasePath();
}
}
assert homePath != null;
GeneralCommandLine commandLine = PerlRunUtil.getPerlCommandLine(project, perlSdkPath, scriptFile, getPerlParameters(runProfile));
String programParameters = runProfile.getProgramParameters();
if (programParameters != null) {
commandLine.addParameters(StringUtil.split(programParameters, " "));
}
String charsetName = runProfile.getConsoleCharset();
Charset charset;
if (!StringUtil.isEmpty(charsetName)) {
try {
charset = Charset.forName(charsetName);
} catch (UnsupportedCharsetException e) {
throw new ExecutionException("Unknown charset: " + charsetName);
}
} else {
charset = scriptFile.getCharset();
}
commandLine.setCharset(charset);
commandLine.withWorkDirectory(homePath);
Map<String, String> environment = calcEnv(runProfile);
commandLine.withEnvironment(environment);
commandLine.withParentEnvironmentType(runProfile.isPassParentEnvs() ? CONSOLE : NONE);
OSProcessHandler handler = new OSProcessHandler(commandLine.createProcess(), commandLine.getCommandLineString(), charset) {
@Override
public void startNotify() {
super.startNotify();
String perl5Opt = environment.get(PerlRunUtil.PERL5OPT);
if (StringUtil.isNotEmpty(perl5Opt)) {
notifyTextAvailable(" - " + PerlRunUtil.PERL5OPT + "=" + perl5Opt + '\n', ProcessOutputTypes.SYSTEM);
}
}
};
ProcessTerminatedListener.attach(handler, project);
return handler;
}
use of com.intellij.execution.configurations.GeneralCommandLine in project Perl5-IDEA by Camelcade.
the class PerlCriticAnnotator method getPerlCriticExecutable.
protected GeneralCommandLine getPerlCriticExecutable(Project project) throws ExecutionException {
PerlSharedSettings sharedSettings = PerlSharedSettings.getInstance(project);
PerlLocalSettings localSettings = PerlLocalSettings.getInstance(project);
String executable = localSettings.PERL_CRITIC_PATH;
if (StringUtil.isEmpty(executable)) {
throw new ExecutionException("Path to Perl::Critic executable must be configured in perl settings");
}
GeneralCommandLine commandLine = new GeneralCommandLine(executable).withWorkDirectory(project.getBasePath());
if (StringUtil.isNotEmpty(sharedSettings.PERL_CRITIC_ARGS)) {
commandLine.addParameters(StringUtil.split(sharedSettings.PERL_CRITIC_ARGS, " "));
}
return commandLine;
}
use of com.intellij.execution.configurations.GeneralCommandLine in project Perl5-IDEA by Camelcade.
the class PerlCriticAnnotator method doAnnotate.
@Nullable
@Override
public List<PerlCriticErrorDescriptor> doAnnotate(final PerlFile sourcePsiFile) {
if (sourcePsiFile == null) {
return null;
}
byte[] sourceBytes = ReadAction.compute(sourcePsiFile::getPerlContentInBytes);
if (sourceBytes == null) {
return null;
}
try {
GeneralCommandLine criticCommandLine = getPerlCriticExecutable(sourcePsiFile.getProject());
final Process process = criticCommandLine.createProcess();
OutputStream outputStream = process.getOutputStream();
outputStream.write(sourceBytes);
outputStream.close();
VirtualFile virtualFile = PsiUtilCore.getVirtualFile(sourcePsiFile);
final CapturingProcessHandler processHandler = new CapturingProcessHandler(process, virtualFile == null ? null : virtualFile.getCharset(), criticCommandLine.getCommandLineString());
List<PerlCriticErrorDescriptor> errors = new ArrayList<>();
PerlCriticErrorDescriptor lastDescriptor = null;
for (String output : processHandler.runProcess().getStdoutLines()) {
PerlCriticErrorDescriptor fromString = PerlCriticErrorDescriptor.getFromString(output);
if (fromString != null) {
errors.add(lastDescriptor = fromString);
} else if (lastDescriptor != null) {
lastDescriptor.append(" " + output);
} else if (!StringUtil.equals(output, "source OK")) {
// fixme we could make some popup here
System.err.println("Could not parse line: " + output);
}
}
return errors;
} catch (ExecutionException e) {
Notifications.Bus.notify(new Notification("PerlCritic error", "Perl::Critic failed to start and has been disabled", "<ul style=\"padding-left:10px;margin-left:0px;\">" + "<li>Make sure that Perl::Critic module is installed</li>" + "<li>Configure path to perlcritic executable in <a href=\"configure\">Perl5 settings</a> and re-enable it</li>" + "</ul>", NotificationType.ERROR, new NotificationListener.Adapter() {
@Override
protected void hyperlinkActivated(@NotNull Notification notification, @NotNull HyperlinkEvent e) {
Perl5SettingsConfigurable.open(sourcePsiFile);
notification.expire();
}
}));
PerlSharedSettings.getInstance(sourcePsiFile.getProject()).PERL_CRITIC_ENABLED = false;
} catch (Exception e) {
e.printStackTrace();
}
return null;
}
use of com.intellij.execution.configurations.GeneralCommandLine in project Perl5-IDEA by Camelcade.
the class PerlDeparseFileAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent event) {
PsiFile file = PerlActionUtil.getPsiFileFromEvent(event);
if (file == null) {
return;
}
final Document document = file.getViewProvider().getDocument();
if (document == null) {
return;
}
final Project project = file.getProject();
String deparseArgument = "-MO=Deparse";
PerlSharedSettings perl5Settings = PerlSharedSettings.getInstance(project);
if (StringUtil.isNotEmpty(perl5Settings.PERL_DEPARSE_ARGUMENTS)) {
deparseArgument += "," + perl5Settings.PERL_DEPARSE_ARGUMENTS;
}
GeneralCommandLine commandLine = PerlRunUtil.getPerlCommandLine(project, file.getVirtualFile(), deparseArgument);
if (commandLine == null) {
return;
}
commandLine.withWorkDirectory(project.getBasePath());
FileDocumentManager.getInstance().saveDocument(document);
try {
ProcessOutput processOutput = ExecUtil.execAndGetOutput(commandLine);
String deparsed = processOutput.getStdout();
String error = processOutput.getStderr();
if (StringUtil.isNotEmpty(error) && !StringUtil.contains(error, "syntax OK")) {
if (StringUtil.isEmpty(deparsed)) {
Notifications.Bus.notify(new Notification(PERL_DEPARSE_GROUP, PerlBundle.message("perl.action.error.notification.title"), error.replaceAll("\\n", "<br/>"), NotificationType.ERROR));
} else {
Notifications.Bus.notify(new Notification(PERL_DEPARSE_GROUP, PerlBundle.message("perl.action.success.notification.title"), PerlBundle.message("perl.action.success.notification.message", error.replaceAll("\\n", "<br/>")), NotificationType.INFORMATION));
}
}
if (StringUtil.isNotEmpty(deparsed)) {
VirtualFile newFile = new LightVirtualFile("Deparsed " + file.getName(), file.getFileType(), deparsed);
OpenFileAction.openFile(newFile, project);
}
} catch (ExecutionException e) {
Notifications.Bus.notify(new Notification(PERL_DEPARSE_GROUP, PerlBundle.message("perl.execution.error.notification.title"), e.getMessage().replaceAll("\\n", "<br/>"), NotificationType.ERROR));
}
}
use of com.intellij.execution.configurations.GeneralCommandLine in project clion-embedded-arm by elmot.
the class OpenOcdComponent method createOcdCommandLine.
@SuppressWarnings("WeakerAccess")
@NotNull
public static GeneralCommandLine createOcdCommandLine(@NotNull Project project, @Nullable File fileToLoad, @Nullable String additionalCommand, boolean shutdown) throws ConfigurationException {
OpenOcdSettingsState ocdSettings = project.getComponent(OpenOcdSettingsState.class);
if (ocdSettings.boardConfigFile == null || "".equals(ocdSettings.boardConfigFile.trim())) {
throw new ConfigurationException("Board Config file is not defined.\nPlease open OpenOCD settings and choose one.", "OpenOCD run error");
}
VirtualFile ocdHome = require(LocalFileSystem.getInstance().findFileByPath(ocdSettings.openOcdHome));
VirtualFile ocdBinary = require(ocdHome.findFileByRelativePath(BIN_OPENOCD));
File ocdBinaryIo = VfsUtil.virtualToIoFile(ocdBinary);
GeneralCommandLine commandLine = new PtyCommandLine().withWorkDirectory(ocdBinaryIo.getParentFile()).withParentEnvironmentType(GeneralCommandLine.ParentEnvironmentType.CONSOLE).withParameters("-c", "tcl_port disabled").withExePath(ocdBinaryIo.getAbsolutePath());
VirtualFile ocdScripts = require(OpenOcdSettingsState.findOcdScripts(ocdHome));
commandLine.addParameters("-s", VfsUtil.virtualToIoFile(ocdScripts).getAbsolutePath());
if (ocdSettings.gdbPort != OpenOcdSettingsState.DEF_GDB_PORT) {
commandLine.addParameters("-c", "gdb_port " + ocdSettings.gdbPort);
}
if (ocdSettings.telnetPort != OpenOcdSettingsState.DEF_TELNET_PORT) {
commandLine.addParameters("-c", "telnet_port " + ocdSettings.telnetPort);
}
commandLine.addParameters("-f", ocdSettings.boardConfigFile);
if (fileToLoad != null) {
String command = "program \"" + fileToLoad.getAbsolutePath().replace(File.separatorChar, '/') + "\"";
commandLine.addParameters("-c", command);
}
if (additionalCommand != null && !additionalCommand.isEmpty()) {
commandLine.addParameters("-c", additionalCommand);
}
if (shutdown) {
commandLine.addParameters("-c", "shutdown");
}
return commandLine;
}
Aggregations