Beispiel #1
0
 private void addNewDependency(
     String id, String version, int match, List preservedImports, List newImports)
     throws CoreException {
   if (findFeaturePlugin(id, version, match) != null) {
     // don't add imports to local plug-ins
     return;
   }
   if (findImport(preservedImports, id, version, match) != null) {
     // already seen
     return;
   }
   if (findImport(newImports, id, version, match) != null) {
     // already seen
     return;
   }
   IFeatureImport iimport = findImport(fImports, id, version, match);
   if (iimport != null) {
     // import still valid
     preservedImports.add(iimport);
     return;
   }
   // a new one is needed
   iimport = getModel().getFactory().createImport();
   iimport.setId(id);
   iimport.setVersion(version);
   iimport.setMatch(match);
   ((FeatureImport) iimport).setInTheModel(true);
   newImports.add(iimport);
 }
Beispiel #2
0
 /**
  * Finds a given import in the list
  *
  * @param imports list of imports
  * @param id
  * @param version
  * @param match
  * @return IFeatureImport or null
  */
 private IFeatureImport findImport(List imports, String id, String version, int match) {
   for (int i = 0; i < imports.size(); i++) {
     IFeatureImport iimport = (IFeatureImport) imports.get(i);
     if (iimport.getId().equals(id)) {
       if (version == null) return iimport;
       if (version.equals(iimport.getVersion()) && match == iimport.getMatch()) return iimport;
     }
   }
   return null;
 }
Beispiel #3
0
 /*
  * returns true if this thread can obtain the global lock or already has the lock;
  * otherwise this loader and thread are added to the waitingList
  */
 private static synchronized boolean tryLock(Thread currentThread, Object loader) {
   if (lockThread == currentThread) {
     lockCount++;
     return true;
   }
   if (lockThread == null) {
     lockCount++;
     lockThread = currentThread;
     return true;
   }
   waitingList.add(new Object[] {currentThread, loader});
   return false;
 }
Beispiel #4
0
  /*
   * unlocks the global lock and notifies the first waiting thread that they
   * now have the lock
   */
  private static void unlock() {
    Thread waitingThread = null;
    Object loader = null;
    synchronized (BundleLoader.class) {
      lockCount--;
      if (lockCount != 0) return;

      if (waitingList.isEmpty()) {
        lockThread = null;
        return;
      }

      Object[] waiting = (Object[]) waitingList.get(0);
      waitingThread = (Thread) waiting[0];
      loader = waiting[1];
    }
    synchronized (loader) {
      synchronized (BundleLoader.class) {
        lockThread = waitingThread;
        waitingList.remove(0);
        loader.notifyAll();
      }
    }
  }