RequireSnapshotVersion extends AbstractNonCacheableEnforcerRule { @Override public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { MavenProject project = getProject( false, helper ); Artifact artifact = project.getArtifact(); if ( !artifact.isSnapshot() ) { String message = getMessage(); StringBuilder sb = new StringBuilder(); if ( message != null ) { sb.append( message ).append( System.lineSeparator() ); } sb.append( "This project cannot be a release:" ).append( artifact.getId() ); throw new EnforcerRuleException( sb.toString() ); } if ( failWhenParentIsRelease && project.hasParent() ) { Artifact parentArtifact = getProject( true, helper ).getArtifact(); if ( parentArtifact != null && !parentArtifact.isSnapshot() ) { throw new EnforcerRuleException( "Parent cannot be a release: " + parentArtifact.getId() ); } } }  @Override void execute( EnforcerRuleHelper helper ); boolean isFailWhenParentIsRelease(); void setFailWhenParentIsRelease( boolean failWhenParentIsRelease );  }
@Test public void testRequireSnapshot() throws IOException { project.setArtifact( factory.getReleaseArtifact() ); EnforcerRuleUtilsHelper.execute( rule, helper, true ); project.setArtifact( factory.getSnapshotArtifact() ); EnforcerRuleUtilsHelper.execute( rule, helper, false ); }