use of javax.json.bind.JsonbConfig in project component-runtime by Talend.
the class ComponentManager method containerServices.
protected void containerServices(final Container container, final Map<Class<?>, Object> services) {
// note: we can move it to manager instances at some point
final JsonProvider jsonpProvider = new PreComputedJsonpProvider(container.getId(), this.jsonpProvider, jsonpParserFactory, jsonpWriterFactory, jsonpBuilderFactory, jsonpGeneratorFactory, jsonpReaderFactory);
services.put(JsonProvider.class, jsonpProvider);
services.put(JsonBuilderFactory.class, javaProxyEnricherFactory.asSerializable(container.getLoader(), container.getId(), JsonBuilderFactory.class.getName(), jsonpBuilderFactory));
services.put(JsonParserFactory.class, javaProxyEnricherFactory.asSerializable(container.getLoader(), container.getId(), JsonParserFactory.class.getName(), jsonpParserFactory));
services.put(JsonReaderFactory.class, javaProxyEnricherFactory.asSerializable(container.getLoader(), container.getId(), JsonReaderFactory.class.getName(), jsonpReaderFactory));
services.put(JsonWriterFactory.class, javaProxyEnricherFactory.asSerializable(container.getLoader(), container.getId(), JsonWriterFactory.class.getName(), jsonpWriterFactory));
services.put(JsonGeneratorFactory.class, javaProxyEnricherFactory.asSerializable(container.getLoader(), container.getId(), JsonGeneratorFactory.class.getName(), jsonpGeneratorFactory));
final Jsonb jsonb = jsonbProvider.create().withProvider(// reuses the same memory buffering
jsonpProvider).withConfig(new JsonbConfig().setProperty("johnzon.cdi.activated", false)).build();
final Jsonb serializableJsonb = Jsonb.class.cast(javaProxyEnricherFactory.asSerializable(container.getLoader(), container.getId(), Jsonb.class.getName(), jsonb));
services.put(Jsonb.class, serializableJsonb);
// not JSON services
services.put(HttpClientFactory.class, new HttpClientFactoryImpl(container.getId(), reflections, serializableJsonb, services));
services.put(LocalCache.class, new LocalCacheService(container.getId()));
services.put(LocalConfiguration.class, new LocalConfigurationService(createRawLocalConfigurations(), container.getId()));
services.put(ProxyGenerator.class, proxyGenerator);
services.put(Resolver.class, new ResolverImpl(container.getId(), container.getLocalDependencyRelativeResolver()));
}
use of javax.json.bind.JsonbConfig in project component-runtime by Talend.
the class Generator method generatedContributors.
private static void generatedContributors(final File generatedDir, final String user, final String pwd) throws Exception {
final Collection<Contributor> contributors;
if (user == null || user.trim().isEmpty() || "skip".equals(user)) {
log.error("No Github credentials, will skip contributors generation");
return;
} else {
try {
contributors = new Github(user, pwd).load();
} catch (final RuntimeException re) {
log.error(re.getMessage(), re);
return;
}
}
final File file = new File(generatedDir, "generated_contributors.adoc");
try (final Jsonb jsonb = JsonbBuilder.create(new JsonbConfig().withPropertyOrderStrategy(PropertyOrderStrategy.LEXICOGRAPHICAL).withFormatting(true));
final OutputStream writer = new WriteIfDifferentStream(file)) {
writer.write("++++\n".getBytes(StandardCharsets.UTF_8));
jsonb.toJson(contributors, writer);
writer.write("\n++++".getBytes(StandardCharsets.UTF_8));
}
}
use of javax.json.bind.JsonbConfig 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());
}
}
use of javax.json.bind.JsonbConfig in project component-runtime by Talend.
the class LoopState method toJsonObject.
private JsonObject toJsonObject(final Object value) {
if (jsonb == null) {
synchronized (this) {
if (jsonb == null) {
final ComponentManager manager = ComponentManager.instance();
jsonb = manager.getJsonbProvider().create().withProvider(manager.getJsonpProvider()).withConfig(new JsonbConfig().setProperty("johnzon.cdi.activated", false)).build();
}
}
}
return jsonb.fromJson(jsonb.toJson(value), JsonObject.class);
}
Aggregations