On Tue, 24 Jan 2017 14:04:54 +0100, Łukasz Dywicki <l...@code-house.org> wrote:

I been digging with my collegue aroudn maven ranges for some time and
we reached point where we would like to customize them. Because we are
using OSGi and maven resolver embedded in Karaf (which is also aether
based) and also some version ranges in XML descriptors (which are
interpreted as osgi ranges) we ended up having a certain gap. The
major problem is lower and upper bound inclusion/excllusion. As found
in ealier mails from this month 2.0.0-SNAPSHOT is smaller than 2.0.0
meaning it is included in [1,2) range. I managed to get rid of this
inclusion by using 1.max bound: [1,1.max], but then 1.0.0-SNAPSHOT is
not in the range. To avoid that I did [1.min, 1.max] range. So far so
good, but lower and upper bound in osgi will not work. When I will
install 1.0.0.SNAPSHOT (which is 1.0.0-SNAPSHOT in maven) it will not
match 1.0.0.min range because osgi treats qualifier with "startsWith"
logic. It is not aware of what snapshot means, for osgi framework its
just a string sequence.

I know ranges in build might be wrong, but I know how to use them and
I use them together with osgi so I am sure my build results will
match.

I managed to complete a code which embeds osgi range resolution inside
aether's VersionRangeResolver implementation. It is straight forward,
covered by simple tests and works as expected. Even if its not working
as expected it can be found by unit tests and fixed. What is hardest
for me now is binding this resolver into build so maven's
implementation of VersionRangeResolver gets replaced by mine. For this
reason I created .mvn/extensions.xml inside project root with my
artifact id:

<?xml version="1.0" encoding="UTF-8"?>
<extensions>
    <extension>
        <groupId>org.code-house.maven</groupId>
        <artifactId>osgi</artifactId>
        <version>3.3.9-SNAPSHOT</version>
    </extension>
</extensions>

During launch with verbose output I see my extension loaded:
[DEBUG] org.code-house.maven:osgi:jar:3.3.9-SNAPSHOT:
[DEBUG]    org.apache.maven:maven-core:jar:3.3.9:compile
[DEBUG]       org.apache.maven:maven-model:jar:3.3.9:compile
[DEBUG]       org.apache.maven:maven-settings:jar:3.3.9:compile
[DEBUG]       org.apache.maven:maven-settings-builder:jar:3.3.9:compile
[DEBUG]          org.apache.maven:maven-builder-support:jar:3.3.9:compile
[DEBUG] org.apache.maven:maven-repository-metadata:jar:3.3.9:compile
[DEBUG]       org.apache.maven:maven-artifact:jar:3.3.9:compile
[DEBUG]       org.apache.maven:maven-plugin-api:jar:3.3.9:compile
[DEBUG]       org.apache.maven:maven-model-builder:jar:3.3.9:compile
[DEBUG]       org.eclipse.aether:aether-util:jar:1.0.2.v20150114:compile
[DEBUG]       org.eclipse.sisu:org.eclipse.sisu.plexus:jar:0.3.2:compile
[DEBUG]          javax.enterprise:cdi-api:jar:1.0:compile
[DEBUG]             javax.annotation:jsr250-api:jar:1.0:compile
[DEBUG] org.eclipse.sisu:org.eclipse.sisu.inject:jar:0.3.2:compile
[DEBUG]       com.google.inject:guice:jar:no_aop:4.0:compile
[DEBUG]       org.codehaus.plexus:plexus-interpolation:jar:1.21:compile
[DEBUG]       org.codehaus.plexus:plexus-utils:jar:3.0.22:compile
[DEBUG]       org.codehaus.plexus:plexus-classworlds:jar:2.5.2:compile
[DEBUG] org.codehaus.plexus:plexus-component-annotations:jar:1.6:compile
[DEBUG]       org.sonatype.plexus:plexus-sec-dispatcher:jar:1.3:compile
[DEBUG]          org.sonatype.plexus:plexus-cipher:jar:1.4:compile
[DEBUG]       org.apache.commons:commons-lang3:jar:3.4:compile
[DEBUG]    org.eclipse.aether:aether-api:jar:1.0.2.v20150114:compile
[DEBUG]    org.eclipse.aether:aether-impl:jar:1.0.2.v20150114:compile
[DEBUG]       org.eclipse.aether:aether-spi:jar:1.0.2.v20150114:compile
[DEBUG]    com.google.inject:guice:jar:4.0:compile
[DEBUG]       javax.inject:javax.inject:jar:1:compile
[DEBUG]       aopalliance:aopalliance:jar:1.0:compile
[DEBUG]       com.google.guava:guava:jar:16.0.1:compile
[DEBUG]    org.osgi:org.osgi.core:jar:6.0.0:compile
[DEBUG]    org.slf4j:slf4j-log4j12:jar:1.7.22:compile
[DEBUG]       org.slf4j:slf4j-api:jar:1.7.22:compile
[DEBUG]       log4j:log4j:jar:1.2.17:compile

