Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Code Block
languagexml
collapsetrue
<dependency>
    <groupId>org.ops4j.pax.exam</groupId>
    <artifactId>pax-exam-container-eclipse</artifactId>
    <version>${pax.exam.version}</version>
    <scope>test</scope>
</dependency>

Basic Concepts

You should already have basic knowledge about Pax Exam so you might want to read especially the Configuration Options part already. Even though the Eclipse-Container provides a lot of own Options you still can use any of the default Pax Exam OSGi ones, infact this implementation produces, as a final result, mostly those standard options for you.

As a very first step you have to decide where your bundles should come from, the so called ArtifactSource, where you always can combine different sources, typically you would choose one or more of the following:

  • a workspace
  • a target.platform
  • an installation folder or exported Eclipse product
  • one or more P2 repositories

then ArtifactSources can, depending on there implementation, provide different artifacts to later stages. Then you have to choose which artifacts you want to provision:

...

typically you want to choose one but you can also combine these as needed. We will describe the different ways to read bundles and provision artifacts.

Creating an ArtifactSource from a workspace

The EclipseWorkspace source comes in two flavours, either a 'real' Eclipse workspace you use in your IDE, or a simple directory tree that contains Eclipse projects, in both cases you can create one the following way

Code Block
languagejava
EclipseWorkspace workspace = EclipseOptions.fromWorkspace(new File("/home/user/workspace"));

this will read all projects from the given location and provide you with bundles and features (if found). This source is a little bit special in the way since it provides you with access to an artifact that is not directly used by tests but comes handy when provisioning things: a project.

You can access projects by name and the access resources from it, e.g product or target definitions, or any resource that seems useful

Code Block
languagejava
EclipseProject project = workspace.project("target-project");
InputStream targetStream = project.getResourceAsStream("default.target");

Creating an ArtifactSource from a target platform

You probably already has some sort of target platform for your development, so you can use this to provision items from

Code Block
languagejava
InputStream targetDefinition = ...;
File cacheFolder = new File("target/eclipsecache");
EclipseOptions.fromTarget(targetDefinition, cacheFolder);

You need to provide an inputstream to the target file an optionally a cache folder. Since resolving a target can be quite time consuming a cache folder is recommended especially when using software-sites/p2 repros. You might find it handy to fetch the InputStream from a workspace like described before but of course can provide if from any source you like.

Creating an ArtifactSource from an installationfolder or exported Eclipse product

The simplest case is where you have a bunch of bundles or features exported as jar files (e.g. an exported product or an eclipse installation or something you have created yourself) you can read in these items like this:

Code Block
languagejava
EclipseInstallation installation = EclipseOptions.fromInstallation(new File("/home/user/exported_product"));

the method detects several layouts of the folder, e.g. having all in one folder or having seperate plugins/features folders.

Creating an ArtifactSource from one or more P2 repositories

You maybe already have deployed everything into a p2 repository? Then you can read of course from one of those

Code Block
languagejava
EclipseRepository repository = EclipseOptions.createRepository(new URL("http://download.eclipse.org/eclipse/updates/4.7"), "eclipse");

just keep in mind that using p2-repositories can be very time consuming (even if there is some caching under the hood). To speed up things you can define a (test) target platform and add the relevant parts there and the use the caching feature of the target platform, since this downloads all necessary parts and keep them on disk this is a lot faster! Just keep in mind to increment the target version number if you repro changes.

Combine different Sources

different Sources can be combined into one like this

Code Block
languagejava
EclipseWorkspace workspace = EclipseOptions.fromWorkspace(new File("/home/user/workspace"));
EclipseProject project = workspace.project("target-project");
InputStream targetStream = project.getResourceAsStream("default.target");
File cacheFolder = new File("target/eclipsecache");
EclipseTargetPlatform target = EclipseOptions.fromTarget(targetStream, cacheFolder);
        
CombinedEclipseArtifactSource combine = EclipseOptions.combine(workspace, target);