Java 类org.osgi.framework.Version 实例源码

项目:neoscada    文件:Starter.java   
private Bundle readFromManifest ( final String location, final Manifest m ) throws IOException
{
    final Object sn = m.getMainAttributes ().getValue ( Constants.BUNDLE_SYMBOLICNAME );
    if ( ! ( sn instanceof String ) )
    {
        return null;
    }

    final Object version = m.getMainAttributes ().getValue ( Constants.BUNDLE_VERSION );
    if ( ! ( version instanceof String ) )
    {
        return null;
    }

    String symName = (String)sn;
    symName = symName.split ( ";", 2 )[0];

    return new Bundle ( symName, new Version ( (String)version ), location );
}
项目:hashsdn-controller    文件:ChildAwareFeatureWrapper.java   
protected Feature extractFeatureFromDependency(final Dependency dependency) throws Exception {
    Feature[] features = featuresService.listFeatures();
    VersionRange range = org.apache.karaf.features.internal.model.Feature.DEFAULT_VERSION.equals(dependency
            .getVersion()) ? VersionRange.ANY_VERSION : new VersionRange(dependency.getVersion(), true, true);
    Feature fi = null;
    for (Feature f : features) {
        if (f.getName().equals(dependency.getName())) {
            Version version = VersionTable.getVersion(f.getVersion());
            if (range.contains(version) && (fi == null || VersionTable.getVersion(fi.getVersion())
                    .compareTo(version) < 0)) {
                fi = f;
                break;
            }
        }
    }
    return fi;
}
项目:osgi-dp    文件:AbstractDpMojo.java   
private Version makeQualifiedVersion() {
    try {
        final ReactorProject rp = (ReactorProject) this.project.getContextValue(ReactorProject.CTX_REACTOR_PROJECT);
        if (rp != null) {
            return new Version(rp.getExpandedVersion());
        }
    } catch (final Exception e) {
        getLog().debug("Failed to get qualified tycho version", e);
    }

    String version = this.project.getVersion();
    if (version.endsWith("-SNAPSHOT")) {
        version = version.replaceAll("-SNAPSHOT$", "." + TIMESTAMP_FORMAT.format(this.session.getStartTime()));
    }

    return new Version(version);
}
项目:packagedrone    文件:InstallableUnitTest.java   
@Test
public void test1 ()
{
    final FeatureInformation fi = new FeatureInformation ();

    fi.setId ( "f1" );
    fi.setVersion ( Version.parseVersion ( "1.2.3" ) );
    fi.setQualifiers ( new Qualifiers () );

    fi.getRequirements ().add ( new Requirement ( Type.FEATURE, "f2", null, MatchRule.DEFAULT ) );
    fi.getRequirements ().add ( new Requirement ( Type.PLUGIN, "b1", null, MatchRule.DEFAULT ) );

    final List<InstallableUnit> ius = InstallableUnit.fromFeature ( fi );

    assertEquals ( 2, ius.size () );

    assertFeatureGroup1 ( ius.get ( 0 ) );
    assertFeatureJar1 ( ius.get ( 1 ) );
}
项目:gwt-eclipse-plugin    文件:GdtPlugin.java   
private static void rebuildProjectIfPluginVersionChanged(IProject project) {
  // We're only worried about GWT projects
  if (GWTNature.isGWTProject(project.getProject())) {
    // Find the last plugin version that know the project was built with
    Version lastForcedRebuildAt = GdtPreferences.getVersionForLastForcedRebuild(project);
    Version currentPluginVersion = GdtPlugin.getVersion();

    if (!lastForcedRebuildAt.equals(currentPluginVersion)) {
      GdtPreferences.setVersionForLastForcedRebuild(project, currentPluginVersion);

      BuilderUtilities.scheduleRebuild(project);
      CorePluginLog.logInfo("Scheduled rebuild of project " + project.getName()
          + " because of plugin update (current version: " + currentPluginVersion.toString() + ")");
    }
  }
}
项目:mytourbook    文件:TourFilterManager.java   
private static XMLMemento writeFilterProfile_10_Root() {

        final XMLMemento xmlRoot = XMLMemento.createWriteRoot(TAG_ROOT);

        // date/time
        xmlRoot.putString(Util.ATTR_ROOT_DATETIME, TimeTools.now().toString());

        // plugin version
        final Version version = _bundle.getVersion();
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MAJOR, version.getMajor());
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MINOR, version.getMinor());
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MICRO, version.getMicro());
        xmlRoot.putString(Util.ATTR_ROOT_VERSION_QUALIFIER, version.getQualifier());

        // layer structure version
        xmlRoot.putInteger(ATTR_TOUR_FILTER_VERSION, TOUR_FILTER_VERSION);

        return xmlRoot;
    }
项目:APICloud-Studio    文件:VersionUtil.java   
private static boolean isCompatibleVersionsRegex(Map<String, Version> installed, String required)
{
    // compile the regex.
    Pattern pattern = null;
    try
    {
        pattern = Pattern.compile(required);
    }
    catch (PatternSyntaxException e)
    {
        IdeLog.logError(CorePlugin.getDefault(), MessageFormat.format(
                "The required version '{0}' should be defined as a regular-expression", required)); //$NON-NLS-1$
        return false;
    }

    // Do a match on the installed-versions original String values
    for (String installedVersion : installed.keySet())
    {
        Matcher matcher = pattern.matcher(installedVersion);
        if (matcher.find())
        {
            return true;
        }
    }
    return false;
}
项目:gwt-eclipse-plugin    文件:XStartOnFirstThreadArgumentProcessor.java   
@Override
public void update(ILaunchConfigurationWorkingCopy launchConfig,
    IJavaProject javaProject, List<String> programArgs, List<String> vmArgs)
    throws CoreException {

  // As of Eclipse Kepler(4.3), the use of -XStartOnFirstThread is a built-in launch config
  // attribute so it is not necessary to make it an explicit argument. This prevents issues when
  // sharing a launch config file across multiple OS platforms.
  Bundle bundle = Platform.getBundle("org.eclipse.platform");
  if (bundle != null) {
    Version bundleVersion = bundle.getVersion();
    if (bundleVersion.getMajor() == 4 && bundleVersion.getMinor() >= 3) {
      updateEclipse43(launchConfig, javaProject, programArgs, vmArgs);
    } else {
      updateNonEclipse43(launchConfig, javaProject, programArgs, vmArgs);
    }
  }
}
项目:Lucee    文件:OSGiUtil.java   
public static Bundle loadBundleFromLocal(BundleContext bc,String name, Version version, boolean loadIfNecessary, Bundle defaultValue) {
name=name.trim();
    Bundle[] bundles = bc.getBundles();
    for(Bundle b:bundles){
        if(name.equalsIgnoreCase(b.getSymbolicName())) {
            if(version==null || version.equals(b.getVersion())) {
                return b;
            }
        }
    }
    if(!loadIfNecessary) return defaultValue;

    // is it in jar directory but not loaded

    CFMLEngine engine = ConfigWebUtil.getEngine(ThreadLocalPageContext.getConfig());
CFMLEngineFactory factory = engine.getCFMLEngineFactory();
BundleFile bf = _getBundleFile(factory, name, version, null);
if(bf!=null) {
    try {
        return _loadBundle(bc, bf.getFile());
    } 
    catch (Exception e) {}
}

    return defaultValue;
  }
项目:mytourbook    文件:MapBookmarkManager.java   
private static XMLMemento create_Root() {

        final XMLMemento xmlRoot = XMLMemento.createWriteRoot(TAG_ROOT);

        // date/time
        xmlRoot.putString(Util.ATTR_ROOT_DATETIME, TimeTools.now().toString());

        // plugin version
        final Version version = _bundle.getVersion();
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MAJOR, version.getMajor());
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MINOR, version.getMinor());
        xmlRoot.putInteger(Util.ATTR_ROOT_VERSION_MICRO, version.getMicro());
        xmlRoot.putString(Util.ATTR_ROOT_VERSION_QUALIFIER, version.getQualifier());

        // config version
        xmlRoot.putInteger(ATTR_CONFIG_VERSION, CONFIG_VERSION);

        return xmlRoot;
    }
