1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.actions.log; 21 22 import org.netbeans.modules.versioning.system.cvss.CvsVersioningSystem; 23 import org.netbeans.modules.versioning.system.cvss.ExecutorSupport; 24 import org.netbeans.modules.versioning.system.cvss.ClientRuntime; 25 import org.netbeans.modules.versioning.system.cvss.util.CommandDuplicator; 26 import org.netbeans.modules.versioning.system.cvss.util.Utils; 27 import org.netbeans.lib.cvsclient.command.GlobalOptions; 28 import org.netbeans.lib.cvsclient.command.log.RlogCommand; 29 import org.netbeans.lib.cvsclient.command.log.LogInformation; 30 import org.netbeans.lib.cvsclient.admin.AdminHandler; 31 import org.netbeans.lib.cvsclient.event.FileInfoEvent; 32 import org.netbeans.lib.cvsclient.event.MessageEvent; 33 import org.openide.ErrorManager; 34 import org.openide.util.NbBundle; 35 36 import java.util.*; 37 import java.io.File ; 38 import java.io.IOException ; 39 40 45 public class RLogExecutor extends ExecutorSupport { 46 47 private final File localRoot; 48 private boolean failedOnSymbolicLink; 49 50 61 public static RLogExecutor [] splitCommand(RlogCommand cmd, File [] roots, GlobalOptions options) { 62 if (cmd.getDisplayName() == null) cmd.setDisplayName(NbBundle.getMessage(RLogExecutor.class, "MSG_RLogExecutor_CmdDisplayName")); 63 if (options == null) options = CvsVersioningSystem.createGlobalOptions(); 64 65 CvsVersioningSystem cvs = CvsVersioningSystem.getInstance(); 66 AdminHandler ah = cvs.getAdminHandler(); 67 CommandDuplicator cloner = CommandDuplicator.getDuplicator(cmd); 68 69 List executors = new ArrayList(); 70 try { 71 File [][] split = ExecutorSupport.splitByCvsRoot(roots); 72 for (int i = 0; i < split.length; i++) { 73 File [] files = split[i]; 74 GlobalOptions currentOptions = (GlobalOptions) options.clone(); 75 currentOptions.setCVSRoot(Utils.getCVSRootFor(files[0])); 76 String remoteRepository = null; 77 File directory = null; 78 for (int j = 0; j < files.length; j++) { 79 File file = files[j]; 80 File dir = file.isDirectory() ? file : file.getParentFile(); 81 String repository = ah.getRepositoryForDirectory(dir.getAbsolutePath(), "").substring(1); if (remoteRepository == null || remoteRepository.equals(repository)) { 83 remoteRepository = repository; 84 directory = dir; 85 } else { 86 RlogCommand command = (RlogCommand) cloner.duplicate(); 87 command.setModule(remoteRepository); 88 command.setDisplayName(NbBundle.getMessage(RLogExecutor.class, "MSG_RLogExecutor_CmdContext", remoteRepository)); 89 RLogExecutor executor = new RLogExecutor(cvs, command, directory, currentOptions); 90 executors.add(executor); 91 remoteRepository = repository; 92 directory = dir; 93 } 94 } 95 RlogCommand command = (RlogCommand) cloner.duplicate(); 96 command.setModule(remoteRepository); 97 command.setDisplayName(NbBundle.getMessage(RLogExecutor.class, "MSG_RLogExecutor_CmdContext", remoteRepository)); 98 RLogExecutor executor = new RLogExecutor(cvs, command, directory, currentOptions); 99 executors.add(executor); 100 } 101 } catch (IOException e) { 102 ErrorManager.getDefault().notify(e); 103 return new RLogExecutor[0]; 104 } 105 return (RLogExecutor[]) executors.toArray(new RLogExecutor[executors.size()]); 106 } 107 108 private RLogExecutor(CvsVersioningSystem cvs, RlogCommand cmd, File localRoot, GlobalOptions options) { 109 super(cvs, cmd, options); 110 this.localRoot = localRoot; 111 } 112 113 public File getFile() { 114 return localRoot; 115 } 116 117 public void fileInfoGenerated(FileInfoEvent e) { 118 LogInformation information = (LogInformation) e.getInfoContainer(); 119 String remotePath = information.getRepositoryFilename(); 120 File f = remote2local(remotePath); 121 information.setFile(f); 122 super.fileInfoGenerated(e); 123 } 124 125 protected void commandFinished(ClientRuntime.Result result) { 126 } 128 129 136 private File remote2local(String remotePath) { 137 AdminHandler ah = CvsVersioningSystem.getInstance().getAdminHandler(); 138 String repository; 139 try { 140 repository = ah.getRepositoryForDirectory(localRoot.getAbsolutePath(), "").substring(1); } catch (IOException e) { 143 ErrorManager.getDefault().notify(e); 144 return null; 145 } 146 147 int idx = remotePath.indexOf(repository); 148 if (idx == -1) { 149 return null; 150 } 151 idx = remotePath.indexOf('/', idx + repository.length()); 152 if (idx == -1) { 153 return null; 154 } 155 String remoteRelativePath = remotePath.substring(idx); 156 157 idx = remoteRelativePath.indexOf(','); 158 if (idx != -1) { 159 remoteRelativePath = remoteRelativePath.substring(0, idx); 160 } 161 162 idx = remoteRelativePath.lastIndexOf('/'); 163 if (idx != -1 && idx >= 6) { 164 if ("/Attic".equals(remoteRelativePath.substring(idx - 6, idx))) { remoteRelativePath = remoteRelativePath.substring(0, idx - 6) + remoteRelativePath.substring(idx); 166 } 167 } 168 169 return new File (localRoot, remoteRelativePath); 170 } 171 172 public List getLogEntries() { 173 return toRefresh; 174 } 175 176 181 public void messageSent(MessageEvent e) { 182 super.messageSent(e); 183 if (!failedOnSymbolicLink && e.isError()) { 184 String msg = e.getMessage(); 185 failedOnSymbolicLink = msg != null && msg.indexOf("failed assertion `strncmp (repository,") != -1; 186 } 187 } 188 189 public boolean hasFailedOnSymbolicLink() { 190 return failedOnSymbolicLink; 191 } 192 193 198 protected boolean logCommandOutput() { 199 return false; 200 } 201 202 205 protected void report(String title, String prompt, List messages, int type) { 206 if (!failedOnSymbolicLink) super.report(title, prompt, messages, type); 207 } 208 209 } 210 | Popular Tags |