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