You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2018/08/17 13:53:18 UTC

[camel] branch master updated: CAMEL-12598: camel-validate maven tool can now also report error when using deprecated options.

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 ba94b89  CAMEL-12598: camel-validate maven tool can now also report error when using deprecated options.
ba94b89 is described below

commit ba94b8992f8db3981d5891e95c35906c3d65c440
Author: Claus Ibsen <cl...@gmail.com>
AuthorDate: Fri Aug 17 15:53:00 2018 +0200

    CAMEL-12598: camel-validate maven tool can now also report error when using deprecated options.
---
 .../camel/runtimecatalog/AbstractCamelCatalog.java | 13 +++++++
 .../runtimecatalog/EndpointValidationResult.java   | 41 ++++++++++++++++++++--
 .../camel/runtimecatalog/JSonSchemaHelper.java     | 17 +++++++++
 .../apache/camel/catalog/AbstractCamelCatalog.java | 13 +++++++
 .../camel/catalog/EndpointValidationResult.java    | 41 ++++++++++++++++++++--
 .../org/apache/camel/catalog/JSonSchemaHelper.java | 17 +++++++++
 .../src/main/docs/camel-maven-plugin.adoc          |  9 ++++-
 .../java/org/apache/camel/maven/ValidateMojo.java  | 25 ++++++++++---
 8 files changed, 166 insertions(+), 10 deletions(-)

diff --git a/camel-core/src/main/java/org/apache/camel/runtimecatalog/AbstractCamelCatalog.java b/camel-core/src/main/java/org/apache/camel/runtimecatalog/AbstractCamelCatalog.java
index 3e58ce4..70590b0 100644
--- a/camel-core/src/main/java/org/apache/camel/runtimecatalog/AbstractCamelCatalog.java
+++ b/camel-core/src/main/java/org/apache/camel/runtimecatalog/AbstractCamelCatalog.java
@@ -47,6 +47,7 @@ import static org.apache.camel.runtimecatalog.JSonSchemaHelper.isComponentLenien
 import static org.apache.camel.runtimecatalog.JSonSchemaHelper.isComponentProducerOnly;
 import static org.apache.camel.runtimecatalog.JSonSchemaHelper.isPropertyBoolean;
 import static org.apache.camel.runtimecatalog.JSonSchemaHelper.isPropertyConsumerOnly;
+import static org.apache.camel.runtimecatalog.JSonSchemaHelper.isPropertyDeprecated;
 import static org.apache.camel.runtimecatalog.JSonSchemaHelper.isPropertyInteger;
 import static org.apache.camel.runtimecatalog.JSonSchemaHelper.isPropertyMultiValue;
 import static org.apache.camel.runtimecatalog.JSonSchemaHelper.isPropertyNumber;
@@ -202,6 +203,12 @@ public abstract class AbstractCamelCatalog {
                     result.addRequired(name);
                 }
 
+                // is the option deprecated
+                boolean deprecated = isPropertyDeprecated(rows, name);
+                if (deprecated) {
+                    result.addDeprecated(name);
+                }
+
                 // is enum but the value is not within the enum range
                 // but we can only check if the value is not a placeholder
                 String enums = getPropertyEnum(rows, name);
@@ -432,6 +439,12 @@ public abstract class AbstractCamelCatalog {
                     result.addRequired(name);
                 }
 
+                // is the option deprecated
+                boolean deprecated = isPropertyDeprecated(rows, name);
+                if (deprecated) {
+                    result.addDeprecated(name);
+                }
+
                 // is enum but the value is not within the enum range
                 // but we can only check if the value is not a placeholder
                 String enums = getPropertyEnum(rows, name);
diff --git a/camel-core/src/main/java/org/apache/camel/runtimecatalog/EndpointValidationResult.java b/camel-core/src/main/java/org/apache/camel/runtimecatalog/EndpointValidationResult.java
index c6ce457..891c3cf 100644
--- a/camel-core/src/main/java/org/apache/camel/runtimecatalog/EndpointValidationResult.java
+++ b/camel-core/src/main/java/org/apache/camel/runtimecatalog/EndpointValidationResult.java
@@ -47,6 +47,7 @@ public class EndpointValidationResult implements Serializable {
     private Set<String> notConsumerOnly;
     private Set<String> notProducerOnly;
     private Set<String> required;
+    private Set<String> deprecated;
     private Map<String, String> invalidEnum;
     private Map<String, String[]> invalidEnumChoices;
     private Map<String, String[]> invalidEnumSuggestions;
@@ -140,6 +141,15 @@ public class EndpointValidationResult implements Serializable {
         }
     }
 
