}
Set<String> namespaces = new LinkedHashSet<String>();
+
+ // 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
+ // is essentially presentation code
+ Set<String> namespacesToCollapse = 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
- // it is located here to avoid the content repository implementation needing to do too much for what
- // is essentially presentation code
- for ( String n : rootNamespaces )
- {
- // TODO: check performance of this
- namespaces.add( collapseNamespaces( repoId, n ) );
- }
+ namespacesToCollapse.addAll( metadataResolver.getRootNamespaces( repoId ) );
+ }
+
+ for ( String n : namespacesToCollapse )
+ {
+ // TODO: check performance of this
+ namespaces.add( collapseNamespaces( selectedRepos, n ) );
}
this.namespaces = getSortedList( namespaces );
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 ( log.isDebugEnabled() )
}
else
{
- Collection<String> projects = metadataResolver.getProjects( repoId, n );
- if ( projects != null && !projects.isEmpty() )
+ for ( String repoId : repoIds )
{
- if ( log.isDebugEnabled() )
+ Collection<String> projects = metadataResolver.getProjects( repoId, n );
+ if ( projects != null && !projects.isEmpty() )
{
- log.debug( n + " is not collapsible as it has projects" );
+ if ( log.isDebugEnabled() )
+ {
+ log.debug( n + " is not collapsible as it has projects" );
+ }
+ return n;
}
- return n;
- }
- else
- {
- return collapseNamespaces( repoId, n + "." + subNamespaces.iterator().next() );
}
+ return collapseNamespaces( repoIds, n + "." + subNamespaces.iterator().next() );
}
}
return GlobalResults.ACCESS_TO_NO_REPOS;
}
- Set<String> namespaces = new LinkedHashSet<String>();
Set<String> projects = new LinkedHashSet<String>();
+
+ Set<String> namespacesToCollapse = new LinkedHashSet<String>();
for ( String repoId : selectedRepos )
{
- Collection<String> childNamespaces = metadataResolver.getNamespaces( repoId, groupId );
- // 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
- // is essentially presentation code
- for ( String n : childNamespaces )
- {
- // TODO: check performance of this
- namespaces.add( collapseNamespaces( repoId, groupId + "." + n ) );
- }
+ 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
+ // it is located here to avoid the content repository implementation needing to do too much for what
+ // is essentially presentation code
+ Set<String> namespaces = new LinkedHashSet<String>();
+ for ( String n : namespacesToCollapse )
+ {
+ // TODO: check performance of this
+ namespaces.add( collapseNamespaces( selectedRepos, groupId + "." + n ) );
+ }
+
this.namespaces = getSortedList( namespaces );
this.projectIds = getSortedList( projects );
return SUCCESS;
private Map<String, List<ProjectVersionReference>> references =
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>>();
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>();
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 + "." ) )
{
return namespaces;
}
- public Collection<String> getNamespaces( String repoId, String namespace )
- {
- return getNamespaces( namespace );
- }
-
public Collection<String> getProjects( String repoId, String namespace )
{
Collection<String> list = projectsInNamespace.get( namespace );
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 );
}
}
Arrays.asList( "org.apache.archiva", "commons-lang", "org.apache.maven", "com.sun", "com.oracle",
"repeat.repeat" );
+ private static final String OTHER_TEST_REPO = "other-repo";
+
public void testInstantiation()
{
assertFalse( action == lookup( Action.class, ACTION_HINT ) );
public void testBrowse()
{
- metadataResolver.setNamespaces( GROUPS );
+ metadataResolver.setNamespaces( TEST_REPO, GROUPS );
String result = action.browse();
assertSuccessResult( result );
String selectedGroupId = "org";
List<String> groups = Arrays.asList( "org.apache.archiva", "org.apache.maven" );
- metadataResolver.setNamespaces( groups );
+ metadataResolver.setNamespaces( TEST_REPO, groups );
action.setGroupId( selectedGroupId );
String result = action.browseGroup();
assertSuccessResult( result );
String selectedGroupId = "org.apache";
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() );
action.setGroupId( selectedGroupId );
String result = action.browseGroup();
{
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
metadataResolver.setProjectVersion( TEST_REPO, "org.apache", "apache", new ProjectVersionMetadata() );
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()
{
String artifacts = "apache";
String selectedGroupId = "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
metadataResolver.setProjectVersion( TEST_REPO, "org.apache", "apache", new ProjectVersionMetadata() );