[MRM-1283] collapse groups properly across multiple repositories

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@893683 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2009-12-24 01:58:25 +00:00
parent 0f2abe9bda
commit 9076b869b3
3 changed files with 76 additions and 46 deletions

View File

@ -69,26 +69,33 @@ public class BrowseAction
} }
Set<String> namespaces = new LinkedHashSet<String>(); Set<String> namespaces = new LinkedHashSet<String>();
for ( String repoId : selectedRepos )
{
Collection<String> rootNamespaces = metadataResolver.getRootNamespaces( repoId );
// TODO: this logic should be optional, particularly remembering we want to keep this code simple // TODO: this logic should be optional, particularly remembering we want to keep this code simple
// it is located here to avoid the content repository implementation needing to do too much for what // it is located here to avoid the content repository implementation needing to do too much for what
// is essentially presentation code // is essentially presentation code
for ( String n : rootNamespaces ) Set<String> namespacesToCollapse = new LinkedHashSet<String>();
for ( String repoId : selectedRepos )
{
namespacesToCollapse.addAll( metadataResolver.getRootNamespaces( repoId ) );
}
for ( String n : namespacesToCollapse )
{ {
// TODO: check performance of this // TODO: check performance of this
namespaces.add( collapseNamespaces( repoId, n ) ); namespaces.add( collapseNamespaces( selectedRepos, n ) );
}
} }
this.namespaces = getSortedList( namespaces ); this.namespaces = getSortedList( namespaces );
return SUCCESS; return SUCCESS;
} }
private String collapseNamespaces( String repoId, String n ) private String collapseNamespaces( Collection<String> repoIds, String n )
{ {
Collection<String> subNamespaces = metadataResolver.getNamespaces( repoId, n ); Set<String> subNamespaces = new LinkedHashSet<String>();
for ( String repoId : repoIds )
{
subNamespaces.addAll( metadataResolver.getNamespaces( repoId, n ) );
}
if ( subNamespaces.size() != 1 ) if ( subNamespaces.size() != 1 )
{ {
if ( log.isDebugEnabled() ) if ( log.isDebugEnabled() )
@ -98,6 +105,8 @@ public class BrowseAction
return n; return n;
} }
else else
{
for ( String repoId : repoIds )
{ {
Collection<String> projects = metadataResolver.getProjects( repoId, n ); Collection<String> projects = metadataResolver.getProjects( repoId, n );
if ( projects != null && !projects.isEmpty() ) if ( projects != null && !projects.isEmpty() )
@ -108,10 +117,8 @@ public class BrowseAction
} }
return n; return n;
} }
else
{
return collapseNamespaces( repoId, n + "." + subNamespaces.iterator().next() );
} }
return collapseNamespaces( repoIds, n + "." + subNamespaces.iterator().next() );
} }
} }
@ -130,21 +137,24 @@ public class BrowseAction
return GlobalResults.ACCESS_TO_NO_REPOS; return GlobalResults.ACCESS_TO_NO_REPOS;
} }
Set<String> namespaces = new LinkedHashSet<String>();
Set<String> projects = new LinkedHashSet<String>(); Set<String> projects = new LinkedHashSet<String>();
Set<String> namespacesToCollapse = new LinkedHashSet<String>();
for ( String repoId : selectedRepos ) for ( String repoId : selectedRepos )
{ {
Collection<String> childNamespaces = metadataResolver.getNamespaces( repoId, groupId ); namespacesToCollapse.addAll( metadataResolver.getNamespaces( repoId, groupId ) );
projects.addAll( metadataResolver.getProjects( repoId, groupId ) );
}
// TODO: this logic should be optional, particularly remembering we want to keep this code simple // TODO: this logic should be optional, particularly remembering we want to keep this code simple
// it is located here to avoid the content repository implementation needing to do too much for what // it is located here to avoid the content repository implementation needing to do too much for what
// is essentially presentation code // is essentially presentation code
for ( String n : childNamespaces ) Set<String> namespaces = new LinkedHashSet<String>();
for ( String n : namespacesToCollapse )
{ {
// TODO: check performance of this // TODO: check performance of this
namespaces.add( collapseNamespaces( repoId, groupId + "." + n ) ); namespaces.add( collapseNamespaces( selectedRepos, groupId + "." + n ) );
}
projects.addAll( metadataResolver.getProjects( repoId, groupId ) );
} }
this.namespaces = getSortedList( namespaces ); this.namespaces = getSortedList( namespaces );

