public void checkoutThroughCache(VcsSupport vcsSupport, final String repositoryUrl, File targetDirectory, String branch, boolean recursive) throws IOException {
String normalizedUrl = vcsSupport.normalizeRepositoryUrl(repositoryUrl);
String moduleInCacheName = cacheMapping.getProperty(normalizedUrl);
boolean newName = moduleInCacheName == null;
if (newName) {
moduleInCacheName = sanitize(normalizedUrl);
}
File moduleInCache = new File(cacheDirectory, moduleInCacheName);
if (!moduleInCache.exists()) {
log.info("Caching repository " + repositoryUrl + " as " + moduleInCacheName);
vcsSupport.checkout(repositoryUrl, moduleInCache, null, false, true);
} else {
log.info("Updating cached repository in " + moduleInCacheName);
vcsSupport.update(moduleInCache, null, false, true);
}
vcsSupport.checkout(moduleInCache.getAbsolutePath(), targetDirectory, branch, recursive, false);
vcsSupport.activate(repositoryUrl, targetDirectory);
if (newName) {
cacheMapping.put(normalizedUrl, moduleInCacheName);
saveCacheMapping();
}
}