if(!overlays.isEmpty() && !isEqual(overlays, _overlays))
{
try
{
Resource resource = _overlays==null ? webAppConfig.getBaseResource() : null;
ResourceCollection rc = new ResourceCollection();
if(resource==null)
{
// nothing configured, so we automagically enable the overlays
int size = overlays.size()+1;
Resource[] resources = new Resource[size];
resources[0] = Resource.newResource(getWebAppSourceDirectory().toURL());
for(int i=1; i<size; i++)
{
resources[i] = (Resource)overlays.get(i-1);
getLog().info("Adding overlay: " + resources[i]);
}
rc.setResources(resources);
}
else
{
if(resource instanceof ResourceCollection)
{
// there was a preconfigured ResourceCollection ... append the artifact wars
Resource[] old = ((ResourceCollection)resource).getResources();
int size = old.length + overlays.size();
Resource[] resources = new Resource[size];
System.arraycopy(old, 0, resources, 0, old.length);
for(int i=old.length,j=0; i<size; i++,j++)
{
resources[i] = (Resource)overlays.get(j);
getLog().info("Adding overlay: " + resources[i]);
}
rc.setResources(resources);
}
else
{
// baseResource was already configured w/c could be src/main/webapp
if(!resource.isDirectory() && String.valueOf(resource.getFile()).endsWith(".war"))
{
// its a war
resource = Resource.newResource("jar:" + resource.getURL().toString() + "!/");
}
int size = overlays.size()+1;
Resource[] resources = new Resource[size];
resources[0] = resource;
for(int i=1; i<size; i++)
{
resources[i] = (Resource)overlays.get(i-1);
getLog().info("Adding overlay: " + resources[i]);
}
rc.setResources(resources);
}
}
webAppConfig.setBaseResource(rc);
_overlays = overlays;
}