public void testIntegrityInModuleHasNoFile() throws MisconfigurationException {
    IntegrityInfo info = AdditionalInfoIntegrityChecker.checkIntegrity(nature, monitor, false);
    assertTrue(info.desc.toString(), info.allOk);

    File f = FileUtils.getTempFileAt(baseDir, "integrity_no_file", ".py");
    FileUtils.writeStrToFile("", f);
    addFooModule(new Module(new stmtType[0]), f);
    info = AdditionalInfoIntegrityChecker.checkIntegrity(nature, monitor, false);
    assertFalse(info.allOk);
    assertEquals(1, info.modulesNotInDisk.size());
    assertEquals(info.modulesNotInDisk.get(0), new ModulesKey("foo", null));

    fixAndCheckAllOk(info);
  }
Ejemplo n.º 2
0
  public void saveToFile(File workspaceMetadataFile) {
    if (workspaceMetadataFile.exists() && !workspaceMetadataFile.isDirectory()) {
      try {
        FileUtils.deleteFile(workspaceMetadataFile);
      } catch (IOException e) {
        throw new RuntimeException(e);
      }
    }
    if (!workspaceMetadataFile.exists()) {
      workspaceMetadataFile.mkdirs();
    }

    File modulesKeysFile = new File(workspaceMetadataFile, "modulesKeys");
    File pythonpatHelperFile = new File(workspaceMetadataFile, "pythonpath");
    FastStringBuffer buf;
    HashMap<String, Integer> commonTokens = new HashMap<String, Integer>();

    synchronized (modulesKeysLock) {
      buf = new FastStringBuffer(this.modulesKeys.size() * 50);
      buf.append(MODULES_MANAGER_V2);

      for (Iterator<ModulesKey> iter = this.modulesKeys.keySet().iterator(); iter.hasNext(); ) {
        ModulesKey next = iter.next();
        buf.append(next.name);
        if (next.file != null) {
          buf.append("|");
          if (next instanceof ModulesKeyForZip) {
            ModulesKeyForZip modulesKeyForZip = (ModulesKeyForZip) next;
            if (modulesKeyForZip.zipModulePath != null) {
              String fileStr = next.file.toString();
              Integer t = commonTokens.get(fileStr);
              if (t == null) {
                t = commonTokens.size();
                commonTokens.put(fileStr, t);
              }
              buf.append(t);
              buf.append("|");

              buf.append(modulesKeyForZip.zipModulePath);
              buf.append("|");
              buf.append(modulesKeyForZip.isFile ? '1' : '0');
            }
          } else {
            buf.append(next.file.toString());
          }
        }
        buf.append('\n');
      }
    }
    if (commonTokens.size() > 0) {
      FastStringBuffer header = new FastStringBuffer(buf.length() + (commonTokens.size() * 50));
      header.append(MODULES_MANAGER_V2);
      header.append("--COMMON--\n");
      for (Map.Entry<String, Integer> entries : commonTokens.entrySet()) {
        header.append(entries.getValue());
        header.append('=');
        header.append(entries.getKey());
        header.append('\n');
      }
      header.append("--END-COMMON--\n");
      header.append(buf);
      buf = header;
    }
    FileUtils.writeStrToFile(buf.toString(), modulesKeysFile);

    this.pythonPathHelper.saveToFile(pythonpatHelperFile);
  }