Java Code Examples for org.osgi.framework.Version#emptyVersion()

The following examples show how to use org.osgi.framework.Version#emptyVersion() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: ImportPkg.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Create an import package entry.
 */
ImportPkg(ExportPkg p) {
  this.name = p.name;
  this.bpkgs = p.bpkgs;
  this.resolution = Constants.RESOLUTION_MANDATORY;
  this.bundleSymbolicName = null;
  if (p.version == Version.emptyVersion) {
    this.packageRange = null;
  } else {
    this.packageRange = new VersionRange(p.version.toString());
  }
  this.bundleRange = null;
  this.attributes = p.attributes;
  // TODO, should we import unknown directives?
  final Map<String,String> dirs = new HashMap<String, String>();
  final Filter filter = toFilter();
  if (null!=filter) {
    dirs.put(Constants.FILTER_DIRECTIVE, filter.toString());
  }
  this.directives = Collections.unmodifiableMap(dirs);
  this.parent = null;
}
 
Example 2
Source File: BundleLocator.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get the bundle archive with the highest version within the given
 * interval for the given bundle.
 *
 * @param name Name of the bundle to look for. Either the part of
 *             the file name that comes before the file version or
 *             the bundle symbolic name.
 * @param min  The lowest acceptable version number (inclusive).
 * @param max  The highest acceptable version number (exclusive). If
 *             null the highest version of this bundle will be
 *             selected.
 * @return <code>null</code> if no matching bundle archive was found.
 *
 */
private BundleArchives.BundleArchive getBundleArchive(final String name,
                                                      Version min,
                                                      final Version max)
{
  SortedSet<BundleArchive> baSet = bas.bnToBundleArchives.get(name);
  if (null==baSet) {
    baSet = bas.bsnToBundleArchives.get(BundleArchives.encodeBundleName(name));
  }
  BundleArchives.BundleArchive ba = null;

  if (null!=baSet) {
    if (null==max) { // Select highest available version
      ba = baSet.last();
    } else {
      if (null==min) {
        min = Version.emptyVersion;
      }
      for (final Object element : baSet) {
        final BundleArchives.BundleArchive candBa
          = (BundleArchives.BundleArchive) element;
        if (candBa.version.compareTo(min)<0) {
          continue;
        }
        if (candBa.version.compareTo(max)>=0) {
          break;
        }
        ba = candBa;
      }
    }
  }

  log("getBundleArchive("+name +", " +min +", " +max +")->"+ba,
      Project.MSG_VERBOSE);
  return ba;
}
 
Example 3
Source File: Util.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Get version of a repository resource form the identity name space.
 */
public static Version getResourceVersion(Resource resource)
{
  final List<Capability> idCaps =
    resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
  if (idCaps.size() != 1) {
    Activator.log.error("Found " + idCaps.size()
                        + " identity capabilites expected one: " + idCaps);
    return Version.emptyVersion;
  }
  final Capability idCap = idCaps.get(0);
  return (Version) idCap.getAttributes()
      .get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
}
 
Example 4
Source File: VersionRange.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Construct the default VersionRange object.
 *
 */
protected VersionRange() {
  low = Version.emptyVersion;
  high = null;
  lowIncluded = true;
  highIncluded = false;
}
 
Example 5
Source File: ExportPkg.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * String describing package name and specification version, if specified.
 *
 * @return String.
 */
public String pkgString() {
  if (version != Version.emptyVersion) {
    return name + ";" + Constants.VERSION_ATTRIBUTE + "=" + version;
  } else {
    return name;
  }
}
 
Example 6
Source File: ClassLoaderOsgiFramework.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Override
public Version getVersion() {
    return Version.emptyVersion;
}
 
Example 7
Source File: ClassLoaderOsgiFramework.java    From vespa with Apache License 2.0 4 votes vote down vote up
@Override
public Version getVersion() {
    return Version.emptyVersion;
}
 
Example 8
Source File: BundleImpl.java    From concierge with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * @see org.osgi.framework.wiring.BundleRevision#getVersion()
 * @category BundleRevision
 */
