Ejemplo n.º 1
0
 Object put(VersionSupplier versionSupplier) {
   VersionSupplier[] existing = (VersionSupplier[]) internal.get(versionSupplier.getName());
   if (existing == null) {
     VersionSupplier[] vss = new VersionSupplier[1];
     vss[0] = versionSupplier;
     internal.put(versionSupplier.getName(), vss);
   } else {
     for (int i = 0; i < existing.length; i++) {
       VersionSupplier e = existing[i];
       if (e == versionSupplier) return e;
       if (versionSupplier.getBundle().isResolved() && !e.getBundle().isResolved()) {
         // Put resolved bundles ahead of unresolved bundles
         internal.put(versionSupplier.getName(), add(i, versionSupplier, existing));
         return null;
       } else if (versionSupplier.getBundle().isResolved() == e.getBundle().isResolved()) {
         if (versionSupplier.getVersion().compareTo(e.getVersion()) > 0) {
           // Put highest versions first
           internal.put(versionSupplier.getName(), add(i, versionSupplier, existing));
           return null;
         } else if (e.getVersion().equals(versionSupplier.getVersion())) {
           if (versionSupplier.getBundle().getBundleId() < e.getBundle().getBundleId()) {
             // Versions match - order by bundle ID
             internal.put(versionSupplier.getName(), add(i, versionSupplier, existing));
             return e;
           }
         }
       }
     }
     // Lowest version, so add at end
     internal.put(versionSupplier.getName(), add(existing.length, versionSupplier, existing));
   }
   return null;
 }
Ejemplo n.º 2
0
 // Once we have resolved bundles, we need to make sure that exports
 // from these are ahead of those from unresolved bundles
 void reorder() {
   Iterator it = internal.values().iterator();
   while (it.hasNext()) {
     ArrayList toBeReordered = new ArrayList();
     VersionSupplier[] existing = (VersionSupplier[]) it.next();
     if (existing == null || existing.length <= 1) continue;
     // Find any VersionSuppliers that need to be reordered
     VersionSupplier vs1 = (VersionSupplier) existing[0];
     for (int i = 1; i < existing.length; i++) {
       VersionSupplier vs2 = (VersionSupplier) existing[i];
       BundleDescription b1 = vs1.getBundle();
       BundleDescription b2 = vs2.getBundle();
       if (b2.isResolved() && !b1.isResolved()) {
         toBeReordered.add(vs2);
       } else if (b2.isResolved() == b1.isResolved()) {
         int versionDiff = vs2.getVersion().compareTo(vs1.getVersion());
         if (versionDiff > 0 || (b2.getBundleId() < b1.getBundleId() && versionDiff == 0)) {
           toBeReordered.add(vs2);
         }
       }
       vs1 = vs2;
     }
     // Reorder them
     for (int i = 0; i < toBeReordered.size(); i++) {
       VersionSupplier vs = (VersionSupplier) toBeReordered.get(i);
       remove(vs);
       put(vs);
     }
   }
 }