Class ExternalRules

    • Field Detail

      • LOCATION_PREFIX_CLASSPATH

        private static final java.lang.String LOCATION_PREFIX_CLASSPATH
        See Also:
        Constant Field Values
      • location

        private java.lang.String location
        The external rules location. If it starts with classpath: the resource is read from the classpath. Otherwise, it is handled as a filesystem path, either absolute, or relative to ${project.basedir}
        Since:
        3.2.0
      • xsltLocation

        private java.lang.String xsltLocation
        An optional location of an XSLT file used to transform the rule document available via location before it is applied. If it starts with classpath: the resource is read from the classpath. Otherwise, it is handled as a filesystem path, either absolute, or relative to ${project.basedir}

        This is useful, when you want to consume rules defined in an external project, but you need to remove or adapt some of those for the local circumstances.

        Example

        If location points at the following rule set:

        
         <enforcer>
           <rules>
             <bannedDependencies>
                <excludes>
                  <exclude>com.google.code.findbugs:jsr305</exclude>
                  <exclude>com.google.guava:listenablefuture</exclude>
                </excludes>
             </bannedDependencies>
           </rules>
         </enforcer>
         
        And if xsltLocation points at the following transformation
        
         <xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
           <xsl:output omit-xml-declaration="yes"/>
        
           <!-- Copy everything unless there is a template with a more specific matcher -->
           <xsl:template match="node()|@*">
             <xsl:copy>
               <xsl:apply-templates select="node()|@*"/>
             </xsl:copy>
           </xsl:template>
        
           <!-- An empty template will effectively remove the matching nodes -->
           <xsl:template match=
         "//bannedDependencies/excludes/exclude[contains(text(), 'com.google.code.findbugs:jsr305')]"/>
         </xsl:stylesheet>
         
        Then the effective rule set will look like to following:
        
         <enforcer>
           <rules>
             <bannedDependencies>
                <excludes>
                  <exclude>com.google.guava:listenablefuture</exclude>
                </excludes>
             </bannedDependencies>
           </rules>
         </enforcer>
         
        Since:
        3.6.0
      • mojoExecution

        private final org.apache.maven.plugin.MojoExecution mojoExecution
    • Constructor Detail

      • ExternalRules

        @Inject
        public ExternalRules​(org.apache.maven.plugin.MojoExecution mojoExecution,
                             ExpressionEvaluator evaluator)
    • Method Detail

      • setLocation

        public void setLocation​(java.lang.String location)
      • setXsltLocation

        public void setXsltLocation​(java.lang.String xsltLocation)
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • transform

        java.io.InputStream transform​(java.lang.String sourceLocation,
                                      java.io.InputStream sourceXml,
                                      java.lang.String xsltLocation)