Search in sources :

Example 1 with CompatibilityLevel

use of com.linkedin.restli.tools.idlcheck.CompatibilityLevel in project rest.li by linkedin.

the class RestLiSnapshotCompatibilityChecker method main.

public static void main(String[] args) {
    final Options options = new Options();
    options.addOption("h", "help", false, "Print help");
    options.addOption(OptionBuilder.withArgName("compatibility_level").withLongOpt("compat").hasArg().withDescription("Compatibility level " + listCompatLevelOptions()).create('c'));
    options.addOption(OptionBuilder.withLongOpt("report").withDescription("Prints a report at the end of the execution that can be parsed for reporting to other tools").create("report"));
    final String cmdLineSyntax = RestLiSnapshotCompatibilityChecker.class.getCanonicalName() + " [pairs of <prevRestspecPath currRestspecPath>]";
    final CommandLineParser parser = new PosixParser();
    final CommandLine cmd;
    try {
        cmd = parser.parse(options, args);
    } catch (ParseException e) {
        new HelpFormatter().printHelp(cmdLineSyntax, options, true);
        System.exit(255);
        // to suppress IDE warning
        return;
    }
    final String[] targets = cmd.getArgs();
    if (cmd.hasOption('h') || targets.length < 2 || targets.length % 2 != 0) {
        new HelpFormatter().printHelp(cmdLineSyntax, options, true);
        System.exit(255);
    }
    final String compatValue;
    if (cmd.hasOption('c')) {
        compatValue = cmd.getOptionValue('c');
    } else {
        compatValue = CompatibilityLevel.DEFAULT.name();
    }
    final CompatibilityLevel compat;
    try {
        compat = CompatibilityLevel.valueOf(compatValue.toUpperCase());
    } catch (IllegalArgumentException e) {
        new HelpFormatter().printHelp(cmdLineSyntax, options, true);
        System.exit(255);
        return;
    }
    final String resolverPath = System.getProperty(AbstractGenerator.GENERATOR_RESOLVER_PATH);
    final RestLiSnapshotCompatibilityChecker checker = new RestLiSnapshotCompatibilityChecker();
    checker.setResolverPath(resolverPath);
    for (int i = 1; i < targets.length; i += 2) {
        String prevTarget = targets[i - 1];
        String currTarget = targets[i];
        checker.checkCompatibility(prevTarget, currTarget, compat, prevTarget.endsWith(".restspec.json"));
    }
    String summary = checker.getInfoMap().createSummary();
    if (compat != CompatibilityLevel.OFF && summary.length() > 0) {
        System.out.println(summary);
    }
    if (cmd.hasOption("report")) {
        System.out.println(new CompatibilityReport(checker.getInfoMap(), compat).createReport());
        System.exit(0);
    }
    System.exit(checker.getInfoMap().isCompatible(compat) ? 0 : 1);
}
Also used : CompatibilityReport(com.linkedin.restli.tools.compatibility.CompatibilityReport) Options(org.apache.commons.cli.Options) PosixParser(org.apache.commons.cli.PosixParser) HelpFormatter(org.apache.commons.cli.HelpFormatter) CommandLine(org.apache.commons.cli.CommandLine) CompatibilityLevel(com.linkedin.restli.tools.idlcheck.CompatibilityLevel) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException)

Example 2 with CompatibilityLevel

use of com.linkedin.restli.tools.idlcheck.CompatibilityLevel in project rest.li by linkedin.

the class RestLiSnapshotCompatibilityChecker method listCompatLevelOptions.

private static String listCompatLevelOptions() {
    final StringBuilder options = new StringBuilder("<");
    for (CompatibilityLevel compatLevel : CompatibilityLevel.values()) {
        options.append(compatLevel.name().toLowerCase()).append("|");
    }
    options.replace(options.length() - 1, options.length(), ">");
    return options.toString();
}
Also used : CompatibilityLevel(com.linkedin.restli.tools.idlcheck.CompatibilityLevel)

Aggregations

CompatibilityLevel (com.linkedin.restli.tools.idlcheck.CompatibilityLevel)2 CompatibilityReport (com.linkedin.restli.tools.compatibility.CompatibilityReport)1 CommandLine (org.apache.commons.cli.CommandLine)1 CommandLineParser (org.apache.commons.cli.CommandLineParser)1 HelpFormatter (org.apache.commons.cli.HelpFormatter)1 Options (org.apache.commons.cli.Options)1 ParseException (org.apache.commons.cli.ParseException)1 PosixParser (org.apache.commons.cli.PosixParser)1