}
@Override
public void execute() throws MojoExecutionException, MojoFailureException {
ClassLoader contextCL = Thread.currentThread().getContextClassLoader();
Faces faces = null;
ExecutorService executorService = null;
Collection<VFSRoot> webResources = null;
Collection<VFSRoot> cpResources = null;
try {
URL[] projectCP = getProjectClassPath();
ClassLoader projectCL = createProjectClassLoader(projectCP);
Thread.currentThread().setContextClassLoader(projectCL);
webResources = getWebrootVfs();
cpResources = getClasspathVfs(projectCP);
Collection<VirtualFile> resourceRoots = ResourceUtil.getResourceRoots(cpResources, webResources);
getLog().debug("resourceRoots: " + resourceRoots);
scanStaticResources(resourceRoots);
StaticResourceHandler staticResourceHandler = new StaticResourceHandler(resourceRoots);
ResourceFactory resourceFactory = new ResourceFactoryImpl(staticResourceHandler);
scanDynamicResources(cpResources, resourceFactory);
DynamicResourceHandler dynamicResourceHandler = new DynamicResourceHandler(staticResourceHandler, resourceFactory);
getLog().debug("foundResources: " + foundResources);
checkBooleanPack();
if (pack != null) {
reorderFoundResources(cpResources, dynamicResourceHandler, resourceFactory);
}
faces = new FacesImpl(null, new FileNameMapperImpl(fileNameMappings), dynamicResourceHandler);
faces.start();
ResourceWriterImpl resourceWriter = new ResourceWriterImpl(new File(resourcesOutputDir),
getDefaultResourceProcessors(), getLogger(), resourcesWithKnownOrder);
ResourceTaskFactoryImpl taskFactory = new ResourceTaskFactoryImpl(faces, pack);
taskFactory.setResourceWriter(resourceWriter);
executorService = createExecutorService();
CompletionService<Object> completionService = new CountingExecutorCompletionService<Object>(executorService);
taskFactory.setCompletionService(completionService);
taskFactory.setSkins(skins);
taskFactory.setLog(getLogger());
taskFactory.setFilter(createResourcesFilter());
taskFactory.submit(foundResources);
getLog().debug(completionService.toString());
Future<Object> future = null;
while (true) {
future = completionService.take();
if (future != null) {
try {
future.get();
} catch (ExecutionException e) {
getLog().error(e);
}
} else {
break;
}
}
getLog().debug(completionService.toString());
resourceWriter.writeProcessedResourceMappings(new File(staticResourceMappingFile), staticResourcePrefix);
resourceWriter.close();
} catch (Exception e) {
throw new MojoExecutionException(e.getMessage(), e);
} finally {
if (cpResources != null) {
for (VFSRoot vfsRoot : cpResources) {
try {
vfsRoot.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
if (webResources != null) {
for (VFSRoot vfsRoot : webResources) {
try {
vfsRoot.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
// TODO review finally block
if (executorService != null) {
executorService.shutdown();
}
if (faces != null) {
faces.stop();
}
Thread.currentThread().setContextClassLoader(contextCL);
}
}