Search in sources :

Example 1 with ProgressBar

use of me.tongfei.progressbar.ProgressBar in project winery by eclipse.

the class WineryCli method main.

public static void main(String[] args) throws ParseException {
    Option repositoryPathOption = new Option("p", "path", true, "use given path as repository path");
    Option serviceTemplatesOnlyOption = new Option("so", "servicetemplatesonly", false, "checks service templates instead of the whole repository");
    Option checkDocumentationOption = new Option("cd", "checkdocumentation", false, "check existence of README.md and LICENSE. Default: No check");
    Option verboseOption = new Option("v", "verbose", false, "be verbose: Output the checked elements");
    Option helpOption = new Option("h", "help", false, "prints this help");
    Options options = new Options();
    options.addOption(repositoryPathOption);
    options.addOption(serviceTemplatesOnlyOption);
    options.addOption(checkDocumentationOption);
    options.addOption(verboseOption);
    options.addOption(helpOption);
    CommandLineParser parser = new DefaultParser();
    CommandLine line = parser.parse(options, args);
    if (line.hasOption("h")) {
        HelpFormatter formatter = new HelpFormatter();
        formatter.printHelp("winery", options);
        System.exit(0);
    }
    IRepository repository;
    if (line.hasOption("p")) {
        repository = RepositoryFactory.getRepository(Paths.get(line.getOptionValue("p")));
    } else {
        repository = RepositoryFactory.getRepository();
    }
    System.out.println("Using repository path " + ((FilebasedRepository) repository).getRepositoryRoot() + "...");
    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);
    ProgressBar progressBar = new ProgressBar("Check", 100, ProgressBarStyle.ASCII);
    progressBar.start();
    ConsistencyErrorLogger errors = ConsistencyChecker.checkCorruption(configuration, new ConsistencyCheckerProgressListener() {

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

        @Override
        public void updateProgress(float progress, String checkingDefinition) {
            progressBar.setExtraMessage("Now checking " + checkingDefinition);
            progressBar.stepTo((long) (progress * 100));
        }
    });
    progressBar.stop();
    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 (Objects.nonNull(elementErrorList.getErrors())) {
                System.out.println("\tErrors:");
                for (String error : elementErrorList.getErrors()) {
                    System.out.println("\t\t" + error);
                }
            }
            if (Objects.nonNull(elementErrorList.getWarnings())) {
                System.out.println("\n\tWarnings:");
                for (String error : elementErrorList.getWarnings()) {
                    System.out.println("\t\t" + error);
                }
            }
            System.out.println();
        }
        System.exit(1);
    }
}
Also used : QName(javax.xml.namespace.QName) IRepository(org.eclipse.winery.repository.backend.IRepository) 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 IRepository (org.eclipse.winery.repository.backend.IRepository)1