Skip to content

Commit 036ac6d

Browse files
committed
fix last inconsistencies in generics (use collections, not arrays)
1 parent cc7509b commit 036ac6d

File tree

7 files changed

+63
-68
lines changed

7 files changed

+63
-68
lines changed

src/java/org/apache/ivy/core/search/SearchEngine.java

+25-39
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import java.util.ArrayList;
2121
import java.util.Arrays;
2222
import java.util.Collection;
23+
import java.util.Collections;
2324
import java.util.HashMap;
2425
import java.util.HashSet;
2526
import java.util.LinkedHashSet;
@@ -60,9 +61,8 @@ public String[] listTokenValues(String token, Map<String, Object> otherTokenValu
6061
Set<String> entries = new LinkedHashSet<>();
6162

6263
for (DependencyResolver resolver : settings.getResolvers()) {
63-
Map<String, String>[] values = resolver.listTokenValues(new String[] {token},
64-
otherTokenValues);
65-
for (Map<String, String> value : values) {
64+
for (Map<String, String> value : resolver.listTokenValues(
65+
Collections.singleton(token), otherTokenValues)) {
6666
entries.add(value.get(token));
6767
}
6868
}
@@ -74,9 +74,9 @@ public OrganisationEntry[] listOrganisationEntries() {
7474
Set<OrganisationEntry> entries = new HashSet<>();
7575

7676
for (DependencyResolver resolver : settings.getResolvers()) {
77-
Map<String, String>[] orgs = resolver.listTokenValues(
78-
new String[] {IvyPatternHelper.ORGANISATION_KEY}, new HashMap<String, Object>());
79-
for (Map<String, String> oe : orgs) {
77+
for (Map<String, String> oe : resolver.listTokenValues(
78+
Collections.singleton(IvyPatternHelper.ORGANISATION_KEY),
79+
new HashMap<String, Object>())) {
8080
String org = oe.get(IvyPatternHelper.ORGANISATION_KEY);
8181
entries.add(new OrganisationEntry(resolver, org));
8282
}
@@ -89,9 +89,9 @@ public String[] listOrganisations() {
8989
Set<String> entries = new HashSet<>();
9090

9191
for (DependencyResolver resolver : settings.getResolvers()) {
92-
Map<String, String>[] orgs = resolver.listTokenValues(
93-
new String[] {IvyPatternHelper.ORGANISATION_KEY}, new HashMap<String, Object>());
94-
for (Map<String, String> org : orgs) {
92+
for (Map<String, String> org : resolver.listTokenValues(
93+
Collections.singleton(IvyPatternHelper.ORGANISATION_KEY),
94+
new HashMap<String, Object>())) {
9595
entries.add(org.get(IvyPatternHelper.ORGANISATION_KEY));
9696
}
9797
}
@@ -106,9 +106,8 @@ public ModuleEntry[] listModuleEntries(OrganisationEntry org) {
106106
tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, org.getOrganisation());
107107

108108
for (DependencyResolver resolver : settings.getResolvers()) {
109-
Map<String, String>[] modules = resolver.listTokenValues(
110-
new String[] {IvyPatternHelper.MODULE_KEY}, tokenValues);
111-
for (Map<String, String> me : modules) {
109+
for (Map<String, String> me : resolver.listTokenValues(
110+
Collections.singleton(IvyPatternHelper.MODULE_KEY), tokenValues)) {
112111
String module = me.get(IvyPatternHelper.MODULE_KEY);
113112
entries.add(new ModuleEntry(org, module));
114113
}
@@ -124,9 +123,8 @@ public String[] listModules(String org) {
124123
tokenValues.put(IvyPatternHelper.ORGANISATION_KEY, org);
125124

126125
for (DependencyResolver resolver : settings.getResolvers()) {
127-
Map<String, String>[] modules = resolver.listTokenValues(
128-
new String[] {IvyPatternHelper.MODULE_KEY}, tokenValues);
129-
for (Map<String, String> module : modules) {
126+
for (Map<String, String> module : resolver.listTokenValues(
127+
Collections.singleton(IvyPatternHelper.MODULE_KEY), tokenValues)) {
130128
entries.add(module.get(IvyPatternHelper.MODULE_KEY));
131129
}
132130
}
@@ -142,9 +140,8 @@ public RevisionEntry[] listRevisionEntries(ModuleEntry module) {
142140
tokenValues.put(IvyPatternHelper.MODULE_KEY, module.getModule());
143141

144142
for (DependencyResolver resolver : settings.getResolvers()) {
145-
Map<String, String>[] revisions = resolver.listTokenValues(
146-
new String[] {IvyPatternHelper.REVISION_KEY}, tokenValues);
147-
for (Map<String, String> revision : revisions) {
143+
for (Map<String, String> revision : resolver.listTokenValues(
144+
Collections.singleton(IvyPatternHelper.REVISION_KEY), tokenValues)) {
148145
entries.add(new RevisionEntry(module, revision.get(IvyPatternHelper.REVISION_KEY)));
149146
}
150147
}
@@ -160,9 +157,8 @@ public String[] listRevisions(String org, String module) {
160157
tokenValues.put(IvyPatternHelper.MODULE_KEY, module);
161158

162159
for (DependencyResolver resolver : settings.getResolvers()) {
163-
Map<String, String>[] revisions = resolver.listTokenValues(
164-
new String[] {IvyPatternHelper.REVISION_KEY}, tokenValues);
165-
for (Map<String, String> revision : revisions) {
160+
for (Map<String, String> revision : resolver.listTokenValues(
161+
Collections.singleton(IvyPatternHelper.REVISION_KEY), tokenValues)) {
166162
entries.add(revision.get(IvyPatternHelper.REVISION_KEY));
167163
}
168164
}
@@ -189,17 +185,14 @@ public ModuleId[] listModules(ModuleId moduleCrit, PatternMatcher matcher) {
189185
IvyPatternHelper.ORGANISATION_KEY);
190186
addMatcher(matcher, moduleCrit.getName(), criteria, IvyPatternHelper.MODULE_KEY);
191187

192-
String[] tokensToList = new String[] {IvyPatternHelper.ORGANISATION_KEY,
193-
IvyPatternHelper.MODULE_KEY};
194-
195188
for (DependencyResolver resolver : settings.getResolvers()) {
196-
Map<String, String>[] moduleIdAsMap = resolver.listTokenValues(tokensToList, criteria);
197-
for (Map<String, String> moduleId : moduleIdAsMap) {
189+
for (Map<String, String> moduleId : resolver.listTokenValues(new HashSet<>(
190+
Arrays.asList(IvyPatternHelper.ORGANISATION_KEY, IvyPatternHelper.MODULE_KEY)), criteria)) {
198191
String org = moduleId.get(IvyPatternHelper.ORGANISATION_KEY);
199192
String name = moduleId.get(IvyPatternHelper.MODULE_KEY);
200193
ModuleId modId = ModuleId.newInstance(org, name);
201-
ret.add(NameSpaceHelper.transform(modId, resolver.getNamespace()
202-
.getToSystemTransformer()));
194+
ret.add(NameSpaceHelper.transform(modId,
195+
resolver.getNamespace().getToSystemTransformer()));
203196
}
204197
}
205198

@@ -225,12 +218,9 @@ public ModuleRevisionId[] listModules(ModuleRevisionId moduleCrit, PatternMatche
225218
addMatcher(matcher, entry.getValue(), criteria, entry.getKey());
226219
}
227220

228-
String[] tokensToList = moduleCrit.getAttributes().keySet()
229-
.toArray(new String[moduleCrit.getAttributes().size()]);
230-
231221
for (DependencyResolver resolver : settings.getResolvers()) {
232-
Map<String, String>[] moduleIdAsMap = resolver.listTokenValues(tokensToList, criteria);
233-
for (Map<String, String> moduleId : moduleIdAsMap) {
222+
for (Map<String, String> moduleId : resolver.listTokenValues(moduleCrit.getAttributes().keySet(),
223+
criteria)) {
234224
String org = moduleId.get(IvyPatternHelper.ORGANISATION_KEY);
235225
String name = moduleId.get(IvyPatternHelper.MODULE_KEY);
236226
String branch = moduleId.get(IvyPatternHelper.BRANCH_KEY);
@@ -281,12 +271,9 @@ public ModuleRevisionId[] listModules(DependencyResolver resolver, ModuleRevisio
281271
addMatcher(matcher, entry.getValue(), criteria, entry.getKey());
282272
}
283273

284-
String[] tokensToList = moduleCrit.getAttributes().keySet()
285-
.toArray(new String[moduleCrit.getAttributes().size()]);
286-
287-
Map<String, String>[] moduleIdAsMap = resolver.listTokenValues(tokensToList, criteria);
288274
Set<ModuleRevisionId> result = new LinkedHashSet<>(); // we use a Set to remove duplicates
289-
for (Map<String, String> moduleId : moduleIdAsMap) {
275+
for (Map<String, String> moduleId : resolver.listTokenValues(moduleCrit.getAttributes().keySet(),
276+
criteria)) {
290277
String org = moduleId.get(IvyPatternHelper.ORGANISATION_KEY);
291278
String name = moduleId.get(IvyPatternHelper.MODULE_KEY);
292279
String branch = moduleId.get(IvyPatternHelper.BRANCH_KEY);
@@ -369,7 +356,6 @@ public Collection<ModuleRevisionId> findModuleRevisionIds(DependencyResolver res
369356
+ " on " + resolverName);
370357
boolean foundModule = false;
371358
for (ModuleEntry mEntry : modules) {
372-
373359
ModuleId foundMid = new ModuleId(mEntry.getOrganisation(), mEntry.getModule());
374360
ModuleId systemMid = foundMid;
375361
if (fromNamespace != null) {

src/java/org/apache/ivy/osgi/repo/AbstractOSGiResolver.java

+1-8
Original file line numberDiff line numberDiff line change
@@ -402,15 +402,8 @@ private void filterCapabilityValues(Set<String> capabilityValues,
402402
}
403403
}
404404

405-
@SuppressWarnings("unchecked")
406405
@Override
407-
public Map<String, String>[] listTokenValues(String[] tokens, Map<String, Object> criteria) {
408-
Set<String> tokenSet = new HashSet<>(Arrays.asList(tokens));
409-
Set<Map<String, String>> listTokenValues = listTokenValues(tokenSet, criteria);
410-
return listTokenValues.toArray(new Map[listTokenValues.size()]);
411-
}
412-
413-
private Set<Map<String, String>> listTokenValues(Set<String> tokens,
406+
public Set<Map<String, String>> listTokenValues(Set<String> tokens,
414407
Map<String, Object> criteria) {
415408
Map<String, String> stringCriteria = new HashMap<>();
416409
for (Entry<String, Object> entry : criteria.entrySet()) {

src/java/org/apache/ivy/plugins/resolver/AbstractPatternsBasedResolver.java

+5-7
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,8 @@ protected Collection<String> findArtifactNames(Map<String, String> tokenValues,
158158
return names;
159159
}
160160

161-
@SuppressWarnings("unchecked")
162161
@Override
163-
public Map<String, String>[] listTokenValues(String[] tokens, Map<String, Object> criteria) {
162+
public Set<Map<String, String>> listTokenValues(Set<String> tokens, Map<String, Object> criteria) {
164163
Set<Map<String, String>> result = new LinkedHashSet<>();
165164

166165
// use ivy patterns
@@ -186,17 +185,17 @@ public Map<String, String>[] listTokenValues(String[] tokens, Map<String, Object
186185
}
187186
}
188187

189-
return result.toArray(new Map[result.size()]);
188+
return result;
190189
}
191190

192191
protected String getModuleDescriptorExtension() {
193192
return "xml";
194193
}
195194

196-
private Set<Map<String, String>> resolveTokenValues(String[] tokens, String pattern,
195+
private Set<Map<String, String>> resolveTokenValues(Set<String> tokens, String pattern,
197196
Map<String, Object> criteria, boolean noMd) {
198197
Set<Map<String, String>> result = new LinkedHashSet<>();
199-
Set<String> tokenSet = new HashSet<>(Arrays.asList(tokens));
198+
Set<String> tokenSet = new HashSet<>(tokens);
200199

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

259257
return result;

src/java/org/apache/ivy/plugins/resolver/AbstractResolver.java

+15
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@
2121
import java.io.IOException;
2222
import java.util.Arrays;
2323
import java.util.Date;
24+
import java.util.HashSet;
2425
import java.util.Map;
26+
import java.util.Set;
2527

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

183+
// new API: provide the default implementation for third party extensions that lack it
184+
@SuppressWarnings("deprecation")
185+
public Set<Map<String, String>> listTokenValues(Set<String> tokens, Map<String, Object> criteria) {
186+
Set<Map<String, String>> tokenValueSet = new HashSet<>();
187+
for (Map<String, String> tokenValue :
188+
listTokenValues(tokens.toArray(new String[tokens.size()]), criteria)) {
189+
tokenValueSet.add(tokenValue);
190+
}
191+
return tokenValueSet;
192+
}
193+
194+
// old API
181195
@SuppressWarnings("unchecked")
196+
@Deprecated
182197
public Map<String, String>[] listTokenValues(String[] tokens, Map<String, Object> criteria) {
183198
return new Map[0];
184199
}

src/java/org/apache/ivy/plugins/resolver/ChainResolver.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -178,17 +178,13 @@ public ResolvedResource findIvyFileRef(DependencyDescriptor dd, ResolveData data
178178
return null;
179179
}
180180

181-
@SuppressWarnings("unchecked")
182181
@Override
183-
public Map<String, String>[] listTokenValues(String[] tokens, Map<String, Object> criteria) {
182+
public Set<Map<String, String>> listTokenValues(Set<String> tokens, Map<String, Object> criteria) {
184183
Set<Map<String, String>> result = new HashSet<>();
185184
for (DependencyResolver resolver : chain) {
186-
Map<String, String>[] temp = resolver.listTokenValues(tokens,
187-
new HashMap<>(criteria));
188-
result.addAll(Arrays.asList(temp));
185+
result.addAll(resolver.listTokenValues(tokens, new HashMap<>(criteria)));
189186
}
190-
191-
return result.toArray(new Map[result.size()]);
187+
return result;
192188
}
193189

194190
@Override

src/java/org/apache/ivy/plugins/resolver/DependencyResolver.java

+4
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.io.IOException;
2222
import java.text.ParseException;
2323
import java.util.Map;
24+
import java.util.Set;
2425

2526
import org.apache.ivy.core.cache.ArtifactOrigin;
2627
import org.apache.ivy.core.cache.RepositoryCacheManager;
@@ -188,6 +189,9 @@ ResolvedModuleRevision getDependency(DependencyDescriptor dd, ResolveData data)
188189
* the token which have values
189190
* @return the list of token values, must not be <code>null</code>
190191
*/
192+
Set<Map<String, String>> listTokenValues(Set<String> tokens, Map<String, Object> criteria);
193+
194+
@Deprecated
191195
Map<String, String>[] listTokenValues(String[] tokens, Map<String, Object> criteria);
192196

193197
OrganisationEntry[] listOrganisations();

test/java/org/apache/ivy/plugins/resolver/IBiblioResolverTest.java

+10-7
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
import static org.junit.Assert.assertNull;
2424
import static org.junit.Assert.assertTrue;
2525

26+
import java.util.Arrays;
27+
import java.util.Collections;
2628
import java.util.HashMap;
2729
import java.util.HashSet;
2830
import java.util.List;
@@ -161,7 +163,6 @@ public void testInitFromConf() throws Exception {
161163
l.get(0));
162164
}
163165

164-
@SuppressWarnings({"rawtypes", "unchecked"})
165166
@Test
166167
public void testMaven2Listing() throws Exception {
167168
IBiblioResolver resolver = new IBiblioResolver();
@@ -179,20 +180,22 @@ public void testMaven2Listing() throws Exception {
179180
RevisionEntry[] revisions = resolver.listRevisions(modules[0]);
180181
assertTrue(revisions.length > 0);
181182

182-
Map otherTokenValues = new HashMap();
183+
Map<String, String> otherTokenValues = new HashMap<>();
183184
otherTokenValues.put(IvyPatternHelper.ORGANISATION_KEY, "commons-lang");
184185
String[] values = resolver.listTokenValues(IvyPatternHelper.MODULE_KEY, otherTokenValues);
185186
assertNotNull(values);
186187
assertEquals(1, values.length);
187188
assertEquals("commons-lang", values[0]);
188189

189-
Map[] valuesMaps = resolver.listTokenValues(new String[] {IvyPatternHelper.MODULE_KEY},
190-
otherTokenValues);
191-
Set vals = new HashSet();
192-
for (Map valuesMap : valuesMaps) {
190+
Map<String, Object> criteria = new HashMap<>();
191+
criteria.putAll(otherTokenValues);
192+
Set<Map<String, String>> valuesMaps = resolver.listTokenValues(
193+
Collections.singleton(IvyPatternHelper.MODULE_KEY), criteria);
194+
Set<String> vals = new HashSet<>();
195+
for (Map<String, String> valuesMap : valuesMaps) {
193196
vals.add(valuesMap.get(IvyPatternHelper.MODULE_KEY));
194197
}
195-
values = (String[]) vals.toArray(new String[vals.size()]);
198+
values = vals.toArray(new String[vals.size()]);
196199
assertEquals(1, values.length);
197200
assertEquals("commons-lang", values[0]);
198201
}

0 commit comments

Comments
 (0)