]> source.dussan.org Git - archiva.git/commitdiff
[MRM-151] index developers and dependencies
authorBrett Porter <brett@apache.org>
Sat, 26 Aug 2006 13:39:54 +0000 (13:39 +0000)
committerBrett Porter <brett@apache.org>
Sat, 26 Aug 2006 13:39:54 +0000 (13:39 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@437165 13f79535-47bb-0310-9956-ffa450edef68

archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/lucene/LuceneStandardIndexRecordConverter.java
archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/StandardArtifactIndexRecord.java
archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/StandardArtifactIndexRecordFactory.java
archiva-indexer/src/main/java/org/apache/maven/archiva/indexer/record/StandardIndexRecordFields.java
archiva-indexer/src/test/java/org/apache/maven/archiva/indexer/record/StandardArtifactIndexRecordFactoryTest.java
archiva-indexer/src/test/managed-repository/org/apache/maven/archiva/record/test-jar-and-pom/1.0-alpha-1/test-jar-and-pom-1.0-alpha-1.pom

index f64dd4a859f2b84ab4a4237e351281f114cc16a0..f97275c983b5a3b1c73445cb15f810034bb8a3e4 100644 (file)
@@ -73,9 +73,18 @@ public class LuceneStandardIndexRecordConverter
         addUntokenizedField( document, StandardIndexRecordFields.INCEPTION_YEAR, rec.getInceptionYear() );
         addTokenizedField( document, StandardIndexRecordFields.PROJECT_NAME, rec.getProjectName() );
         addTokenizedField( document, StandardIndexRecordFields.PROJECT_DESCRIPTION, rec.getProjectDescription() );
+        if ( rec.getDependencies() != null )
+        {
+            addTokenizedField( document, StandardIndexRecordFields.DEPENDENCIES,
+                               StringUtils.join( rec.getDependencies().iterator(), "\n" ) );
+        }
+        if ( rec.getDevelopers() != null )
+        {
+            addTokenizedField( document, StandardIndexRecordFields.DEVELOPERS,
+                               StringUtils.join( rec.getDevelopers().iterator(), "\n" ) );
+        }
 /* TODO: add later
         document.add( Field.Keyword( StandardIndexRecordFields.FLD_LICENSE_URLS, "" ) );
-        document.add( Field.Keyword( StandardIndexRecordFields.FLD_DEPENDENCIES, "" ) );
         document.add( Field.Keyword( StandardIndexRecordFields.FLD_PLUGINS_REPORT, "" ) );
         document.add( Field.Keyword( StandardIndexRecordFields.FLD_PLUGINS_BUILD, "" ) );
 */
@@ -111,6 +120,16 @@ public class LuceneStandardIndexRecordConverter
         {
             record.setFiles( Arrays.asList( files.split( "\n" ) ) );
         }
+        String dependencies = document.get( StandardIndexRecordFields.DEPENDENCIES );
+        if ( dependencies != null )
+        {
+            record.setDependencies( Arrays.asList( dependencies.split( "\n" ) ) );
+        }
+        String developers = document.get( StandardIndexRecordFields.DEVELOPERS );
+        if ( developers != null )
+        {
+            record.setDevelopers( Arrays.asList( developers.split( "\n" ) ) );
+        }
         record.setPluginPrefix( document.get( StandardIndexRecordFields.PLUGIN_PREFIX ) );
         record.setInceptionYear( document.get( StandardIndexRecordFields.INCEPTION_YEAR ) );
         record.setProjectName( document.get( StandardIndexRecordFields.PROJECT_NAME ) );
index ae60fcfa2d194bd0cb121817ea3613370b1c0961..625d43e5f6b388aea8f60955f49c945000250cac 100644 (file)
@@ -96,6 +96,16 @@ public class StandardArtifactIndexRecord
      */
     private String baseVersion;
 
+    /**
+     * A list of dependencies for the artifact, each a string of the form <code>groupId:artifactId:version</code>.
+     */
+    private List dependencies;
+
+    /**
+     * A list of developers in the POM, each a string of the form <code>id:name:email</code>.
+     */
+    private List developers;
+
     public void setSha1Checksum( String sha1Checksum )
     {
         this.sha1Checksum = sha1Checksum;
@@ -164,6 +174,14 @@ public class StandardArtifactIndexRecord
         {
             return false;
         }
+        if ( dependencies != null ? !dependencies.equals( that.dependencies ) : that.dependencies != null )
+        {
+            return false;
+        }
+        if ( developers != null ? !developers.equals( that.developers ) : that.developers != null )
+        {
+            return false;
+        }
         if ( files != null ? !files.equals( that.files ) : that.files != null )
         {
             return false;
@@ -228,6 +246,8 @@ public class StandardArtifactIndexRecord
         result = 31 * result + ( classifier != null ? classifier.hashCode() : 0 );
         result = 31 * result + ( type != null ? type.hashCode() : 0 );
         result = 31 * result + ( files != null ? files.hashCode() : 0 );
+        result = 31 * result + ( developers != null ? developers.hashCode() : 0 );
+        result = 31 * result + ( dependencies != null ? dependencies.hashCode() : 0 );
         result = 31 * result + ( repository != null ? repository.hashCode() : 0 );
         result = 31 * result + ( packaging != null ? packaging.hashCode() : 0 );
         result = 31 * result + ( pluginPrefix != null ? pluginPrefix.hashCode() : 0 );
@@ -336,4 +356,24 @@ public class StandardArtifactIndexRecord
     {
         return baseVersion;
     }
+
+    public void setDependencies( List dependencies )
+    {
+        this.dependencies = dependencies;
+    }
+
+    public void setDevelopers( List developers )
+    {
+        this.developers = developers;
+    }
+
+    public List getDevelopers()
+    {
+        return developers;
+    }
+
+    public List getDependencies()
+    {
+        return dependencies;
+    }
 }
index d4f67b3e426c24ed9aac8e2eca69d8cbf673f335..965adfe1c3ad5303502ea932500665f1714fb397 100644 (file)
@@ -21,6 +21,8 @@ import org.apache.maven.archiva.indexer.RepositoryIndexException;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.model.Dependency;
+import org.apache.maven.model.Developer;
 import org.apache.maven.model.Model;
 import org.apache.maven.project.MavenProject;
 import org.apache.maven.project.MavenProjectBuilder;
@@ -136,6 +138,7 @@ public class StandardArtifactIndexRecordFactory
                 record.setLastModified( file.lastModified() );
                 record.setSize( file.length() );
                 record.setRepository( artifact.getRepository().getId() );
+
                 if ( files != null )
                 {
                     populateArchiveEntries( files, record, artifact.getFile() );
@@ -196,14 +199,53 @@ public class StandardArtifactIndexRecordFactory
         record.setProjectDescription( pom.getDescription() );
         record.setInceptionYear( pom.getInceptionYear() );
 
+        List dependencies = populateDependencies( pom.getDependencies() );
+        if ( !dependencies.isEmpty() )
+        {
+            record.setDependencies( dependencies );
+        }
+        List developers = populateDevelopers( pom.getDevelopers() );
+        if ( !developers.isEmpty() )
+        {
+            record.setDevelopers( developers );
+        }
+
 /* TODO: fields for later
                 indexPlugins( doc, FLD_PLUGINS_BUILD, pom.getBuild().getPlugins().iterator() );
                 indexReportPlugins( doc, FLD_PLUGINS_REPORT, pom.getReporting().getPlugins().iterator() );
-                record.setDependencies( dependencies );
                 record.setLicenses( licenses );
 */
     }
 
+    private List populateDependencies( List dependencies )
+    {
+        List convertedDependencies = new ArrayList();
+
+        for ( Iterator i = dependencies.iterator(); i.hasNext(); )
+        {
+            Dependency dependency = (Dependency) i.next();
+
+            convertedDependencies.add(
+                dependency.getGroupId() + ":" + dependency.getArtifactId() + ":" + dependency.getVersion() );
+        }
+
+        return convertedDependencies;
+    }
+
+    private List populateDevelopers( List developers )
+    {
+        List convertedDevelopers = new ArrayList();
+
+        for ( Iterator i = developers.iterator(); i.hasNext(); )
+        {
+            Developer developer = (Developer) i.next();
+
+            convertedDevelopers.add( developer.getId() + ":" + developer.getName() + ":" + developer.getEmail() );
+        }
+
+        return convertedDevelopers;
+    }
+
     private Model readPom( Artifact artifact, ArtifactRepository repository )
         throws RepositoryIndexException, ProjectBuildingException
     {
index 437bac35044fc893a27c9ce95758d16c6402f03d..4f63154a5a1079f880eb95360bca1454ae15f514 100644 (file)
@@ -70,6 +70,10 @@ public class StandardIndexRecordFields
 
     public static final String PROJECT_DESCRIPTION = "projectDesc";
 
+    public static final String DEVELOPERS = "developers";
+
+    public static final String DEPENDENCIES = "dependencies";
+
     private StandardIndexRecordFields()
     {
         // No touchy!
index 3a425ca61d8ae8e58c4d964c7c2197517a49edc5..6d3733a1d59d5a37e98969ae019435afdf9efc9f 100644 (file)
@@ -28,7 +28,9 @@ import org.codehaus.plexus.util.xml.pull.XmlPullParserException;
 
 import java.io.File;
 import java.io.IOException;
+import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -52,6 +54,10 @@ public class StandardArtifactIndexRecordFactoryTest
     private static final List JAR_FILE_LIST =
         Arrays.asList( new String[]{"META-INF/MANIFEST.MF", "A.class", "b/B.class", "b/c/C.class"} );
 
+    private static final String JUNIT_DEPENDENCY = "junit:junit:3.8.1";
+
+    private static final String PLUGIN_API_DEPENDENCY = "org.apache.maven:maven-plugin-api:2.0";
+
     protected void setUp()
         throws Exception
     {
@@ -145,6 +151,8 @@ public class StandardArtifactIndexRecordFactoryTest
         expectedRecord.setRepository( "test" );
         expectedRecord.setPackaging( "jar" );
         expectedRecord.setProjectName( "Test JAR and POM" );
+        expectedRecord.setDependencies( createDependencies() );
+        expectedRecord.setDevelopers( createDevelopers() );
 
         assertEquals( "check record", expectedRecord, record );
     }
@@ -173,6 +181,8 @@ public class StandardArtifactIndexRecordFactoryTest
         expectedRecord.setPackaging( "jar" );
         expectedRecord.setProjectName( "Test JAR and POM" );
         expectedRecord.setClassifier( "jdk14" );
+        expectedRecord.setDependencies( createDependencies() );
+        expectedRecord.setDevelopers( createDevelopers() );
 
         assertEquals( "check record", expectedRecord, record );
     }
@@ -202,6 +212,7 @@ public class StandardArtifactIndexRecordFactoryTest
         expectedRecord.setProjectName( "Child Project" );
         expectedRecord.setProjectDescription( "Description" );
         expectedRecord.setInceptionYear( "2005" );
+        expectedRecord.setDependencies( Collections.singletonList( JUNIT_DEPENDENCY ) );
 
         assertEquals( "check record", expectedRecord, record );
     }
@@ -289,6 +300,7 @@ public class StandardArtifactIndexRecordFactoryTest
         expectedRecord.setPackaging( "maven-plugin" );
         expectedRecord.setProjectName( "Maven Mojo Archetype" );
         expectedRecord.setPluginPrefix( "test" );
+        expectedRecord.setDependencies( Arrays.asList( new String[]{JUNIT_DEPENDENCY, PLUGIN_API_DEPENDENCY} ) );
 
         assertEquals( "check record", expectedRecord, record );
     }
@@ -413,4 +425,19 @@ public class StandardArtifactIndexRecordFactoryTest
         artifact.setRepository( repository );
         return artifact;
     }
+
+    private static List createDevelopers()
+    {
+        List developers = new ArrayList();
+        developers.add( "brett:Brett Porter:brett@apache.org" );
+        return developers;
+    }
+
+    private static List createDependencies()
+    {
+        List dependencies = new ArrayList();
+        dependencies.add( JUNIT_DEPENDENCY );
+        dependencies.add( "org.apache.maven:maven-project:2.0" );
+        return dependencies;
+    }
 }
index dce711522d3ac05ce4802384dcce64d867fd578b..cc8085fb1a2ae31c61b3786e27586ee13f5f5104 100644 (file)
   <version>1.0-alpha-1</version>
   <name>Test JAR and POM</name>
   <dependencies>
+    <dependency>
+      <groupId>org.apache.maven</groupId>
+      <artifactId>maven-project</artifactId>
+      <version>2.0</version>
+    </dependency>
     <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
       <scope>test</scope>
     </dependency>
   </dependencies>
+  <developers>
+    <developer>
+      <id>brett</id>
+      <name>Brett Porter</name>
+      <email>brett@apache.org</email>
+      <roles>
+        <role>Developer</role>
+      </roles>
+    </developer>
+  </developers>
 </project>