// refer to a valid artifact
final List configuredWarArtifacts = new ArrayList();
final ListIterator it = overlays.listIterator();
while ( it.hasNext() )
{
Overlay overlay = (Overlay) it.next();
if ( overlay == null )
{
throw new InvalidOverlayConfigurationException( "overlay could not be null." );
}
// If it's the current project, return the project instance
if ( overlay.isCurrentProject() )
{
overlay = Overlay.currentProjectInstance();
it.set( overlay );
}
// default includes/excludes - only if the overlay uses the default settings
if ( Arrays.equals( Overlay.DEFAULT_INCLUDES, overlay.getIncludes() )
&& Arrays.equals( Overlay.DEFAULT_EXCLUDES, overlay.getExcludes() ) )
{
overlay.setIncludes( defaultIncludes );
overlay.setExcludes( defaultExcludes );
}
final Artifact artifact = getAssociatedArtifact( overlay );
if ( artifact != null )
{
configuredWarArtifacts.add( artifact );
overlay.setArtifact( artifact );
}
}
// Build the list of missing overlays
final Iterator it2 = artifactsOverlays.iterator();
while ( it2.hasNext() )
{
Artifact artifact = (Artifact) it2.next();
if ( !configuredWarArtifacts.contains( artifact ) )
{
// Add a default overlay for the given artifact which will be applied after
// the ones that have been configured
overlays.add( new DefaultOverlay( artifact, defaultIncludes, defaultExcludes ) );
}
}
// Final validation, make sure that the current project is in there. Otherwise add it first
final Iterator it3 = overlays.iterator();
while ( it3.hasNext() )
{
Overlay overlay = (Overlay) it3.next();
if ( overlay.equals( Overlay.currentProjectInstance() ) )
{
return;
}
}
overlays.add( 0, Overlay.currentProjectInstance() );