@ Override @ SuppressWarnings ( "PMD.PreserveStackTrace" ) public final void execute ( final EnforcerRuleHelper helper ) throws EnforcerRuleException { final MavenProject project ; try { project = ( MavenProject ) helper . evaluate ( "${project}" ) ; } catch ( final ExpressionEvaluationException e ) { // Whoops. final String msg = "Could not acquire MavenProject. (Expression lookup failure for: " + e . getLocalizedMessage ( ) + ")" ; throw new EnforcerRuleException ( msg , e ) ; } // Delegate. try { performValidation ( project , helper ) ; } catch ( RuleFailureException e ) { // Create a somewhat verbose failure message. String message = "\n" + "\n#" + "\n# Structure rule failure:" + "\n# " + getShortRuleDescription ( ) + "\n# " + "\n# Message: " + e . getLocalizedMessage ( ) + "\n# " + "\n# Offending project [" + project . getGroupId ( ) + ":" + project . getArtifactId ( ) + ":" + project . getVersion ( ) + "]" + "\n#" ; final Artifact art = e . getOffendingArtifact ( ) ; if ( art != null ) { message += "\n# Offending artifact [" + art . getGroupId ( ) + ":" + art . getArtifactId ( ) + ":" + art . getVersion ( ) + "]" + "\n#" ; } message += "\n" ; // Re-throw for pretty print throw new EnforcerRuleException ( message ) ; } }
This is the interface into the rule . This method should throw an exception containing a reason message if the rule fails the check . The plugin will then decide based on the fail flag if it should stop or just log the message as a warning .