From 33401e981936f2aa20568ccbeaa0d59bfe6436b4 Mon Sep 17 00:00:00 2001 From: Brett Porter Date: Thu, 10 Dec 2009 02:30:01 +0000 Subject: [PATCH] [MRM-1282] fix problem with getArtifactVersions when there are multiple artifacts git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@889062 13f79535-47bb-0310-9956-ffa450edef68 --- .../repository/file/FileMetadataRepository.java | 3 ++- .../file/FileMetadataRepositoryTest.java | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java index dbef173e7..a280f3c6c 100644 --- a/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java +++ b/archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java @@ -30,6 +30,7 @@ import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.HashMap; +import java.util.HashSet; import java.util.LinkedHashSet; import java.util.List; import java.util.Map; @@ -691,7 +692,7 @@ public class FileMetadataRepository Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY ); - List versions = new ArrayList(); + Set versions = new HashSet(); for ( Map.Entry entry : properties.entrySet() ) { String name = (String) entry.getKey(); diff --git a/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java b/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java index bf9365587..b004a21b1 100644 --- a/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java +++ b/archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java @@ -25,6 +25,7 @@ import java.util.Arrays; import java.util.Collection; import java.util.Collections; import java.util.Date; +import java.util.HashSet; import java.util.List; import java.util.Map; @@ -220,7 +221,21 @@ public class FileMetadataRepositoryTest repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 ); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 ); - assertEquals( Arrays.asList( version2, version1 ), + assertEquals( new HashSet( Arrays.asList( version2, version1 ) ), + repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, + TEST_PROJECT_VERSION ) ); + } + + public void testGetArtifactVersionsMultipleArtifactsSingleVersion() + { + ArtifactMetadata artifact1 = createArtifact(); + artifact1.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" ); + ArtifactMetadata artifact2 = createArtifact(); + artifact2.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "-sources.jar" ); + repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 ); + repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 ); + + assertEquals( Collections.singleton( TEST_PROJECT_VERSION ), repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ); } -- 2.39.5