Author: epunzalan
Date: Tue Dec 20 17:54:19 2005
New Revision: 358176

URL: http://svn.apache.org/viewcvs?rev=358176&view=rev
Log:
Adding maven-repository-indexer

Added:
    maven/repository-manager/trunk/maven-repository-indexer/
    maven/repository-manager/trunk/maven-repository-indexer/pom.xml   (with 
props)
    maven/repository-manager/trunk/maven-repository-indexer/src/
    maven/repository-manager/trunk/maven-repository-indexer/src/main/
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/
    maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java
   (with props)
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexer.java
   (with props)
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexerFactory.java
   (with props)
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexer.java
   (with props)
    
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexerFactory.java
   (with props)
    maven/repository-manager/trunk/maven-repository-indexer/src/test/
    maven/repository-manager/trunk/maven-repository-indexer/src/test/java/
    maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/
    
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/
    
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/
    
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/
    
maven/repository-manager/trunk/maven-repository-indexer/src/test/java/org/apache/maven/repository/indexing/
Modified:
    maven/repository-manager/trunk/pom.xml

Added: maven/repository-manager/trunk/maven-repository-indexer/pom.xml
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/pom.xml?rev=358176&view=auto
==============================================================================
--- maven/repository-manager/trunk/maven-repository-indexer/pom.xml (added)
+++ maven/repository-manager/trunk/maven-repository-indexer/pom.xml Tue Dec 20 
17:54:19 2005
@@ -0,0 +1,29 @@
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/maven-v4_0_0.xsd";>
+  <parent>
+    <groupId>org.apache.maven.repository</groupId>
+    <artifactId>maven-repository-manager</artifactId>
+    <version>1.0-SNAPSHOT</version>
+  </parent>
+  <modelVersion>4.0.0</modelVersion>
+  <artifactId>maven-repository-indexer</artifactId>
+  <packaging>jar</packaging>
+  <name>Maven Repository Indexer</name>
+  <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-artifact</artifactId>
+    </dependency>
+    <dependency>
+      <groupId>lucene</groupId>
+      <artifactId>lucene</artifactId>
+      <version>1.4.3</version>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <version>3.8.1</version>
+      <scope>test</scope>
+    </dependency>
+  </dependencies>
+</project>

Propchange: maven/repository-manager/trunk/maven-repository-indexer/pom.xml
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: maven/repository-manager/trunk/maven-repository-indexer/pom.xml
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java?rev=358176&view=auto
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java
 (added)
+++ 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java
 Tue Dec 20 17:54:19 2005
@@ -0,0 +1,32 @@
+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.
+ */
+
+/**
+ *
+ * @author Edwin Punzalan
+ */
+public abstract class AbstractRepositoryIndexer
+    implements RepositoryIndexer
+{
+    
+    protected void addDocument( Object obj )
+    {
+        
+    }
+}

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexer.java
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexer.java?rev=358176&view=auto
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexer.java
 (added)
+++ 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexer.java
 Tue Dec 20 17:54:19 2005
