]> source.dussan.org Git - archiva.git/commitdiff
Renamed RepositorySearcher to RepositoryIndexSearcher and also some more refactoring
authorEdwin L. Punzalan <epunzalan@apache.org>
Tue, 27 Dec 2005 03:28:27 +0000 (03:28 +0000)
committerEdwin L. Punzalan <epunzalan@apache.org>
Tue, 27 Dec 2005 03:28:27 +0000 (03:28 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/repository-manager/trunk@359164 13f79535-47bb-0310-9956-ffa450edef68

maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java [new file with mode: 0644]
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositorySearcher.java [deleted file]
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexSearcher.java [new file with mode: 0644]
maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositorySearcher.java [deleted file]
maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexingTest.java

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
new file mode 100644 (file)
index 0000000..c552e0f
--- /dev/null
@@ -0,0 +1,167 @@
+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 java.io.File;
+import java.io.IOException;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.PerFieldAnalyzerWrapper;
+import org.apache.lucene.analysis.SimpleAnalyzer;
+import org.apache.lucene.analysis.StopAnalyzer;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.queryParser.ParseException;
+import org.apache.lucene.queryParser.QueryParser;
+import org.apache.lucene.search.Hits;
+import org.apache.lucene.search.IndexSearcher;
+import org.apache.lucene.search.Query;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.DefaultArtifact;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+import org.apache.maven.artifact.factory.DefaultArtifactFactory;
+import org.apache.maven.artifact.handler.ArtifactHandler;
+import org.apache.maven.artifact.handler.DefaultArtifactHandler;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.versioning.VersionRange;
+
+/**
+ * This class searches the index for existing artifacts that contains the
+ * specified query string.
+ * 
+ */
+public class ArtifactRepositoryIndexSearcher
+    implements RepositoryIndexSearcher
+{
+       private static final String NAME = "name";
+       private static final String GROUPID = "groupId";
+       private static final String ARTIFACTID = "artifactId";
+       private static final String VERSION = "version";
+       private static final String JAR_TYPE = "jar";
+       private static final String XML_TYPE = "xml";
+       private static final String POM_TYPE = "pom";
+
+       private IndexSearcher searcher;
+       private ArtifactRepository repository;
+       private ArtifactFactory factory;
+       
+       /**
+        * Constructor
+        * 
+        * @param indexPath
+        * @param repository
+        */
+       public ArtifactRepositoryIndexSearcher( String indexPath, ArtifactRepository repository )
+    {
+               this.repository = repository;
+
+               try
+        {
+                       searcher = new IndexSearcher( indexPath );
+        }
+        catch ( IOException ie )
+        {
+                       ie.printStackTrace();
+               }
+       }
+       
+       protected Analyzer getAnalyzer()
+    {
+        return new ArtifactRepositoryIndexAnalyzer( new SimpleAnalyzer() );
+    }
+
+       /**
+        * Search the artifact that contains the query string in the specified
+        * search field.
+        * 
+        * @param queryString
+        * @param searchField
+        * @return
+        */
+       public List searchArtifact( String queryString, String searchField )
+    {
+               List artifactList = new ArrayList();
+
+               try {
+            QueryParser parser = new QueryParser( searchField, getAnalyzer() );
+            Query qry = parser.parse( queryString );
+            Hits hits = searcher.search( qry );
+                        //System.out.println("HITS SIZE --> " + hits.length());
+
+                       for ( int i = 0; i < hits.length(); i++ )
+            {
+                               Document doc = hits.doc( i );
+                               // System.out.println("===========================");
+                               // System.out.println("NAME :: " + (String) doc.get(NAME));
+                               // System.out.println("GROUP ID :: " + (String)
+                               // doc.get(GROUPID));
+                               // System.out.println("ARTIFACT ID :: " + (String)
+                               // doc.get(ARTIFACTID));
+                               //System.out.println("VERSION :: " + (String)
+                               // doc.get(VERSION));
+                               // System.out.println("SHA! :: " + (String) doc.get(SHA1));
+                               // System.out.println("MD5 :: " + (String) doc.get(MD5));
+                               // System.out.println("CLASSES :: " + (String)
+                               // doc.get(CLASSES));
+                               // System.out.println("PACKAGES :: " + (String)
+                               // doc.get(PACKAGES));
+                               // System.out.println("FILES :: " + (String) doc.get(FILES));
+                               // System.out.println("===========================");
+
+                               String name = (String) doc.get( NAME );
+                               String type = "";
+                               if ( ( name.substring( name.length() - 3 ).toLowerCase() ).equals( JAR_TYPE ) )
+                {
+                                       type = JAR_TYPE;
+                }
+                               else if ( ( name.substring( name.length() - 3 ).toLowerCase() ).equals( XML_TYPE ) ||
+                          ( name.substring( name.length() - 3 ).toLowerCase() ).equals( POM_TYPE ) )
+                {
+                                       type = POM_TYPE;
+                }
+
+                               if ( type != null && type.length() > 0 )
+                {
+                                       ArtifactHandler handler = new DefaultArtifactHandler( type );
+                                       VersionRange version = VersionRange.createFromVersion( (String) doc.get( VERSION ) );
+
+                                       Artifact artifact = new DefaultArtifact((String) doc.get( GROUPID ), (String) doc.get( ARTIFACTID ),
+                                                       version, "compile", type, "", handler );
+
+                                       /*
+                                        * Artifact artifact = factory.createArtifact((String)
+                                        * doc.get(GROUPID), (String) doc.get(ARTIFACTID), (String)
+                                        * doc.get(VERSION), "", type);
+                                        */
+                                       artifact.setRepository( repository );
+                                       artifact.setFile( new File( repository.getBasedir() + "/" + (String) doc.get( NAME ) ) );
+
+                                       artifactList.add( artifact );
+                               }
+                       }
+               }
+        catch ( Exception e )
+        {
+                       e.printStackTrace();
+               }
+
+               return artifactList;
+       }
+}
diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositorySearcher.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositorySearcher.java
deleted file mode 100644 (file)
index 0329488..0000000
+++ /dev/null
@@ -1,169 +0,0 @@
-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 java.io.File;
-import java.io.IOException;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.lucene.analysis.Analyzer;
-import org.apache.lucene.analysis.PerFieldAnalyzerWrapper;
-import org.apache.lucene.analysis.SimpleAnalyzer;
-import org.apache.lucene.analysis.StopAnalyzer;
-import org.apache.lucene.analysis.standard.StandardAnalyzer;
-import org.apache.lucene.document.Document;
-import org.apache.lucene.queryParser.ParseException;
-import org.apache.lucene.queryParser.QueryParser;
-import org.apache.lucene.search.Hits;
-import org.apache.lucene.search.IndexSearcher;
-import org.apache.lucene.search.Query;
-import org.apache.maven.artifact.Artifact;
-import org.apache.maven.artifact.DefaultArtifact;
-import org.apache.maven.artifact.factory.ArtifactFactory;
-import org.apache.maven.artifact.factory.DefaultArtifactFactory;
-import org.apache.maven.artifact.handler.ArtifactHandler;
-import org.apache.maven.artifact.handler.DefaultArtifactHandler;
-import org.apache.maven.artifact.repository.ArtifactRepository;
-import org.apache.maven.artifact.versioning.VersionRange;
-
-/**
- * This class searches the index for existing artifacts that contains the
- * specified query string.
- * 
- */
-public class ArtifactRepositorySearcher
-    implements RepositorySearcher
-{
-
-       private IndexSearcher searcher;
-       private ArtifactRepository repository;
-       private ArtifactFactory factory;
-       private static final String NAME = "name";
-       private static final String GROUPID = "groupId";
-       private static final String ARTIFACTID = "artifactId";
-       private static final String VERSION = "version";
-       private static final String JAR_TYPE = "jar";
-       private static final String XML_TYPE = "xml";
-       private static final String POM_TYPE = "pom";
-       
-       /**
-        * Constructor
-        * 
-        * @param indexPath
-        * @param repository
-        */
-       public ArtifactRepositorySearcher( String indexPath,
-                       ArtifactRepository repository )
-    {
-               this.repository = repository;
-               factory = new DefaultArtifactFactory();
-
-               try
-        {
-                       searcher = new IndexSearcher( indexPath );
-        }
-        catch ( IOException ie )
-        {
-                       ie.printStackTrace();
-               }
-       }
-       
-       protected Analyzer getAnalyzer()
-    {
-        return new ArtifactRepositoryIndexAnalyzer( new SimpleAnalyzer() );
-    }
-
-       /**
-        * Search the artifact that contains the query string in the specified
-        * search field.
-        * 
-        * @param queryString
-        * @param searchField
-        * @return
-        */
-       public List searchArtifact( String queryString, String searchField )
-    {
-               List artifactList = new ArrayList();
-
-               try {
-            QueryParser parser = new QueryParser( searchField, getAnalyzer() );
-            Query qry = parser.parse( queryString );
-            Hits hits = searcher.search( qry );
-                        //System.out.println("HITS SIZE --> " + hits.length());
-
-                       for ( int i = 0; i < hits.length(); i++ )
-            {
-                               Document doc = hits.doc( i );
-                               // System.out.println("===========================");
-                               // System.out.println("NAME :: " + (String) doc.get(NAME));
-                               // System.out.println("GROUP ID :: " + (String)
-                               // doc.get(GROUPID));
-                               // System.out.println("ARTIFACT ID :: " + (String)
-                               // doc.get(ARTIFACTID));
-                               //System.out.println("VERSION :: " + (String)
-                               // doc.get(VERSION));
-                               // System.out.println("SHA! :: " + (String) doc.get(SHA1));
-                               // System.out.println("MD5 :: " + (String) doc.get(MD5));
-                               // System.out.println("CLASSES :: " + (String)
-                               // doc.get(CLASSES));
-                               // System.out.println("PACKAGES :: " + (String)
-                               // doc.get(PACKAGES));
-                               // System.out.println("FILES :: " + (String) doc.get(FILES));
-                               // System.out.println("===========================");
-
-                               String name = (String) doc.get( NAME );
-                               String type = "";
-                               if ( ( name.substring( name.length() - 3 ).toLowerCase() ).equals( JAR_TYPE ) )
-                {
-                                       type = JAR_TYPE;
-                }
-                               else if ( ( name.substring( name.length() - 3 ).toLowerCase() ).equals( XML_TYPE ) ||
-                          ( name.substring( name.length() - 3 ).toLowerCase() ).equals( POM_TYPE ) )
-                {
-                                       type = POM_TYPE;
-                }
-
-                               if ( type != null && type.length() > 0 )
-                {
-                                       ArtifactHandler handler = new DefaultArtifactHandler( type );
-                                       VersionRange version = VersionRange.createFromVersion( (String) doc.get( VERSION ) );
-
-                                       Artifact artifact = new DefaultArtifact((String) doc.get( GROUPID ), (String) doc.get( ARTIFACTID ),
-                                                       version, "compile", type, "", handler );
-
-                                       /*
-                                        * Artifact artifact = factory.createArtifact((String)
-                                        * doc.get(GROUPID), (String) doc.get(ARTIFACTID), (String)
-                                        * doc.get(VERSION), "", type);
-                                        */
-                                       artifact.setRepository( repository );
-                                       artifact.setFile( new File( repository.getBasedir() + "/" + (String) doc.get( NAME ) ) );
-
-                                       artifactList.add( artifact );
-                               }
-                       }
-               }
-        catch ( Exception e )
-        {
-                       e.printStackTrace();
-               }
-
-               return artifactList;
-       }
-}
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
new file mode 100644 (file)
index 0000000..2677fd6
--- /dev/null
@@ -0,0 +1,39 @@
+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 java.util.List;
+
+/**
+ *
+ */
+public interface RepositoryIndexSearcher {
+
+       String ROLE = RepositoryIndexer.class.getName();
+       
+       /**
+        * Search the artifact that contains the query string in the specified
+        * search field.
+        * 
+        * @param queryString
+        * @param searchField
+        * @return
+        */
+       public List searchArtifact( String queryString, String searchField );
+       
+}
diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositorySearcher.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositorySearcher.java
deleted file mode 100644 (file)
index d8119d5..0000000
+++ /dev/null
@@ -1,39 +0,0 @@
-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 java.util.List;
-
-/**
- *
- */
-public interface RepositorySearcher {
-
-       String ROLE = RepositoryIndexer.class.getName();
-       
-       /**
-        * Search the artifact that contains the query string in the specified
-        * search field.
-        * 
-        * @param queryString
-        * @param searchField
-        * @return
-        */
-       public List searchArtifact( String queryString, String searchField );
-       
-}
index 881ff45f95aa4d989687e27be8d9ab155678791b..9179c5df796509a65a0756bfcd7e4eb6f5f8ca35 100644 (file)
@@ -40,7 +40,7 @@ public class ArtifactRepositoryIndexingTest
     protected ArtifactFactory artifactFactory;
     protected ArtifactRepository repository;
     protected String indexPath;
-    private RepositorySearcher repoSearcher;
+    private RepositoryIndexSearcher repoSearcher;
     private static final String GROUPID = "groupId";
     private static final String ARTIFACTID = "artifactId";
        private static final String VERSION = "version";
@@ -67,7 +67,7 @@ public class ArtifactRepositoryIndexingTest
         indexer = (ArtifactRepositoryIndexer) factory.getArtifactRepositoryIndexer( indexPath, repository );
         artifactFactory = (ArtifactFactory) lookup( ArtifactFactory.ROLE );
         
-        repoSearcher = new ArtifactRepositorySearcher(indexPath, repository);
+        repoSearcher = new ArtifactRepositoryIndexSearcher(indexPath, repository);
     }
     
     public void testIndex()