Search in sources :

Example 1 with JsonbBuilder

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());
    }
}
Also used : JsonbBuilder(javax.json.bind.JsonbBuilder) ContainerComponentRegistry(org.talend.sdk.component.runtime.manager.ContainerComponentRegistry) Container(org.talend.sdk.component.container.Container) Collections.emptyList(java.util.Collections.emptyList) Collection(java.util.Collection) FileOutputStream(java.io.FileOutputStream) Parameter(org.apache.maven.plugins.annotations.Parameter) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JsonbConfig(javax.json.bind.JsonbConfig) File(java.io.File) FileNotFoundException(java.io.FileNotFoundException) Collections.singletonList(java.util.Collections.singletonList) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Mojo(org.apache.maven.plugins.annotations.Mojo) Collectors.toList(java.util.stream.Collectors.toList) Stream(java.util.stream.Stream) Locale(java.util.Locale) PROCESS_CLASSES(org.apache.maven.plugins.annotations.LifecyclePhase.PROCESS_CLASSES) Data(lombok.Data) Jsonb(javax.json.bind.Jsonb) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) COMPILE_PLUS_RUNTIME(org.apache.maven.plugins.annotations.ResolutionScope.COMPILE_PLUS_RUNTIME) AllArgsConstructor(lombok.AllArgsConstructor) Method(java.lang.reflect.Method) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) JsonbBuilder(javax.json.bind.JsonbBuilder) FileNotFoundException(java.io.FileNotFoundException) Method(java.lang.reflect.Method) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) FileNotFoundException(java.io.FileNotFoundException) MojoFailureException(org.apache.maven.plugin.MojoFailureException) Jsonb(javax.json.bind.Jsonb) JsonbConfig(javax.json.bind.JsonbConfig) FileOutputStream(java.io.FileOutputStream) File(java.io.File)

Aggregations

File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 Method (java.lang.reflect.Method)1 Collection (java.util.Collection)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 Locale (java.util.Locale)1 Collectors.toList (java.util.stream.Collectors.toList)1 Stream (java.util.stream.Stream)1 Jsonb (javax.json.bind.Jsonb)1 JsonbBuilder (javax.json.bind.JsonbBuilder)1 JsonbConfig (javax.json.bind.JsonbConfig)1 AllArgsConstructor (lombok.AllArgsConstructor)1 Data (lombok.Data)1 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)1 MojoFailureException (org.apache.maven.plugin.MojoFailureException)1 PROCESS_CLASSES (org.apache.maven.plugins.annotations.LifecyclePhase.PROCESS_CLASSES)1 Mojo (org.apache.maven.plugins.annotations.Mojo)1 Parameter (org.apache.maven.plugins.annotations.Parameter)1