protected void execute()

in src/main/java/org/apache/sling/feature/extension/apiregions/analyser/CheckApiRegionsCrossFeatureDups.java [52:116]


    protected void execute(ApiRegions apiRegions, AnalyserTaskContext ctx) throws Exception {
        Set<String> checkedRegions = splitListConfig(ctx.getConfiguration().get("regions"));
        Set<String> ignoredPackages = splitListConfig(ctx.getConfiguration().get("ignoredPackages"));
        Set<String> warningPackages = splitListConfig(ctx.getConfiguration().get("warningPackages"));
        Set<String> definingFeatures = splitListConfig(ctx.getConfiguration().get("definingFeatures"));

        Map<String, Set<String>> regionExports = new HashMap<>();
        Set<ArtifactId> apiRegionsFeatures = new HashSet<>();

        for (ApiRegion r : apiRegions.listRegions()) {
            apiRegionsFeatures.addAll(Arrays.asList(r.getFeatureOrigins()));
            if (checkedRegions.isEmpty() || checkedRegions.contains(r.getName())) {
                Set<String> exports = regionExports.get(r.getName());
                if (exports == null) {
                    exports = new HashSet<>();
                    regionExports.put(r.getName(), exports);
                }
                exports.addAll(r.listExports().stream().map(ApiExport::getName).collect(Collectors.toSet()));
            }
        }

        if (definingFeatures.isEmpty()) {
            definingFeatures = apiRegionsFeatures
                    .stream()
                    .map(ArtifactId::toMvnId)
                    .collect(Collectors.toSet());
        }

        FeatureDescriptor f = ctx.getFeatureDescriptor();
        for (BundleDescriptor bd : f.getBundleDescriptors()) {
            List<ArtifactId> borgs = new ArrayList<>(Arrays.asList(bd.getArtifact().getFeatureOrigins()));
            removeDefiningFeatures(definingFeatures, borgs);

            if (!borgs.isEmpty()) {
                Set<String> reportedPackages = new HashSet<>();
                for (PackageInfo pi : bd.getExportedPackages()) {
                    String pkgName = pi.getName();
                    for (Map.Entry<String, Set<String>> entry : regionExports.entrySet()) {
                        if (entry.getValue().contains(pkgName) && !reportedPackages.contains(pkgName)) {
                            if (matchesSet(pkgName, ignoredPackages)) {
                                continue;
                            }

                            if (allOtherExportersNonDefining(pi, f, definingFeatures)) {
                                // If all exports are done by non-defining features then that's ok
                                continue;
                            }

                            reportedPackages.add(pi.getName());

                            String msg = "Package overlap found between region " + entry.getKey()
                                + " and bundle " + bd.getBundleSymbolicName() + " " + bd.getBundleVersion()
                                + " which comes from feature: " + borgs
                                + ". Both export package: " + pi.getName();
                            if (matchesSet(pkgName, warningPackages)) {
                                ctx.reportArtifactWarning(bd.getArtifact().getId(), msg);
                            } else {
                                ctx.reportArtifactError(bd.getArtifact().getId(), msg);
                            }
                        }
                    }
                }
            }
        }
    }