From 58d71d96ef937be0690dd306270b161b4bfd7b15 Mon Sep 17 00:00:00 2001 From: "Edwin L. Punzalan" Date: Thu, 22 Dec 2005 06:37:47 +0000 Subject: [PATCH] Refactored classes and added some more interface methods git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@358512 13f79535-47bb-0310-9956-ffa450edef68 --- .../indexing/AbstractRepositoryIndexer.java | 94 +++++++++++++++++++ .../indexing/ArtifactRepositoryIndexer.java | 82 ++++++++-------- .../indexing/RepositoryIndexer.java | 10 ++ 3 files changed, 147 insertions(+), 39 deletions(-) diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java index 291d6d82b..428f6d41e 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java @@ -18,6 +18,7 @@ package org.apache.maven.repository.indexing; */ import java.io.IOException; +import java.util.Collection; import org.apache.lucene.analysis.Analyzer; import org.apache.lucene.analysis.standard.StandardAnalyzer; @@ -32,8 +33,77 @@ public abstract class AbstractRepositoryIndexer implements RepositoryIndexer { protected String indexPath; + protected boolean indexOpen; protected IndexReader indexReader; protected IndexWriter indexWriter; + + public void optimize() + throws RepositoryIndexerException + { + if ( !isOpen() ) + { + throw new RepositoryIndexerException( "Unable to optimize index on a closed index" ); + } + + try + { + indexWriter.optimize(); + } + catch ( IOException ioe ) + { + throw new RepositoryIndexerException( "Failed to optimize index", ioe ); + } + } + + public boolean isOpen() + { + return indexOpen; + } + + public void close() + throws RepositoryIndexerException + { + if ( indexOpen ) + { + try + { + if ( indexWriter != null ) + { + indexWriter.close(); + indexWriter = null; + } + + if ( indexReader != null ) + { + indexReader.close(); + indexReader = null; + } + + indexOpen = false; + } + catch ( Exception e ) + { + throw new RepositoryIndexerException( e ); + } + } + } + + public void open() + throws RepositoryIndexerException + { + try + { + if ( !indexOpen ) + { + validateIndex(); + } + } + catch ( Exception e ) + { + throw new RepositoryIndexerException( e ); + } + } + protected void getIndexWriter() throws IOException @@ -57,4 +127,28 @@ public abstract class AbstractRepositoryIndexer { return new StandardAnalyzer(); } + + protected void validateIndex() + throws RepositoryIndexerException + { + try + { + getIndexReader(); + Collection fields = indexReader.getFieldNames(); + String[] indexFields = getIndexFields(); + for( int idx=0; idx