项目:incubator-taverna-osgi    文件:PluginManagerImpl.java   
@Override
public void checkForUpdates() throws PluginException {
    boolean updatesFound = false;
    synchronized (pluginUpdates) {
        pluginUpdates.clear();
        for (PluginSite pluginSite : pluginSiteManager.getPluginSites()) {
            List<PluginVersions> plugins = pluginSiteManager.getPlugins(pluginSite);
            for (PluginVersions plugin : plugins) {
                if (installedPlugins.containsKey(plugin.getId())) {
                    Plugin installedPlugin = installedPlugins.get(plugin.getId());
                    if (installedPlugin.getFile().toFile().canWrite()) {
                        Version latestVersion = Version.parseVersion(plugin.getLatestVersion()
                                .getVersion());
                        if (latestVersion.compareTo(installedPlugin.getVersion()) > 0) {
                            pluginUpdates.put(plugin.getId(), plugin);
                            updatesFound = true;
                        }
                    }
                }
            }
        }
    }
    if (updatesFound) {
        postEvent(PluginManager.UPDATES_AVAILABLE);
    }
}
项目:osgi.security-tests    文件:TestServer.java   
private void runTest(Map<String, Bundle> installed, DataInputStream input, DataOutputStream output) throws Exception {
    String symbolicName = input.readUTF();
    Version version = Version.parseVersion(input.readUTF());
    String testClass = input.readUTF();
    String testName = input.readUTF();

    Bundle testBundle = getTestBundle(installed, input, output, symbolicName, version);

    Class<?> testClazz = testBundle.loadClass(testClass);

    Result result = new JUnitCore().run(Request.method(testClazz, testName));

    if(result.wasSuccessful()) {
        output.writeUTF(SUCCESS);
    } else {
        Failure failure = result.getFailures().get(0);
        output.writeUTF(FAIL);
        output.writeUTF(failure.getMessage());
    }

    output.flush();
}
项目:AgentWorkbench    文件:VersionInfo.java   
/**
 * Loads the version information to this instance.
 */
