This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git


The following commit(s) were added to refs/heads/master by this push:
     new 23cb0f4  CAMEL-14044: camel catalog tooling - Do not report validation 
error for camel uri based on property placeholder; such incpable parsing etc
23cb0f4 is described below

commit 23cb0f489c35a5dadeb9bac68495316f696f604a
Author: Claus Ibsen <claus.ib...@gmail.com>
AuthorDate: Mon Oct 14 06:23:39 2019 +0200

    CAMEL-14044: camel catalog tooling - Do not report validation error for 
camel uri based on property placeholder; such incpable parsing etc
---
 .../org/apache/camel/catalog/CamelCatalogTest.java |  9 +++--
 .../src/main/docs/camel-report-maven-plugin.adoc   |  2 +-
 .../java/org/apache/camel/maven/ValidateMojo.java  | 17 ++-------
 .../runtimecatalog/EndpointValidationResult.java   | 42 ++++++++++++++--------
 .../impl/RuntimeCamelCatalogTest.java              | 23 +++++++-----
 5 files changed, 51 insertions(+), 42 deletions(-)

diff --git 
a/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
 
b/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
index 8b3761a..72ce4b7 100644
--- 
a/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
+++ 
b/catalog/camel-catalog/src/test/java/org/apache/camel/catalog/CamelCatalogTest.java
@@ -682,9 +682,11 @@ public class CamelCatalogTest {
 
         // unknown component
         result = catalog.validateEndpointProperties("foo:bar?me=you");
-        assertFalse(result.isSuccess());
+        assertTrue(result.isSuccess());
+        assertTrue(result.hasWarnings());
         assertTrue(result.getUnknownComponent().equals("foo"));
-        assertEquals(1, result.getNumberOfErrors());
+        assertEquals(0, result.getNumberOfErrors());
+        assertEquals(1, result.getNumberOfWarnings());
 
         // invalid boolean but default value
         result = catalog.validateEndpointProperties("log:output?showAll=ggg");
@@ -792,7 +794,8 @@ public class CamelCatalogTest {
 
         // incapable to parse
         result = 
catalog.validateEndpointProperties("{{getFtpUrl}}?recursive=true");
-        assertFalse(result.isSuccess());
+        assertTrue(result.isSuccess());
+        assertTrue(result.hasWarnings());
         assertTrue(result.getIncapable() != null);
     }
 
diff --git 
a/catalog/camel-report-maven-plugin/src/main/docs/camel-report-maven-plugin.adoc
 
b/catalog/camel-report-maven-plugin/src/main/docs/camel-report-maven-plugin.adoc
index 3f406ea..903b6ab 100644
--- 
a/catalog/camel-report-maven-plugin/src/main/docs/camel-report-maven-plugin.adoc
+++ 
b/catalog/camel-report-maven-plugin/src/main/docs/camel-report-maven-plugin.adoc
@@ -148,7 +148,7 @@ The maven plugin *validate* goal supports the following 
options which can be con
 | showAll | false | Whether to show all endpoints and simple expressions (both 
invalid and valid).
 |===
 
-For example to turn off ignorning usage of deprecated options from the command 
line, you can run:
+For example to turn off ignoring usage of deprecated options from the command 
line, you can run:
 
 ----
 $mvn camel-report:validate -Dcamel.ignoreDeprecated=true
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 f12ad75..8f17ace 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
@@ -64,35 +64,30 @@ public class ValidateMojo extends AbstractExecMojo {
 
     /**
      * 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;
 
     /**
      * Whether to log endpoint URIs which was un-parsable and therefore not 
possible to validate
-     *
      */
     @Parameter(property = "camel.logUnparseable", defaultValue = "false")
     private boolean logUnparseable;
 
     /**
      * Whether to include Java files to be validated for invalid Camel 
endpoints
-     *
      */
     @Parameter(property = "camel.includeJava", defaultValue = "true")
     private boolean includeJava;
 
     /**
      * Whether to include XML files to be validated for invalid Camel endpoints
-     *
      */
     @Parameter(property = "camel.includeXml", defaultValue = "true")
     private boolean includeXml;
 
     /**
      * Whether to include test source code
-     *
      */
     @Parameter(property = "camel.includeTest", defaultValue = "false")
     private boolean includeTest;
@@ -113,21 +108,18 @@ public class ValidateMojo extends AbstractExecMojo {
 
     /**
      * Whether to ignore unknown components
-     *
      */
     @Parameter(property = "camel.ignoreUnknownComponent", defaultValue = 
"true")
     private boolean ignoreUnknownComponent;
 
     /**
      * Whether to ignore incapable of parsing the endpoint uri
-     *
      */
     @Parameter(property = "camel.ignoreIncapable", defaultValue = "true")
     private boolean ignoreIncapable;
 
     /**
      * Whether to ignore deprecated options being used in the endpoint uri
-     *
      */
     @Parameter(property = "camel.ignoreDeprecated", defaultValue = "true")
     private boolean ignoreDeprecated;
@@ -136,14 +128,12 @@ public class ValidateMojo extends AbstractExecMojo {
      * Whether to ignore components that uses lenient properties. When this is 
true, then the uri validation is stricter
      * but would fail on properties that are not part of the component but in 
the uri because of using lenient properties.
      * For example using the HTTP components to provide query parameters in 
the endpoint uri.
-     *
      */
     @Parameter(property = "camel.ignoreLenientProperties", defaultValue = 
"true")
     private boolean ignoreLenientProperties;
 
     /**
      * Whether to show all endpoints and simple expressions (both invalid and 
valid).
-     *
      */
     @Parameter(property = "camel.showAll", defaultValue = "false")
     private boolean showAll;
@@ -151,7 +141,6 @@ public class ValidateMojo extends AbstractExecMojo {
     /**
      * 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.
-     *
      */
     @Parameter(property = "camel.downloadVersion", defaultValue = "true")
     private boolean downloadVersion;
@@ -159,14 +148,12 @@ public class ValidateMojo extends AbstractExecMojo {
     /**
      * Whether to validate for duplicate route ids. Route ids should be unique 
and if there are duplicates
      * then Camel will fail to startup.
-     *
      */
     @Parameter(property = "camel.duplicateRouteId", defaultValue = "true")
     private boolean duplicateRouteId;
 
     /**
      * Whether to validate direct/seda endpoints sending to non existing 
consumers.
-     *
      */
     @Parameter(property = "camel.directOrSedaPairCheck", defaultValue = "true")
     private boolean directOrSedaPairCheck;
@@ -330,7 +317,7 @@ public class ValidateMojo extends AbstractExecMojo {
             int deprecated = result.getDeprecated() != null ? 
result.getDeprecated().size() : 0;
             deprecatedOptions += deprecated;
 
-            boolean ok = result.isSuccess();
+            boolean ok = result.isSuccess() && !result.hasWarnings();
             if (!ok && ignoreUnknownComponent && result.getUnknownComponent() 
!= null) {
                 // if we failed due unknown component then be okay if we 
should ignore that
                 unknownComponents++;
@@ -378,7 +365,7 @@ public class ValidateMojo extends AbstractExecMojo {
                     sb.append(detail.getFileName());
                 }
                 sb.append("\n\n");
-                String out = result.summaryErrorMessage(false, 
ignoreDeprecated);
+                String out = result.summaryErrorMessage(false, 
ignoreDeprecated, true);
                 sb.append(out);
                 sb.append("\n\n");
 
diff --git 
a/core/camel-api/src/main/java/org/apache/camel/runtimecatalog/EndpointValidationResult.java
 
b/core/camel-api/src/main/java/org/apache/camel/runtimecatalog/EndpointValidationResult.java
index d4b1ea1..091820a 100644
--- 
a/core/camel-api/src/main/java/org/apache/camel/runtimecatalog/EndpointValidationResult.java
+++ 
b/core/camel-api/src/main/java/org/apache/camel/runtimecatalog/EndpointValidationResult.java
@@ -32,9 +32,11 @@ public class EndpointValidationResult implements 
Serializable {
 
     private final String uri;
     private int errors;
+    private int warnings;
 
-    // general
+    // general error
     private String syntaxError;
+    // general warnings
     private String unknownComponent;
     private String incapable;
 
@@ -75,9 +77,16 @@ public class EndpointValidationResult implements 
Serializable {
         return errors;
     }
 
+    public boolean hasWarnings() {
+        return warnings > 0;
+    }
+
+    public int getNumberOfWarnings() {
+        return warnings;
+    }
+
     public boolean isSuccess() {
-        boolean ok = syntaxError == null && unknownComponent == null && 
incapable == null
-                && unknown == null && required == null;
+        boolean ok = syntaxError == null && unknown == null && required == 
null;
         if (ok) {
             ok = notConsumerOnly == null && notProducerOnly == null;
         }
@@ -95,12 +104,12 @@ public class EndpointValidationResult implements 
Serializable {
 
     public void addIncapable(String uri) {
         this.incapable = uri;
-        errors++;
+        warnings++;
     }
 
     public void addUnknownComponent(String name) {
         this.unknownComponent = name;
-        errors++;
+        warnings++;
     }
 
     public void addUnknown(String name) {
@@ -325,7 +334,7 @@ public class EndpointValidationResult implements 
Serializable {
      * @return the summary, or <tt>null</tt> if no validation errors
      */
     public String summaryErrorMessage(boolean includeHeader) {
-        return summaryErrorMessage(includeHeader, true);
+        return summaryErrorMessage(includeHeader, true, false);
     }
 
     /**
@@ -333,9 +342,10 @@ public class EndpointValidationResult implements 
Serializable {
      *
      * @param includeHeader    whether to include a header
      * @param ignoreDeprecated whether to ignore deprecated options in use as 
an error or not
+     * @param includeWarnings  whether to include warnings as an error or not
      * @return the summary, or <tt>null</tt> if no validation errors
      */
-    public String summaryErrorMessage(boolean includeHeader, boolean 
ignoreDeprecated) {
+    public String summaryErrorMessage(boolean includeHeader, boolean 
ignoreDeprecated, boolean includeWarnings) {
         boolean ok = isSuccess();
 
         // special check if we should ignore deprecated options being used
@@ -343,16 +353,18 @@ public class EndpointValidationResult implements 
Serializable {
             ok = deprecated == null;
         }
 
-        if (ok) {
-            return null;
+        if (includeWarnings) {
+            if (incapable != null) {
+                return "\tIncapable of parsing uri: " + incapable;
+            } else if (syntaxError != null) {
+                return "\tSyntax error: " + syntaxError;
+            } else if (unknownComponent != null) {
+                return "\tUnknown component: " + unknownComponent;
+            }
         }
 
-        if (incapable != null) {
-            return "\tIncapable of parsing uri: " + incapable;
-        } else if (syntaxError != null) {
-            return "\tSyntax error: " + syntaxError;
-        } else if (unknownComponent != null) {
-            return "\tUnknown component: " + unknownComponent;
+        if (ok) {
+            return null;
         }
 
         // for each invalid option build a reason message
diff --git 
a/core/camel-core/src/test/java/org/apache/camel/runtimecatalog/impl/RuntimeCamelCatalogTest.java
 
b/core/camel-core/src/test/java/org/apache/camel/runtimecatalog/impl/RuntimeCamelCatalogTest.java
index d950e66..37d79a8 100644
--- 
a/core/camel-core/src/test/java/org/apache/camel/runtimecatalog/impl/RuntimeCamelCatalogTest.java
+++ 
b/core/camel-core/src/test/java/org/apache/camel/runtimecatalog/impl/RuntimeCamelCatalogTest.java
@@ -197,9 +197,11 @@ public class RuntimeCamelCatalogTest {
 
         // unknown component
         result = catalog.validateEndpointProperties("foo:bar?me=you");
-        assertFalse(result.isSuccess());
+        assertTrue(result.isSuccess());
+        assertTrue(result.hasWarnings());
         assertTrue(result.getUnknownComponent().equals("foo"));
-        assertEquals(1, result.getNumberOfErrors());
+        assertEquals(0, result.getNumberOfErrors());
+        assertEquals(1, result.getNumberOfWarnings());
 
         // invalid boolean but default value
         result = catalog.validateEndpointProperties("log:output?showAll=ggg");
@@ -229,21 +231,26 @@ public class RuntimeCamelCatalogTest {
 
         // incapable to parse
         result = 
catalog.validateEndpointProperties("{{getFtpUrl}}?recursive=true");
-        assertFalse(result.isSuccess());
+        assertTrue(result.isSuccess());
+        assertTrue(result.hasWarnings());
         assertTrue(result.getIncapable() != null);
     }
 
     @Test
-    public void validatePropertiesSummary() throws Exception {
+    public void validatePropertiesSummaryUnknown() throws Exception {
+        // unknown component yammer
         EndpointValidationResult result = catalog
             
.validateEndpointProperties("yammer:MESSAGES?blah=yada&accessToken=aaa&consumerKey=&useJson=no&initialDelay=five&pollStrategy=myStrategy");
-        assertFalse(result.isSuccess());
-        String reason = result.summaryErrorMessage(true);
+        assertTrue(result.isSuccess());
+        assertTrue(result.hasWarnings());
+        String reason = result.summaryErrorMessage(true, true, true);
         LOG.info(reason);
 
+        // unknown component jms
         result = catalog.validateEndpointProperties("jms:unknown:myqueue");
-        assertFalse(result.isSuccess());
-        reason = result.summaryErrorMessage(false);
+        assertTrue(result.isSuccess());
+        assertTrue(result.hasWarnings());
+        reason = result.summaryErrorMessage(false, false, true);
         LOG.info(reason);
     }
 

Reply via email to