From: Brett Porter Date: Mon, 21 Dec 2009 11:48:08 +0000 (+0000) Subject: [MRM-1285][MRM-404] preserve correct ordering in download box X-Git-Tag: archiva-1.4-M1~1017^2~58 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=e4c08941e97e42da1b6208259ee2674448438d3a;p=archiva.git [MRM-1285][MRM-404] preserve correct ordering in download box git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@892778 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java index c6998e075..dda04be67 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/ShowArtifactAction.java @@ -22,7 +22,9 @@ package org.apache.maven.archiva.web.action; import java.text.DecimalFormat; import java.util.ArrayList; import java.util.Collection; -import java.util.HashMap; +import java.util.Collections; +import java.util.Comparator; +import java.util.LinkedHashMap; import java.util.List; import java.util.Map; @@ -39,6 +41,7 @@ import org.apache.maven.archiva.repository.ManagedRepositoryContent; import org.apache.maven.archiva.repository.RepositoryContentFactory; import org.apache.maven.archiva.repository.RepositoryException; import org.apache.maven.archiva.repository.layout.LayoutException; +import org.apache.maven.artifact.versioning.DefaultArtifactVersion; /** * Browse the repository. @@ -99,7 +102,7 @@ public class ShowArtifactAction public String artifact() { ProjectVersionMetadata versionMetadata = null; - artifacts = new HashMap>(); + artifacts = new LinkedHashMap>(); List repos = getObservableRepos(); // In the future, this should be replaced by the repository grouping mechanism, so that we are only making @@ -115,7 +118,21 @@ public class ShowArtifactAction { repositoryId = repoId; - Collection artifacts = metadataResolver.getArtifacts( repoId, groupId, artifactId, version ); + List artifacts = new ArrayList( + metadataResolver.getArtifacts( repoId, groupId, artifactId, version ) ); + Collections.sort( artifacts, new Comparator() + { + public int compare( ArtifactMetadata o1, ArtifactMetadata o2 ) + { + // sort by version (reverse), then ID + // TODO: move version sorting into repository handling (maven2 specific), and perhaps add a + // way to get latest instead + int result = new DefaultArtifactVersion( o2.getVersion() ).compareTo( + new DefaultArtifactVersion( o1.getVersion() ) ); + return result != 0 ? result : o1.getId().compareTo( o2.getId() ); + } + } ); + for ( ArtifactMetadata artifact : artifacts ) { List l = this.artifacts.get( artifact.getVersion() ); @@ -158,7 +175,7 @@ public class ShowArtifactAction public String mailingLists() { String result = artifact(); - + this.mailingLists = model.getMailingLists(); return result; @@ -281,7 +298,7 @@ public class ShowArtifactAction return dependees; } - public String getRepositoryId() + public String getRepositoryId() { return repositoryId; } @@ -317,6 +334,7 @@ public class ShowArtifactAction } // TODO: move this into the artifact metadata itself via facets where necessary + public class ArtifactDownloadInfo { private String type;