]> source.dussan.org Git - archiva.git/commitdiff
[MRM-144] fix some minor issues
authorBrett Porter <brett@apache.org>
Mon, 28 Aug 2006 06:48:46 +0000 (06:48 +0000)
committerBrett Porter <brett@apache.org>
Mon, 28 Aug 2006 06:48:46 +0000 (06:48 +0000)
git-svn-id: https://svn.apache.org/repos/asf/maven/archiva/trunk@437570 13f79535-47bb-0310-9956-ffa450edef68

archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/SearchAction.java
archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java
archiva-webapp/src/main/resources/xwork.xml

index 38b9b248f09e3498ed2109776f6b42150b15582b..a3bdc1867f6580244b1134bbacbec9a45c19088c 100644 (file)
@@ -75,8 +75,6 @@ public class SearchAction
      */
     private ConfigurationStore configurationStore;
 
-    private static final String NO_RESULTS = "noResults";
-
     private static final String RESULTS = "results";
 
     private static final String ARTIFACT = "artifact";
@@ -97,7 +95,6 @@ public class SearchAction
             return ERROR;
         }
 
-        // TODO! this is correct, but ugly
         MultiFieldQueryParser parser = new MultiFieldQueryParser( new String[]{StandardIndexRecordFields.GROUPID,
             StandardIndexRecordFields.ARTIFACTID, StandardIndexRecordFields.BASE_VERSION,
             StandardIndexRecordFields.CLASSIFIER, StandardIndexRecordFields.CLASSES, StandardIndexRecordFields.FILES,
@@ -105,6 +102,12 @@ public class SearchAction
             StandardIndexRecordFields.PROJECT_DESCRIPTION}, new StandardAnalyzer() );
         searchResults = index.search( new LuceneQuery( parser.parse( q ) ) );
 
+        if ( searchResults.isEmpty() )
+        {
+            addActionError( "No results found" );
+            return INPUT;
+        }
+
         return SUCCESS;
     }
 
@@ -128,7 +131,8 @@ public class SearchAction
 
         if ( searchResults.isEmpty() )
         {
-            return NO_RESULTS;
+            addActionError( "No results found" );
+            return INPUT;
         }
         if ( searchResults.size() == 1 )
         {
index 2b80de6d877163195abba33e3814d25e80a3bccf..113910483aa9789898eadbac4116aa057de6bb8c 100644 (file)
@@ -32,6 +32,7 @@ import org.apache.maven.archiva.indexer.record.StandardArtifactIndexRecord;
 import org.apache.maven.artifact.Artifact;
 import org.apache.maven.artifact.factory.ArtifactFactory;
 import org.apache.maven.artifact.repository.ArtifactRepository;
+import org.apache.maven.artifact.versioning.DefaultArtifactVersion;
 import org.apache.maven.model.Dependency;
 import org.apache.maven.model.Model;
 import org.apache.maven.project.MavenProject;
@@ -45,10 +46,12 @@ import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 
 /**
  * Browse the repository.
@@ -278,7 +281,10 @@ public class ShowArtifactAction
 
         private final String artifactId;
 
-        private List versions = new ArrayList();
+        /**
+         * Versions added. We ignore duplicates since you might add those with varying classifiers.
+         */
+        private Set versions = new HashSet();
 
         private String version;
 
@@ -318,9 +324,77 @@ public class ShowArtifactAction
             return classifier;
         }
 
+        private static class Ver
+        {
+            private int buildNumber;
+
+            private int major;
+
+            private int minor;
+
+            private int incremental;
+
+            private String qualifier;
+
+
+        }
+
         public void addVersion( String version )
         {
-            versions.add( version );
+            // We use DefaultArtifactVersion to get the correct sorting order later, however it does not have
+            // hashCode properly implemented, so we add it here.
+            // TODO: add these methods to the actual DefaultArtifactVersion and use that.
+            versions.add( new DefaultArtifactVersion( version )
+            {
+                public int hashCode()
+                {
+                    int result;
+                    result = getBuildNumber();
+                    result = 31 * result + getMajorVersion();
+                    result = 31 * result + getMinorVersion();
+                    result = 31 * result + getIncrementalVersion();
+                    result = 31 * result + ( getQualifier() != null ? getQualifier().hashCode() : 0 );
+                    return result;
+                }
+
+                public boolean equals( Object o )
+                {
+                    if ( this == o )
+                    {
+                        return true;
+                    }
+                    if ( o == null || getClass() != o.getClass() )
+                    {
+                        return false;
+                    }
+
+                    DefaultArtifactVersion that = (DefaultArtifactVersion) o;
+
+                    if ( getBuildNumber() != that.getBuildNumber() )
+                    {
+                        return false;
+                    }
+                    if ( getIncrementalVersion() != that.getIncrementalVersion() )
+                    {
+                        return false;
+                    }
+                    if ( getMajorVersion() != that.getMajorVersion() )
+                    {
+                        return false;
+                    }
+                    if ( getMinorVersion() != that.getMinorVersion() )
+                    {
+                        return false;
+                    }
+                    if ( getQualifier() != null ? !getQualifier().equals( that.getQualifier() )
+                        : that.getQualifier() != null )
+                    {
+                        return false;
+                    }
+
+                    return true;
+                }
+            } );
 
             if ( versions.size() == 1 )
             {
@@ -329,8 +403,6 @@ public class ShowArtifactAction
             else
             {
                 this.version = null;
-                // TODO: use version comparator!
-                Collections.sort( versions );
             }
         }
 
@@ -346,6 +418,8 @@ public class ShowArtifactAction
 
         public List getVersions()
         {
+            List versions = new ArrayList( this.versions );
+            Collections.sort( versions );
             return versions;
         }
 
index 87f83ee666da80902dcefb7a9a98b780a82f58bd..2177cacc9963ac4a9a12705daabaa93ee9412098 100644 (file)
@@ -76,8 +76,6 @@
       <result name="input">/WEB-INF/jsp/quickSearch.jsp</result>
       <result>/WEB-INF/jsp/results.jsp</result>
       <result name="error">/WEB-INF/jsp/quickSearch.jsp</result>
-      <result name="noResults">/WEB-INF/jsp/noResults.jsp</result>
-      <!-- TODO! -->
     </action>
 
     <action name="findArtifact" class="searchAction" method="input">
@@ -88,8 +86,6 @@
       <result name="input">/WEB-INF/jsp/findArtifact.jsp</result>
       <result name="results">/WEB-INF/jsp/results.jsp</result>
       <result name="error">/WEB-INF/jsp/findArtifact.jsp</result>
-      <result name="noResults">/WEB-INF/jsp/noResults.jsp</result>
-      <!-- TODO! -->
       <result name="artifact" type="redirect">
         /browse/${searchResults[0].groupId}/${searchResults[0].artifactId}/${searchResults[0].version}
       </result>