1 | |
package org.apache.maven.index.context; |
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
|
18 | |
|
19 | |
|
20 | |
|
21 | |
|
22 | |
import java.io.File; |
23 | |
import java.io.IOException; |
24 | |
import java.util.ArrayList; |
25 | |
import java.util.Collection; |
26 | |
import java.util.Date; |
27 | |
import java.util.HashSet; |
28 | |
import java.util.List; |
29 | |
import java.util.Set; |
30 | |
|
31 | |
import org.apache.lucene.analysis.Analyzer; |
32 | |
import org.apache.lucene.index.IndexReader; |
33 | |
import org.apache.lucene.index.IndexWriter; |
34 | |
import org.apache.lucene.index.MultiReader; |
35 | |
import org.apache.lucene.search.IndexSearcher; |
36 | |
import org.apache.lucene.store.Directory; |
37 | |
import org.apache.lucene.store.FSDirectory; |
38 | |
import org.apache.maven.index.artifact.GavCalculator; |
39 | |
import org.apache.maven.index.artifact.M2GavCalculator; |
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
47 | |
public class MergedIndexingContext |
48 | |
extends AbstractIndexingContext |
49 | |
{ |
50 | |
private final String id; |
51 | |
|
52 | |
private final String repositoryId; |
53 | |
|
54 | |
private final File repository; |
55 | |
|
56 | |
private final ContextMemberProvider membersProvider; |
57 | |
|
58 | |
private final GavCalculator gavCalculator; |
59 | |
|
60 | |
private final Directory directory; |
61 | |
|
62 | |
private File directoryFile; |
63 | |
|
64 | |
private boolean searchable; |
65 | |
|
66 | |
private MergedIndexingContext( ContextMemberProvider membersProvider, String id, String repositoryId, |
67 | |
File repository, Directory indexDirectory, boolean searchable ) |
68 | |
throws IOException |
69 | 14 | { |
70 | 14 | this.id = id; |
71 | 14 | this.repositoryId = repositoryId; |
72 | 14 | this.repository = repository; |
73 | 14 | this.membersProvider = membersProvider; |
74 | 14 | this.gavCalculator = new M2GavCalculator(); |
75 | 14 | this.directory = indexDirectory; |
76 | 14 | this.searchable = searchable; |
77 | 14 | } |
78 | |
|
79 | |
public MergedIndexingContext( String id, String repositoryId, File repository, File indexDirectoryFile, |
80 | |
boolean searchable, ContextMemberProvider membersProvider ) |
81 | |
throws IOException |
82 | |
{ |
83 | 10 | this( membersProvider, id, repositoryId, repository, FSDirectory.open( indexDirectoryFile ), searchable ); |
84 | |
|
85 | 10 | this.directoryFile = indexDirectoryFile; |
86 | 10 | } |
87 | |
|
88 | |
public MergedIndexingContext( String id, String repositoryId, File repository, Directory indexDirectory, |
89 | |
boolean searchable, ContextMemberProvider membersProvider ) |
90 | |
throws IOException |
91 | |
{ |
92 | 4 | this( membersProvider, id, repositoryId, repository, indexDirectory, searchable ); |
93 | |
|
94 | 4 | if ( indexDirectory instanceof FSDirectory ) |
95 | |
{ |
96 | 0 | this.directoryFile = ( (FSDirectory) indexDirectory ).getFile(); |
97 | |
} |
98 | 4 | } |
99 | |
|
100 | |
public Collection<IndexingContext> getMembers() |
101 | |
{ |
102 | 317204 | return membersProvider.getMembers(); |
103 | |
} |
104 | |
|
105 | |
public String getId() |
106 | |
{ |
107 | 140024 | return id; |
108 | |
} |
109 | |
|
110 | |
public String getRepositoryId() |
111 | |
{ |
112 | 139823 | return repositoryId; |
113 | |
} |
114 | |
|
115 | |
public File getRepository() |
116 | |
{ |
117 | 0 | return repository; |
118 | |
} |
119 | |
|
120 | |
public String getRepositoryUrl() |
121 | |
{ |
122 | 0 | return null; |
123 | |
} |
124 | |
|
125 | |
public String getIndexUpdateUrl() |
126 | |
{ |
127 | 0 | return null; |
128 | |
} |
129 | |
|
130 | |
public boolean isSearchable() |
131 | |
{ |
132 | 2 | return searchable; |
133 | |
} |
134 | |
|
135 | |
public void setSearchable( boolean searchable ) |
136 | |
{ |
137 | 0 | this.searchable = searchable; |
138 | 0 | } |
139 | |
|
140 | |
public Date getTimestamp() |
141 | |
{ |
142 | 660 | Date ts = null; |
143 | |
|
144 | 660 | for ( IndexingContext ctx : getMembers() ) |
145 | |
{ |
146 | 1254 | Date cts = ctx.getTimestamp(); |
147 | |
|
148 | 1254 | if ( cts != null ) |
149 | |
{ |
150 | 1254 | if ( ts == null || cts.after( ts ) ) |
151 | |
{ |
152 | 714 | ts = cts; |
153 | |
} |
154 | |
} |
155 | 1254 | } |
156 | |
|
157 | 660 | return ts; |
158 | |
} |
159 | |
|
160 | |
public void updateTimestamp() |
161 | |
throws IOException |
162 | |
{ |
163 | |
|
164 | 0 | } |
165 | |
|
166 | |
public void updateTimestamp( boolean save ) |
167 | |
throws IOException |
168 | |
{ |
169 | |
|
170 | 0 | } |
171 | |
|
172 | |
public void updateTimestamp( boolean save, Date date ) |
173 | |
throws IOException |
174 | |
{ |
175 | |
|
176 | 0 | } |
177 | |
|
178 | |
public int getSize() |
179 | |
throws IOException |
180 | |
{ |
181 | 0 | int size = 0; |
182 | |
|
183 | 0 | for ( IndexingContext ctx : getMembers() ) |
184 | |
{ |
185 | 0 | size += ctx.getSize(); |
186 | |
} |
187 | |
|
188 | 0 | return size; |
189 | |
} |
190 | |
|
191 | |
public IndexReader getIndexReader() |
192 | |
throws IOException |
193 | |
{ |
194 | 141443 | Collection<IndexingContext> members = getMembers(); |
195 | |
|
196 | 141443 | ArrayList<IndexReader> contextsToSearch = new ArrayList<IndexReader>( members.size() ); |
197 | |
|
198 | 141443 | for ( IndexingContext ctx : members ) |
199 | |
{ |
200 | 282824 | contextsToSearch.add( ctx.getIndexReader() ); |
201 | |
} |
202 | |
|
203 | 141443 | MultiReader multiReader = |
204 | |
new MultiReader( contextsToSearch.toArray( new IndexReader[contextsToSearch.size()] ) ); |
205 | |
|
206 | 141443 | return multiReader; |
207 | |
} |
208 | |
|
209 | |
public IndexSearcher getIndexSearcher() |
210 | |
throws IOException |
211 | |
{ |
212 | 141086 | return new NexusIndexSearcher( getIndexReader() ); |
213 | |
} |
214 | |
|
215 | |
public IndexWriter getIndexWriter() |
216 | |
throws IOException |
217 | |
{ |
218 | |
|
219 | 0 | return null; |
220 | |
|
221 | |
} |
222 | |
|
223 | |
public List<IndexCreator> getIndexCreators() |
224 | |
{ |
225 | 172053 | HashSet<IndexCreator> creators = new HashSet<IndexCreator>(); |
226 | |
|
227 | 172053 | for ( IndexingContext ctx : getMembers() ) |
228 | |
{ |
229 | 343987 | creators.addAll( ctx.getIndexCreators() ); |
230 | |
} |
231 | |
|
232 | 172053 | return new ArrayList<IndexCreator>( creators ); |
233 | |
} |
234 | |
|
235 | |
public Analyzer getAnalyzer() |
236 | |
{ |
237 | 0 | return new NexusAnalyzer(); |
238 | |
} |
239 | |
|
240 | |
public void commit() |
241 | |
throws IOException |
242 | |
{ |
243 | |
|
244 | 2 | } |
245 | |
|
246 | |
public void rollback() |
247 | |
throws IOException |
248 | |
{ |
249 | |
|
250 | 0 | } |
251 | |
|
252 | |
public void optimize() |
253 | |
throws IOException |
254 | |
{ |
255 | |
|
256 | 0 | } |
257 | |
|
258 | |
public void lock() |
259 | |
{ |
260 | 1521 | for ( IndexingContext ctx : getMembers() ) |
261 | |
{ |
262 | 3022 | ctx.lock(); |
263 | |
} |
264 | 1521 | } |
265 | |
|
266 | |
public void unlock() |
267 | |
{ |
268 | 1521 | for ( IndexingContext ctx : getMembers() ) |
269 | |
{ |
270 | 3022 | ctx.unlock(); |
271 | |
} |
272 | 1521 | } |
273 | |
|
274 | |
public void close( boolean deleteFiles ) |
275 | |
throws IOException |
276 | |
{ |
277 | |
|
278 | 13 | } |
279 | |
|
280 | |
public void purge() |
281 | |
throws IOException |
282 | |
{ |
283 | |
|
284 | 0 | } |
285 | |
|
286 | |
public void merge( Directory directory ) |
287 | |
throws IOException |
288 | |
{ |
289 | |
|
290 | 0 | } |
291 | |
|
292 | |
public void merge( Directory directory, DocumentFilter filter ) |
293 | |
throws IOException |
294 | |
{ |
295 | |
|
296 | 0 | } |
297 | |
|
298 | |
public void replace( Directory directory ) |
299 | |
throws IOException |
300 | |
{ |
301 | |
|
302 | 0 | } |
303 | |
|
304 | |
public Directory getIndexDirectory() |
305 | |
{ |
306 | 161 | return directory; |
307 | |
} |
308 | |
|
309 | |
public File getIndexDirectoryFile() |
310 | |
{ |
311 | 327 | return directoryFile; |
312 | |
} |
313 | |
|
314 | |
public GavCalculator getGavCalculator() |
315 | |
{ |
316 | 0 | return gavCalculator; |
317 | |
} |
318 | |
|
319 | |
public void setAllGroups( Collection<String> groups ) |
320 | |
throws IOException |
321 | |
{ |
322 | |
|
323 | 0 | } |
324 | |
|
325 | |
public Set<String> getAllGroups() |
326 | |
throws IOException |
327 | |
{ |
328 | 0 | HashSet<String> result = new HashSet<String>(); |
329 | |
|
330 | 0 | for ( IndexingContext ctx : getMembers() ) |
331 | |
{ |
332 | 0 | result.addAll( ctx.getAllGroups() ); |
333 | |
} |
334 | |
|
335 | 0 | return result; |
336 | |
} |
337 | |
|
338 | |
public void setRootGroups( Collection<String> groups ) |
339 | |
throws IOException |
340 | |
{ |
341 | |
|
342 | 0 | } |
343 | |
|
344 | |
public Set<String> getRootGroups() |
345 | |
throws IOException |
346 | |
{ |
347 | 1 | HashSet<String> result = new HashSet<String>(); |
348 | |
|
349 | 1 | for ( IndexingContext ctx : getMembers() ) |
350 | |
{ |
351 | 4 | result.addAll( ctx.getRootGroups() ); |
352 | |
} |
353 | |
|
354 | 1 | return result; |
355 | |
} |
356 | |
|
357 | |
public void rebuildGroups() |
358 | |
throws IOException |
359 | |
{ |
360 | |
|
361 | 0 | } |
362 | |
|
363 | |
} |