コード例 #1
0
ファイル: JpmRepoTest.java プロジェクト: kwin/bnd
 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;
 }
コード例 #2
0
ファイル: ResourcesRepository.java プロジェクト: GitHubTE/bnd
 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;
 }
コード例 #3
0
ファイル: Util.java プロジェクト: PioneerLab/knopflerfish.org
 /** 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();
 }
コード例 #4
0
 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);
     }
   }
 }
コード例 #5
0
 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();
 }
コード例 #6
0
ファイル: Util.java プロジェクト: PioneerLab/knopflerfish.org
 /**
  * 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;
 }
コード例 #7
0
ファイル: Util.java プロジェクト: PioneerLab/knopflerfish.org
 /** 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);
 }
コード例 #8
0
ファイル: Util.java プロジェクト: PioneerLab/knopflerfish.org
 /**
  * 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;
 }
コード例 #9
0
ファイル: Util.java プロジェクト: PioneerLab/knopflerfish.org
 /**
  * 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;";
 }
コード例 #10
0
ファイル: Util.java プロジェクト: PioneerLab/knopflerfish.org
 /**
  * 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;
 }
コード例 #11
0
ファイル: Util.java プロジェクト: PioneerLab/knopflerfish.org
 /**
  * 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;
 }
コード例 #12
0
ファイル: Util.java プロジェクト: PioneerLab/knopflerfish.org
 /**
  * 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;
 }