use of org.apache.camel.quarkus.core.deployment.LanguageExpressionContentHandler in project camel-quarkus by apache.
the class CSimpleXmlProcessor method collectCSimpleExpresions.
@BuildStep
void collectCSimpleExpresions(BuildProducer<CSimpleExpressionSourceBuildItem> csimpleExpressions) throws Exception {
final String[] includes = Stream.of("camel.main.routesIncludePattern", "camel.main.routes-include-pattern").map(prop -> CamelSupport.getOptionalConfigValue(prop, String[].class, new String[0])).flatMap(Stream::of).filter(path -> !path.equals("false")).toArray(String[]::new);
final String[] excludes = Stream.of("camel.main.routesExcludePattern", "camel.main.routes-exclude-pattern").map(prop -> CamelSupport.getOptionalConfigValue(prop, String[].class, new String[0])).flatMap(Stream::of).filter(path -> !path.equals("false")).toArray(String[]::new);
try (DefaultPackageScanResourceResolver resolver = new DefaultPackageScanResourceResolver()) {
resolver.setCamelContext(new DefaultCamelContext());
final SAXParserFactory saxParserFactory = SAXParserFactory.newInstance();
saxParserFactory.setNamespaceAware(true);
final SAXParser saxParser = saxParserFactory.newSAXParser();
for (String include : includes) {
for (Resource resource : resolver.findResources(include)) {
if (AntPathMatcher.INSTANCE.anyMatch(excludes, resource.getLocation())) {
continue;
}
try (InputStream is = resource.getInputStream()) {
saxParser.parse(is, new LanguageExpressionContentHandler("csimple", (script, isPredicate) -> csimpleExpressions.produce(new CSimpleExpressionSourceBuildItem(script, isPredicate, "org.apache.camel.language.csimple.XmlRouteBuilder"))));
} catch (FileNotFoundException e) {
LOG.debugf("No XML routes found in %s. Skipping XML routes detection.", resource.getLocation());
} catch (Exception e) {
throw new RuntimeException("Could not analyze CSimple expressions in " + resource.getLocation(), e);
}
}
}
}
}
Aggregations