Search in sources :

Example 41 with Version

use of org.osgi.framework.Version in project aries by apache.

the class VersionRangeTest method testExactVersion.

@Test
public void testExactVersion() throws Exception {
    VersionRange vr;
    try {
        vr = new VersionRange("[1.0.0, 2.0.0]", true);
        fail("from 1 to 2 not excludsive is not an exact range");
    } catch (IllegalArgumentException e) {
    // expected
    }
    vr = new VersionRange("[1.0.0, 1.0.0]", true);
    assertTrue(vr.isExactVersion());
    try {
        vr = new VersionRange("(1.0.0, 1.0.0]", true);
        fail("from 1 (not including 1) to 1, is not valid");
    } catch (IllegalArgumentException e) {
    // expected
    }
    try {
        vr = new VersionRange("[1.0.0, 1.0.0)", true);
        fail("sfrom 1 to 1 (not including 1), is not valid");
    } catch (IllegalArgumentException e) {
    // expected
    }
    vr = new VersionRange("1.0.0", true);
    assertTrue(vr.isExactVersion());
    vr = new VersionRange("1.0.0", false);
    assertFalse(vr.isExactVersion());
    vr = new VersionRange("[1.0.0, 2.0.0]");
    assertFalse(vr.isExactVersion());
    vr = new VersionRange("[1.0.0, 1.0.0]");
    assertTrue(vr.isExactVersion());
    vr = new VersionRange("1.0.0", true);
    assertEquals(new Version("1.0.0"), vr.getMinimumVersion());
    assertTrue(vr.isExactVersion());
    vr = new VersionRange("1.0.0", false);
    assertEquals(new Version("1.0.0"), vr.getMinimumVersion());
    assertNull(vr.getMaximumVersion());
    assertFalse(vr.isExactVersion());
    // don't throw any silly exceptions
    vr = new VersionRange("[1.0.0,2.0.0)", false);
    assertFalse(vr.isExactVersion());
    vr = new VersionRange("[1.0.0, 2.0.0]");
    assertFalse(vr.isExactVersion());
    vr = new VersionRange("[1.0.0, 1.0.0]");
    assertTrue(vr.isExactVersion());
}
Also used : Version(org.osgi.framework.Version) Test(org.junit.Test)

Example 42 with Version

use of org.osgi.framework.Version in project dbeaver by serge-rider.

the class FireBirdUtils method getViewSourceWithHeader.

public static String getViewSourceWithHeader(DBRProgressMonitor monitor, GenericTable view, String source) throws DBException {
    Version version = getFireBirdServerVersion(view.getDataSource());
    StringBuilder sql = new StringBuilder();
    sql.append("CREATE ");
    if (version.getMajor() > 2 || (version.getMajor() == 2 && version.getMinor() >= 5)) {
        sql.append("OR ALTER ");
    }
    sql.append("VIEW ").append(view.getName()).append(" ");
    Collection<GenericTableColumn> columns = view.getAttributes(monitor);
    if (columns != null) {
        sql.append("(");
        boolean first = true;
        for (GenericTableColumn column : columns) {
            if (!first) {
                sql.append(", ");
            }
            first = false;
            sql.append(DBUtils.getQuotedIdentifier(column));
        }
        sql.append(")\n");
    }
    sql.append("AS\n").append(source);
    return sql.toString();
}
Also used : Version(org.osgi.framework.Version)

Example 43 with Version

use of org.osgi.framework.Version in project dbeaver by serge-rider.

the class FireBirdUtils method getFireBirdServerVersion.

public static Version getFireBirdServerVersion(DBPDataSource dataSource) {
    String versionInfo = dataSource.getInfo().getDatabaseProductVersion();
    Matcher matcher = VERSION_PATTERN.matcher(versionInfo);
    if (matcher.matches()) {
        return new Version(matcher.group(1));
    }
    return new Version(0, 0, 0);
}
Also used : Matcher(java.util.regex.Matcher) Version(org.osgi.framework.Version)

Example 44 with Version

use of org.osgi.framework.Version in project sling by apache.

the class UninstallBundleCommandTest method setUp.

@Before
public void setUp() throws Exception {
    final Bundle[] b = new Bundle[3];
    for (int i = 0; i < b.length; i++) {
        b[i] = mockery.mock(Bundle.class, "bundle" + i);
    }
    // b0 is in version range, will be uninstalled
    mockery.checking(new Expectations() {

        {
            allowing(b[0]).getSymbolicName();
            will(returnValue("testbundle"));
            allowing(b[0]).getHeaders();
            will(returnValue(new Hashtable<String, String>()));
            allowing(b[0]).getVersion();
            will(returnValue(new Version("1.0.0")));
            exactly(1).of(b[0]).uninstall();
        }
    });
    // b1 is not in version range, not uninstalled
    mockery.checking(new Expectations() {

        {
            allowing(b[1]).getSymbolicName();
            will(returnValue("testbundle"));
            allowing(b[1]).getHeaders();
            will(returnValue(new Hashtable<String, String>()));
            allowing(b[1]).getVersion();
            will(returnValue(new Version("2.0.0")));
        }
    });
    // b2 has different symbolic name, not uninstalled
    mockery.checking(new Expectations() {

        {
            allowing(b[2]).getSymbolicName();
            will(returnValue("otherbundle"));
            allowing(b[2]).getHeaders();
            will(returnValue(new Hashtable<String, String>()));
            allowing(b[2]).getVersion();
            will(returnValue(new Version("1.0.0")));
        }
    });
    bundleContext = mockery.mock(BundleContext.class);
    mockery.checking(new Expectations() {

        {
            allowing(bundleContext).getBundles();
            will(returnValue(b));
        }
    });
}
Also used : Expectations(org.jmock.Expectations) Version(org.osgi.framework.Version) Bundle(org.osgi.framework.Bundle) BundleContext(org.osgi.framework.BundleContext) Before(org.junit.Before)

Example 45 with Version

use of org.osgi.framework.Version in project bnd by bndtools.

the class CapReqBuilder method toAttrs.

public Attrs toAttrs() {
    Attrs attrs = new Attrs();
    if (attributes != null) {
        for (Entry<String, Object> e : attributes.entrySet()) {
            Object value = e.getValue();
            if (e.getKey().equals("version") || value instanceof Version)
                value = toBndVersions(value);
            attrs.putTyped(e.getKey(), value);
        }
    }
    if (directives != null)
        for (Entry<String, String> e : directives.entrySet()) {
            attrs.put(e.getKey() + ":", e.getValue());
        }
    return attrs;
}
Also used : Entry(java.util.Map.Entry) Version(org.osgi.framework.Version) Attrs(aQute.bnd.header.Attrs)

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