davsclaus commented on code in PR #27717:
URL: https://github.com/apache/camel/pull/27717#discussion_r4248001465
##########
dsl/camel-jbang/camel-jbang-core/src/main/java/org/apache/camel/dsl/jbang/core/commands/ai/EndpointConsumerChecks.java:
##########
@@ -189,46 +187,55 @@ private static boolean isRouteFile(Path f) {
* constants, String.format and the endpoint DSL are resolved; null when
they cannot be known: a route template,
* whose input is a parameter, an input known only at runtime, or a from(
the parser could not read.
*/
- static Set<String> javaConsumed(String src, CamelCatalog catalog) {
- JavaParseResult result = JavaRouteReader.parse(src, catalog, null);
- if (!result.routeTemplates().getRouteTemplates().isEmpty()) {
- return null;
- }
- List<RouteDefinition> routes = result.routes().getRoutes();
- if (routes.isEmpty() && JAVA_FROM.matcher(src).find()) {
+ static Set<String> javaConsumed(String fileName, String src, CamelCatalog
catalog) {
+ RouteModel model = RouteModel.read(fileName, src, catalog, Map.of());
+ if (model == null || model.routes().isEmpty()) {
// a from( the parser did not read as a route: what it consumes is
not known
- return null;
+ return JAVA_FROM.matcher(src).find() ? null : Set.of();
}
- Set<String> answer = new HashSet<>();
- for (RouteDefinition r : routes) {
- String uri = r.getInput() != null ? r.getInput().getUri() : null;
- if (uri == null || uri.contains(LwJavaParser.UNRESOLVED_PREFIX) ||
!add(uri, answer)) {
- return null;
- }
+ return consumed(model, RouteNodes.of(model, catalog));
+ }
+
+ /**
+ * The endpoints the routes of an XML DSL source consume, read into the
model; empty for an XML file that is not a
+ * Camel route file, null when it cannot be read or a route consumes an
endpoint only known at runtime.
+ */
+ static Set<String> xmlConsumed(String fileName, String src) {
+ RouteModel model = RouteModel.read(fileName, src, null, Map.of());
+ if (model == null) {
+ return Set.of();
}
- return answer;
+ if (model.unread().stream().anyMatch(RouteModel.Unread::error)) {
+ // a file the XML DSL refuses: what it consumes is not known
+ return null;
+ }
+ return consumed(model, RouteNodes.of(model, null));
}
- static Set<String> xmlConsumed(String src) {
+ /**
+ * The checked endpoints the routes of a Java or XML source consume: their
inputs, and the poll and pollEnrich
+ * steps; null when they cannot be known: a route template (or a route
made from one), or an endpoint only known at
+ * runtime (a placeholder, an expression, a value the parser could not
work out), which could be any of them.
+ */
+ static Set<String> consumed(RouteModel model, List<RouteNodes.Node> nodes)
{
+ if (model.hasTemplates()) {
+ return null;
+ }
Set<String> answer = new HashSet<>();
- Matcher m = XML_FROM.matcher(src);
- while (m.find()) {
- if (!add(m.group(1), answer)) {
+ for (RouteNodes.Node n : nodes) {
+ if (n.kind() != RouteNodes.Kind.ENDPOINT ||
!EndpointRules.CONSUMERS.contains(n.eip())) {
+ continue;
+ }
+ String uri = n.uri();
+ if (uri == null || RouteModel.hasUnknownValue(uri)
+ || EndpointRules.isDynamic(uri) &&
EndpointRules.mayBeChecked(uri)) {
Review Comment:
Applied in 4cd509f6cef9.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]