Skip to content

Commit

Permalink
fix last inconsistencies in generics (use collections, not arrays)
Browse files Browse the repository at this point in the history
  • Loading branch information
twogee committed Sep 17, 2017
1 parent b126634 commit 59fc3a4
Show file tree
Hide file tree
Showing 7 changed files with 66 additions and 75 deletions.
75 changes: 29 additions & 46 deletions src/java/org/apache/ivy/core/search/SearchEngine.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedHashSet;
Expand Down Expand Up @@ -60,9 +61,8 @@ public String[] listTokenValues(String token, Map<String, Object> otherTokenValu
Set<String> entries = new LinkedHashSet<>();

for (DependencyResolver resolver : settings.getResolvers()) {
Map<String, String>[] values = resolver.listTokenValues(new String[] {token},
otherTokenValues);
for (Map<String, String> value : values) {
for (Map<String, String> value : resolver.listTokenValues(
Collections.singleton(token), otherTokenValues)) {
entries.add(value.get(token));
}
}
Expand All @@ -74,11 +74,10 @@ public OrganisationEntry[] listOrganisationEntries() {
Set<OrganisationEntry> entries = new HashSet<>();

for (DependencyResolver resolver : settings.getResolvers()) {
Map<String, String>[] orgs = resolver.listTokenValues(
new String[] {IvyPatternHelper.ORGANISATION_KEY}, new HashMap<String, Object>());
for (Map<String, String> oe : orgs) {
String org = oe.get(IvyPatternHelper.ORGANISATION_KEY);
entries.add(new OrganisationEntry(resolver, org));
for (Map<String, String> oe : resolver.listTokenValues(
Collections.singleton(IvyPatternHelper.ORGANISATION_KEY),
new HashMap<String, Object>())) {
entries.add(new OrganisationEntry(resolver, oe.get(IvyPatternHelper.ORGANISATION_KEY)));
}
}

Expand All @@ -89,9 +88,9 @@ public String[] listOrganisations() {
Set<String> entries = new HashSet<>();

for (DependencyResolver resolver : settings.getResolvers()) {
Map<String, String>[] orgs = resolver.listTokenValues(
new String[] {IvyPatternHelper.ORGANISATION_KEY}, new HashMap<String, Object>());
for (Map<String, String> org : orgs) {
for (Map<String, String> org : resolver.listTokenValues(
Collections.singleton(IvyPatternHelper.ORGANISATION_KEY),
new HashMap<String, Object>())) {
entries.add(org.get(IvyPatternHelper.ORGANISATION_KEY));
}
}
Expand All @@ -106,11 +105,9 @@ public ModuleEntry[] listModuleEntries(OrganisationEntry org) {
tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, org.getOrganisation());

for (DependencyResolver resolver : settings.getResolvers()) {
Map<String, String>[] modules = resolver.listTokenValues(
new String[] {IvyPatternHelper.MODULE_KEY}, tokenValues);
for (Map<String, String> me : modules) {
String module = me.get(IvyPatternHelper.MODULE_KEY);
entries.add(new ModuleEntry(org, module));
for (Map<String, String> me : resolver.listTokenValues(
Collections.singleton(IvyPatternHelper.MODULE_KEY), tokenValues)) {
entries.add(new ModuleEntry(org, me.get(IvyPatternHelper.MODULE_KEY)));
}
}

Expand All @@ -124,9 +121,8 @@ public String[] listModules(String org) {
tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, org);

for (DependencyResolver resolver : settings.getResolvers()) {
Map<String, String>[] modules = resolver.listTokenValues(
new String[] {IvyPatternHelper.MODULE_KEY}, tokenValues);
for (Map<String, String> module : modules) {
for (Map<String, String> module : resolver.listTokenValues(
Collections.singleton(IvyPatternHelper.MODULE_KEY), tokenValues)) {
entries.add(module.get(IvyPatternHelper.MODULE_KEY));
}
}
Expand All @@ -142,9 +138,8 @@ public RevisionEntry[] listRevisionEntries(ModuleEntry module) {
tokenValues.put(IvyPatternHelper.MODULE_KEY, module.getModule());

for (DependencyResolver resolver : settings.getResolvers()) {
Map<String, String>[] revisions = resolver.listTokenValues(
new String[] {IvyPatternHelper.REVISION_KEY}, tokenValues);
for (Map<String, String> revision : revisions) {
for (Map<String, String> revision : resolver.listTokenValues(
Collections.singleton(IvyPatternHelper.REVISION_KEY), tokenValues)) {
entries.add(new RevisionEntry(module, revision.get(IvyPatternHelper.REVISION_KEY)));
}
}
Expand All @@ -160,9 +155,8 @@ public String[] listRevisions(String org, String module) {
tokenValues.put(IvyPatternHelper.MODULE_KEY, module);

for (DependencyResolver resolver : settings.getResolvers()) {
Map<String, String>[] revisions = resolver.listTokenValues(
new String[] {IvyPatternHelper.REVISION_KEY}, tokenValues);
for (Map<String, String> revision : revisions) {
for (Map<String, String> revision : resolver.listTokenValues(
Collections.singleton(IvyPatternHelper.REVISION_KEY), tokenValues)) {
entries.add(revision.get(IvyPatternHelper.REVISION_KEY));
}
}
Expand All @@ -189,17 +183,13 @@ public ModuleId[] listModules(ModuleId moduleCrit, PatternMatcher matcher) {
IvyPatternHelper.ORGANISATION_KEY);
addMatcher(matcher, moduleCrit.getName(), criteria, IvyPatternHelper.MODULE_KEY);

String[] tokensToList = new String[] {IvyPatternHelper.ORGANISATION_KEY,
IvyPatternHelper.MODULE_KEY};

for (DependencyResolver resolver : settings.getResolvers()) {
Map<String, String>[] moduleIdAsMap = resolver.listTokenValues(tokensToList, criteria);
for (Map<String, String> moduleId : moduleIdAsMap) {
String org = moduleId.get(IvyPatternHelper.ORGANISATION_KEY);
String name = moduleId.get(IvyPatternHelper.MODULE_KEY);
ModuleId modId = ModuleId.newInstance(org, name);
ret.add(NameSpaceHelper.transform(modId, resolver.getNamespace()
.getToSystemTransformer()));
for (Map<String, String> moduleId : resolver.listTokenValues(new HashSet<>(
Arrays.asList(IvyPatternHelper.ORGANISATION_KEY, IvyPatternHelper.MODULE_KEY)), criteria)) {
ModuleId modId = ModuleId.newInstance(moduleId.get(IvyPatternHelper.ORGANISATION_KEY),
moduleId.get(IvyPatternHelper.MODULE_KEY));
ret.add(NameSpaceHelper.transform(modId,
resolver.getNamespace().getToSystemTransformer()));
}
}

Expand All @@ -225,12 +215,9 @@ public ModuleRevisionId[] listModules(ModuleRevisionId moduleCrit, PatternMatche
addMatcher(matcher, entry.getValue(), criteria, entry.getKey());
}

String[] tokensToList = moduleCrit.getAttributes().keySet()
.toArray(new String[moduleCrit.getAttributes().size()]);

for (DependencyResolver resolver : settings.getResolvers()) {
Map<String, String>[] moduleIdAsMap = resolver.listTokenValues(tokensToList, criteria);
for (Map<String, String> moduleId : moduleIdAsMap) {
for (Map<String, String> moduleId : resolver.listTokenValues(moduleCrit.getAttributes().keySet(),
criteria)) {
String org = moduleId.get(IvyPatternHelper.ORGANISATION_KEY);
String name = moduleId.get(IvyPatternHelper.MODULE_KEY);
String branch = moduleId.get(IvyPatternHelper.BRANCH_KEY);
Expand Down Expand Up @@ -281,12 +268,9 @@ public ModuleRevisionId[] listModules(DependencyResolver resolver, ModuleRevisio
addMatcher(matcher, entry.getValue(), criteria, entry.getKey());
}

String[] tokensToList = moduleCrit.getAttributes().keySet()
.toArray(new String[moduleCrit.getAttributes().size()]);

Map<String, String>[] moduleIdAsMap = resolver.listTokenValues(tokensToList, criteria);
Set<ModuleRevisionId> result = new LinkedHashSet<>(); // we use a Set to remove duplicates
for (Map<String, String> moduleId : moduleIdAsMap) {
for (Map<String, String> moduleId : resolver.listTokenValues(moduleCrit.getAttributes().keySet(),
criteria)) {
String org = moduleId.get(IvyPatternHelper.ORGANISATION_KEY);
String name = moduleId.get(IvyPatternHelper.MODULE_KEY);
String branch = moduleId.get(IvyPatternHelper.BRANCH_KEY);
Expand Down Expand Up @@ -369,7 +353,6 @@ public Collection<ModuleRevisionId> findModuleRevisionIds(DependencyResolver res
+ " on " + resolverName);
boolean foundModule = false;
for (ModuleEntry mEntry : modules) {

ModuleId foundMid = new ModuleId(mEntry.getOrganisation(), mEntry.getModule());
ModuleId systemMid = foundMid;
if (fromNamespace != null) {
Expand Down
9 changes: 1 addition & 8 deletions src/java/org/apache/ivy/osgi/repo/AbstractOSGiResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -402,15 +402,8 @@ private void filterCapabilityValues(Set<String> capabilityValues,
}
}

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

private Set<Map<String, String>> listTokenValues(Set<String> tokens,
public Set<Map<String, String>> listTokenValues(Set<String> tokens,
Map<String, Object> criteria) {
Map<String, String> stringCriteria = new HashMap<>();
for (Entry<String, Object> entry : criteria.entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,8 @@ protected Collection<String> findArtifactNames(Map<String, String> tokenValues,
return names;
}

@SuppressWarnings("unchecked")
@Override
public Map<String, String>[] listTokenValues(String[] tokens, Map<String, Object> criteria) {
public Set<Map<String, String>> listTokenValues(Set<String> tokens, Map<String, Object> criteria) {
Set<Map<String, String>> result = new LinkedHashSet<>();

// use ivy patterns
Expand All @@ -186,17 +185,17 @@ public Map<String, String>[] listTokenValues(String[] tokens, Map<String, Object
}
}

return result.toArray(new Map[result.size()]);
return result;
}

protected String getModuleDescriptorExtension() {
return "xml";
}

private Set<Map<String, String>> resolveTokenValues(String[] tokens, String pattern,
private Set<Map<String, String>> resolveTokenValues(Set<String> tokens, String pattern,
Map<String, Object> criteria, boolean noMd) {
Set<Map<String, String>> result = new LinkedHashSet<>();
Set<String> tokenSet = new HashSet<>(Arrays.asList(tokens));
Set<String> tokenSet = new HashSet<>(tokens);

Map<String, String> tokenValues = new HashMap<>();
for (Entry<String, Object> entry : criteria.entrySet()) {
Expand Down Expand Up @@ -252,8 +251,7 @@ private Set<Map<String, String>> resolveTokenValues(String[] tokens, String patt
} else if (noMd && "module".equals(token)) {
newCriteria.put("artifact", value);
}
result.addAll(resolveTokenValues(tokenSet.toArray(new String[tokenSet.size()]),
moreResolvedPattern, newCriteria, noMd));
result.addAll(resolveTokenValues(tokenSet, moreResolvedPattern, newCriteria, noMd));
}

return result;
Expand Down
15 changes: 15 additions & 0 deletions src/java/org/apache/ivy/plugins/resolver/AbstractResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@
import java.io.IOException;
import java.util.Arrays;
import java.util.Date;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;

import org.apache.ivy.core.IvyContext;
import org.apache.ivy.core.LogOptions;
Expand Down Expand Up @@ -178,7 +180,20 @@ public String[] listTokenValues(String token, Map<String, String> otherTokenValu
return new String[0];
}

// new API: provide the default implementation for third party extensions that lack it
@SuppressWarnings("deprecation")
public Set<Map<String, String>> listTokenValues(Set<String> tokens, Map<String, Object> criteria) {
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) {
return new Map[0];
}
Expand Down
10 changes: 3 additions & 7 deletions src/java/org/apache/ivy/plugins/resolver/ChainResolver.java
Original file line number Diff line number Diff line change
Expand Up @@ -178,17 +178,13 @@ public ResolvedResource findIvyFileRef(DependencyDescriptor dd, ResolveData data
return null;
}

@SuppressWarnings("unchecked")
@Override
public Map<String, String>[] listTokenValues(String[] tokens, Map<String, Object> criteria) {
public Set<Map<String, String>> listTokenValues(Set<String> tokens, Map<String, Object> criteria) {
Set<Map<String, String>> result = new HashSet<>();
for (DependencyResolver resolver : chain) {
Map<String, String>[] temp = resolver.listTokenValues(tokens,
new HashMap<>(criteria));
result.addAll(Arrays.asList(temp));
result.addAll(resolver.listTokenValues(tokens, new HashMap<>(criteria)));
}

return result.toArray(new Map[result.size()]);
return result;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import java.io.IOException;
import java.text.ParseException;
import java.util.Map;
import java.util.Set;

import org.apache.ivy.core.cache.ArtifactOrigin;
import org.apache.ivy.core.cache.RepositoryCacheManager;
Expand Down Expand Up @@ -188,6 +189,9 @@ ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
* the token which have values
* @return the list of token values, must not be <code>null</code>
*/
Set<Map<String, String>> listTokenValues(Set<String> tokens, Map<String, Object> criteria);

@Deprecated
Map<String, String>[] listTokenValues(String[] tokens, Map<String, Object> criteria);

OrganisationEntry[] listOrganisations();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -153,7 +154,6 @@ public void testInitFromConf() throws Exception {
l.get(0));
}

@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void testMaven2Listing() throws Exception {
IBiblioResolver resolver = new IBiblioResolver();
Expand All @@ -171,20 +171,22 @@ public void testMaven2Listing() throws Exception {
RevisionEntry[] revisions = resolver.listRevisions(modules[0]);
assertTrue(revisions.length > 0);

Map otherTokenValues = new HashMap();
Map<String, String> otherTokenValues = new HashMap<>();
otherTokenValues.put(IvyPatternHelper.ORGANISATION_KEY, "commons-lang");
String[] values = resolver.listTokenValues(IvyPatternHelper.MODULE_KEY, otherTokenValues);
assertNotNull(values);
assertEquals(1, values.length);
assertEquals("commons-lang", values[0]);

Map[] valuesMaps = resolver.listTokenValues(new String[] {IvyPatternHelper.MODULE_KEY},
otherTokenValues);
Set vals = new HashSet();
for (Map valuesMap : valuesMaps) {
Map<String, Object> criteria = new HashMap<>();
criteria.putAll(otherTokenValues);
Set<Map<String, String>> valuesMaps = resolver.listTokenValues(
Collections.singleton(IvyPatternHelper.MODULE_KEY), criteria);
Set<String> vals = new HashSet<>();
for (Map<String, String> valuesMap : valuesMaps) {
vals.add(valuesMap.get(IvyPatternHelper.MODULE_KEY));
}
values = (String[]) vals.toArray(new String[vals.size()]);
values = vals.toArray(new String[vals.size()]);
assertEquals(1, values.length);
assertEquals("commons-lang", values[0]);
}
Expand Down

0 comments on commit 59fc3a4

Please sign in to comment.