What's the proper way to create a feature repository with maven?

classic Classic list List threaded Threaded
6 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

What's the proper way to create a feature repository with maven?

Steinar Bang
What's the proper way to create a feature repository with maven?

I have something that sort of works here:
 https://github.com/steinarb/ukelonn/blob/master/ukelonn.karaf/pom.xml

Basically, what I do, is:
 1. Piggyback feature generation on the bundle projects
      https://github.com/steinarb/ukelonn/blob/master/ukelonn.api/pom.xml#L47
      https://github.com/steinarb/ukelonn/blob/master/ukelonn.bundle.test.db/pom.xml#L117
      https://github.com/steinarb/ukelonn/blob/master/ukelonn.bundle.postgresql.db/pom.xml#L112
      https://github.com/steinarb/ukelonn/blob/master/ukelonn.bundle/pom.xml#L199
    The karaf-maven-plugin automagically attaches the features to the
    maven bundle artifacts, with packaging "xml" and classifier
    "features"
 2. The ukelonn.karaf project has the features piggybacked on the bundle
    projects as dependencies
      https://github.com/steinarb/ukelonn/blob/master/ukelonn.karaf/pom.xml#L15
 3. karaf:features-generate-descriptor is attached to the packaging
    phase
      https://github.com/steinarb/ukelonn/blob/master/ukelonn.karaf/pom.xml#L47

This create a feature file attached to the pom artifact (the
ukelonn.karaf/pom.xml file has packaging "pom"), that can be used as a
feature repository containing the 4 features of my 4 bundles.

However:
 1. The feature file has a 5th feature that is the aggregation of the 4
    dependencies, and I would like to avoid the existence of that
    feature (it's a feature what will never work, since it will load two
    competing database bundles.  I have a PostgreSQL bundle that's for
    production, and a derby in-memory bundle that is for testing)
 2. This isn't the documented way of generating a feature file, that is
    using <packaging>features</packaging>

Is there a state-of-the-art example for generating a feature repository
somewhere?  

The pax-*-features pom.xml files I have looked at looked more
cumbersome, and probably doesn't use all of the newest stuff in the
karaf-maven-plugin (such as e.g. auto-attachment of the generated
feature file).

Thanks!


- Steinar

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What's the proper way to create a feature repository with maven?

jbonofre
Hi Steinar,

Actually, to have a complete control, it's better to create your features XML by
hand. It's what we do in Karaf itself.

Regards
JB

On 04/21/2017 07:52 PM, Steinar Bang wrote:

> What's the proper way to create a feature repository with maven?
>
> I have something that sort of works here:
>  https://github.com/steinarb/ukelonn/blob/master/ukelonn.karaf/pom.xml
>
> Basically, what I do, is:
>  1. Piggyback feature generation on the bundle projects
>       https://github.com/steinarb/ukelonn/blob/master/ukelonn.api/pom.xml#L47
>       https://github.com/steinarb/ukelonn/blob/master/ukelonn.bundle.test.db/pom.xml#L117
>       https://github.com/steinarb/ukelonn/blob/master/ukelonn.bundle.postgresql.db/pom.xml#L112
>       https://github.com/steinarb/ukelonn/blob/master/ukelonn.bundle/pom.xml#L199
>     The karaf-maven-plugin automagically attaches the features to the
>     maven bundle artifacts, with packaging "xml" and classifier
>     "features"
>  2. The ukelonn.karaf project has the features piggybacked on the bundle
>     projects as dependencies
>       https://github.com/steinarb/ukelonn/blob/master/ukelonn.karaf/pom.xml#L15
>  3. karaf:features-generate-descriptor is attached to the packaging
>     phase
>       https://github.com/steinarb/ukelonn/blob/master/ukelonn.karaf/pom.xml#L47
>
> This create a feature file attached to the pom artifact (the
> ukelonn.karaf/pom.xml file has packaging "pom"), that can be used as a
> feature repository containing the 4 features of my 4 bundles.
>
> However:
>  1. The feature file has a 5th feature that is the aggregation of the 4
>     dependencies, and I would like to avoid the existence of that
>     feature (it's a feature what will never work, since it will load two
>     competing database bundles.  I have a PostgreSQL bundle that's for
>     production, and a derby in-memory bundle that is for testing)
>  2. This isn't the documented way of generating a feature file, that is
>     using <packaging>features</packaging>
>
> Is there a state-of-the-art example for generating a feature repository
> somewhere?
>
> The pax-*-features pom.xml files I have looked at looked more
> cumbersome, and probably doesn't use all of the newest stuff in the
> karaf-maven-plugin (such as e.g. auto-attachment of the generated
> feature file).
>
> Thanks!
>
>
> - Steinar
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What's the proper way to create a feature repository with maven?

Steinar Bang
>>>>> Jean-Baptiste Onofré <[hidden email]>:

