From dbe356a8e6ce9f07751e0b72d3ddf6e77f0a8a02 Mon Sep 17 00:00:00 2001 From: Benjamin Bentmann Date: Mon, 25 May 2009 12:39:30 +0000 Subject: [PATCH] o Generified code git-svn-id: https://svn.apache.org/repos/asf/maven/components/branches/MNG-2766@778408 13f79535-47bb-0310-9956-ffa450edef68 --- .../validation/DefaultModelValidator.java | 37 +++++-------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/maven-core/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java b/maven-core/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java index 87be7f478f..6d65e98160 100644 --- a/maven-core/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java +++ b/maven-core/src/main/java/org/apache/maven/project/validation/DefaultModelValidator.java @@ -20,7 +20,6 @@ package org.apache.maven.project.validation; */ import java.io.File; -import java.util.Iterator; import java.util.List; import org.apache.maven.artifact.Artifact; @@ -82,10 +81,8 @@ public class DefaultModelValidator validateStringNotEmpty( "version", result, model.getVersion() ); - for ( Iterator it = model.getDependencies().iterator(); it.hasNext(); ) + for ( Dependency d : model.getDependencies() ) { - Dependency d = (Dependency) it.next(); - validateId( "dependencies.dependency.artifactId", result, d.getArtifactId() ); validateId( "dependencies.dependency.groupId", result, d.getGroupId() ); @@ -122,10 +119,8 @@ public class DefaultModelValidator DependencyManagement mgmt = model.getDependencyManagement(); if ( mgmt != null ) { - for ( Iterator it = mgmt.getDependencies().iterator(); it.hasNext(); ) + for ( Dependency d : mgmt.getDependencies() ) { - Dependency d = (Dependency) it.next(); - validateSubElementStringNotEmpty( d, "dependencyManagement.dependencies.dependency.artifactId", result, d.getArtifactId() ); @@ -161,10 +156,8 @@ public class DefaultModelValidator Build build = model.getBuild(); if ( build != null ) { - for ( Iterator it = build.getPlugins().iterator(); it.hasNext(); ) + for ( Plugin p : build.getPlugins() ) { - Plugin p = (Plugin) it.next(); - validateStringNotEmpty( "build.plugins.plugin.artifactId", result, p.getArtifactId() ); validateStringNotEmpty( "build.plugins.plugin.groupId", result, p.getGroupId() ); @@ -177,17 +170,13 @@ public class DefaultModelValidator */ } - for ( Iterator it = build.getResources().iterator(); it.hasNext(); ) + for ( Resource r : build.getResources() ) { - Resource r = (Resource) it.next(); - validateStringNotEmpty( "build.resources.resource.directory", result, r.getDirectory() ); } - for ( Iterator it = build.getTestResources().iterator(); it.hasNext(); ) + for ( Resource r : build.getTestResources() ) { - Resource r = (Resource) it.next(); - validateStringNotEmpty( "build.testResources.testResource.directory", result, r.getDirectory() ); } } @@ -195,10 +184,8 @@ public class DefaultModelValidator Reporting reporting = model.getReporting(); if ( reporting != null ) { - for ( Iterator it = reporting.getPlugins().iterator(); it.hasNext(); ) + for ( ReportPlugin p : reporting.getPlugins()) { - ReportPlugin p = (ReportPlugin) it.next(); - validateStringNotEmpty( "reporting.plugins.plugin.artifactId", result, p.getArtifactId() ); validateStringNotEmpty( "reporting.plugins.plugin.groupId", result, p.getGroupId() ); @@ -231,12 +218,10 @@ public class DefaultModelValidator } } - private void validateRepositories( ModelValidationResult result, List repositories, String prefix ) + private void validateRepositories( ModelValidationResult result, List repositories, String prefix ) { - for ( Iterator it = repositories.iterator(); it.hasNext(); ) + for ( Repository repository : repositories ) { - Repository repository = (Repository) it.next(); - validateStringNotEmpty( prefix + ".id", result, repository.getId() ); validateStringNotEmpty( prefix + ".url", result, repository.getUrl() ); @@ -249,14 +234,12 @@ public class DefaultModelValidator if ( build != null ) { - List plugins = build.getPlugins(); + List plugins = build.getPlugins(); if ( plugins != null ) { - for ( Iterator it = plugins.iterator(); it.hasNext(); ) + for ( Plugin plugin : plugins ) { - Plugin plugin = (Plugin) it.next(); - // this will force an IllegalStateException, even if we don't have to do inheritance assembly. try {