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.IndexWriter; 31 import org.apache.lucene.search.IndexSearcher; 32 import org.apache.lucene.store.Directory; 33 import org.apache.maven.index.artifact.GavCalculator; 34 35 /** 36 * An indexing context is representing artifact repository for indexing and searching. Indexing context is a statefull 37 * component, it keeps state of index readers and writers. 38 * 39 * @author Jason van Zyl 40 * @author Tamas Cservenak 41 * @author Eugene Kuleshov 42 */ 43 public interface IndexingContext 44 { 45 /** 46 * Standard name of the full repository index that is used when clients requesting index information have nothing to 47 * start with. 48 */ 49 String INDEX_FILE_PREFIX = "nexus-maven-repository-index"; 50 51 String INDEX_REMOTE_PROPERTIES_FILE = INDEX_FILE_PREFIX + ".properties"; 52 53 String INDEX_UPDATER_PROPERTIES_FILE = INDEX_FILE_PREFIX + "-updater.properties"; 54 55 String INDEX_PACKER_PROPERTIES_FILE = INDEX_FILE_PREFIX + "-packer.properties"; 56 57 /** 58 * A prefix used for all index property names 59 */ 60 String INDEX_PROPERTY_PREFIX = "nexus.index."; 61 62 /** 63 * A property name used to specify index id 64 */ 65 String INDEX_ID = INDEX_PROPERTY_PREFIX + "id"; 66 67 /** 68 * A property name used to specify legacy index timestamp (the last update time) 69 */ 70 String INDEX_LEGACY_TIMESTAMP = INDEX_PROPERTY_PREFIX + "time"; 71 72 /** 73 * A property name used to specify index timtestamp 74 */ 75 String INDEX_TIMESTAMP = INDEX_PROPERTY_PREFIX + "timestamp"; 76 77 /** 78 * A prefix used to specify an incremental update chunk name 79 */ 80 String INDEX_CHUNK_PREFIX = INDEX_PROPERTY_PREFIX + "incremental-"; 81 82 /** 83 * A date format used for index timestamp 84 */ 85 String INDEX_TIME_FORMAT = "yyyyMMddHHmmss.SSS Z"; 86 87 /** 88 * A date format used for incremental update chunk names 89 */ 90 String INDEX_TIME_DAY_FORMAT = "yyyyMMdd"; 91 92 /** 93 * A counter used to id the chunks 94 */ 95 String INDEX_CHUNK_COUNTER = INDEX_PROPERTY_PREFIX + "last-incremental"; 96 97 /** 98 * An id that defines the current incremental chain. If when checking remote repo, the index chain doesn't match 99 * you'll know that you need to download the full index 100 */ 101 String INDEX_CHAIN_ID = INDEX_PROPERTY_PREFIX + "chain-id"; 102 103 /** 104 * Returns this indexing context id. 105 */ 106 String getId(); 107 108 /** 109 * Returns repository id. 110 */ 111 String getRepositoryId(); 112 113 /** 114 * Returns location for the local repository. 115 */ 116 File getRepository(); 117 118 /** 119 * Returns public repository url. 120 */ 121 String getRepositoryUrl(); 122 123 /** 124 * Returns url for the index update 125 */ 126 String getIndexUpdateUrl(); 127 128 /** 129 * Is the context searchable when doing "non-targeted" searches? Ie. Should it take a part when searching without 130 * specifying context? 131 * 132 * @return 133 */ 134 boolean isSearchable(); 135 136 /** 137 * Sets is the context searchable when doing "non-targeted" searches. 138 * 139 * @param searchable 140 */ 141 void setSearchable( boolean searchable ); 142 143 /** 144 * Returns index update time 145 */ 146 Date getTimestamp(); 147 148 void updateTimestamp() 149 throws IOException; 150 151 void updateTimestamp( boolean save ) 152 throws IOException; 153 154 void updateTimestamp( boolean save, Date date ) 155 throws IOException; 156 157 /** 158 * Returns a number that represents the "size" useful for doing comparisons between contexts (which one has more 159 * data indexed?). The number return does not represent the count of ArtifactInfos, neither other "meaningful" info, 160 * it is purely to be used for inter-context comparisons only! 161 * 162 * @return 163 * @throws IOException 164 */ 165 int getSize() 166 throws IOException; 167 168 /** 169 * Acquires a fresh instance of {@link IndexSearcher}. You have to release the received instance with 170 * {@link #releaseIndexSearcher(IndexSearcher)} otherwise you are about to introduce leak. 171 * 172 * @return 173 */ 174 IndexSearcher acquireIndexSearcher() 175 throws IOException; 176 177 /** 178 * Releases the {@link IndexSearcher} instance. 179 * 180 * @param s 181 */ 182 void releaseIndexSearcher( IndexSearcher s ) 183 throws IOException; 184 185 /** 186 * Returns the Lucene IndexWriter (thread safe, shared instance) of this context. 187 * 188 * @return indexWriter 189 * @throws IOException 190 */ 191 IndexWriter getIndexWriter() 192 throws IOException; 193 194 /** 195 * List of IndexCreators used in this context. 196 * 197 * @return list of index creators. 198 */ 199 List<IndexCreator> getIndexCreators(); 200 201 /** 202 * Returns the Lucene Analyzer of this context used for by IndexWriter and IndexSearcher. Note: this method always 203 * creates a new instance of analyzer! 204 * 205 * @return 206 */ 207 Analyzer getAnalyzer(); 208 209 /** 210 * Commits changes to context, eventually refreshing readers/searchers too. 211 * 212 * @throws IOException 213 */ 214 void commit() 215 throws IOException; 216 217 /** 218 * Rolls back changes to context, eventually refreshing readers/searchers too. 219 * 220 * @throws IOException 221 */ 222 void rollback() 223 throws IOException; 224 225 /** 226 * Optimizes index. According to Lucene 3.6+ Javadoc, there is no more sense to optimize, so this method might 227 * become "noop". 228 */ 229 void optimize() 230 throws IOException; 231 232 /** 233 * Shuts down this context. 234 */ 235 void close( boolean deleteFiles ) 236 throws IOException; 237 238 /** 239 * Purge (cleans) the context, deletes/empties the index and restores the context to new/empty state. 240 * 241 * @throws IOException 242 */ 243 void purge() 244 throws IOException; 245 246 /** 247 * Merges content of given Lucene directory with this context. 248 * 249 * @param directory - the directory to merge 250 */ 251 void merge( Directory directory ) 252 throws IOException; 253 254 /** 255 * Merges content of given Lucene directory with this context, but filters out the unwanted ones. 256 * 257 * @param directory - the directory to merge 258 */ 259 void merge( Directory directory, DocumentFilter filter ) 260 throws IOException; 261 262 /** 263 * Replaces the Lucene index with the one from supplied directory. 264 * 265 * @param directory 266 * @throws IOException 267 */ 268 void replace( Directory directory ) 269 throws IOException; 270 271 Directory getIndexDirectory(); 272 273 File getIndexDirectoryFile(); 274 275 /** 276 * Returns the GavCalculator for this Context. Implies repository layout. 277 */ 278 GavCalculator getGavCalculator(); 279 280 /** 281 * Sets all group names stored in the current indexing context 282 */ 283 void setAllGroups( Collection<String> groups ) 284 throws IOException; 285 286 /** 287 * Gets all group names stored in the current indexing context 288 */ 289 Set<String> getAllGroups() 290 throws IOException; 291 292 /** 293 * Sets root group names stored in the current indexing context 294 */ 295 void setRootGroups( Collection<String> groups ) 296 throws IOException; 297 298 /** 299 * Gets root group names stored in the current indexing context 300 */ 301 Set<String> getRootGroups() 302 throws IOException; 303 304 /** 305 * Rebuilds stored group names from the index 306 */ 307 void rebuildGroups() 308 throws IOException; 309 310 /** 311 * Returns true if this context is receiving updates from remote via IndexUpdater. 312 * 313 * @return 314 */ 315 boolean isReceivingUpdates(); 316 }