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);
}
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();
}
Aggregations