in src/main/java/org/apache/sling/feature/builder/BuilderUtil.java [207:269]
static List<Artifact> selectArtifactOverride(Feature source, Artifact fromTarget, Artifact fromSource,
List<ArtifactId> artifactOverrides, ArtifactId sourceID) {
if (fromTarget.getId().equals(fromSource.getId())) {
// They're the same so return the source (latest)
return Collections.singletonList(addFeatureOrigin(selectStartOrder(fromTarget, fromSource, fromSource), source, fromSource, fromTarget));
}
final Set<ArtifactId> commonPrefixes = getCommonArtifactIds(fromTarget, fromSource);
if (commonPrefixes.isEmpty()) {
throw new IllegalStateException(
"Internal error selecting override. No common prefix between " + fromTarget + " and " + fromSource);
}
final List<Artifact> result = new ArrayList<>();
if (artifactOverrides.isEmpty() && fromTarget.getMetadata().containsKey(BuilderUtil.class.getName() + "added")) {
result.add(fromTarget);
result.add(addFeatureOrigin(fromSource, source, fromSource));
return result;
}
outer: for (ArtifactId prefix : commonPrefixes) {
for (final ArtifactId override : artifactOverrides) {
if (match(prefix, override)) {
String rule = override.getVersion();
if (BuilderContext.VERSION_OVERRIDE_ALL.equalsIgnoreCase(rule)) {
result.add(fromTarget);
result.add(fromSource);
} else if (BuilderContext.VERSION_OVERRIDE_HIGHEST.equalsIgnoreCase(rule)) {
Version a1v = fromTarget.getAliases(true).stream().filter(prefix::isSame).findFirst().get().getOSGiVersion();
Version a2v = fromSource.getAliases(true).stream().filter(prefix::isSame).findFirst().get().getOSGiVersion();
result.add(
addFeatureOrigin(
selectStartOrder(fromTarget, fromSource, a1v.compareTo(a2v) > 0 ? fromTarget : fromSource),
source, fromSource, fromTarget));
} else if (BuilderContext.VERSION_OVERRIDE_FIRST.equalsIgnoreCase(rule)) {
result.add(addFeatureOrigin(selectStartOrder(fromTarget, fromSource, fromTarget), source, fromSource, fromTarget));
} else if (BuilderContext.VERSION_OVERRIDE_LATEST.equalsIgnoreCase(rule)) {
result.add(addFeatureOrigin(selectStartOrder(fromTarget, fromSource, fromSource), source, fromSource, fromTarget));
} else {
// The rule must represent a version
// See if its one of the existing artifact. If so use those, as they may have
// additional metadata
if (fromTarget.getId().getVersion().equals(rule)) {
result.add(addFeatureOrigin(selectStartOrder(fromTarget, fromSource, fromTarget), source, fromSource, fromTarget));
} else if (fromSource.getId().getVersion().equals(rule)) {
result.add(addFeatureOrigin(selectStartOrder(fromTarget, fromSource, fromSource), source, fromSource, fromTarget));
} else {
// It's a completely new artifact
result.add(addFeatureOrigin(selectStartOrder(fromTarget, fromSource, new Artifact(override)), source, fromSource, fromTarget));
}
}
break outer;
}
}
}
if (!result.isEmpty()) {
return result;
}
throw new IllegalStateException("Artifact override rule required to select between these two artifacts " +
fromTarget + " and " + fromSource + ". The rule must be specified for " + commonPrefixes);
}