@Test public void testAllBannedNoRepositories() throws EnforcerRuleException { MavenProject baseProject = createStandAloneProject(); setupSortedProjects( Collections.singletonList( baseProject ) ); rule.execute( helper ); }
@Override public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { logger = helper.getLog(); MavenSession session; try { session = (MavenSession) helper.evaluate( "${session}" ); List<MavenProject> sortedProjects = session.getProjectDependencyGraph().getSortedProjects(); List<Model> models = new ArrayList<>(); for ( MavenProject mavenProject : sortedProjects ) { logger.debug( "Scanning project: " + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + VERSION + mavenProject.getVersion() ); models.add( mavenProject.getOriginalModel() ); } List<Model> badModels = new ArrayList<>(); StringBuilder newMsg = new StringBuilder(); newMsg.append( "Some poms have repositories defined:" + System.lineSeparator() ); for ( Model model : models ) { if ( banRepositories ) { List<Repository> repos = model.getRepositories(); if ( repos != null && !repos.isEmpty() ) { List<String> bannedRepos = findBannedRepositories( repos, allowedRepositories, allowSnapshotRepositories ); if ( !bannedRepos.isEmpty() ) { badModels.add( model ); newMsg.append( model.getGroupId() + ":" + model.getArtifactId() + VERSION + model.getVersion() + " has repositories " + bannedRepos ); } } } if ( banPluginRepositories ) { List<Repository> repos = model.getPluginRepositories(); if ( repos != null && !repos.isEmpty() ) { List<String> bannedRepos = findBannedRepositories( repos, allowedPluginRepositories, allowSnapshotPluginRepositories ); if ( !bannedRepos.isEmpty() ) { badModels.add( model ); newMsg.append( model.getGroupId() + ":" + model.getArtifactId() + VERSION + model.getVersion() + " has plugin repositories " + bannedRepos ); } } } } if ( !badModels.isEmpty() ) { String message = getMessage(); if ( StringUtils.isNotEmpty( message ) ) { newMsg.append( message ); } throw new EnforcerRuleException( newMsg.toString() ); } } catch ( ExpressionEvaluationException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } }
RequireNoRepositories extends AbstractNonCacheableEnforcerRule { @Override public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { logger = helper.getLog(); MavenSession session; try { session = (MavenSession) helper.evaluate( "${session}" ); List<MavenProject> sortedProjects = session.getProjectDependencyGraph().getSortedProjects(); List<Model> models = new ArrayList<>(); for ( MavenProject mavenProject : sortedProjects ) { logger.debug( "Scanning project: " + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + VERSION + mavenProject.getVersion() ); models.add( mavenProject.getOriginalModel() ); } List<Model> badModels = new ArrayList<>(); StringBuilder newMsg = new StringBuilder(); newMsg.append( "Some poms have repositories defined:" + System.lineSeparator() ); for ( Model model : models ) { if ( banRepositories ) { List<Repository> repos = model.getRepositories(); if ( repos != null && !repos.isEmpty() ) { List<String> bannedRepos = findBannedRepositories( repos, allowedRepositories, allowSnapshotRepositories ); if ( !bannedRepos.isEmpty() ) { badModels.add( model ); newMsg.append( model.getGroupId() + ":" + model.getArtifactId() + VERSION + model.getVersion() + " has repositories " + bannedRepos ); } } } if ( banPluginRepositories ) { List<Repository> repos = model.getPluginRepositories(); if ( repos != null && !repos.isEmpty() ) { List<String> bannedRepos = findBannedRepositories( repos, allowedPluginRepositories, allowSnapshotPluginRepositories ); if ( !bannedRepos.isEmpty() ) { badModels.add( model ); newMsg.append( model.getGroupId() + ":" + model.getArtifactId() + VERSION + model.getVersion() + " has plugin repositories " + bannedRepos ); } } } } if ( !badModels.isEmpty() ) { String message = getMessage(); if ( StringUtils.isNotEmpty( message ) ) { newMsg.append( message ); } throw new EnforcerRuleException( newMsg.toString() ); } } catch ( ExpressionEvaluationException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } } }
RequireNoRepositories extends AbstractNonCacheableEnforcerRule { @Override public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { logger = helper.getLog(); MavenSession session; try { session = (MavenSession) helper.evaluate( "${session}" ); List<MavenProject> sortedProjects = session.getProjectDependencyGraph().getSortedProjects(); List<Model> models = new ArrayList<>(); for ( MavenProject mavenProject : sortedProjects ) { logger.debug( "Scanning project: " + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + VERSION + mavenProject.getVersion() ); models.add( mavenProject.getOriginalModel() ); } List<Model> badModels = new ArrayList<>(); StringBuilder newMsg = new StringBuilder(); newMsg.append( "Some poms have repositories defined:" + System.lineSeparator() ); for ( Model model : models ) { if ( banRepositories ) { List<Repository> repos = model.getRepositories(); if ( repos != null && !repos.isEmpty() ) { List<String> bannedRepos = findBannedRepositories( repos, allowedRepositories, allowSnapshotRepositories ); if ( !bannedRepos.isEmpty() ) { badModels.add( model ); newMsg.append( model.getGroupId() + ":" + model.getArtifactId() + VERSION + model.getVersion() + " has repositories " + bannedRepos ); } } } if ( banPluginRepositories ) { List<Repository> repos = model.getPluginRepositories(); if ( repos != null && !repos.isEmpty() ) { List<String> bannedRepos = findBannedRepositories( repos, allowedPluginRepositories, allowSnapshotPluginRepositories ); if ( !bannedRepos.isEmpty() ) { badModels.add( model ); newMsg.append( model.getGroupId() + ":" + model.getArtifactId() + VERSION + model.getVersion() + " has plugin repositories " + bannedRepos ); } } } } if ( !badModels.isEmpty() ) { String message = getMessage(); if ( StringUtils.isNotEmpty( message ) ) { newMsg.append( message ); } throw new EnforcerRuleException( newMsg.toString() ); } } catch ( ExpressionEvaluationException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } }  }
RequireNoRepositories extends AbstractNonCacheableEnforcerRule { @Override public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { logger = helper.getLog(); MavenSession session; try { session = (MavenSession) helper.evaluate( "${session}" ); List<MavenProject> sortedProjects = session.getProjectDependencyGraph().getSortedProjects(); List<Model> models = new ArrayList<>(); for ( MavenProject mavenProject : sortedProjects ) { logger.debug( "Scanning project: " + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + VERSION + mavenProject.getVersion() ); models.add( mavenProject.getOriginalModel() ); } List<Model> badModels = new ArrayList<>(); StringBuilder newMsg = new StringBuilder(); newMsg.append( "Some poms have repositories defined:" + System.lineSeparator() ); for ( Model model : models ) { if ( banRepositories ) { List<Repository> repos = model.getRepositories(); if ( repos != null && !repos.isEmpty() ) { List<String> bannedRepos = findBannedRepositories( repos, allowedRepositories, allowSnapshotRepositories ); if ( !bannedRepos.isEmpty() ) { badModels.add( model ); newMsg.append( model.getGroupId() + ":" + model.getArtifactId() + VERSION + model.getVersion() + " has repositories " + bannedRepos ); } } } if ( banPluginRepositories ) { List<Repository> repos = model.getPluginRepositories(); if ( repos != null && !repos.isEmpty() ) { List<String> bannedRepos = findBannedRepositories( repos, allowedPluginRepositories, allowSnapshotPluginRepositories ); if ( !bannedRepos.isEmpty() ) { badModels.add( model ); newMsg.append( model.getGroupId() + ":" + model.getArtifactId() + VERSION + model.getVersion() + " has plugin repositories " + bannedRepos ); } } } } if ( !badModels.isEmpty() ) { String message = getMessage(); if ( StringUtils.isNotEmpty( message ) ) { newMsg.append( message ); } throw new EnforcerRuleException( newMsg.toString() ); } } catch ( ExpressionEvaluationException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } }  final void setBanRepositories( boolean banRepositories ); final void setBanPluginRepositories( boolean banPluginRepositories ); final void setAllowedRepositories( List<String> allowedRepositories ); final void setAllowedPluginRepositories( List<String> allowedPluginRepositories ); final void setAllowSnapshotRepositories( boolean allowSnapshotRepositories ); final void setAllowSnapshotPluginRepositories( boolean allowSnapshotPluginRepositories ); @Override void execute( EnforcerRuleHelper helper ); }
RequireNoRepositories extends AbstractNonCacheableEnforcerRule { @Override public void execute( EnforcerRuleHelper helper ) throws EnforcerRuleException { logger = helper.getLog(); MavenSession session; try { session = (MavenSession) helper.evaluate( "${session}" ); List<MavenProject> sortedProjects = session.getProjectDependencyGraph().getSortedProjects(); List<Model> models = new ArrayList<>(); for ( MavenProject mavenProject : sortedProjects ) { logger.debug( "Scanning project: " + mavenProject.getGroupId() + ":" + mavenProject.getArtifactId() + VERSION + mavenProject.getVersion() ); models.add( mavenProject.getOriginalModel() ); } List<Model> badModels = new ArrayList<>(); StringBuilder newMsg = new StringBuilder(); newMsg.append( "Some poms have repositories defined:" + System.lineSeparator() ); for ( Model model : models ) { if ( banRepositories ) { List<Repository> repos = model.getRepositories(); if ( repos != null && !repos.isEmpty() ) { List<String> bannedRepos = findBannedRepositories( repos, allowedRepositories, allowSnapshotRepositories ); if ( !bannedRepos.isEmpty() ) { badModels.add( model ); newMsg.append( model.getGroupId() + ":" + model.getArtifactId() + VERSION + model.getVersion() + " has repositories " + bannedRepos ); } } } if ( banPluginRepositories ) { List<Repository> repos = model.getPluginRepositories(); if ( repos != null && !repos.isEmpty() ) { List<String> bannedRepos = findBannedRepositories( repos, allowedPluginRepositories, allowSnapshotPluginRepositories ); if ( !bannedRepos.isEmpty() ) { badModels.add( model ); newMsg.append( model.getGroupId() + ":" + model.getArtifactId() + VERSION + model.getVersion() + " has plugin repositories " + bannedRepos ); } } } } if ( !badModels.isEmpty() ) { String message = getMessage(); if ( StringUtils.isNotEmpty( message ) ) { newMsg.append( message ); } throw new EnforcerRuleException( newMsg.toString() ); } } catch ( ExpressionEvaluationException e ) { throw new EnforcerRuleException( e.getLocalizedMessage() ); } }  final void setBanRepositories( boolean banRepositories ); final void setBanPluginRepositories( boolean banPluginRepositories ); final void setAllowedRepositories( List<String> allowedRepositories ); final void setAllowedPluginRepositories( List<String> allowedPluginRepositories ); final void setAllowSnapshotRepositories( boolean allowSnapshotRepositories ); final void setAllowSnapshotPluginRepositories( boolean allowSnapshotPluginRepositories ); @Override void execute( EnforcerRuleHelper helper );  }