import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
-import org.codehaus.plexus.logging.AbstractLogEnabled;
+import org.apache.maven.artifact.repository.ArtifactRepository;
import java.io.File;
import java.io.IOException;
* @author Edwin Punzalan
*/
public abstract class AbstractRepositoryIndex
- extends AbstractLogEnabled
implements RepositoryIndex
{
private String indexPath;
-
+
private boolean indexOpen;
private IndexReader indexReader;
private IndexWriter indexWriter;
+ protected ArtifactRepository repository;
+
/**
* method to encapsulate the optimize() method for lucene
*/
/**
* method for opening the index directory for indexing operations
*/
- public void open( String indexPath )
+ protected void open( String indexPath )
throws RepositoryIndexException
{
try
}
else
{
- getLogger().info( "Skipping index field validations for empty index." );
+ //getLogger().info( "Skipping index field validations for empty index." );
}
}
else if ( !indexDir.exists() )
{
indexWriter = new IndexWriter( indexPath, getAnalyzer(), true );
- getLogger().info( "New index directory created in: " + indexDir.getAbsolutePath() );
+ //getLogger().info( "New index directory created in: " + indexDir.getAbsolutePath() );
}
else if ( indexDir.isDirectory() )
{
import java.util.zip.ZipEntry;
import java.util.zip.ZipException;
import java.util.zip.ZipFile;
+import org.apache.maven.artifact.repository.ArtifactRepository;
/**
* Class used to index Artifact objects in a specified repository
*
* @author Edwin Punzalan
- * @plexus.component role="org.apache.maven.repository.indexing.RepositoryIndex" role-hint="artifact" instantiation-strategy="per-lookup"
* @todo I think we should merge with Abstract*. Don't see that there'd be multiple implementations based on this
* @todo I think we should instantiate this based on a repository from a factory instead of making it a component of its own
*/
private Analyzer analyzer;
- /** @plexus.requirement */
private Digester digester;
+ public ArtifactRepositoryIndex( String indexPath, ArtifactRepository repository, Digester digester )
+ throws RepositoryIndexException
+ {
+ this.repository = repository;
+ this.digester = digester;
+
+ open( indexPath );
+ }
+
/**
* method to get the Analyzer used to create indices
*
artifactList.add( artifact );
}
+
+ searcher.close();
}
catch ( IOException e )
{
--- /dev/null
+package org.apache.maven.repository.indexing;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.repository.digest.Digester;
+
+/**
+ *
+ * @author Edwin Punzalan
+ * @plexus.component role="org.apache.maven.repository.indexing.RepositoryIndexingFactory"
+ */
+public class DefaultRepositoryIndexingFactory
+ implements RepositoryIndexingFactory
+{
+ /** @plexus.requirement */
+ private Digester digester;
+
+ public ArtifactRepositoryIndexSearcher createArtifactRepositoryIndexSearcher(ArtifactRepositoryIndex index)
+ {
+ return null;
+ }
+
+ public ArtifactRepositoryIndex createArtifactRepositoryIndex( String indexPath, ArtifactRepository repository )
+ throws RepositoryIndexException
+ {
+ return new ArtifactRepositoryIndex( indexPath, repository, digester );
+ }
+}
void close()
throws RepositoryIndexException;
- void open( String indexPath )
+/* void open( String indexPath )
throws RepositoryIndexException;
-
+*/
void optimize()
throws RepositoryIndexException;
* @param index
* @param queryString
* @param searchField
-
- List search( RepositoryIndex index, String queryString, String searchField )
- throws RepositoryIndexSearchException;
- */
-
- /**
- *
*/
- void addQuery( String queryField, String queryText );
-
- /**
- *
- */
- void addQuery( String queryField, String queryText, boolean required );
-
- /**
- *
- */
- List search( RepositoryIndex index )
+ List search( RepositoryIndex index, String queryString, String searchField )
throws RepositoryIndexSearchException;
}
--- /dev/null
+package org.apache.maven.repository.indexing;
+
+/*
+ * Copyright 2001-2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.repository.digest.Digester;
+
+/**
+ *
+ * @author Edwin Punzalan
+ */
+public interface RepositoryIndexingFactory
+{
+ String ROLE = RepositoryIndexingFactory.class.getName();
+
+ ArtifactRepositoryIndexSearcher createArtifactRepositoryIndexSearcher( ArtifactRepositoryIndex index );
+ ArtifactRepositoryIndex createArtifactRepositoryIndex( String indexPath, ArtifactRepository repository )
+ throws RepositoryIndexException;
+}
repository = repoFactory.createArtifactRepository( "test", repoDir, layout, null, null );
indexPath = "target/index";
-
- FileUtils.deleteDirectory( indexPath );
}
public void testIndexerExceptions()
throws Exception
{
ArtifactRepositoryIndex indexer;
+ RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
+
try
{
String notIndexDir = new File( "pom.xml" ).getAbsolutePath();
- indexer = (ArtifactRepositoryIndex) lookup( RepositoryIndex.ROLE, "artifact" );
- indexer.open( notIndexDir );
+ indexer = factory.createArtifactRepositoryIndex( notIndexDir, repository );
fail( "Must throw exception on non-directory index directory" );
}
catch ( RepositoryIndexException e )
try
{
String notIndexDir = new File( "" ).getAbsolutePath();
- indexer = (ArtifactRepositoryIndex) lookup( RepositoryIndex.ROLE, "artifact" );
- indexer.open( notIndexDir );
+ indexer = factory.createArtifactRepositoryIndex( notIndexDir, repository );
fail( "Must throw an exception on a non-index directory" );
}
catch ( RepositoryIndexException e )
//expected
}
- //indexer = (ArtifactRepositoryIndex) factory.getArtifactRepositoryIndexer( indexPath, repository );
- //indexer.close();
- indexer = (ArtifactRepositoryIndex) lookup( RepositoryIndex.ROLE, "artifact" );
Artifact artifact = getArtifact( "test", "test-artifactId", "1.0" );
artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
+ indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
+ indexer.close();
+
try
{
indexer.indexArtifact( artifact );
//expected
}
- indexer.open( indexPath );
+ indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
try
{
indexer.close();
}
- public void testIndex()
+ public void createTestIndex()
throws Exception
{
- //indexer = (ArtifactRepositoryIndex) factory.getArtifactRepositoryIndexer( indexPath, repository );
- ArtifactRepositoryIndex indexer = (ArtifactRepositoryIndex) lookup( RepositoryIndex.ROLE, "artifact" );
- indexer.open( indexPath );
+ RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
+ ArtifactRepositoryIndex indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
Artifact artifact = getArtifact( "org.apache.maven", "maven-artifact", "2.0.1" );
artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
indexer.indexArtifact( artifact );
- indexer.optimize();
- indexer.close();
-
- indexer.open( indexPath );
artifact = getArtifact( "test", "test-artifactId", "1.0" );
artifact.setFile( new File( repository.getBasedir(), repository.pathOf( artifact ) ) );
indexer.index( artifact );
- indexer.close();
- // TODO: assert something!
+ indexer.optimize();
+ indexer.close();
}
public void testSearch()
throws Exception
{
- ArtifactRepositoryIndex indexer = (ArtifactRepositoryIndex) lookup( RepositoryIndex.ROLE, "artifact" );
- indexer.open( getTestPath( "src/test/index" ) );
+ createTestIndex();
+
+ RepositoryIndexingFactory factory = (RepositoryIndexingFactory) lookup( RepositoryIndexingFactory.ROLE );
+ ArtifactRepositoryIndex indexer = indexer = factory.createArtifactRepositoryIndex( indexPath, repository );
RepositoryIndexSearcher repoSearcher =
(RepositoryIndexSearcher) lookup( RepositoryIndexSearcher.ROLE, "artifact" );
artifacts = repoSearcher.search( indexer, "2", VERSION );
assertEquals( 2, artifacts.size() );
+
+ indexer.close();
}
private Artifact getArtifact( String groupId, String artifactId, String version )
return artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" );
}
+
+ protected void tearDown()
+ throws Exception
+ {
+ repository = null;
+ FileUtils.deleteDirectory( indexPath );
+
+ super.tearDown();
+ }
}