How to add <repository> elements to aggregated feature repositories?

classic Classic list List threaded Threaded
8 messages Options
Reply | Threaded
Open this post in threaded view
|

How to add <repository> elements to aggregated feature repositories?

Steinar Bang
Versions: karaf-maven-plugin 4.1.5

If you add <repository> elements pointing to other feature repositories to
a template feature.xml file in a bundle project, like eg. here
 https://github.com/steinarb/sonar-collector/blob/master/sonar-collector-webhook/src/main/feature/feature.xml#L2
then those <feature> elements are included in the built feature file
that is attached to the bundle project, like eg. here

However, if you create aggregate feature repositories like eg. this one
 https://github.com/steinarb/ukelonn/blob/master/ukelonn.karaf/pom.xml#L27
then the <repository> elements aren't part of the aggregated feature
repository.

Is there a way to include the <repository> elements?

I tried creating a template feature.xml in the aggregate project (a
project with packaging pom), but the <repository> elements weren't
included in the target/feature/feature.xml (ie. the generated feature
repository).

Is there a config to make karaf-maven-plugin include <repository>
elements from its dependency feature files?

Thanks!


- Steinar

Reply | Threaded
Open this post in threaded view
|

Re: How to add <repository> elements to aggregated feature repositories?

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

> Is there a way to include the <repository> elements?

It looks from the code as if the repository elements are meant to be
included:
 https://github.com/apache/karaf/blob/master/tooling/karaf-maven-plugin/src/main/java/org/apache/karaf/tooling/features/GenerateDescriptorMojo.java

Also, the repositories added to the template feature file should have
made it to the generated feature file...?

Have I made a mistake in the config?  Or has the code changed since
karaf-maven-plugin 4.1.5?

Reply | Threaded
Open this post in threaded view
|

Re: How to add <repository> elements to aggregated feature repositories?

jbonofre
Hi Steinar

That's tricky because users might want different behavior about features repositories dependencies.

As already mentioned, it gives more control to write the features repository XML by hand and verify using the plugin.

Regards
JB
Le 20 avr. 2018, à 19:03, Steinar Bang <[hidden email]> a écrit:
Reply | Threaded
Open this post in threaded view
|

Re: How to add <repository> elements to aggregated feature repositories?

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

> That's tricky because users might want different behavior about features repositories dependencies.

> As already mentioned, it gives more control to write the features repository XML by hand and verify using the plugin.

Yes, but that means maintaining the dependencies in multiple places.

How about adding an attribute that can tell karaf-maven-plugin to
include it when aggregating features?

Eg. something like this
 <repository includeinaggregaterepo="true" .../>

Default would be false (ie the current behaviour).

The karaf-maven-plugin would then include it in an aggregate repository
(stripping this attribute in the process).

Alternatively: if the aggregate has a template feature file with
<repository> elements, then include those elements in the generated
aggregate (this was the behaviour I expected to see).

This wouldn't be ideal in that I would have to maintain the URL in two
places (but I could use a maven property and just maintain the actual
URL in a single location).

Reply | Threaded
Open this post in threaded view
|

Re: How to add <repository> elements to aggregated feature repositories?

nino martinez wael
What about doing it based on pom and what scope the declared dependency feature types are in? 

On Sat, 21 Apr 2018, 23:46 Steinar Bang, <[hidden email]> wrote:
>>>>> Jean-Baptiste Onofré <[hidden email]>:

> That's tricky because users might want different behavior about features repositories dependencies.

> As already mentioned, it gives more control to write the features repository XML by hand and verify using the plugin.

Yes, but that means maintaining the dependencies in multiple places.

How about adding an attribute that can tell karaf-maven-plugin to
include it when aggregating features?

Eg. something like this
 <repository includeinaggregaterepo="true" .../>

Default would be false (ie the current behaviour).

The karaf-maven-plugin would then include it in an aggregate repository
(stripping this attribute in the process).

Alternatively: if the aggregate has a template feature file with
<repository> elements, then include those elements in the generated
aggregate (this was the behaviour I expected to see).

This wouldn't be ideal in that I would have to maintain the URL in two
places (but I could use a maven property and just maintain the actual
URL in a single location).

Reply | Threaded
Open this post in threaded view
|

Re: How to add <repository> elements to aggregated feature repositories?

jbonofre
That's the idea of template yet, leveraging the deps.

Regards
JB

On 05/03/2018 08:18 PM, nino martinez wael wrote:

