Skip to content

Commit bf4db7c

Browse files
committed
fix last inconsistencies in generics (use collections, not arrays)
1 parent 9b21658 commit bf4db7c

File tree

14 files changed

+134
-121
lines changed

14 files changed

+134
-121
lines changed

src/java/org/apache/ivy/core/IvyPatternHelper.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public static String substitute(String pattern, String org, String module, Strin
163163
tokens.put(ORIGINAL_ARTIFACTNAME_KEY, new OriginalArtifactNameValue(origin));
164164
}
165165

166-
return substituteTokens(pattern, tokens);
166+
return substituteTokens(pattern, tokens, false);
167167
}
168168

169169
// CheckStyle:ParameterNumber ON
@@ -218,9 +218,15 @@ private static String substituteVariables(String pattern, IvyVariableContainer v
218218
}
219219
}
220220

221-
@SuppressWarnings({"rawtypes", "unchecked"})
222-
public static String substituteTokens(String pattern, Map tokens) {
223-
Map<String, Object> tokensCopy = new HashMap<>(tokens);
221+
// This is a cludge to reconcile different values passed to the method
222+
public static String substituteTokens(String pattern, Map<String, String> tokens) {
223+
Map<String, Object> tokensCopy = new HashMap<>();
224+
tokensCopy.putAll(tokens);
225+
return substituteTokens(pattern, tokensCopy, true);
226+
}
227+
228+
private static String substituteTokens(String pattern, Map<String, Object> tokens, boolean external) {
229+
Map<String, Object> tokensCopy = external ? tokens : new HashMap<>(tokens);
224230
if (tokensCopy.containsKey(ORGANISATION_KEY) && !tokensCopy.containsKey(ORGANISATION_KEY2)) {
225231
tokensCopy.put(ORGANISATION_KEY2, tokensCopy.get(ORGANISATION_KEY));
226232
}

src/java/org/apache/ivy/core/module/descriptor/Configuration.java

Lines changed: 13 additions & 12 deletions
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.LinkedHashSet;
2425
import java.util.Map;
2526
import java.util.Set;
@@ -74,7 +75,7 @@ public static Collection<Configuration> findConfigurationExtending(String conf,
7475

7576
private String description;
7677

77-
private String[] extendsFrom;
78+
private Set<String> extendsFrom;
7879

7980
private Visibility visibility;
8081

@@ -95,9 +96,9 @@ public Configuration(String name) {
9596
}
9697

9798
public Configuration(Configuration source, ModuleRevisionId sourceModule) {
98-
this(source.getAttributes(), source.getQualifiedExtraAttributes(), source.getName(), source
99-
.getVisibility(), source.getDescription(), source.getExtends(), source
100-
.isTransitive(), source.getDeprecated(), sourceModule);
99+
this(source.getAttributes(), source.getQualifiedExtraAttributes(), source.getName(),
100+
source.getVisibility(), source.getDescription(), source.getExtends(),
101+
source.isTransitive(), source.getDeprecated(), sourceModule);
101102
}
102103

103104
/**
@@ -122,7 +123,7 @@ public Configuration(String name, Visibility visibility, String description, Str
122123
}
123124

124125
private Configuration(Map<String, String> attributes, Map<String, String> extraAttributes,
125-
String name, Visibility visibility, String description, String[] ext,
126+
String name, Visibility visibility, String description, String[] exts,
126127
boolean transitive, String deprecated, ModuleRevisionId sourceModule) {
127128
super(attributes, extraAttributes);
128129

@@ -135,12 +136,12 @@ private Configuration(Map<String, String> attributes, Map<String, String> extraA
135136
this.name = name;
136137
this.visibility = visibility;
137138
this.description = description;
138-
if (ext == null) {
139-
extendsFrom = new String[0];
139+
if (exts == null) {
140+
extendsFrom = Collections.emptySet();
140141
} else {
141-
extendsFrom = new String[ext.length];
142-
for (int i = 0; i < ext.length; i++) {
143-
extendsFrom[i] = ext[i].trim();
142+
extendsFrom = new LinkedHashSet<>();
143+
for (String ext : exts) {
144+
extendsFrom.add(ext.trim());
144145
}
145146
}
146147
this.transitive = transitive;
@@ -168,7 +169,7 @@ public String getDescription() {
168169
* @return Returns the extends. May be empty, but never null.
169170
*/
170171
public String[] getExtends() {
171-
return extendsFrom;
172+
return extendsFrom.toArray(new String[extendsFrom.size()]);
172173
}
173174

174175
/**
@@ -232,7 +233,7 @@ public void replaceWildcards(ModuleDescriptor md) {
232233
}
233234
}
234235

235-
this.extendsFrom = newExtends.toArray(new String[newExtends.size()]);
236+
this.extendsFrom = newExtends;
236237
}
237238

238239
private void addOther(Configuration[] allConfigs, Visibility visibility, Set<String> configs) {

src/java/org/apache/ivy/core/report/ResolveReport.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,16 +322,16 @@ public String getResolveId() {
322322
* specified one.
323323
*
324324
* @param extended String
325-
* @return String[]
325+
* @return Set of String
326326
*/
327327
@SuppressWarnings("unused")
328-
private String[] getExtendingConfs(String extended) {
328+
private Set<String> getExtendingConfs(String extended) {
329329
Set<String> extendingConfs = new HashSet<>();
330330
extendingConfs.add(extended);
331331
for (String conf : md.getConfigurationsNames()) {
332332
gatherExtendingConfs(extendingConfs, conf, extended);
333333
}
334-
return extendingConfs.toArray(new String[extendingConfs.size()]);
334+
return extendingConfs;
335335
}
336336

337337
private boolean gatherExtendingConfs(Set<String> extendingConfs, String conf, String extended) {

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

Lines changed: 25 additions & 38 deletions
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+
new HashSet<>(Collections.singletonList(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+
new HashSet<>(Collections.singletonList(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+
new HashSet<>(Collections.singletonList(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+
new HashSet<>(Collections.singletonList(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+
new HashSet<>(Collections.singletonList(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+
new HashSet<>(Collections.singletonList(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+
new HashSet<>(Collections.singletonList(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);

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

Lines changed: 1 addition & 8 deletions
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/parser/xml/XmlModuleDescriptorParser.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,8 @@
8787
* uses only the SAX API, which makes the parsing code harder to understand.
8888
*/
8989
public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
90-
static final String[] DEPENDENCY_REGULAR_ATTRIBUTES = new String[] {"org", "name", "branch",
91-
"branchConstraint", "rev", "revConstraint", "force", "transitive", "changing", "conf"};
90+
static final List<String> DEPENDENCY_REGULAR_ATTRIBUTES = Arrays.asList("org", "name", "branch",
91+
"branchConstraint", "rev", "revConstraint", "force", "transitive", "changing", "conf");
9292

9393
private static final XmlModuleDescriptorParser INSTANCE = new XmlModuleDescriptorParser();
9494

@@ -843,8 +843,8 @@ protected void confStarted(Attributes attributes) {
843843
: visibility), settings.substitute(attributes.getValue("description")),
844844
(ext == null) ? null : ext.split(","), transitive, deprecated);
845845
ExtendableItemHelper.fillExtraAttributes(settings, configuration, attributes,
846-
new String[] {"name", "visibility", "extends", "transitive", "description",
847-
"deprecated"});
846+
Arrays.asList("name", "visibility", "extends", "transitive", "description",
847+
"deprecated"));
848848
getMd().addConfiguration(configuration);
849849
break;
850850
case State.PUB:
@@ -952,7 +952,7 @@ protected void artifactStarted(String qName, Attributes attributes)
952952
String url = settings.substitute(attributes.getValue("url"));
953953
artifact = new MDArtifact(getMd(), artName, type, ext, url == null ? null
954954
: new URL(url), ExtendableItemHelper.getExtraAttributes(settings,
955-
attributes, new String[] {"ext", "type", "name", "conf"}));
955+
attributes, Arrays.asList("ext", "type", "name", "conf")));
956956
String confs = settings.substitute(attributes.getValue("conf"));
957957
// only add confs if they are specified. if they aren't, endElement will
958958
// handle this
@@ -1011,9 +1011,9 @@ protected void infoStarted(Attributes attributes) {
10111011
module,
10121012
branch,
10131013
revision,
1014-
ExtendableItemHelper.getExtraAttributes(settings, attributes, new String[] {
1014+
ExtendableItemHelper.getExtraAttributes(settings, attributes, Arrays.asList(
10151015
"organisation", "module", "revision", "status", "publication",
1016-
"branch", "namespace", "default", "resolver"})));
1016+
"branch", "namespace", "default", "resolver"))));
10171017

10181018
String namespace = settings.substitute(attributes.getValue("namespace"));
10191019
if (namespace != null) {
@@ -1105,7 +1105,7 @@ protected void parseRule(String tag, Attributes attributes) throws MalformedURLE
11051105
if (state == State.DEP_ARTIFACT) {
11061106
String url = settings.substitute(attributes.getValue("url"));
11071107
Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
1108-
attributes, new String[] {"name", "type", "ext", "url", "conf"});
1108+
attributes, Arrays.asList("name", "type", "ext", "url", "conf"));
11091109
confAware = new DefaultDependencyArtifactDescriptor(dd, name, type, ext,
11101110
url == null ? null : new URL(url), extraAtt);
11111111
} else if (state == State.ARTIFACT_INCLUDE) {
@@ -1116,8 +1116,8 @@ protected void parseRule(String tag, Attributes attributes) throws MalformedURLE
11161116
module = module == null ? PatternMatcher.ANY_EXPRESSION : module;
11171117
ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext);
11181118
Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
1119-
attributes, new String[] {"org", "module", "name", "type", "ext", "matcher",
1120-
"conf"});
1119+
attributes, Arrays.asList("org", "module", "name", "type", "ext", "matcher",
1120+
"conf"));
11211121
confAware = new DefaultIncludeRule(aid, matcher, extraAtt);
11221122
} else { // _state == ARTIFACT_EXCLUDE || EXCLUDE
11231123
PatternMatcher matcher = getPatternMatcher(attributes.getValue("matcher"));
@@ -1127,8 +1127,8 @@ protected void parseRule(String tag, Attributes attributes) throws MalformedURLE
11271127
module = module == null ? PatternMatcher.ANY_EXPRESSION : module;
11281128
ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext);
11291129
Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
1130-
attributes, new String[] {"org", "module", "name", "type", "ext", "matcher",
1131-
"conf"});
1130+
attributes, Arrays.asList("org", "module", "name", "type", "ext", "matcher",
1131+
"conf"));
11321132
confAware = new DefaultExcludeRule(aid, matcher, extraAtt);
11331133
}
11341134
String confs = settings.substitute(attributes.getValue("conf"));

0 commit comments

Comments
 (0)