Deal with POM dependencies in generated features.xml using generate Maven plugin
@@ -580,7 +580,14 @@ public class GenerateDescriptorMojo extends MojoSupport {
Dependency dependency = new Dependency(includedFeature.getName(), includedFeature.getVersion());
dependency.setPrerequisite(prerequisiteFeatures.contains(dependency.getName()));
dependency.setDependency(dependencyFeatures.contains(dependency.getName()));
- // We musn't de-duplicate here, we may have seen a feature in !add mode
+ // Determine what dependency we're actually going to use
+ Dependency matchingDependency = findMatchingDependency(feature.getFeature(), dependency);
+ if (matchingDependency != null) {
+ // The feature already has a matching dependency, merge
+ mergeDependencies(matchingDependency, dependency);
+ dependency = matchingDependency;
+ }
+ // We mustn't de-duplicate here, we may have seen a feature in !add mode
otherFeatures.put(dependency, includedFeature);
if (add) {
if (!feature.getFeature().contains(dependency)) {
@@ -598,6 +605,28 @@ public class GenerateDescriptorMojo extends MojoSupport {
}
}
+ private Dependency findMatchingDependency(List<Dependency> dependencies, Dependency reference) {
+ String referenceName = reference.getName();
+ for (Dependency dependency : dependencies) {
+ if (referenceName.equals(dependency.getName())) {
+ return dependency;
+ }
+ }
+ return null;
+ }
+
+ private void mergeDependencies(Dependency target, Dependency source) {
+ if (target.getVersion() == null || Feature.DEFAULT_VERSION.equals(target.getVersion())) {
+ target.setVersion(source.getVersion());
+ }
+ if (source.isDependency()) {
+ target.setDependency(true);
+ }
+ if (source.isPrerequisite()) {
+ target.setPrerequisite(true);
+ }
+ }
+
private boolean isBundleIncludedTransitively(Feature feature, Map<Dependency, Feature> otherFeatures,
Bundle bundle) {
for (Dependency dependency : feature.getFeature()) {
