mirror of https://github.com/apache/ant-ivy
fix last inconsistencies in generics (use collections, not arrays)
This commit is contained in:
parent
87de654504
commit
4aa8401e77
|
|
@ -20,6 +20,7 @@ package org.apache.ivy.core.search;
|
|||
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;
|
||||
|
|
@ -59,9 +60,8 @@ public class SearchEngine {
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
@ -73,11 +73,10 @@ public class SearchEngine {
|
|||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -88,9 +87,9 @@ public class SearchEngine {
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
@ -105,11 +104,9 @@ public class SearchEngine {
|
|||
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)));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -123,9 +120,8 @@ public class SearchEngine {
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
@ -141,9 +137,8 @@ public class SearchEngine {
|
|||
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)));
|
||||
}
|
||||
}
|
||||
|
|
@ -159,9 +154,8 @@ public class SearchEngine {
|
|||
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));
|
||||
}
|
||||
}
|
||||
|
|
@ -188,17 +182,13 @@ public class SearchEngine {
|
|||
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()));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -224,12 +214,9 @@ public class SearchEngine {
|
|||
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);
|
||||
|
|
@ -280,12 +267,9 @@ public class SearchEngine {
|
|||
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);
|
||||
|
|
@ -368,7 +352,6 @@ public class SearchEngine {
|
|||
+ " on " + resolverName);
|
||||
boolean foundModule = false;
|
||||
for (ModuleEntry mEntry : modules) {
|
||||
|
||||
ModuleId foundMid = new ModuleId(mEntry.getOrganisation(), mEntry.getModule());
|
||||
ModuleId systemMid = foundMid;
|
||||
if (fromNamespace != null) {
|
||||
|
|
|
|||
|
|
@ -403,15 +403,8 @@ public abstract class AbstractOSGiResolver extends BasicResolver {
|
|||
}
|
||||
}
|
||||
|
||||
@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 (Map.Entry<String, Object> entry : criteria.entrySet()) {
|
||||
|
|
|
|||
|
|
@ -156,9 +156,8 @@ public abstract class AbstractPatternsBasedResolver extends BasicResolver {
|
|||
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
|
||||
|
|
@ -184,17 +183,17 @@ public abstract class AbstractPatternsBasedResolver extends BasicResolver {
|
|||
}
|
||||
}
|
||||
|
||||
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 (Map.Entry<String, Object> entry : criteria.entrySet()) {
|
||||
|
|
@ -250,8 +249,7 @@ public abstract class AbstractPatternsBasedResolver extends BasicResolver {
|
|||
} 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;
|
||||
|
|
|
|||
|
|
@ -178,7 +178,9 @@ public abstract class AbstractResolver implements DependencyResolver, HasLatestS
|
|||
return new String[0];
|
||||
}
|
||||
|
||||
// old API
|
||||
@SuppressWarnings("unchecked")
|
||||
@Deprecated
|
||||
public Map<String, String>[] listTokenValues(String[] tokens, Map<String, Object> criteria) {
|
||||
return new Map[0];
|
||||
}
|
||||
|
|
|
|||
|
|
@ -178,17 +178,13 @@ public class ChainResolver extends AbstractResolver {
|
|||
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
|
||||
|
|
|
|||
|
|
@ -20,7 +20,9 @@ package org.apache.ivy.plugins.resolver;
|
|||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.text.ParseException;
|
||||
import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
import org.apache.ivy.core.cache.ArtifactOrigin;
|
||||
import org.apache.ivy.core.cache.RepositoryCacheManager;
|
||||
|
|
@ -188,6 +190,17 @@ public interface DependencyResolver {
|
|||
* the token which have values
|
||||
* @return the list of token values, must not be <code>null</code>
|
||||
*/
|
||||
default 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;
|
||||
}
|
||||
|
||||
// http://www.tothenew.com/blog/why-is-generic-array-creation-not-allowed-in-java/
|
||||
@Deprecated
|
||||
Map<String, String>[] listTokenValues(String[] tokens, Map<String, Object> criteria);
|
||||
|
||||
OrganisationEntry[] listOrganisations();
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@ import static org.junit.Assert.assertNotNull;
|
|||
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;
|
||||
|
|
@ -155,7 +156,6 @@ public class IBiblioResolverTest extends AbstractDependencyResolverTest {
|
|||
l.get(0));
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@Test
|
||||
public void testMaven2Listing() {
|
||||
IBiblioResolver resolver = new IBiblioResolver();
|
||||
|
|
@ -173,20 +173,22 @@ public class IBiblioResolverTest extends AbstractDependencyResolverTest {
|
|||
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]);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue