Search in sources :

Example 6 with PythonSourceFolder

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]);
}
Also used : PythonNature(org.python.pydev.plugin.nature.PythonNature) File(java.io.File) PythonSourceFolder(org.python.pydev.navigator.elements.PythonSourceFolder) HashSet(java.util.HashSet)

Example 7 with PythonSourceFolder

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();
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) IWorkingSet(org.eclipse.ui.IWorkingSet) PythonNature(org.python.pydev.plugin.nature.PythonNature) PythonFolder(org.python.pydev.navigator.elements.PythonFolder) FolderStub(org.python.pydev.shared_core.resource_stubs.FolderStub) PythonSourceFolder(org.python.pydev.navigator.elements.PythonSourceFolder) PipelinedShapeModification(org.eclipse.ui.navigator.PipelinedShapeModification) File(java.io.File) HashSet(java.util.HashSet)

Example 8 with PythonSourceFolder

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();
    }
}
Also used : HashSet(java.util.HashSet) Set(java.util.Set) IWorkingSet(org.eclipse.ui.IWorkingSet) PythonNature(org.python.pydev.plugin.nature.PythonNature) PythonFolder(org.python.pydev.navigator.elements.PythonFolder) FolderStub(org.python.pydev.shared_core.resource_stubs.FolderStub) PythonSourceFolder(org.python.pydev.navigator.elements.PythonSourceFolder) PipelinedShapeModification(org.eclipse.ui.navigator.PipelinedShapeModification) File(java.io.File) HashSet(java.util.HashSet)

Example 9 with PythonSourceFolder

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");
    }
}
Also used : PythonNature(org.python.pydev.plugin.nature.PythonNature) File(java.io.File) PythonSourceFolder(org.python.pydev.navigator.elements.PythonSourceFolder) HashSet(java.util.HashSet)

Example 10 with PythonSourceFolder

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;
}
Also used : PythonSourceFolder(org.python.pydev.navigator.elements.PythonSourceFolder)

Aggregations

PythonSourceFolder (org.python.pydev.navigator.elements.PythonSourceFolder)17 PythonNature (org.python.pydev.plugin.nature.PythonNature)10 HashSet (java.util.HashSet)9 IProject (org.eclipse.core.resources.IProject)8 IFolder (org.eclipse.core.resources.IFolder)6 IWorkingSet (org.eclipse.ui.IWorkingSet)6 IWrappedResource (org.python.pydev.navigator.elements.IWrappedResource)6 File (java.io.File)5 Set (java.util.Set)5 IContainer (org.eclipse.core.resources.IContainer)5 IResource (org.eclipse.core.resources.IResource)5 PythonFolder (org.python.pydev.navigator.elements.PythonFolder)5 IFile (org.eclipse.core.resources.IFile)4 PythonProjectSourceFolder (org.python.pydev.navigator.elements.PythonProjectSourceFolder)4 IPath (org.eclipse.core.runtime.IPath)3 PipelinedShapeModification (org.eclipse.ui.navigator.PipelinedShapeModification)3 FolderStub (org.python.pydev.shared_core.resource_stubs.FolderStub)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 IPythonNature (org.python.pydev.core.IPythonNature)2