Skip to content

Commit

Permalink
right semantics for backwards compatibility
Browse files Browse the repository at this point in the history
  • Loading branch information
twogee committed Jul 28, 2017
1 parent e849096 commit cf1554f
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 6 deletions.
14 changes: 10 additions & 4 deletions src/java/org/apache/ivy/plugins/resolver/AbstractResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
import java.io.File;
import java.io.IOException;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.HashSet;
import java.util.Map;
Expand Down Expand Up @@ -181,15 +180,22 @@ public String[] listTokenValues(String token, Map<String, String> otherTokenValu
return new String[0];
}

// new API: provide the default implementation for third party implementations that lack it
@SuppressWarnings("deprecation")
public Set<Map<String, String>> listTokenValues(Set<String> tokens, Map<String, Object> criteria) {
return Collections.emptySet();
Set<Map<String, String>> tokenValueSet = new HashSet<>();
for (Map<String, String> tokenValue :
listTokenValues(tokens.toArray(new String[tokens.size()]), criteria)) {
tokenValueSet.add(tokenValue);
}
return tokenValueSet;
}

// old API
@SuppressWarnings("unchecked")
@Deprecated
public Map<String, String>[] listTokenValues(String[] tokens, Map<String, Object> criteria) {
Set<Map<String, String>> listTokenValues = listTokenValues(new HashSet<>(Arrays.asList(tokens)), criteria);
return listTokenValues.toArray(new Map[listTokenValues.size()]);
return new Map[0];
}

public OrganisationEntry[] listOrganisations() {
Expand Down
13 changes: 11 additions & 2 deletions src/java/org/apache/ivy/plugins/resolver/ChainResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -181,12 +181,21 @@ public ResolvedResource findIvyFileRef(DependencyDescriptor dd, ResolveData data
}

@Override
@SuppressWarnings("deprecation")
public Set<Map<String, String>> listTokenValues(Set<String> tokens, Map<String, Object> criteria) {
Set<Map<String, String>> result = new HashSet<>();
for (DependencyResolver resolver : chain) {
result.addAll(resolver.listTokenValues(tokens, new HashMap<>(criteria)));
if (resolver instanceof AbstractResolver) {
// new API
result.addAll(resolver.listTokenValues(tokens, new HashMap<>(criteria)));
} else {
// old API
for (Map<String, String> tokenValue :
resolver.listTokenValues(tokens.toArray(new String[tokens.size()]), criteria)) {
result.add(tokenValue);
}
}
}

return result;
}

Expand Down

0 comments on commit cf1554f

Please sign in to comment.