in indexer-core/src/main/java/org/apache/maven/index/updater/DefaultIndexUpdater.java [99:161]
public IndexUpdateResult fetchAndUpdateIndex(final IndexUpdateRequest updateRequest) throws IOException {
IndexUpdateResult result = new IndexUpdateResult();
IndexingContext context = updateRequest.getIndexingContext();
ResourceFetcher fetcher = null;
if (!updateRequest.isOffline()) {
fetcher = updateRequest.getResourceFetcher();
// If no resource fetcher passed in, use the wagon fetcher by default
// and put back in request for future use
if (fetcher == null) {
throw new IOException("Update of the index without provided ResourceFetcher is impossible.");
}
fetcher.connect(context.getId(), context.getIndexUpdateUrl());
}
File cacheDir = updateRequest.getLocalIndexCacheDir();
Locker locker = updateRequest.getLocker();
Lock lock = locker != null && cacheDir != null ? locker.lock(cacheDir) : null;
try {
if (cacheDir != null) {
LocalCacheIndexAdaptor cache = new LocalCacheIndexAdaptor(cacheDir, result);
if (!updateRequest.isOffline()) {
cacheDir.mkdirs();
try {
if (fetchAndUpdateIndex(updateRequest, fetcher, cache).isSuccessful()) {
cache.commit();
}
} finally {
fetcher.disconnect();
}
}
fetcher = cache.getFetcher();
} else if (updateRequest.isOffline()) {
throw new IllegalArgumentException("LocalIndexCacheDir can not be null in offline mode");
}
try {
if (!updateRequest.isCacheOnly()) {
LuceneIndexAdaptor target = new LuceneIndexAdaptor(updateRequest);
result = fetchAndUpdateIndex(updateRequest, fetcher, target);
if (result.isSuccessful()) {
target.commit();
}
}
} finally {
fetcher.disconnect();
}
} finally {
if (lock != null) {
lock.release();
}
}
return result;
}