Search in sources :

Example 1 with DefaultPackageScanResourceResolver

use of org.apache.camel.impl.engine.DefaultPackageScanResourceResolver 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);
                }
            }
        }
    }
}
Also used : CamelSupport(org.apache.camel.quarkus.core.deployment.util.CamelSupport) Resource(org.apache.camel.spi.Resource) Logger(org.jboss.logging.Logger) SAXParserFactory(javax.xml.parsers.SAXParserFactory) LanguageExpressionContentHandler(org.apache.camel.quarkus.core.deployment.LanguageExpressionContentHandler) FileNotFoundException(java.io.FileNotFoundException) BuildProducer(io.quarkus.deployment.annotations.BuildProducer) BuildStep(io.quarkus.deployment.annotations.BuildStep) Stream(java.util.stream.Stream) DefaultPackageScanResourceResolver(org.apache.camel.impl.engine.DefaultPackageScanResourceResolver) SAXParser(javax.xml.parsers.SAXParser) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) AntPathMatcher(org.apache.camel.util.AntPathMatcher) InputStream(java.io.InputStream) LanguageExpressionContentHandler(org.apache.camel.quarkus.core.deployment.LanguageExpressionContentHandler) InputStream(java.io.InputStream) DefaultPackageScanResourceResolver(org.apache.camel.impl.engine.DefaultPackageScanResourceResolver) Resource(org.apache.camel.spi.Resource) FileNotFoundException(java.io.FileNotFoundException) DefaultCamelContext(org.apache.camel.impl.DefaultCamelContext) FileNotFoundException(java.io.FileNotFoundException) SAXParser(javax.xml.parsers.SAXParser) Stream(java.util.stream.Stream) InputStream(java.io.InputStream) SAXParserFactory(javax.xml.parsers.SAXParserFactory) BuildStep(io.quarkus.deployment.annotations.BuildStep)

Aggregations

BuildProducer (io.quarkus.deployment.annotations.BuildProducer)1 BuildStep (io.quarkus.deployment.annotations.BuildStep)1 FileNotFoundException (java.io.FileNotFoundException)1 InputStream (java.io.InputStream)1 Stream (java.util.stream.Stream)1 SAXParser (javax.xml.parsers.SAXParser)1 SAXParserFactory (javax.xml.parsers.SAXParserFactory)1 DefaultCamelContext (org.apache.camel.impl.DefaultCamelContext)1 DefaultPackageScanResourceResolver (org.apache.camel.impl.engine.DefaultPackageScanResourceResolver)1 LanguageExpressionContentHandler (org.apache.camel.quarkus.core.deployment.LanguageExpressionContentHandler)1 CamelSupport (org.apache.camel.quarkus.core.deployment.util.CamelSupport)1 Resource (org.apache.camel.spi.Resource)1 AntPathMatcher (org.apache.camel.util.AntPathMatcher)1 Logger (org.jboss.logging.Logger)1