use of com.perl5.lang.perl.idea.execution.PerlCommandLine in project Perl5-IDEA by Camelcade.
the class PerlXSubsState method reparseXSubs.
public void reparseXSubs() {
if (!PerlProjectManager.isPerlEnabled(myProject)) {
return;
}
if (myParserTask != null) {
Messages.showErrorDialog(myProject, PerlBundle.message("perl.deparsing.in.progress.message"), PerlBundle.message("perl.deparsing.in.progress.title"));
return;
}
PerlCommandLine commandLine = PerlRunUtil.getPerlCommandLine(myProject, PerlPluginUtil.getHelperPath("xs_parser_simple.pl"));
if (commandLine == null) {
LOG.warn("Unable to create deparser command line");
return;
}
commandLine.withCharset(StandardCharsets.UTF_8).withMissingPackageListener(false);
LOG.info("Deparsing: " + commandLine.getCommandLineString());
myParserTask = new Task.Backgroundable(myProject, PerlBundle.message("perl.deparsing.xsubs"), false) {
@Override
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
var project = PerlXSubsState.this.myProject;
Map<String, Long> newFilesMap = ReadAction.compute(() -> {
if (project.isDisposed()) {
return null;
}
final Map<String, Long> result = new THashMap<>();
for (VirtualFile virtualFile : getAllXSFiles(project)) {
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;
try {
processOutput = PerlHostData.execAndGetOutput(commandLine);
} catch (ExecutionException e) {
LOG.warn("Error deparsing", e);
showNotification(PerlBundle.message("perl.deparsing.error.execution"), e.getMessage(), NotificationType.ERROR);
myParserTask = null;
return;
}
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 (project.isDisposed()) {
return;
}
try {
VirtualFile newFile = project.getBaseDir().findOrCreateChildData(this, DEPARSED_FILE_NAME);
newFile.setWritable(true);
OutputStream outputStream = newFile.getOutputStream(null);
outputStream.write(stdout.getBytes());
outputStream.close();
newFile.setWritable(false);
FileContentUtilCore.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();
}
Aggregations