Search in sources :

Example 1 with Check

use of de.tudarmstadt.ukp.clarin.webanno.diag.checks.Check in project webanno by webanno.

the class CasDoctor method analyze.

public boolean analyze(Project aProject, CAS aCas, List<LogMessage> aMessages, boolean aFatalChecks) throws CasDoctorException {
    long tStart = System.currentTimeMillis();
    boolean ok = true;
    for (Class<? extends Check> checkClass : checkClasses) {
        try {
            long tStartTask = System.currentTimeMillis();
            Check check = checkClass.newInstance();
            if (context != null) {
                context.getAutowireCapableBeanFactory().autowireBean(check);
            }
            LOG.debug("CasDoctor analysis [" + checkClass.getSimpleName() + "] running...");
            ok &= check.check(aProject, aCas, aMessages);
            LOG.debug("CasDoctor analysis [" + checkClass.getSimpleName() + "] completed in " + (System.currentTimeMillis() - tStartTask) + "ms");
        } catch (InstantiationException | IllegalAccessException e) {
            aMessages.add(new LogMessage(this, LogLevel.ERROR, "Cannot instantiate [%s]: %s", checkClass.getSimpleName(), ExceptionUtils.getRootCauseMessage(e)));
            LOG.error("Error running check", e);
        }
    }
    if (!ok) {
        aMessages.forEach(s -> LOG.error("{}", s));
    }
    if (!ok && aFatalChecks) {
        throw new CasDoctorException(aMessages);
    }
    LOG.debug("CasDoctor completed all analyses in " + (System.currentTimeMillis() - tStart) + "ms");
    return ok;
}
Also used : LogMessage(de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage) Check(de.tudarmstadt.ukp.clarin.webanno.diag.checks.Check)

Example 2 with Check

use of de.tudarmstadt.ukp.clarin.webanno.diag.checks.Check in project webanno by webanno.

the class CasDoctor method scanChecks.

public static List<Class<? extends Check>> scanChecks() {
    long start = currentTimeMillis();
    Reflections reflections = new Reflections(Check.class.getPackage().getName());
    List<Class<? extends Check>> checks = reflections.getSubTypesOf(Check.class).stream().filter(c -> !Modifier.isAbstract(c.getModifiers())).sorted(Comparator.comparing(Class::getName)).collect(Collectors.toList());
    LOG.info("Found {} checks in {}ms", checks.size(), currentTimeMillis() - start);
    return checks;
}
Also used : Check(de.tudarmstadt.ukp.clarin.webanno.diag.checks.Check) Reflections(org.reflections.Reflections)

Aggregations

Check (de.tudarmstadt.ukp.clarin.webanno.diag.checks.Check)2 LogMessage (de.tudarmstadt.ukp.clarin.webanno.support.logging.LogMessage)1 Reflections (org.reflections.Reflections)1