1 19 20 package org.netbeans.modules.versioning.system.cvss.ui.history; 21 22 import org.netbeans.lib.cvsclient.command.log.RlogCommand; 23 import org.netbeans.lib.cvsclient.command.log.LogInformation; 24 import org.netbeans.lib.cvsclient.command.log.LogCommand; 25 import org.netbeans.modules.versioning.system.cvss.ui.actions.log.RLogExecutor; 26 import org.netbeans.modules.versioning.system.cvss.ui.actions.log.LogExecutor; 27 import org.netbeans.modules.versioning.system.cvss.ExecutorGroup; 28 import org.netbeans.modules.versioning.system.cvss.CvsVersioningSystem; 29 import org.netbeans.modules.versioning.system.cvss.ClientRuntime; 30 import org.netbeans.modules.versioning.system.cvss.CvsModuleConfig; 31 import org.netbeans.modules.versioning.system.cvss.util.Utils; 32 33 import java.io.File ; 34 import java.io.IOException ; 35 import java.util.*; 36 import java.text.DateFormat ; 37 import java.text.ParseException ; 38 import java.text.SimpleDateFormat ; 39 import java.net.URL ; 40 import java.net.MalformedURLException ; 41 42 import org.openide.util.NbBundle; 43 import org.openide.windows.OutputListener; 44 import org.openide.windows.OutputEvent; 45 import org.openide.awt.HtmlBrowser; 46 import org.openide.awt.StatusDisplayer; 47 48 53 class SearchExecutor implements Runnable { 54 55 public static final SimpleDateFormat simpleDateFormat = new SimpleDateFormat ("yyyy-MM-dd HH:mm"); 57 private static final SimpleDateFormat fullDateFormat = new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss Z"); private static final DateFormat [] dateFormats = new DateFormat [] { 59 fullDateFormat, 60 new SimpleDateFormat ("yyyy-MM-dd HH:mm:ss"), simpleDateFormat, 62 new SimpleDateFormat ("yyyy-MM-dd"), }; 64 65 68 private static Set misconfiguredServers = Collections.synchronizedSet(new HashSet()); 69 70 private final SearchHistoryPanel master; 71 private File [] folders; 72 private File [] files; 73 private final SearchCriteriaPanel criteria; 74 75 private List results = new ArrayList(); 76 77 public SearchExecutor(SearchHistoryPanel master) { 78 this.master = master; 79 File [] roots = master.getRoots(); 80 81 Set printedWarnings = new HashSet(1); 82 Set foldersSet = new HashSet(roots.length); 83 Set filesSet = new HashSet(roots.length); 84 for (int i = 0; i < roots.length; i++) { 85 File root = roots[i]; 86 boolean isMisconfiguredServer = false; 87 try { 88 String cvsRoot = Utils.getCVSRootFor(root); 89 isMisconfiguredServer = misconfiguredServers.contains(cvsRoot); 90 if (root.isDirectory() && isMisconfiguredServer && printedWarnings.add(cvsRoot)) { 91 showMisconfiguredServerWarning(cvsRoot); 92 } 93 } catch (IOException e) { 94 } 96 if (root.isFile() || isMisconfiguredServer) { 97 filesSet.add(root); 98 } else { 99 foldersSet.add(root); 100 } 101 } 102 files = (File []) filesSet.toArray(new File [filesSet.size()]); 103 folders = (File []) foldersSet.toArray(new File [foldersSet.size()]); 104 criteria = master.getCriteria(); 105 } 106 107 public void run() { 108 String from = criteria.getFrom(); 109 String to = criteria.getTo(); 110 Date fromDate = parseDate(from); 111 Date toDate = parseDate(to); 112 113 RlogCommand rcmd = new RlogCommand(); 114 LogCommand lcmd = new LogCommand(); 115 116 if (fromDate != null || toDate != null) { 117 String dateFilter = ""; if (fromDate != null) { 119 dateFilter = fullDateFormat.format(fromDate); 120 } 121 dateFilter += "<="; if (toDate != null) { 123 dateFilter += fullDateFormat.format(toDate); 124 } 125 rcmd.setDateFilter(dateFilter); 126 lcmd.setDateFilter(dateFilter); 127 } else if (from != null || to != null) { 128 String revFilter = ""; if (from != null) { 130 revFilter = from; 131 } 132 revFilter += ":"; if (to != null) { 134 revFilter += to; 135 } 136 rcmd.setRevisionFilter(revFilter); 137 lcmd.setRevisionFilter(revFilter); 138 } 139 140 rcmd.setNoTags(!CvsModuleConfig.getDefault().getPreferences().getBoolean(CvsModuleConfig.PROP_SEARCHHISTORY_FETCHTAGS, true)); 141 lcmd.setNoTags(!CvsModuleConfig.getDefault().getPreferences().getBoolean(CvsModuleConfig.PROP_SEARCHHISTORY_FETCHTAGS, true)); 142 rcmd.setUserFilter(criteria.getUsername()); 143 lcmd.setUserFilter(criteria.getUsername()); 144 145 ExecutorGroup group = new ExecutorGroup(NbBundle.getMessage(SearchExecutor.class, "BK0001"), false); RLogExecutor [] rexecutors; 147 if (folders.length > 0) { 148 rexecutors = RLogExecutor.splitCommand(rcmd, folders, null); 149 } else { 150 rexecutors = new RLogExecutor[0]; 151 } 152 group.addExecutors(rexecutors); 153 154 LogExecutor [] lexecutors; 155 if (files.length > 0) { 156 lcmd.setFiles(files); 157 lexecutors = LogExecutor.splitCommand(lcmd, null); 158 } else { 159 lexecutors = new LogExecutor[0]; 160 } 161 group.addExecutors(lexecutors); 162 163 final RLogExecutor [] frexecutors = rexecutors; 164 final LogExecutor [] flexecutors = lexecutors; 165 Runnable action = new Runnable () { 166 public void run() { 167 List newResults = processResults(frexecutors, flexecutors); 168 results.addAll(newResults); 169 if (testForRLogFailures(frexecutors)) { 170 SearchExecutor.this.run(); 171 return; 172 } 173 master.setResults(results); 174 } 175 }; 176 group.addBarrier(action); 177 group.execute(); 178 179 } 180 181 private boolean testForRLogFailures(RLogExecutor[] executors) { 182 Set failedFiles = new HashSet(); 183 Set printedWarnings = new HashSet(1); 184 for (int i = 0; i < executors.length; i++) { 185 RLogExecutor executor = executors[i]; 186 if (executor.hasFailedOnSymbolicLink()) { 187 try { 188 String cvsRoot = Utils.getCVSRootFor(executor.getFile()); 189 if (printedWarnings.add(cvsRoot)) { 190 showMisconfiguredServerWarning(cvsRoot); 191 } 192 misconfiguredServers.add(cvsRoot); 193 } catch (IOException e) { 194 } 196 failedFiles.add(executor.getFile()); 197 } 198 } 199 if (failedFiles.size() > 0) { 200 files = (File []) failedFiles.toArray(new File [failedFiles.size()]); 201 folders = new File [0]; 202 return true; 203 } else { 204 return false; 205 } 206 } 207 208 private void showMisconfiguredServerWarning(String cvsRoot) { 209 final String relNotesUrl = "http://javacvs.netbeans.org/release/5.0"; ClientRuntime runtime = CvsVersioningSystem.getInstance().getClientRuntime(cvsRoot); 211 runtime.log(NbBundle.getMessage(SearchExecutor.class, "MSG_SymlinkWarning1") + "\n", null); runtime.log(NbBundle.getMessage(SearchExecutor.class, "MSG_SymlinkWarning2", relNotesUrl) + "\n", new OutputListener() { public void outputLineSelected(OutputEvent ev) { 214 } 215 216 public void outputLineAction(OutputEvent ev) { 217 try { 218 HtmlBrowser.URLDisplayer.getDefault().showURL(new URL (relNotesUrl)); 219 } catch (MalformedURLException e) { 220 } 222 } 223 224 public void outputLineCleared(OutputEvent ev) { 225 } 226 }); 227 StatusDisplayer.getDefault().setStatusText(NbBundle.getMessage(SearchExecutor.class, "MSG_StatusSymlinkWarning")); } 229 230 private List processResults(RLogExecutor[] rexecutors, LogExecutor[] lexecutors) { 231 List log = new ArrayList(200); 232 for (int i = 0; i < rexecutors.length; i++) { 233 RLogExecutor executor = rexecutors[i]; 234 log.addAll(executor.getLogEntries()); 235 } 236 for (int i = 0; i < lexecutors.length; i++) { 237 LogExecutor executor = lexecutors[i]; 238 log.addAll(executor.getLogEntries()); 239 } 240 String commitMessage = criteria.getCommitMessage(); 241 242 List newResults = new ArrayList(log.size()); 243 for (Iterator i = log.iterator(); i.hasNext();) { 244 LogInformation info = (LogInformation) i.next(); 245 newResults.addAll(info.getRevisionList()); 246 } 247 248 if (commitMessage != null) { 249 for (Iterator i = newResults.iterator(); i.hasNext();) { 250 LogInformation.Revision revision = (LogInformation.Revision) i.next(); 251 String msg = revision.getMessage(); 252 if (msg.indexOf(commitMessage) == -1) { 253 i.remove(); 254 } 255 } 256 } 257 258 return newResults; 259 } 260 261 private Date parseDate(String s) { 262 if (s == null) return null; 263 for (int i = 0; i < dateFormats.length; i++) { 264 DateFormat dateformat = dateFormats[i]; 265 try { 266 return dateformat.parse(s); 267 } catch (ParseException e) { 268 } 270 } 271 return null; 272 } 273 274 } 275 | Popular Tags |