karaf-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Grzegorz Grzybek <gr.grzy...@gmail.com>
Subject [heads up - long] "Features Processor" that replaces overrides and blacklisting (and more)
Date Sat, 02 Dec 2017 20:27:27 GMT

I want to report about my progress with
https://issues.apache.org/jira/browse/KARAF-5376 (Processor mechanism for
feature definitions (a.k.a. "better overrides")).

*Goal* - to replace (or provide more flexible alternative) of "overrides"
and "blacklisting" mechanisms

*Idea* - Karaf features come (normally) from features XML files, according
to XML Schema specified by Karaf itself. My idea was that we can
"intercept" the process of loading the repositories and alter the
definitions. Effectively we could then affect the definitions which may be
out of our influence, or use some bundles we'd rather like to replace with
others. Some feature repositories include other repositories (e.g., Camel
2.19.2 features referencing CXF 3.1.11 features) and we'd rather like to
avoid it.

*Problems with blacklisting and overrides* - blacklisting is purely static
thing - applied at distro creation time. Overrides are a bit awkward to use
("range" clause) and have some implicit behavior (requiring runtime access
to resource, to verify version and symbolic name).

*What I did*

In short words - I've created a mechanism steered by
etc/org.apache.karaf.features.xml (name matching
etc/org.apache.karaf.features.cfg PID) that looks roughly like this:

<featuresProcessing xmlns="


        <!-- ... -->
        <feature version="[2,3)">*jclouds*</feature>
        <!-- ... -->

        <!-- Override "dependency" flag for all bundles of all features for
given repository URI(s) -->
dependency="true" />
        <repository uri="mvn:*/xml/features" dependency="true" />
        <!-- Override "dependency" flag for all bundles of given feature(s)
        <feature name="jclouds*" version="[1,3)" dependency="true" />
        <!-- Override "dependency" flag for given bundle(s) -->
        <bundle uri="mvn:javax.annotation/javax.annotation-api/*"
dependency="true" />

replacement="mvn:commons-collections/commons-collections/3.2.2" />

mode="maven" />
        <!-- ... -->

        <replacement mode="replace">
            <feature name="pax-jsf-resources-support" description="Provide
sharing of resources according to Servlet 3.0 for OSGi bundles and JSF"
                <f:feature version="[6.0,6.1)">pax-jsf-support</f:feature>

        <!-- ... -->



 - blacklistedRepositories, blacklistedFeatures and blacklistedBundles mean
what they mean - mark (instead of removing) given item kind from JAXB model
of loaded features XML. This information is preserved at runtime, and for
example is displayed with "features:list" command

 - overrideBundleDependency (not yet implemented) - is a method of
overriding "dependency="true|false"" flags in feature definitions

 - bundleReplacements (implemented) - is an extension of "overrides"
mechanism. In "osgi" mode, it roughly works like before - requires access
to runtime ResourceImpl, to check headers and compare versions and symbolic
names. In "maven" mode it's just static change of given bundle URI - any
feature declaring <bundle>originalUri</bundle> will be seen as declaring
<bundle>replacement</bundle>. This allows for replacement of e.g., SMX
specs bundle with javax.* bundle (or vice versa).

 - featureReplacements (not yet implemented) - is a way of changing (or
altering) any features by name (or pattern) and version simply by providing
different definition of given feature. This could be useful if we as Karaf
users know "better" than authors of original features, for whom OSGi and
Karaf were rather an afterthought.

Both bundle/feature/repository blacklisting and bundle/feature override use
two new classes to "match" candidate to replace/override:
 - org.apache.karaf.features.LocationPattern - matches URI (of bundle or
repository) in two modes - for non mvn: URI, it just uses a string with
possible "*" glob. For mvn: URI, it splits the URI into well known
components (groupId, artifactId, version, type and classifier). For version
it can use version range (e.g, "[2.1,2.2)") and for other components it can
use "*" glob.
 - org.apache.karaf.features.FeaturePattern - matches feature by name
(possibly containing "*" glob) and version range

Universally applicable:

FeaturesProcessor generally postprocesses
org.apache.karaf.features.internal.model.Features instance(s) and marks
items as blacklisted if they match given pattern and changes the model
(according to overrides/replacements).

The behavior after processing JAXB model of features is exactly the same
both when using FeaturesServiceImpl at runtime and when using profile
Builder during custom assembly creation. For example changed flow of
karaf-maven-plugin:asembly invocation looks like this:

[INFO] --- karaf-maven-plugin:4.2.0-SNAPSHOT:assembly (default-assembly) @
test-karaf-plugins ---
[INFO] Using repositories:
[INFO]    https://repo.maven.apache.org/maven2@id=central
[INFO]    Custom startup KAR found:
[INFO] Unzipping kars
[INFO]    processing KAR:
[INFO]       found repository:
[INFO] Found features processor configuration:
[INFO] Loading profiles from:
[INFO]    jar:mvn:test/profiles/42!/profiles/2
[INFO]    Found profiles: p1a, p1b-another, p2b, p2c-two, p2c-one-two, p2a
[INFO] Generating features processor configuration:
[INFO] Startup stage
[INFO]    Loading startup repositories
[INFO]    Resolving startup features and bundles
[INFO]       Features: undertow, my-startup-feature
[INFO]       skipping blacklisted maven bundle:
[INFO] Boot stage
[INFO]    Loading boot repositories
[INFO]       adding feature repository:
[INFO]       adding feature repository:
[INFO]    Feature undertow/ is defined as a boot feature
[INFO]       adding overriden maven artifact:
mvn:org.jboss.logging/jboss-logging/3.3.1.Final (original location:
[INFO]       skipping blacklisted maven artifact:
[INFO]       adding overriden maven artifact:
mvn:javax.servlet/javax.servlet-api/3.1-b09 (original location:
[INFO] Install stage
[INFO]    Loading installed repositories

overrides and blacklisting information may come from karaf-maven-plugin
configuration (in POM), from externally provided
org.apache.karaf.features.xml (e.g., in resource KAR or in POM:
<configuration>/<featuresProcessing>) or from profiles.

There are still few things to polish, but I'll appreciate any feedback to
check if I misunderstood something or there were other plans related to
these mechanisms. The changes are in
https://github.com/apache/karaf/commits/KARAF-5376-overrides_v2 branch.

best regards
Grzegorz Grzybek

  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message