@@ -0,0 +1,164 @@
+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.FileInputStream;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.MessageDigest;
+import java.security.NoSuchAlgorithmException;
+import java.util.Collection;
+import org.apache.lucene.analysis.standard.StandardAnalyzer;
+import org.apache.lucene.document.Document;
+import org.apache.lucene.document.Field;
+
+import org.apache.lucene.index.IndexReader;
+import org.apache.lucene.index.IndexWriter;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+
+/**
+ *
+ * @author Edwin Punzalan
+ */
+public class ArtifactRepositoryIndexer
+    extends AbstractRepositoryIndexer
+{
+    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 SHA1 = "sha1";
+    private static final String MD5 = "md5";
+    private static final String CLASSES = "classes";
+    private static final String PACKAGES = "packages";
+    
+    private static final String[] FIELDS = { NAME, GROUPID, ARTIFACTID, 
VERSION, SHA1, MD5, CLASSES, PACKAGES };
+    
+    String indexPath;
+    ArtifactRepository repository;
+    IndexReader indexReader;
+    IndexWriter indexWriter;
+    
+    public ArtifactRepositoryIndexer( ArtifactRepository repository, String 
path )
+    {
+        try
+        {
+            this.repository = repository;
+            validateIndex();
+        }
+        catch ( IOException e )
+        {
+            
+        }
+    }
+
+    public void addArtifactIndex( Artifact artifact )
+        throws IOException, NoSuchAlgorithmException
+    {
+        getIndexWriter();
+
+        Document doc = new Document();
+        doc.add( Field.Text( NAME, repository.pathOf( artifact ) ) );
+        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, getSha1( artifact ) ) );
+        doc.add( Field.Text( MD5, getMd5( artifact ) ) );
+        doc.add( Field.Text( CLASSES, getClasses( artifact ) ) );
+        doc.add( Field.Text( PACKAGES, getPackages( artifact ) ) );
+        indexWriter.addDocument( doc );
+    }
+
+    private String getSha1( Artifact artifact )
+        throws FileNotFoundException, IOException, NoSuchAlgorithmException
+    {
+        FileInputStream fIn = new FileInputStream( artifact.getFile() );
+        return new String( getChecksum( fIn, "SHA-1" ) );
+    }
+    
+    private String getMd5( Artifact artifact )
+        throws FileNotFoundException, IOException, NoSuchAlgorithmException
+    {
+        FileInputStream fIn = new FileInputStream( artifact.getFile() );
+        return new String( getChecksum( fIn, "MD5" ) );
+    }
+
+    private byte[] getChecksum( InputStream inStream, String algorithm )
+        throws IOException, NoSuchAlgorithmException
+    {
+        byte[] buffer = new byte[ 256 ];
+        MessageDigest complete = MessageDigest.getInstance( algorithm );
+        int numRead;
+        do
+        {
+            numRead = inStream.read( buffer );
+            if ( numRead > 0 )
+            {
+                complete.update( buffer, 0, numRead );
+            }
+        }
+        while ( numRead != -1 );
+        inStream.close();
+
+        return complete.digest();
+    }
+
+    private String getClasses( Artifact artifact )
+    {
+        return null;
+    }
+
+    private String getPackages( Artifact artifact )
+    {
+        return null;
+    }
+
+    private void getIndexWriter() 
+        throws IOException
+    {
+        if ( indexWriter == null )
+        {
+            indexWriter = new IndexWriter( indexPath, new StandardAnalyzer(), 
true );
+        }
+    }
+    
+    private void getIndexReader()
+        throws IOException
+    {
+        if ( indexReader == null )
+        {
+            indexReader = IndexReader.open( indexPath );
+        }
+    }
+    
+    private void validateIndex()
+        throws IOException
+    {
+        getIndexReader();
+        Collection fields = indexReader.getFieldNames();
+        for( int idx=0; idx<FIELDS.length; idx++ )
+        {
+            if ( !fields.contains( FIELDS[ idx ] ) )
+            {
+                //should throw something
+            }
+        }
+    }
+}

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexer.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexerFactory.java
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexerFactory.java?rev=358176&view=auto
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexerFactory.java
 (added)
+++ 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexerFactory.java
 Tue Dec 20 17:54:19 2005
@@ -0,0 +1,54 @@
+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.HashMap;
+import java.util.Map;
+import org.apache.maven.artifact.Artifact;
+import org.apache.maven.artifact.repository.ArtifactRepository;
+
+/**
+ *
+ * @author Edwin Punzalan
+ */
+public class DefaultRepositoryIndexerFactory
+    implements RepositoryIndexerFactory
+{
+    Map indexerMap = new HashMap();
+    
+    public RepositoryIndexer getRepositoryIndexer( ArtifactRepository 
repository, Class indexType )
+    {
+        if ( !indexerMap.containsKey( indexType ) )
+        {
+            RepositoryIndexer indexer;
+            
+            if ( Artifact.class == indexType )
+            {
+                indexer = new ArtifactRepositoryIndexer(  );
+            }
+            else
+            {
+                indexer = null;
+            }
+            
+            indexerMap.put( indexType, indexer );
+        }
+
+        return (RepositoryIndexer) indexerMap.get( indexType );
+    }
+}

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexerFactory.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexer.java
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexer.java?rev=358176&view=auto
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexer.java
 (added)
+++ 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexer.java
 Tue Dec 20 17:54:19 2005
@@ -0,0 +1,29 @@
+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.
+ */
+
+/**
+ *
+ * @author Edwin Punzalan
+ */
+public interface RepositoryIndexer
+{
+    String ROLE = RepositoryIndexer.class.getName();
+
+    
+}

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexer.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexer.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Added: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexerFactory.java
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexerFactory.java?rev=358176&view=auto
==============================================================================
--- 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexerFactory.java
 (added)
+++ 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexerFactory.java
 Tue Dec 20 17:54:19 2005
@@ -0,0 +1,31 @@
+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;
+
+/**
+ *
+ * @author Edwin Punzalan
+ */
+public interface RepositoryIndexerFactory
+{
+    String ROLE = RepositoryIndexerFactory.class.getName();
+    
+    RepositoryIndexer getRepositoryIndexer( ArtifactRepository repository, 
Class indexType );
+}

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexerFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: 
maven/repository-manager/trunk/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexerFactory.java
------------------------------------------------------------------------------
    svn:keywords = "Author Date Id Revision"

Modified: maven/repository-manager/trunk/pom.xml
URL: 
http://svn.apache.org/viewcvs/maven/repository-manager/trunk/pom.xml?rev=358176&r1=358175&r2=358176&view=diff
==============================================================================
--- maven/repository-manager/trunk/pom.xml (original)
+++ maven/repository-manager/trunk/pom.xml Tue Dec 20 17:54:19 2005
@@ -101,6 +101,7 @@
   <modules>
     <module>maven-repository-discovery</module>
     <module>maven-repository-reports-standard</module>
+    <module>maven-repository-indexer</module>
   </modules>
   <repositories>
     <repository>


Reply via email to