KroArtem commented on a change in pull request #86:
URL: https://github.com/apache/maven-enforcer/pull/86#discussion_r565083783



##########
File path: 
enforcer-rules/src/main/java/org/apache/maven/plugins/enforcer/RequireJavaVendor.java
##########
@@ -31,40 +33,112 @@
  */
 public class RequireJavaVendor extends AbstractNonCacheableEnforcerRule
 {
-    private String name;
+    /**
+     * Specify the banned vendors. This should be an exact match of the System 
Property
+     * java.vendor, which you can also see with mvn --version. <br>
+     * The rule will fail if vendor name matches any exclude, unless it also 
matches an
+     * include rule.
+     *
+     * Some examples are:
+     * <ul>
+     * <li><code>AdoptOpenJDK</code> prohibits vendor name AdoptOpenJDK </li>
+     * <li><code>Amazon</code> prohibits vendor name Amazon </li>
+     * </ul>
+     *
+     * @see #setExcludes(List)
+     * @see #getExcludes()
+     */
+    private List<String> excludes = null;
+
+    /**
+     * Specify the allowed vendor names. This should be an exact match of the 
System Property
+     * java.vendor, which you can also see with mvn --version. <br>
+     * Includes override the exclude rules.
+     *
+     * @see #setIncludes(List)
+     * @see #getIncludes()
+     */
+    private List<String> includes = null;
 
     @Override
     public void execute( EnforcerRuleHelper helper ) throws 
EnforcerRuleException
     {
-        if ( !SystemUtils.JAVA_VENDOR.equals( name ) )
+        if ( excludes != null )
         {
-            String message = getMessage();
-            String error = "Vendor " + SystemUtils.JAVA_VENDOR + " did not 
match required vendor " + name;
-            StringBuilder sb = new StringBuilder();
-            if ( message != null )
+            if ( excludes.contains( SystemUtils.JAVA_VENDOR ) )
             {
-                sb.append( message ).append( System.lineSeparator() );
+                if ( includes != null )
+                {
+                    if ( !includes.contains( SystemUtils.JAVA_VENDOR ) )
+                    {
+                        createException();
+                    }
+                    return;
+                }
+                createException();
             }
-
-            sb.append( error );
-
-            throw new EnforcerRuleException( sb.toString() );
         }
     }
 
     /**
-     * Specify the required name. Some examples are:
-     * Name should be an exact match of the System Property java.vendor, which 
you can also see with mvn --version
+     * Gets the excludes.
      *
-     * <ul>
-     * <li><code>AdoptOpenJDK</code> enforces vendor name AdoptOpenJDK </li>
-     * <li><code>Amazon</code> enforces vendor name Amazon </li>
-     * </ul>
+     * @return the excludes
+     */
+    public List<String> getExcludes()
+    {
+        return this.excludes;
+    }
+
+    /**
+     * Specify the banned vendors. This should be an exact match of the System 
Property
+     * java.vendor, which you can also see with mvn --version. <br>
+     * The rule will fail if vendor name matches any exclude, unless it also 
matches an
+     * include rule.
+     *
+     * @see #getExcludes()
+     * @param theExcludes the excludes to set
+     */
+    public void setExcludes( List<String> theExcludes )
+    {
+        this.excludes = theExcludes;
+    }
+
+    /**
+     * Gets the includes.
      *
-     * @param name the required name to set
+     * @return the includes
      */
-    public final void setName( String name )
+    public List<String> getIncludes()
     {
-        this.name = name;
+        return this.includes;
+    }
+
+    /**
+     * Specify the allowed vendor names. This should be an exact match of the 
System Property
+     * java.vendor, which you can also see with mvn --version. <br>
+     * Includes override the exclude rules.
+     * *
+     * @see #setIncludes(List)
+     * @param theIncludes the includes to set
+     */
+    public void setIncludes( List<String> theIncludes )
+    {
+        this.includes = theIncludes;
+    }
+
+    private void createException() throws EnforcerRuleException
+    {
+        String message = getMessage();
+        String error = "Vendor " + SystemUtils.JAVA_VENDOR + " is in a list of 
banned vendors: " + excludes;
+        StringBuilder sb = new StringBuilder();
+        if ( message != null )
+        {
+            sb.append( message ).append( System.lineSeparator() );

Review comment:
       ok, I'll fix it today. Just understood that documentation 
(`requireJavaVendor.apt.vm`) has to be updated too.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


Reply via email to