> Actually, to have a complete control, it's better to create your
> features XML by hand. It's what we do in Karaf itself.

Hm... actually, the karaf-maven-plugin is pretty good these days... you
should try it out...;-)

Especially the stuff about piggy-backing a feature on a bundle is
good. Requires very little config in the poms (see the URLs in my
previous message), define the version, set some properties and bind
karaf:features-generate-descriptor to packaging in the
<pluginManagement> section of the top POM
 https://github.com/steinarb/ukelonn/blob/master/ukelonn.bundle.test.db/pom.xml#L117
and then just reference the karaf-maven-plugin and set the feature name
in the bundle POMs.

If you need feature or bundle dependencies, create a template feature
file for that:
 https://github.com/steinarb/ukelonn/blob/master/ukelonn.bundle.test.db/src/main/feature/feature.xml
 https://github.com/steinarb/ukelonn/blob/master/ukelonn.bundle.postgresql.db/src/main/feature/feature.xml
 https://github.com/steinarb/ukelonn/blob/master/ukelonn.bundle/src/main/feature/feature.xml

(what the karaf-maven-plugin mainly lacks, is documentation)

The only issue I have right now, with my autogenerated features, is the
"extra" feature in the feature repository.

Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What's the proper way to create a feature repository with maven?

jbonofre
Hi Steinar,

I think I know pretty well the karaf-maven-plugin ;)

My point is when your features XML is a bit complex, you have to use at least a
template: I didn't mean the concrete features XML, just the features XML template.

Regards
JB

On 04/22/2017 07:25 AM, Steinar Bang wrote:

>>>>>> Jean-Baptiste Onofré <[hidden email]>:
>
>> Actually, to have a complete control, it's better to create your
>> features XML by hand. It's what we do in Karaf itself.
>
> Hm... actually, the karaf-maven-plugin is pretty good these days... you
> should try it out...;-)
>
> Especially the stuff about piggy-backing a feature on a bundle is
> good. Requires very little config in the poms (see the URLs in my
> previous message), define the version, set some properties and bind
> karaf:features-generate-descriptor to packaging in the
> <pluginManagement> section of the top POM
>  https://github.com/steinarb/ukelonn/blob/master/ukelonn.bundle.test.db/pom.xml#L117
> and then just reference the karaf-maven-plugin and set the feature name
> in the bundle POMs.
>
> If you need feature or bundle dependencies, create a template feature
> file for that:
>  https://github.com/steinarb/ukelonn/blob/master/ukelonn.bundle.test.db/src/main/feature/feature.xml
>  https://github.com/steinarb/ukelonn/blob/master/ukelonn.bundle.postgresql.db/src/main/feature/feature.xml
>  https://github.com/steinarb/ukelonn/blob/master/ukelonn.bundle/src/main/feature/feature.xml
>
> (what the karaf-maven-plugin mainly lacks, is documentation)
>
> The only issue I have right now, with my autogenerated features, is the
> "extra" feature in the feature repository.
>

--
Jean-Baptiste Onofré
[hidden email]
http://blog.nanthrax.net
Talend - http://www.talend.com
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What's the proper way to create a feature repository with maven?

Steinar Bang
>>>>> Jean-Baptiste Onofré <[hidden email]>:

> I think I know pretty well the karaf-maven-plugin ;)

I know. :-)

As I said, it's pretty good now, the way it works out of the box (and I
know it wouldn't get there by itself).

Thanks for that!

> My point is when your features XML is a bit complex, you have to use
> at least a template: I didn't mean the concrete features XML, just the
> features XML template.

Right.  I use templates for all but the simplest bundle (the karaf.api
feature which has no dependencies of its own),... and for the feature
repo.

Are you saying I should use a template, rather than maven dependencies
to reference the templates included in the repo?  If so, should I use a
particular syntax in the template?  I think that if I just reference the
features as dependencies, references will be what I'll get...?

Right now, this is what I do:
 https://github.com/steinarb/ukelonn/blob/master/ukelonn.karaf/pom.xml#L45