+    public void addDeprecated(String name) {
+        if (deprecated == null) {
+            deprecated = new LinkedHashSet<>();
+        }
+        if (!deprecated.contains(name)) {
+            deprecated.add(name);
+        }
+    }
+
     public void addInvalidEnum(String name, String value) {
         if (invalidEnum == null) {
             invalidEnum = new LinkedHashMap<>();
@@ -259,6 +269,10 @@ public class EndpointValidationResult implements Serializable {
         return required;
     }
 
+    public Set<String> getDeprecated() {
+        return deprecated;
+    }
+
     public Map<String, String> getInvalidEnum() {
         return invalidEnum;
     }
@@ -309,11 +323,29 @@ public class EndpointValidationResult implements Serializable {
     /**
      * A human readable summary of the validation errors.
      *
-     * @param includeHeader whether to include a header
+     * @param includeHeader    whether to include a header
      * @return the summary, or <tt>null</tt> if no validation errors
      */
     public String summaryErrorMessage(boolean includeHeader) {
-        if (isSuccess()) {
+        return summaryErrorMessage(includeHeader, true);
+    }
+
+    /**
+     * A human readable summary of the validation errors.
+     *
+     * @param includeHeader    whether to include a header
+     * @param ignoreDeprecated whether to ignore deprecated options in use as an error or not
+     * @return the summary, or <tt>null</tt> if no validation errors
+     */
+    public String summaryErrorMessage(boolean includeHeader, boolean ignoreDeprecated) {
+        boolean ok = isSuccess();
+
+        // special check if we should ignore deprecated options being used
+        if (ok && !ignoreDeprecated) {
+            ok = deprecated == null;
+        }
+
+        if (ok) {
             return null;
         }
 
@@ -357,6 +389,11 @@ public class EndpointValidationResult implements Serializable {
                 options.put(name, "Missing required option");
             }
         }
+        if (deprecated != null) {
+            for (String name : deprecated) {
+                options.put(name, "Deprecated option");
+            }
+        }
         if (invalidEnum != null) {
             for (Map.Entry<String, String> entry : invalidEnum.entrySet()) {
                 String name = entry.getKey();
diff --git a/camel-core/src/main/java/org/apache/camel/runtimecatalog/JSonSchemaHelper.java b/camel-core/src/main/java/org/apache/camel/runtimecatalog/JSonSchemaHelper.java
index fa5315f..1becdf9 100644
--- a/camel-core/src/main/java/org/apache/camel/runtimecatalog/JSonSchemaHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/runtimecatalog/JSonSchemaHelper.java
@@ -195,6 +195,23 @@ public final class JSonSchemaHelper {
         return false;
     }
 
+    public static boolean isPropertyDeprecated(List<Map<String, String>> rows, String name) {
+        for (Map<String, String> row : rows) {
+            boolean deprecated = false;
+            boolean found = false;
+            if (row.containsKey("name")) {
+                found = name.equals(row.get("name"));
+            }
+            if (row.containsKey("deprecated")) {
+                deprecated = "true".equals(row.get("deprecated"));
+            }
+            if (found) {
+                return deprecated;
+            }
+        }
+        return false;
+    }
+
     public static String getPropertyKind(List<Map<String, String>> rows, String name) {
         for (Map<String, String> row : rows) {
             String kind = null;
diff --git a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/AbstractCamelCatalog.java b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/AbstractCamelCatalog.java
index a85dcf6..99f5fbd 100644
--- a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/AbstractCamelCatalog.java
+++ b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/AbstractCamelCatalog.java
@@ -47,6 +47,7 @@ import static org.apache.camel.catalog.JSonSchemaHelper.isComponentLenientProper
 import static org.apache.camel.catalog.JSonSchemaHelper.isComponentProducerOnly;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyBoolean;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyConsumerOnly;
+import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyDeprecated;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyInteger;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyMultiValue;
 import static org.apache.camel.catalog.JSonSchemaHelper.isPropertyNumber;
@@ -202,6 +203,12 @@ public abstract class AbstractCamelCatalog {
                     result.addRequired(name);
                 }
 
+                // is the option deprecated
+                boolean deprecated = isPropertyDeprecated(rows, name);
+                if (deprecated) {
+                    result.addDeprecated(name);
+                }
+
                 // is enum but the value is not within the enum range
                 // but we can only check if the value is not a placeholder
                 String enums = getPropertyEnum(rows, name);
@@ -432,6 +439,12 @@ public abstract class AbstractCamelCatalog {
                     result.addRequired(name);
                 }
 
+                // is the option deprecated
+                boolean deprecated = isPropertyDeprecated(rows, name);
+                if (deprecated) {
+                    result.addDeprecated(name);
+                }
+
                 // is enum but the value is not within the enum range
                 // but we can only check if the value is not a placeholder
                 String enums = getPropertyEnum(rows, name);
diff --git a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java
index 63c201c..718b9a3 100644
--- a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java
+++ b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/EndpointValidationResult.java
@@ -47,6 +47,7 @@ public class EndpointValidationResult implements Serializable {
     private Set<String> notConsumerOnly;
     private Set<String> notProducerOnly;
     private Set<String> required;
+    private Set<String> deprecated;
     private Map<String, String> invalidEnum;
     private Map<String, String[]> invalidEnumChoices;
     private Map<String, String[]> invalidEnumSuggestions;
@@ -140,6 +141,15 @@ public class EndpointValidationResult implements Serializable {
         }
     }
 
+    public void addDeprecated(String name) {
+        if (deprecated == null) {
+            deprecated = new LinkedHashSet<>();
+        }
+        if (!deprecated.contains(name)) {
+            deprecated.add(name);
+        }
+    }
+
     public void addInvalidEnum(String name, String value) {
         if (invalidEnum == null) {
             invalidEnum = new LinkedHashMap<>();
@@ -259,6 +269,10 @@ public class EndpointValidationResult implements Serializable {
         return required;
     }
 
+    public Set<String> getDeprecated() {
+        return deprecated;
+    }
+
     public Map<String, String> getInvalidEnum() {
         return invalidEnum;
     }
@@ -309,11 +323,29 @@ public class EndpointValidationResult implements Serializable {
     /**
      * A human readable summary of the validation errors.
      *
-     * @param includeHeader whether to include a header
+     * @param includeHeader    whether to include a header
      * @return the summary, or <tt>null</tt> if no validation errors
      */
     public String summaryErrorMessage(boolean includeHeader) {
-        if (isSuccess()) {
+        return summaryErrorMessage(includeHeader, true);
+    }
+
+    /**
+     * A human readable summary of the validation errors.
+     *
+     * @param includeHeader    whether to include a header
+     * @param ignoreDeprecated whether to ignore deprecated options in use as an error or not
+     * @return the summary, or <tt>null</tt> if no validation errors
+     */
+    public String summaryErrorMessage(boolean includeHeader, boolean ignoreDeprecated) {
+        boolean ok = isSuccess();
+
+        // special check if we should ignore deprecated options being used
+        if (ok && !ignoreDeprecated) {
+            ok = deprecated == null;
+        }
+
+        if (ok) {
             return null;
         }
 
@@ -357,6 +389,11 @@ public class EndpointValidationResult implements Serializable {
                 options.put(name, "Missing required option");
             }
         }
+        if (deprecated != null) {
+            for (String name : deprecated) {
+                options.put(name, "Deprecated option");
+            }
+        }
         if (invalidEnum != null) {
             for (Map.Entry<String, String> entry : invalidEnum.entrySet()) {
                 String name = entry.getKey();
diff --git a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
index c17b03e..f8ce950 100644
--- a/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
+++ b/platforms/camel-catalog/src/main/java/org/apache/camel/catalog/JSonSchemaHelper.java
@@ -195,6 +195,23 @@ public final class JSonSchemaHelper {
         return false;
     }
 
+    public static boolean isPropertyDeprecated(List<Map<String, String>> rows, String name) {
+        for (Map<String, String> row : rows) {
+            boolean deprecated = false;
+            boolean found = false;
+            if (row.containsKey("name")) {
+                found = name.equals(row.get("name"));
+            }
+            if (row.containsKey("deprecated")) {
+                deprecated = "true".equals(row.get("deprecated"));
+            }
+            if (found) {
+                return deprecated;
+            }
+        }
+        return false;
+    }
+
     public static String getPropertyKind(List<Map<String, String>> rows, String name) {
         for (Map<String, String> row : rows) {
             String kind = null;
diff --git a/tooling/maven/camel-maven-plugin/src/main/docs/camel-maven-plugin.adoc b/tooling/maven/camel-maven-plugin/src/main/docs/camel-maven-plugin.adoc
index cd30b44..8b912a5 100644
--- a/tooling/maven/camel-maven-plugin/src/main/docs/camel-maven-plugin.adoc
+++ b/tooling/maven/camel-maven-plugin/src/main/docs/camel-maven-plugin.adoc
@@ -260,7 +260,6 @@ And when running the validate goal again reports the following:
 [INFO] ------------------------------------------------------------------------
 ----
 
-
 === Options
 
 The maven plugin *validate* goal supports the following options which can be configured from the command line (use `-D` syntax), or defined in the `pom.xml` file in the `<configuration>` tag.
@@ -278,10 +277,18 @@ The maven plugin *validate* goal supports the following options which can be con
 | ignoreUnknownComponent | true | Whether to ignore unknown components.
 | ignoreIncapable | true | Whether to ignore incapable of parsing the endpoint uri or simple expression.
 | ignoreLenientProperties | true | 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.
+| ignoreDeprecated | true | *Camel 2.23* Whether to ignore deprecated options being used in the endpoint uri.
 | duplicateRouteId | true | *Camel 2.20* Whether to validate for duplicate route ids. Route ids should be unique and if there are duplicates then Camel will fail to startup.
 | 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:
+
+----
+$mvn camel:validate -Dcamel.ignoreDeprecated=true
+----
+
+Notice that you must prefix the `-D` command argument with `camel.`, eg `camel.ignoreDeprecated` as the option name.
 
 === Validating include test
 
diff --git a/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ValidateMojo.java b/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ValidateMojo.java
index 27dae53..3c6a653 100644
--- a/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ValidateMojo.java
+++ b/tooling/maven/camel-maven-plugin/src/main/java/org/apache/camel/maven/ValidateMojo.java
@@ -136,6 +136,14 @@ public class ValidateMojo extends AbstractExecMojo {
     private boolean ignoreIncapable;
 
     /**
+     * Whether to ignore deprecated options being used in the endpoint uri
+     *
+     * @parameter property="camel.ignoreDeprecated"
+     *            default-value="true"
+     */
+    private boolean ignoreDeprecated;
+
+    /**
      * 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.
@@ -322,9 +330,12 @@ public class ValidateMojo extends AbstractExecMojo {
         int endpointErrors = 0;
         int unknownComponents = 0;
         int incapableErrors = 0;
+        int deprecatedOptions = 0;
         for (CamelEndpointDetails detail : endpoints) {
             getLog().debug("Validating endpoint: " + detail.getEndpointUri());
             EndpointValidationResult result = catalog.validateEndpointProperties(detail.getEndpointUri(), ignoreLenientProperties);
+            int deprecated = result.getDeprecated() != null ? result.getDeprecated().size() : 0;
+            deprecatedOptions += deprecated;
 
             boolean ok = result.isSuccess();
             if (!ok && ignoreUnknownComponent && result.getUnknownComponent() != null) {
@@ -337,6 +348,10 @@ public class ValidateMojo extends AbstractExecMojo {
                 incapableErrors++;
                 ok = true;
             }
+            if (ok && !ignoreDeprecated && deprecated > 0) {
+                ok = false;
+            }
+
             if (!ok) {
                 if (result.getUnknownComponent() != null) {
                     unknownComponents++;
@@ -370,7 +385,7 @@ public class ValidateMojo extends AbstractExecMojo {
                     sb.append(detail.getFileName());
                 }
                 sb.append("\n\n");
-                String out = result.summaryErrorMessage(false);
+                String out = result.summaryErrorMessage(false, ignoreDeprecated);
                 sb.append(out);
                 sb.append("\n\n");
 
@@ -409,12 +424,12 @@ public class ValidateMojo extends AbstractExecMojo {
         String endpointSummary;
         if (endpointErrors == 0) {
             int ok = endpoints.size() - endpointErrors - incapableErrors - unknownComponents;
-            endpointSummary = String.format("Endpoint validation success: (%s = passed, %s = invalid, %s = incapable, %s = unknown components)",
-                    ok, endpointErrors, incapableErrors, unknownComponents);
+            endpointSummary = String.format("Endpoint validation success: (%s = passed, %s = invalid, %s = incapable, %s = unknown components, %s = deprecated options)",
+                    ok, endpointErrors, incapableErrors, unknownComponents, deprecatedOptions);
         } else {
             int ok = endpoints.size() - endpointErrors - incapableErrors - unknownComponents;
-            endpointSummary = String.format("Endpoint validation error: (%s = passed, %s = invalid, %s = incapable, %s = unknown components)",
-                    ok, endpointErrors, incapableErrors, unknownComponents);
+            endpointSummary = String.format("Endpoint validation error: (%s = passed, %s = invalid, %s = incapable, %s = unknown components, %s = deprecated options)",
+                    ok, endpointErrors, incapableErrors, unknownComponents, deprecatedOptions);
         }
 
         if (endpointErrors > 0) {