Camel Maven Plugin can now parse your source code and report invalid endpoints

I have previously blogged about the fabric8 Camel Maven Plugin which is able to parse your source code and parse all the Java RouteBuilder and XML routes and report invalid Camel endpoints.

That was in the start of 2016. Now at the end of 2016, the code has stabilized and the fabric8 team has gracefully donated the source to to ASF so it will be included out of the box from Apache Camel 2.19.0 onwards.

To see the plugin in action you can watch the video from my previous blog. The plugin would work the same when its from Apache Camel.

To give a demonstration of the plugin, I have modified the camel-example-twitter-websocket example from Apache Camel to make some invalid configurations:

- Renamed the polling to poling in the twitter endpoint
- Added foo=bar as option to the log endpoint
- Spelt the sendToAll option with a lower case a.

And when I run the plugin I see

mvn camel:validate

Then Maven outputs:

[INFO] --- camel-maven-plugin:2.19.0-SNAPSHOT:validate (default-cli) @ camel-example-twitter-websocket ---
[INFO] Using Camel version: 2.19.0-SNAPSHOT
[WARNING] Endpoint validation error at: org.apache.camel.example.websocket.TwitterWebSocketRoute.configure(TwitterWebSocketRoute.java:109)


                   type    Invalid enum value: poling. Possible values: [polling, direct, event]. Did you mean: [polling]. Default value: direct

[WARNING] Endpoint validation error at: org.apache.camel.example.websocket.TwitterWebSocketRoute.configure(TwitterWebSocketRoute.java:110)


                    foo    Unknown option

[WARNING] Endpoint validation error at: org.apache.camel.example.websocket.TwitterWebSocketRoute.configure(TwitterWebSocketRoute.java:112)


              sendToall    Unknown option. Did you mean: [sendToAll]

[WARNING] Endpoint validation error: (0 = passed, 3 = invalid, 0 = incapable, 0 = unknown components)
[INFO] Simple validation success: (0 = passed, 0 = invalid)
[INFO] ------------------------------------------------------------------------
[INFO] ------------------------------------------------------------------------

As you can see it discovered 3 invalid endpoints, and reported suggestions what is the error.

By default the maven goal does not fail maven itself, and hence why you see BUILD SUCCESS. The plugin has a number of options you can configure.

For more information see the Camel Maven Plugin documentation.

PS: The plugin also parses your Simple expressions and report invalid configurations as well.

We may in the future add parsers for other languages so we can parse XPath, XQuery, Groovy and others.


Unknown said...

Really cool, a very valuable part of the CI build process to catch these errors that do occur. Great!

Unknown said...

Now that looks like a very good feature for us Camel users, good work!

Unknown said...

Great feature, How can we pass a directory path so that the goal only checks the routes in that specific directory ?

Claus Ibsen said...

You can use the includes option to only include files matching a pattern or wildcard, so you can try to use that to match the file directory, eg start of the package name etc.