...
Code Block |
---|
|
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); |
Provisioning from Products and Installations
Even though most powerful, provisioning directly from the source (see below) can be very time consuming and error prone, since you have to configure all things accordingly. In most cases you already have a product defined (or can define one for testing purpose) that is easily configured through the Eclipse UI. These can also be used to provision your test. This is the preferable way to setup your test as you can completely configure your test case with the tools you know and only need to specif the Product under Test.
Build from a product
The builder also reads VM-Options, start-levels and so on from the product file so you are ready to go testing
Code Block |
---|
|
@Configuration
public Option[] configure() throws IOException {
EclipseArtifactSource source = ... ;
EclipseApplicationOption option = EclipseOptions.buildFromProduct(SimpleContainerTest.class.getResourceAsStream("/testcase1.product"))
.source(source).create();
return options(option, junitBundles());
} |
Build from an installation
Here you don't even need a source since the installation itself is used as the source.
Code Block |
---|
|
@Configuration
public Option[] configure() throws IOException {
EclipseApplicationOption option = EclipseOptions.buildFromEclipseInstallation(EclipseOptions.fromInstallation(new File("/opt/eclise-installation/"))).create();
return options(option, junitBundles());
} |
Build from a Zip-File
And you can even just use a Zipped version of your product
Code Block |
---|
|
@Configuration
public Option[] configure() throws IOException {
EclipseApplicationOption option = EclipseOptions.buildFromEclipseArchive(new File("/tmp/eclipse.zip")).create();
return options(option, junitBundles());
} |
Extend an existing product for testing purpose
From time to time you might want to extend an existing product by some features/bundles/... even that is possible
Code Block |
---|
|
@Configuration
public Option[] configureFromProduct() throws IOException {
EclipseUnitSource source = ... ;
EclipseApplicationOption option = EclipseOptions.buildFromProduct(SimpleContainerTest.class.getResourceAsStream("/testcase1.product"))
.source(source).create();
EclipseProvision provision = option.getProduct().getLauncher().getProvision();
provision.singletonConflictResolution(SingletonConflictResolution.USE_HIGHEST_VERSION);
EclipseRepository repository = EclipseOptions.createRepository(new URL("http://download.eclipse.org/technology/swtbot/releases/latest/"), "swt-bot");
EclipseInstallableUnit gnerator_unit = repository.unit("org.eclipse.swtbot.generator");
EclipseInstallableUnit eclipse_unit = repository.unit("org.eclipse.swtbot.eclipse.feature.group");
EclipseInstallableUnit hamcrestlib_unit = repository.unit("org.hamcrest.library");
List<EclipseBundleOption> bundles = provision
.units(IncludeMode.PLANNER, repository, gnerator_unit, eclipse_unit, hamcrestlib_unit);
return options(option, junitBundles());
} |
Provision Artifacts from the sources directly
Now we have a source to provision items from we can proceed by adding items from this source to our test setup. Depending on the type the following things can be accessed. Even though this way is very flexible it requires you to setup a bunch of stuff (bundles to include, setting startlevels and so on) it is adviced to use products instead to configure your test setup (see above!).
EclipseBundleSource
The basic artifact to use is the bundle, you can obtain bundles either by name, by name and version or by name and version range. A bundle might be used directly with pax exam.
Code Block |
---|
|
@Configuration
public Option[] configure() throws IOException {
EclipseBundleSource bundleSource = ...;
return options(EclipseOptions.launcher(EclipseOptions.provision(bundleSource)).ignoreApp(), bundleSource.bundle("my.eclipse.bundle"), junitBundles());
} |
In fact it is more convenient to not provision bundles directly, so keep on reading to learn about more options...
...
EclipseFeatureSource
You can obtain features either by name, by name and version or by name and version range. A feature structures a set of bundles and dependant dependent features (either required or optional). Even though a feature can be added as-is to pax exam this is not desireable desirable in most cases, since you can't install a feature that way into the OSGi-Framework. To take full advantage of a feature it must be resolved first.
Code Block |
---|
|
@Configuration
public Option[] configure() throws IOException {
EclipseFeatureSource featureSource = EclipseOptions.fromInstallation(new File(""));
EclipseFeatureOption feature = featureSource.feature("my.eclipse.feature");
EclipseProvision provision = EclipseOptions.provision(featureSource);
List<EclipseBundleOption> list = provision.feature(feature);
for (EclipseBundleOption bundle : list) {
//configure bundle here
}
return options(EclipseOptions.launcher(provision).ignoreApp(), junitBundles());
} |
EclipseUnitSource
This is the most powerful source since you can provision a whole eclipse feature including dependencies! Like features Installable Units can not be installed directly but must be resolved. Beside this it is the most expensive operation in terms of resolving time since it requires to fetch and compute potential large datasets. So you are able to cache a resolved result of this but take in mind that you are responsible for clearing the cache if needed!
Code Block |
---|
|
@Configuration
public Option[] configure() throws IOException {
EclipseUnitSource unitSource = EclipseOptions.createRepository(new URL("http://download.eclipse.org/eclipse/updates/4.7"), "eclipse");
EclipseInstallableUnit unit = unitSource.unit("org.eclipse.pde");
EclipseProvision provision = EclipseOptions.provision(unitSource);
provision.singletonConflictResolution(SingletonConflictResolution.USE_HIGHEST_VERSION);
List<EclipseBundleOption> list = provision.units(IncludeMode.PLANNER, unit);
for (EclipseBundleOption bundle : list) {
//configure bundle here
}
return options(EclipseOptions.launcher(provision).asOptionignoreApp(), junitBundles());
} |