Improving versioning of indices inside the IDE.
authorJan Lahoda <jlahoda@netbeans.org>
Thu, 06 Jan 2011 19:27:10 +0100
changeset 506ec6bf12c6eee
parent 505 a9c7f05dd888
child 507 6cbc51eb46bb
Improving versioning of indices inside the IDE.
api/src/org/netbeans/modules/jackpot30/impl/duplicates/ComputeDuplicates.java
api/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DuplicatesCustomIndexerImpl.java
api/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DuplicatesIndex.java
api/src/org/netbeans/modules/jackpot30/impl/indexing/Cache.java
api/src/org/netbeans/modules/jackpot30/impl/indexing/CustomIndexerImpl.java
api/src/org/netbeans/modules/jackpot30/impl/indexing/FileBasedIndex.java
server/indexer/src/org/netbeans/modules/jackpot30/server/indexer/StandaloneFinder.java
     1.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/duplicates/ComputeDuplicates.java	Tue Dec 28 22:16:52 2010 +0100
     1.2 +++ b/api/src/org/netbeans/modules/jackpot30/impl/duplicates/ComputeDuplicates.java	Thu Jan 06 19:27:10 2011 +0100
     1.3 @@ -113,7 +113,7 @@
     1.4                  //TODO: needs to be removed for server mode
     1.5                  new DuplicatesCustomIndexerImpl.FactoryImpl().updateIndex(u, cancel); //TODO: show updating progress to the user
     1.6                  
     1.7 -                File cacheRoot = Cache.findCache(DuplicatesIndex.NAME).findCacheRoot(u);
     1.8 +                File cacheRoot = Cache.findCache(DuplicatesIndex.NAME, DuplicatesIndex.VERSION).findCacheRoot(u);
     1.9  
    1.10                  File dir = new File(cacheRoot, "fulltext");
    1.11  
     2.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DuplicatesCustomIndexerImpl.java	Tue Dec 28 22:16:52 2010 +0100
     2.2 +++ b/api/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DuplicatesCustomIndexerImpl.java	Thu Jan 06 19:27:10 2011 +0100
     2.3 @@ -59,6 +59,8 @@
     2.4   */
     2.5  public class DuplicatesCustomIndexerImpl extends DeferredCustomIndexer {
     2.6  
     2.7 +    private static final String NAME = "";
     2.8 +    private static final int VERSION = 1;
     2.9      public DuplicatesCustomIndexerImpl(DeferredCustomIndexerFactory factory) {
    2.10          super(factory);
    2.11      }
    2.12 @@ -111,12 +113,12 @@
    2.13  
    2.14          @Override
    2.15          public int getIndexVersion() {
    2.16 -            return Cache.VERSION;
    2.17 +            return DuplicatesIndex.VERSION;
    2.18          }
    2.19  
    2.20          @Override
    2.21          protected File cacheRoot(URL root) throws IOException {
    2.22 -            return Cache.findCache(DuplicatesIndex.NAME).findCacheRoot(root);
    2.23 +            return Cache.findCache(DuplicatesIndex.NAME, DuplicatesIndex.VERSION).findCacheRoot(root);
    2.24          }
    2.25  
    2.26      }
     3.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DuplicatesIndex.java	Tue Dec 28 22:16:52 2010 +0100
     3.2 +++ b/api/src/org/netbeans/modules/jackpot30/impl/duplicates/indexing/DuplicatesIndex.java	Thu Jan 06 19:27:10 2011 +0100
     3.3 @@ -92,7 +92,7 @@
     3.4      }
     3.5  
     3.6      public static @CheckForNull DuplicatesIndex get(URL sourceRoot) throws IOException {
     3.7 -        return new DuplicatesIndex(sourceRoot, Cache.findCache(NAME).findCacheRoot(sourceRoot)); //XXX: new!
     3.8 +        return new DuplicatesIndex(sourceRoot, Cache.findCache(NAME, VERSION).findCacheRoot(sourceRoot)); //XXX: new!
     3.9      }
    3.10  
    3.11      public IndexWriter openForWriting() throws IOException {
    3.12 @@ -193,4 +193,5 @@
    3.13      private static final int MINIMAL_VALUE = 10;
    3.14  
    3.15      public static final String NAME = "duplicates"; //NOI18N
    3.16 +    public static final int    VERSION = 1; //NOI18N
    3.17  }
     4.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/indexing/Cache.java	Tue Dec 28 22:16:52 2010 +0100
     4.2 +++ b/api/src/org/netbeans/modules/jackpot30/impl/indexing/Cache.java	Thu Jan 06 19:27:10 2011 +0100
     4.3 @@ -66,25 +66,25 @@
     4.4   */
     4.5  public class Cache {
     4.6  
     4.7 -    public static final int VERSION = 1;
     4.8 -
     4.9      private static File standaloneCacheRoot;
    4.10      private static Map<String, Cache> name2Cache = new HashMap<String, Cache>();
    4.11  
    4.12 -    public static Cache findCache(String indexName) {
    4.13 +    public static Cache findCache(String indexName, int version) {
    4.14          Cache cache = name2Cache.get(indexName);
    4.15  
    4.16          if (cache == null) {
    4.17 -            name2Cache.put(indexName, cache = new Cache(indexName));
    4.18 +            name2Cache.put(indexName, cache = new Cache(indexName, version));
    4.19          }
    4.20  
    4.21          return cache;
    4.22      }
    4.23  
    4.24      private final String name;
    4.25 +    private final int version;
    4.26  
    4.27 -    private Cache(String name) {
    4.28 +    private Cache(String name, int version) {
    4.29          this.name = name;
    4.30 +        this.version = version;
    4.31      }
    4.32      
    4.33      public File findCacheRoot(URL sourceRoot) throws IOException {
    4.34 @@ -96,13 +96,13 @@
    4.35          if (standaloneCacheRoot != null) {
    4.36              return getDataFolder(sourceRoot, name);
    4.37          } else {
    4.38 -            return findCacheRootNB(sourceRoot);
    4.39 +            return findCacheRootNB(sourceRoot, version);
    4.40          }
    4.41      }
    4.42  
    4.43 -    private File findCacheRootNB(URL sourceRoot) throws IOException {
    4.44 +    private File findCacheRootNB(URL sourceRoot, int version) throws IOException {
    4.45          FileObject indexBaseFolder = CacheFolder.getDataFolder(sourceRoot);
    4.46 -        String path = SPIAccessor.getInstance().getIndexerPath(name, VERSION);
    4.47 +        String path = SPIAccessor.getInstance().getIndexerPath(name, version);
    4.48          FileObject indexFolder = FileUtil.createFolder(indexBaseFolder, path);
    4.49          return FileUtil.toFile(indexFolder);
    4.50      }
     5.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/indexing/CustomIndexerImpl.java	Tue Dec 28 22:16:52 2010 +0100
     5.2 +++ b/api/src/org/netbeans/modules/jackpot30/impl/indexing/CustomIndexerImpl.java	Thu Jan 06 19:27:10 2011 +0100
     5.3 @@ -161,7 +161,7 @@
     5.4  
     5.5          @Override
     5.6          public int getIndexVersion() {
     5.7 -            return Cache.VERSION;
     5.8 +            return FileBasedIndex.VERSION;
     5.9          }
    5.10  
    5.11      }
     6.1 --- a/api/src/org/netbeans/modules/jackpot30/impl/indexing/FileBasedIndex.java	Tue Dec 28 22:16:52 2010 +0100
     6.2 +++ b/api/src/org/netbeans/modules/jackpot30/impl/indexing/FileBasedIndex.java	Thu Jan 06 19:27:10 2011 +0100
     6.3 @@ -68,11 +68,11 @@
     6.4      }
     6.5  
     6.6      public static @CheckForNull Index get(URL sourceRoot) throws IOException {
     6.7 -        return new FileBasedIndex(sourceRoot, Cache.findCache(FileBasedIndex.NAME).findCacheRoot(sourceRoot), false); //XXX: new!
     6.8 +        return new FileBasedIndex(sourceRoot, Cache.findCache(FileBasedIndex.NAME, FileBasedIndex.VERSION).findCacheRoot(sourceRoot), false); //XXX: new!
     6.9      }
    6.10  
    6.11      public static @NonNull Index create(URL sourceRoot, boolean storeSources) throws IOException {
    6.12 -        return new FileBasedIndex(sourceRoot, Cache.findCache(FileBasedIndex.NAME).findCacheRoot(sourceRoot), storeSources);
    6.13 +        return new FileBasedIndex(sourceRoot, Cache.findCache(FileBasedIndex.NAME, FileBasedIndex.VERSION).findCacheRoot(sourceRoot), storeSources);
    6.14      }
    6.15  
    6.16      private final URL  sourceRoot;
    6.17 @@ -171,4 +171,6 @@
    6.18      }
    6.19      
    6.20      public static final String NAME = "jackpot30"; //NOI18N
    6.21 +    public static final int VERSION = AbstractLuceneIndex.MAJOR_VERSION * 1000 + AbstractLuceneIndex.MINOR_VERSION;
    6.22 +
    6.23  }
     7.1 --- a/server/indexer/src/org/netbeans/modules/jackpot30/server/indexer/StandaloneFinder.java	Tue Dec 28 22:16:52 2010 +0100
     7.2 +++ b/server/indexer/src/org/netbeans/modules/jackpot30/server/indexer/StandaloneFinder.java	Thu Jan 06 19:27:10 2011 +0100
     7.3 @@ -120,7 +120,7 @@
     7.4      }
     7.5  
     7.6      public static Map<String, Collection<? extends String>> containsHash(File sourceRoot, Iterable<? extends String> hashes) throws IOException {
     7.7 -        File cacheRoot = Cache.findCache(DuplicatesIndex.NAME).findCacheRoot(sourceRoot.toURI().toURL());
     7.8 +        File cacheRoot = Cache.findCache(DuplicatesIndex.NAME, DuplicatesIndex.VERSION).findCacheRoot(sourceRoot.toURI().toURL());
     7.9          File dir = new File(cacheRoot, "fulltext");
    7.10  
    7.11          if (dir.listFiles() != null && dir.listFiles().length > 0) {