* Scans the associated paths to recompute the available resources.
*
* @param logger status and error details are written here
*/
public synchronized void scanResources(TreeLogger logger) {
Event resourceOracle =
SpeedTracerLogger.start(CompilerEventType.RESOURCE_ORACLE, "phase", "refresh");
TreeLogger refreshBranch = Messages.REFRESHING_RESOURCES.branch(logger, null);
Map<String, ResourceDescription> resourceDescriptionsByPath =
new LinkedHashMap<String, ResourceDescription>();
for (ClassPathEntry classPathEntry : classPathEntries) {
TreeLogger branchForClassPathEntry =
Messages.EXAMINING_PATH_ROOT.branch(refreshBranch, classPathEntry.getLocation(), null);
Map<AbstractResource, ResourceResolution> prefixesByResource =
classPathEntry.findApplicableResources(branchForClassPathEntry, pathPrefixSet);
for (Entry<AbstractResource, ResourceResolution> entry : prefixesByResource.entrySet()) {
AbstractResource resource = entry.getKey();
ResourceResolution resourceResolution = entry.getValue();
ResourceDescription resourceDescription =
new ResourceDescription(resource, resourceResolution.getPathPrefix());
String resourcePath = resourceDescription.resource.getPath();
maybeRecordTypeForModule(resourceResolution, resourcePath);
maybeRecordOverlapWarning(resourceResolution, resourcePath);
// In case of collision.
if (resourceDescriptionsByPath.containsKey(resourcePath)) {
ResourceDescription oldResourceDescription = resourceDescriptionsByPath.get(resourcePath);
if (resourceDescription.isPreferredOver(oldResourceDescription)) {
resourceDescriptionsByPath.put(resourcePath, resourceDescription);
} else {
Messages.IGNORING_SHADOWED_RESOURCE.log(branchForClassPathEntry, resourcePath, null);
}
} else {
resourceDescriptionsByPath.put(resourcePath, resourceDescription);
}
}
}
Map<String, Resource> resourcesByPath = new HashMap<String, Resource>();
for (Entry<String, ResourceDescription> entry : resourceDescriptionsByPath.entrySet()) {
resourcesByPath.put(entry.getKey(), entry.getValue().resource);
}
// Update exposed collections with new (unmodifiable) data structures.
exposedResources = Collections.unmodifiableSet(Sets.newHashSet(resourcesByPath.values()));
exposedResourceMap = Collections.unmodifiableMap(resourcesByPath);
exposedPathNames = Collections.unmodifiableSet(resourcesByPath.keySet());
resourceOracle.end();
}