use of com.intellij.execution.process.CapturingAnsiEscapesAwareProcessHandler in project android by JetBrains.
the class UnpackOperation method untar.
/**
* @throws IOException when tar fails in a way that we may retry the operation
* @throws WizardException if retry is not possible (e.g. no tar executable)
*/
@NotNull
private static File untar(final File archive, File destination, final InstallContext context, final ProgressIndicator indicator) throws IOException, WizardException {
if (!destination.mkdirs()) {
throw new WizardException("Cannot create temporary directory to extract files");
}
indicator.start();
// 0%
indicator.setFraction(0.0);
try {
GeneralCommandLine line = new GeneralCommandLine(getTarExecutablePath(), TAR_FLAGS_EXTRACT_UNPACK_VERBOSE_FILENAME_TARGETDIR, archive.getAbsolutePath(), destination.getAbsolutePath());
CapturingAnsiEscapesAwareProcessHandler handler = new CapturingAnsiEscapesAwareProcessHandler(line);
handler.addProcessListener(new ProcessAdapter() {
@Override
public void onTextAvailable(ProcessEvent event, Key outputType) {
String string = event.getText();
if (!StringUtil.isEmptyOrSpaces(string)) {
if (string.startsWith(EXTRACT_OPERATION_OUTPUT)) {
// Extract operation prefix
String fileName = string.substring(EXTRACT_OPERATION_OUTPUT.length()).trim();
indicator.setText(fileName);
} else if (ProcessOutputTypes.STDOUT.equals(outputType)) {
indicator.setText(string.trim());
} else {
context.print(string, ConsoleViewContentType.getConsoleViewType(outputType));
}
}
}
});
if (handler.runProcess().getExitCode() != 0) {
throw new IOException("Unable to unpack archive file");
}
return destination;
} catch (ExecutionException e) {
throw new WizardException("Unable to run tar utility");
} finally {
// 100%
indicator.setFraction(1.0);
indicator.stop();
}
}
Aggregations