Search in sources :

Example 1 with FeaturePattern

use of org.apache.karaf.features.FeaturePattern in project karaf by apache.

the class Blacklist method compileClauses.

/**
 * Extracts blacklisting clauses related to bundles, features and repositories and changes them to more
 * usable form.
 */
private void compileClauses() {
    for (Clause c : clauses) {
        String type = c.getAttribute(BLACKLIST_TYPE);
        if (type == null) {
            String url = c.getAttribute(BLACKLIST_URL);
            if (url != null || c.getName().startsWith("mvn:")) {
                // some special rules from etc/blacklisted.properties
                type = TYPE_BUNDLE;
            } else {
                type = TYPE_FEATURE;
            }
        }
        String location;
        switch(type) {
            case TYPE_REPOSITORY:
                location = c.getName();
                if (c.getAttribute(BLACKLIST_URL) != null) {
                    location = c.getAttribute(BLACKLIST_URL);
                }
                if (location == null) {
                    // should not happen?
                    LOG.warn("Repository blacklist URI is empty. Ignoring.");
                } else {
                    try {
                        repositoryBlacklist.add(new LocationPattern(location));
                    } catch (IllegalArgumentException e) {
                        LOG.warn("Problem parsing repository blacklist URI \"" + location + "\": " + e.getMessage() + ". Ignoring.");
                    }
                }
                break;
            case TYPE_FEATURE:
                try {
                    featureBlacklist.add(new FeaturePattern(c.toString()));
                } catch (IllegalArgumentException e) {
                    LOG.warn("Problem parsing blacklisted feature identifier \"" + c.toString() + "\": " + e.getMessage() + ". Ignoring.");
                }
                break;
            case TYPE_BUNDLE:
                location = c.getName();
                if (c.getAttribute(BLACKLIST_URL) != null) {
                    location = c.getAttribute(BLACKLIST_URL);
                }
                if (location == null) {
                    // should not happen?
                    LOG.warn("Bundle blacklist URI is empty. Ignoring.");
                } else {
                    try {
                        bundleBlacklist.add(new LocationPattern(location));
                    } catch (IllegalArgumentException e) {
                        LOG.warn("Problem parsing bundle blacklist URI \"" + location + "\": " + e.getMessage() + ". Ignoring.");
                    }
                }
                break;
        }
    }
}
Also used : LocationPattern(org.apache.karaf.features.LocationPattern) FeaturePattern(org.apache.karaf.features.FeaturePattern) Clause(org.apache.felix.utils.manifest.Clause)

Example 2 with FeaturePattern

use of org.apache.karaf.features.FeaturePattern in project karaf by apache.

the class FeaturesProcessorImpl method process.

@Override
public void process(Features features) {
    List<Feature> featureList = features.getFeature();
    for (int i = 0; i < featureList.size(); i++) {
        Feature f = featureList.get(i);
        // overriding features first, so we can further override their bundles
        for (FeatureReplacements.OverrideFeature override : getInstructions().getFeatureReplacements().getReplacements()) {
            if (f.getId().equals(override.getFeature().getId())) {
                switch(override.getMode()) {
                    case REPLACE:
                        featureList.set(i, override.getFeature());
                        break;
                    case MERGE:
                        f.getBundle().addAll(override.getFeature().getBundle());
                        break;
                    case REMOVE:
                        // TODO
                        break;
                }
            }
        }
    }
    for (Feature feature : features.getFeature()) {
        // blacklisting features
        boolean allBlacklisted = features.isBlacklisted();
        feature.setBlacklisted(allBlacklisted || isFeatureBlacklisted(feature));
        // blacklisting feature's dependencies and conditionals
        for (Conditional conditional : feature.getConditional()) {
            boolean isConditionBlacklisted = false;
            for (String cond : conditional.getCondition()) {
                isConditionBlacklisted |= isFeatureBlacklisted(new Feature(cond));
            }
            conditional.setBlacklisted(feature.isBlacklisted() || isConditionBlacklisted);
        }
        for (Dependency dep : feature.getFeature()) {
            dep.setBlacklisted(feature.isBlacklisted() || isFeatureBlacklisted(new Feature(dep.getName(), dep.getVersion())));
        }
        // override dependency flag (null - don't touch, false - change to false, true - change to true)
        Boolean dependency = null;
        for (OverrideBundleDependency.OverrideFeatureDependency overrideFeatureDependency : getInstructions().getOverrideBundleDependency().getFeatures()) {
            FeaturePattern pattern = new FeaturePattern(overrideFeatureDependency.getName() + "/" + overrideFeatureDependency.getVersion());
            if (pattern.matches(feature.getName(), feature.getVersion())) {
                dependency = overrideFeatureDependency.isDependency();
            }
        }
        // blacklisting bundles and processing bundles
        processBundles(feature.getBundle(), allBlacklisted, dependency);
        for (Conditional c : feature.getConditional()) {
            processBundles(c.getBundle(), allBlacklisted, dependency);
        }
    // TODO: think about overriding at repository level
    // for (OverrideBundleDependency.OverrideDependency overrideDependency : getInstructions().getOverrideBundleDependency().getRepositories()) {
    // }
    }
}
Also used : FeaturePattern(org.apache.karaf.features.FeaturePattern) FeatureReplacements(org.apache.karaf.features.internal.model.processing.FeatureReplacements) Conditional(org.apache.karaf.features.internal.model.Conditional) Dependency(org.apache.karaf.features.internal.model.Dependency) OverrideBundleDependency(org.apache.karaf.features.internal.model.processing.OverrideBundleDependency) Feature(org.apache.karaf.features.internal.model.Feature) OverrideBundleDependency(org.apache.karaf.features.internal.model.processing.OverrideBundleDependency)