And this is what I get, the features from the maven pom depdenencies are
nicely expanded (which is what I want), but there is a feature at the
end for the project itself that I don't want (because I don't need it,
and because it won't work, since it will install two competing database
features):

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="ukelonn.karaf">
    <feature name="ukelonn-api" description="Ukelonn webapp OSGi service definitions OSGi bundle" version="1.0.0.SNAPSHOT">
        <bundle start-level="80">mvn:no.priv.bang.ukelonn/ukelonn.api/1.0.0-SNAPSHOT</bundle>
    </feature>
    <feature name="ukelonn-db-derby-test" description="Ukelonn webapp derby test database OSGi bundle" version="1.0.0.SNAPSHOT">
        <feature prerequisite="false" dependency="false">pax-jdbc</feature>
        <feature prerequisite="false" dependency="false">pax-jdbc-derby</feature>
        <feature version="1.0.0.SNAPSHOT" prerequisite="false" dependency="false">ukelonn-api</feature>
        <bundle start-level="80">mvn:no.priv.bang.ukelonn/ukelonn.bundle.test.db/1.0.0-SNAPSHOT</bundle>
    </feature>
    <feature name="ukelonn-db-postgresql" description="Ukelonn webapp PostgreSQL database connection OSGi bundle" version="1.0.0.SNAPSHOT">
        <feature prerequisite="false" dependency="false">transaction-api</feature>
        <feature prerequisite="false" dependency="false">pax-jdbc</feature>
        <feature version="1.0.0.SNAPSHOT" prerequisite="false" dependency="false">ukelonn-api</feature>
        <bundle start-level="80">mvn:no.priv.bang.ukelonn/ukelonn.bundle.postgresql.db/1.0.0-SNAPSHOT</bundle>
        <bundle start-level="80">mvn:org.postgresql/postgresql/9.4.1211.jre7</bundle>
    </feature>
    <feature name="ukelonn" description="Ukelonn webapp OSGi bundle" version="1.0.0.SNAPSHOT">
        <feature prerequisite="true" dependency="false">wrap</feature>
        <feature prerequisite="false" dependency="false">pax-jsf-support</feature>
        <feature prerequisite="false" dependency="false">ukelonn-api</feature>
        <bundle start-level="80">mvn:javax.el/javax.el-api/3.0.0</bundle>
        <bundle start-level="80">mvn:javax.faces/jsf-api/2.1</bundle>
        <bundle start-level="80">mvn:javax.validation/validation-api/1.1.0.Final</bundle>
        <bundle start-level="80">mvn:org.apache.shiro/shiro-core/1.3.1</bundle>
        <bundle start-level="80">mvn:org.apache.shiro/shiro-web/1.3.1</bundle>
        <bundle start-level="80">mvn:org.ops4j.pax.shiro/pax-shiro-faces/0.1.0</bundle>
        <bundle start-level="80">mvn:org.primefaces/primefaces/6.0</bundle>
        <bundle start-level="80">mvn:no.priv.bang.ukelonn/ukelonn.bundle/1.0.0-SNAPSHOT/war</bundle>
    </feature>
    <!-- This is the one I want to get rid of -->
    <feature name="ukelonn.karaf" description="Ukelonn webapp karaf feature repository" version="1.0.0.SNAPSHOT">
        <feature version="1.0.0.SNAPSHOT" prerequisite="false" dependency="false">ukelonn-api</feature>
        <feature version="1.0.0.SNAPSHOT" prerequisite="false" dependency="false">ukelonn-db-derby-test</feature>
        <feature version="1.0.0.SNAPSHOT" prerequisite="false" dependency="false">ukelonn-db-postgresql</feature>
        <feature version="1.0.0.SNAPSHOT" prerequisite="false" dependency="false">ukelonn</feature>
    </feature>
</features>


Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: What's the proper way to create a feature repository with maven?

Steinar Bang
>>>>> Steinar Bang <[hidden email]>:

> Are you saying I should use a template, rather than maven dependencies
> to reference the templates included in the repo?  If so, should I use a
> particular syntax in the template?  I think that if I just reference the
> features as dependencies, references will be what I'll get...?

I decided to just try and see what happens...:-)

I tried adding a
 https://github.com/steinarb/ukelonn/tree/master/ukelonn.karaf/src/main/feature/feature.xml
(not committed and checked in).

At first I just tried to reference the repos of the referenced features
and then referencing the features, but this failed the maven build with
a NullpointerException:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="ukelonn.bundle">
 <repository>mvn:no.priv.bang.ukelonn/ukelonn.api/${project.version}/xml/features</repository>
 <repository>mvn:no.priv.bang.ukelonn/ukelonn.bundle.test.db/${project.version}/xml/features</repository>
 <repository>mvn:no.priv.bang.ukelonn/ukelonn.bundle.postgresql.db/${project.version}/xml/features</repository>
 <repository>mvn:no.priv.bang.ukelonn/ukelonn.bundle/${project.version}/xml/features</repository>
 <feature>ukelonn-api</feature>
 <feature>ukelonn-db-derby-test</feature>
 <feature>ukelonn-db-postgresql</feature>
 <feature>ukelonn</feature>
</features>

Then I tried making a "fake" feature and surround the reference, but
that just gave me a file similar to the one I already generate from just
the maven dependencies, but was slightly worse:
 1. The file has two "useless" feature instead of one
 2. The file lists the repos for all referenced features (and there is
    no need, since the features are inlined in the generated file)

So I'll stay without a template and live with the "useless" feature in
the generated feature repo for the time being...:-)


