use of org.python.pydev.navigator.elements.PythonSourceFolder in project Pydev by fabioz.
the class PythonModelProviderTest method testPythonpathChanges.
/**
* Test if changing the pythonpath has the desired effects in the python model.
*/
public void testPythonpathChanges() throws Exception {
final HashSet<String> pythonPathSet = new HashSet<String>();
pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source");
pythonPathSet.add("invalid");
PythonNature nature = createNature(pythonPathSet);
project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot"), nature, true);
provider = new PythonModelProvider();
Object[] children1 = provider.getChildren(project);
assertTrue(children1[0] instanceof PythonSourceFolder);
// no changes in the pythonpath
// still the same
provider.internalDoNotifyPythonPathRebuilt(project, new ArrayList<String>(pythonPathSet));
Object[] children2 = provider.getChildren(project);
assertEquals(1, children1.length);
assertEquals(1, children2.length);
// changed pythonpath (source folders should be removed)
pythonPathSet.clear();
pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source/python");
provider.internalDoNotifyPythonPathRebuilt(project, new ArrayList<String>(pythonPathSet));
Object[] children3 = provider.getChildren(project);
assertFalse(children3[0] instanceof PythonSourceFolder);
// restore initial
pythonPathSet.clear();
pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source");
Object[] children4 = provider.getChildren(project);
assertTrue(children4[0] instanceof PythonSourceFolder);
// because it was removed
assertNotSame(children1[0], children4[0]);
}
use of org.python.pydev.navigator.elements.PythonSourceFolder in project Pydev by fabioz.
the class PythonModelProviderTest method testFolderToSourceFolder2.
public void testFolderToSourceFolder2() throws Exception {
final HashSet<String> pythonPathSet = new HashSet<String>();
pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source");
String source2Folder = TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source2";
File f = new File(source2Folder);
File f1 = new File(f, "childFolder");
File f2 = new File(f1, "rechildFolder");
if (f2.exists()) {
f2.delete();
}
if (f1.exists()) {
f1.delete();
}
if (f.exists()) {
f.delete();
}
// still not created!
pythonPathSet.add(source2Folder);
PythonNature nature = createNature(pythonPathSet);
project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot"), nature, false);
provider = new PythonModelProvider();
Object[] children1 = provider.getChildren(project);
assertEquals(1, children1.length);
assertTrue("Expected source folder. Received: " + children1[0], children1[0] instanceof PythonSourceFolder);
f.mkdir();
f1.mkdir();
f2.mkdir();
try {
FolderStub source2FolderFile = new FolderStub(project, f);
FolderStub source2FolderChild = new FolderStub(project, source2FolderFile, f1);
FolderStub source2FolderReChild = new FolderStub(project, source2FolderChild, f2);
Set set = new HashSet();
set.add(source2FolderReChild);
provider.interceptAdd(new PipelinedShapeModification(source2FolderChild, set));
assertEquals(1, set.size());
PythonFolder c = (PythonFolder) set.iterator().next();
PythonSourceFolder sourceFolder = c.getSourceFolder();
assertTrue(sourceFolder instanceof PythonSourceFolder);
set.clear();
set.add(source2FolderChild);
provider.interceptRemove(new PipelinedShapeModification(source2FolderFile, set));
assertTrue(set.iterator().next() instanceof PythonFolder);
// System.out.println(set);
set.clear();
set.add(source2FolderReChild);
provider.interceptAdd(new PipelinedShapeModification(source2FolderChild, set));
assertTrue(set.iterator().next() instanceof PythonFolder);
// System.out.println(set);
set.clear();
set.add(source2FolderChild);
provider.interceptRemove(new PipelinedShapeModification(source2FolderFile, set));
assertTrue(set.iterator().next() instanceof PythonFolder);
// System.out.println(set);
set.clear();
set.add(source2FolderReChild);
provider.interceptAdd(new PipelinedShapeModification(source2FolderChild, set));
assertTrue(set.iterator().next() instanceof PythonFolder);
// System.out.println(set);
} finally {
f2.delete();
f1.delete();
f.delete();
}
}
use of org.python.pydev.navigator.elements.PythonSourceFolder in project Pydev by fabioz.
the class PythonModelProviderTest method testFolderToSourceFolder.
public void testFolderToSourceFolder() throws Exception {
final HashSet<String> pythonPathSet = new HashSet<String>();
pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source");
String source2Folder = TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source2";
File f = new File(source2Folder);
File f1 = new File(f, "childFolder");
if (f1.exists()) {
f1.delete();
}
if (f.exists()) {
f.delete();
}
// still not created!
pythonPathSet.add(source2Folder);
PythonNature nature = createNature(pythonPathSet);
project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot"), nature, false);
provider = new PythonModelProvider();
Object[] children1 = provider.getChildren(project);
assertEquals(1, children1.length);
assertTrue("Found: " + children1[0], children1[0] instanceof PythonSourceFolder);
f.mkdir();
f1.mkdir();
try {
FolderStub source2FolderFile = new FolderStub(project, f);
FolderStub source2FolderChild = new FolderStub(project, source2FolderFile, f1);
Set set = new HashSet();
set.add(source2FolderChild);
provider.interceptAdd(new PipelinedShapeModification(source2FolderFile, set));
assertEquals(1, set.size());
PythonFolder c = (PythonFolder) set.iterator().next();
PythonSourceFolder sourceFolder = c.getSourceFolder();
assertTrue(sourceFolder instanceof PythonSourceFolder);
set.clear();
set.add(source2FolderChild);
provider.interceptAdd(new PipelinedShapeModification(source2FolderFile, set));
} finally {
f1.delete();
f.delete();
}
}
use of org.python.pydev.navigator.elements.PythonSourceFolder in project Pydev by fabioz.
the class PythonModelProviderTest method testDontRemoveOtherPluginElements.
public void testDontRemoveOtherPluginElements() throws Exception {
final HashSet<String> pythonPathSet = new HashSet<String>();
pythonPathSet.add(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot/source");
PythonNature nature = createNature(pythonPathSet);
project = new ProjectStub(new File(TestDependent.TEST_PYSRC_NAVIGATOR_LOC + "projroot"), nature);
provider = new PythonModelProvider();
HashSet<Object> currentChildren = new HashSet<Object>();
currentChildren.add("Test");
provider.getPipelinedChildren(project, currentChildren);
assertEquals(1, currentChildren.size());
assertEquals("Test", currentChildren.iterator().next());
Object[] children = provider.getChildren(project);
currentChildren.addAll(Arrays.asList(children));
provider.getPipelinedChildren(project, currentChildren);
// Test + source folder
assertEquals(2, currentChildren.size());
boolean found = false;
for (Object o : currentChildren) {
if ("Test".equals(o)) {
found = true;
} else {
assertTrue(o instanceof PythonSourceFolder);
}
}
if (!found) {
fail("Could not find generated child");
}
}
use of org.python.pydev.navigator.elements.PythonSourceFolder in project Pydev by fabioz.
the class PythonBaseModelProvider method getResourceInPythonModel.
/**
* Given some IResource in the filesystem, return the representation for it in the python model
* or the resource itself if it could not be found in the python model.
*
* Note that this method only returns some resource already created (it does not
* create some resource if it still does not exist)
*/
protected Object getResourceInPythonModel(IResource object, boolean removeFoundResource, boolean returnNullIfNotFound) {
if (DEBUG) {
System.out.println("Getting resource in python model:" + object);
}
Set<PythonSourceFolder> sourceFolders = getProjectSourceFolders(object.getProject());
Object f = null;
PythonSourceFolder sourceFolder = null;
for (Iterator<PythonSourceFolder> it = sourceFolders.iterator(); f == null && it.hasNext(); ) {
sourceFolder = it.next();
if (sourceFolder.getActualObject().equals(object)) {
f = sourceFolder;
} else {
f = sourceFolder.getChild(object);
}
}
if (f == null) {
if (returnNullIfNotFound) {
return null;
} else {
return object;
}
} else {
if (removeFoundResource) {
if (f == sourceFolder) {
sourceFolders.remove(f);
} else {
sourceFolder.removeChild(object);
}
}
}
return f;
}
Aggregations