4

I'm building an Eclipse plugin using Tycho and am making use of Declarative Services for my OSGi services. Eclipse has a nice Editor for DS files, but it still is a manual process, which means it's slow and error-prone.

In non-Tycho OSGi projects I can use the maven-scr-plugin to generate these annotations. The catch with Tycho is that I can't add a reference to the org.apache.felix.annotations jar since it's

  • not present in a p2 repository
  • not a bundle

These annotations are defined with a RetentionPolicy = CLASS, so they don't have to be in a bundle.

I know about dependency on pom-first artifacts, but it's not going to work for me since the annotations jar is not a bundle. Ideally I could just configure Tycho/Eclipse to look for an extra jar just at compile time.

How can I get a compile-time only jar considered by Tycho and Eclipse?


Update: I've tried to use the extraClasspathElements option of the tycho-compiler-plugin. That does allow me to invoke the maven-scr-plugin (see the current pom.xml). However, it seems that the scr plugin can't access the classes, as the build fails with

[ERROR] Failed to execute goal org.apache.felix:maven-scr-plugin:1.13.0:scr (generate-scr-descriptor) on project org.apache.sling.ide.eclipse-core: /mnt/md/robert/git/sling-ide-tools/eclipse-core/src/org/apache/sling/ide/eclipse/core/ServerUtil.java : Unable to load compiled class: org.apache.sling.ide.eclipse.core.ServerUtil

You can also see the full build log

oberlies
  • 11,503
  • 4
  • 63
  • 110
Robert Munteanu
  • 67,031
  • 36
  • 206
  • 278
  • Try to pastebin or gist your POM, if you can. In the meantime, try this: http://eclipse.org/tycho/sitedocs/tycho-compiler-plugin/compile-mojo.html#extraClasspathElements – Sheena Artrip Jul 24 '13 at 19:08
  • I think there is a bigger issue than just getting visibility of the annotations in your build classpath. You need to get PDE/Tycho to actually invoke the annotation processor to generate the XML from the annotations. As far as I know, the maven-scr-plugin will not work in a Tycho build, and certainly not in PDE which always tries to avoid having any kind of generated artifact (other than the .class files...) – Neil Bartlett Jul 24 '13 at 19:41
  • @NeilBartlett - you're probably right, once I hooked up the maven-scr-plugin properly in the build it was unable to look up the compiled classes. – Robert Munteanu Jul 24 '13 at 20:59
  • 1
    @NeilBartlett I'm actually surprised the maven-scr-plugin doesn't provide an javax.annotation.processing.Processor that can be hooked into the tycho compiler configuration. (On first glance, apache felix provides its own unrelated processor interface for it). – Sheena Artrip Jul 24 '13 at 21:07
  • https://gist.github.com/sheenobu/6074999 A couple of things. You want to attach it to the 'compile' lifecycle. No idea why. Actually that is just about it. – Sheena Artrip Jul 24 '13 at 22:00
  • @SheenaArtrip - that actually generated the SCR descriptors for me, thanks! But now I get compilation errors in Eclipse - how do you work around that? – Robert Munteanu Jul 29 '13 at 12:14
  • @SheenaArtrip - I also have the problem that the generated annotations are not included in the packaged jar file. Does that work for you? – Robert Munteanu Jul 29 '13 at 14:55
  • @RobertMunteanu Generated annotations? – Sheena Artrip Jul 30 '13 at 14:37
  • @SheenaArtrip - sorry, I mean generated SCR descriptors. – Robert Munteanu Jul 30 '13 at 15:19
  • @RobertMunteanu Oh! I thought it was, but it wasn't. You need to update build.properties to include target/scr-plugin-generated/ OR use http://www.eclipse.org/tycho/sitedocs/tycho-packaging-plugin/package-plugin-mojo.html#additionalFileSets. Updated the gist: https://gist.github.com/sheenobu/6074999 – Sheena Artrip Jul 30 '13 at 17:55
  • @SheenaArtrip - I tried build.properties, but the files were included with the full path, e.g. `target/scr-plugin-generated/OSGI-INF/org.apache.sling.ide.impl.resource.util.Tracer.xml` . But including the tycho-packaging-plugin config is what did the trick. Now the only question left is - do you have any idea on how to convince Eclipse to include the scr-annotations jar in the IDE? I get compile errors right now and that's a pretty bad experience. – Robert Munteanu Jul 31 '13 at 08:12
  • @RobertMunteanu That is where "http://eclipse.org/tycho/sitedocs/tycho-compiler-plugin/compile-mojo.html#extraClasspathElements" should come in handy, but i'm not sure how the mvn definitions tie into the Eclipse IDE. I'd check your .classpath and .project files to start – Sheena Artrip Aug 01 '13 at 04:16