public Version getVersion() {
    if (version==null) {
        Bundle bundle = Platform.getBundle(this.plugInID);
        version = bundle.getVersion();
    }
    return version;
}
项目:aries-jpa    文件:PropsConfigurationTest.java   
@SuppressWarnings("unchecked")
@Before
public void setup() throws Exception {

    when(punit.getPersistenceUnitName()).thenReturn("test-props");
    when(punit.getPersistenceProviderClassName())
        .thenReturn(ECLIPSE_PERSISTENCE_PROVIDER);
    when(punit.getTransactionType()).thenReturn(PersistenceUnitTransactionType.JTA);
    when(punit.getBundle()).thenReturn(punitBundle);
    when(punit.getProperties()).thenReturn(punitProperties);

    when(punitBundle.getBundleContext()).thenReturn(punitContext);
    when(punitBundle.getVersion()).thenReturn(Version.parseVersion("1.2.3"));

    when(containerContext.registerService(eq(ManagedService.class), 
            any(ManagedService.class), any(Dictionary.class))).thenReturn(msReg);
    when(containerContext.getService(dsfRef)).thenReturn(dsf);
    when(containerContext.getService(dsRef)).thenReturn(ds);
    when(containerContext.createFilter(Mockito.anyString()))
        .thenAnswer(new Answer<Filter>() {
            @Override
            public Filter answer(InvocationOnMock i) throws Throwable {
                return FrameworkUtil.createFilter(i.getArguments()[0].toString());
            }
        });

    when(punitContext.registerService(eq(EntityManagerFactory.class), any(EntityManagerFactory.class), 
            any(Dictionary.class))).thenReturn(emfReg);

    when(emf.isOpen()).thenReturn(true);


    Properties jdbcProps = new Properties();
    jdbcProps.setProperty("url", JDBC_URL);
    jdbcProps.setProperty("user", JDBC_USER);
    jdbcProps.setProperty("password", JDBC_PASSWORD);

    when(dsf.createDataSource(jdbcProps)).thenReturn(ds);

}
项目:neoscada    文件:Processor.java   
private static String readQualifier ( final Path jarFile ) throws IOException
{
    final String version = readManifest ( jarFile ).getMainAttributes ().getValue ( Constants.BUNDLE_VERSION );
    if ( version == null )
    {
        return version;
    }

    return Version.parseVersion ( version ).getQualifier ();
}
项目:osc-core    文件:DeploymentInstaller.java   
private static String getVersion(Capability identityCap) {
    Object versionObj = identityCap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
    if (versionObj == null) {
        return Version.emptyVersion.toString();
    }
    if (versionObj instanceof Version) {
        return ((Version) versionObj).toString();
    }
    if (versionObj instanceof String) {
        return Version.parseVersion((String) versionObj).toString();
    }
    throw new IllegalArgumentException("Incorrect type on identity version");
}
项目:gemini.blueprint    文件:PublishedInterfacesTest.java   
private void checkedPublishedOSGiService(int expectedContexts) throws Exception {
    ServiceReference[] refs = bundleContext.getServiceReferences(
        ConfigurableOsgiBundleApplicationContext.class.getName(), null);
    assertEquals("different number of published contexts encountered", expectedContexts, refs.length);

    for (int i = 0; i < refs.length; i++) {
        ServiceReference serviceReference = refs[i];
        String[] interfaces = (String[]) serviceReference.getProperty(Constants.OBJECTCLASS);
        assertEquals("not enough interfaces published", 15, interfaces.length);
        assertEquals(Version.emptyVersion, serviceReference.getProperty(Constants.BUNDLE_VERSION));
        assertEquals(bundleContext.getBundle().getSymbolicName(),
            serviceReference.getProperty(Constants.BUNDLE_SYMBOLICNAME));
    }
}
项目:gemini.blueprint    文件:MockBundle.java   
private static Version getVersion(Dictionary headers) {
    if (headers != null) {
        Object header = headers.get(Constants.BUNDLE_VERSION);
        if (header instanceof String) {
            return Version.parseVersion((String) header);
        }
    }

    return Version.emptyVersion;
}
项目:gemini.blueprint    文件:OsgiEventDispatcher.java   
private Dictionary<String, Object> init(BlueprintEvent event) {
    Dictionary<String, Object> props = new Hashtable<String, Object>();

    Bundle bundle = event.getBundle();

    // common properties
    props.put(TIMESTAMP, System.currentTimeMillis());
    props.put(EVENT, event);
    props.put(TYPE, Integer.valueOf(event.getType()));

    props.put(BUNDLE, event.getBundle());
    props.put(BUNDLE_ID, bundle.getBundleId());

    // name (under two keys)
    String name = OsgiStringUtils.nullSafeName(bundle);
    props.put(BUNDLE_NAME, name);
    props.put(Constants.BUNDLE_NAME, name);

    // sym name (under two keys)
    String symName = OsgiStringUtils.nullSafeSymbolicName(bundle);
    props.put(BUNDLE_SYM_NAME, symName);
    props.put(Constants.BUNDLE_SYMBOLICNAME, symName);

    // version (as well under two keys)
    Version version = OsgiBundleUtils.getBundleVersion(bundle);
    props.put(BUNDLE_VERSION, version);
    props.put(Constants.BUNDLE_VERSION, version);

    // extender bundle info
    Bundle extenderBundle = event.getExtenderBundle();

    props.put(EXTENDER_BUNDLE, extenderBundle);
    props.put(EXTENDER_BUNDLE_ID, extenderBundle.getBundleId());
    props.put(EXTENDER_BUNDLE_SYM_NAME, extenderBundle.getSymbolicName());
    Version extenderVersion = OsgiBundleUtils.getBundleVersion(extenderBundle);
    props.put(EXTENDER_BUNDLE_VERSION, extenderVersion);

    return props;
}
项目:gemini.blueprint    文件:NamespaceHandlerActivator.java   
public void start(BundleContext extenderBundleContext) {
    this.extenderBundleContext = extenderBundleContext;
    this.nsManager = new NamespaceManager(extenderBundleContext);
    this.bundleId = extenderBundleContext.getBundle().getBundleId();
    Version extenderVersion = OsgiBundleUtils.getBundleVersion(extenderBundleContext.getBundle());
    this.versionMatcher = new DefaultVersionMatcher(getManagedBundleExtenderVersionHeader(), extenderVersion);

    initNamespaceHandlers(extenderBundleContext);
}
项目:gemini.blueprint    文件:ConfigUtilsVersioningTest.java   
protected void setUp() throws Exception {
    props = new Properties();
    bundle = new MockBundle(props);

    min = Version.parseVersion("1.2");
    max = Version.parseVersion("1.3");
    version = Version.parseVersion("1.2.5");
}
项目:gemini.blueprint    文件:ConfigUtilsVersioningTest.java   
public void testTooManyCommas() {
    String ver = "[1.2, ,1.3]";
    addVersion(ver);

    try {
        ConfigUtils.matchExtenderVersionRange(bundle, ConfigUtils.EXTENDER_VERSION, Version.emptyVersion);
        fail("should have thrown exception; invalid range");
    }
    catch (IllegalArgumentException ex) {
        // expected
    }
}
项目:gemini.blueprint    文件:ConfigUtilsVersioningTest.java   
public void testTooManyCommasAgain() {
    String ver = "[1,2 , 1.3)";
    addVersion(ver);

    try {
        ConfigUtils.matchExtenderVersionRange(bundle, ConfigUtils.EXTENDER_VERSION, Version.emptyVersion);
        fail("should have thrown exception; invalid range");
    }
    catch (IllegalArgumentException ex) {
        // expected
    }
}
项目:gemini.blueprint    文件:ConfigUtilsVersioningTest.java   
public void testNoBracketsIntervalOnRight() {
    String ver = "[1.2, 1.3";
    addVersion(ver);

    try {
        ConfigUtils.matchExtenderVersionRange(bundle, ConfigUtils.EXTENDER_VERSION, Version.emptyVersion);
        fail("should have thrown exception; invalid range");
    }
    catch (IllegalArgumentException ex) {
        // expected
    }

}
项目:gemini.blueprint    文件:ConfigUtilsVersioningTest.java   
public void testNoBracketsIntervalOnLeft() {
    String ver = "1.2, 1.3)";
    addVersion(ver);

    try {
        ConfigUtils.matchExtenderVersionRange(bundle, ConfigUtils.EXTENDER_VERSION, Version.emptyVersion);
        fail("should have thrown exception; invalid range");
    }
    catch (IllegalArgumentException ex) {
        // expected
    }

}
项目:gemini.blueprint    文件:ConfigUtilsVersioningTest.java   
public void testNoCommaInterval() {
    String ver = "[1.2 1.3]";
    addVersion(ver);

    try {
        ConfigUtils.matchExtenderVersionRange(bundle, ConfigUtils.EXTENDER_VERSION, Version.emptyVersion);
        fail("should have thrown exception; invalid range");
    }
    catch (IllegalArgumentException ex) {
        // expected
    }
}
项目:gemini.blueprint    文件:DebugUtils.java   
/**
 * Get the version of a package import from a bundle.
 * 
 * @param bundle
 * @param packageName
 * @return
 */
