Search in sources :

Example 76 with Version

use of org.osgi.framework.Version in project Lucee by lucee.

the class Admin method doGetBundle.

private void doGetBundle() throws PageException {
    String symbolicName = getString("admin", "getBundle", "symbolicName", true);
    Version version = OSGiUtil.toVersion(getString("version", null), null);
    BundleDefinition bd;
    BundleFile bf = null;
    Bundle b = OSGiUtil.getBundleLoaded(symbolicName, version, null);
    if (b != null) {
        bd = new BundleDefinition(b);
    } else {
        try {
            bf = OSGiUtil.getBundleFile(symbolicName, version, null, false);
            bd = bf.toBundleDefinition();
            b = bd.getLoadedBundle();
        } catch (BundleException e) {
            throw Caster.toPageException(e);
        }
    }
    CFMLEngine engine = ConfigWebUtil.getEngine(config);
    BundleCollection coreBundles = engine.getBundleCollection();
    java.util.Collection<BundleDefinition> extBundles = config.getAllExtensionBundleDefintions();
    Struct sct = new StructImpl();
    pageContext.setVariable(getString("admin", action, "returnVariable"), sct);
    sct.set(SYMBOLIC_NAME, bd.getName());
    sct.set(KeyConstants._title, bd.getName());
    sct.set(KeyConstants._version, bd.getVersionAsString());
    sct.set(USED_BY, _usedBy(bd.getName(), bd.getVersion(), coreBundles, extBundles));
    try {
        if (b != null) {
            sct.set(PATH, b.getLocation());
        } else {
            if (bf == null)
                bf = bd.getBundleFile(false);
            sct.set(PATH, bf.getFile());
        }
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
    Map<String, Object> headers = null;
    if (b != null) {
        sct.set(KeyConstants._version, bd.getVersion().toString());
        sct.set(KeyConstants._id, b.getBundleId());
        sct.set(KeyConstants._state, OSGiUtil.toState(b.getState(), null));
        sct.set(FRAGMENT, OSGiUtil.isFragment(b));
        headers = OSGiUtil.getHeaders(b);
    } else {
        sct.set(KeyConstants._state, "notinstalled");
        try {
            if (bf == null)
                bf = bd.getBundleFile(false);
            sct.set(KeyConstants._version, bf.getVersionAsString());
            sct.set(FRAGMENT, OSGiUtil.isFragment(bf));
            headers = bf.getHeaders();
        } catch (BundleException e) {
        }
    }
    if (headers != null) {
        Struct h = Caster.toStruct(headers, false);
        sct.set(HEADERS, h);
        // title
        String str = Caster.toString(h.get("Bundle-Title", null), null);
        if (StringUtil.isEmpty(str))
            str = Caster.toString(h.get("Implementation-Title", null), null);
        if (StringUtil.isEmpty(str))
            str = Caster.toString(h.get("Specification-Title", null), null);
        if (StringUtil.isEmpty(str))
            str = Caster.toString(h.get("Bundle-Name", null), null);
        if (!StringUtil.isEmpty(str))
            sct.set(KeyConstants._title, str);
        // description
        str = Caster.toString(h.get("Bundle-Description", null), null);
        if (StringUtil.isEmpty(str))
            str = Caster.toString(h.get("Implementation-Description", null), null);
        if (StringUtil.isEmpty(str))
            str = Caster.toString(h.get("Specification-Description", null), null);
        if (!StringUtil.isEmpty(str))
            sct.set(KeyConstants._description, str);
        // Vendor
        str = Caster.toString(h.get("Bundle-Vendor", null), null);
        if (StringUtil.isEmpty(str))
            str = Caster.toString(h.get("Implementation-Vendor", null), null);
        if (StringUtil.isEmpty(str))
            str = Caster.toString(h.get("Specification-Vendor", null), null);
        if (!StringUtil.isEmpty(str))
            sct.set(VENDOR, str);
    }
}
Also used : Bundle(org.osgi.framework.Bundle) Struct(lucee.runtime.type.Struct) BundleDefinition(lucee.runtime.osgi.OSGiUtil.BundleDefinition) BundleCollection(lucee.loader.osgi.BundleCollection) StructImpl(lucee.runtime.type.StructImpl) Version(org.osgi.framework.Version) BundleException(org.osgi.framework.BundleException) CFMLEngine(lucee.loader.engine.CFMLEngine) BundleFile(lucee.runtime.osgi.BundleFile)

Example 77 with Version

use of org.osgi.framework.Version in project Lucee by lucee.

the class XMLConfigAdmin method installBundle.

/*
	 * important! returns null when not a bundle!
	 */
static BundleFile installBundle(Config config, Resource resJar, String extVersion, boolean convert2bundle) throws IOException, BundleException {
    BundleFile bf = new BundleFile(resJar);
    // resJar is a bundle
    if (bf.isBundle()) {
        return installBundle(config, bf);
    }
    if (!convert2bundle)
        return null;
    // name
    String name = bf.getSymbolicName();
    if (StringUtil.isEmpty(name))
        name = BundleBuilderFactory.createSymbolicName(resJar);
    // version
    Version version = bf.getVersion();
    if (version == null)
        version = OSGiUtil.toVersion(extVersion);
    SystemOut.printDate("failed to load [" + resJar + "] as OSGi Bundle");
    BundleBuilderFactory bbf = new BundleBuilderFactory(resJar, name);
    bbf.setVersion(version);
    bbf.setIgnoreExistingManifest(false);
    bbf.build();
    bf = new BundleFile(resJar);
    SystemOut.printDate("converted  [" + resJar + "] to an OSGi Bundle");
    return installBundle(config, bf);
}
Also used : Version(org.osgi.framework.Version) BundleFile(lucee.runtime.osgi.BundleFile) BundleBuilderFactory(lucee.runtime.osgi.BundleBuilderFactory)

Example 78 with Version

use of org.osgi.framework.Version in project Lucee by lucee.

the class XMLConfigFactory method doNew.

public static UpdateInfo doNew(CFMLEngine engine, Resource contextDir, boolean readOnly) {
    lucee.Info info = engine.getInfo();
    try {
        String strOldVersion;
        final Resource resOldVersion = contextDir.getRealResource("version");
        String strNewVersion = info.getVersion() + "-" + info.getRealeaseTime();
        // fresh install
        if (!resOldVersion.exists()) {
            if (!readOnly) {
                resOldVersion.createNewFile();
                IOUtil.write(resOldVersion, strNewVersion, SystemUtil.getCharset(), false);
            }
            return UpdateInfo.NEW_FRESH;
        } else // changed version
        if (!(strOldVersion = IOUtil.toString(resOldVersion, SystemUtil.getCharset())).equals(strNewVersion)) {
            if (!readOnly)
                IOUtil.write(resOldVersion, strNewVersion, SystemUtil.getCharset(), false);
            Version oldVersion = OSGiUtil.toVersion(strOldVersion);
            return new UpdateInfo(oldVersion, oldVersion.getMajor() < 5 ? NEW_FROM4 : NEW_MINOR);
        }
    } catch (Throwable t) {
        ExceptionUtil.rethrowIfNecessary(t);
    }
    return UpdateInfo.NEW_NONE;
}
Also used : Version(org.osgi.framework.Version) Resource(lucee.commons.io.res.Resource)

Example 79 with Version

use of org.osgi.framework.Version in project linuxtools by eclipse.

the class ValgrindRemoteProxyLaunchDelegate method getValgrindVersion.

private Version getValgrindVersion(IProject project) throws CoreException {
    Version valgrindVersion;
    String verString = whichVersion(project);
    if (verString == null || verString.isEmpty()) {
        // $NON-NLS-1$
        throw new CoreException(new Status(IStatus.ERROR, ValgrindLaunchPlugin.PLUGIN_ID, Messages.getString("ValgrindLaunchPlugin.Couldn't_determine_version")));
    }
    // $NON-NLS-1$
    verString = verString.replace(VERSION_PREFIX, "");
    if (verString.indexOf(VERSION_DELIMITER) > 0) {
        verString = verString.substring(0, verString.indexOf(VERSION_DELIMITER));
    }
    if (!verString.isEmpty()) {
        valgrindVersion = Version.parseVersion(verString);
    } else {
        // $NON-NLS-1$
        throw new CoreException(new Status(IStatus.ERROR, ValgrindLaunchPlugin.PLUGIN_ID, Messages.getString("ValgrindLaunchPlugin.Couldn't_determine_version")));
    }
    // check for minimum supported version
    if (valgrindVersion.compareTo(MIN_VER) < 0) {
        // $NON-NLS-1$
        throw new CoreException(new Status(IStatus.ERROR, ValgrindLaunchPlugin.PLUGIN_ID, NLS.bind(Messages.getString("ValgrindLaunchPlugin.Error_min_version"), valgrindVersion.toString(), MIN_VER.toString())));
    }
    return valgrindVersion;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) CoreException(org.eclipse.core.runtime.CoreException) Version(org.osgi.framework.Version)

Example 80 with Version

use of org.osgi.framework.Version in project linuxtools by eclipse.

the class LaunchConfigTabTest method testTrackOrigins.

@Test
public void testTrackOrigins() throws Exception {
    ILaunchConfigurationWorkingCopy wc = initConfig();
    IProject project = CDebugUtils.verifyCProject(config).getProject();
    Version ver = ValgrindLaunchPlugin.getDefault().getValgrindVersion(project);
    if (ver.compareTo(ValgrindLaunchPlugin.VER_3_4_0) >= 0) {
        dynamicTab.getTrackOriginsButton().setSelection(true);
        // $NON-NLS-1$
        ILaunch launch = saveAndLaunch(wc, "testTrackOrigins");
        IProcess[] p = launch.getProcesses();
        assertTrue("process array should not be empty", p.length > 0);
        String cmd = p[0].getAttribute(IProcess.ATTR_CMDLINE);
        assertEquals(0, p[0].getExitValue());
        // $NON-NLS-1$
        assertTrue(cmd.contains("--track-origins=yes"));
    } else {
        assertNull(dynamicTab.getTrackOriginsButton());
    }
}
Also used : Version(org.osgi.framework.Version) ILaunch(org.eclipse.debug.core.ILaunch) ILaunchConfigurationWorkingCopy(org.eclipse.debug.core.ILaunchConfigurationWorkingCopy) IProcess(org.eclipse.debug.core.model.IProcess) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

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