Search in sources :

Example 1 with CompatibilityReport

use of com.linkedin.restli.tools.compatibility.CompatibilityReport 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 CompatibilityReport

use of com.linkedin.restli.tools.compatibility.CompatibilityReport in project rest.li by linkedin.

the class RestLiResourceModelCompatibilityChecker 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 = RestLiResourceModelCompatibilityChecker.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 StringBuilder allSummaries = new StringBuilder();
    final RestLiResourceModelCompatibilityChecker checker = new RestLiResourceModelCompatibilityChecker();
    for (int i = 1; i < targets.length; i += 2) {
        checker.setResolverPath(System.getProperty(AbstractGenerator.GENERATOR_RESOLVER_PATH));
        String prevTarget = targets[i - 1];
        String currTarget = targets[i];
        checker.check(prevTarget, currTarget, compat);
    }
    allSummaries.append(checker.getInfoMap().createSummary());
    if (compat != CompatibilityLevel.OFF && allSummaries.length() > 0) {
        System.out.println(allSummaries);
    }
    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) CommandLineParser(org.apache.commons.cli.CommandLineParser) ParseException(org.apache.commons.cli.ParseException)

Aggregations

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