private static Version hasImport(Bundle bundle, String packageName) {
    Dictionary dict = bundle.getHeaders();
    // Check imports
    String imports = (String) dict.get(Constants.IMPORT_PACKAGE);
    Version v = getVersion(imports, packageName);
    if (v != null) {
        return v;
    }
    // Check for dynamic imports
    String dynimports = (String) dict.get(Constants.DYNAMICIMPORT_PACKAGE);
    if (dynimports != null) {
        for (StringTokenizer strok = new StringTokenizer(dynimports, COMMA); strok.hasMoreTokens();) {
            StringTokenizer parts = new StringTokenizer(strok.nextToken(), SEMI_COLON);
            String pkg = parts.nextToken().trim();
            if (pkg.endsWith(".*") && packageName.startsWith(pkg.substring(0, pkg.length() - 2)) || pkg.equals("*")) {
                Version version = Version.emptyVersion;
                for (; parts.hasMoreTokens();) {
                    String modifier = parts.nextToken().trim();
                    if (modifier.startsWith("version")) {
                        version = Version.parseVersion(modifier.substring(modifier.indexOf(EQUALS) + 1).trim());
                    }
                }
                return version;
            }
        }
    }
    return null;
}
项目:gemini.blueprint    文件:BlueprintContainerServicePublisher.java   
private void registerService(ApplicationContext applicationContext) {
    final Dictionary<String, Object> serviceProperties = new Hashtable<String, Object>();

    Bundle bundle = bundleContext.getBundle();
    String symName = bundle.getSymbolicName();
    serviceProperties.put(Constants.BUNDLE_SYMBOLICNAME, symName);
    serviceProperties.put(BLUEPRINT_SYMNAME, symName);

    Version version = OsgiBundleUtils.getBundleVersion(bundle);
    serviceProperties.put(Constants.BUNDLE_VERSION, version);
    serviceProperties.put(BLUEPRINT_VERSION, version);

    log.info("Publishing BlueprintContainer as OSGi service with properties " + serviceProperties);

    // export just the interface
    final String[] serviceNames = new String[] { BlueprintContainer.class.getName() };

    if (log.isDebugEnabled())
        log.debug("Publishing service under classes " + ObjectUtils.nullSafeToString(serviceNames));

    AccessControlContext acc = SecurityUtils.getAccFrom(applicationContext);

    // publish service
    if (System.getSecurityManager() != null) {
        registration = AccessController.doPrivileged(new PrivilegedAction<ServiceRegistration>() {
            public ServiceRegistration run() {
                return bundleContext.registerService(serviceNames, blueprintContainer, serviceProperties);
            }
        }, acc);
    } else {
        registration = bundleContext.registerService(serviceNames, blueprintContainer, serviceProperties);
    }
}
项目:egradle    文件:EclipseUtil.java   
public static VersionData createVersionData(Bundle bundle) {
    if (bundle == null) {
        return VersionData.UNKNOWN;
    }
    Version osgiVersion = bundle.getVersion();
    if (osgiVersion == null) {
        return VersionData.UNKNOWN;
    }
    return new VersionData(osgiVersion.toString());
}
项目:aries-rsa    文件:EventAdminHelper.java   
private Event createEvent(Map<String, Object> props, String type) {
    String topic = "org/osgi/service/remoteserviceadmin/" + type;
    props.put("bundle", bctx.getBundle());
    props.put("bundle.id", bctx.getBundle().getBundleId());
    props.put("bundle.symbolicname", bctx.getBundle().getSymbolicName());

    String version = (String)bctx.getBundle().getHeaders().get("Bundle-Version");
    Version v = version != null ? new Version(version) : Version.emptyVersion;
    setIfNotNull(props, "bundle.version", v);

    return new Event(topic, props);
}
项目:gvnix1    文件:UaaRegistrationServiceImpl.java   
/**
 * Populates the version information in the passed {@link Builder}. This
 * information is obtained by locating the bundle and using its version
 * metadata. The Git hash code is acquired from the manifest.
 * <p>
 * The method returns without error if the bundle could not be found.
 * 
 * @param featureUseBuilder to insert feature use information into
 *            (required)
 * @param bundleSymbolicName to locate (required)
 */
