lburgazzoli / gradle-karaf-features-plugin

Apache License 2.0
4 stars 13 forks source link

Gradle KAR file task should pull dependency versions from gradle properties file #23

Closed eschizoid closed 8 years ago

eschizoid commented 8 years ago

Currently, the karaf-maven-plugin for creating a kar file can resolve the version number from a <prooperties> tag, for instance:

Maven pom.xml

<properties>
    <commons.beanutils.version>1.9.2</commons.beanutils.version>
    <commons.dbcp.version>2.0.1</commons.dbcp.version>
    <commons.dbutils.version>1.6</commons.dbutils.version>
    <commons.codec.version>1.9</commons.codec.version>
    <commons.collections.version>4.0</commons.collections.version>
    <commons.io.version>2.4</commons.io.version>
    <commons.lang.version>3.3.2</commons.lang.version>
</properties>

That way you can define a feature.xml file like the following

<feature name="commons-dbutils" description="Apache Commons JDBC Utility Component" version="${commons.dbutils.version}">
        <bundle dependency="true">mvn:commons-dbutils/commons-dbutils/${commons.dbutils.version}</bundle>
</feature>

It would be ideal if the same behavior can be accomplished using a gradle.properties file.

lburgazzoli commented 8 years ago

Do you mean to generate a feature with properties or start from a feature xml file with properties ?

eschizoid commented 8 years ago

The second one, start from a feature.xml file that pulls the properties from a gradle.properties file.

lburgazzoli commented 8 years ago

The problem is that this plugin does not read an arbitrary features file to generate a kar but instead is uses project dependencies (same as features file generation) so as long as you have defined your dependencies in grade and potentially versions in gradle.properties you should be fine.

Generating a kar from an arbitrary file might be added later on, but not my highest priority for the moment.

eschizoid commented 8 years ago

@lburgazzoli The problem is that the feature file that we are using has a lot of customization. For instance, I have some jar files that need to be wrap since are not OSGi ready.

<feature name="sql-server"
    description="Microsoft SQL Server Driver"
    version="${sql.version}">
    <!-- as if Microsoft cared about OSGi... -->
    <bundle dependency="true">wrap:mvn:com.microsoft/sql-jdbc/${sql.version}</bundle>
</feature>

And some custom features:

<feature name="camel-cache" version="${camel.version}">
    <feature version="[1.1,2)">transaction</feature>
    <feature version="[2.10,3)">ehcache</feature>
    <bundle dependency="true">mvn:org.apache.servicemix.bundles/org.apache.servicemix.bundles.jdom/1.1_4</bundle>
    <bundle dependency="true">mvn:org.apache.camel/camel-cache/${camel.version}</bundle>
</feature>

I don't think the KAR task is going to be able to add all this instructions if it only scans the dependencies.

lburgazzoli commented 8 years ago

It is, if the jar do not have an osgi-fied meta-inf it add wrap to the feature, but you can also force wrapping

eschizoid commented 8 years ago

Great! And what about the custom features?

lburgazzoli commented 8 years ago

Can. you give an example?

eschizoid commented 8 years ago
<feature name="jpa" description="OSGi Persistence Container" version="2.1.0">
    <details>JPA implementation provided by Apache Aries JPA 1.0.2.</details>
    <feature version="[1.1,2)">transaction</feature>
    <bundle dependency="true" start-level="30">mvn:org.hibernate.javax.persistence/hibernate-jpa-2.1-api/1.0.0.Final</bundle>
    <bundle dependency="true" start-level="30">mvn:org.apache.aries/org.apache.aries.util/1.1.0</bundle>
    <bundle start-level="30">mvn:org.apache.aries.jpa/org.apache.aries.jpa.api/1.0.2</bundle>
    <bundle start-level="30">mvn:org.apache.aries.jpa/org.apache.aries.jpa.container/1.0.2</bundle>
    <bundle start-level="30">mvn:org.apache.aries.jpa/org.apache.aries.jpa.container.context/1.0.4</bundle>
    <conditional>
        <condition>aries-blueprint</condition>
        <bundle start-level="30">mvn:org.apache.aries.jpa/org.apache.aries.jpa.blueprint.aries/1.0.4</bundle>
    </conditional>
</feature>
lburgazzoli commented 8 years ago

so here you are referring to:

correct ?

eschizoid commented 8 years ago

That is correct.

eschizoid commented 8 years ago

@lburgazzoli Any update regarding to this?

lburgazzoli commented 8 years ago

Not yet implemented, hope I have some time next week

On Wednesday, 6 January 2016, Mariano Gonzalez notifications@github.com wrote:

@lburgazzoli https://github.com/lburgazzoli Any update regarding to this?

— Reply to this email directly or view it on GitHub https://github.com/lburgazzoli/gradle-karaf-features-plugin/issues/23#issuecomment-169180644 .

lburgazzoli commented 8 years ago

Hi, I'm re-factoring the plugin to support more Karaf functionalities and the first cut can be found in Gradle Plugin portal .

It only support karaf features files at the moment so with a configuration like:

