You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@ant.apache.org by xa...@apache.org on 2008/02/07 19:03:16 UTC
svn commit: r619531 -
/ant/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/ResolveEngine.java
Author: xavier
Date: Thu Feb 7 10:03:12 2008
New Revision: 619531
URL: http://svn.apache.org/viewvc?rev=619531&view=rev
Log:
refactor: check parameters in getDependencies at the beginning of the method for quicker feedback on problems + some refactoring and changes to comply to checkstyle rules
Modified:
ant/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/ResolveEngine.java
Modified: ant/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/ResolveEngine.java
URL: http://svn.apache.org/viewvc/ant/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/ResolveEngine.java?rev=619531&r1=619530&r2=619531&view=diff
==============================================================================
--- ant/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/ResolveEngine.java (original)
+++ ant/ivy/core/trunk/src/java/org/apache/ivy/core/resolve/ResolveEngine.java Thu Feb 7 10:03:12 2008
@@ -57,7 +57,6 @@
import org.apache.ivy.core.report.DownloadStatus;
import org.apache.ivy.core.report.ResolveReport;
import org.apache.ivy.core.resolve.IvyNodeEviction.EvictionData;
-import org.apache.ivy.core.settings.IvySettings;
import org.apache.ivy.core.sort.SortEngine;
import org.apache.ivy.plugins.conflict.ConflictManager;
import org.apache.ivy.plugins.parser.ModuleDescriptorParser;
@@ -432,13 +431,31 @@
*/
public IvyNode[] getDependencies(ModuleDescriptor md, ResolveOptions options,
ResolveReport report) {
+ // check parameters
if (md == null) {
throw new NullPointerException("module descriptor must not be null");
}
- IvyContext context = IvyContext.pushNewCopyContext();
+ String[] confs = options.getConfs(md);
+ Collection missingConfs = new ArrayList();
+ for (int i = 0; i < confs.length; i++) {
+ if (confs[i] == null) {
+ throw new NullPointerException("null conf not allowed: confs where: "
+ + Arrays.asList(confs));
+ }
+
+ if (md.getConfiguration(confs[i]) == null) {
+ missingConfs.add(" '" + confs[i] + "' ");
+ }
+ }
+ if (!missingConfs.isEmpty()) {
+ throw new IllegalArgumentException(
+ "requested configuration" + (missingConfs.size() > 1 ? "s" : "")
+ + " not found in "
+ + md.getModuleRevisionId() + ": " + missingConfs);
+ }
+ IvyContext context = IvyContext.pushNewCopyContext();
try {
- String[] confs = options.getConfs(md);
options.setConfs(confs);
Date reportDate = new Date();
@@ -450,65 +467,47 @@
IvyNode rootNode = new IvyNode(data, md);
for (int i = 0; i < confs.length; i++) {
- if (confs[i] == null) {
- throw new NullPointerException("null conf not allowed: confs where: "
- + Arrays.asList(confs));
- }
-
Message.verbose("resolving dependencies for configuration '" + confs[i] + "'");
// for each configuration we clear the cache of what's been fetched
fetchedSet.clear();
- Configuration configuration = md.getConfiguration(confs[i]);
- if (configuration == null) {
- Collection missingConfs = new ArrayList();
- missingConfs.add(" '" + confs[i] + "' ");
- for (i++; i < confs.length; i++) {
- if (md.getConfiguration(confs[i]) == null) {
- missingConfs.add(" '" + confs[i] + "' ");
- }
- }
- throw new IllegalArgumentException("asked configuration(s) not found in "
- + md.getModuleRevisionId() + ": " + missingConfs);
- } else {
- ConfigurationResolveReport confReport = null;
- if (report != null) {
- confReport = report.getConfigurationReport(confs[i]);
- if (confReport == null) {
- confReport = new ConfigurationResolveReport(
- this, md, confs[i], reportDate, options);
- report.addReport(confs[i], 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]));
-
- // go fetch !
- boolean fetched = false;
- while (!fetched) {
- try {
- fetchDependencies(root, confs[i], false);
- fetched = true;
- } catch (RestartResolveProcess restart) {
- Message.verbose("====================================================");
- Message.verbose("= RESTARTING RESOLVE PROCESS");
- Message.verbose("= " + restart.getMessage());
- Message.verbose("====================================================");
- fetchedSet.clear();
- }
+ ConfigurationResolveReport confReport = null;
+ if (report != null) {
+ confReport = report.getConfigurationReport(confs[i]);
+ if (confReport == null) {
+ confReport = new ConfigurationResolveReport(
+ this, md, confs[i], reportDate, options);
+ report.addReport(confs[i], confReport);
}
-
- // clean data
- for (Iterator iter = data.getNodes().iterator(); iter.hasNext();) {
- IvyNode dep = (IvyNode) iter.next();
- dep.clean();
+ }
+ // 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]));
+
+ // go fetch !
+ boolean fetched = false;
+ while (!fetched) {
+ try {
+ fetchDependencies(root, confs[i], false);
+ fetched = true;
+ } catch (RestartResolveProcess restart) {
+ Message.verbose("====================================================");
+ Message.verbose("= RESTARTING RESOLVE PROCESS");
+ Message.verbose("= " + restart.getMessage());
+ Message.verbose("====================================================");
+ fetchedSet.clear();
}
}
+
+ // clean data
+ for (Iterator iter = data.getNodes().iterator(); iter.hasNext();) {
+ IvyNode dep = (IvyNode) iter.next();
+ dep.clean();
+ }
}
// prune and reverse sort fectched dependencies
@@ -524,61 +523,66 @@
List sortedDependencies = sortEngine.sortNodes(dependencies);
Collections.reverse(sortedDependencies);
- // handle transitive eviction now:
- // if a module has been evicted then all its dependencies required only by it should be
- // evicted too. Since nodes are now sorted from the more dependent to the less one, we
- // can traverse the list and check only the direct parent and not all the ancestors
- for (ListIterator iter = sortedDependencies.listIterator(); iter.hasNext();) {
- IvyNode node = (IvyNode) iter.next();
- if (!node.isCompletelyEvicted()) {
- for (int i = 0; i < confs.length; i++) {
- IvyNodeCallers.Caller[] callers = node.getCallers(confs[i]);
- if (settings.debugConflictResolution()) {
- Message.debug("checking if " + node.getId()
- + " is transitively evicted in " + confs[i]);
- }
- boolean allEvicted = callers.length > 0;
- for (int j = 0; j < callers.length; j++) {
- if (callers[j].getModuleRevisionId().equals(md.getModuleRevisionId())) {
- // the caller is the root module itself, it can't be evicted
+ handleTransiviteEviction(md, confs, data, sortedDependencies);
+
+ return (IvyNode[]) dependencies.toArray(new IvyNode[dependencies.size()]);
+ } finally {
+ IvyContext.popContext();
+ }
+ }
+
+ private void handleTransiviteEviction(
+ ModuleDescriptor md, String[] confs, ResolveData data, List sortedDependencies) {
+ // handle transitive eviction now:
+ // if a module has been evicted then all its dependencies required only by it should be
+ // evicted too. Since nodes are now sorted from the more dependent to the less one, we
+ // can traverse the list and check only the direct parent and not all the ancestors
+ for (ListIterator iter = sortedDependencies.listIterator(); iter.hasNext();) {
+ IvyNode node = (IvyNode) iter.next();
+ if (!node.isCompletelyEvicted()) {
+ for (int i = 0; i < confs.length; i++) {
+ IvyNodeCallers.Caller[] callers = node.getCallers(confs[i]);
+ if (settings.debugConflictResolution()) {
+ Message.debug("checking if " + node.getId()
+ + " is transitively evicted in " + confs[i]);
+ }
+ boolean allEvicted = callers.length > 0;
+ for (int j = 0; j < callers.length; j++) {
+ if (callers[j].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());
+ if (callerNode == null) {
+ Message.warn("ivy internal error: no node found for "
+ + callers[j].getModuleRevisionId() + ": looked in "
+ + data.getNodeIds() + " and root module id was "
+ + md.getModuleRevisionId());
+ } else if (!callerNode.isEvicted(confs[i])) {
allEvicted = false;
break;
} else {
- IvyNode callerNode = data.getNode(callers[j].getModuleRevisionId());
- if (callerNode == null) {
- Message.warn("ivy internal error: no node found for "
- + callers[j].getModuleRevisionId() + ": looked in "
- + data.getNodeIds() + " and root module id was "
- + md.getModuleRevisionId());
- } else if (!callerNode.isEvicted(confs[i])) {
- allEvicted = false;
- break;
- } else {
- if (settings.debugConflictResolution()) {
- Message.debug("caller " + callerNode.getId() + " of "
- + node.getId() + " is evicted");
- }
+ if (settings.debugConflictResolution()) {
+ Message.debug("caller " + callerNode.getId() + " of "
+ + node.getId() + " is evicted");
}
}
}
- if (allEvicted) {
- Message.verbose("all callers are evicted for "
- + node + ": evicting too");
- node.markEvicted(confs[i], null, null, null);
- } else {
- if (settings.debugConflictResolution()) {
- Message.debug(node.getId()
- + " isn't transitively evicted, at least one caller was"
- + " not evicted");
- }
+ }
+ if (allEvicted) {
+ Message.verbose("all callers are evicted for "
+ + node + ": evicting too");
+ node.markEvicted(confs[i], null, null, null);
+ } else {
+ if (settings.debugConflictResolution()) {
+ Message.debug(node.getId()
+ + " isn't transitively evicted, at least one caller was"
+ + " not evicted");
}
}
}
}
-
- return (IvyNode[]) dependencies.toArray(new IvyNode[dependencies.size()]);
- } finally {
- IvyContext.popContext();
}
}