use of com.liferay.blade.api.Reporter in project liferay-ide by liferay.
the class ProjectMigrationService method reportProblems.
@Override
public void reportProblems(List<Problem> problems, int detail, String format, Object... args) {
Reporter reporter = null;
try {
Collection<ServiceReference<Reporter>> references = _context.getServiceReferences(Reporter.class, "(format=" + format + ")");
if (ListUtil.isNotEmpty(references)) {
reporter = _context.getService(references.iterator().next());
} else {
ServiceReference<Reporter> sr = _context.getServiceReference(Reporter.class);
reporter = _context.getService(sr);
}
} catch (InvalidSyntaxException ise) {
ise.printStackTrace();
}
OutputStream fos = null;
try {
if (ListUtil.isNotEmpty(args)) {
if (args[0] instanceof File) {
File outputFile = (File) args[0];
outputFile.getParentFile().mkdirs();
outputFile.createNewFile();
fos = Files.newOutputStream(outputFile.toPath());
} else if (args[0] instanceof OutputStream) {
fos = (OutputStream) args[0];
}
}
if (ListUtil.isNotEmpty(problems)) {
reporter.beginReporting(detail, fos);
for (Problem problem : problems) {
reporter.report(problem);
}
reporter.endReporting();
}
} catch (IOException ioe) {
ioe.printStackTrace();
} finally {
try {
if (fos != null) {
fos.close();
}
} catch (IOException ioe) {
ioe.printStackTrace();
}
}
}
Aggregations