Package org.apache.maven.index.context
Class DefaultIndexingContext
- java.lang.Object
-
- org.apache.maven.index.context.AbstractIndexingContext
-
- org.apache.maven.index.context.DefaultIndexingContext
-
- All Implemented Interfaces:
IndexingContext
public class DefaultIndexingContext extends AbstractIndexingContext
The defaultIndexingContextimplementation.
-
-
Field Summary
Fields Modifier and Type Field Description private static org.apache.lucene.index.TermDESCRIPTOR_TERMstatic java.lang.StringFLD_DESCRIPTORstatic java.lang.StringFLD_DESCRIPTOR_CONTENTSstatic java.lang.StringFLD_IDXINFOprivate GavCalculatorgavCalculatorCurrently nexus-indexer knows only M2 reposesprivate java.lang.Stringidprivate static java.lang.StringINDEX_DIRECTORYA standard location for indices served up by a webserver.private java.util.List<? extends IndexCreator>indexCreatorsprivate org.apache.lucene.store.DirectoryindexDirectoryprivate java.io.FileindexDirectoryFileprivate java.lang.StringindexUpdateUrlprivate NexusIndexWriterindexWriterprivate TrackingLockFactorylockFactoryprivate java.io.Filerepositoryprivate java.lang.StringrepositoryIdprivate java.lang.StringrepositoryUrlprivate booleansearchableprivate org.apache.lucene.search.SearcherManagersearcherManagerprivate java.util.Datetimestampstatic java.lang.StringVERSION-
Fields inherited from interface org.apache.maven.index.context.IndexingContext
INDEX_CHAIN_ID, INDEX_CHUNK_COUNTER, INDEX_CHUNK_PREFIX, INDEX_FILE_PREFIX, INDEX_ID, INDEX_LEGACY_TIMESTAMP, INDEX_PACKER_PROPERTIES_FILE, INDEX_PROPERTY_PREFIX, INDEX_REMOTE_PROPERTIES_FILE, INDEX_TIME_DAY_FORMAT, INDEX_TIME_FORMAT, INDEX_TIMESTAMP, INDEX_UPDATER_PROPERTIES_FILE
-
-
Constructor Summary
Constructors Modifier Constructor Description DefaultIndexingContext(java.lang.String id, java.lang.String repositoryId, java.io.File repository, java.io.File indexDirectoryFile, java.lang.String repositoryUrl, java.lang.String indexUpdateUrl, java.util.List<? extends IndexCreator> indexCreators, boolean reclaimIndex)privateDefaultIndexingContext(java.lang.String id, java.lang.String repositoryId, java.io.File repository, java.io.File indexDirectoryFile, TrackingLockFactory lockFactory, java.lang.String repositoryUrl, java.lang.String indexUpdateUrl, java.util.List<? extends IndexCreator> indexCreators, boolean reclaimIndex)privateDefaultIndexingContext(java.lang.String id, java.lang.String repositoryId, java.io.File repository, java.lang.String repositoryUrl, java.lang.String indexUpdateUrl, java.util.List<? extends IndexCreator> indexCreators, org.apache.lucene.store.Directory indexDirectory, TrackingLockFactory lockFactory, boolean reclaimIndex)DefaultIndexingContext(java.lang.String id, java.lang.String repositoryId, java.io.File repository, org.apache.lucene.store.Directory indexDirectory, java.lang.String repositoryUrl, java.lang.String indexUpdateUrl, java.util.List<? extends IndexCreator> indexCreators, boolean reclaimIndex)Deprecated.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description org.apache.lucene.search.IndexSearcheracquireIndexSearcher()Acquires a fresh instance ofIndexSearcher.private voidcheckAndUpdateIndexDescriptor(boolean reclaimIndex)voidclose(boolean deleteFiles)Shuts down this context.private voidcloseReaders()voidcommit()Commits changes to context, eventually refreshing readers/searchers too.protected org.apache.lucene.document.DocumentcreateGroupsDocument(java.util.Collection<java.lang.String> groups, java.lang.String field, java.lang.String fieldValue, java.lang.String listField)private voiddeleteIndexFiles(boolean full)java.util.Set<java.lang.String>getAllGroups()Gets all group names stored in the current indexing contextorg.apache.lucene.analysis.AnalyzergetAnalyzer()Returns the Lucene Analyzer of this context used for by IndexWriter and IndexSearcher.GavCalculatorgetGavCalculator()Returns the GavCalculator for this Context.protected java.util.Set<java.lang.String>getGroups(java.lang.String field, java.lang.String filedValue, java.lang.String listField)java.lang.StringgetId()Returns this indexing context id.java.util.List<IndexCreator>getIndexCreators()List of IndexCreators used in this context.org.apache.lucene.store.DirectorygetIndexDirectory()java.io.FilegetIndexDirectoryFile()java.lang.StringgetIndexUpdateUrl()Returns url for the index updateorg.apache.lucene.index.IndexWritergetIndexWriter()Returns the Lucene IndexWriter (thread safe, shared instance) of this context.java.io.FilegetRepository()Returns location for the local repository.java.lang.StringgetRepositoryId()Returns repository id.java.lang.StringgetRepositoryUrl()Returns public repository url.java.util.Set<java.lang.String>getRootGroups()Gets root group names stored in the current indexing contextintgetSize()Returns a number that represents the "size" useful for doing comparisons between contexts (which one has more data indexed?).java.util.DategetTimestamp()Returns index update timeprotected org.apache.lucene.index.IndexWriterConfiggetWriterConfig()Returns new IndexWriterConfig instancebooleanisSearchable()Is the context searchable when doing "non-targeted" searches? Ie.voidmerge(org.apache.lucene.store.Directory directory)Merges content of given Lucene directory with this context.voidmerge(org.apache.lucene.store.Directory directory, DocumentFilter filter)Merges content of given Lucene directory with this context, but filters out the unwanted ones.protected voidopenAndWarmup()voidoptimize()Optimizes index.private voidprepareCleanIndex(boolean deleteExisting)private voidprepareIndex(boolean reclaimIndex)voidpurge()Purge (cleans) the context, deletes/empties the index and restores the context to new/empty state.voidrebuildGroups()Rebuilds stored group names from the indexvoidreleaseIndexSearcher(org.apache.lucene.search.IndexSearcher is)Releases theIndexSearcherinstance.voidreplace(org.apache.lucene.store.Directory directory)Replaces the Lucene index with the one from supplied directory.voidreplace(org.apache.lucene.store.Directory directory, java.util.Set<java.lang.String> allGroups, java.util.Set<java.lang.String> rootGroups)voidrollback()Rolls back changes to context, eventually refreshing readers/searchers too.voidsetAllGroups(java.util.Collection<java.lang.String> groups)Sets all group names stored in the current indexing contextprotected voidsetGroups(java.util.Collection<java.lang.String> groups, java.lang.String groupField, java.lang.String groupFieldValue, java.lang.String groupListField)protected voidsetIndexDirectoryFile(java.io.File dir)Sets index location.voidsetRootGroups(java.util.Collection<java.lang.String> groups)Sets root group names stored in the current indexing contextvoidsetSearchable(boolean searchable)Sets is the context searchable when doing "non-targeted" searches.private voidstoreDescriptor()java.lang.StringtoString()private static voidunlockForcibly(TrackingLockFactory lockFactory, org.apache.lucene.store.Directory dir)voidupdateTimestamp()voidupdateTimestamp(boolean save)voidupdateTimestamp(boolean save, java.util.Date timestamp)-
Methods inherited from class org.apache.maven.index.context.AbstractIndexingContext
isReceivingUpdates
-
-
-
-
Field Detail
-
INDEX_DIRECTORY
private static final java.lang.String INDEX_DIRECTORY
A standard location for indices served up by a webserver.- See Also:
- Constant Field Values
-
FLD_DESCRIPTOR
public static final java.lang.String FLD_DESCRIPTOR
- See Also:
- Constant Field Values
-
FLD_DESCRIPTOR_CONTENTS
public static final java.lang.String FLD_DESCRIPTOR_CONTENTS
- See Also:
- Constant Field Values
-
FLD_IDXINFO
public static final java.lang.String FLD_IDXINFO
- See Also:
- Constant Field Values
-
VERSION
public static final java.lang.String VERSION
- See Also:
- Constant Field Values
-
DESCRIPTOR_TERM
private static final org.apache.lucene.index.Term DESCRIPTOR_TERM
-
indexDirectory
private org.apache.lucene.store.Directory indexDirectory
-
lockFactory
private TrackingLockFactory lockFactory
-
indexDirectoryFile
private java.io.File indexDirectoryFile
-
id
private java.lang.String id
-
searchable
private boolean searchable
-
repositoryId
private java.lang.String repositoryId
-
repository
private java.io.File repository
-
repositoryUrl
private java.lang.String repositoryUrl
-
indexUpdateUrl
private java.lang.String indexUpdateUrl
-
indexWriter
private NexusIndexWriter indexWriter
-
searcherManager
private org.apache.lucene.search.SearcherManager searcherManager
-
timestamp
private java.util.Date timestamp
-
indexCreators
private java.util.List<? extends IndexCreator> indexCreators
-
gavCalculator
private GavCalculator gavCalculator
Currently nexus-indexer knows only M2 reposesXXX move this into a concrete Scanner implementation
-
-
Constructor Detail
-
DefaultIndexingContext
private DefaultIndexingContext(java.lang.String id, java.lang.String repositoryId, java.io.File repository, java.lang.String repositoryUrl, java.lang.String indexUpdateUrl, java.util.List<? extends IndexCreator> indexCreators, org.apache.lucene.store.Directory indexDirectory, TrackingLockFactory lockFactory, boolean reclaimIndex) throws ExistingLuceneIndexMismatchException, java.io.IOException- Throws:
ExistingLuceneIndexMismatchExceptionjava.io.IOException
-
DefaultIndexingContext
private DefaultIndexingContext(java.lang.String id, java.lang.String repositoryId, java.io.File repository, java.io.File indexDirectoryFile, TrackingLockFactory lockFactory, java.lang.String repositoryUrl, java.lang.String indexUpdateUrl, java.util.List<? extends IndexCreator> indexCreators, boolean reclaimIndex) throws java.io.IOException, ExistingLuceneIndexMismatchException- Throws:
java.io.IOExceptionExistingLuceneIndexMismatchException
-
DefaultIndexingContext
public DefaultIndexingContext(java.lang.String id, java.lang.String repositoryId, java.io.File repository, java.io.File indexDirectoryFile, java.lang.String repositoryUrl, java.lang.String indexUpdateUrl, java.util.List<? extends IndexCreator> indexCreators, boolean reclaimIndex) throws java.io.IOException, ExistingLuceneIndexMismatchException- Throws:
java.io.IOExceptionExistingLuceneIndexMismatchException
-
DefaultIndexingContext
@Deprecated public DefaultIndexingContext(java.lang.String id, java.lang.String repositoryId, java.io.File repository, org.apache.lucene.store.Directory indexDirectory, java.lang.String repositoryUrl, java.lang.String indexUpdateUrl, java.util.List<? extends IndexCreator> indexCreators, boolean reclaimIndex) throws java.io.IOException, ExistingLuceneIndexMismatchExceptionDeprecated.- Throws:
java.io.IOExceptionExistingLuceneIndexMismatchException
-
-
Method Detail
-
getIndexDirectory
public org.apache.lucene.store.Directory getIndexDirectory()
-
setIndexDirectoryFile
protected void setIndexDirectoryFile(java.io.File dir) throws java.io.IOExceptionSets index location. As usually index is persistent (is on disk), this will point to that value, but in some circumstances (ie, using RAMDisk for index), this will point to an existing tmp directory.- Throws:
java.io.IOException
-
getIndexDirectoryFile
public java.io.File getIndexDirectoryFile()
-
prepareIndex
private void prepareIndex(boolean reclaimIndex) throws java.io.IOException, ExistingLuceneIndexMismatchException- Throws:
java.io.IOExceptionExistingLuceneIndexMismatchException
-
prepareCleanIndex
private void prepareCleanIndex(boolean deleteExisting) throws java.io.IOException- Throws:
java.io.IOException
-
checkAndUpdateIndexDescriptor
private void checkAndUpdateIndexDescriptor(boolean reclaimIndex) throws java.io.IOException, ExistingLuceneIndexMismatchException- Throws:
java.io.IOExceptionExistingLuceneIndexMismatchException
-
storeDescriptor
private void storeDescriptor() throws java.io.IOException- Throws:
java.io.IOException
-
deleteIndexFiles
private void deleteIndexFiles(boolean full) throws java.io.IOException- Throws:
java.io.IOException
-
isSearchable
public boolean isSearchable()
Description copied from interface:IndexingContextIs the context searchable when doing "non-targeted" searches? Ie. Should it take a part when searching without specifying context?- Returns:
-
setSearchable
public void setSearchable(boolean searchable)
Description copied from interface:IndexingContextSets is the context searchable when doing "non-targeted" searches.
-
getId
public java.lang.String getId()
Description copied from interface:IndexingContextReturns this indexing context id.
-
updateTimestamp
public void updateTimestamp() throws java.io.IOException- Throws:
java.io.IOException
-
updateTimestamp
public void updateTimestamp(boolean save) throws java.io.IOException- Throws:
java.io.IOException
-
updateTimestamp
public void updateTimestamp(boolean save, java.util.Date timestamp) throws java.io.IOException- Throws:
java.io.IOException
-
getTimestamp
public java.util.Date getTimestamp()
Description copied from interface:IndexingContextReturns index update time
-
getSize
public int getSize() throws java.io.IOExceptionDescription copied from interface:IndexingContextReturns a number that represents the "size" useful for doing comparisons between contexts (which one has more data indexed?). The number return does not represent the count of ArtifactInfos, neither other "meaningful" info, it is purely to be used for inter-context comparisons only!- Returns:
- Throws:
java.io.IOException
-
getRepositoryId
public java.lang.String getRepositoryId()
Description copied from interface:IndexingContextReturns repository id.
-
getRepository
public java.io.File getRepository()
Description copied from interface:IndexingContextReturns location for the local repository.
-
getRepositoryUrl
public java.lang.String getRepositoryUrl()
Description copied from interface:IndexingContextReturns public repository url.
-
getIndexUpdateUrl
public java.lang.String getIndexUpdateUrl()
Description copied from interface:IndexingContextReturns url for the index update
-
getAnalyzer
public org.apache.lucene.analysis.Analyzer getAnalyzer()
Description copied from interface:IndexingContextReturns the Lucene Analyzer of this context used for by IndexWriter and IndexSearcher. Note: this method always creates a new instance of analyzer!- Returns:
-
openAndWarmup
protected void openAndWarmup() throws java.io.IOException- Throws:
java.io.IOException
-
getWriterConfig
protected org.apache.lucene.index.IndexWriterConfig getWriterConfig()
Returns new IndexWriterConfig instance- Since:
- 5.1
-
getIndexWriter
public org.apache.lucene.index.IndexWriter getIndexWriter() throws java.io.IOExceptionDescription copied from interface:IndexingContextReturns the Lucene IndexWriter (thread safe, shared instance) of this context.- Returns:
- indexWriter
- Throws:
java.io.IOException
-
acquireIndexSearcher
public org.apache.lucene.search.IndexSearcher acquireIndexSearcher() throws java.io.IOExceptionDescription copied from interface:IndexingContextAcquires a fresh instance ofIndexSearcher. You have to release the received instance withIndexingContext.releaseIndexSearcher(IndexSearcher)otherwise you are about to introduce leak.- Returns:
- Throws:
java.io.IOException
-
releaseIndexSearcher
public void releaseIndexSearcher(org.apache.lucene.search.IndexSearcher is) throws java.io.IOExceptionDescription copied from interface:IndexingContextReleases theIndexSearcherinstance.- Throws:
java.io.IOException
-
commit
public void commit() throws java.io.IOExceptionDescription copied from interface:IndexingContextCommits changes to context, eventually refreshing readers/searchers too.- Throws:
java.io.IOException
-
rollback
public void rollback() throws java.io.IOExceptionDescription copied from interface:IndexingContextRolls back changes to context, eventually refreshing readers/searchers too.- Throws:
java.io.IOException
-
optimize
public void optimize() throws org.apache.lucene.index.CorruptIndexException, java.io.IOExceptionDescription copied from interface:IndexingContextOptimizes index. According to Lucene 3.6+ Javadoc, there is no more sense to optimize, so this method might become "noop".- Throws:
org.apache.lucene.index.CorruptIndexExceptionjava.io.IOException
-
close
public void close(boolean deleteFiles) throws java.io.IOExceptionDescription copied from interface:IndexingContextShuts down this context.- Throws:
java.io.IOException
-
purge
public void purge() throws java.io.IOExceptionDescription copied from interface:IndexingContextPurge (cleans) the context, deletes/empties the index and restores the context to new/empty state.- Throws:
java.io.IOException
-
replace
public void replace(org.apache.lucene.store.Directory directory) throws java.io.IOExceptionDescription copied from interface:IndexingContextReplaces the Lucene index with the one from supplied directory.- Throws:
java.io.IOException
-
replace
public void replace(org.apache.lucene.store.Directory directory, java.util.Set<java.lang.String> allGroups, java.util.Set<java.lang.String> rootGroups) throws java.io.IOException- Throws:
java.io.IOException
-
merge
public void merge(org.apache.lucene.store.Directory directory) throws java.io.IOExceptionDescription copied from interface:IndexingContextMerges content of given Lucene directory with this context.- Parameters:
directory- - the directory to merge- Throws:
java.io.IOException
-
merge
public void merge(org.apache.lucene.store.Directory directory, DocumentFilter filter) throws java.io.IOExceptionDescription copied from interface:IndexingContextMerges content of given Lucene directory with this context, but filters out the unwanted ones.- Parameters:
directory- - the directory to merge- Throws:
java.io.IOException
-
closeReaders
private void closeReaders() throws org.apache.lucene.index.CorruptIndexException, java.io.IOException- Throws:
org.apache.lucene.index.CorruptIndexExceptionjava.io.IOException
-
getGavCalculator
public GavCalculator getGavCalculator()
Description copied from interface:IndexingContextReturns the GavCalculator for this Context. Implies repository layout.
-
getIndexCreators
public java.util.List<IndexCreator> getIndexCreators()
Description copied from interface:IndexingContextList of IndexCreators used in this context.- Returns:
- list of index creators.
-
rebuildGroups
public void rebuildGroups() throws java.io.IOExceptionDescription copied from interface:IndexingContextRebuilds stored group names from the index- Throws:
java.io.IOException
-
getAllGroups
public java.util.Set<java.lang.String> getAllGroups() throws java.io.IOExceptionDescription copied from interface:IndexingContextGets all group names stored in the current indexing context- Throws:
java.io.IOException
-
setAllGroups
public void setAllGroups(java.util.Collection<java.lang.String> groups) throws java.io.IOExceptionDescription copied from interface:IndexingContextSets all group names stored in the current indexing context- Throws:
java.io.IOException
-
getRootGroups
public java.util.Set<java.lang.String> getRootGroups() throws java.io.IOExceptionDescription copied from interface:IndexingContextGets root group names stored in the current indexing context- Throws:
java.io.IOException
-
setRootGroups
public void setRootGroups(java.util.Collection<java.lang.String> groups) throws java.io.IOExceptionDescription copied from interface:IndexingContextSets root group names stored in the current indexing context- Throws:
java.io.IOException
-
getGroups
protected java.util.Set<java.lang.String> getGroups(java.lang.String field, java.lang.String filedValue, java.lang.String listField) throws java.io.IOException, org.apache.lucene.index.CorruptIndexException- Throws:
java.io.IOExceptionorg.apache.lucene.index.CorruptIndexException
-
setGroups
protected void setGroups(java.util.Collection<java.lang.String> groups, java.lang.String groupField, java.lang.String groupFieldValue, java.lang.String groupListField) throws java.io.IOException, org.apache.lucene.index.CorruptIndexException- Throws:
java.io.IOExceptionorg.apache.lucene.index.CorruptIndexException
-
createGroupsDocument
protected org.apache.lucene.document.Document createGroupsDocument(java.util.Collection<java.lang.String> groups, java.lang.String field, java.lang.String fieldValue, java.lang.String listField)
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
unlockForcibly
private static void unlockForcibly(TrackingLockFactory lockFactory, org.apache.lucene.store.Directory dir) throws java.io.IOException
- Throws:
java.io.IOException
-
-