1 11 package org.eclipse.team.internal.ccvs.core.client; 12 13 14 import java.util.HashSet ; 15 import java.util.Iterator ; 16 import java.util.Set ; 17 18 import org.eclipse.team.internal.ccvs.core.CVSException; 19 import org.eclipse.team.internal.ccvs.core.ICVSFile; 20 import org.eclipse.team.internal.ccvs.core.ICVSFolder; 21 import org.eclipse.team.internal.ccvs.core.ICVSResource; 22 import org.eclipse.team.internal.ccvs.core.ICVSResourceVisitor; 23 24 29 public class PruneFolderVisitor implements ICVSResourceVisitor { 30 31 private ICVSFolder localRoot; 32 33 public PruneFolderVisitor() { 34 } 35 36 39 public void visit(Session s, ICVSResource[] resources) throws CVSException { 40 visit(s.getLocalRoot(), resources); 41 } 42 43 46 public void visit(ICVSFolder root, ICVSResource[] resources) throws CVSException { 47 localRoot = root; 48 49 Set prunableParents = new HashSet (); 51 for (int i = 0; i < resources.length; i++) { 52 ICVSResource cvsResource = resources[i]; 53 cvsResource.accept(this); 55 if (!cvsResource.exists()) 57 prunableParents.add(cvsResource.getParent()); 58 } 59 for (Iterator iter = prunableParents.iterator(); iter.hasNext();) { 60 ICVSFolder cvsFolder = (ICVSFolder)iter.next(); 61 pruneFolderAndParentsIfAppropriate(cvsFolder); 62 } 63 } 64 67 public void visitFile(ICVSFile file) throws CVSException { 68 } 70 71 74 public void visitFolder(ICVSFolder folder) throws CVSException { 75 folder.acceptChildren(this); 77 pruneFolderIfAppropriate(folder); 79 } 80 81 private void pruneFolderIfAppropriate(ICVSFolder folder) throws CVSException { 82 if (folder.exists() && folder.isManaged() 84 && ! folder.equals(getLocalRoot()) 85 && folder.members(ICVSFolder.ALL_EXISTING_MEMBERS).length == 0) { 86 87 folder.delete(); 89 } 90 } 91 92 private ICVSFolder getLocalRoot() { 93 return localRoot; 94 } 95 96 99 private void pruneFolderAndParentsIfAppropriate(ICVSFolder folder) throws CVSException { 100 pruneFolderIfAppropriate(folder); 101 if (!folder.exists()) { 102 ICVSFolder parent = folder.getParent(); 103 pruneFolderAndParentsIfAppropriate(parent); 104 } 105 } 106 } 107 | Popular Tags |