use of org.python.pydev.core.ModulesKey in project Pydev by fabioz.
the class DiskCache method writeTo.
/**
* Writes this cache in a format that may later be restored with loadFrom.
*/
public void writeTo(FastStringBuffer tempBuf) {
tempBuf.append("-- START DISKCACHE_" + DiskCache.VERSION + "\n");
tempBuf.append(folderToPersist);
tempBuf.append('\n');
for (CompleteIndexKey key : keys.values()) {
ModulesKey modKey = key.key;
tempBuf.append(modKey.name);
tempBuf.append('|');
tempBuf.append(key.lastModified);
tempBuf.append('|');
if (modKey.file != null) {
tempBuf.append(modKey.file.toString());
} else {
// could be null!
}
if (modKey instanceof ModulesKeyForZip) {
ModulesKeyForZip modulesKeyForZip = (ModulesKeyForZip) modKey;
tempBuf.append('|');
tempBuf.append(modulesKeyForZip.zipModulePath);
tempBuf.append('|');
tempBuf.append(modulesKeyForZip.isFile ? '0' : '1');
} else if (modKey instanceof ModulesKeyForFolder) {
tempBuf.append('|');
tempBuf.append('^');
}
tempBuf.append('\n');
}
tempBuf.append("-- END DISKCACHE\n");
}
use of org.python.pydev.core.ModulesKey in project Pydev by fabioz.
the class DiskCacheTest method testDiskCacheWithZipModulesKey.
public void testDiskCacheWithZipModulesKey() throws Exception {
DiskCache cache = new DiskCache(new File(baseDir, ".cache"), "_test_disk_cache");
cache.add(new CompleteIndexKey(new ModulesKey("mod1", new File(baseDir, "f1")), 100));
cache.add(new CompleteIndexKey(new ModulesKey("modnull", null), 100));
cache.add(new CompleteIndexKey(new ModulesKeyForZip("mod2", new File(baseDir, "my.zip"), "path", true), 100));
cache.add(new CompleteIndexKey(new ModulesKeyForZip("mod3", new File(baseDir, "my.zip"), "path2", false), 100));
FastStringBuffer tempBuf = new FastStringBuffer();
cache.writeTo(tempBuf);
FastBufferedReader reader = new FastBufferedReader(new StringReader(tempBuf.toString()));
//
FastStringBuffer line = reader.readLine();
assertEquals(line.toString(), "-- START DISKCACHE_" + DiskCache.VERSION);
ObjectsPoolMap objectsPoolMap = new ObjectsPoolMap();
DiskCache loadFrom = DiskCache.loadFrom(reader, objectsPoolMap);
assertEquals(cache.keys(), loadFrom.keys());
assertEquals(cache.getFolderToPersist(), loadFrom.getFolderToPersist());
CompleteIndexKey mod = cache.keys().get(new CompleteIndexKey("mod2"));
ModulesKeyForZip zip = (ModulesKeyForZip) mod.key;
assertEquals(zip.zipModulePath, "path");
mod = loadFrom.keys().get(new CompleteIndexKey("mod2"));
zip = (ModulesKeyForZip) mod.key;
assertEquals(zip.zipModulePath, "path");
mod = loadFrom.keys().get(new CompleteIndexKey("modnull"));
assertNull(mod.key.file);
mod = loadFrom.keys().get(new CompleteIndexKey("mod3"));
zip = (ModulesKeyForZip) mod.key;
assertEquals(zip.zipModulePath, "path2");
assertTrue(zip.isFile);
}
use of org.python.pydev.core.ModulesKey in project Pydev by fabioz.
the class ModulesManager method buildKeysForRegularEntries.
public static void buildKeysForRegularEntries(IProgressMonitor monitor, ModulesFoundStructure modulesFound, PyPublicTreeMap<ModulesKey, ModulesKey> keys, boolean includeOnlySourceModules) {
String[] dottedValidSourceFiles = FileTypesPreferences.getDottedValidSourceFiles();
int j = 0;
FastStringBuffer buffer = new FastStringBuffer();
Map<String, File> packages = new HashMap<String, File>();
String packageM;
File packageF;
// 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;
}
}
packageM = FullRepIterable.getParentModule(m);
packageF = f.getParentFile();
while (!packageM.isEmpty()) {
packages.put(packageM, packageF);
packageM = FullRepIterable.getParentModule(packageM);
packageF = packageF.getParentFile();
}
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);
}
}
}
}
for (Map.Entry<String, File> packageEntry : packages.entrySet()) {
buffer.clear();
File f = packageEntry.getValue();
ModulesKey modulesKeyForFolder = new ModulesKeyForFolder(buffer.append(packageEntry.getKey()).append(".__init__").toString(), f);
if (!keys.containsKey(modulesKeyForFolder)) {
keys.put(modulesKeyForFolder, modulesKeyForFolder);
}
}
}
use of org.python.pydev.core.ModulesKey in project Pydev by fabioz.
the class ModulesManager method buildKeysForZipContents.
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);
}
}
}
}
use of org.python.pydev.core.ModulesKey in project Pydev by fabioz.
the class ModulesManager method getAllDirectModulesStartingWith.
@Override
public SortedMap<ModulesKey, ModulesKey> getAllDirectModulesStartingWith(String strStartingWith) {
if (strStartingWith.length() == 0) {
synchronized (modulesKeysLock) {
// 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(strStartingWith + "\uffff\uffff\uffff\uffff", null);
synchronized (modulesKeysLock) {
// a java.util.ConcurrentModificationException on places that use it)
return new PyPublicTreeMap<ModulesKey, ModulesKey>(modulesKeys.subMap(startingWith, endingWith));
}
}
Aggregations