use of org.talend.sdk.component.runtime.manager.reflect.parameterenricher.ValidationParameterEnricher in project component-runtime by Talend.
the class Generator method generatedConstraints.
private static void generatedConstraints(final File generatedDir) throws Exception {
final File file = new File(generatedDir, "generated_constraints.adoc");
try (final PrintStream stream = new PrintStream(new WriteIfDifferentStream(file))) {
stream.println("");
stream.println("[role=\"table-striped table-hover table-ordered\",options=\"header,autowidth\"]");
stream.println("|====");
stream.println("|API|Name|Parameter Type|Description|Supported Types|Metadata sample");
final File api = jarLocation(Validation.class);
final ClassLoader loader = Thread.currentThread().getContextClassLoader();
final AnnotationFinder finder = new AnnotationFinder(api.isDirectory() ? new FileArchive(loader, api) : new JarArchive(loader, api.toURI().toURL()));
final ValidationParameterEnricher enricher = new ValidationParameterEnricher();
final Mapper mapper = new MapperBuilder().build();
Stream.concat(finder.findAnnotatedClasses(Validation.class).stream().map(validation -> {
final Validation val = validation.getAnnotation(Validation.class);
return createConstraint(validation, val);
}), finder.findAnnotatedClasses(Validations.class).stream().flatMap(validations -> Stream.of(validations.getAnnotation(Validations.class).value()).map(validation -> createConstraint(validations, validation)))).sorted((o1, o2) -> {
final int types = Stream.of(o1.types).map(Class::getName).collect(joining("/")).compareTo(Stream.of(o2.types).map(Class::getName).collect(joining("/")));
if (types == 0) {
return o1.name.compareTo(o2.name);
}
return types;
}).forEach(constraint -> stream.println("|@" + constraint.marker.getName() + "|" + constraint.name + "|" + sanitizeType(constraint.paramType) + "|" + constraint.description + "|" + Stream.of(constraint.types).map(Class::getName).map(Generator::sanitizeType).collect(joining(", ")) + "|" + mapper.writeObjectAsString(enricher.onParameterAnnotation("test", constraint.types[0], generateAnnotation(constraint.marker))).replace("tcomp::", "")));
stream.println("|====");
stream.println();
}
}
Aggregations