mirror of
https://gitflic.ru/project/openide/openide.git
synced 2026-09-27 10:03:11 +07:00
refactoring: use ID<?,?> for IndexingStamp.rewriteVersion / IndexingStamp.versionDiffers
This commit is contained in:
@@ -107,11 +107,14 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponentAdap
|
||||
synchronized (state) {
|
||||
state.myIndexIdToVersionMap.put(indexKey, version);
|
||||
}
|
||||
final File versionFile = IndexInfrastructure.getVersionFile(indexKey);
|
||||
final boolean versionFileExisted = versionFile.exists();
|
||||
|
||||
final File indexRootDir = IndexInfrastructure.getIndexRootDir(indexKey);
|
||||
boolean needRebuild = false;
|
||||
if (forceClean || IndexingStamp.versionDiffers(versionFile, version)) {
|
||||
|
||||
if (forceClean || IndexingStamp.versionDiffers(indexKey, version)) {
|
||||
final File versionFile = IndexInfrastructure.getVersionFile(indexKey);
|
||||
final boolean versionFileExisted = versionFile.exists();
|
||||
|
||||
final String[] children = indexRootDir.list();
|
||||
// rebuild only if there exists what to rebuild
|
||||
boolean indexRootHasChildren = children != null && children.length > 0;
|
||||
@@ -120,7 +123,7 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponentAdap
|
||||
LOG.info("Version has changed for stub index " + extension.getKey() + ". The index will be rebuilt.");
|
||||
}
|
||||
if (indexRootHasChildren) FileUtil.deleteWithRenaming(indexRootDir);
|
||||
IndexingStamp.rewriteVersion(versionFile, version); // todo snapshots indices
|
||||
IndexingStamp.rewriteVersion(indexKey, version); // todo snapshots indices
|
||||
}
|
||||
|
||||
for (int attempt = 0; attempt < 2; attempt++) {
|
||||
@@ -172,21 +175,24 @@ public class StubIndexImpl extends StubIndex implements ApplicationComponentAdap
|
||||
}
|
||||
catch (IOException e) {
|
||||
needRebuild = true;
|
||||
onExceptionInstantiatingIndex(version, versionFile, indexRootDir, e);
|
||||
onExceptionInstantiatingIndex(indexKey, version, indexRootDir, e);
|
||||
} catch (RuntimeException e) {
|
||||
//noinspection ThrowableResultOfMethodCallIgnored
|
||||
Throwable cause = FileBasedIndexImpl.getCauseToRebuildIndex(e);
|
||||
if (cause == null) throw e;
|
||||
onExceptionInstantiatingIndex(version, versionFile, indexRootDir, e);
|
||||
onExceptionInstantiatingIndex(indexKey, version, indexRootDir, e);
|
||||
}
|
||||
}
|
||||
return needRebuild;
|
||||
}
|
||||
|
||||
private static void onExceptionInstantiatingIndex(int version, File versionFile, File indexRootDir, Exception e) throws IOException {
|
||||
private static <K> void onExceptionInstantiatingIndex(StubIndexKey<K, ?> indexKey,
|
||||
int version,
|
||||
File indexRootDir,
|
||||
Exception e) throws IOException {
|
||||
LOG.info(e);
|
||||
FileUtil.deleteWithRenaming(indexRootDir);
|
||||
IndexingStamp.rewriteVersion(versionFile, version); // todo snapshots indices
|
||||
IndexingStamp.rewriteVersion(indexKey, version); // todo snapshots indices
|
||||
}
|
||||
|
||||
public long getIndexModificationStamp(StubIndexKey<?, ?> indexId, @NotNull Project project) {
|
||||
|
||||
@@ -329,9 +329,11 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
final int version = extension.getVersion();
|
||||
|
||||
final File versionFile = IndexInfrastructure.getVersionFile(name);
|
||||
final boolean versionFileExisted = versionFile.exists();
|
||||
boolean versionChanged = false;
|
||||
if (IndexingStamp.versionDiffers(versionFile, version)) {
|
||||
|
||||
if (IndexingStamp.versionDiffers(name, version)) {
|
||||
final boolean versionFileExisted = versionFile.exists();
|
||||
|
||||
if (versionFileExisted) {
|
||||
versionChanged = true;
|
||||
LOG.info("Version has changed for index " + name + ". The index will be rebuilt.");
|
||||
@@ -341,15 +343,17 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
}
|
||||
File rootDir = IndexInfrastructure.getIndexRootDir(name);
|
||||
if (versionFileExisted) FileUtil.deleteWithRenaming(rootDir);
|
||||
IndexingStamp.rewriteVersion(versionFile, version);
|
||||
IndexingStamp.rewriteVersion(name, version);
|
||||
}
|
||||
|
||||
initIndexStorage(extension, version, versionFile, state);
|
||||
initIndexStorage(extension, version, state);
|
||||
|
||||
return versionChanged;
|
||||
}
|
||||
|
||||
private static <K, V> void initIndexStorage(@NotNull FileBasedIndexExtension<K, V> extension, int version, @NotNull File versionFile, IndexConfiguration state)
|
||||
private static <K, V> void initIndexStorage(@NotNull FileBasedIndexExtension<K, V> extension,
|
||||
int version,
|
||||
IndexConfiguration state)
|
||||
throws IOException {
|
||||
VfsAwareMapIndexStorage<K, V> storage = null;
|
||||
final ID<K, V> name = extension.getName();
|
||||
@@ -401,7 +405,7 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
if (extension.hasSnapshotMapping() && (!contentHashesEnumeratorOk || instantiatedStorage)) {
|
||||
FileUtil.deleteWithRenaming(IndexInfrastructure.getPersistentIndexRootDir(name)); // todo there is possibility of corruption of storage and content hashes
|
||||
}
|
||||
IndexingStamp.rewriteVersion(versionFile, version);
|
||||
IndexingStamp.rewriteVersion(name, version);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1137,7 +1141,7 @@ public class FileBasedIndexImpl extends FileBasedIndex {
|
||||
|
||||
private void advanceIndexVersion(ID<?, ?> indexId) {
|
||||
try {
|
||||
IndexingStamp.rewriteVersion(IndexInfrastructure.getVersionFile(indexId), myState.getIndexVersion(indexId));
|
||||
IndexingStamp.rewriteVersion(indexId, myState.getIndexVersion(indexId));
|
||||
}
|
||||
catch (IOException e) {
|
||||
LOG.error(e);
|
||||
|
||||
@@ -71,7 +71,8 @@ public class IndexingStamp {
|
||||
|
||||
private IndexingStamp() {}
|
||||
|
||||
public static synchronized void rewriteVersion(@NotNull final File file, final int version) throws IOException {
|
||||
public static synchronized void rewriteVersion(@NotNull ID<?,?> indexId, final int version) throws IOException {
|
||||
File file = IndexInfrastructure.getVersionFile(indexId);
|
||||
if (FileBasedIndexImpl.LOG.isDebugEnabled()) {
|
||||
FileBasedIndexImpl.LOG.debug("Rewriting " + file + "," + version);
|
||||
}
|
||||
@@ -122,7 +123,8 @@ public class IndexingStamp {
|
||||
|
||||
private static final int OUR_INDICES_TIMESTAMP_INCREMENT = SystemProperties.getIntProperty("idea.indices.timestamp.resolution", 1);
|
||||
|
||||
public static boolean versionDiffers(@NotNull File versionFile, final int currentIndexVersion) {
|
||||
public static boolean versionDiffers(@NotNull ID<?,?> indexId, final int currentIndexVersion) {
|
||||
File versionFile = IndexInfrastructure.getVersionFile(indexId);
|
||||
try {
|
||||
ourLastStamp = Math.max(ourLastStamp, versionFile.lastModified());
|
||||
final DataInputStream in = new DataInputStream(new BufferedInputStream(new FileInputStream(versionFile)));
|
||||
|
||||
Reference in New Issue
Block a user