BanDistributionManagement extends AbstractNonCacheableEnforcerRule { @Override public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { logger = helper.getLog(); try { MavenProject project = (MavenProject) helper.evaluate( "${project}" ); if ( project.isExecutionRoot() ) { if ( project.getParent() == null ) { logger.debug( "We have no parent and in the root of a build we don't check anything," ); logger.debug( "because that is the location where we defined maven-enforcer-plugin." ); } else { logger.debug( "We are in the root of the execution and we have a parent." ); DistributionManagementCheck check = new DistributionManagementCheck( project ); check.execute( isAllowRepository(), isAllowSnapshotRepository(), isAllowSite() ); } } else { logger.debug( "We are in a deeper level." ); DistributionManagementCheck check = new DistributionManagementCheck( project ); check.execute( isAllowRepository(), isAllowSnapshotRepository(), isAllowSite() ); } } catch ( ExpressionEvaluationException e ) { throw new EnforcerRuleException( e.getMessage(), e ); } }  @Override void execute( EnforcerRuleHelper helper ); boolean isAllowRepository(); void setAllowRepository( boolean allowRepository ); boolean isAllowSnapshotRepository(); void setAllowSnapshotRepository( boolean allowSnapshotRepository ); boolean isAllowSite(); void setAllowSite( boolean allowSite );  }
@Test public void shouldNotFailWithoutDistributionManagement() throws Exception { BanDistributionManagement rule = setupProjectWithoutDistributionManagement(); rule.execute( helper ); }
@Test( expected = EnforcerRuleException.class ) public void shouldThrowExceptionIfDistributionManagementIsDefinedWithRepository() throws Exception { BanDistributionManagement rule = setupProjectWithDistributionManagement( new DeploymentRepository(), null, null ); rule.execute( helper ); }
@Test( expected = EnforcerRuleException.class ) public void shouldThrowExceptionIfDistributionManagementIsDefinedWithRepositorySnapshotRepository() throws Exception { BanDistributionManagement rule = setupProjectWithDistributionManagement( new DeploymentRepository(), new DeploymentRepository(), null ); rule.execute( helper ); }
@Test( expected = EnforcerRuleException.class ) public void shouldThrowExceptionIfDistributionManagementIsDefinedWithRepositorySnapshotRepositorySite() throws Exception { BanDistributionManagement rule = setupProjectWithDistributionManagement( new DeploymentRepository(), new DeploymentRepository(), new Site() ); rule.execute( helper ); }