Skip to content

Commit

Permalink
[FIXED JENKINS-35488] Ensure we only ever add each store once
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenc committed Jun 9, 2016
1 parent b8a57fd commit a708241
Showing 1 changed file with 15 additions and 2 deletions.
Expand Up @@ -45,8 +45,10 @@
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import javax.servlet.ServletException;
import jenkins.model.Jenkins;
import net.sf.json.JSONObject;
Expand Down Expand Up @@ -124,6 +126,7 @@ public ModelObject resolveContext(Object context) {
*/
@Restricted(NoExternalUse.class)
public List<StoreItem> getStoreItems(ModelObject context, boolean includeUser) {
Set<String> urls = new HashSet<String>();
List<StoreItem> result = new ArrayList<StoreItem>();
if (context == null) {
StaplerRequest request = Stapler.getCurrentRequest();
Expand All @@ -133,7 +136,12 @@ public List<StoreItem> getStoreItems(ModelObject context, boolean includeUser) {
}
if (context != null) {
for (CredentialsStore store : CredentialsProvider.lookupStores(context)) {
result.add(new StoreItem(store));
StoreItem item = new StoreItem(store);
String url = item.getUrl();
if (item.getUrl() != null && !urls.contains(url)) {
result.add(item);
urls.add(url);
}
}
}
if (includeUser) {
Expand All @@ -152,7 +160,12 @@ public List<StoreItem> getStoreItems(ModelObject context, boolean includeUser) {
}
if (hasPermission) {
for (CredentialsStore store : CredentialsProvider.lookupStores(User.current())) {
result.add(new StoreItem(store));
StoreItem item = new StoreItem(store);
String url = item.getUrl();
if (item.getUrl() != null && !urls.contains(url)) {
result.add(item);
urls.add(url);
}
}
}
}
Expand Down

0 comments on commit a708241

Please sign in to comment.