Search in sources :

Example 1 with ConsistencyCheckerProgressListener

use of org.eclipse.winery.repository.backend.consistencycheck.ConsistencyCheckerProgressListener in project winery by eclipse.

the class WineryCli method doConsistencyCheck.

private static void doConsistencyCheck(CommandLine line, IRepository repository) {
    EnumSet<ConsistencyCheckerVerbosity> verbosity;
    if (line.hasOption("v")) {
        verbosity = EnumSet.of(ConsistencyCheckerVerbosity.OUTPUT_NUMBER_OF_TOSCA_COMPONENTS, ConsistencyCheckerVerbosity.OUTPUT_CURRENT_TOSCA_COMPONENT_ID, ConsistencyCheckerVerbosity.OUTPUT_ERRORS);
    } else {
        verbosity = EnumSet.of(ConsistencyCheckerVerbosity.OUTPUT_NUMBER_OF_TOSCA_COMPONENTS);
    }
    boolean serviceTemplatesOnly = line.hasOption("so");
    boolean checkDocumentation = line.hasOption("cd");
    ConsistencyCheckerConfiguration configuration = new ConsistencyCheckerConfiguration(serviceTemplatesOnly, checkDocumentation, verbosity, repository);
    final ConsistencyChecker consistencyChecker = new ConsistencyChecker(configuration);
    int numberOfDefinitionsToCheck = consistencyChecker.numberOfDefinitionsToCheck();
    ProgressBar progressBar = new ProgressBar("Check", numberOfDefinitionsToCheck, ProgressBarStyle.ASCII);
    consistencyChecker.setConsistencyCheckerProgressListener(new ConsistencyCheckerProgressListener() {

        @Override
        public void updateProgress(float progress) {
            progressBar.stepTo((long) (progress * numberOfDefinitionsToCheck));
        }

        @Override
        public void updateProgress(float progress, String checkingDefinition) {
            progressBar.setExtraMessage("Now checking " + checkingDefinition);
            progressBar.stepTo((long) (progress * numberOfDefinitionsToCheck));
        }
    });
    progressBar.start();
    consistencyChecker.checkCorruption();
    progressBar.stop();
    ConsistencyErrorCollector errors = consistencyChecker.getErrorCollector();
    System.out.println();
    if (errors.getErrorList().isEmpty()) {
        System.out.println("No errors exist.");
    } else {
        System.out.println("Errors found in the repository:");
        System.out.println();
        for (Map.Entry<QName, ElementErrorList> qName : errors.getErrorList().entrySet()) {
            System.out.println(qName.getKey());
            ElementErrorList elementErrorList = qName.getValue();
            if (!elementErrorList.getErrors().isEmpty()) {
                System.out.println("\tErrors:");
                for (String error : elementErrorList.getErrors()) {
                    System.out.println("\t\t" + error);
                }
            }
            if (!elementErrorList.getWarnings().isEmpty()) {
                System.out.println("\n\tWarnings:");
                for (String error : elementErrorList.getWarnings()) {
                    System.out.println("\t\t" + error);
                }
            }
            System.out.println();
        }
        System.exit(1);
    }
}
Also used : ConsistencyCheckerProgressListener(org.eclipse.winery.repository.backend.consistencycheck.ConsistencyCheckerProgressListener) QName(javax.xml.namespace.QName) ElementErrorList(org.eclipse.winery.repository.backend.consistencycheck.ElementErrorList) ConsistencyErrorCollector(org.eclipse.winery.repository.backend.consistencycheck.ConsistencyErrorCollector) ConsistencyCheckerConfiguration(org.eclipse.winery.repository.backend.consistencycheck.ConsistencyCheckerConfiguration) ConsistencyChecker(org.eclipse.winery.repository.backend.consistencycheck.ConsistencyChecker) ConsistencyCheckerVerbosity(org.eclipse.winery.repository.backend.consistencycheck.ConsistencyCheckerVerbosity) ProgressBar(me.tongfei.progressbar.ProgressBar) Map(java.util.Map)

Aggregations

Map (java.util.Map)1 QName (javax.xml.namespace.QName)1 ProgressBar (me.tongfei.progressbar.ProgressBar)1 ConsistencyChecker (org.eclipse.winery.repository.backend.consistencycheck.ConsistencyChecker)1 ConsistencyCheckerConfiguration (org.eclipse.winery.repository.backend.consistencycheck.ConsistencyCheckerConfiguration)1 ConsistencyCheckerProgressListener (org.eclipse.winery.repository.backend.consistencycheck.ConsistencyCheckerProgressListener)1 ConsistencyCheckerVerbosity (org.eclipse.winery.repository.backend.consistencycheck.ConsistencyCheckerVerbosity)1 ConsistencyErrorCollector (org.eclipse.winery.repository.backend.consistencycheck.ConsistencyErrorCollector)1 ElementErrorList (org.eclipse.winery.repository.backend.consistencycheck.ElementErrorList)1