2 Answers2

1

Since you are using Tycho/Eclipse, you probably want to use "org.eclipse.equinox.ds" rather than "org.apache.felix.annotations". If I understand correctly, org.eclipse.equinox.ds is a bundle. The Tycho FAQ mentions this as well:

http://wiki.eclipse.org/Tycho/FAQ#How_to_add_a_undeclared_dependency.3F__.28e.g..2C_OSGi_declarative_service.29

EDIT:

http://eclipse.org/tycho/sitedocs/tycho-compiler-plugin/compile-mojo.html#extraClasspathElements

EDIT2: A lot has changed. I'll be updating my answer when time permits. Check the comment threads in the meantime =)

Sheena Artrip
  • 1,990
  • 12
  • 16
  • Thanks for the reply. Using DS actually works nicely under Equinox. It's creating the descriptor by hand which is annoying. I want to use the SCR annotations ( http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin/scr-annotations.html ) to generate the descriptors automatically using the maven-scr-plugin ( http://felix.apache.org/documentation/subprojects/apache-felix-maven-scr-plugin/apache-felix-maven-scr-plugin-use.html ) – Robert Munteanu Jul 24 '13 at 17:38
  • Ooo okay. I think I misunderstood the scope of org.eclipse.equinox.ds compared to SCR/org.apache.felix.annotations – Sheena Artrip Jul 24 '13 at 18:59
  • This answer helped me advance a bit, but I'm still stuck unfortunately. I'll update my question. – Robert Munteanu Jul 24 '13 at 20:54
  • BTW, don't worry about updating the answer, I'll do that myself when I have a definitive solution. – Robert Munteanu Jul 31 '13 at 08:12
0

I think the best you can do is to separate your building in two steps. One for building the felix (scr/bnd) based bundles. the result will be on a local maven repository and all will be already bundles with the manifests and component xmls.

As the annotation is processed only at building time you won't have any problem with the following step.

The second step is to build the tycho based artifacts(bundles,features,rcp,p2,etc) that will consume the bundles in the first build.

Cristiano
  • 1,414
  • 15
  • 22
  • The maven-scr-plugin does not use the javac annotation processing mechanism. Instead, it inspects the classes using ASM, so I'm not sure how this would work. – Robert Munteanu Jul 31 '13 at 08:28
  • unless I didn't understand right your question... What I suggest to you work well for me. The maven-bundle-plugin and maven-scr-plugin create manifest and all component xmls and maven installs the bundle in the local repository. after that jenkins starts the tycho building that consumes the prior generated bundles. – Cristiano Jul 31 '13 at 16:39
  • How do you consume the generated bundles with tycho? I use a target file and tycho does not support local directories in target files ( see http://wiki.eclipse.org/Tycho/Target_Platform#Target_files ) – Robert Munteanu Aug 01 '13 at 08:19
  • Well, Tycho can use bundles installed in any maven repository, including local one. But for have them in my target, I created eclipse features for every group of bnd based bundles and let jenkins to create and install a P2 repository that I publish into a web server. – Cristiano Aug 01 '13 at 22:16