use of org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem in project camel-quarkus by apache.
the class CamelContextCustomizerTest method buildCustomizer.
static Consumer<BuildChainBuilder> buildCustomizer() {
return new Consumer<BuildChainBuilder>() {
@Override
public void accept(BuildChainBuilder builder) {
builder.addBuildStep(new BuildStep() {
@Override
public void execute(BuildContext context) {
String methodName = "execute";
BytecodeRecorderImpl bri = new BytecodeRecorderImpl(true, getClass().getSimpleName(), methodName, Integer.toString(methodName.hashCode()), true, s -> null);
RuntimeValue<CamelContextCustomizer> value = bri.newInstance(RestConfigurationCustomizer.class.getName());
context.produce(new CamelContextCustomizerBuildItem(value));
context.produce(new StaticBytecodeRecorderBuildItem(bri));
}
}).produces(CamelContextCustomizerBuildItem.class).produces(StaticBytecodeRecorderBuildItem.class).build();
}
};
}
use of org.apache.camel.quarkus.core.deployment.spi.CamelContextCustomizerBuildItem in project camel-quarkus by apache.
the class KameletProcessor method configureTemplates.
@Record(ExecutionTime.STATIC_INIT)
@BuildStep
CamelContextCustomizerBuildItem configureTemplates(List<KameletResolverBuildItem> resolvers, KameletConfiguration configuration, KameletRecorder recorder) throws Exception {
List<RouteTemplateDefinition> definitions = new ArrayList<>();
List<KameletResolver> kameletResolvers = resolvers.stream().map(KameletResolverBuildItem::getResolver).sorted(Comparator.comparingInt(Ordered::getOrder)).collect(Collectors.toList());
CamelContext context = new DefaultCamelContext();
ExtendedCamelContext ecc = context.adapt(ExtendedCamelContext.class);
for (String id : configuration.identifiers.orElse(Collections.emptyList())) {
for (KameletResolver resolver : kameletResolvers) {
final Optional<Resource> resource = resolver.resolve(id, ecc);
if (!resource.isPresent()) {
continue;
}
Collection<RoutesBuilder> rbs = ecc.getRoutesLoader().findRoutesBuilders(resource.get());
for (RoutesBuilder rb : rbs) {
RouteBuilder routeBuilder = (RouteBuilder) rb;
routeBuilder.configure();
if (routeBuilder.getRouteTemplateCollection().getRouteTemplates().size() == 0) {
throw new IllegalStateException("No kamelet template was created for " + "kamelet:" + id + ". It might be that the kamelet was malformed?");
} else if (routeBuilder.getRouteTemplateCollection().getRouteTemplates().size() > 1) {
throw new IllegalStateException("A kamelet is not supposed to create more than one route (" + "kamelet:" + id + "," + "routes: " + routeBuilder.getRouteTemplateCollection().getRouteTemplates().size() + ")");
}
definitions.add(routeBuilder.getRouteTemplateCollection().getRouteTemplates().get(0));
}
}
}
return new CamelContextCustomizerBuildItem(recorder.createTemplateLoaderCustomizer(definitions));
}
Aggregations