Example #1
0
 private static Resource getResource(Set<Resource> resources, String bsn, String versionString) {
   for (Resource resource : resources) {
     List<Capability> identities = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
     if (identities != null && identities.size() == 1) {
       Capability idCap = identities.get(0);
       Object id = idCap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE);
       Object version = idCap.getAttributes().get(IdentityNamespace.CAPABILITY_VERSION_ATTRIBUTE);
       if (bsn.equals(id)) {
         if (versionString == null) {
           return resource;
         }
         Version requested = Version.parseVersion(versionString);
         Version current;
         if (version instanceof Version) {
           current = (Version) version;
         } else {
           current = Version.parseVersion((String) version);
         }
         if (requested.equals(current)) {
           return resource;
         }
       }
     }
   }
   return null;
 }
Example #2
0
 public List<Capability> findProvider(Requirement requirement) {
   List<Capability> result = new ArrayList<Capability>();
   String namespace = requirement.getNamespace();
   for (Resource resource : resources) {
     for (Capability capability : resource.getCapabilities(namespace))
       if (ResourceUtils.matches(requirement, capability)) result.add(capability);
   }
   return result;
 }
Example #3
0
 /** Get the name of a repository resource from the identity name space." */
 public static String getResourceName(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 resource.toString();
   }
   final Capability idCap = idCaps.get(0);
   return idCap.getAttributes().get(IdentityNamespace.IDENTITY_NAMESPACE).toString();
 }
 private static void ensureOsgiContentUrlsAreAbsolute(URL repositoryUrl, Collection<Resource> rs)
     throws Exception {
   for (Resource r : rs) {
     for (Capability c : r.getCapabilities(ContentNamespace.CONTENT_NAMESPACE)) {
       String url = (String) c.getAttributes().get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE);
       url = new URL(repositoryUrl, url).toExternalForm();
       c.getAttributes().put(ContentNamespace.CAPABILITY_URL_ATTRIBUTE, url);
     }
   }
 }
 public static void debug(ParseResult pr) {
   System.out.println("======= BEGIN PARSED REPOSITORY XML =======");
   for (Resource r : pr.resources) {
     System.out.println(r.toString());
   }
   System.out.println("======== END PARSED REPOSITORY XML ========");
   System.out.println("======== NAME: " + pr.name);
   System.out.println("======== INCREMENT: " + pr.increment);
   System.out.println("======== RESOURCES FOUND: " + pr.resources.size());
   System.out.flush();
 }
Example #6
0
 /**
  * Get the icon for a repository resource.
  *
  * <p>The icon is specified as the value of the bundle manifest entry named {@code Bundle-Icon}.
  *
  * @param resource The resource to get the icon for.
  * @return Resource icon string or {@code null} if icon information is not available.
  */
 public static String getResourceIcon(Resource resource) {
   for (final Capability cap : resource.getCapabilities(KF_EXTRAS_NAMESPACE)) {
     final Map<String, Object> attrs = cap.getAttributes();
     final Object val = attrs.get("icon");
     if (val != null) {
       return (String) val;
     }
   }
   return null;
 }
Example #7
0
 /** 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 #8
0
 /**
  * Get the size in bytes of a repository resource.
  *
  * @param resource The resource to get the size of.
  * @return Resource size in byte or {@code -1} if no size available.
  */
 public static long getResourceSize(Resource resource) {
   long res = -1;
   for (final Capability cap : resource.getCapabilities(ContentNamespace.CONTENT_NAMESPACE)) {
     final Map<String, Object> attrs = cap.getAttributes();
     final Long size = (Long) attrs.get(ContentNamespace.CAPABILITY_SIZE_ATTRIBUTE);
     if (size != null) {
       res = size.longValue();
     }
   }
   return res;
 }
Example #9
0
 /**
  * Get the type of a repository resource from the identity name space."
  *
  * @param resource The resource to get the type for.
  * @return Type as a string, one of {@link IdentityNamespace#TYPE_BUNDLE}, {@link
  *     IdentityNamespace#TYPE_FRAGMENT}, and {@link IdentityNamespace#TYPE_UNKNOWN}.
  */
 public static String getResourceType(Resource resource) {
   final List<Capability> idCaps = resource.getCapabilities(IdentityNamespace.IDENTITY_NAMESPACE);
   for (final Capability idCap : idCaps) {
     final String type =
         (String) idCap.getAttributes().get(IdentityNamespace.CAPABILITY_TYPE_ATTRIBUTE);
     if (type != null) {
       return type;
     }
   }
   return "&mdash;";
 }
Example #10
0
 /**
  * Get the location to use when installing this resource.
  *
  * <p>If available, the resource URL will be used as the location. Otherwise we simply use the
  * hash code of the resource.
  *
  * @param resource the resource to determine the installation location for.
  * @return location to use when installing this resource or {@code null} if location is available
  *     for this resource.
  */
 public static String getLocation(Resource resource) {
   for (final Capability cap : resource.getCapabilities(ContentNamespace.CONTENT_NAMESPACE)) {
     final Map<String, Object> attrs = cap.getAttributes();
     if (supportedMimeTypes.contains(attrs.get(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE))) {
       final String url = (String) attrs.get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE);
       if (url != null) {
         return url;
       }
     }
   }
   return null;
 }
Example #11
0
 /**
  * Get the MIME-type of a repository resource.
  *
  * @param resource The resource to get the MIME type for.
  * @return Resource MIME type or {@code null} if no MIME-type available.
  */
 public static String getResourceMime(Resource resource) {
   String res = null;
   for (final Capability cap : resource.getCapabilities(ContentNamespace.CONTENT_NAMESPACE)) {
     final Map<String, Object> attrs = cap.getAttributes();
     final String mime = (String) attrs.get(ContentNamespace.CAPABILITY_MIME_ATTRIBUTE);
     if (mime != null) {
       res = mime;
       break;
     }
   }
   return res;
 }
Example #12
0
 /**
  * Get the URL of a repository resource.
  *
  * @param resource The resource to get the URL for.
  * @return Resource download URL or {@code null} if no URL available.
  */
 public static URL getResourceUrl(Resource resource) {
   URL res = null;
   for (final Capability cap : resource.getCapabilities(ContentNamespace.CONTENT_NAMESPACE)) {
     final Map<String, Object> attrs = cap.getAttributes();
     final String url = (String) attrs.get(ContentNamespace.CAPABILITY_URL_ATTRIBUTE);
     if (url != null) {
       try {
         res = new URL(url);
         break;
       } catch (final Exception e) {
         Activator.log.warn("Failed to parse reosurce URL '" + url + "' for " + resource, e);
       }
     }
   }
   return res;
 }