Пример #1
0
 /** Custom serialization is needed. */
 private void writeObject(ObjectOutputStream aStream) throws IOException {
   synchronized (modulesKeys) {
     aStream.defaultWriteObject();
     // write only the keys
     HashSet<ModulesKey> set = new HashSet<ModulesKey>(modulesKeys.keySet());
     if (DEBUG_IO) {
       for (ModulesKey key : set) {
         System.out.println("Write:" + key);
       }
     }
     aStream.writeObject(set);
   }
 }
Пример #2
0
 public SortedMap<ModulesKey, ModulesKey> getAllDirectModulesStartingWith(String strStartingWith) {
   if (strStartingWith.length() == 0) {
     synchronized (modulesKeys) {
       // 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 ModulesKeyTreeMap<ModulesKey, ModulesKey>(modulesKeys);
     }
   }
   ModulesKey startingWith = new ModulesKey(strStartingWith, null);
   ModulesKey endingWith = new ModulesKey(startingWith + "z", null);
   synchronized (modulesKeys) {
     // 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 ModulesKeyTreeMap<ModulesKey, ModulesKey>(
         modulesKeys.subMap(startingWith, endingWith));
   }
 }
Пример #3
0
  /** Custom deserialization is needed. */
  @SuppressWarnings("unchecked")
  private void readObject(ObjectInputStream aStream) throws IOException, ClassNotFoundException {
    lockCompletionCache = new Object();
    lockTemporaryModules = new Object();
    modulesKeys = new ModulesKeyTreeMap<ModulesKey, ModulesKey>();

    files = new HashSet<File>();
    aStream.defaultReadObject();
    Set<ModulesKey> set = (Set<ModulesKey>) aStream.readObject();
    if (DEBUG_IO) {
      for (ModulesKey key : set) {
        System.out.println("Read:" + key);
      }
    }
    for (Iterator<ModulesKey> iter = set.iterator(); iter.hasNext(); ) {
      ModulesKey key = iter.next();
      // restore with empty modules.
      modulesKeys.put(key, key);
      if (key.file != null) {
        files.add(key.file);
      }
    }
  }
Пример #4
0
  /**
   * Change the pythonpath (used for both: system and project)
   *
   * @param project: may be null
   * @param defaultSelectedInterpreter: may be null
   */
  public void changePythonPath(
      String pythonpath, final IProject project, IProgressMonitor monitor) {
    pythonPathHelper.setPythonPath(pythonpath);
    ModulesFoundStructure modulesFound = pythonPathHelper.getModulesFoundStructure(monitor);

    // now, on to actually filling the module keys
    ModulesKeyTreeMap<ModulesKey, ModulesKey> keys =
        new ModulesKeyTreeMap<ModulesKey, ModulesKey>();
    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();
      File f = entry.getKey();
      String m = entry.getValue();

      if (j % 15 == 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);
      }

      if (m != null) {
        // we don't load them at this time.
        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())) {
            // 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);
          }
        }
      }
    }

    for (ZipContents zipContents : modulesFound.zipContents) {
      if (monitor.isCanceled()) {
        break;
      }
      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);
          }
        }
      }
    }

    onChangePythonpath(keys);

    // assign to instance variable
    this.setModules(keys);
  }