1 22 package org.netbeans.lib.cvsclient.command.remove; 23 24 import java.io.*; 25 26 import org.netbeans.lib.cvsclient.*; 27 import org.netbeans.lib.cvsclient.admin.*; 28 import org.netbeans.lib.cvsclient.command.*; 29 import org.netbeans.lib.cvsclient.connection.*; 30 import org.netbeans.lib.cvsclient.event.*; 31 import org.netbeans.lib.cvsclient.request.*; 32 import org.netbeans.lib.cvsclient.util.*; 33 34 39 public class RemoveCommand extends BasicCommand { 40 43 private boolean deleteBeforeRemove; 44 45 private boolean ignoreLocallyExistingFiles; 46 47 50 public boolean isDeleteBeforeRemove() { 51 return deleteBeforeRemove; 52 } 53 54 57 public void setDeleteBeforeRemove(boolean deleteBeforeRemove) { 58 this.deleteBeforeRemove = deleteBeforeRemove; 59 } 60 61 67 public boolean doesIgnoreLocallyExistingFiles() { 68 return ignoreLocallyExistingFiles; 69 } 70 71 76 public boolean isIgnoreLocallyExistingFiles() { 77 return ignoreLocallyExistingFiles; 78 } 79 80 85 public void setIgnoreLocallyExistingFiles(boolean ignoreLocallyExistingFiles) { 86 this.ignoreLocallyExistingFiles = ignoreLocallyExistingFiles; 87 } 88 89 94 public Builder createBuilder(EventManager eventMan) { 95 return new RemoveBuilder(eventMan, this); 96 } 97 98 105 public void execute(ClientServices client, EventManager em) 106 throws CommandException, AuthenticationException { 107 if (files == null || files.length == 0) { 108 throw new CommandException("No files have been specified for " + "removal.", CommandException.getLocalMessage("RemoveCommand.noFilesSpecified", null)); } 111 112 client.ensureConnection(); 113 114 if (isDeleteBeforeRemove()) { 115 removeAll(files); 116 } 117 super.execute(client, em); 118 119 try { 120 addRequestForWorkingDirectory(client); 121 addArgumentRequests(); 122 addRequest(CommandRequest.REMOVE); 123 124 client.processRequests(requests); 125 } 126 catch (CommandException ex) { 127 throw ex; 128 } 129 catch (Exception ex) { 130 throw new CommandException(ex, ex.getLocalizedMessage()); 131 } 132 finally { 133 requests.clear(); 134 } 135 } 136 137 protected void sendEntryAndModifiedRequests(Entry entry, File file) { 138 super.sendEntryAndModifiedRequests(entry, 139 isIgnoreLocallyExistingFiles() ? null : file); 140 if (entry.getRevision().equals("0")) { 141 try { 143 clientServices.removeEntry(file); 144 } catch (IOException exc) { 145 BugLog.getInstance().showException(exc); 146 } 147 148 } 149 } 150 151 157 public String getCVSCommand() { 158 StringBuffer toReturn = new StringBuffer ("remove "); toReturn.append(getCVSArguments()); 160 File[] files = getFiles(); 161 if (files != null) { 162 for (int index = 0; index < files.length; index++) { 163 toReturn.append(files[index].getName() + " "); } 165 } 166 return toReturn.toString(); 167 } 168 169 174 public boolean setCVSCommand(char opt, String optArg) { 175 if (opt == 'l') { 176 setRecursive(false); 177 } 178 else if (opt == 'R') { 179 setRecursive(true); 180 } 181 else if (opt == 'f') { 182 setDeleteBeforeRemove(true); 183 } 184 else { 185 return false; 186 } 187 return true; 188 } 189 190 196 private void removeAll(File[] filesToDel) 197 throws CommandException { 198 if (filesToDel == null) { 199 return; 200 } 201 for (int index = 0; index < filesToDel.length; index++) { 202 File file = filesToDel[index]; 203 if (file.exists() && file.isFile()) { 204 if (!file.delete()) { 205 throw new CommandException("Cannot delete file " + file.getAbsolutePath(), CommandException.getLocalMessage("RemoveCommand.cannotDelete", new Object []{file.getAbsolutePath()})); } 208 } 209 else { 210 if (isRecursive() && 213 !file.getName().equalsIgnoreCase("CVS")) { removeAll(file.listFiles()); 215 } 216 } 217 } 218 } 219 220 223 public String getOptString() { 224 return "flR"; } 226 227 231 public void resetCVSCommand() { 232 setRecursive(true); 233 setDeleteBeforeRemove(false); 234 } 235 236 240 public String getCVSArguments() { 241 StringBuffer toReturn = new StringBuffer (""); if (!isRecursive()) { 243 toReturn.append("-l "); } 245 if (isDeleteBeforeRemove()) { 246 toReturn.append("-f "); } 248 return toReturn.toString(); 249 } 250 } 251 | Popular Tags |