Questo contenuto non è disponibile nella lingua selezionata.

Appendix D. Camel Maven plugin


You can use the camel-maven plugin to validate all your Camel endpoints from the source code. This allows you to ensure that the endpoints are valid before you run your Camel applications or unit tests.

D.1. Camel Maven plugin goals

For validating Camel endpoints in the source code use

  • camel:validate: This goal validates the Maven project source code to identify invalid camel endpoint URIs.

D.2. Adding the camel-maven plugin to your project

You can add the camel-maven plug-in to your project by adding it to your project’s pom.xml file.

Procedure

  1. To enable the Plugin, add the following to the pom.xml file.

    <plugin>
        <groupId>org.jboss.redhat-fuse</groupId>
        <artifactId>camel-maven-plugin</artifactId>
        <version>${fuse.bom.version}</version>
    </plugin>
  2. Run the validate goal from the command line or from your Java editor.

    mvn camel:validate

Running the plugin automatically

You can enable the plugin to run automatically as a part of the build to catch any errors. The phase determines when the plugin runs.

In the following example, the plugin runs in the phase process-classes , which runs after the compilation of the main source code.

Example

<plugin>
    <groupId>org.jboss.redhat-fuse</groupId>
    <artifactId>camel-maven-plugin</artifactId>
    <version>7.13.0.fuse-7_13_0-00012-redhat-00001</version>
    <executions>
        <execution>
            <phase>process-classes</phase>
                <goals>
                    <goal>validate</goal>
                </goals>
        </execution>
    </executions>
</plugin>

Validating the test source code

You can configure the maven plugin to validate the test source code, by changing the phase to process-test-classes:

Example

<plugin>
    <groupId>org.jboss.redhat-fuse</groupId>
    <artifactId>camel-maven-plugin</artifactId>
    <version>7.13.0.fuse-7_13_0-00012-redhat-00001</version>
    <executions>
        <execution>
          <configuration>
            <includeTest>true</includeTest>
          </configuration>
            <phase>process-test-classes</phase>
                <goals>
                    <goal>validate</goal>
                </goals>
        </execution>
    </executions>
</plugin>

D.3. Running the goal on any Maven project

You can also run the validate goal on any Maven project, without adding the Plugin to the pom.xml file. You need to specify the Plugin, using its fully qualified name.

Procedure

  • To run the goal on the camel-example-cdi plugin from Apache Camel, run the following commands:

        $cd camel-example-cdi
        $mvn org.jboss.redhat-fuse:camel-maven-plugin:7.13.0.fuse-7_13_0-00012-redhat-00001:validate

    This displays the following output:

    [INFO] ------------------------------------------------------------------------
    [INFO] Building Camel :: Example :: CDI 2.16.2
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- fabric8-camel-maven-plugin:2.3.80:validate (default-cli) @ camel-example-cdi ---
    [INFO] Endpoint validation success: (4 = passed, 0 = invalid, 0 = incapable, 0 = unknown components)
    [INFO] Simple validation success: (0 = passed, 0 = invalid)
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------

After passing the validation successfully, you can validate the four endpoints. The following example shows how to validate and if required, correct the camel endpoints.

Example

Let us assume that you made a typo in one of the Camel endpoint URIs in the source code, such as:

  1. The correct Camel endpoint URI is as follows.

      @Uri("timer:foo?period=5000")
  2. You can make changes to include a typo error in the period option, such as:

      @Uri("timer:foo?perid=5000")
  3. Run the validate goal again.

    [INFO] ------------------------------------------------------------------------
    [INFO] Building Camel :: Example :: CDI 2.16.2
    [INFO] ------------------------------------------------------------------------
    [INFO]
    [INFO] --- org.jboss.redhat-fuse:camel-maven-plugin:7.13.0.fuse-7_13_0-00012-redhat-00001:validate (default-cli) @ camel-example-cdi ---
    [WARNING] Endpoint validation error at: org.apache.camel.example.cdi.MyRoutes(MyRoutes.java:32)
    
    	timer:foo?perid=5000
    
    	                   perid    Unknown option. Did you mean: [period]
    
    
    [WARNING] Endpoint validation error: (3 = passed, 1 = invalid, 0 = incapable, 0 = unknown components)
    [INFO] Simple validation success: (0 = passed, 0 = invalid)
    [INFO] ------------------------------------------------------------------------
    [INFO] BUILD SUCCESS
    [INFO] ------------------------------------------------------------------------

    As shown above, the error in the camel endpoint URI is displayed.

D.4. Options

The maven plugin supports the following options, which you can configure from the command line (use -D syntax), or defined in the pom.xml file in the <configuration> tag.

Table D.1. Camel Maven plugin options
ParameterDefaultDescriptionComment

downloadVersion

true

Allow downloading Camel catalog version from the internet.

Use if the project uses a different Camel version than the plugin default.

failOnError

false

Fail if invalid Camel endpoints was found.

By default the plug-in logs the errors at WARN level.

logUnparseable

false

Log endpoint URIs which could not be parsed and therefore cannot be validated.

 

includeJava

true

Include Java files in the validation of Camel endpoints.

Also see includes and excludes.

includeXML

true

Include XML files in the validation of Camel endpoints.

Also see includes and excludes.

includeTest

false

Include test source code in validation.

 

includes

-

Wildcard and regular expression patterns to filter java and xml file names to include in validation.

Multiple values can be separated by a comma.

excludes

-

Wildcard and regular expression patterns to filter java and xml files to exclude from validation.

Multiple values can be separated by a comma.

ignoreUnknownComponent

true

Ignore unknown components.

 

ignoreIncapable

true

Ignore incapable of parsing the endpoint URI.

 

ignoreLenientProperties

true

Ignore components that use lenient properties so they can have custom parameters.

By default, URI validation fails on properties that are not part of the component. (For example HTTP components used to provide query parameters in the endpoint URI.)

showAll

false

Show all endpoints and simple expressions.

Both invalid and valid are shown.

D.5. Validating include test

If you have a Maven project, then you can run the plugin to validate the endpoints in the unit test source code as well.

Procedure

  • Pass in the options using -D:
$cd myproject

$mvn org.jboss.redhat-fuse:camel-maven-plugin:7.13.0.fuse-7_13_0-00012-redhat-00001:validate -DincludeTest=true
Red Hat logoGithubRedditYoutubeTwitter

Formazione

Prova, acquista e vendi

Community

Informazioni sulla documentazione di Red Hat

Aiutiamo gli utenti Red Hat a innovarsi e raggiungere i propri obiettivi con i nostri prodotti e servizi grazie a contenuti di cui possono fidarsi.

Rendiamo l’open source più inclusivo

Red Hat si impegna a sostituire il linguaggio problematico nel codice, nella documentazione e nelle proprietà web. Per maggiori dettagli, visita ilBlog di Red Hat.

Informazioni su Red Hat

Forniamo soluzioni consolidate che rendono più semplice per le aziende lavorare su piattaforme e ambienti diversi, dal datacenter centrale all'edge della rete.

© 2024 Red Hat, Inc.