private void populateVersionInfoIfPossible(final Builder featureUseBuilder,
        final String bundleSymbolicName) {
    Version version = bsnVersionCache.get(bundleSymbolicName);
    String commitHash = bsnCommitHashCache.get(bundleSymbolicName);

    if (version == null) {
        for (final Bundle b : bundleContext.getBundles()) {
            if (bundleSymbolicName.equals(b.getSymbolicName())) {
                version = b.getVersion();
                bsnVersionCache.put(bundleSymbolicName, version);
                final Object manifestResult = b.getHeaders().get(
                        "Git-Commit-Hash");
                if (manifestResult != null) {
                    commitHash = manifestResult.toString();
                    bsnCommitHashCache.put(bundleSymbolicName, commitHash);
                }
                break;
            }
        }
    }

    if (version == null) {
        // Can't acquire OSGi version information for this bundle, so give
        // up now
        return;
    }

    featureUseBuilder.setMajorVersion(version.getMajor());
    featureUseBuilder.setMinorVersion(version.getMinor());
    featureUseBuilder.setPatchVersion(version.getMicro());
    featureUseBuilder.setReleaseQualifier(version.getQualifier());
    if (commitHash != null && commitHash.length() > 0) {
        featureUseBuilder.setSourceControlIdentifier(commitHash);
    }
}
项目:vespa    文件:RestApiContext.java   
public BundleInfo(String symbolicName, Version version, String fileLocation, URL webInfUrl, ClassLoader classLoader) {
    this.symbolicName = symbolicName;
    this.version = version;
    this.fileLocation = fileLocation;
    this.webInfUrl = webInfUrl;
    this.classLoader = classLoader;
}
项目:tlaplus    文件:ToolboxHandle.java   
/**
   * Returns the classpath entry of the tla2tool.jar (the TLA tools) 
   */
  public static IPath getTLAToolsClasspath() {
    Bundle bundle = null;

    // find the tlatools bundle among all installed bundles
    // (this code assumes tlatools has a bundle shape "dir")
Bundle[] bundles = Activator.getDefault().getBundle()
        .getBundleContext().getBundles();
      for (int i = 0; i < bundles.length; i++) {
    Bundle aBundle = bundles[i];
    if ("org.lamport.tlatools".equals(aBundle.getSymbolicName())) {
        // OSGi supports multiple bundles with the same symbolic name, but
        // different versions. This e.g. occurs after a Toolbox update
        // before the old bundle version gets purged from the
        // installation directory.
        // Without this explicitly version check, the Toolbox
        // might accidentally use an old tla version which leads to
        // undefined behavior.
        // @see Bug #285 in general/bugzilla/index.html
        Version otherVersion = bundle != null ? bundle.getVersion()
                : Version.parseVersion("0.0.0");
        if (aBundle.getVersion().compareTo(otherVersion) > 0) {
            bundle = aBundle;
        }
    }
}
      if (bundle == null)
          return null;

      URL local = null;
      try
      {
          local = FileLocator.toFileURL(bundle.getEntry("/")); //$NON-NLS-1$
      } catch (IOException e)
      {
          return null;
      }
      String fullPath = new File(local.getPath()).getAbsolutePath();
      return Path.fromOSString(fullPath);
  }
