use of com.intellij.execution.process.ProcessOutput in project Perl5-IDEA by Camelcade.
the class PerlXSubsState method reparseXSubs.
public void reparseXSubs() {
if (myProject.isDisposed()) {
return;
}
if (myParserTask != null) {
Messages.showErrorDialog(myProject, PerlBundle.message("perl.deparsing.in.progress.message"), PerlBundle.message("perl.deparsing.in.progress.title"));
return;
}
GeneralCommandLine commandLine = PerlPluginUtil.getPluginScriptCommandLine(myProject, "xs_parser_simple.pl");
if (commandLine == null) {
return;
}
try {
LOG.info("Deparsing: " + commandLine.getCommandLineString());
final CapturingProcessHandler processHandler = new CapturingProcessHandler(commandLine.createProcess(), CharsetToolkit.UTF8_CHARSET, commandLine.getCommandLineString());
myParserTask = new Task.Backgroundable(myProject, PerlBundle.message("perl.deparsing.xsubs"), false) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
Map<String, Long> newFilesMap = ReadAction.compute(() -> {
if (myProject.isDisposed()) {
return null;
}
final Map<String, Long> result = new THashMap<>();
for (VirtualFile virtualFile : getAllXSFiles(myProject)) {
if (virtualFile.isValid()) {
String filePath = virtualFile.getCanonicalPath();
if (filePath != null) {
result.put(filePath, VfsUtilCore.virtualToIoFile(virtualFile).lastModified());
}
}
}
return result;
});
if (newFilesMap == null) {
myParserTask = null;
return;
}
ProcessOutput processOutput = processHandler.runProcess();
final String stdout = processOutput.getStdout();
String stderr = processOutput.getStderr();
int exitCode = processOutput.getExitCode();
LOG.info("Deparsing finished with exit code: " + exitCode + (StringUtil.isEmpty(stderr) ? "" : ". STDERR:\n" + stderr));
if (exitCode != 0) {
showNotification(PerlBundle.message("perl.deparsing.error.execution"), stderr, NotificationType.ERROR);
} else if (!stdout.isEmpty()) {
Application application = ApplicationManager.getApplication();
application.invokeAndWait(() -> WriteAction.run(() -> {
if (myProject.isDisposed()) {
return;
}
try {
VirtualFile newFile = myProject.getBaseDir().findOrCreateChildData(this, DEPARSED_FILE_NAME);
newFile.setWritable(true);
OutputStream outputStream = newFile.getOutputStream(null);
outputStream.write(stdout.getBytes());
outputStream.close();
newFile.setWritable(false);
FileContentUtil.reparseFiles(newFile);
myFilesMap = newFilesMap;
isActual = true;
showNotification(PerlBundle.message("perl.deparsing.finished"), "", NotificationType.INFORMATION);
} catch (IOException e) {
LOG.warn("Error creating deparsed file", e);
showNotification(PerlBundle.message("perl.deparsing.error.creating.file"), e.getMessage(), NotificationType.ERROR);
}
// fixme fix modality state
}));
}
myParserTask = null;
}
};
myParserTask.queue();
} catch (ExecutionException e) {
LOG.warn("Error deparsing", e);
showNotification(PerlBundle.message("perl.deparsing.error.execution"), e.getMessage(), NotificationType.ERROR);
}
}
Aggregations