Here's the template that didn't generate a NullreferenceException:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="ukelonn.bundle">
 <repository>mvn:no.priv.bang.ukelonn/ukelonn.api/${project.version}/xml/features</repository>
 <repository>mvn:no.priv.bang.ukelonn/ukelonn.bundle.test.db/${project.version}/xml/features</repository>
 <repository>mvn:no.priv.bang.ukelonn/ukelonn.bundle.postgresql.db/${project.version}/xml/features</repository>
 <repository>mvn:no.priv.bang.ukelonn/ukelonn.bundle/${project.version}/xml/features</repository>
 <feature name="blah">
  <feature>ukelonn-api</feature>
  <feature>ukelonn-db-derby-test</feature>
  <feature>ukelonn-db-postgresql</feature>
  <feature>ukelonn</feature>
 </feature>
</features>


Here's the resulting generated feature repo:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="ukelonn.bundle">
    <repository>mvn:no.priv.bang.ukelonn/ukelonn.api/1.0.0-SNAPSHOT/xml/features</repository>
    <repository>mvn:no.priv.bang.ukelonn/ukelonn.bundle.test.db/1.0.0-SNAPSHOT/xml/features</repository>
    <repository>mvn:no.priv.bang.ukelonn/ukelonn.bundle.postgresql.db/1.0.0-SNAPSHOT/xml/features</repository>
    <repository>mvn:no.priv.bang.ukelonn/ukelonn.bundle/1.0.0-SNAPSHOT/xml/features</repository>
    <feature name="blah" version="0.0.0">
        <feature prerequisite="false" dependency="false">ukelonn-api</feature>
        <feature prerequisite="false" dependency="false">ukelonn-db-derby-test</feature>
        <feature prerequisite="false" dependency="false">ukelonn-db-postgresql</feature>
        <feature prerequisite="false" dependency="false">ukelonn</feature>
    </feature>
    <feature name="ukelonn-api" description="Ukelonn webapp OSGi service definitions OSGi bundle" version="1.0.0.SNAPSHOT">
        <bundle start-level="80">mvn:no.priv.bang.ukelonn/ukelonn.api/1.0.0-SNAPSHOT</bundle>
    </feature>
    <feature name="ukelonn-db-derby-test" description="Ukelonn webapp derby test database OSGi bundle" version="1.0.0.SNAPSHOT">
        <feature prerequisite="false" dependency="false">pax-jdbc</feature>
        <feature prerequisite="false" dependency="false">pax-jdbc-derby</feature>
        <feature version="1.0.0.SNAPSHOT" prerequisite="false" dependency="false">ukelonn-api</feature>
        <bundle start-level="80">mvn:no.priv.bang.ukelonn/ukelonn.bundle.test.db/1.0.0-SNAPSHOT</bundle>
    </feature>
    <feature name="ukelonn-db-postgresql" description="Ukelonn webapp PostgreSQL database connection OSGi bundle" version="1.0.0.SNAPSHOT">
        <feature prerequisite="false" dependency="false">transaction-api</feature>
        <feature prerequisite="false" dependency="false">pax-jdbc</feature>
        <feature version="1.0.0.SNAPSHOT" prerequisite="false" dependency="false">ukelonn-api</feature>
        <bundle start-level="80">mvn:no.priv.bang.ukelonn/ukelonn.bundle.postgresql.db/1.0.0-SNAPSHOT</bundle>
        <bundle start-level="80">mvn:org.postgresql/postgresql/9.4.1211.jre7</bundle>
    </feature>
    <feature name="ukelonn" description="Ukelonn webapp OSGi bundle" version="1.0.0.SNAPSHOT">
        <feature prerequisite="true" dependency="false">wrap</feature>
        <feature prerequisite="false" dependency="false">pax-http</feature>
        <feature version="1.0.0.SNAPSHOT" prerequisite="false" dependency="false">ukelonn-api</feature>
        <bundle start-level="80">mvn:no.priv.bang.ukelonn/ukelonn.bundle/1.0.0-SNAPSHOT</bundle>
        <bundle start-level="80">mvn:org.rendersnake/rendersnake/1.8</bundle>
        <bundle start-level="80">mvn:org.apache.commons/commons-lang3/3.1</bundle>
    </feature>
    <feature name="ukelonn.karaf" description="Ukelonn webapp karaf feature repository" version="1.0.0.SNAPSHOT">
        <feature version="1.0.0.SNAPSHOT" prerequisite="false" dependency="false">ukelonn-api</feature>
        <feature version="1.0.0.SNAPSHOT" prerequisite="false" dependency="false">ukelonn-db-derby-test</feature>
        <feature version="1.0.0.SNAPSHOT" prerequisite="false" dependency="false">ukelonn-db-postgresql</feature>
        <feature version="1.0.0.SNAPSHOT" prerequisite="false" dependency="false">ukelonn</feature>
    </feature>
</features>

Loading...