Search in sources :

Example 86 with Version

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);
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) Version(org.osgi.framework.Version)

Example 87 with Version

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;
    }
}
Also used : Version(org.osgi.framework.Version)

Example 88 with Version

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());
}
Also used : CapReqBuilder(aQute.bnd.osgi.resource.CapReqBuilder) PersistentResource(aQute.bnd.osgi.resource.PersistentResource) Requirement(org.osgi.resource.Requirement) ResourceBuilder(aQute.bnd.osgi.resource.ResourceBuilder) Capability(org.osgi.resource.Capability) Version(org.osgi.framework.Version) Resource(org.osgi.resource.Resource) PersistentResource(aQute.bnd.osgi.resource.PersistentResource) JSONCodec(aQute.lib.json.JSONCodec)

Example 89 with Version

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"));
}
Also used : Capability(org.osgi.resource.Capability) Version(org.osgi.framework.Version) Resource(org.osgi.resource.Resource) URI(java.net.URI) File(java.io.File) FileInputStream(java.io.FileInputStream)

Example 90 with Version

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;
}
Also used : Version(org.osgi.framework.Version) Manifest(java.util.jar.Manifest)

Aggregations

Version (org.osgi.framework.Version)222 Test (org.junit.Test)35 ArrayList (java.util.ArrayList)28 Bundle (org.osgi.framework.Bundle)27 File (java.io.File)23 HashMap (java.util.HashMap)21 Capability (org.osgi.resource.Capability)20 IOException (java.io.IOException)19 BundleException (org.osgi.framework.BundleException)15 Resource (org.osgi.resource.Resource)14 InputStream (java.io.InputStream)12 Map (java.util.Map)11 Manifest (java.util.jar.Manifest)11 List (java.util.List)10 URL (java.net.URL)8 HashSet (java.util.HashSet)8 Content (org.apache.aries.application.Content)8 AriesApplication (org.apache.aries.application.management.AriesApplication)8 VersionRange (org.apache.felix.utils.version.VersionRange)8 BundleRevision (org.osgi.framework.wiring.BundleRevision)8