项目:Camel    文件:OsgiCamelContextPublisher.java   
public ServiceRegistration<?> registerCamelContext(CamelContext camelContext) throws InvalidSyntaxException {
    // avoid registering the same service again
    // we must include unique camel management name so the symbolic name becomes unique,
    // in case the bundle has more than one CamelContext
    String name = camelContext.getName();
    String managementName = camelContext.getManagementName();
    String symbolicName = bundleContext.getBundle().getSymbolicName();

    if (!lookupCamelContext(bundleContext, symbolicName, name)) {
        Version bundleVersion = getBundleVersion(bundleContext.getBundle());

        Dictionary<String, Object > props = new Hashtable<String, Object>();
        props.put(CONTEXT_SYMBOLIC_NAME_PROPERTY, symbolicName);
        props.put(CONTEXT_VERSION_PROPERTY, bundleVersion);
        props.put(CONTEXT_NAME_PROPERTY, name);
        if (managementName != null) {
            props.put(CONTEXT_MANAGEMENT_NAME_PROPERTY, managementName);
        }

        if (log.isDebugEnabled()) {
            log.debug("Registering CamelContext [{}] of in OSGi registry", camelContext.getName());
        }

        ServiceRegistration<?> reg = bundleContext.registerService(CamelContext.class.getName(), camelContext, props);
        if (reg != null) {
            registrations.put(camelContext, reg);
        }
        return reg;
    } else {
        return null;
    }
}
项目:Camel    文件:OsgiCamelContextPublisher.java   
/**
 * Lookup in the OSGi Service Registry whether a {@link org.apache.camel.CamelContext} is already registered with the given symbolic name.
 *
 * @return <tt>true</tt> if exists, <tt>false</tt> otherwise
 */