> What about doing it based on pom and what scope the declared dependency feature
> types are in? 
>
> On Sat, 21 Apr 2018, 23:46 Steinar Bang, <[hidden email] <mailto:[hidden email]>> wrote:
>
>     >>>>> Jean-Baptiste Onofré <[hidden email] <mailto:[hidden email]>>:
>
>     > That's tricky because users might want different behavior about features
>     repositories dependencies.
>
>     > As already mentioned, it gives more control to write the features
>     repository XML by hand and verify using the plugin.
>
>     Yes, but that means maintaining the dependencies in multiple places.
>
>     How about adding an attribute that can tell karaf-maven-plugin to
>     include it when aggregating features?
>
>     Eg. something like this
>      <repository includeinaggregaterepo="true" .../>
>
>     Default would be false (ie the current behaviour).
>
>     The karaf-maven-plugin would then include it in an aggregate repository
>     (stripping this attribute in the process).
>
>     Alternatively: if the aggregate has a template feature file with
>     <repository> elements, then include those elements in the generated
>     aggregate (this was the behaviour I expected to see).
>
>     This wouldn't be ideal in that I would have to maintain the URL in two
>     places (but I could use a maven property and just maintain the actual
>     URL in a single location).
>

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

Re: How to add <repository> elements to aggregated feature repositories?

Steinar Bang
In reply to this post by jbonofre
>>>>> Jean-Baptiste Onofré <[hidden email]>:

> That's tricky because users might want different behavior about
> features repositories dependencies.

> As already mentioned, it gives more control to write the features
> repository XML by hand and verify using the plugin.

Do you have an example of a project doing this?

I basically just need to expand maven properties for version numbers in
a template file, and install the expanded feature as a maven artifact
(whether as an attachment to the POM or as a feature artifact in its own
right).

Reply | Threaded
Open this post in threaded view
|

Re: How to add <repository> elements to aggregated feature repositories?

Steinar Bang
>>>>> Steinar Bang <[hidden email]>:
>>>>> Jean-Baptiste Onofré <[hidden email]>:
[snip!]
>> As already mentioned, it gives more control to write the features
>> repository XML by hand and verify using the plugin.

[snip!]
> I basically just need to expand maven properties for version numbers
> in a template file, and install the expanded feature as a maven
> artifact (whether as an attachment to the POM or as a feature artifact
> in its own right).

Ok, now I've got it working.  

I just created a feature.xml file that references the bundles'
repositores, but with ${project.version} in place of the version, then I
created maven configuration for the parent pom that expanded the
feature.xml file and attached the expanded file to the parent POM.

Advantages to my old approach of letting karaf-maven-plugin generate an
aggregated feature repository from dependencies to the bundle projects'
feature repositories:
 1. It's actually simpler
 2. The <repository> references of the referenced <repositories> are
    preserved (ie. all the necessary repositories are loaded into karaf)
 3. I can stop having a special maven module just to build the
    aggregated feature repository, and instead just attach this feature
    repository to the parent POM of a multi-module project

This is an example project that has two bundles that generate their own
feature repositories and a parent POM that has an aggregated feature
repository for the two bundles' repositories as an attachement:
  https://github.com/steinarb/whiteboard-web-and-api-karaf-demo

The resource feature file that becomes the attachment after expansion,
is here:
 https://github.com/steinarb/whiteboard-web-and-api-karaf-demo/blob/master/src/main/filtered-resources/feature.xml
and looks like this:
 <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
 <features xmlns="http://karaf.apache.org/xmlns/features/v1.4.0" name="webapi">
  <repository>mvn:no.priv.bang.demos.whiteboardwebapi/webapi/${project.version}/xml/features</repository>
  <repository>mvn:no.priv.bang.demos.whiteboardwebapi/webgui/${project.version}/xml/features</repository>
 </features>

The maven config that filters the feature.xml file and attach the
filtered file (note the not-inherited setting on the attachment) is here:
 https://github.com/steinarb/whiteboard-web-and-api-karaf-demo/blob/master/pom.xml#L149
and looks like this:
 <project>
  <build>
   <plugins>
    <plugin>
     <artifactId>maven-resources-plugin</artifactId>
     <version>3.1.0</version>
     <executions>
      <execution>
       <id>filter-resources</id>
       <phase>validate</phase>
       <goals>
        <goal>resources</goal>
       </goals>
       <configuration>
        <resources>
         <resource>
          <directory>src/main/filtered-resources</directory>
          <filtering>true</filtering>
         </resource>
        </resources>
       </configuration>
      </execution>
     </executions>
    </plugin>
    <plugin>
     <groupId>org.codehaus.mojo</groupId>
     <artifactId>build-helper-maven-plugin</artifactId>
     <version>3.0.0</version>
     <inherited>false</inherited>
     <executions>
      <execution>
       <id>attach-karaf-feature</id>
       <phase>package</phase>
       <goals>
        <goal>attach-artifact</goal>
       </goals>
       <configuration>
        <artifacts>
         <artifact>
          <file>target/classes/feature.xml</file>
          <type>xml</type>
          <classifier>features</classifier>
         </artifact>
        </artifacts>
       </configuration>
      </execution>
     </executions>
    </plugin>
   </plugins>
  </build>
 </project>