public void buildSprites(Collection<String> filePaths) throws FileNotFoundException,
IOException
{
final long start = System.currentTimeMillis();
final LevelCounterMessageSink levelCounter = new LevelCounterMessageSink();
messageLog.addMessageSink(levelCounter);
// Collect sprite declarations from all css files
final Multimap<String, SpriteImageOccurrence> spriteImageOccurrencesByFile = spriteDirectiveOccurrenceCollector
.collectSpriteImageOccurrences(filePaths);
// Merge them, checking for duplicates
final Map<String, SpriteImageOccurrence> spriteImageOccurrencesBySpriteId = spriteDirectiveOccurrenceCollector
.mergeSpriteImageOccurrences(spriteImageOccurrencesByFile);
final Map<String, SpriteImageDirective> spriteImageDirectivesBySpriteId = Maps
.newLinkedHashMap();
for (Map.Entry<String, SpriteImageOccurrence> entry : spriteImageOccurrencesBySpriteId
.entrySet())
{
spriteImageDirectivesBySpriteId.put(entry.getKey(),
entry.getValue().spriteImageDirective);
}
// Collect sprite references from all css files
final Multimap<String, SpriteReferenceOccurrence> spriteEntriesByFile = spriteDirectiveOccurrenceCollector
.collectSpriteReferenceOccurrences(filePaths, spriteImageDirectivesBySpriteId);
// Now merge and regroup all files by sprite-id
final Multimap<String, SpriteReferenceOccurrence> spriteReferenceOccurrencesBySpriteId = SpriteDirectiveOccurrenceCollector
.mergeSpriteReferenceOccurrences(spriteEntriesByFile);
// Build the sprite images
messageLog.setCssFile(null);
final Multimap<String, SpriteReferenceReplacement> spriteReplacementsByFile = spriteImageBuilder
.buildSpriteImages(spriteImageOccurrencesBySpriteId,
spriteReferenceOccurrencesBySpriteId);
// Rewrite the CSS
rewriteCssFiles(spriteImageOccurrencesByFile, spriteReplacementsByFile);
final long stop = System.currentTimeMillis();
if (levelCounter.getWarnCount() > 0)
{
messageLog.status(MessageType.PROCESSING_COMPLETED_WITH_WARNINGS,
(stop - start), levelCounter.getWarnCount());
}
else
{
messageLog.status(MessageType.PROCESSING_COMPLETED, (stop - start));
}