Example 3 with FeaturePattern

use of org.apache.karaf.features.FeaturePattern in project karaf by apache.

the class Builder method processBlacklist.

/**
 * Checks existing and configured blacklisting definitions
 * @param initialProfile
 * @return
 * @throws IOException
 */
private Blacklist processBlacklist(Profile initialProfile) throws IOException {
    Blacklist existingBlacklist = null;
    Blacklist blacklist = new Blacklist();
    Path existingBLacklistedLocation = etcDirectory.resolve("blacklisted.properties");
    if (existingBLacklistedLocation.toFile().isFile()) {
        LOGGER.warn("Found {} which is deprecated, please use new feature processor configuration.", homeDirectory.relativize(existingBLacklistedLocation));
        existingBlacklist = new Blacklist(Files.readAllLines(existingBLacklistedLocation));
    }
    for (String br : blacklistedRepositoryURIs) {
        // from Maven/Builder configuration
        try {
            blacklist.blacklistRepository(new LocationPattern(br));
        } catch (IllegalArgumentException e) {
            LOGGER.warn("Blacklisted features XML repository URI is invalid: {}, ignoring", br);
        }
    }
    for (LocationPattern br : initialProfile.getBlacklistedRepositories()) {
        // from profile configuration
        blacklist.blacklistRepository(br);
    }
    for (String bf : blacklistedFeatureIdentifiers) {
        // from Maven/Builder configuration
        blacklist.blacklistFeature(new FeaturePattern(bf));
    }
    for (FeaturePattern bf : initialProfile.getBlacklistedFeatures()) {
        // from profile configuration
        blacklist.blacklistFeature(bf);
    }
    for (String bb : blacklistedBundleURIs) {
        // from Maven/Builder configuration
        try {
            blacklist.blacklistBundle(new LocationPattern(bb));
        } catch (IllegalArgumentException e) {
            LOGGER.warn("Blacklisted bundle URI is invalid: {}, ignoring", bb);
        }
    }
    for (LocationPattern bb : initialProfile.getBlacklistedBundles()) {
        // from profile configuration
        blacklist.blacklistBundle(bb);
    }
    if (existingBlacklist != null) {
        blacklist.merge(existingBlacklist);
    }
    return blacklist;
}
Also used : Path(java.nio.file.Path) LocationPattern(org.apache.karaf.features.LocationPattern) FeaturePattern(org.apache.karaf.features.FeaturePattern) Blacklist(org.apache.karaf.features.internal.service.Blacklist)

Example 4 with FeaturePattern

use of org.apache.karaf.features.FeaturePattern in project karaf by apache.

the class FeatureSelector method getMatchingFeatures.

/**
 * Assuming <code>idOrPattern</code> may be a pattern (with glob and version range), get all matching features
 * @param idOrPattern
 * @param repositories
 * @return
 */
public static Collection<String> getMatchingFeatures(String idOrPattern, Collection<Features> repositories) {
    List<String> result = new LinkedList<>();
    FeaturePattern pattern = new FeaturePattern(idOrPattern);
    for (Features features : repositories) {
        for (Feature feature : features.getFeature()) {
            // blacklisting will be applied anyway, so no need to do it here
            if (/*!feature.isBlacklisted() && */
            pattern.matches(feature.getName(), feature.getVersion())) {
                result.add(feature.getId());
            }
        }
    }
    return result;
}
Also used : FeaturePattern(org.apache.karaf.features.FeaturePattern) Features(org.apache.karaf.features.internal.model.Features) Feature(org.apache.karaf.features.internal.model.Feature) LinkedList(java.util.LinkedList)

Aggregations

FeaturePattern (org.apache.karaf.features.FeaturePattern)4 LocationPattern (org.apache.karaf.features.LocationPattern)2 Feature (org.apache.karaf.features.internal.model.Feature)2 Path (java.nio.file.Path)1 LinkedList (java.util.LinkedList)1 Clause (org.apache.felix.utils.manifest.Clause)1 Conditional (org.apache.karaf.features.internal.model.Conditional)1 Dependency (org.apache.karaf.features.internal.model.Dependency)1 Features (org.apache.karaf.features.internal.model.Features)1 FeatureReplacements (org.apache.karaf.features.internal.model.processing.FeatureReplacements)1 OverrideBundleDependency (org.apache.karaf.features.internal.model.processing.OverrideBundleDependency)1 Blacklist (org.apache.karaf.features.internal.service.Blacklist)1