plugins {
    id 'java'
    id 'groovy'
    id 'maven'
   id "com.github.lburgazzoli.karaf" version "0.0.9"
}

group = 'com.lburgazzoli.github'
version = '1.2.3'

repositories {
    mavenLocal()
    mavenCentral()
}

dependencies {
    compile "com.google.guava:guava:19.0"
    compile "com.squareup.retrofit:retrofit:1.9.0"
    compile 'com.fasterxml.jackson.core:jackson-core:2.7.0'
    compile 'com.fasterxml.jackson.core:jackson-databind:2.7.0'
    compile 'com.fasterxml.jackson.core:jackson-annotations:2.7.0'
}

karaf {
    features {
        xsdVersion = "1.3.0"

        feature {
            name = "karaf-features-example"
            description = "feature-description"
            details = "my detailed description"
            includeProject = false

            conditional {
                condition = 'json-p'

                feature 'myfeature-1'
                feature 'myfeature-2'

                bundle 'com.fasterxml.jackson.core'
            }
        }
    }
}

It will generates the following xml:

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<features xmlns="http://karaf.apache.org/xmlns/features/v1.3.0" name="example">
  <feature name="karaf-features-example" version="1.2.3" description="feature-description">
    <details>my detailed description</details>
    <bundle>mvn:com.google.guava/guava/19.0</bundle>
    <bundle>mvn:com.google.code.gson/gson/2.3.1</bundle>
    <bundle>wrap:mvn:com.squareup.retrofit/retrofit/1.9.0</bundle>
    <conditional>
      <condition>json-p</condition>
      <feature>myfeature-1</feature>
      <feature>myfeature-2</feature>
      <bundle>mvn:com.fasterxml.jackson.core/jackson-core/2.7.0</bundle>
      <bundle>mvn:com.fasterxml.jackson.core/jackson-annotations/2.7.0</bundle>
      <bundle>mvn:com.fasterxml.jackson.core/jackson-databind/2.7.0</bundle>
    </conditional>
  </feature>
</features>
eschizoid commented 8 years ago

@lburgazzoli These are great news man! Thank you!

eschizoid commented 8 years ago

@lburgazzoli Don't forget the repository element :wink:

<repository>mvn:org.apache.karaf.cellar/apache-karaf-cellar/${cellar.version}/xml/features</repository>
<repository>mvn:org.apache.karaf.features/standard/${karaf.version}/xml/features</repository>
<repository>mvn:org.apache.karaf.features/enterprise/${karaf.version}/xml/features</repository>
<repository>mvn:org.ops4j.pax.web/pax-web-features/3.1.0/xml/features</repository>
<repository>mvn:org.apache.cxf.karaf/apache-cxf/${cxf.version}/xml/features</repository>
<repository>mvn:org.apache.karaf.features/spring/${karaf.version}/xml/features</repository>
eschizoid commented 8 years ago

Hey @lburgazzoli have you done any progress related to this?

lburgazzoli commented 8 years ago

Not for the moment, hope get back working on this next week

lburgazzoli commented 8 years ago

I've just relased a new gradle-karaf-plugin 0.0.10 on gradle plugin central, can you havea look ? If any issue an you report them to gradle-karaf-plugin

eschizoid commented 8 years ago

@lburgazzoli You have any documentation how to use it?

eschizoid commented 8 years ago

@lburgazzoli Testing it right now.

eschizoid commented 8 years ago

generateFeatures task is working pretty well. However, I don't see any task to generate a kararchive.

lburgazzoli commented 8 years ago

@eschizoid yes it is still missing, I will add it soon

jvz commented 8 years ago

Does this support resource property filtering like the maven plugins?

lburgazzoli commented 8 years ago

@jvz can you post an example ?

jvz commented 8 years ago

@eschizoid had a good example actually (except I don't think you can use periods in gradle properties):

<repository>mvn:org.apache.karaf.features/standard/${karafVersion}/xml/features</repository>

Where karafVersion is defined in gradle.properties or specified by the -P option. When I specify a property like that in maven, karaf-maven-plugin does the same thing as maven-resources-plugin by filtering its files with property placeholders specified through either ${thisSyntax} or @thisSyntax@.

lburgazzoli commented 8 years ago

This is when you tell maven-karaf-plugin to generate a kar based on a pre-existing features file correct ?

jvz commented 8 years ago

Yeah. I originally used a custom features file because the maven plugin was generating dependencies out of order which was causing Karaf to barf. Now it's legacy even if the plugin generates dependencies in the right order (plus I like to reuse feature repositories like camel's).

lburgazzoli commented 8 years ago

@jvz I may add support for external features definition but not in the initial phase, can you log a ticket on gradle-karaf-plugin ?

jvz commented 8 years ago

Sure.

eschizoid commented 8 years ago

@lburgazzoli shall we close this ticket? and probably link it to the one @jvz created?

lburgazzoli commented 8 years ago

yes please

eschizoid commented 8 years ago

Closing in favor of this one:

https://github.com/lburgazzoli/gradle-karaf-plugin/issues/2