This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch main in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push: new cfd2b1745a4 Add properties to skip execution of the validate and route coverage mojos (#13717) cfd2b1745a4 is described below commit cfd2b1745a405984b3f45a75d06f8445dfa9c9de Author: Adriano Machado <60320+ammach...@users.noreply.github.com> AuthorDate: Sat Apr 13 01:51:16 2024 -0400 Add properties to skip execution of the validate and route coverage mojos (#13717) * Add properties to skip execution of the validate and route coverage mojos * Fixing typo * Better log messages * Adding new parameters to documentation --- catalog/camel-report-maven-plugin/pom.xml | 12 ------- .../org/apache/camel/maven/RouteCoverageMojo.java | 14 ++++++-- .../java/org/apache/camel/maven/ValidateMojo.java | 37 +++++++++++++++------- .../ROOT/pages/camel-report-maven-plugin.adoc | 2 ++ 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/catalog/camel-report-maven-plugin/pom.xml b/catalog/camel-report-maven-plugin/pom.xml index 2ae648c57b6..19e9a38649e 100644 --- a/catalog/camel-report-maven-plugin/pom.xml +++ b/catalog/camel-report-maven-plugin/pom.xml @@ -55,18 +55,6 @@ <groupId>org.apache.maven</groupId> <artifactId>maven-core</artifactId> </dependency> - <!-- we extend the exec-maven-plugin for this camel maven plugin --> - <dependency> - <groupId>org.codehaus.mojo</groupId> - <artifactId>exec-maven-plugin</artifactId> - <version>${exec-maven-plugin-version}</version> - <exclusions> - <exclusion> - <groupId>org.apache.maven</groupId> - <artifactId>maven-plugin-descriptor</artifactId> - </exclusion> - </exclusions> - </dependency> <dependency> <groupId>org.apache.maven</groupId> <artifactId>maven-plugin-api</artifactId> diff --git a/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/RouteCoverageMojo.java b/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/RouteCoverageMojo.java index fc3af32c3c2..ff56fe196b1 100644 --- a/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/RouteCoverageMojo.java +++ b/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/RouteCoverageMojo.java @@ -43,6 +43,7 @@ import javax.xml.transform.TransformerFactory; import javax.xml.transform.dom.DOMSource; import javax.xml.transform.stream.StreamResult; +import org.apache.maven.plugin.AbstractMojo; import org.w3c.dom.Attr; import org.w3c.dom.Document; import org.w3c.dom.Element; @@ -59,7 +60,6 @@ import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; -import org.codehaus.mojo.exec.AbstractExecMojo; import org.jboss.forge.roaster.Roaster; import org.jboss.forge.roaster.model.JavaType; import org.jboss.forge.roaster.model.source.JavaClassSource; @@ -74,7 +74,7 @@ import static org.apache.camel.catalog.common.CatalogHelper.stripRootPath; * Performs route coverage reports after running Camel unit tests with camel-test modules */ @Mojo(name = "route-coverage", threadSafe = true) -public class RouteCoverageMojo extends AbstractExecMojo { +public class RouteCoverageMojo extends AbstractMojo { public static final String DESTINATION_DIR = "/target/camel-route-coverage"; /** @@ -83,6 +83,12 @@ public class RouteCoverageMojo extends AbstractExecMojo { @Parameter(property = "project", required = true, readonly = true) protected MavenProject project; + /** + * Skip route coverage execution. + */ + @Parameter(property = "camel.skipRouteCoverage", defaultValue = "false") + private boolean skip; + /** * Whether to fail if a route was not fully covered. * @@ -152,6 +158,10 @@ public class RouteCoverageMojo extends AbstractExecMojo { @Override public void execute() throws MojoExecutionException { + if (skip) { + getLog().info("skipping route coverage as per configuration"); + return; + } Set<File> javaFiles = new LinkedHashSet<>(); Set<File> xmlFiles = new LinkedHashSet<>(); diff --git a/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/ValidateMojo.java b/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/ValidateMojo.java index 0e7436ff431..529573b5b89 100644 --- a/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/ValidateMojo.java +++ b/catalog/camel-report-maven-plugin/src/main/java/org/apache/camel/maven/ValidateMojo.java @@ -45,14 +45,15 @@ import org.apache.camel.tooling.maven.MavenResolutionException; import org.apache.camel.util.OrderedProperties; import org.apache.camel.util.StringHelper; import org.apache.commons.io.IOUtils; +import org.apache.maven.execution.MavenSession; import org.apache.maven.model.Dependency; import org.apache.maven.model.Resource; +import org.apache.maven.plugin.AbstractMojo; import org.apache.maven.plugin.MojoExecutionException; import org.apache.maven.plugins.annotations.Component; import org.apache.maven.plugins.annotations.Mojo; import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.project.MavenProject; -import org.codehaus.mojo.exec.AbstractExecMojo; import org.eclipse.aether.RepositorySystem; import org.eclipse.aether.RepositorySystemSession; import org.jboss.forge.roaster.Roaster; @@ -71,7 +72,7 @@ import static org.apache.camel.catalog.common.FileUtil.findJavaFiles; * configuration files such as application.properties. */ @Mojo(name = "validate", threadSafe = true) -public class ValidateMojo extends AbstractExecMojo { +public class ValidateMojo extends AbstractMojo { /** * The maven project. @@ -79,8 +80,17 @@ public class ValidateMojo extends AbstractExecMojo { @Parameter(property = "project", required = true, readonly = true) protected MavenProject project; + @Parameter(defaultValue = "${session}", readonly = true, required = true) + private MavenSession session; + + /** + * Skip the validation execution. + */ + @Parameter(property = "camel.skipValidation", defaultValue = "false") + private boolean skip; + /** - * Whether to fail if invalid Camel endpoints was found. By default the plugin logs the errors at WARN level + * Whether to fail if invalid Camel endpoints was found. By default, the plugin logs the errors at WARN level */ @Parameter(property = "camel.failOnError", defaultValue = "false") private boolean failOnError; @@ -185,7 +195,7 @@ public class ValidateMojo extends AbstractExecMojo { private boolean duplicateRouteId; /** - * Whether to validate direct/seda endpoints sending to non existing consumers. + * Whether to validate direct/seda endpoints sending to non-existing consumers. */ @Parameter(property = "camel.directOrSedaPairCheck", defaultValue = "true") private boolean directOrSedaPairCheck; @@ -201,8 +211,8 @@ public class ValidateMojo extends AbstractExecMojo { * Location of configuration files to validate. The default is application.properties Multiple values can be * separated by comma and use wildcard pattern matching. */ - @Parameter(property = "camel.configurationFiles") - private String configurationFiles = "application.properties"; + @Parameter(property = "camel.configurationFiles", defaultValue = "application.properties") + private String configurationFiles; @Component private RepositorySystem repositorySystem; @@ -213,16 +223,21 @@ public class ValidateMojo extends AbstractExecMojo { /** * javaFiles in memory cache, useful for multi modules maven project */ - private static Set<File> javaFiles = new LinkedHashSet<>(); + private static final Set<File> javaFiles = new LinkedHashSet<>(); /** * xmlFiles in memory cache, useful for multi modules maven project */ - private static Set<File> xmlFiles = new LinkedHashSet<>(); + private static final Set<File> xmlFiles = new LinkedHashSet<>(); - private static Set<String> downloadedArtifacts = new LinkedHashSet<>(); + private static final Set<String> downloadedArtifacts = new LinkedHashSet<>(); @Override public void execute() throws MojoExecutionException { + if (skip) { + getLog().info("skipping route validation as per configuration"); + return; + } + // Download extra sources only if artifacts sources are defined and the current project is not a parent project if (!"pom".equals(project.getPackaging()) && sourcesArtifacts != null && sourcesArtifacts.length > 0) { // setup MavenDownloader, it will be used to download and locate artifacts declared via sourcesArtifacts @@ -239,7 +254,7 @@ public class ValidateMojo extends AbstractExecMojo { }); try (MavenDownloaderImpl downloader - = new MavenDownloaderImpl(repositorySystem, repositorySystemSession, getSession().getSettings())) { + = new MavenDownloaderImpl(repositorySystem, repositorySystemSession, session.getSettings())) { downloader.init(); Set<String> repositorySet = Arrays.stream(extraMavenRepositories) .collect(Collectors.toSet()); @@ -298,7 +313,7 @@ public class ValidateMojo extends AbstractExecMojo { catalog.setSuggestionStrategy(new LuceneSuggestionStrategy()); // enable loading other catalog versions dynamically catalog.setVersionManager( - new MavenVersionManager(repositorySystem, repositorySystemSession, getSession().getSettings())); + new MavenVersionManager(repositorySystem, repositorySystemSession, session.getSettings())); // use custom class loading catalog.getJSonSchemaResolver().setClassLoader(ValidateMojo.class.getClassLoader()); // enable caching diff --git a/docs/user-manual/modules/ROOT/pages/camel-report-maven-plugin.adoc b/docs/user-manual/modules/ROOT/pages/camel-report-maven-plugin.adoc index c0cf076b7c2..56eac9211fd 100644 --- a/docs/user-manual/modules/ROOT/pages/camel-report-maven-plugin.adoc +++ b/docs/user-manual/modules/ROOT/pages/camel-report-maven-plugin.adoc @@ -133,6 +133,7 @@ The maven plugin *validate* goal supports the following options which can be con |=== | Parameter | Default Value | Description +| skip | false | Whether to skip the plugin execution. | downloadVersion | true | Whether to allow downloading Camel catalog version from the internet. This is needed if the project uses a different Camel version than this plugin is using by default. | failOnError | false | Whether to fail if invalid Camel endpoints was found. By default the plugin logs the errors at WARN level. | coverageThreshold | 100 | The minimum route coverage in percent when using failOnError. @@ -351,6 +352,7 @@ The maven plugin *coverage* goal supports the following options which can be con |=== | Parameter | Default Value | Description +| skip | false | Whether to skip the plugin execution. | failOnError | false | Whether to fail if any of the routes has not 100% coverage. | includeTest | false | Whether to include test source code. | includes | | To filter the names of java and xml files to only include files matching any of the given list of