use of javax.json.bind.JsonbBuilder in project component-runtime by Talend.
the class ComponentMetadataMojo method doWork.
@Override
protected void doWork(final ComponentManager manager, final Container container, final ContainerComponentRegistry registry) throws MojoExecutionException, MojoFailureException {
final File output = new File(classes, location);
if (!output.getParentFile().exists() && !output.getParentFile().mkdirs()) {
throw new MojoExecutionException("Can't create " + output);
}
final Collection<Component> components = registry.getComponents().values().stream().flatMap(c -> Stream.concat(c.getPartitionMappers().values().stream().map(p -> new Component(p.getParent().getCategories(), p.getParent().getName(), p.getName(), p.findBundle(container.getLoader(), Locale.ENGLISH).displayName().orElse(p.getName()), p.getIcon(), emptyList(), singletonList("MAIN"))), c.getProcessors().values().stream().map(p -> {
final Method listener = p.getListener();
return new Component(p.getParent().getCategories(), p.getParent().getName(), p.getName(), p.findBundle(container.getLoader(), Locale.ENGLISH).displayName().orElse(p.getName()), p.getIcon(), getDesignModel(p).getInputFlows(), getDesignModel(p).getOutputFlows());
}))).collect(toList());
try (final Jsonb mapper = inPluginContext(JsonbBuilder::newBuilder).withConfig(new JsonbConfig().setProperty("johnzon.cdi.activated", false).setProperty("johnzon.attributeOrder", String.CASE_INSENSITIVE_ORDER)).build()) {
container.execute(() -> {
try {
mapper.toJson(new ComponentContainer(components), new FileOutputStream(output));
} catch (final FileNotFoundException e) {
throw new IllegalStateException(e);
}
getLog().info("Created " + output);
return null;
});
} catch (final Exception e) {
throw new MojoExecutionException(e.getMessage());
}
}
Aggregations