From: Edwin L. Punzalan Date: Tue, 3 Jan 2006 09:34:00 +0000 (+0000) Subject: Added factory for ArtifactRepositoryIndex X-Git-Tag: archiva-0.9-alpha-1~1011 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=c4a2df22e536921da5d60d0b7b429e95171a875e;p=archiva.git Added factory for ArtifactRepositoryIndex Removed usage of src/test/index createTestIndex (renamed from testIndex() which gave the wrong impression) will create the index needed git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@365590 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java index 2815183a0..12a3c7ef6 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java @@ -18,7 +18,7 @@ package org.apache.maven.repository.indexing; 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; @@ -30,17 +30,18 @@ import java.util.Collection; * @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 */ @@ -103,7 +104,7 @@ public abstract class AbstractRepositoryIndex /** * method for opening the index directory for indexing operations */ - public void open( String indexPath ) + protected void open( String indexPath ) throws RepositoryIndexException { try @@ -169,13 +170,13 @@ public abstract class AbstractRepositoryIndex } 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() ) { diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java index a75d58367..115c989ef 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java @@ -30,13 +30,13 @@ import java.util.Enumeration; 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 */ @@ -65,9 +65,17 @@ public class ArtifactRepositoryIndex 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 * diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java index 91acdc9c9..e24548619 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java @@ -84,6 +84,8 @@ public class ArtifactRepositoryIndexSearcher artifactList.add( artifact ); } + + searcher.close(); } catch ( IOException e ) { diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java new file mode 100644 index 000000000..92fa7a82f --- /dev/null +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexingFactory.java @@ -0,0 +1,44 @@ +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 ); + } +} diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java index 29b8bc514..f8cac4d63 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java @@ -35,9 +35,9 @@ public interface RepositoryIndex void close() throws RepositoryIndexException; - void open( String indexPath ) +/* void open( String indexPath ) throws RepositoryIndexException; - +*/ void optimize() throws RepositoryIndexException; diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java index e999a0c37..ac592818d 100644 --- a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java @@ -32,24 +32,7 @@ public interface RepositoryIndexSearcher * @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; } diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java new file mode 100644 index 000000000..5601ec968 --- /dev/null +++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexingFactory.java @@ -0,0 +1,34 @@ +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; +} diff --git a/maven-repository-indexer/src/test/index/_2.cfs b/maven-repository-indexer/src/test/index/_2.cfs deleted file mode 100644 index f772f8ed6..000000000 Binary files a/maven-repository-indexer/src/test/index/_2.cfs and /dev/null differ diff --git a/maven-repository-indexer/src/test/index/_4.cfs b/maven-repository-indexer/src/test/index/_4.cfs deleted file mode 100644 index 348d8de92..000000000 Binary files a/maven-repository-indexer/src/test/index/_4.cfs and /dev/null differ diff --git a/maven-repository-indexer/src/test/index/deletable b/maven-repository-indexer/src/test/index/deletable deleted file mode 100644 index e71c84c0a..000000000 Binary files a/maven-repository-indexer/src/test/index/deletable and /dev/null differ diff --git a/maven-repository-indexer/src/test/index/segments b/maven-repository-indexer/src/test/index/segments deleted file mode 100644 index 39fa60a95..000000000 Binary files a/maven-repository-indexer/src/test/index/segments and /dev/null differ diff --git a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java index fef34439f..5cf09fdab 100644 --- a/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java +++ b/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java @@ -63,19 +63,18 @@ public class ArtifactRepositoryIndexingTest 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 ) @@ -86,8 +85,7 @@ public class ArtifactRepositoryIndexingTest 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 ) @@ -95,12 +93,12 @@ public class ArtifactRepositoryIndexingTest //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 ); @@ -121,7 +119,7 @@ public class ArtifactRepositoryIndexingTest //expected } - indexer.open( indexPath ); + indexer = factory.createArtifactRepositoryIndex( indexPath, repository ); try { @@ -136,12 +134,11 @@ public class ArtifactRepositoryIndexingTest 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 ) ) ); @@ -151,23 +148,21 @@ public class ArtifactRepositoryIndexingTest 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" ); @@ -198,6 +193,8 @@ public class ArtifactRepositoryIndexingTest artifacts = repoSearcher.search( indexer, "2", VERSION ); assertEquals( 2, artifacts.size() ); + + indexer.close(); } private Artifact getArtifact( String groupId, String artifactId, String version ) @@ -210,4 +207,13 @@ public class ArtifactRepositoryIndexingTest return artifactFactory.createBuildArtifact( groupId, artifactId, version, "jar" ); } + + protected void tearDown() + throws Exception + { + repository = null; + FileUtils.deleteDirectory( indexPath ); + + super.tearDown(); + } }