use of org.osgi.framework.Version in project eclipse-pmd by acanda.
the class PMDMarkerResolutionGenerator method getCompilerCompliance.
private Version getCompilerCompliance(final IMarker marker) {
final IJavaProject project = JavaCore.create(marker.getResource().getProject());
final String compilerCompliance = project.getOption(JavaCore.COMPILER_COMPLIANCE, true);
return new Version(compilerCompliance);
}
use of org.osgi.framework.Version in project eclipse-pmd by acanda.
the class ProjectPropertyTester method isJavaVersionLessThan.
/**
* Returns {@code true} if the version of the currently used JVM is lower than the provided argument. If either of
* the versions cannot be parsed this method returns {@code false}.
*
* @param version The version string against the version of the JVM is tested. The format of the version string
* should follow the Java version format, e.g. 1.7.0_45.
*/
private boolean isJavaVersionLessThan(final String version) {
try {
final Version actual = new Version(convert(System.getProperty("java.version", "0")));
final Version upperBound = new Version(convert(version));
return actual.compareTo(upperBound) < 0;
} catch (IllegalArgumentException e) {
return false;
}
}
use of org.osgi.framework.Version in project bnd by bndtools.
the class PersistentResourceTest method testSimple.
public void testSimple() throws Exception {
ResourceBuilder rb = new ResourceBuilder();
rb.addCapability(new CapReqBuilder("test").addAttribute("double", 3.0).addAttribute("long", 3L).addAttribute("string", "3.0").addAttribute("version", new Version("3.0")).buildSyntheticCapability());
Resource r = rb.build();
PersistentResource pr = new PersistentResource(r);
String s = new JSONCodec().enc().put(pr).toString();
PersistentResource pr2 = new JSONCodec().dec().from(s).get(PersistentResource.class);
List<Capability> capabilities = pr.getResource().getCapabilities(null);
List<Requirement> requirements = pr.getResource().getRequirements(null);
assertEquals(1, capabilities.size());
assertEquals(0, requirements.size());
Capability capability = capabilities.get(0);
assertEquals("test", capability.getNamespace());
assertEquals(3.0, capability.getAttributes().get("double"));
assertEquals(3L, capability.getAttributes().get("long"));
assertEquals("3.0", capability.getAttributes().get("string"));
assertEquals(new Version("3.0"), capability.getAttributes().get("version"));
assertEquals(0, capability.getDirectives().size());
}
use of org.osgi.framework.Version in project bnd by bndtools.
the class TestObrCapReqParsing method testObrContentCaps.
public static void testObrContentCaps() throws Exception {
FileInputStream stream = new FileInputStream("testdata/fullobr.xml");
URI baseUri = new File("testdata").toURI();
List<Resource> resources = parseIndex(stream, baseUri);
assertEquals(7, resources.size());
Resource resource = resources.get(0);
// Check identity
List<Capability> idCaps = resource.getCapabilities("osgi.identity");
assertEquals(1, idCaps.size());
assertEquals("name.njbartlett.osgi.emf.minimal", idCaps.get(0).getAttributes().get("osgi.identity"));
// Check content
List<Capability> contentCaps = resource.getCapabilities("osgi.content");
assertEquals(1, contentCaps.size());
assertEquals(IO.getFile("testdata/bundles/name.njbartlett.osgi.emf.minimal-2.7.0.jar").getAbsoluteFile().toURI(), contentCaps.get(0).getAttributes().get("url"));
// Check bundle
List<Capability> bundleCaps = resource.getCapabilities("osgi.wiring.bundle");
assertEquals(1, bundleCaps.size());
assertEquals("name.njbartlett.osgi.emf.minimal", bundleCaps.get(0).getAttributes().get("osgi.wiring.bundle"));
assertEquals(new Version("2.7.0.201104130744"), bundleCaps.get(0).getAttributes().get("bundle-version"));
// Check packages
List<Capability> pkgCaps = resource.getCapabilities("osgi.wiring.package");
assertNotNull(pkgCaps);
assertEquals(14, pkgCaps.size());
assertEquals("org.eclipse.emf.common", pkgCaps.get(0).getAttributes().get("osgi.wiring.package"));
assertEquals(new Version("2.7.0.201104130744"), pkgCaps.get(0).getAttributes().get("version"));
assertEquals("org.eclipse.core.runtime,org.eclipse.emf.common.util,org.osgi.framework", pkgCaps.get(0).getDirectives().get("uses"));
// Check service capabilities of felix.shell bundle
List<Capability> svcCaps = resources.get(4).getCapabilities("osgi.service");
assertNotNull(svcCaps);
assertEquals(2, svcCaps.size());
assertEquals("org.apache.felix.shell.ShellService", svcCaps.get(0).getAttributes().get("osgi.service"));
assertEquals("org.ungoverned.osgi.service.shell.ShellService", svcCaps.get(1).getAttributes().get("osgi.service"));
}
use of org.osgi.framework.Version in project bnd by bndtools.
the class Util method getVersion.
public static Version getVersion(Resource resource) throws IOException {
Manifest manifest = resource.getManifest();
if (manifest == null)
throw new IllegalArgumentException(String.format("Cannot identify version for resource %s: manifest unavailable", resource.getLocation()));
String versionStr = manifest.getMainAttributes().getValue(Constants.BUNDLE_VERSION);
Version version = (versionStr != null) ? new Version(versionStr) : Version.emptyVersion;
return version;
}
Aggregations