All Downloads are FREE. Search and download functionalities are using the official Maven repository.

aQute.tester.bundle.engine.discovery.BundleSelector Maven / Gradle / Ivy

Go to download

A bnd tester using JUnit Platform. Like biz.aQute.tester, this bundle will add itself to the -runbundles at the end. At startup, this bundle will then look for TestEngine implementations among the loaded bundles and use them to execute the tests. This bundle does NOT contain the necessary TestEngine implementations for JUnit 3, 4 or 5 - it will import them just like any other bundle.

There is a newer version: 7.1.0
Show newest version
package aQute.tester.bundle.engine.discovery;

import java.util.Objects;

import org.junit.platform.engine.DiscoverySelector;
import org.osgi.framework.Bundle;
import org.osgi.framework.Version;
import org.osgi.framework.VersionRange;

public class BundleSelector implements DiscoverySelector {
	private static final VersionRange	allRange	= new VersionRange(VersionRange.LEFT_CLOSED, Version.emptyVersion,
		null, VersionRange.RIGHT_OPEN);

	private final String				symbolicName;
	private final VersionRange			versionRange;

	private BundleSelector(String symbolicName, VersionRange versionRange) {
		this.symbolicName = symbolicName;
		this.versionRange = versionRange;
	}

	public String getSymbolicName() {
		return symbolicName;
	}

	public VersionRange getVersionRange() {
		return versionRange;
	}

	public static BundleSelector selectBundle(String symbolicName) {
		return new BundleSelector(symbolicName, allRange);
	}

	public static BundleSelector selectBundle(String symbolicName, String versionRange) {
		return new BundleSelector(symbolicName, VersionRange.valueOf(versionRange));
	}

	public static BundleSelector selectBundle(Bundle bundle) {
		return new BundleSelector(bundle.getSymbolicName(), new VersionRange(VersionRange.LEFT_CLOSED,
			bundle.getVersion(), bundle.getVersion(), VersionRange.RIGHT_CLOSED));
	}

	public boolean selects(Bundle bundle) {
		return Objects.equals(getSymbolicName(), bundle.getSymbolicName())
			&& getVersionRange().includes(bundle.getVersion());
	}

	@Override
	public String toString() {
		return "BundleSelector [symbolicName = '" + getSymbolicName() + "', versionRange = " + getVersionRange() + "]";
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy