Search in sources :

Example 1 with CopybaraGenerator

use of org.eclipse.winery.tools.copybaragenerator.CopybaraGenerator in project winery by eclipse.

the class WineryCli method main.

public static void main(String[] args) throws Exception {
    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 generateCopybaraConfigOption = new Option("cb", "generatecopybaraconfig", true, "Generates a configuration for Copybara.");
    generateCopybaraConfigOption.setOptionalArg(true);
    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(generateCopybaraConfigOption);
    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();
    }
    if (line.hasOption("cb")) {
        CopybaraGenerator copybaraGenerator = new CopybaraGenerator();
        String outfile = line.getOptionValue("cb");
        if (outfile == null) {
            String copybaraConfigFile = copybaraGenerator.generateCopybaraConfigFile();
            System.out.println(copybaraConfigFile);
        } else {
            Path file = Paths.get(outfile);
            copybaraGenerator.generateCopybaraConfigFile(file);
        }
        System.exit(0);
    }
    if (repository instanceof AbstractFileBasedRepository) {
        System.out.println("Using repository path " + repository.getRepositoryRoot() + "...");
    } else {
        System.out.println("Using non-filebased repository");
    }
    doConsistencyCheck(line, repository);
}
Also used : HelpFormatter(org.apache.commons.cli.HelpFormatter) Path(java.nio.file.Path) Options(org.apache.commons.cli.Options) CommandLine(org.apache.commons.cli.CommandLine) AbstractFileBasedRepository(org.eclipse.winery.repository.backend.filebased.AbstractFileBasedRepository) CopybaraGenerator(org.eclipse.winery.tools.copybaragenerator.CopybaraGenerator) Option(org.apache.commons.cli.Option) CommandLineParser(org.apache.commons.cli.CommandLineParser) IRepository(org.eclipse.winery.repository.backend.IRepository) DefaultParser(org.apache.commons.cli.DefaultParser)

Aggregations

Path (java.nio.file.Path)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 DefaultParser (org.apache.commons.cli.DefaultParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 Option (org.apache.commons.cli.Option)1 Options (org.apache.commons.cli.Options)1 IRepository (org.eclipse.winery.repository.backend.IRepository)1 AbstractFileBasedRepository (org.eclipse.winery.repository.backend.filebased.AbstractFileBasedRepository)1 CopybaraGenerator (org.eclipse.winery.tools.copybaragenerator.CopybaraGenerator)1