Extension gets initialized as well:
[DEBUG] Extension realms for project
com.example.web:model:bundle:4.0.0-SNAPSHOT:
[ClassRealm[extension>org.code-house.maven:osgi:3.3.9-SNAPSHOT,
parent: sun.misc.Launcher$AppClassLoader@18b4aac2],
ClassRealm[extension>org.apache.felix:maven-bundle-plugin:3.2.0,
parent: sun.misc.Launcher$AppClassLoader@18b4aac2]]
[DEBUG] Created new class realm project>com.example.web:model:4.0.0-SNAPSHOT [DEBUG] Populating class realm project>com.example.web:model:4.0.0-SNAPSHOT
[DEBUG] Looking up lifecyle mappings for packaging bundle from
ClassRealm[project>com.example.web:model:4.0.0-SNAPSHOT, parent:
ClassRealm[maven.api, parent: null]]
[DEBUG] Extension realms for project
com.example.web:parent:pom:4.0.0-SNAPSHOT:
[ClassRealm[extension>org.code-house.maven:osgi:3.3.9-SNAPSHOT,
parent: sun.misc.Launcher$AppClassLoader@18b4aac2],
ClassRealm[extension>org.apache.felix:maven-bundle-plugin:3.2.0,
parent: sun.misc.Launcher$AppClassLoader@18b4aac2]]
[DEBUG] Looking up lifecyle mappings for packaging pom from
ClassRealm[project>com.example.web:model:4.0.0-SNAPSHOT, parent:
ClassRealm[maven.api, parent: null]]
[DEBUG] Extension realms for project
com.example.web:pom:4.0.0-SNAPSHOT:
[ClassRealm[extension>org.apache.felix:maven-bundle-plugin:3.2.0,
parent: sun.misc.Launcher$AppClassLoader@18b4aac2]]
[DEBUG] Created new class realm project>com.example.web:4.0.0-SNAPSHOT
[DEBUG] Populating class realm project>com.example.web:4.0.0-SNAPSHOT
[DEBUG] Looking up lifecyle mappings for packaging pom from
ClassRealm[project>com.example.web:4.0.0-SNAPSHOT, parent:
ClassRealm[maven.api, parent: null]]
[DEBUG] Extension realms for project
com.example:example:pom:3.0.4-SNAPSHOT:
[ClassRealm[extension>org.apache.felix:maven-bundle-plugin:3.2.0,
parent: sun.misc.Launcher$AppClassLoader@18b4aac2]]
[DEBUG] Looking up lifecyle mappings for packaging pom from
ClassRealm[project>com.example.web:4.0.0-SNAPSHOT, parent:
ClassRealm[maven.api, parent: null]]
[DEBUG] === REACTOR BUILD PLAN ================================================
[DEBUG] Project: com.example.web:model:bundle:4.0.0-SNAPSHOT
[DEBUG] Tasks:   [clean, install]
[DEBUG] Style:   Regular

I see DefaultVersionRangeResolver initialized before my extension. One
of initializations is quite early during start up of maven, and second
when actual build is launched. There is quite long stack trace with
guice/plexus/sisu invocations to build this up but finally my
extension get called. Most interesting part, which **seems to be a
bug**, is DefaultVersionRangeResolver always gets called for first
level dependencies and my implementation of resolver gets called for
anything below that level. This makes it completely useless because I
have ranges in first level, not lower.

I also couldn't manage to get plexus test container looking up my
implementation as default one. To let plexus initialize it and use for
tests I have to use hint, otherwise I always get default
implementation, however hint causes complete ignoring of extension
when building real project. Should I provide integration test to
confirm a runtime bug? Any tips how to customize plexus container
during tests so it will locate my extension are also welcome.

The plexus test container is only about the container (CDI), it is not aware of a Maven context or extensions.
So I wonder if it is possible to test extensions like this.
Instead have a look at https://git1-us-west.apache.org/repos/asf?p=maven-integration-testing.git;a=summary

Robert


Source code of resolver:
https://github.com/splatch/aether-osgi-range-resolver

Kind regards,
Lukasz
--
Apache Karaf Committer & PMC
Twitter: @ldywicki
Blog: http://dywicki.pl
Code-House - http://code-house.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@maven.apache.org
For additional commands, e-mail: users-h...@maven.apache.org

Reply via email to