Search in sources :

Example 1 with Reporter

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();
        }
    }
}
Also used : Reporter(com.liferay.blade.api.Reporter) OutputStream(java.io.OutputStream) InvalidSyntaxException(org.osgi.framework.InvalidSyntaxException) Problem(com.liferay.blade.api.Problem) IOException(java.io.IOException) File(java.io.File) ServiceReference(org.osgi.framework.ServiceReference)

Aggregations

Problem (com.liferay.blade.api.Problem)1 Reporter (com.liferay.blade.api.Reporter)1 File (java.io.File)1 IOException (java.io.IOException)1 OutputStream (java.io.OutputStream)1 InvalidSyntaxException (org.osgi.framework.InvalidSyntaxException)1 ServiceReference (org.osgi.framework.ServiceReference)1