Search in sources :

Example 1 with ContainerComponentRegistry

use of org.talend.sdk.component.runtime.manager.ContainerComponentRegistry in project component-runtime by Talend.

the class DesignContainerListener method onCreate.

/**
 * Enriches {@link Container} with {@link DesignModel} and
 * {@link RepositoryModel} It depends on Updater listener which adds
 * {@link ContainerComponentRegistry} class to {@link Container}
 */
@Override
public void onCreate(final Container container) {
    final ContainerComponentRegistry componentRegistry = container.get(ContainerComponentRegistry.class);
    if (componentRegistry == null) {
        throw new IllegalArgumentException("container doesn't contain ContainerComponentRegistry");
    }
    final Collection<ComponentFamilyMeta> componentFamilyMetas = componentRegistry.getComponents().values();
    // Create Design Model
    componentFamilyMetas.stream().flatMap(family -> Stream.concat(family.getPartitionMappers().values().stream(), family.getProcessors().values().stream())).forEach(meta -> {
        final ComponentExtension.ComponentContext context = container.get(ComponentContexts.class).getContexts().get(meta.getType());
        final ComponentExtension owningExtension = context.owningExtension();
        meta.set(DesignModel.class, ofNullable(owningExtension).map(e -> e.unwrap(FlowsFactory.class, meta)).map(e -> new DesignModel(meta.getId(), e.getInputFlows(), e.getOutputFlows())).orElseGet(() -> {
            final FlowsFactory factory = FlowsFactory.get(meta);
            return new DesignModel(meta.getId(), factory.getInputFlows(), factory.getOutputFlows());
        }));
    });
    // Create Repository Model
    container.set(RepositoryModel.class, repositoryModelBuilder.create(container.get(ComponentManager.AllServices.class), componentFamilyMetas, migrationHandlerFactory));
}
Also used : ContainerComponentRegistry(org.talend.sdk.component.runtime.manager.ContainerComponentRegistry) Container(org.talend.sdk.component.container.Container) ComponentContexts(org.talend.sdk.component.runtime.manager.extension.ComponentContexts) Optional.ofNullable(java.util.Optional.ofNullable) Collection(java.util.Collection) ComponentFamilyMeta(org.talend.sdk.component.runtime.manager.ComponentFamilyMeta) Stream(java.util.stream.Stream) FlowsFactory(org.talend.sdk.component.design.extension.flows.FlowsFactory) RepositoryModelBuilder(org.talend.sdk.component.design.extension.repository.RepositoryModelBuilder) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) MigrationHandlerFactory(org.talend.sdk.component.runtime.manager.reflect.MigrationHandlerFactory) ContainerListenerExtension(org.talend.sdk.component.runtime.manager.spi.ContainerListenerExtension) ComponentExtension(org.talend.sdk.component.spi.component.ComponentExtension) ContainerComponentRegistry(org.talend.sdk.component.runtime.manager.ContainerComponentRegistry) FlowsFactory(org.talend.sdk.component.design.extension.flows.FlowsFactory) ComponentFamilyMeta(org.talend.sdk.component.runtime.manager.ComponentFamilyMeta) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager) ComponentExtension(org.talend.sdk.component.spi.component.ComponentExtension)

Example 2 with ContainerComponentRegistry

use of org.talend.sdk.component.runtime.manager.ContainerComponentRegistry in project component-runtime by Talend.

the class ComponentManagerBasedMojo method doExecute.

@Override
protected void doExecute() throws MojoExecutionException, MojoFailureException {
    if (!classes.exists()) {
        throw new MojoExecutionException("No " + classes);
    }
    try (final ComponentManager manager = new ComponentManager(repository, "TALEND-INF/dependencies.txt", "org.talend.sdk.component:type=component,value=%s") {

        {
            addPlugin(artifactId, classes.getAbsolutePath());
        }
    }) {
        final Container container = manager.findPlugin(artifactId).get();
        final ContainerComponentRegistry registry = container.get(ContainerComponentRegistry.class);
        registry.getComponents().values().forEach(c -> {
            c.getPartitionMappers().forEach((k, p) -> getLog().info("Found component " + c.getName() + "#" + p.getName()));
            c.getProcessors().forEach((k, p) -> getLog().info("Found component " + c.getName() + "#" + p.getName()));
        });
        doWork(manager, container, registry);
    }
}
Also used : ContainerComponentRegistry(org.talend.sdk.component.runtime.manager.ContainerComponentRegistry) Container(org.talend.sdk.component.container.Container) MojoExecutionException(org.apache.maven.plugin.MojoExecutionException) ComponentManager(org.talend.sdk.component.runtime.manager.ComponentManager)

Example 3 with ContainerComponentRegistry

use of org.talend.sdk.component.runtime.manager.ContainerComponentRegistry 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

Container (org.talend.sdk.component.container.Container)3 ComponentManager (org.talend.sdk.component.runtime.manager.ComponentManager)3 ContainerComponentRegistry (org.talend.sdk.component.runtime.manager.ContainerComponentRegistry)3 Collection (java.util.Collection)2 Stream (java.util.stream.Stream)2 MojoExecutionException (org.apache.maven.plugin.MojoExecutionException)2 File (java.io.File)1 FileNotFoundException (java.io.FileNotFoundException)1 FileOutputStream (java.io.FileOutputStream)1 Method (java.lang.reflect.Method)1 Collections.emptyList (java.util.Collections.emptyList)1 Collections.singletonList (java.util.Collections.singletonList)1 Locale (java.util.Locale)1 Optional.ofNullable (java.util.Optional.ofNullable)1 Collectors.toList (java.util.stream.Collectors.toList)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