| package org.eclipse.wtp.releng.cvslog.tools; |
| |
| import java.util.ArrayList; |
| import java.util.HashMap; |
| import java.util.Iterator; |
| import java.util.List; |
| import java.util.Map; |
| import java.util.Set; |
| import java.util.StringTokenizer; |
| import java.util.TreeSet; |
| |
| import org.eclipse.wtp.releng.cvstools.Bug; |
| import org.eclipse.wtp.releng.cvstools.BugLogDocument; |
| import org.eclipse.wtp.releng.cvstools.Delta; |
| import org.eclipse.wtp.releng.cvstools.RlogDocument; |
| import org.eclipse.wtp.releng.cvstools.RevisionDocument.Revision; |
| import org.eclipse.wtp.releng.cvstools.RlogDocument.Rlog; |
| |
| public class CVSBugLog { |
| |
| /** |
| * seperator beetween target milestones and statuses of the wtp |
| */ |
| private static final String SEPERATOR = ","; |
| |
| private Map targetMileStones = new HashMap(); |
| |
| private Map statuses = new HashMap(); |
| |
| private RlogDocument rlogDocument; |
| |
| private String fromBuild; |
| |
| private String toBuild; |
| |
| public String getFromBuild() { |
| return fromBuild; |
| } |
| |
| public void setFromBuild(String fromBuild) { |
| this.fromBuild = fromBuild; |
| } |
| |
| public String getToBuild() { |
| return toBuild; |
| } |
| |
| public void setToBuild(String toBuild) { |
| this.toBuild = toBuild; |
| } |
| |
| public Map getStatuses() { |
| return statuses; |
| } |
| |
| public void setStatuses(Map statuses) { |
| this.statuses = statuses; |
| } |
| |
| public Map getTargetMileStones() { |
| return targetMileStones; |
| } |
| |
| public void setTargetMileStones(Map targetMileStones) { |
| this.targetMileStones = targetMileStones; |
| } |
| |
| /** |
| * target milestones string is parsed and each target milestone is put in to the map |
| * |
| * @param string target milestones to be parsed |
| */ |
| public void setTargetMileStones(String string) { |
| StringTokenizer tokenizer = new StringTokenizer(string, SEPERATOR); |
| |
| while (tokenizer.hasMoreTokens()) { |
| Object object = tokenizer.nextToken(); |
| targetMileStones.put(object, object); |
| } |
| |
| } |
| /** |
| * bug statuses string is parsed and each status is put in to the map |
| * |
| * @param string bug statuses to be parsed |
| */ |
| public void setStatuses(String string) { |
| StringTokenizer tokenizer = new StringTokenizer(string, SEPERATOR); |
| |
| while (tokenizer.hasMoreTokens()) { |
| Object object = tokenizer.nextToken(); |
| statuses.put(object, object); |
| } |
| } |
| |
| public void setRlogDocument(RlogDocument rlogDocument) { |
| this.rlogDocument = rlogDocument; |
| } |
| |
| /** |
| * rlogDocument is traversed to prepare the set of bug nos,first deltas in document |
| * and then revisons in deltas are traversed for unique bug nos |
| * |
| * @return unique bug no set |
| */ |
| public Set filterRlogDocmentAndGetUniqueBugNos() { |
| Set uniqueBugNos = new TreeSet(); |
| Rlog rlog = rlogDocument.getRlog(); |
| Delta[] deltas = rlog.getCvsdeltaArray(); |
| boolean bStatus; |
| boolean bTarget; |
| |
| for (int i = 0; i < deltas.length; i++) { |
| Revision[] revisions = deltas[i].getRevisionArray(); |
| |
| for (int j = 0; j < revisions.length; j++) { |
| Revision revision = revisions[j]; |
| String targetMileStone = revision.getBugzillaTargetMilestone(); |
| String status = revision.getBugzillaStatus(); |
| |
| /*status of bug may be omitted according to status parameter value*/ |
| if (checkStatus()) |
| bStatus = statuses.containsKey(status); |
| else |
| bStatus = true; |
| |
| bTarget = targetMileStones.containsKey(targetMileStone); |
| /*both targer milesstone and status should match*/ |
| if (bStatus && bTarget) { |
| String bugNo = revision.getBugzilla(); |
| try { |
| Integer.parseInt(bugNo); |
| uniqueBugNos.add(bugNo); |
| } catch (Exception e) { |
| //BugzillaUtil.consoleLogBug("NoBugFound["+bugNo+"]"); |
| } |
| } |
| } |
| } |
| return uniqueBugNos; |
| } |
| |
| |
| public boolean checkStatus() { |
| return (!statuses.containsKey("-")); |
| } |
| /** |
| * parses rlog document for certain target milestones and for certain statuses |
| * |
| * @param rlogDocument to be parsed |
| * @param target milestones to be searched |
| * @param statuses(camma delimitted) of bug to be searched |
| * @return buglogdocument |
| */ |
| public BugLogDocument getBugLog(RlogDocument rlogDocument, String target,String status) { |
| this.rlogDocument = rlogDocument; |
| BugLogDocument bugLogDocument = BugLogDocument.Factory.newInstance(); |
| bugLogDocument.addNewBugLog(); |
| bugLogDocument.getBugLog().setStatus(status); |
| bugLogDocument.getBugLog().setTarget(target); |
| bugLogDocument.getBugLog().setFromBuild(getFromBuild()); |
| bugLogDocument.getBugLog().setToBuild(getToBuild()); |
| setTargetMileStones(target); |
| setStatuses(status); |
| |
| Iterator stIterator = statuses.keySet().iterator(); |
| while (stIterator.hasNext()) { |
| String st = (String) stIterator.next(); |
| Trace.trace(Trace.FINEST,"\nIncluding bugs with status:" + st ); |
| } |
| stIterator = targetMileStones.keySet().iterator(); |
| while (stIterator.hasNext()) { |
| String st = (String) stIterator.next(); |
| Trace.trace(Trace.FINEST,"\nIncluding bugs with target:" + st ); |
| } |
| |
| Set bugNos = filterRlogDocmentAndGetUniqueBugNos(); |
| |
| Iterator it = bugNos.iterator(); |
| |
| while (it.hasNext()) { |
| String bugNo = (String) it.next(); |
| addNewBug(bugNo, bugLogDocument.getBugLog().addNewBugs()); |
| } |
| |
| return bugLogDocument; |
| } |
| |
| /** |
| * adds single bug to the bugLogDocument that mathces target milestones and status |
| * bug's deltas and revisons are read from rlogDocument and new bug is prepared |
| * from these datas |
| * @param bugNo |
| * @param bug |
| */ |
| private void addNewBug(String bugNo, Bug bug) { |
| Delta[] deltas = rlogDocument.getRlog().getCvsdeltaArray(); |
| boolean isBugPropertiesSet = false; |
| |
| for (int i = 0; i < deltas.length; i++) { |
| CVSDelta cvsDelta = new CVSDelta(); |
| Delta delta = deltas[i]; |
| cvsDelta.branch = delta.getBranch().getDomNode().getNodeValue(); |
| cvsDelta.file = delta.getFile(); |
| cvsDelta.folder = ""; |
| cvsDelta.head = delta.getHead(); |
| |
| Revision[] deltaRevisions = delta.getRevisionArray(); |
| |
| for (int j = 0; j < deltaRevisions.length; j++) { |
| |
| Revision revision = deltaRevisions[j]; |
| String bugzillaNo = revision.getBugzilla(); |
| |
| if (bugzillaNo != null) { |
| if (bugzillaNo.equals(bugNo)) { |
| CVSRevision cvsRevision = new CVSRevision(); |
| cvsRevision.author = revision.getAuthor(); |
| cvsRevision.comment = revision.getBugzillaSummary(); |
| cvsRevision.stringDate = revision.getDate(); |
| cvsRevision.rev = revision.getRev(); |
| cvsRevision.bugNo = bugNo; |
| List revisions = new ArrayList(); |
| revisions.add(cvsRevision); |
| cvsDelta.setRevisions(revisions); |
| cvsDelta.toXML(bug.addNewDelta()); |
| bug.setNo(bugNo); |
| if(!isBugPropertiesSet){ |
| bug.setStatus(revision.getBugzillaStatus()); |
| bug.setSummary(revision.getBugzillaSummary()); |
| isBugPropertiesSet = true; |
| } |
| break; |
| } |
| } |
| } |
| } |
| } |
| } |