예제 #1
0
  /**
   * @return a tuple with the new keys to be added to the modules manager (i.e.: found in keysFound
   *     but not in the modules manager) and the keys to be removed from the modules manager (i.e.:
   *     found in the modules manager but not in the keysFound)
   */
  public Tuple<List<ModulesKey>, List<ModulesKey>> diffModules(
      PyPublicTreeMap<ModulesKey, ModulesKey> keysFound) {
    ArrayList<ModulesKey> newKeys = new ArrayList<ModulesKey>();
    ArrayList<ModulesKey> removedKeys = new ArrayList<ModulesKey>();
    Iterator<ModulesKey> it = keysFound.keySet().iterator();

    synchronized (modulesKeysLock) {
      while (it.hasNext()) {
        ModulesKey next = it.next();
        ModulesKey modulesKey = modulesKeys.get(next);
        if (modulesKey == null || modulesKey.getClass() != next.getClass()) {
          // Check the class because ModulesKey and ModulesKeyForZip are equal considering only the
          // name.
          newKeys.add(next);
        }
      }

      it = modulesKeys.keySet().iterator();
      while (it.hasNext()) {
        ModulesKey next = it.next();
        ModulesKey modulesKey = modulesKeys.get(next);
        if (modulesKey == null || modulesKey.getClass() != next.getClass()) {
          removedKeys.add(next);
        }
      }
    }

    return new Tuple<List<ModulesKey>, List<ModulesKey>>(newKeys, removedKeys);
  }
예제 #2
0
  public static void buildKeysForRegularEntries(
      IProgressMonitor monitor,
      ModulesFoundStructure modulesFound,
      PyPublicTreeMap<ModulesKey, ModulesKey> keys,
      boolean includeOnlySourceModules) {
    String[] dottedValidSourceFiles = FileTypesPreferencesPage.getDottedValidSourceFiles();

    int j = 0;
    FastStringBuffer buffer = new FastStringBuffer();
    // now, create in memory modules for all the loaded files (empty modules).
    for (Iterator<Map.Entry<File, String>> iterator =
            modulesFound.regularModules.entrySet().iterator();
        iterator.hasNext() && monitor.isCanceled() == false;
        j++) {
      Map.Entry<File, String> entry = iterator.next();
      String m = entry.getValue();

      if (m != null) {
        if (j % 20 == 0) {
          // no need to report all the time (that's pretty fast now)
          buffer.clear();
          monitor.setTaskName(buffer.append("Module resolved: ").append(m).toString());
          monitor.worked(1);
        }

        // we don't load them at this time.
        File f = entry.getKey();

        if (includeOnlySourceModules) {
          // check if we should include only source modules
          if (!PythonPathHelper.isValidSourceFile(f.getName())) {
            continue;
          }
        }
        ModulesKey modulesKey = new ModulesKey(m, f);

        // no conflict (easy)
        if (!keys.containsKey(modulesKey)) {
          keys.put(modulesKey, modulesKey);

        } else {
          // we have a conflict, so, let's resolve which one to keep (the old one or this one)
          if (PythonPathHelper.isValidSourceFile(f.getName(), dottedValidSourceFiles)) {
            // source files have priority over other modules (dlls) -- if both are source, there is
            // no real way to resolve
            // this priority, so, let's just add it over.
            keys.put(modulesKey, modulesKey);
          }
        }
      }
    }
  }
예제 #3
0
  public static void buildKeysForZipContents(
      PyPublicTreeMap<ModulesKey, ModulesKey> keys, ZipContents zipContents) {
    for (String filePathInZip : zipContents.foundFileZipPaths) {
      String modName = StringUtils.stripExtension(filePathInZip).replace('/', '.');
      if (DEBUG_ZIP) {
        System.out.println("Found in zip:" + modName);
      }
      ModulesKey k = new ModulesKeyForZip(modName, zipContents.zipFile, filePathInZip, true);
      keys.put(k, k);

      if (zipContents.zipContentsType == ZipContents.ZIP_CONTENTS_TYPE_JAR) {
        // folder modules are only created for jars (because for python files, the __init__.py is
        // required).
        for (String s :
            new FullRepIterable(
                FullRepIterable.getWithoutLastPart(
                    modName))) { // the one without the last part was already added
          k = new ModulesKeyForZip(s, zipContents.zipFile, s.replace('.', '/'), false);
          keys.put(k, k);
        }
      }
    }
  }
예제 #4
0
 public SortedMap<ModulesKey, ModulesKey> getAllDirectModulesStartingWith(String strStartingWith) {
   if (strStartingWith.length() == 0) {
     synchronized (modulesKeysLock) {
       // we don't want it to be backed up by the same set (because it may be changed, so, we may
       // get
       // a java.util.ConcurrentModificationException on places that use it)
       return new PyPublicTreeMap<ModulesKey, ModulesKey>(modulesKeys);
     }
   }
   ModulesKey startingWith = new ModulesKey(strStartingWith, null);
   ModulesKey endingWith = new ModulesKey(startingWith + "z", null);
   synchronized (modulesKeysLock) {
     // we don't want it to be backed up by the same set (because it may be changed, so, we may get
     // a java.util.ConcurrentModificationException on places that use it)
     return new PyPublicTreeMap<ModulesKey, ModulesKey>(
         modulesKeys.subMap(startingWith, endingWith));
   }
 }