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 Aug 24, 2017
1 parent 14313cf commit 74d1de7
Show file tree
Hide file tree
Showing 14 changed files with 134 additions and 121 deletions.
14 changes: 10 additions & 4 deletions src/java/org/apache/ivy/core/IvyPatternHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -163,7 +163,7 @@ public static String substitute(String pattern, String org, String module, Strin
tokens.put(ORIGINAL_ARTIFACTNAME_KEY, new OriginalArtifactNameValue(origin));
}

return substituteTokens(pattern, tokens);
return substituteTokens(pattern, tokens, false);
}

// CheckStyle:ParameterNumber ON
Expand Down Expand Up @@ -218,9 +218,15 @@ private static String substituteVariables(String pattern, IvyVariableContainer v
}
}

@SuppressWarnings({"rawtypes", "unchecked"})
public static String substituteTokens(String pattern, Map tokens) {
Map<String, Object> tokensCopy = new HashMap<>(tokens);
// This is a cludge to reconcile different values passed to the method
public static String substituteTokens(String pattern, Map<String, String> tokens) {
Map<String, Object> tokensCopy = new HashMap<>();
tokensCopy.putAll(tokens);
return substituteTokens(pattern, tokensCopy, true);
}

private static String substituteTokens(String pattern, Map<String, Object> tokens, boolean external) {
Map<String, Object> tokensCopy = external ? tokens : new HashMap<>(tokens);
if (tokensCopy.containsKey(ORGANISATION_KEY) && !tokensCopy.containsKey(ORGANISATION_KEY2)) {
tokensCopy.put(ORGANISATION_KEY2, tokensCopy.get(ORGANISATION_KEY));
}
Expand Down
25 changes: 13 additions & 12 deletions src/java/org/apache/ivy/core/module/descriptor/Configuration.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.LinkedHashSet;
import java.util.Map;
import java.util.Set;
Expand Down Expand Up @@ -74,7 +75,7 @@ public static Collection<Configuration> findConfigurationExtending(String conf,

private String description;

private String[] extendsFrom;
private Set<String> extendsFrom;

private Visibility visibility;

Expand All @@ -95,9 +96,9 @@ public Configuration(String name) {
}

public Configuration(Configuration source, ModuleRevisionId sourceModule) {
this(source.getAttributes(), source.getQualifiedExtraAttributes(), source.getName(), source
.getVisibility(), source.getDescription(), source.getExtends(), source
.isTransitive(), source.getDeprecated(), sourceModule);
this(source.getAttributes(), source.getQualifiedExtraAttributes(), source.getName(),
source.getVisibility(), source.getDescription(), source.getExtends(),
source.isTransitive(), source.getDeprecated(), sourceModule);
}

/**
Expand All @@ -122,7 +123,7 @@ public Configuration(String name, Visibility visibility, String description, Str
}

private Configuration(Map<String, String> attributes, Map<String, String> extraAttributes,
String name, Visibility visibility, String description, String[] ext,
String name, Visibility visibility, String description, String[] exts,
boolean transitive, String deprecated, ModuleRevisionId sourceModule) {
super(attributes, extraAttributes);

Expand All @@ -135,12 +136,12 @@ private Configuration(Map<String, String> attributes, Map<String, String> extraA
this.name = name;
this.visibility = visibility;
this.description = description;
if (ext == null) {
extendsFrom = new String[0];
if (exts == null) {
extendsFrom = Collections.emptySet();
} else {
extendsFrom = new String[ext.length];
for (int i = 0; i < ext.length; i++) {
extendsFrom[i] = ext[i].trim();
extendsFrom = new LinkedHashSet<>();
for (String ext : exts) {
extendsFrom.add(ext.trim());
}
}
this.transitive = transitive;
Expand Down Expand Up @@ -168,7 +169,7 @@ public String getDescription() {
* @return Returns the extends. May be empty, but never null.
*/
public String[] getExtends() {
return extendsFrom;
return extendsFrom.toArray(new String[extendsFrom.size()]);
}

/**
Expand Down Expand Up @@ -232,7 +233,7 @@ public void replaceWildcards(ModuleDescriptor md) {
}
}

this.extendsFrom = newExtends.toArray(new String[newExtends.size()]);
this.extendsFrom = newExtends;
}

private void addOther(Configuration[] allConfigs, Visibility visibility, Set<String> configs) {
Expand Down
6 changes: 3 additions & 3 deletions src/java/org/apache/ivy/core/report/ResolveReport.java
Original file line number Diff line number Diff line change
Expand Up @@ -322,16 +322,16 @@ public String getResolveId() {
* specified one.
*
* @param extended String
* @return String[]
* @return Set of String
*/
@SuppressWarnings("unused")
private String[] getExtendingConfs(String extended) {
private Set<String> getExtendingConfs(String extended) {
Set<String> extendingConfs = new HashSet<>();
extendingConfs.add(extended);
for (String conf : md.getConfigurationsNames()) {
gatherExtendingConfs(extendingConfs, conf, extended);
}
return extendingConfs.toArray(new String[extendingConfs.size()]);
return extendingConfs;
}

private boolean gatherExtendingConfs(Set<String> extendingConfs, String conf, String extended) {
Expand Down
63 changes: 25 additions & 38 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(
new HashSet<>(Collections.singletonList(token)), otherTokenValues)) {
entries.add(value.get(token));
}
}
Expand All @@ -74,9 +74,9 @@ 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) {
for (Map<String, String> oe : resolver.listTokenValues(
new HashSet<>(Collections.singletonList(IvyPatternHelper.ORGANISATION_KEY)),
new HashMap<String, Object>())) {
String org = oe.get(IvyPatternHelper.ORGANISATION_KEY);
entries.add(new OrganisationEntry(resolver, org));
}
Expand All @@ -89,9 +89,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(
new HashSet<>(Collections.singletonList(IvyPatternHelper.ORGANISATION_KEY)),
new HashMap<String, Object>())) {
entries.add(org.get(IvyPatternHelper.ORGANISATION_KEY));
}
}
Expand All @@ -106,9 +106,8 @@ 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) {
for (Map<String, String> me : resolver.listTokenValues(
new HashSet<>(Collections.singletonList(IvyPatternHelper.MODULE_KEY)), tokenValues)) {
String module = me.get(IvyPatternHelper.MODULE_KEY);
entries.add(new ModuleEntry(org, module));
}
Expand All @@ -124,9 +123,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(
new HashSet<>(Collections.singletonList(IvyPatternHelper.MODULE_KEY)), tokenValues)) {
entries.add(module.get(IvyPatternHelper.MODULE_KEY));
}
}
Expand All @@ -142,9 +140,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(
new HashSet<>(Collections.singletonList(IvyPatternHelper.REVISION_KEY)), tokenValues)) {
entries.add(new RevisionEntry(module, revision.get(IvyPatternHelper.REVISION_KEY)));
}
}
Expand All @@ -160,9 +157,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(
new HashSet<>(Collections.singletonList(IvyPatternHelper.REVISION_KEY)), tokenValues)) {
entries.add(revision.get(IvyPatternHelper.REVISION_KEY));
}
}
Expand All @@ -189,17 +185,14 @@ 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) {
for (Map<String, String> moduleId : resolver.listTokenValues(new HashSet<>(
Arrays.asList(IvyPatternHelper.ORGANISATION_KEY, IvyPatternHelper.MODULE_KEY)), criteria)) {
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()));
ret.add(NameSpaceHelper.transform(modId,
resolver.getNamespace().getToSystemTransformer()));
}
}

