Return-Path: X-Original-To: archive-asf-public-internal@cust-asf2.ponee.io Delivered-To: archive-asf-public-internal@cust-asf2.ponee.io Received: from cust-asf.ponee.io (cust-asf.ponee.io [163.172.22.183]) by cust-asf2.ponee.io (Postfix) with ESMTP id 9C553200CD7 for ; Tue, 18 Jul 2017 07:02:22 +0200 (CEST) Received: by cust-asf.ponee.io (Postfix) id 9AE341664C9; Tue, 18 Jul 2017 05:02:22 +0000 (UTC) Delivered-To: archive-asf-public@cust-asf.ponee.io Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by cust-asf.ponee.io (Postfix) with SMTP id 1075A1664C8 for ; Tue, 18 Jul 2017 07:02:19 +0200 (CEST) Received: (qmail 36072 invoked by uid 500); 18 Jul 2017 05:02:19 -0000 Mailing-List: contact notifications-help@ant.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@ant.apache.org Delivered-To: mailing list notifications@ant.apache.org Received: (qmail 35942 invoked by uid 99); 18 Jul 2017 05:02:18 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 18 Jul 2017 05:02:18 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 3BFE2F21AB; Tue, 18 Jul 2017 05:02:18 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: jaikiran@apache.org To: notifications@ant.apache.org Date: Tue, 18 Jul 2017 05:02:21 -0000 Message-Id: In-Reply-To: References: X-Mailer: ASF-Git Admin Mailer Subject: [4/7] ant-ivy git commit: Add generics and Java 7 syntax to core archived-at: Tue, 18 Jul 2017 05:02:22 -0000 http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/69207179/src/java/org/apache/ivy/core/resolve/IvyNode.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/ivy/core/resolve/IvyNode.java b/src/java/org/apache/ivy/core/resolve/IvyNode.java index a26146f..47bc3e1 100644 --- a/src/java/org/apache/ivy/core/resolve/IvyNode.java +++ b/src/java/org/apache/ivy/core/resolve/IvyNode.java @@ -82,7 +82,7 @@ public class IvyNode implements Comparable { private ModuleRevisionId id; // set only when node has been built or updated from a DependencyDescriptor - private Map dds = new HashMap(); + private Map dds = new HashMap<>(); // Set when data has been loaded only, or when constructed from a module descriptor private ModuleDescriptor md; @@ -96,18 +96,18 @@ public class IvyNode implements Comparable { private boolean searched = false; - private Collection confsToFetch = new HashSet(); + private Collection confsToFetch = new HashSet<>(); - private Collection fetchedConfigurations = new HashSet(); + private Collection fetchedConfigurations = new HashSet<>(); - private Collection loadedRootModuleConfs = new HashSet(); + private Collection loadedRootModuleConfs = new HashSet<>(); // //////// USAGE DATA private IvyNodeUsage usage = new IvyNodeUsage(this); // usage information merged from evicted nodes this node is "replacing" - private Map mergedUsages = new LinkedHashMap(); + private Map mergedUsages = new LinkedHashMap<>(); public IvyNode(ResolveData data, IvyNode parent, DependencyDescriptor dd) { id = dd.getDependencyRevisionId(); @@ -310,9 +310,9 @@ public class IvyNode implements Comparable { confs = md.getPublicConfigurationsNames(); } } - Collection deps = new HashSet(); - for (int i = 0; i < confs.length; i++) { - deps.addAll(getDependencies(rootModuleConf, confs[i], requestedConf)); + Collection deps = new HashSet<>(); + for (String conf : confs) { + deps.addAll(getDependencies(rootModuleConf, conf, requestedConf)); } return deps; } @@ -336,10 +336,9 @@ public class IvyNode implements Comparable { throw new IllegalStateException( "impossible to get dependencies when data has not been loaded"); } - DependencyDescriptor[] dds = md.getDependencies(); // it's important to respect order => LinkedHashMap - Map dependencies = new LinkedHashMap(); - for (DependencyDescriptor dependencyDescriptor : dds) { + Map dependencies = new LinkedHashMap<>(); + for (DependencyDescriptor dependencyDescriptor : md.getDependencies()) { DependencyDescriptor dd = data.mediate(dependencyDescriptor); String[] dependencyConfigurations = dd.getDependencyConfigurations(conf, requestedConf); if (dependencyConfigurations.length == 0) { @@ -423,7 +422,7 @@ public class IvyNode implements Comparable { // a circular dependency, we cannot be conclusive here return null; } - return Boolean.valueOf(c.doesCallersExclude(rootModuleConf, artifact, callersStack)); + return c.doesCallersExclude(rootModuleConf, artifact, callersStack); } return Boolean.FALSE; } @@ -513,7 +512,7 @@ public class IvyNode implements Comparable { // there are exclusions in the configuration List exclusions = Arrays.asList(conf.substring(2).split("\\!")); - List ret = new ArrayList(Arrays.asList(getDescriptor() + List ret = new ArrayList<>(Arrays.asList(getDescriptor() .getPublicConfigurationsNames())); ret.removeAll(exclusions); @@ -530,7 +529,7 @@ public class IvyNode implements Comparable { * @return array of configuration names */ public String[] getRequiredConfigurations(IvyNode in, String inConf) { - Collection req = new LinkedHashSet(); + Collection req = new LinkedHashSet<>(); addAllIfNotNull(req, usage.getRequiredConfigurations(in, inConf)); for (IvyNodeUsage usage : mergedUsages.values()) { addAllIfNotNull(req, usage.getRequiredConfigurations(in, inConf)); @@ -550,7 +549,7 @@ public class IvyNode implements Comparable { * @return array of configuration names */ public String[] getRequiredConfigurations() { - Collection required = new ArrayList(confsToFetch.size() + Collection required = new ArrayList<>(confsToFetch.size() + fetchedConfigurations.size()); required.addAll(fetchedConfigurations); required.addAll(confsToFetch); @@ -578,7 +577,7 @@ public class IvyNode implements Comparable { * @return array of configuration names */ public String[] getConfigurations(String rootModuleConf) { - Set depConfs = new LinkedHashSet(); + Set depConfs = new LinkedHashSet<>(); addAllIfNotNull(depConfs, usage.getConfigurations(rootModuleConf)); for (IvyNodeUsage usage : mergedUsages.values()) { addAllIfNotNull(depConfs, usage.getConfigurations(rootModuleConf)); @@ -598,10 +597,9 @@ public class IvyNode implements Comparable { // remove all given dependency configurations to the set + extended ones Configuration c = md.getConfiguration(conf); if (conf != null) { - String[] exts = c.getExtends(); - for (int i = 0; i < exts.length; i++) { - discardConf(rootModuleConf, exts[i]); // recursive remove of extended - // configurations + // recursive remove of extended configurations + for (String ext : c.getExtends()) { + discardConf(rootModuleConf, ext); } depConfs.remove(c.getName()); } else { @@ -643,7 +641,7 @@ public class IvyNode implements Comparable { * @return {@link Set} of configuration names */ public Set getRootModuleConfigurationsSet() { - Set confs = new LinkedHashSet(); + Set confs = new LinkedHashSet<>(); addAllIfNotNull(confs, usage.getRootModuleConfigurations()); for (IvyNodeUsage usage : mergedUsages.values()) { addAllIfNotNull(confs, usage.getRootModuleConfigurations()); @@ -672,7 +670,7 @@ public class IvyNode implements Comparable { if (conf.charAt(0) == '*') { return resolveSpecialConfigurations(new String[] {conf}); } - if (conf.indexOf(',') != -1) { + if (conf.contains(",")) { String[] confs = conf.split(","); for (int i = 0; i < confs.length; i++) { confs[i] = confs[i].trim(); @@ -749,7 +747,7 @@ public class IvyNode implements Comparable { } private Collection getAllUsages() { - Collection usages = new ArrayList(); + Collection usages = new ArrayList<>(); usages.add(usage); usages.addAll(mergedUsages.values()); return usages; @@ -761,7 +759,7 @@ public class IvyNode implements Comparable { * @return array of {@link Artifact}s */ public Artifact[] getAllArtifacts() { - Set ret = new HashSet(); + Set ret = new HashSet<>(); for (String rootModuleConf : getRootModuleConfigurationsSet()) { ret.addAll(Arrays.asList(getArtifacts(rootModuleConf))); } @@ -776,7 +774,7 @@ public class IvyNode implements Comparable { * @return array of {@link Artifact}s */ public Artifact[] getSelectedArtifacts(Filter artifactFilter) { - Collection ret = new HashSet(); + Collection ret = new HashSet<>(); for (String rootModuleConf : getRootModuleConfigurationsSet()) { if (!isEvicted(rootModuleConf) && !isBlacklisted(rootModuleConf)) { ret.addAll(Arrays.asList(getArtifacts(rootModuleConf))); @@ -807,7 +805,7 @@ public class IvyNode implements Comparable { + this); } - Set artifacts = new HashSet(); // the set we fill before returning + Set artifacts = new HashSet<>(); // the set we fill before returning // we check if we have dependencyArtifacts includes description for this rootModuleConf Set dependencyArtifacts = usage @@ -817,7 +815,7 @@ public class IvyNode implements Comparable { addArtifactsFromOwnUsage(artifacts, dependencyArtifacts); addArtifactsFromMergedUsage(rootModuleConf, artifacts); } else { - Set includes = new LinkedHashSet(); + Set includes = new LinkedHashSet<>(); addAllIfNotNull(includes, usage.getDependencyIncludesSet(rootModuleConf)); for (IvyNodeUsage usage : mergedUsages.values()) { addAllIfNotNull(includes, usage.getDependencyIncludesSet(rootModuleConf)); @@ -826,19 +824,17 @@ public class IvyNode implements Comparable { if ((dependencyArtifacts == null || dependencyArtifacts.isEmpty()) && (includes.isEmpty())) { // no artifacts / includes: we get all artifacts as defined by the descriptor - for (int i = 0; i < confs.length; i++) { - artifacts.addAll(Arrays.asList(md.getArtifacts(confs[i]))); + for (String conf : confs) { + artifacts.addAll(Arrays.asList(md.getArtifacts(conf))); } } else { - // we have to get only artifacts listed as "includes" - + // we have to get only artifacts listed as "includes"; // first we get all artifacts as defined by the module descriptor // and classify them by artifact id - Map allArtifacts = new HashMap(); - for (int i = 0; i < confs.length; i++) { - Artifact[] arts = md.getArtifacts(confs[i]); - for (int j = 0; j < arts.length; j++) { - allArtifacts.put(arts[j].getId().getArtifactId(), arts[j]); + Map allArtifacts = new HashMap<>(); + for (String conf : confs) { + for (Artifact art : md.getArtifacts(conf)) { + allArtifacts.put(art.getId().getArtifactId(), art); } } @@ -849,7 +845,8 @@ public class IvyNode implements Comparable { addArtifactsFromMergedUsage(rootModuleConf, artifacts); // and now we filter according to include rules - for (Iterator it = includes.iterator(); it.hasNext();) { + Iterator it = includes.iterator(); + while (it.hasNext()) { IncludeRule dad = it.next(); Collection arts = findArtifactsMatching(dad, allArtifacts); if (arts.isEmpty()) { @@ -866,8 +863,9 @@ public class IvyNode implements Comparable { } } - // now excludes artifacts that aren't accepted by any caller - for (Iterator iter = artifacts.iterator(); iter.hasNext();) { + // now exclude artifacts that aren't accepted by any caller + Iterator iter = artifacts.iterator(); + while (iter.hasNext()) { Artifact artifact = iter.next(); boolean excluded = callers.doesCallersExclude(rootModuleConf, artifact); if (excluded) { @@ -892,7 +890,7 @@ public class IvyNode implements Comparable { .getDependencyArtifactsSet(rootModuleConf); if (mergedDependencyArtifacts != null) { for (DependencyArtifactDescriptor dad : mergedDependencyArtifacts) { - Map extraAttributes = new HashMap( + Map extraAttributes = new HashMap<>( dad.getQualifiedExtraAttributes()); MDArtifact artifact = new MDArtifact(md, dad.getName(), dad.getType(), dad.getExt(), dad.getUrl(), extraAttributes); @@ -910,7 +908,7 @@ public class IvyNode implements Comparable { private static Collection findArtifactsMatching(IncludeRule rule, Map allArtifacts) { - Collection ret = new ArrayList(); + Collection ret = new ArrayList<>(); for (Entry entry : allArtifacts.entrySet()) { if (MatcherHelper.matches(rule.getMatcher(), rule.getId(), entry.getKey())) { ret.add(entry.getValue()); @@ -1243,7 +1241,7 @@ public class IvyNode implements Comparable { Message.verbose("BLACKLISTING " + bdata); } - Stack callerStack = new Stack(); + Stack callerStack = new Stack<>(); callerStack.push(this); clearEvictionDataInAllCallers(bdata.getRootModuleConf(), callerStack); http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/69207179/src/java/org/apache/ivy/core/resolve/IvyNodeCallers.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/ivy/core/resolve/IvyNodeCallers.java b/src/java/org/apache/ivy/core/resolve/IvyNodeCallers.java index f9c6d57..558565b 100644 --- a/src/java/org/apache/ivy/core/resolve/IvyNodeCallers.java +++ b/src/java/org/apache/ivy/core/resolve/IvyNodeCallers.java @@ -39,7 +39,7 @@ public class IvyNodeCallers { private ModuleRevisionId mrid; // callerConf -> dependencyConfs - private Map confs = new HashMap(); + private Map confs = new HashMap<>(); private DependencyDescriptor dd; @@ -61,8 +61,8 @@ public class IvyNodeCallers { if (conf != null) { String[] confExtends = conf.getExtends(); if (confExtends != null) { - for (int i = 0; i < confExtends.length; i++) { - addConfiguration(confExtends[i], dependencyConfs); + for (String confExtend : confExtends) { + addConfiguration(confExtend, dependencyConfs); } } } @@ -71,7 +71,7 @@ public class IvyNodeCallers { private void updateConfs(String callerConf, String[] dependencyConfs) { String[] prevDepConfs = confs.get(callerConf); if (prevDepConfs != null) { - Set newDepConfs = new HashSet(Arrays.asList(prevDepConfs)); + Set newDepConfs = new HashSet<>(Arrays.asList(prevDepConfs)); newDepConfs.addAll(Arrays.asList(dependencyConfs)); confs.put(callerConf, newDepConfs.toArray(new String[newDepConfs.size()])); } else { @@ -137,12 +137,12 @@ public class IvyNodeCallers { } // key in second map is used to easily get a caller by its mrid - private Map> callersByRootConf = new HashMap>(); + private Map> callersByRootConf = new HashMap<>(); // this map contains all the module ids calling this one (including transitively) as keys. // the mapped nodes (values) correspond to a direct caller from which the transitive caller // comes - private Map allCallers = new HashMap(); + private Map allCallers = new HashMap<>(); private IvyNode node; @@ -170,7 +170,7 @@ public class IvyNodeCallers { } Map callers = callersByRootConf.get(rootModuleConf); if (callers == null) { - callers = new HashMap(); + callers = new HashMap<>(); callersByRootConf.put(rootModuleConf, callers); } Caller caller = callers.get(mrid); @@ -204,7 +204,7 @@ public class IvyNodeCallers { } public Caller[] getAllCallers() { - Set all = new HashSet(); + Set all = new HashSet<>(); for (Map callers : callersByRootConf.values()) { all.addAll(callers.values()); } @@ -212,7 +212,7 @@ public class IvyNodeCallers { } public Caller[] getAllRealCallers() { - Set all = new HashSet(); + Set all = new HashSet<>(); for (Map callers : callersByRootConf.values()) { for (Caller c : callers.values()) { if (c.isRealCaller()) { @@ -232,7 +232,7 @@ public class IvyNodeCallers { if (nodecallers != null) { Map thiscallers = callersByRootConf.get(rootModuleConf); if (thiscallers == null) { - thiscallers = new HashMap(); + thiscallers = new HashMap<>(); callersByRootConf.put(rootModuleConf, thiscallers); } for (Caller caller : nodecallers.values()) { @@ -270,14 +270,14 @@ public class IvyNodeCallers { return false; } boolean allInconclusive = true; - for (int i = 0; i < callers.length; i++) { - if (!callers[i].canExclude()) { + for (Caller caller : callers) { + if (!caller.canExclude()) { return false; } - ModuleDescriptor md = callers[i].getModuleDescriptor(); + ModuleDescriptor md = caller.getModuleDescriptor(); Boolean doesExclude = node.doesExclude(md, rootModuleConf, - callers[i].getCallerConfigurations(), callers[i].getDependencyDescriptor(), - artifact, callersStack); + caller.getCallerConfigurations(), caller.getDependencyDescriptor(), + artifact, callersStack); if (doesExclude != null) { if (!doesExclude) { return false; http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/69207179/src/java/org/apache/ivy/core/resolve/IvyNodeEviction.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/ivy/core/resolve/IvyNodeEviction.java b/src/java/org/apache/ivy/core/resolve/IvyNodeEviction.java index 3524f21..abd135c 100644 --- a/src/java/org/apache/ivy/core/resolve/IvyNodeEviction.java +++ b/src/java/org/apache/ivy/core/resolve/IvyNodeEviction.java @@ -157,7 +157,9 @@ public class IvyNodeEviction { @Override public boolean equals(Object obj) { - return obj instanceof ModuleIdConf && getModuleId().equals(((ModuleIdConf) obj).getModuleId()) && getConf().equals(((ModuleIdConf) obj).getConf()); + return obj instanceof ModuleIdConf + && getModuleId().equals(((ModuleIdConf) obj).getModuleId()) + && getConf().equals(((ModuleIdConf) obj).getConf()); } @Override @@ -174,20 +176,20 @@ public class IvyNodeEviction { private IvyNode node; // map indicating for each dependency which node has been selected - private Map> selectedDeps = new HashMap>(); + private Map> selectedDeps = new HashMap<>(); // map indicating for each dependency which nodes are in pending conflict (conflict detected but // not yet resolved) - private Map> pendingConflicts = new HashMap>(); + private Map> pendingConflicts = new HashMap<>(); // map indicating for each dependency which node has been evicted - private Map> evictedDeps = new HashMap>(); + private Map> evictedDeps = new HashMap<>(); // map indicating for each dependency which revision has been evicted - private Map> evictedRevs = new HashMap>(); + private Map> evictedRevs = new HashMap<>(); // indicates if the node is evicted in each root module conf - private Map evicted = new HashMap(); + private Map evicted = new HashMap<>(); public IvyNodeEviction(IvyNode node) { if (node == null) { @@ -203,7 +205,7 @@ public class IvyNodeEviction { */ public Set getResolvedNodes(ModuleId mid, String rootModuleConf) { Collection resolved = selectedDeps.get(new ModuleIdConf(mid, rootModuleConf)); - Set ret = new HashSet(); + Set ret = new HashSet<>(); if (resolved != null) { for (IvyNode node : resolved) { ret.add(node.getRealNode()); @@ -215,9 +217,9 @@ public class IvyNodeEviction { public Collection getResolvedRevisions(ModuleId mid, String rootModuleConf) { Collection resolved = selectedDeps.get(new ModuleIdConf(mid, rootModuleConf)); if (resolved == null) { - return new HashSet(); + return new HashSet<>(); } else { - Collection resolvedRevs = new HashSet(); + Collection resolvedRevs = new HashSet<>(); for (IvyNode node : resolved) { ModuleRevisionId resolvedId = node.getResolvedId(); resolvedRevs.add(node.getId()); @@ -237,12 +239,12 @@ public class IvyNodeEviction { public void setResolvedNodes(ModuleId moduleId, String rootModuleConf, Collection resolved) { ModuleIdConf moduleIdConf = new ModuleIdConf(moduleId, rootModuleConf); - selectedDeps.put(moduleIdConf, new HashSet(resolved)); + selectedDeps.put(moduleIdConf, new HashSet<>(resolved)); } public Collection getEvictedNodes(ModuleId mid, String rootModuleConf) { Collection resolved = evictedDeps.get(new ModuleIdConf(mid, rootModuleConf)); - Set ret = new HashSet(); + Set ret = new HashSet<>(); if (resolved != null) { for (IvyNode node : resolved) { ret.add(node.getRealNode()); @@ -255,17 +257,17 @@ public class IvyNodeEviction { Collection evicted = evictedRevs .get(new ModuleIdConf(mid, rootModuleConf)); if (evicted == null) { - return new HashSet(); + return new HashSet<>(); } else { - return new HashSet(evicted); + return new HashSet<>(evicted); } } public void setEvictedNodes(ModuleId moduleId, String rootModuleConf, Collection evicted) { ModuleIdConf moduleIdConf = new ModuleIdConf(moduleId, rootModuleConf); - evictedDeps.put(moduleIdConf, new HashSet(evicted)); - Collection evictedRevs = new HashSet(); + evictedDeps.put(moduleIdConf, new HashSet<>(evicted)); + Collection evictedRevs = new HashSet<>(); for (IvyNode node : evicted) { evictedRevs.add(node.getId()); evictedRevs.add(node.getResolvedId()); @@ -295,9 +297,8 @@ public class IvyNodeEviction { if (node.isRoot()) { return false; } - String[] rootModuleConfigurations = node.getRootModuleConfigurations(); - for (int i = 0; i < rootModuleConfigurations.length; i++) { - if (!isEvicted(rootModuleConfigurations[i])) { + for (String rootModuleConfiguration : node.getRootModuleConfigurations()) { + if (!isEvicted(rootModuleConfiguration)) { return false; } } @@ -306,7 +307,8 @@ public class IvyNodeEviction { private void cleanEvicted() { // check if it was evicted by a node that we are now the real node for - for (Iterator iter = evicted.keySet().iterator(); iter.hasNext();) { + Iterator iter = evicted.keySet().iterator(); + while (iter.hasNext()) { String rootModuleConf = iter.next(); EvictionData ed = evicted.get(rootModuleConf); Collection sel = ed.getSelected(); @@ -348,7 +350,7 @@ public class IvyNodeEviction { Collection selected = ed.getSelected(); if (selected != null) { if (allEvictingNodes == null) { - allEvictingNodes = new HashSet(); + allEvictingNodes = new HashSet<>(); } allEvictingNodes.addAll(selected); } @@ -362,7 +364,7 @@ public class IvyNodeEviction { Collection selected = ed.getSelected(); if (selected != null) { if (ret == null) { - ret = new HashSet(); + ret = new HashSet<>(); } if (selected.size() == 1) { ret.add(selected.iterator().next() @@ -376,7 +378,7 @@ public class IvyNodeEviction { } public Collection getAllEvictingConflictManagers() { - Collection ret = new HashSet(); + Collection ret = new HashSet<>(); for (EvictionData ed : evicted.values()) { ret.add(ed.getConflictManager()); } @@ -409,7 +411,7 @@ public class IvyNodeEviction { public Collection getPendingConflicts(String rootModuleConf, ModuleId mid) { Collection resolved = pendingConflicts.get(new ModuleIdConf(mid, rootModuleConf)); - Set ret = new HashSet(); + Set ret = new HashSet<>(); if (resolved != null) { for (IvyNode node : resolved) { ret.add(node.getRealNode()); @@ -421,7 +423,7 @@ public class IvyNodeEviction { public void setPendingConflicts(ModuleId moduleId, String rootModuleConf, Collection conflicts) { ModuleIdConf moduleIdConf = new ModuleIdConf(moduleId, rootModuleConf); - pendingConflicts.put(moduleIdConf, new HashSet(conflicts)); + pendingConflicts.put(moduleIdConf, new HashSet<>(conflicts)); } } http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/69207179/src/java/org/apache/ivy/core/resolve/IvyNodeUsage.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/ivy/core/resolve/IvyNodeUsage.java b/src/java/org/apache/ivy/core/resolve/IvyNodeUsage.java index 0399f52..99bdf74 100644 --- a/src/java/org/apache/ivy/core/resolve/IvyNodeUsage.java +++ b/src/java/org/apache/ivy/core/resolve/IvyNodeUsage.java @@ -123,14 +123,14 @@ public class IvyNodeUsage { // used to know which configurations of the dependency are required // for each root module configuration // rootConfName -> confNames - private Map> rootModuleConfs = new HashMap>(); + private Map> rootModuleConfs = new HashMap<>(); - private Map> requiredConfs = new HashMap>(); + private Map> requiredConfs = new HashMap<>(); - private Map> dependers = new HashMap>(); + private Map> dependers = new HashMap<>(); // rootModuleConf -> black list - private Map blacklisted = new HashMap(); + private Map blacklisted = new HashMap<>(); public IvyNodeUsage(IvyNode node) { this.node = node; @@ -141,12 +141,12 @@ public class IvyNodeUsage { } protected void setRequiredConfs(IvyNode parent, String parentConf, Collection confs) { - requiredConfs.put(new NodeConf(parent, parentConf), new HashSet(confs)); + requiredConfs.put(new NodeConf(parent, parentConf), new HashSet<>(confs)); } /** * Returns the configurations of the dependency required in a given root module configuration. - * + * * @param rootModuleConf ditto * @return Set<String> */ @@ -157,7 +157,7 @@ public class IvyNodeUsage { protected Set addAndGetConfigurations(String rootModuleConf) { Set depConfs = rootModuleConfs.get(rootModuleConf); if (depConfs == null) { - depConfs = new HashSet(); + depConfs = new HashSet<>(); rootModuleConfs.put(rootModuleConf, depConfs); } return depConfs; @@ -197,7 +197,7 @@ public class IvyNodeUsage { if (toupdate != null) { toupdate.addAll(set); } else { - to.put(key, new HashSet(set)); + to.put(key, new HashSet<>(set)); } } } @@ -205,7 +205,7 @@ public class IvyNodeUsage { private void addObjectsForConf(K rootModuleConf, V objectToAdd, Map> map) { Set set = map.get(rootModuleConf); if (set == null) { - set = new HashSet(); + set = new HashSet<>(); map.put(rootModuleConf, set); } set.add(objectToAdd); @@ -224,7 +224,7 @@ public class IvyNodeUsage { if (dependersInConf == null) { return null; } - Set dependencyArtifacts = new HashSet(); + Set dependencyArtifacts = new HashSet<>(); for (Depender depender : dependersInConf) { DependencyArtifactDescriptor[] dads = depender.dd .getDependencyArtifacts(depender.dependerConf); @@ -238,7 +238,7 @@ public class IvyNodeUsage { if (dependersInConf == null) { return null; } - Set dependencyIncludes = new HashSet(); + Set dependencyIncludes = new HashSet<>(); for (Depender depender : dependersInConf) { IncludeRule[] rules = depender.dd.getIncludeRules(depender.dependerConf); if (rules == null || rules.length == 0) { @@ -264,10 +264,10 @@ public class IvyNodeUsage { *

* A blacklisted node should be considered as if it doesn't even exist on the repository. *

- * + * * @param rootModuleConf * the root module conf for which we'd like to know if the node is blacklisted - * + * * @return true if this node is blacklisted int he given root module conf, false otherwise * @see #blacklist(IvyNodeBlacklist) */ @@ -278,7 +278,7 @@ public class IvyNodeUsage { /** * Returns the blacklist data of this node in the given root module conf, or null * if this node is not blacklisted in this root module conf. - * + * * @param rootModuleConf * the root module configuration to consider * @return the blacklist data if any @@ -294,7 +294,7 @@ public class IvyNodeUsage { /** * Indicates if at least one depender has a transitive dependency descriptor for the given root * module conf. - * + * * @param rootModuleConf * the root module conf to consider * @return true if at least one depender has a transitive dependency descriptor for http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/69207179/src/java/org/apache/ivy/core/resolve/ResolveData.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/ivy/core/resolve/ResolveData.java b/src/java/org/apache/ivy/core/resolve/ResolveData.java index 74221f0..920e97d 100644 --- a/src/java/org/apache/ivy/core/resolve/ResolveData.java +++ b/src/java/org/apache/ivy/core/resolve/ResolveData.java @@ -82,7 +82,7 @@ public class ResolveData { } public Collection getNodes() { - Collection nodes = new ArrayList(); + Collection nodes = new ArrayList<>(); for (VisitData vdata : visitData.values()) { nodes.add(vdata.getNode()); } @@ -142,19 +142,7 @@ public class ResolveData { } private static boolean isEqual(Object obj1, Object obj2) { - if (obj1 == obj2) { - return true; - } - - if (obj1 == null) { - return obj2 == null; - } - - if (obj2 == null) { - return obj1 == null; - } - - return obj1.equals(obj2); + return obj1 == obj2 || obj1 != null && obj2 != null && obj1.equals(obj2); } /** @@ -256,11 +244,10 @@ public class ResolveData { } void blacklist(IvyNode node) { - for (Iterator> iter = visitData.entrySet().iterator(); iter - .hasNext();) { + Iterator> iter = visitData.entrySet().iterator(); + while (iter.hasNext()) { Entry entry = iter.next(); - VisitData vdata = entry.getValue(); - if (vdata.getNode() == node && !node.getResolvedId().equals(entry.getKey())) { + if (entry.getValue().getNode() == node && !node.getResolvedId().equals(entry.getKey())) { // this visit data was associated with the blacklisted node, // we discard this association iter.remove(); @@ -271,22 +258,22 @@ public class ResolveData { public boolean isBlacklisted(String rootModuleConf, ModuleRevisionId mrid) { IvyNode node = getNode(mrid); - // if (node == null) { - // // search again, now ignore the extra attributes - // // TODO: maybe we should search the node that has at least the - // // same attributes as mrid - // for (Iterator it = visitData.entrySet().iterator(); it.hasNext();) { - // Map.Entry entry = (Entry) it.next(); - // ModuleRevisionId current = (ModuleRevisionId) entry.getKey(); - // if (current.getModuleId().equals(mrid.getModuleId()) - // && current.getRevision().equals(mrid.getRevision())) { - // VisitData data = (VisitData) entry.getValue(); - // node = data.getNode(); - // break; - // } - // } - // } - // + /* + if (node == null) { + // search again, now ignore the extra attributes + // TODO: maybe we should search the node that has at least the same attributes as mrid + for (Entry entry : visitData.entrySet()) { + ModuleRevisionId current = entry.getKey(); + if (current.getModuleId().equals(mrid.getModuleId()) + && current.getRevision().equals(mrid.getRevision())) { + VisitData data = entry.getValue(); + node = data.getNode(); + break; + } + } + } + */ + return node != null && node.isBlacklisted(rootModuleConf); } @@ -297,7 +284,7 @@ public class ResolveData { VisitNode current = getCurrentVisitNode(); if (current != null) { // mediating dd through dependers stack - List dependers = new ArrayList(current.getPath()); + List dependers = new ArrayList<>(current.getPath()); // the returned path contains the currently visited node, we are only interested in // the dependers, so we remove the currently visited node from the end dependers.remove(dependers.size() - 1); http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/69207179/src/java/org/apache/ivy/core/resolve/ResolveEngine.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/ivy/core/resolve/ResolveEngine.java b/src/java/org/apache/ivy/core/resolve/ResolveEngine.java index 4258424..3d538ae 100644 --- a/src/java/org/apache/ivy/core/resolve/ResolveEngine.java +++ b/src/java/org/apache/ivy/core/resolve/ResolveEngine.java @@ -86,7 +86,7 @@ public class ResolveEngine { private SortEngine sortEngine; - private Set fetchedSet = new HashSet(); + private Set fetchedSet = new HashSet<>(); private DependencyResolver dictatorResolver; @@ -267,47 +267,47 @@ public class ResolveEngine { .getResolvedModuleRevisionId()); Properties props = new Properties(); if (dependencies.length > 0) { - Map forcedRevisions = new HashMap(); - for (int i = 0; i < dependencies.length; i++) { - if (dependencies[i].getModuleRevision() != null - && dependencies[i].getModuleRevision().isForce()) { - forcedRevisions.put(dependencies[i].getModuleId(), - dependencies[i].getResolvedId()); + Map forcedRevisions = new HashMap<>(); + for (IvyNode dependency : dependencies) { + if (dependency.getModuleRevision() != null + && dependency.getModuleRevision().isForce()) { + forcedRevisions.put(dependency.getModuleId(), + dependency.getResolvedId()); } } IvyNode root = dependencies[0].getRoot(); - Map topLevelDeps = new HashMap(); - for (int i = 0; i < dependencies.length; i++) { - if (!dependencies[i].hasProblem()) { - DependencyDescriptor dd = dependencies[i].getDependencyDescriptor(root); + Map topLevelDeps = new HashMap<>(); + for (IvyNode dependency : dependencies) { + if (!dependency.hasProblem()) { + DependencyDescriptor dd = dependency.getDependencyDescriptor(root); if (dd != null) { - ModuleId orgMod = dependencies[i].getModuleId(); - topLevelDeps.put(orgMod, dependencies[i]); + ModuleId orgMod = dependency.getModuleId(); + topLevelDeps.put(orgMod, dependency); } } } - for (int i = 0; i < dependencies.length; i++) { - if (!dependencies[i].hasProblem() && !dependencies[i].isCompletelyEvicted()) { - DependencyDescriptor dd = dependencies[i].getDependencyDescriptor(root); + for (IvyNode dependency : dependencies) { + if (!dependency.hasProblem() && !dependency.isCompletelyEvicted()) { + DependencyDescriptor dd = dependency.getDependencyDescriptor(root); if (dd == null) { - ModuleId mid = dependencies[i].getModuleId(); + ModuleId mid = dependency.getModuleId(); IvyNode tlDep = topLevelDeps.get(mid); if (tlDep != null) { dd = tlDep.getDependencyDescriptor(root); } } if (dd != null) { - ModuleRevisionId depResolvedId = dependencies[i].getResolvedId(); - ModuleDescriptor depDescriptor = dependencies[i].getDescriptor(); + ModuleRevisionId depResolvedId = dependency.getResolvedId(); + ModuleDescriptor depDescriptor = dependency.getDescriptor(); ModuleRevisionId depRevisionId = dd.getDependencyRevisionId(); - ModuleRevisionId forcedRevisionId = forcedRevisions.get(dependencies[i] + ModuleRevisionId forcedRevisionId = forcedRevisions.get(dependency .getModuleId()); - if (dependencies[i].getModuleRevision() != null - && dependencies[i].getModuleRevision().isForce() + if (dependency.getModuleRevision() != null + && dependency.getModuleRevision().isForce() && !depResolvedId.equals(depRevisionId) && !settings.getVersionMatcher().isDynamic(depRevisionId)) { // if we were forced to this revision and we @@ -319,7 +319,7 @@ public class ResolveEngine { if (depResolvedId == null) { throw new NullPointerException("getResolvedId() is null for " - + dependencies[i].toString()); + + dependency.toString()); } if (depRevisionId == null) { throw new NullPointerException("getDependencyRevisionId() " @@ -391,49 +391,45 @@ public class ResolveEngine { public void downloadArtifacts(ResolveReport report, Filter artifactFilter, DownloadOptions options) { long start = System.currentTimeMillis(); - IvyNode[] dependencies = report.getDependencies().toArray( - new IvyNode[report.getDependencies().size()]); eventManager.fireIvyEvent(new PrepareDownloadEvent(report.getArtifacts().toArray( new Artifact[report.getArtifacts().size()]))); long totalSize = 0; - for (int i = 0; i < dependencies.length; i++) { + for (IvyNode dependency : report.getDependencies()) { checkInterrupted(); // download artifacts required in all asked configurations - if (!dependencies[i].isCompletelyEvicted() && !dependencies[i].hasProblem() - && dependencies[i].getModuleRevision() != null) { - DependencyResolver resolver = dependencies[i].getModuleRevision() + if (!dependency.isCompletelyEvicted() && !dependency.hasProblem() + && dependency.getModuleRevision() != null) { + DependencyResolver resolver = dependency.getModuleRevision() .getArtifactResolver(); - Artifact[] selectedArtifacts = dependencies[i].getSelectedArtifacts(artifactFilter); + Artifact[] selectedArtifacts = dependency.getSelectedArtifacts(artifactFilter); DownloadReport dReport = resolver.download(selectedArtifacts, options); - ArtifactDownloadReport[] adrs = dReport.getArtifactsReports(); - for (int j = 0; j < adrs.length; j++) { - if (adrs[j].getDownloadStatus() == DownloadStatus.FAILED) { - if (adrs[j].getArtifact().getExtraAttribute("ivy:merged") != null) { - Message.warn("\tmerged artifact not found: " + adrs[j].getArtifact() + for (ArtifactDownloadReport adr : dReport.getArtifactsReports()) { + if (adr.getDownloadStatus() == DownloadStatus.FAILED) { + if (adr.getArtifact().getExtraAttribute("ivy:merged") != null) { + Message.warn("\tmerged artifact not found: " + adr.getArtifact() + ". It was required in " - + adrs[j].getArtifact().getExtraAttribute("ivy:merged")); + + adr.getArtifact().getExtraAttribute("ivy:merged")); } else { - Message.warn("\t" + adrs[j]); - resolver.reportFailure(adrs[j].getArtifact()); + Message.warn("\t" + adr); + resolver.reportFailure(adr.getArtifact()); } - } else if (adrs[j].getDownloadStatus() == DownloadStatus.SUCCESSFUL) { - totalSize += adrs[j].getSize(); + } else if (adr.getDownloadStatus() == DownloadStatus.SUCCESSFUL) { + totalSize += adr.getSize(); } } // update concerned reports - String[] dconfs = dependencies[i].getRootModuleConfigurations(); - for (int j = 0; j < dconfs.length; j++) { + for (String dconf : dependency.getRootModuleConfigurations()) { // the report itself is responsible to take into account only // artifacts required in its corresponding configuration // (as described by the Dependency object) - if (dependencies[i].isEvicted(dconfs[j]) - || dependencies[i].isBlacklisted(dconfs[j])) { - report.getConfigurationReport(dconfs[j]).addDependency(dependencies[i]); + if (dependency.isEvicted(dconf) + || dependency.isBlacklisted(dconf)) { + report.getConfigurationReport(dconf).addDependency(dependency); } else { - report.getConfigurationReport(dconfs[j]).addDependency(dependencies[i], - dReport); + report.getConfigurationReport(dconf).addDependency(dependency, + dReport); } } } @@ -554,15 +550,15 @@ public class ResolveEngine { throw new NullPointerException("module descriptor must not be null"); } String[] confs = options.getConfs(md); - Collection missingConfs = new ArrayList(); - for (int i = 0; i < confs.length; i++) { - if (confs[i] == null) { + Collection missingConfs = new ArrayList<>(); + for (String conf : confs) { + if (conf == null) { throw new NullPointerException("null conf not allowed: confs where: " + Arrays.asList(confs)); } - if (md.getConfiguration(confs[i]) == null) { - missingConfs.add(" '" + confs[i] + "' "); + if (md.getConfiguration(conf) == null) { + missingConfs.add(" '" + conf + "' "); } } if (!missingConfs.isEmpty()) { @@ -583,33 +579,33 @@ public class ResolveEngine { } IvyNode rootNode = new IvyNode(data, md); - for (int i = 0; i < confs.length; i++) { - Message.verbose("resolving dependencies for configuration '" + confs[i] + "'"); + for (String conf : confs) { + Message.verbose("resolving dependencies for configuration '" + conf + "'"); // for each configuration we clear the cache of what's been fetched fetchedSet.clear(); ConfigurationResolveReport confReport = null; if (report != null) { - confReport = report.getConfigurationReport(confs[i]); + confReport = report.getConfigurationReport(conf); if (confReport == null) { - confReport = new ConfigurationResolveReport(this, md, confs[i], reportDate, + confReport = new ConfigurationResolveReport(this, md, conf, reportDate, options); - report.addReport(confs[i], confReport); + report.addReport(conf, confReport); } } // we reuse the same resolve data with a new report for each conf data.setReport(confReport); // update the root module conf we are about to fetch - VisitNode root = new VisitNode(data, rootNode, null, confs[i], null); - root.setRequestedConf(confs[i]); - rootNode.updateConfsToFetch(Collections.singleton(confs[i])); + VisitNode root = new VisitNode(data, rootNode, null, conf, null); + root.setRequestedConf(conf); + rootNode.updateConfsToFetch(Collections.singleton(conf)); // go fetch ! boolean fetched = false; while (!fetched) { try { - fetchDependencies(root, confs[i], false); + fetchDependencies(root, conf, false); fetched = true; } catch (RestartResolveProcess restart) { Message.verbose("===================================================="); @@ -629,7 +625,7 @@ public class ResolveEngine { // prune and reverse sort fetched dependencies Collection nodes = data.getNodes(); // use a Set to avoid duplicates, linked to preserve order - Collection dependencies = new LinkedHashSet(nodes.size()); + Collection dependencies = new LinkedHashSet<>(nodes.size()); for (IvyNode node : nodes) { if (node != null && !node.isRoot() && !node.isCompletelyBlacklisted()) { dependencies.add(node); @@ -655,26 +651,26 @@ public class ResolveEngine { // can traverse the list and check only the direct parent and not all the ancestors for (IvyNode node : sortedDependencies) { if (!node.isCompletelyEvicted()) { - for (int i = 0; i < confs.length; i++) { - IvyNodeCallers.Caller[] callers = node.getCallers(confs[i]); + for (String conf : confs) { + IvyNodeCallers.Caller[] callers = node.getCallers(conf); if (settings.debugConflictResolution()) { Message.debug("checking if " + node.getId() - + " is transitively evicted in " + confs[i]); + + " is transitively evicted in " + conf); } boolean allEvicted = callers.length > 0; - for (int j = 0; j < callers.length; j++) { - if (callers[j].getModuleRevisionId().equals(md.getModuleRevisionId())) { + for (IvyNodeCallers.Caller caller : callers) { + if (caller.getModuleRevisionId().equals(md.getModuleRevisionId())) { // the caller is the root module itself, it can't be evicted allEvicted = false; break; } else { - IvyNode callerNode = data.getNode(callers[j].getModuleRevisionId()); + IvyNode callerNode = data.getNode(caller.getModuleRevisionId()); if (callerNode == null) { Message.warn("ivy internal error: no node found for " - + callers[j].getModuleRevisionId() + ": looked in " + + caller.getModuleRevisionId() + ": looked in " + data.getNodeIds() + " and root module id was " + md.getModuleRevisionId()); - } else if (!callerNode.isEvicted(confs[i])) { + } else if (!callerNode.isEvicted(conf)) { allEvicted = false; break; } else { @@ -687,7 +683,7 @@ public class ResolveEngine { } if (allEvicted) { Message.verbose("all callers are evicted for " + node + ": evicting too"); - node.markEvicted(confs[i], null, null, null); + node.markEvicted(conf, null, null, null); } else { if (settings.debugConflictResolution()) { Message.debug(node.getId() @@ -715,9 +711,8 @@ public class ResolveEngine { data.setCurrentVisitNode(node); DependencyDescriptor dd = node.getDependencyDescriptor(); VersionMatcher versionMatcher = node.getNode().getData().getSettings().getVersionMatcher(); - if (dd != null - && !(node.getRoot() == node.getParent() && versionMatcher.isDynamic(dd - .getDependencyRevisionId()))) { + if (dd != null && !(node.getRoot() == node.getParent() + && versionMatcher.isDynamic(dd.getDependencyRevisionId()))) { /* * we don't resolve conflicts before loading data for direct dependencies on dynamic * revisions, so that direct dynamic revisions are always resolved, which is mandatory @@ -732,18 +727,16 @@ public class ResolveEngine { // dependency to take the decision resolveConflict(node, conf); if (!node.isEvicted() && !node.isCircular()) { - String[] confs = node.getRealConfs(conf); - for (int i = 0; i < confs.length; i++) { - doFetchDependencies(node, confs[i]); + for (String rconf : node.getRealConfs(conf)) { + doFetchDependencies(node, rconf); } } } else if (!node.hasProblem()) { // the node has not been loaded but hasn't problem: it was already loaded // => we just have to update its dependencies data if (!node.isEvicted() && !node.isCircular()) { - String[] confs = node.getRealConfs(conf); - for (int i = 0; i < confs.length; i++) { - doFetchDependencies(node, confs[i]); + for (String rconf : node.getRealConfs(conf)) { + doFetchDependencies(node, rconf); } } } @@ -797,31 +790,28 @@ public class ResolveEngine { if (extendedConfs.length > 0) { node.updateConfsToFetch(Arrays.asList(extendedConfs)); } - for (int i = 0; i < extendedConfs.length; i++) { - fetchDependencies(node, extendedConfs[i], false); + for (String extendedConf : extendedConfs) { + fetchDependencies(node, extendedConf, false); } // now we can actually resolve this configuration dependencies if (!isDependenciesFetched(node.getNode(), conf) && node.isTransitive()) { - Collection dependencies = node.getDependencies(conf); - for (VisitNode dep : dependencies) { + for (VisitNode dep : node.getDependencies(conf)) { dep.useRealNode(); // the node may have been resolved to another real one while // resolving other deps - String[] confs = dep.getRequiredConfigurations(node, conf); - for (int i = 0; i < confs.length; i++) { - fetchDependencies(dep, confs[i], true); + for (String rconf : dep.getRequiredConfigurations(node, conf)) { + fetchDependencies(dep, rconf, true); } if (!dep.isEvicted() && !dep.hasProblem()) { // if there are still confs to fetch (usually because they have // been updated when evicting another module), we fetch them now - confs = dep.getConfsToFetch(); - for (int i = 0; i < confs.length; i++) { + for (String fconf : dep.getConfsToFetch()) { // shouldBeFixed=false to because some of those dependencies might // be private when they were actually extending public conf. // Should we keep two list of confs to fetch (private&public)? // I don't think, visibility is already checked, and a change in the // configuration between version might anyway have worse problems. - fetchDependencies(dep, confs[i], false); + fetchDependencies(dep, fconf, false); } } } @@ -982,8 +972,8 @@ public class ResolveEngine { ancestor.getNode().setResolvedNodes(node.getModuleId(), node.getRootModuleConf(), resolved); - Collection evicted = new HashSet(ancestor.getNode().getEvictedNodes( - node.getModuleId(), node.getRootModuleConf())); + Collection evicted = new HashSet<>(ancestor.getNode().getEvictedNodes( + node.getModuleId(), node.getRootModuleConf())); evicted.removeAll(resolved); evicted.addAll(toevict); ancestor.getNode().setEvictedNodes(node.getModuleId(), node.getRootModuleConf(), @@ -1003,8 +993,8 @@ public class ResolveEngine { // it's time to update parent resolved and evicted with what was found - Collection evicted = new HashSet(ancestor.getNode().getEvictedNodes( - node.getModuleId(), node.getRootModuleConf())); + Collection evicted = new HashSet<>(ancestor.getNode().getEvictedNodes( + node.getModuleId(), node.getRootModuleConf())); toevict.removeAll(resolved); evicted.removeAll(resolved); evicted.addAll(toevict); @@ -1091,7 +1081,7 @@ public class ResolveEngine { */ private Collection computeConflicts(VisitNode node, VisitNode ancestor, String conf, Collection toevict, Collection selectedNodes) { - Collection conflicts = new LinkedHashSet(); + Collection conflicts = new LinkedHashSet<>(); conflicts.add(node.getNode()); /* * We first try to remove all evicted nodes from the collection of selected nodes to update http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/69207179/src/java/org/apache/ivy/core/resolve/ResolveOptions.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/ivy/core/resolve/ResolveOptions.java b/src/java/org/apache/ivy/core/resolve/ResolveOptions.java index b434c05..77c5ee1 100644 --- a/src/java/org/apache/ivy/core/resolve/ResolveOptions.java +++ b/src/java/org/apache/ivy/core/resolve/ResolveOptions.java @@ -175,12 +175,7 @@ public class ResolveOptions extends LogOptions { * @see #getConfs(ModuleDescriptor) */ public boolean useSpecialConfs() { - for (int i = 0; confs != null && i < confs.length; i++) { - if (confs[0].startsWith("*")) { - return true; - } - } - return false; + return confs != null && confs[0].startsWith("*"); } /** http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/69207179/src/java/org/apache/ivy/core/resolve/VisitData.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/ivy/core/resolve/VisitData.java b/src/java/org/apache/ivy/core/resolve/VisitData.java index 3beb877..fa66858 100644 --- a/src/java/org/apache/ivy/core/resolve/VisitData.java +++ b/src/java/org/apache/ivy/core/resolve/VisitData.java @@ -38,7 +38,7 @@ public class VisitData { * The associated visit nodes, per rootModuleConf Note that the value is a List, because a node * can be visited from several parents during the resolution process */ - private Map> visitNodes = new HashMap>(); + private Map> visitNodes = new HashMap<>(); public VisitData(IvyNode node) { this.node = node; @@ -52,7 +52,7 @@ public class VisitData { public List getVisitNodes(String rootModuleConf) { List visits = visitNodes.get(rootModuleConf); if (visits == null) { - visits = new ArrayList(); + visits = new ArrayList<>(); visitNodes.put(rootModuleConf, visits); } return visits; http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/69207179/src/java/org/apache/ivy/core/resolve/VisitNode.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/ivy/core/resolve/VisitNode.java b/src/java/org/apache/ivy/core/resolve/VisitNode.java index b5171b9..39497f1 100644 --- a/src/java/org/apache/ivy/core/resolve/VisitNode.java +++ b/src/java/org/apache/ivy/core/resolve/VisitNode.java @@ -164,7 +164,7 @@ public class VisitNode { private Collection computePath() { if (parent != null) { - Collection p = new LinkedHashSet(parent.getPath()); + Collection p = new LinkedHashSet<>(parent.getPath()); p.add(this); return p; } else { @@ -196,7 +196,7 @@ public class VisitNode { public static VisitNode getRoot(VisitNode parent) { VisitNode root = parent; - Collection path = new HashSet(); + Collection path = new HashSet<>(); path.add(root); while (root.getParent() != null && !root.getNode().isRoot()) { if (path.contains(root.getParent())) { @@ -303,7 +303,7 @@ public class VisitNode { public Collection getDependencies(String conf) { Collection deps = node.getDependencies(rootModuleConf, conf, requestedConf); - Collection ret = new ArrayList(deps.size()); + Collection ret = new ArrayList<>(deps.size()); for (IvyNode depNode : deps) { ret.add(traverseChild(conf, depNode)); } http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/69207179/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java b/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java index 4822e89..9fcf80a 100644 --- a/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java +++ b/src/java/org/apache/ivy/core/retrieve/RetrieveEngine.java @@ -128,15 +128,15 @@ public class RetrieveEngine { report.setRetrieveRoot(fileRetrieveRoot); File ivyRetrieveRoot = destIvyPattern == null ? null : settings .resolveFile(IvyPatternHelper.getTokenRoot(destIvyPattern)); - Collection targetArtifactsStructure = new HashSet(); + Collection targetArtifactsStructure = new HashSet<>(); // Set(File) set of all paths which should be present at then end of retrieve (useful // for sync) - Collection targetIvysStructure = new HashSet(); // same for ivy files + Collection targetIvysStructure = new HashSet<>(); // same for ivy files if (options.isMakeSymlinksInMass()) { // The HashMap is of "destToSrc" because src could go two places, but dest can only // come from one - destToSrcMap = new HashMap(); + destToSrcMap = new HashMap<>(); } // do retrieve @@ -217,15 +217,13 @@ public class RetrieveEngine { Collection ignoreList = Arrays.asList(ignorableFilenames); Collection existingArtifacts = FileUtil.listAll(fileRetrieveRoot, ignoreList); - Collection existingIvys = ivyRetrieveRoot == null ? null : FileUtil.listAll( + Collection existingIvys = (ivyRetrieveRoot == null) ? null : FileUtil.listAll( ivyRetrieveRoot, ignoreList); if (fileRetrieveRoot.equals(ivyRetrieveRoot)) { - Collection target = targetArtifactsStructure; - target.addAll(targetIvysStructure); - Collection existing = existingArtifacts; - existing.addAll(existingIvys); - sync(target, existing); + targetArtifactsStructure.addAll(targetIvysStructure); + existingArtifacts.addAll(existingIvys); + sync(targetArtifactsStructure, existingArtifacts); } else { sync(targetArtifactsStructure, existingArtifacts); if (existingIvys != null) { @@ -269,9 +267,7 @@ public class RetrieveEngine { } catch (IOException e) { throw e; } catch (Exception e) { - IOException ioex = new IOException(e.getMessage()); - ioex.initCause(e); - throw ioex; + throw new IOException(e.getMessage(), e); } } return confs; @@ -282,7 +278,7 @@ public class RetrieveEngine { } private void sync(Collection target, Collection existing) { - Collection toRemove = new HashSet(); + Collection toRemove = new HashSet<>(); for (File file : existing) { toRemove.add(file.getAbsoluteFile()); } @@ -313,28 +309,25 @@ public class RetrieveEngine { // find what we must retrieve where // ArtifactDownloadReport source -> Set (String copyDestAbsolutePath) - final Map> artifactsToCopy = new HashMap>(); + final Map> artifactsToCopy = new HashMap<>(); // String copyDestAbsolutePath -> Set (ArtifactRevisionId source) - final Map> conflictsMap = new HashMap>(); + final Map> conflictsMap = new HashMap<>(); // String copyDestAbsolutePath -> Set (ArtifactDownloadReport source) - final Map> conflictsReportsMap = new HashMap>(); + final Map> conflictsReportsMap = new HashMap<>(); // String copyDestAbsolutePath -> Set (String conf) - final Map> conflictsConfMap = new HashMap>(); + final Map> conflictsConfMap = new HashMap<>(); XmlReportParser parser = new XmlReportParser(); - for (int i = 0; i < confs.length; i++) { - final String conf = confs[i]; - + for (final String conf : confs) { File report = cacheManager.getConfigurationResolveReportInCache(options.getResolveId(), conf); parser.parse(report); - Collection artifacts = new ArrayList( + Collection artifacts = new ArrayList<>( Arrays.asList(parser.getArtifactReports())); if (destIvyPattern != null) { - ModuleRevisionId[] mrids = parser.getRealDependencyRevisionIds(); - for (int j = 0; j < mrids.length; j++) { - artifacts.add(parser.getMetadataArtifactReport(mrids[j])); + for (ModuleRevisionId rmrid : parser.getRealDependencyRevisionIds()) { + artifacts.add(parser.getMetadataArtifactReport(rmrid)); } } final PackagingManager packagingManager = new PackagingManager(); @@ -356,8 +349,8 @@ public class RetrieveEngine { unpackedArtifact = packagingManager.getUnpackedArtifact(artifact); } if (unpackedArtifact == null) { - throw new RuntimeException("Could not determine unpacked artifact for " + artifact + - " while determining artifacts to copy for module " + mrid); + throw new RuntimeException("Could not determine unpacked artifact for " + artifact + + " while determining artifacts to copy for module " + mrid); } ext = unpackedArtifact.getExt(); } @@ -377,7 +370,7 @@ public class RetrieveEngine { artifact.getQualifiedExtraAttributes()); Set dest = artifactsToCopy.get(adr); if (dest == null) { - dest = new HashSet(); + dest = new HashSet<>(); artifactsToCopy.put(adr, dest); } String copyDest = settings.resolveFile(destFileName).getAbsolutePath(); @@ -387,24 +380,24 @@ public class RetrieveEngine { destinations = options.getMapper().mapFileName(copyDest); } - for (int j = 0; j < destinations.length; j++) { - dest.add(destinations[j]); + for (String destination : destinations) { + dest.add(destination); - Set conflicts = conflictsMap.get(destinations[j]); + Set conflicts = conflictsMap.get(destination); Set conflictsReports = conflictsReportsMap - .get(destinations[j]); - Set conflictsConf = conflictsConfMap.get(destinations[j]); + .get(destination); + Set conflictsConf = conflictsConfMap.get(destination); if (conflicts == null) { - conflicts = new HashSet(); - conflictsMap.put(destinations[j], conflicts); + conflicts = new HashSet<>(); + conflictsMap.put(destination, conflicts); } if (conflictsReports == null) { - conflictsReports = new HashSet(); - conflictsReportsMap.put(destinations[j], conflictsReports); + conflictsReports = new HashSet<>(); + conflictsReportsMap.put(destination, conflictsReports); } if (conflictsConf == null) { - conflictsConf = new HashSet(); - conflictsConfMap.put(destinations[j], conflictsConf); + conflictsConf = new HashSet<>(); + conflictsConfMap.put(destination, conflictsConf); } if (conflicts.add(artifact.getId())) { conflictsReports.add(adr); @@ -420,7 +413,7 @@ public class RetrieveEngine { Set artifacts = entry.getValue(); Set conflictsConfs = conflictsConfMap.get(copyDest); if (artifacts.size() > 1) { - List artifactsList = new ArrayList( + List artifactsList = new ArrayList<>( conflictsReportsMap.get(copyDest)); // conflicts battle is resolved by a sort using a conflict resolving policy // comparator which consider as greater a winning artifact http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/69207179/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java b/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java index 7f27d56..6fa2399 100644 --- a/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java +++ b/src/java/org/apache/ivy/core/retrieve/RetrieveOptions.java @@ -18,6 +18,7 @@ package org.apache.ivy.core.retrieve; import org.apache.ivy.core.LogOptions; +import org.apache.ivy.core.module.descriptor.Artifact; import org.apache.ivy.util.filter.Filter; import org.apache.ivy.util.filter.FilterHelper; @@ -55,7 +56,7 @@ public class RetrieveOptions extends LogOptions { /** * The filter to apply before retrieving artifacts. */ - private Filter artifactFilter = FilterHelper.NO_FILTER; + private Filter artifactFilter = FilterHelper.NO_FILTER; /** * True if a synchronisation of the destination directory should be done, false if a simple copy @@ -117,11 +118,11 @@ public class RetrieveOptions extends LogOptions { return this; } - public Filter getArtifactFilter() { + public Filter getArtifactFilter() { return artifactFilter; } - public RetrieveOptions setArtifactFilter(Filter artifactFilter) { + public RetrieveOptions setArtifactFilter(Filter artifactFilter) { this.artifactFilter = artifactFilter; return this; } http://git-wip-us.apache.org/repos/asf/ant-ivy/blob/69207179/src/java/org/apache/ivy/core/retrieve/RetrieveReport.java ---------------------------------------------------------------------- diff --git a/src/java/org/apache/ivy/core/retrieve/RetrieveReport.java b/src/java/org/apache/ivy/core/retrieve/RetrieveReport.java index 6dcb9fd..256678c 100644 --- a/src/java/org/apache/ivy/core/retrieve/RetrieveReport.java +++ b/src/java/org/apache/ivy/core/retrieve/RetrieveReport.java @@ -28,11 +28,11 @@ import org.apache.ivy.core.report.ArtifactDownloadReport; public class RetrieveReport { - private Collection upToDateFiles = new HashSet(); + private Collection upToDateFiles = new HashSet<>(); - private Collection copiedFiles = new HashSet(); + private Collection copiedFiles = new HashSet<>(); - private Map downloadReport = new HashMap(); + private Map downloadReport = new HashMap<>(); private File retrieveRoot; @@ -74,7 +74,7 @@ public class RetrieveReport { * @return Collection<File> */ public Collection getCopiedFiles() { - return new ArrayList(copiedFiles); + return new ArrayList<>(copiedFiles); } /** @@ -84,7 +84,7 @@ public class RetrieveReport { * @return Collection<File> */ public Collection getUpToDateFiles() { - return new ArrayList(upToDateFiles); + return new ArrayList<>(upToDateFiles); } /** @@ -94,7 +94,7 @@ public class RetrieveReport { * @return Collection<File> */ public Collection getRetrievedFiles() { - Collection result = new ArrayList(upToDateFiles.size() + copiedFiles.size()); + Collection result = new ArrayList<>(upToDateFiles.size() + copiedFiles.size()); result.addAll(upToDateFiles); result.addAll(copiedFiles); return result;