1

I have a bundle project (Eclipse) that has the following structure:

src/main/java
   Bundle source files here
src/test/java
   Bundle internal test cases

When I try to make the bundle I get an error that there are some "Unsolved references". The error is causes by the internal test classes. How do I configure BND to ignore those classes?

Splitting the test cases into a separate project is not an option as the test cases are of a much finer granularity as the API provided by the bundle.

Robert
  • 39,162
  • 17
  • 99
  • 152
  • Which tools do you use? Maven, m2eclipse and maven-bundle-plugin? – FrVaBe Mar 02 '11 at 14:57
  • No Maven - plain Eclipse. I have only taken over the source file structure. After throwing away Maven/M2eclipse because it was very unstable - sometimes successful builds sometimes thousands of errors without any change to the whole workspace. – Robert Mar 02 '11 at 18:20

3 Answers3

4

The problem is that Eclipse is compiling both src/main/java and src/test/java into the same output directory, probably "bin", and Bnd works by scanning the compiled .class files in the bin folder.

You can fix this by following these steps:

  1. Right click on src/test/java and select Build Path > Configure Output Folder...

  2. Click "specific output folder" and enter a directory name such as bin_tests.

Now Eclipse will compile the test classes into a separate folder, and Bnd will only see the real classes.

Neil Bartlett
  • 23,743
  • 4
  • 44
  • 77
  • Works - but this looks more like a bug of BND to me. BND only recognizes classes in the bin folder independently of what has been configured for the project. – Robert Mar 04 '11 at 09:08
  • Why is it a bug in Bnd? As I said, Bnd looks at the compiled classes, not the sources. Eclipse by default just puts all the compiled classes in one place, so there's no way for Bnd to know which classes are "real" and which are tests. – Neil Bartlett Mar 04 '11 at 10:20
  • From my point of view BND should check the project configuration and should include/process all class output directories - but it doesn't. Therefore I would consider it as a bug. Nevertheless your answer was very helpful. – Robert Mar 04 '11 at 10:52
  • 1
    The problem is that the project configuration is Eclipse-specific. If Bnd used this information then what would it do when run from the command line, or from Hudson/Jenkins, or from NetBeans etc? This is why Bnd avoids reading it and only takes its configuration from the .bnd files. – Neil Bartlett Mar 04 '11 at 11:00
1

The good approach for unit tests in OSGi is to use fragments. Therefore you could put your tests in a fragment bundle, and you wouldn't have this issue anymore. And moreover, the tests will have access to all the classes and not only to APIs as it would be the case if you put them in a simple bundle

RaduK
  • 1,463
  • 10
  • 16
  • In general I have to admit that you are totally correct - but I don't like the answer; Especially because this means that I would have to create a fragment bundle for each of my bundles. This means a lot of new work... – Robert Mar 04 '11 at 10:50
  • It doesn't take a lot of time to create a new project. You can use some kind of template "fragment" project if you want, and only change the name and the host bundle. From my point of view, it totally justifies the separation of concerns and it eases a lot the deployment phase because you can exclude the tests very easily – RaduK Mar 08 '11 at 13:02
  • In bndtools you can add as many bundles to a project as you want – Peter Kriens Aug 04 '11 at 16:23
0

I assume that your test classes are included in the jar bundle file (what should not be the case). Check the content of your jar file and modify the package process to not include the test classes (a maven build does not include src/test/java).

I sometimes noticed this behaviour when using m2eclipse to package my project whereas running maven from the command line worked well.

FrVaBe
  • 47,963
  • 16
  • 124
  • 157