1 package org.apache.maven.index.context; 2 3 /* 4 * Licensed to the Apache Software Foundation (ASF) under one 5 * or more contributor license agreements. See the NOTICE file 6 * distributed with this work for additional information 7 * regarding copyright ownership. The ASF licenses this file 8 * to you under the Apache License, Version 2.0 (the 9 * "License"); you may not use this file except in compliance 10 * with the License. You may obtain a copy of the License at 11 * 12 * http://www.apache.org/licenses/LICENSE-2.0 13 * 14 * Unless required by applicable law or agreed to in writing, 15 * software distributed under the License is distributed on an 16 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 17 * KIND, either express or implied. See the License for the 18 * specific language governing permissions and limitations 19 * under the License. 20 */ 21 22 import java.io.File; 23 import java.io.IOException; 24 import java.util.Collection; 25 import java.util.Date; 26 import java.util.List; 27 import java.util.Set; 28 29 import org.apache.lucene.analysis.Analyzer; 30 import org.apache.lucene.index.IndexReader; 31 import org.apache.lucene.index.IndexWriter; 32 import org.apache.lucene.search.IndexSearcher; 33 import org.apache.lucene.store.Directory; 34 import org.apache.maven.index.artifact.GavCalculator; 35 36 /** 37 * An indexing context is representing artifact repository for indexing and searching. Indexing context is a statefull 38 * component, it keeps state of index readers and writers. 39 * 40 * @author Jason van Zyl 41 * @author Tamas Cservenak 42 * @author Eugene Kuleshov 43 */ 44 public interface IndexingContext 45 { 46 /** 47 * Standard name of the full repository index that is used when clients requesting index information have nothing to 48 * start with. 49 */ 50 String INDEX_FILE_PREFIX = "nexus-maven-repository-index"; 51 52 String INDEX_REMOTE_PROPERTIES_FILE = INDEX_FILE_PREFIX + ".properties"; 53 54 String INDEX_UPDATER_PROPERTIES_FILE = INDEX_FILE_PREFIX + "-updater.properties"; 55 56 String INDEX_PACKER_PROPERTIES_FILE = INDEX_FILE_PREFIX + "-packer.properties"; 57 58 /** 59 * A prefix used for all index property names 60 */ 61 String INDEX_PROPERTY_PREFIX = "nexus.index."; 62 63 /** 64 * A property name used to specify index id 65 */ 66 String INDEX_ID = INDEX_PROPERTY_PREFIX + "id"; 67 68 /** 69 * A property name used to specify legacy index timestamp (the last update time) 70 */ 71 String INDEX_LEGACY_TIMESTAMP = INDEX_PROPERTY_PREFIX + "time"; 72 73 /** 74 * A property name used to specify index timtestamp 75 */ 76 String INDEX_TIMESTAMP = INDEX_PROPERTY_PREFIX + "timestamp"; 77 78 /** 79 * A prefix used to specify an incremental update chunk name 80 */ 81 String INDEX_CHUNK_PREFIX = INDEX_PROPERTY_PREFIX + "incremental-"; 82 83 /** 84 * A date format used for index timestamp 85 */ 86 String INDEX_TIME_FORMAT = "yyyyMMddHHmmss.SSS Z"; 87 88 /** 89 * A date format used for incremental update chunk names 90 */ 91 String INDEX_TIME_DAY_FORMAT = "yyyyMMdd"; 92 93 /** 94 * A counter used to id the chunks 95 */ 96 String INDEX_CHUNK_COUNTER = INDEX_PROPERTY_PREFIX + "last-incremental"; 97 98 /** 99 * An id that defines the current incremental chain. If when checking remote repo, the index chain doesn't match 100 * you'll know that you need to download the full index 101 */ 102 String INDEX_CHAIN_ID = INDEX_PROPERTY_PREFIX + "chain-id"; 103 104 /** 105 * Returns this indexing context id. 106 */ 107 String getId(); 108 109 /** 110 * Returns repository id. 111 */ 112 String getRepositoryId(); 113 114 /** 115 * Returns location for the local repository. 116 */ 117 File getRepository(); 118 119 /** 120 * Returns public repository url. 121 */ 122 String getRepositoryUrl(); 123 124 /** 125 * Returns url for the index update 126 */ 127 String getIndexUpdateUrl(); 128 129 /** 130 * Is the context searchable when doing "non-targeted" searches? Ie. Should it take a part when searching without 131 * specifying context? 132 * 133 * @return 134 */ 135 boolean isSearchable(); 136 137 /** 138 * Sets is the context searchable when doing "non-targeted" searches. 139 * 140 * @param searchable 141 */ 142 void setSearchable( boolean searchable ); 143 144 /** 145 * Returns index update time 146 */ 147 Date getTimestamp(); 148 149 void updateTimestamp() 150 throws IOException; 151 152 void updateTimestamp( boolean save ) 153 throws IOException; 154 155 void updateTimestamp( boolean save, Date date ) 156 throws IOException; 157 158 /** 159 * Returns a number that represents the "size" useful for doing comparisons between contexts (which one has more 160 * data indexed?). The number return does not represent the count of ArtifactInfos, neither other "meaningful" info, 161 * it is purely to be used for inter-context comparisons only! 162 * 163 * @return 164 * @throws IOException 165 */ 166 int getSize() 167 throws IOException; 168 169 /** 170 * Returns the Lucene IndexReader of this context. 171 * 172 * @return reader 173 * @throws IOException 174 */ 175 IndexReader getIndexReader() 176 throws IOException; 177 178 /** 179 * Returns the Lucene IndexSearcher of this context. 180 * 181 * @return searcher 182 * @throws IOException 183 */ 184 IndexSearcher getIndexSearcher() 185 throws IOException; 186 187 /** 188 * Returns the Lucene IndexWriter of this context. 189 * 190 * @return indexWriter 191 * @throws IOException 192 */ 193 IndexWriter getIndexWriter() 194 throws IOException; 195 196 /** 197 * List of IndexCreators used in this context. 198 * 199 * @return list of index creators. 200 */ 201 List<IndexCreator> getIndexCreators(); 202 203 /** 204 * Returns the Lucene Analyzer of this context used for by IndexWriter and IndexSearcher. Note: this method always 205 * creates a new instance of analyzer! 206 * 207 * @return 208 */ 209 Analyzer getAnalyzer(); 210 211 /** 212 * Commits changes to context, eventually refreshing readers/searchers too. 213 * 214 * @throws IOException 215 */ 216 void commit() 217 throws IOException; 218 219 /** 220 * Rolls back changes to context, eventually refreshing readers/searchers too. 221 * 222 * @throws IOException 223 */ 224 void rollback() 225 throws IOException; 226 227 /** 228 * Optimizes index 229 */ 230 void optimize() 231 throws IOException; 232 233 /** 234 * Performs a shared locking on this context, guaranteeing that no IndexReader/Searcher/Writer close will occur. But 235 * the cost of it is potentially blocking other threads, so stay in critical region locking this context as less as 236 * possible. 237 */ 238 void lock(); 239 240 /** 241 * Releases the shared lock on this context. 242 */ 243 void unlock(); 244 245 /** 246 * Shuts down this context. 247 */ 248 void close( boolean deleteFiles ) 249 throws IOException; 250 251 /** 252 * Purge (cleans) the context, deletes/empties the index and restores the context to new/empty state. 253 * 254 * @throws IOException 255 */ 256 void purge() 257 throws IOException; 258 259 /** 260 * Merges content of given Lucene directory with this context. 261 * 262 * @param directory - the directory to merge 263 */ 264 void merge( Directory directory ) 265 throws IOException; 266 267 /** 268 * Merges content of given Lucene directory with this context, but filters out the unwanted ones. 269 * 270 * @param directory - the directory to merge 271 */ 272 void merge( Directory directory, DocumentFilter filter ) 273 throws IOException; 274 275 /** 276 * Replaces the Lucene index with the one from supplied directory. 277 * 278 * @param directory 279 * @throws IOException 280 */ 281 void replace( Directory directory ) 282 throws IOException; 283 284 Directory getIndexDirectory(); 285 286 File getIndexDirectoryFile(); 287 288 /** 289 * Returns the GavCalculator for this Context. Implies repository layout. 290 */ 291 GavCalculator getGavCalculator(); 292 293 /** 294 * Sets all group names stored in the current indexing context 295 */ 296 void setAllGroups( Collection<String> groups ) 297 throws IOException; 298 299 /** 300 * Gets all group names stored in the current indexing context 301 */ 302 Set<String> getAllGroups() 303 throws IOException; 304 305 /** 306 * Sets root group names stored in the current indexing context 307 */ 308 void setRootGroups( Collection<String> groups ) 309 throws IOException; 310 311 /** 312 * Gets root group names stored in the current indexing context 313 */ 314 Set<String> getRootGroups() 315 throws IOException; 316 317 /** 318 * Rebuilds stored group names from the index 319 */ 320 void rebuildGroups() 321 throws IOException; 322 323 /** 324 * Returns true if this context is receiving updates from remote via IndexUpdater. 325 * 326 * @return 327 */ 328 boolean isReceivingUpdates(); 329 }