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));
}
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);
}
}
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());
}
}
Aggregations