public void execute()

in src/main/java/org/apache/sling/feature/analyser/task/impl/CheckCompareFeatures.java [44:100]


    public void execute(AnalyserTaskContext ctx) throws Exception {
        Map<String, String> cfg = ctx.getConfiguration();
        String aid = cfg.get("compare-with");
        if (aid == null) {
            throw new Exception("Missing 'compare-with' configuration for compare-features analyser.");
        }

        String ext = cfg.get("compare-extension");
        String mode = cfg.getOrDefault("compare-mode", "SAME");
        String type = cfg.getOrDefault("compare-type", "ARTIFACTS");
        if (!"ARTIFACTS".equals(type)) {
            throw new Exception("The only supported value for 'compare-type' right now is ARTIFACTS");
        }

        boolean strictMetadata = !cfg.getOrDefault("compare-metadata", "false").equalsIgnoreCase("false");

        FeatureProvider featureProvider = ctx.getFeatureProvider();
        if (featureProvider == null) {
            throw new Exception("This analyser requires a Feature Provider to be set in the Analyser Task Context.");
        }

        Feature feat = featureProvider.provide(ArtifactId.fromMvnId(aid));
        if (feat == null)
            throw new Exception("Feature not found: " + aid);

        Artifacts mainArts = getArtifactsToCompare(feat, ext);
        Artifacts compArts = getArtifactsToCompare(ctx.getFeature(), ext);

        String violationMessage = null;
        switch (mode) {
        case "SAME":
            violationMessage = assertArtifactsSame(mainArts, compArts, strictMetadata);
            break;
        case "DIFFERENT":
            violationMessage = assertArtifactsSame(mainArts, compArts, strictMetadata);
            if (violationMessage == null) {
                violationMessage = "Artifacts are not different";
            } else {
                violationMessage = null;
            }
            break;
        default:
            throw new Exception("Unknown comparison mode: " + mode);
        }

        if (violationMessage != null) {
            String origin;
            if (ext == null) {
                origin = "bundles";
            } else {
                origin = "extension " + ext;
            }

            ctx.reportError("Compare " + origin + " in feature " + feat.getId() + " and "
                    + ctx.getFeature().getId() + " failed: " + violationMessage);
        }
    }