KroArtem commented on a change in pull request #86: URL: https://github.com/apache/maven-enforcer/pull/86#discussion_r563658948
########## 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() Review comment: What's up with backwards compatibility? This rule was not released in any version (M4 was not released), there is no information about this rule on site https://maven.apache.org/enforcer/enforcer-rules/index.html From my point of view, this was specifically done to prevent breaking backward compatibility in future. Here is your comment as an example 😃 https://issues.apache.org/jira/browse/MENFORCER-338?focusedCommentId=17169274&page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#comment-17169274 ---------------------------------------------------------------- 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