aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--maven-repository-indexer/pom.xml29
-rw-r--r--maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java32
-rw-r--r--maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexer.java164
-rw-r--r--maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexerFactory.java54
-rw-r--r--maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexer.java29
-rw-r--r--maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexerFactory.java31
-rw-r--r--pom.xml1
7 files changed, 340 insertions, 0 deletions
diff --git a/maven-repository-indexer/pom.xml b/maven-repository-indexer/pom.xml
new file mode 100644
index 000000000..81a8d7e28
--- /dev/null
+++ b/maven-repository-indexer/pom.xml
@@ -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>
diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java
new file mode 100644
index 000000000..da8fa397f
--- /dev/null
+++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/AbstractRepositoryIndexer.java
@@ -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 )
+ {
+
+ }
+}
diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexer.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexer.java
new file mode 100644
index 000000000..8d6d45d15
--- /dev/null
+++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/ArtifactRepositoryIndexer.java
@@ -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
+ }
+ }
+ }
+}
diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexerFactory.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexerFactory.java
new file mode 100644
index 000000000..ffdba32da
--- /dev/null
+++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/DefaultRepositoryIndexerFactory.java
@@ -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 );
+ }
+}
diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexer.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexer.java
new file mode 100644
index 000000000..dd1d641eb
--- /dev/null
+++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexer.java
@@ -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();
+
+
+}
diff --git a/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexerFactory.java b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexerFactory.java
new file mode 100644
index 000000000..9a677e860
--- /dev/null
+++ b/maven-repository-indexer/src/main/java/org/apache/maven/repository/indexing/RepositoryIndexerFactory.java
@@ -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 );
+}
diff --git a/pom.xml b/pom.xml
index 86c84c787..9bcb1c09c 100644
--- a/pom.xml
+++ b/pom.xml
@@ -101,6 +101,7 @@
<modules>
<module>maven-repository-discovery</module>
<module>maven-repository-reports-standard</module>
+ <module>maven-repository-indexer</module>
</modules>
<repositories>
<repository>