Expand All @@ -225,12 +218,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 +271,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
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 @@ -89,8 +89,8 @@
* uses only the SAX API, which makes the parsing code harder to understand.
*/
public class XmlModuleDescriptorParser extends AbstractModuleDescriptorParser {
static final String[] DEPENDENCY_REGULAR_ATTRIBUTES = new String[] {"org", "name", "branch",
"branchConstraint", "rev", "revConstraint", "force", "transitive", "changing", "conf"};
static final List<String> DEPENDENCY_REGULAR_ATTRIBUTES = Arrays.asList("org", "name", "branch",
"branchConstraint", "rev", "revConstraint", "force", "transitive", "changing", "conf");

private static final XmlModuleDescriptorParser INSTANCE = new XmlModuleDescriptorParser();

Expand Down Expand Up @@ -845,8 +845,8 @@ protected void confStarted(Attributes attributes) {
settings.substitute(attributes.getValue("description")),
(ext == null) ? null : ext.split(","), transitive, deprecated);
ExtendableItemHelper.fillExtraAttributes(settings, configuration, attributes,
new String[] {"name", "visibility", "extends", "transitive", "description",
"deprecated"});
Arrays.asList("name", "visibility", "extends", "transitive", "description",
"deprecated"));
getMd().addConfiguration(configuration);
break;
case State.PUB:
Expand Down Expand Up @@ -954,7 +954,7 @@ protected void artifactStarted(String qName, Attributes attributes)
String url = settings.substitute(attributes.getValue("url"));
artifact = new MDArtifact(getMd(), artName, type, ext, url == null ? null
: new URL(url), ExtendableItemHelper.getExtraAttributes(settings,
attributes, new String[] {"ext", "type", "name", "conf"}));
attributes, Arrays.asList("ext", "type", "name", "conf")));
String confs = settings.substitute(attributes.getValue("conf"));
// only add confs if they are specified. if they aren't, endElement will
// handle this
Expand Down Expand Up @@ -1013,9 +1013,9 @@ protected void infoStarted(Attributes attributes) {
module,
branch,
revision,
ExtendableItemHelper.getExtraAttributes(settings, attributes, new String[] {
ExtendableItemHelper.getExtraAttributes(settings, attributes, Arrays.asList(
"organisation", "module", "revision", "status", "publication",
"branch", "namespace", "default", "resolver"})));
"branch", "namespace", "default", "resolver"))));