View File

@ -43,7 +43,7 @@ public class TestMetadataResolver
private Map<String, List<ProjectVersionReference>> references = private Map<String, List<ProjectVersionReference>> references =
new HashMap<String, List<ProjectVersionReference>>(); new HashMap<String, List<ProjectVersionReference>>();
private List<String> namespaces; private Map<String, List<String>> namespaces = new HashMap<String, List<String>>();
private Map<String, Collection<String>> projectsInNamespace = new HashMap<String, Collection<String>>(); private Map<String, Collection<String>> projectsInNamespace = new HashMap<String, Collection<String>>();
@ -77,14 +77,14 @@ public class TestMetadataResolver
public Collection<String> getRootNamespaces( String repoId ) public Collection<String> getRootNamespaces( String repoId )
{ {
return getNamespaces( null ); return getNamespaces( repoId, null );
} }
private Collection<String> getNamespaces( String baseNamespace ) public Collection<String> getNamespaces( String repoId, String baseNamespace )
{ {
Set<String> namespaces = new LinkedHashSet<String>(); Set<String> namespaces = new LinkedHashSet<String>();
int fromIndex = baseNamespace != null ? baseNamespace.length() + 1 : 0; int fromIndex = baseNamespace != null ? baseNamespace.length() + 1 : 0;
for ( String namespace : this.namespaces ) for ( String namespace : this.namespaces.get( repoId ) )
{ {
if ( baseNamespace == null || namespace.startsWith( baseNamespace + "." ) ) if ( baseNamespace == null || namespace.startsWith( baseNamespace + "." ) )
{ {
@ -102,11 +102,6 @@ public class TestMetadataResolver
return namespaces; return namespaces;
} }
public Collection<String> getNamespaces( String repoId, String namespace )
{
return getNamespaces( namespace );
}
public Collection<String> getProjects( String repoId, String namespace ) public Collection<String> getProjects( String repoId, String namespace )
{ {
Collection<String> list = projectsInNamespace.get( namespace ); Collection<String> list = projectsInNamespace.get( namespace );
@ -167,8 +162,8 @@ public class TestMetadataResolver
this.references.put( createMapKey( repoId, namespace, projectId, projectVersion ), references ); this.references.put( createMapKey( repoId, namespace, projectId, projectVersion ), references );
} }
public void setNamespaces( List<String> namespaces ) public void setNamespaces( String repoId, List<String> namespaces )
{ {
this.namespaces = namespaces; this.namespaces.put( repoId, namespaces );
} }
} }

View File

@ -38,6 +38,8 @@ public class BrowseActionTest
Arrays.asList( "org.apache.archiva", "commons-lang", "org.apache.maven", "com.sun", "com.oracle", Arrays.asList( "org.apache.archiva", "commons-lang", "org.apache.maven", "com.sun", "com.oracle",
"repeat.repeat" ); "repeat.repeat" );
private static final String OTHER_TEST_REPO = "other-repo";
public void testInstantiation() public void testInstantiation()
{ {
assertFalse( action == lookup( Action.class, ACTION_HINT ) ); assertFalse( action == lookup( Action.class, ACTION_HINT ) );
@ -45,7 +47,7 @@ public class BrowseActionTest
public void testBrowse() public void testBrowse()
{ {
metadataResolver.setNamespaces( GROUPS ); metadataResolver.setNamespaces( TEST_REPO, GROUPS );
String result = action.browse(); String result = action.browse();
assertSuccessResult( result ); assertSuccessResult( result );
@ -120,7 +122,7 @@ public class BrowseActionTest
String selectedGroupId = "org"; String selectedGroupId = "org";
List<String> groups = Arrays.asList( "org.apache.archiva", "org.apache.maven" ); List<String> groups = Arrays.asList( "org.apache.archiva", "org.apache.maven" );
metadataResolver.setNamespaces( groups ); metadataResolver.setNamespaces( TEST_REPO, groups );
action.setGroupId( selectedGroupId ); action.setGroupId( selectedGroupId );
String result = action.browseGroup(); String result = action.browseGroup();
assertSuccessResult( result ); assertSuccessResult( result );
@ -141,7 +143,7 @@ public class BrowseActionTest
String selectedGroupId = "org.apache"; String selectedGroupId = "org.apache";
List<String> groups = Arrays.asList( "org.apache.archiva", "org.apache.maven" ); List<String> groups = Arrays.asList( "org.apache.archiva", "org.apache.maven" );
metadataResolver.setNamespaces( groups ); metadataResolver.setNamespaces( TEST_REPO, groups );
metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, artifacts, new ProjectVersionMetadata() ); metadataResolver.setProjectVersion( TEST_REPO, selectedGroupId, artifacts, new ProjectVersionMetadata() );
action.setGroupId( selectedGroupId ); action.setGroupId( selectedGroupId );
String result = action.browseGroup(); String result = action.browseGroup();
@ -161,7 +163,7 @@ public class BrowseActionTest
{ {
List<String> groups = Arrays.asList( "org.apache.archiva", "org.apache" ); List<String> groups = Arrays.asList( "org.apache.archiva", "org.apache" );
metadataResolver.setNamespaces( groups ); metadataResolver.setNamespaces( TEST_REPO, groups );
// add an artifact in the tree to make sure "single" is not collapsed // add an artifact in the tree to make sure "single" is not collapsed
metadataResolver.setProjectVersion( TEST_REPO, "org.apache", "apache", new ProjectVersionMetadata() ); metadataResolver.setProjectVersion( TEST_REPO, "org.apache", "apache", new ProjectVersionMetadata() );
@ -178,13 +180,36 @@ public class BrowseActionTest
assertNull( action.getSharedModel() ); assertNull( action.getSharedModel() );
} }
public void testBrowseWithCollapsedGroupsAndArtifactsAcrossRepositories()
{
setObservableRepos( Arrays.asList( TEST_REPO, OTHER_TEST_REPO ) );
metadataResolver.setNamespaces( TEST_REPO, Arrays.asList( "org.apache.archiva", "org.apache" ) );
metadataResolver.setNamespaces( OTHER_TEST_REPO, Arrays.asList( "org.codehaus.plexus", "org.codehaus" ) );
// add an artifact in the tree to make sure "single" is not collapsed
metadataResolver.setProjectVersion( TEST_REPO, "org.apache", "apache", new ProjectVersionMetadata() );
String result = action.browse();
assertSuccessResult( result );
assertEquals( Collections.singletonList( "org" ), action.getNamespaces() );
assertNull( action.getProjectIds() );
assertNull( action.getProjectVersions() );
assertNull( action.getGroupId() );
assertNull( action.getArtifactId() );
assertNull( action.getRepositoryId() );
assertNull( action.getSharedModel() );
}
public void testBrowseGroupWithCollapsedGroupsAndArtifacts() public void testBrowseGroupWithCollapsedGroupsAndArtifacts()
{ {
String artifacts = "apache"; String artifacts = "apache";
String selectedGroupId = "org.apache"; String selectedGroupId = "org.apache";
List<String> groups = Arrays.asList( "org.apache.archiva", "org.apache" ); List<String> groups = Arrays.asList( "org.apache.archiva", "org.apache" );
metadataResolver.setNamespaces( groups ); metadataResolver.setNamespaces( TEST_REPO, groups );
// add an artifact in the tree to make sure "single" is not collapsed // add an artifact in the tree to make sure "single" is not collapsed
metadataResolver.setProjectVersion( TEST_REPO, "org.apache", "apache", new ProjectVersionMetadata() ); metadataResolver.setProjectVersion( TEST_REPO, "org.apache", "apache", new ProjectVersionMetadata() );