public static boolean lookupCamelContext(BundleContext bundleContext, String symbolicName, String contextName) throws InvalidSyntaxException {
    Version bundleVersion = getBundleVersion(bundleContext.getBundle());
    ServiceReference<?>[] refs = bundleContext.getServiceReferences(CamelContext.class.getName(),
            "(&(" + CONTEXT_SYMBOLIC_NAME_PROPERTY + "=" + symbolicName + ")"
            + "(" + CONTEXT_NAME_PROPERTY + "=" + contextName + ")"
            + "(" + CONTEXT_VERSION_PROPERTY + "=" + bundleVersion + "))");
    return refs != null && refs.length > 0;
}
项目:Lucee    文件:OSGiUtil.java   
public static Bundle getBundleLoaded(BundleContext bc,String name, Version version, Bundle defaultValue) {
name=name.trim();

    Bundle[] bundles = bc.getBundles();
    for(Bundle b:bundles){
        if(name.equalsIgnoreCase(b.getSymbolicName())) {
            if(version==null || version.equals(b.getVersion())) {
                return b;
            }
        }
    }
    return defaultValue;
  }
项目:triquetrum    文件:Activator.java   
@Override
public void start(BundleContext context) throws Exception {

  // FIXME figure out a more compact way to create a version-aware provider,
  // that uses the bundle version but is not too dependent on OSGi APIs itself.
  Version bundleVersion = context.getBundle().getVersion();
  VersionSpecification providerVersion = new ThreeDigitVersionSpecification(bundleVersion.getMajor(), bundleVersion.getMinor(), bundleVersion.getMicro(),
      bundleVersion.getQualifier());

  _apSvcReg = context.registerService(ModelElementClassProvider.class.getName(), new DefaultModelElementClassProvider(providerVersion, XYPlotActor.class),
      null);
}
项目:PDFReporter-Studio    文件:PluginUtilities.java   
/**
 * Return the version identifier associated with the plug-in with the given identifier, or
 * <code>null</code> if there is no such plug-in.
 * 
 * @param pluginId
 *          the identifier of the plug-in
 * 
 * @return the version identifier for the specified plug-in
 */
public static Version getVersion(Plugin plugin) {
  String version;
  if (plugin == null) {
    return null;
  }
  version =
      (String) plugin.getBundle().getHeaders().get(org.osgi.framework.Constants.BUNDLE_VERSION);
  return new Version(version);
}
项目:Lucee    文件:OSGiUtil.java   
public boolean matches(Version v) {
    if(EQ==op) return v.compareTo(version)==0;
    if(LTE==op) return v.compareTo(version)<=0;
    if(LT==op) return v.compareTo(version)<0;
    if(GTE==op) return v.compareTo(version)>=0;
    if(GT==op) return v.compareTo(version)>0;
    if(NEQ==op) return v.compareTo(version)!=0;
    return false;
}
项目:triquetrum    文件:DefaultTaskProcessingBroker.java   
private boolean internalRegisterService(TaskProcessingService service, Version svcVersion) {
  boolean result = false;
  SortedSet<ServiceEntry> svcSet = services.get(service.getName());
  if (svcSet == null) {
    svcSet = new ConcurrentSkipListSet<>();
    services.put(service.getName(), svcSet);
  }
  if (svcSet.add(new ServiceEntry(service, svcVersion))) {
    result = true;
    LOGGER.debug("Registered service {} with version {}", service.getName(), svcVersion);
  } else {
    LOGGER.debug("Ignored duplicate service {} with version {}", service.getName(), svcVersion);
  }
  return result;
}