public Version getVersion() {
	return identity == null ? Version.emptyVersion
			: (Version) identity.getAttributes().get(
					IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
}
 
Example 9
Source File: VersionRange.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Extract a version range from an OSGi LDAP filter.
 *
 * E.g. from a require capability filter like
 *
 * <pre>
 *  (&amp;(osgi.wiring.package=org.kxml.io)(&amp;(version>=0.0.0)(!(version>=1.0.0))))
 * </pre>
 *
 * @param filter
 *          The filter string to process.
 * @param key
 *          The attribute name of the version.
 * @param defaultIfNotSpecified
 *          if no version is found in the filter then this controls whether to
 *          return the default version range or throw
 *          {@link IllegalArgumentException}.
 *
 * @throws IllegalArgumentException
 *           when no version range was found in the filter.
 */
public VersionRange(final String filter, final String key,
                    boolean defaultIfNotSpecified)
{
  Version low = null;
  Version high = null;
  boolean lowIncluded = true;
  boolean highIncluded = false;

  boolean negated = false;
  String op = null;
  int start = filter.indexOf(key);
  while (start>-1) {
    int end = start + key.length();

    // Check to the left for '(' and '!'
    --start;
    while (start>=0 && Character.isWhitespace(filter.charAt(start))) {
      --start;
    }
    if (filter.charAt(start) == '(') {
      --start;
      while (start>=0 && Character.isWhitespace(filter.charAt(start))) {
        --start;
      }
      negated = filter.charAt(start) == '!';
    }

    while (end<filter.length() && Character.isWhitespace(filter.charAt(end))) {
      ++end;
    }
    if (filter.charAt(end) == '=') {
      op = "eq";
    } else if (filter.charAt(end) == '<' && filter.charAt(++end) == '=') {
      op = negated ? "gt" : "le";
    } else if (filter.charAt(end) == '>' && filter.charAt(++end) == '=') {
      op = negated ? "lt" : "ge";
    }
    start = ++end;
    while (start<filter.length() && Character.isWhitespace(filter.charAt(start))) {
      ++start;
    }
    end = filter.indexOf(')', start);
    if (end > -1) {
      try {
        final Version v = new Version(filter.substring(start, end));
        if ("eq".equals(op)) {
          low = v;
          high = v;
          highIncluded = true;
          lowIncluded = true;
          break;
        } else if (op.charAt(0) == 'g') {
          low = v;
          lowIncluded = op.charAt(1) == 'e';
        } else if (op.charAt(0) == 'l') {
          high = v;
          highIncluded = op.charAt(1) == 'e';
        }
      } catch (final IllegalArgumentException eae) {
      }
    }
    start = filter.indexOf(key, end);
  }

  if (low!=null) {
    this.low = low;
    this.lowIncluded = lowIncluded;
    this.high = high;
    this.highIncluded = highIncluded;
  } else if (defaultIfNotSpecified) {
    // The default empty version
    this.low = Version.emptyVersion;
    this.lowIncluded = true;
    this.high = null;
    this.highIncluded = false;
  } else {
    throw new IllegalArgumentException("no version range found in " +filter);
  }

}
 
Example 10
Source File: ConditionalPermissionAdminImpl.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public Version getVersion() {
  return Version.emptyVersion;
}
 
Example 11
Source File: ExportPkg.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
/**
 * Create an export package entry.
 */
ExportPkg(final String name, final HeaderEntry he, final BundlePackages b)
{
  this.bpkgs = b;
  this.name = name;
  if (name.startsWith("java.")) {
    throw new IllegalArgumentException("You can not export a java.* package");
  }
  this.uses = Util.parseEnumeration(Constants.USES_DIRECTIVE, he
      .getDirectives().get(Constants.USES_DIRECTIVE));
  this.mandatory = Util.parseEnumeration(Constants.MANDATORY_DIRECTIVE, he
      .getDirectives().get(Constants.MANDATORY_DIRECTIVE));
  this.include = Util.parseEnumeration(Constants.INCLUDE_DIRECTIVE, he
      .getDirectives().get(Constants.INCLUDE_DIRECTIVE));
  this.exclude = Util.parseEnumeration(Constants.EXCLUDE_DIRECTIVE, he
      .getDirectives().get(Constants.EXCLUDE_DIRECTIVE));
  final String versionStr = (String) he.getAttributes()
      .remove(Constants.VERSION_ATTRIBUTE);
  @SuppressWarnings("deprecation")
  final String SPEC_VERSION = Constants.PACKAGE_SPECIFICATION_VERSION;
  final String specVersionStr = (String) he.getAttributes().remove(SPEC_VERSION);
  if (specVersionStr != null) {
    this.version = new Version(specVersionStr);
    if (versionStr != null && !this.version.equals(new Version(versionStr))) {
      throw new IllegalArgumentException("Both " + Constants.VERSION_ATTRIBUTE +
                                         " and " + SPEC_VERSION  +
                                         " are specified, and differs");
    }
  } else if (versionStr != null) {
    this.version = new Version(versionStr);
  } else {
    this.version = Version.emptyVersion;
  }
  if (he.getAttributes().containsKey(Constants.BUNDLE_VERSION_ATTRIBUTE)) {
    throw new IllegalArgumentException("Export definition illegally contains attribute, " +
                                       Constants.BUNDLE_VERSION_ATTRIBUTE);
  }
  if (he.getAttributes().containsKey(Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE)) {
    throw new IllegalArgumentException("Export definition illegally contains attribute, " +
                                       Constants.BUNDLE_SYMBOLICNAME_ATTRIBUTE);
  }
  this.attributes = Collections.unmodifiableMap(he.getAttributes());
}
 
Example 12
Source File: DefaultAddonRegistration.java    From packagedrone with Eclipse Public License 1.0 4 votes vote down vote up
public Invalid ( final Path path, final Throwable e )
{
    this.path = path;
    this.error = e;
    this.description = new AddonDescription ( "unknwown", Version.emptyVersion, "n/a" );
}
 
Example 13
Source File: OSGiJaxwsEndpointManager.java    From cxf with Apache License 2.0 4 votes vote down vote up
private Version getBundleVersion(Bundle bundle) {
    Dictionary<?, ?> headers = bundle.getHeaders();
    String version = (String) headers.get(Constants.BUNDLE_VERSION);
    return (version != null) ? Version.parseVersion(version) : Version.emptyVersion;
}
 
Example 14
Source File: OSGIBusListener.java    From cxf with Apache License 2.0 4 votes vote down vote up
private Version getBundleVersion(Bundle bundle) {
    Dictionary<?, ?> headers = bundle.getHeaders();
    String version = (String) headers.get(Constants.BUNDLE_VERSION);
    return (version != null) ? Version.parseVersion(version) : Version.emptyVersion;
}