in indexer-core/src/main/java/org/apache/maven/index/updater/DefaultIndexUpdater.java [545:628]
private IndexUpdateResult fetchAndUpdateIndex(
final IndexUpdateRequest updateRequest, ResourceFetcher source, IndexAdaptor target) throws IOException {
IndexUpdateResult result = new IndexUpdateResult();
if (!updateRequest.isForceFullUpdate()) {
Properties localProperties = target.getProperties();
Date localTimestamp = null;
if (localProperties != null) {
localTimestamp = getTimestamp(localProperties, IndexingContext.INDEX_TIMESTAMP);
}
// this will download and store properties in the target, so next run
// target.getProperties() will retrieve it
Properties remoteProperties = target.setProperties(source);
Date updateTimestamp = getTimestamp(remoteProperties, IndexingContext.INDEX_TIMESTAMP);
// If new timestamp is missing, dont bother checking incremental, we have an old file
if (updateTimestamp != null) {
List<String> filenames = incrementalHandler.loadRemoteIncrementalUpdates(
updateRequest, localProperties, remoteProperties);
// if we have some incremental files, merge them in
if (filenames != null) {
for (String filename : filenames) {
target.addIndexChunk(source, filename);
}
result.setTimestamp(updateTimestamp);
result.setSuccessful(true);
return result;
}
} else {
updateTimestamp = getTimestamp(remoteProperties, IndexingContext.INDEX_LEGACY_TIMESTAMP);
}
// fallback to timestamp comparison, but try with one coming from local properties, and if not possible (is
// null)
// fallback to context timestamp
if (localTimestamp != null) {
// if we have localTimestamp
// if incremental can't be done for whatever reason, simply use old logic of
// checking the timestamp, if the same, nothing to do
if (updateTimestamp != null && localTimestamp != null && !updateTimestamp.after(localTimestamp)) {
// Index is up to date
result.setSuccessful(true);
return result;
}
}
} else {
// create index properties during forced full index download
target.setProperties(source);
}
if (!updateRequest.isIncrementalOnly()) {
Date timestamp;
try {
timestamp = target.setIndexFile(source, IndexingContext.INDEX_FILE_PREFIX + ".gz");
if (source instanceof LocalIndexCacheFetcher) {
// local cache has inverse organization compared to remote indexes,
// i.e. initial index file and delta chunks to apply on top of it
for (String filename : ((LocalIndexCacheFetcher) source).getChunks()) {
target.addIndexChunk(source, filename);
}
}
} catch (IOException ex) {
// try to look for legacy index transfer format
try {
timestamp = target.setIndexFile(source, IndexingContext.INDEX_FILE_PREFIX + ".zip");
} catch (IOException ex2) {
getLogger().error("Fallback to *.zip also failed: " + ex2); // do not bother with stack trace
throw ex; // original exception more likely to be interesting
}
}
result.setTimestamp(timestamp);
result.setSuccessful(true);
result.setFullUpdate(true);
}
return result;
}