You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@maven.apache.org by ep...@apache.org on 2006/01/05 09:00:28 UTC
svn commit: r366112 -
/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/
Author: epunzalan
Date: Thu Jan 5 00:00:17 2006
New Revision: 366112
URL: http://svn.apache.org/viewcvs?rev=366112&view=rev
Log:
PR: MRM-34
Added Pom indexer and searcher. Also refactored some common code.
Added:
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java (with props)
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndexSearcher.java (with props)
Modified:
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexSearcher.java
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java
Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java?rev=366112&r1=366111&r2=366112&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndex.java Thu Jan 5 00:00:17 2006
@@ -18,6 +18,7 @@
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
+import org.apache.maven.artifact.repository.ArtifactRepository;
import java.io.File;
import java.io.IOException;
@@ -39,6 +40,17 @@
private IndexWriter indexWriter;
+ private ArtifactRepository repository;
+
+ public AbstractRepositoryIndex( ArtifactRepository repository, String indexPath )
+ throws RepositoryIndexException
+ {
+ this.repository = repository;
+ this.indexPath = indexPath;
+
+ open( indexPath );
+ }
+
/**
* method to encapsulate the optimize() method for lucene
*/
@@ -185,5 +197,10 @@
}
indexOpen = true;
+ }
+
+ public ArtifactRepository getRepository()
+ {
+ return repository;
}
}
Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexSearcher.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexSearcher.java?rev=366112&r1=366111&r2=366112&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexSearcher.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexSearcher.java Thu Jan 5 00:00:17 2006
@@ -39,7 +39,7 @@
public abstract class AbstractRepositoryIndexSearcher
implements RepositoryIndexSearcher
{
- protected ArtifactRepositoryIndex index;
+ protected RepositoryIndex index;
private BooleanQuery bQry;
@@ -52,7 +52,7 @@
*
* @param index the index object
*/
- public AbstractRepositoryIndexSearcher( ArtifactRepositoryIndex index )
+ public AbstractRepositoryIndexSearcher( RepositoryIndex index )
{
this.index = index;
}
Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java?rev=366112&r1=366111&r2=366112&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndex.java Thu Jan 5 00:00:17 2006
@@ -41,39 +41,36 @@
public class ArtifactRepositoryIndex
extends AbstractRepositoryIndex
{
- private static final String NAME = "name";
+ protected static final String FLD_NAME = "name";
- private static final String GROUPID = "groupId";
+ protected static final String FLD_GROUPID = "groupId";
- private static final String ARTIFACTID = "artifactId";
+ protected static final String FLD_ARTIFACTID = "artifactId";
- private static final String VERSION = "version";
+ protected static final String FLD_VERSION = "version";
- private static final String SHA1 = "sha1";
+ protected static final String FLD_SHA1 = "sha1";
- private static final String MD5 = "md5";
+ protected static final String FLD_MD5 = "md5";
- private static final String CLASSES = "classes";
+ protected static final String FLD_CLASSES = "classes";
- private static final String PACKAGES = "packages";
+ protected static final String FLD_PACKAGES = "packages";
- private static final String FILES = "files";
+ protected static final String FLD_FILES = "files";
- private static final String[] FIELDS = {NAME, GROUPID, ARTIFACTID, VERSION, SHA1, MD5, CLASSES, PACKAGES, FILES};
+ private static final String[] FIELDS =
+ {FLD_NAME, FLD_GROUPID, FLD_ARTIFACTID, FLD_VERSION, FLD_SHA1, FLD_MD5, FLD_CLASSES, FLD_PACKAGES, FLD_FILES};
private Analyzer analyzer;
private Digester digester;
- private ArtifactRepository repository;
-
public ArtifactRepositoryIndex( String indexPath, ArtifactRepository repository, Digester digester )
throws RepositoryIndexException
{
- this.repository = repository;
+ super( repository, indexPath );
this.digester = digester;
-
- open( indexPath );
}
/**
@@ -175,15 +172,15 @@
//@todo should some of these fields be Keyword instead of Text ?
Document doc = new Document();
- doc.add( Field.Text( NAME, artifact.getFile().getName() ) );
- doc.add( Field.Text( GROUPID, artifact.getGroupId() ) );
- doc.add( Field.Text( ARTIFACTID, artifact.getArtifactId() ) );
- doc.add( Field.Text( VERSION, artifact.getVersion() ) );
- doc.add( Field.Text( SHA1, sha1sum ) );
- doc.add( Field.Text( MD5, md5sum ) );
- doc.add( Field.Text( CLASSES, classes.toString() ) );
- doc.add( Field.Text( PACKAGES, packages.toString() ) );
- doc.add( Field.Text( FILES, files.toString() ) );
+ doc.add( Field.Text( FLD_NAME, artifact.getFile().getName() ) );
+ doc.add( Field.Text( FLD_GROUPID, artifact.getGroupId() ) );
+ doc.add( Field.Text( FLD_ARTIFACTID, artifact.getArtifactId() ) );
+ doc.add( Field.Text( FLD_VERSION, artifact.getVersion() ) );
+ doc.add( Field.Text( FLD_SHA1, sha1sum ) );
+ doc.add( Field.Text( FLD_MD5, md5sum ) );
+ doc.add( Field.Text( FLD_CLASSES, classes.toString() ) );
+ doc.add( Field.Text( FLD_PACKAGES, packages.toString() ) );
+ doc.add( Field.Text( FLD_FILES, files.toString() ) );
try
{
@@ -255,10 +252,5 @@
}
return isAdded;
- }
-
- public ArtifactRepository getRepository()
- {
- return repository;
}
}
Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java?rev=366112&r1=366111&r2=366112&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexSearcher.java Thu Jan 5 00:00:17 2006
@@ -32,14 +32,6 @@
public class ArtifactRepositoryIndexSearcher
extends AbstractRepositoryIndexSearcher
{
- 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 ArtifactFactory factory;
private BooleanQuery bQry;
@@ -62,10 +54,10 @@
protected Object createSearchedObjectFromIndexDocument( Document doc )
{
- String groupId = doc.get( GROUPID );
- String artifactId = doc.get( ARTIFACTID );
- String version = doc.get( VERSION );
- String name = doc.get( NAME );
+ String groupId = doc.get( ArtifactRepositoryIndex.FLD_GROUPID );
+ String artifactId = doc.get( ArtifactRepositoryIndex.FLD_ARTIFACTID );
+ String version = doc.get( ArtifactRepositoryIndex.FLD_VERSION );
+ String name = doc.get( ArtifactRepositoryIndex.FLD_NAME );
String packaging = name.substring( name.lastIndexOf( '.' ) + 1 );
Artifact artifact = factory.createBuildArtifact( groupId, artifactId, version, packaging );
String groupIdTemp = groupId.replace( '.', '/' );
Added: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java?rev=366112&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java (added)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java Thu Jan 5 00:00:17 2006
@@ -0,0 +1,166 @@
+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.lucene.analysis.Analyzer;
+import org.apache.lucene.analysis.SimpleAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.License;
+import org.apache.maven.model.Model;
+import org.apache.maven.model.Plugin;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.codehaus.plexus.util.StringUtils;
+
+import java.io.IOException;
+import java.util.Iterator;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class PomRepositoryIndex
+ extends AbstractRepositoryIndex
+{
+ protected static final String FLD_GROUPID = "groupId";
+
+ protected static final String FLD_ARTIFACTID = "artifactId";
+
+ protected static final String FLD_VERSION = "version";
+
+ protected static final String FLD_PACKAGING = "packaging";
+
+ protected static final String FLD_LICENSE_URLS = "license_urls";
+
+ protected static final String FLD_DEPENDENCIES = "dependencies";
+
+ protected static final String FLD_PLUGINS_BUILD = "plugins_build";
+
+ protected static final String FLD_PLUGINS_REPORT = "plugins_report";
+
+ protected static final String FLD_PLUGINS_ALL = "plugins_all";
+
+ private static final String[] FIELDS = {FLD_GROUPID, FLD_ARTIFACTID, FLD_VERSION, FLD_PACKAGING, FLD_LICENSE_URLS, FLD_DEPENDENCIES,
+ FLD_PLUGINS_BUILD, FLD_PLUGINS_REPORT, FLD_PLUGINS_ALL};
+
+ private Analyzer analyzer;
+
+ public PomRepositoryIndex( ArtifactRepository repository, String indexPath )
+ throws RepositoryIndexException
+ {
+ super( repository, indexPath );
+ }
+
+ public Analyzer getAnalyzer()
+ {
+ if ( analyzer == null )
+ {
+ analyzer = new SimpleAnalyzer();
+ }
+
+ return analyzer;
+ }
+
+ public void index( Object obj )
+ throws RepositoryIndexException
+ {
+ if ( obj instanceof Model )
+ {
+ indexModel( (Model) obj );
+ }
+ else
+ {
+ throw new RepositoryIndexException(
+ "This instance of indexer cannot index instances of " + obj.getClass().getName() );
+ }
+ }
+
+ public String[] getIndexFields()
+ {
+ return FIELDS;
+ }
+
+ public void indexModel( Model pom )
+ throws RepositoryIndexException
+ {
+ if ( !isOpen() )
+ {
+ throw new RepositoryIndexException( "Unable to add pom index on a closed index" );
+ }
+
+ Document doc = new Document();
+ doc.add( Field.Text( FLD_GROUPID, pom.getGroupId() ) );
+ doc.add( Field.Text( FLD_ARTIFACTID, pom.getArtifactId() ) );
+ doc.add( Field.Text( FLD_VERSION, pom.getVersion() ) );
+ doc.add( Field.Keyword( FLD_PACKAGING, pom.getPackaging() ) );
+
+ indexLicenseUrls( doc, pom.getLicenses().iterator() );
+ indexDependencies( doc, pom.getDependencies().iterator() );
+ indexPlugins( doc, FLD_PLUGINS_BUILD, pom.getBuild().getPlugins().iterator() );
+ indexPlugins( doc, FLD_PLUGINS_REPORT, pom.getReporting().getPlugins().iterator() );
+ indexPlugins( doc, FLD_PLUGINS_ALL, pom.getBuild().getPlugins().iterator() );
+ indexPlugins( doc, FLD_PLUGINS_ALL, pom.getReporting().getPlugins().iterator() );
+
+ try
+ {
+ getIndexWriter().addDocument( doc );
+ }
+ catch ( IOException e )
+ {
+ throw new RepositoryIndexException( "Error opening index", e );
+ }
+ }
+
+ private void indexLicenseUrls( Document doc, Iterator licenses )
+ {
+ while ( licenses.hasNext() )
+ {
+ License license = (License) licenses.next();
+ String url = license.getUrl();
+ if ( StringUtils.isNotEmpty( url ) )
+ {
+ doc.add( Field.Keyword( FLD_LICENSE_URLS, url ) );
+ }
+ }
+ }
+
+ private void indexDependencies( Document doc, Iterator dependencies )
+ {
+ while ( dependencies.hasNext() )
+ {
+ Dependency dep = (Dependency) dependencies.next();
+ String id = getId( dep.getGroupId(), dep.getArtifactId(), dep.getVersion() );
+ doc.add( Field.Keyword( FLD_DEPENDENCIES, id ) );
+ }
+ }
+
+ private void indexPlugins( Document doc, String field, Iterator plugins )
+ {
+ while ( plugins.hasNext() )
+ {
+ Plugin plugin = (Plugin) plugins.next();
+ String id = getId( plugin.getGroupId(), plugin.getArtifactId(), plugin.getVersion() );
+ doc.add( Field.Keyword( field, id ) );
+ }
+ }
+
+ private String getId( String groupId, String artifactId, String version )
+ {
+ return groupId + ":" + artifactId + ":" + version;
+ }
+}
Propchange: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndex.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Added: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndexSearcher.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndexSearcher.java?rev=366112&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndexSearcher.java (added)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndexSearcher.java Thu Jan 5 00:00:17 2006
@@ -0,0 +1,52 @@
+package org.apache.maven.repository.indexing;
+
+/**
+ * Copyright 2005-2006 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.lucene.document.Document;
+import org.apache.maven.artifact.factory.ArtifactFactory;
+
+/**
+ * @author Edwin Punzalan
+ */
+public class PomRepositoryIndexSearcher
+ extends AbstractRepositoryIndexSearcher
+{
+ private static final String GROUPID = "groupId";
+
+ private static final String ARTIFACTID = "artifactId";
+
+ private static final String VERSION = "version";
+
+ private static final String PACKAGING = "packaging";
+
+ private ArtifactFactory factory;
+
+ public PomRepositoryIndexSearcher( RepositoryIndex index, ArtifactFactory artifactFactory )
+ {
+ super( index );
+ this.factory = artifactFactory;
+ }
+
+ protected Object createSearchedObjectFromIndexDocument( Document doc )
+ {
+ String groupId = doc.get( PomRepositoryIndex.FLD_GROUPID ) ;
+ String artifactId = doc.get( PomRepositoryIndex.FLD_ARTIFACTID );
+ String version = doc.get( PomRepositoryIndex.FLD_VERSION );
+ String packaging = doc.get( PomRepositoryIndex.FLD_PACKAGING );
+ return factory.createBuildArtifact( groupId, artifactId, version, packaging );
+ }
+}
Propchange: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndexSearcher.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/PomRepositoryIndexSearcher.java
------------------------------------------------------------------------------
svn:keywords = "Author Date Id Revision"
Modified: maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java
URL: http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java?rev=366112&r1=366111&r2=366112&view=diff
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java (original)
+++ maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndex.java Thu Jan 5 00:00:17 2006
@@ -17,6 +17,7 @@
*/
import org.apache.lucene.analysis.Analyzer;
+import org.apache.maven.artifact.repository.ArtifactRepository;
/**
* @author Edwin Punzalan
@@ -35,9 +36,7 @@
void close()
throws RepositoryIndexException;
-/* void open( String indexPath )
- throws RepositoryIndexException;
-*/
+ ArtifactRepository getRepository();
void optimize()
throws RepositoryIndexException;