String namespace = settings.substitute(attributes.getValue("namespace"));
if (namespace != null) {
Expand Down Expand Up @@ -1107,7 +1107,7 @@ protected void parseRule(String tag, Attributes attributes) throws MalformedURLE
if (state == State.DEP_ARTIFACT) {
String url = settings.substitute(attributes.getValue("url"));
Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
attributes, new String[] {"name", "type", "ext", "url", "conf"});
attributes, Arrays.asList("name", "type", "ext", "url", "conf"));
confAware = new DefaultDependencyArtifactDescriptor(dd, name, type, ext,
url == null ? null : new URL(url), extraAtt);
} else if (state == State.ARTIFACT_INCLUDE) {
Expand All @@ -1118,8 +1118,8 @@ protected void parseRule(String tag, Attributes attributes) throws MalformedURLE
module = module == null ? PatternMatcher.ANY_EXPRESSION : module;
ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext);
Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
attributes, new String[] {"org", "module", "name", "type", "ext", "matcher",
"conf"});
attributes, Arrays.asList("org", "module", "name", "type", "ext", "matcher",
"conf"));
confAware = new DefaultIncludeRule(aid, matcher, extraAtt);
} else { // _state == ARTIFACT_EXCLUDE || EXCLUDE
PatternMatcher matcher = getPatternMatcher(attributes.getValue("matcher"));
Expand All @@ -1129,8 +1129,8 @@ protected void parseRule(String tag, Attributes attributes) throws MalformedURLE
module = module == null ? PatternMatcher.ANY_EXPRESSION : module;
ArtifactId aid = new ArtifactId(new ModuleId(org, module), name, type, ext);
Map<String, String> extraAtt = ExtendableItemHelper.getExtraAttributes(settings,
attributes, new String[] {"org", "module", "name", "type", "ext", "matcher",
"conf"});
attributes, Arrays.asList("org", "module", "name", "type", "ext", "matcher",
"conf"));
confAware = new DefaultExcludeRule(aid, matcher, extraAtt);
}
String confs = settings.substitute(attributes.getValue("conf"));
Expand Down
Loading

0 comments on commit 74d1de7

Please sign in to comment.