This is an automated email from the ASF dual-hosted git repository.
bodewig pushed a commit to branch ivy-1642
in repository https://gitbox.apache.org/repos/asf/ant-ivy.git
The following commit(s) were added to refs/heads/ivy-1642 by this push:
new ed104821 don't revert changes made for IVY-1580
ed104821 is described below
commit ed104821825bafb113c5a8bac2c81d97a8e6a729
Author: Stefan Bodewig <[email protected]>
AuthorDate: Fri Apr 14 12:13:58 2023 +0200
don't revert changes made for IVY-1580
---
src/java/org/apache/ivy/core/resolve/IvyNode.java | 6 +++
.../org/apache/ivy/core/resolve/IvyNodeUsage.java | 50 ++++++++++++++++++----
2 files changed, 48 insertions(+), 8 deletions(-)
diff --git a/src/java/org/apache/ivy/core/resolve/IvyNode.java
b/src/java/org/apache/ivy/core/resolve/IvyNode.java
index 273488ef..c7872c89 100644
--- a/src/java/org/apache/ivy/core/resolve/IvyNode.java
+++ b/src/java/org/apache/ivy/core/resolve/IvyNode.java
@@ -49,6 +49,7 @@ import org.apache.ivy.core.module.descriptor.IncludeRule;
import org.apache.ivy.core.module.descriptor.MDArtifact;
import org.apache.ivy.core.module.descriptor.ModuleDescriptor;
import org.apache.ivy.core.module.id.ArtifactId;
+import org.apache.ivy.core.module.id.ArtifactRevisionId;
import org.apache.ivy.core.module.id.ModuleId;
import org.apache.ivy.core.module.id.ModuleRevisionId;
import org.apache.ivy.core.resolve.IvyNodeCallers.Caller;
@@ -873,6 +874,7 @@ public class IvyNode implements Comparable<IvyNode> {
// now exclude artifacts that aren't accepted by any caller
Iterator<Artifact> iter = artifacts.iterator();
+ Set<ArtifactRevisionId> artifactRevisionsSeen = new
HashSet<ArtifactRevisionId>();
while (iter.hasNext()) {
Artifact artifact = iter.next();
boolean excluded = callers.doesCallersExclude(rootModuleConf,
artifact);
@@ -880,6 +882,10 @@ public class IvyNode implements Comparable<IvyNode> {
Message.debug(this + " in " + rootModuleConf + ": excluding "
+ artifact);
iter.remove();
}
+ if (!artifactRevisionsSeen.add(artifact.getId())) {
+ Message.debug(this + " in " + rootModuleConf + ": skipping
duplicate " + artifact);
+ iter.remove();
+ }
}
return artifacts.toArray(new Artifact[artifacts.size()]);
}
diff --git a/src/java/org/apache/ivy/core/resolve/IvyNodeUsage.java
b/src/java/org/apache/ivy/core/resolve/IvyNodeUsage.java
index c9676dcc..f96beb91 100644
--- a/src/java/org/apache/ivy/core/resolve/IvyNodeUsage.java
+++ b/src/java/org/apache/ivy/core/resolve/IvyNodeUsage.java
@@ -24,10 +24,15 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
+import org.apache.ivy.core.module.descriptor.DefaultIncludeRule;
import org.apache.ivy.core.module.descriptor.DependencyArtifactDescriptor;
import org.apache.ivy.core.module.descriptor.DependencyDescriptor;
import org.apache.ivy.core.module.descriptor.IncludeRule;
import org.apache.ivy.core.module.descriptor.WorkspaceModuleDescriptor;
+import org.apache.ivy.core.module.id.ArtifactId;
+import org.apache.ivy.core.module.id.ModuleId;
+import org.apache.ivy.plugins.matcher.ExactPatternMatcher;
+import org.apache.ivy.plugins.matcher.PatternMatcher;
/**
* Class collecting usage data for an IvyNode.
@@ -238,15 +243,35 @@ public class IvyNodeUsage {
if (dependersInConf == null) {
return null;
}
- Set<IncludeRule> dependencyIncludes = new HashSet<>();
- for (Depender depender : dependersInConf) {
- IncludeRule[] rules =
depender.dd.getIncludeRules(depender.dependerConf);
- if (rules == null || rules.length == 0) {
- // no include rule in at least one depender -> we must include
everything,
- // and so return no include rule at all
- return null;
+ final Set<IncludeRule> dependencyIncludes = new HashSet<>();
+ // true if the depedency descriptor of any of the depender *doesn't*
have an explicit
+ // "<artifact>" or an "<include>". false otherwise
+ boolean atLeastOneDependerNeedsAllArtifacts = false;
+ // true if the dependency descriptor of any of the depender either has
an explicit "<artifact>"
+ // or an "<include>". false otherwise
+ boolean atLeastOneDependerHasSpecificArtifactSelection = false;
+ for (final Depender depender : dependersInConf) {
+ final DependencyArtifactDescriptor dads[] =
depender.dd.getDependencyArtifacts(depender.dd.getModuleConfigurations());
+ final boolean declaresArtifacts = dads != null && dads.length > 0;
+ final IncludeRule[] rules =
depender.dd.getIncludeRules(depender.dependerConf);
+ final boolean hasIncludeRule = rules != null && rules.length > 0;
+ if (hasIncludeRule) {
+ dependencyIncludes.addAll(Arrays.asList(rules));
+ }
+ if (declaresArtifacts || hasIncludeRule) {
+ atLeastOneDependerHasSpecificArtifactSelection = true;
}
- dependencyIncludes.addAll(Arrays.asList(rules));
+ if (!hasIncludeRule && !declaresArtifacts) {
+ atLeastOneDependerNeedsAllArtifacts = true;
+ }
+ }
+ // so there's at least one depender D1 which has a specific artifact
dependency and at the
+ // same time there's a depender D2 which doesn't have any explicit
artifact/includes.
+ // so it is expected that an implicit "include all artifacts" is
applied so that dependencies
+ // such as D2 get (all) the artifacts that are published by the
dependency's module
+ if (atLeastOneDependerHasSpecificArtifactSelection &&
atLeastOneDependerNeedsAllArtifacts) {
+ // add a "include all artifacts" rule
+ dependencyIncludes.add(includeAllArtifacts());
}
return dependencyIncludes;
}
@@ -313,4 +338,13 @@ public class IvyNodeUsage {
return false;
}
+ private static IncludeRule includeAllArtifacts() {
+ final ArtifactId aid = new ArtifactId(
+ new ModuleId(PatternMatcher.ANY_EXPRESSION,
PatternMatcher.ANY_EXPRESSION),
+ PatternMatcher.ANY_EXPRESSION, PatternMatcher.ANY_EXPRESSION,
+ PatternMatcher.ANY_EXPRESSION);
+ return new DefaultIncludeRule(aid, ExactPatternMatcher.INSTANCE, null);
+ }
+
+
}