KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > changelog > ChangeLogDisplayer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.changelog;
22
23 /**
24  *
25  * @author Milos Kleint, ralph krueger
26  */

27 import org.netbeans.modules.javacvs.events.CommandDisplayerAdapter;
28 import org.netbeans.modules.javacvs.commands.*;
29 import org.netbeans.modules.cvsclient.*;
30
31 import org.apache.regexp.RE;
32 import org.apache.regexp.RESyntaxException;
33
34
35 import org.netbeans.lib.cvsclient.command.DefaultFileInfoContainer;
36 import org.netbeans.lib.cvsclient.command.FileInfoContainer;
37 import org.netbeans.lib.cvsclient.command.log.LogInformation;
38 import java.util.*;
39 import java.io.*;
40 import org.openide.filesystems.*;
41 import org.openide.*;
42 import org.openide.loaders.*;
43 import org.openide.util.*;
44 import javax.swing.*;
45 import java.awt.Dialog JavaDoc;
46 import java.awt.event.*;
47
48 public class ChangeLogDisplayer extends CommandDisplayerAdapter {
49     
50     private static final String JavaDoc INITIAL_REV = "Initial revision"; //NOI18N
51
private static final String JavaDoc WAS_ADDED_ON_BRANCH = "was initially added on branch"; //NOI18N
52

53     private int commandCount = 0;
54     private int finishedCommandCount = 0;
55     private long revisionsNumber = 0;
56     private boolean errorsOccured = false;
57     
58     private HashMap fileObjectMap;
59     
60     private RE messageRE = null;
61     
62     private ChangeLogProcessor processor;
63     
64     /** Creates new ChangeLogDisplayer */
65     public ChangeLogDisplayer(ChangeLogProcessor proces) {
66         fileObjectMap = new HashMap(10);
67         processor = proces;
68     }
69     
70     
71     /**
72      * adds fileobjects to a map of selected fileobjects for this action.
73      * Is needed to convert correctly the resulting files back to
74      * fileobjects.
75      */

76     public void addFileObjects(FileObject[] fos) {
77         if (fos != null) {
78             for (int i=0; i < fos.length; i++) {
79                 File file = FileSystemCommand.toFile(fos[i]);
80                 if (file != null) {
81                     fileObjectMap.put(file, fos[i]);
82                 }
83             }
84         }
85     }
86
87     public synchronized void setNumberOfCommands(int number) {
88         commandCount = number;
89     }
90     
91     public int getNumberOfCommand() {
92         return commandCount;
93     }
94     
95     
96     public synchronized void showFinishedCommand() {
97 // System.out.println("finished 1 status command..");
98
finishedCommandCount = finishedCommandCount + 1;
99         if (finishedCommandCount == commandCount) {
100             showDialog();
101         }
102     }
103     
104     public synchronized void showExecutionFailed(Exception JavaDoc exception) {
105         errorsOccured = true;
106         System.out.println("exc=" + exception);
107         exception.printStackTrace();
108         finishedCommandCount = finishedCommandCount + 1;
109         if (finishedCommandCount == commandCount) {
110             showDialog();
111         }
112     }
113
114     public synchronized void showStartCommand() {
115         
116     }
117     
118     private java.util.List JavaDoc extractBranches(LogInformation info) {
119         LinkedList list = new LinkedList();
120         if (info.getAllSymbolicNames() != null) {
121             Iterator it = info.getAllSymbolicNames().iterator();
122             while (it.hasNext()) {
123                 LogInformation.SymName name = (LogInformation.SymName)it.next();
124                 // performance related condition??
125
if (name.getRevision().indexOf(".0") > 0) {
126                     int[] arr = ChangeLogUtils.convertRevisionToIntArray(name.getRevision());
127                     if (arr[arr.length - 2] == 0) {
128                         // needs to be performance improved!!!!
129

130                         name.setRevision(ChangeLogUtils.convertIntArrayToRevision(arr).intern());
131                         list.add(name);
132                     }
133                 }
134             }
135         }
136         return list;
137     }
138     
139     public synchronized void showFileInfoGenerated(FileInfoContainer info) {
140         if (info.getClass().equals(LogInformation.class)) {
141             LogInformation lInfo = (LogInformation)info;
142             LogInfoRevision.LogInfoHeader header = createHeader(lInfo);
143             List branchList = extractBranches(lInfo);
144             boolean include = true;
145             Iterator it =lInfo.getRevisionList().iterator();
146             while (it.hasNext()) {
147                 include = true;
148                 LogInformation.Revision rev = (LogInformation.Revision)it.next();
149                 // don't include revision 1.1 created on background when
150
// the file is added on the branch..
151
if (rev.getState() != null &&
152                     rev.getMessage() != null &&
153                     rev.getNumber() != null &&
154                     rev.getState().equals("dead") && //NOI18N
155
rev.getNumber().equals("1.1") && //NOI18N
156
rev.getMessage().indexOf(WAS_ADDED_ON_BRANCH) > 0) {
157                         continue;
158                 }
159                 // don't include the revision created during import command.
160
// not sure if the condition here is bulletproof.
161
if (rev.getMessage() != null &&
162                     rev.getNumber() != null &&
163                     rev.getNumber().equals("1.1") && //NOI18N
164
rev.getMessage().indexOf(INITIAL_REV) >= 0) {
165                         continue;
166                 }
167                 if (processor.messageMatchesFilterPattern(rev.getMessage())) {
168                     LogInfoRevision revision = createRevision(rev, header);
169                     revision.setBranch(findBranchInSymNamesList(branchList, revision.getNumber()));
170                     processor.addRevision(revision, rev.getMessage());
171                 }
172             }
173         }
174     }
175
176     /**
177      * TODO:
178      * can be optimized by first sorting from longest to shortest branch number..
179      */

180     private String JavaDoc findBranchInSymNamesList(List list, String JavaDoc revisionNumber) {
181         Iterator it = list.iterator();
182         if (revisionNumber.indexOf('.') == revisionNumber.lastIndexOf('.')) {
183             return null;
184         }
185         String JavaDoc branch = null;
186         String JavaDoc longestMatch = "";
187         while (it.hasNext()) {
188             LogInformation.SymName name = (LogInformation.SymName)it.next();
189             if (revisionNumber.startsWith(name.getRevision())) {
190                 if (name.getRevision().length() > longestMatch.length()) {
191                     branch = name.getName();
192                     longestMatch = name.getRevision();
193                 }
194             }
195         }
196         return branch;
197     }
198     
199     private void showDialog() {
200         processor.finishProcessing();
201     }
202     
203     
204     
205     
206     private LogInfoRevision.LogInfoHeader createHeader(LogInformation info) {
207         LogInfoRevision.LogInfoHeader header = new LogInfoRevision.LogInfoHeader();
208         header.setAccessList(info.getAccessList());
209         header.setBranch(info.getBranch());
210         header.setDescription(info.getDescription());
211         header.setFile(info.getFile());
212         header.setHeadRevision(info.getHeadRevision());
213         header.setKeywordSubstitution(info.getKeywordSubstitution());
214         header.setLocks(info.getLocks());
215         header.setRepositoryFilename(info.getRepositoryFilename());
216         header.setSelectedRevisions(info.getSelectedRevisions());
217         header.setTotalRevisions(info.getTotalRevisions());
218         return header;
219     }
220     
221     private LogInfoRevision createRevision(LogInformation.Revision jcvsRev,
222                                            LogInfoRevision.LogInfoHeader header) {
223         LogInfoRevision rev = new LogInfoRevision(header.getFile());
224         rev.setAuthor(jcvsRev.getAuthor());
225 // rev.setBranches(jcvsRev.getBranches());
226
rev.setDate(jcvsRev.getDate());
227         rev.setLines(jcvsRev.getLines());
228         rev.setLogInfoHeader(header);
229         rev.setNumber(jcvsRev.getNumber());
230         rev.setState(jcvsRev.getState());
231         return rev;
232     }
233         
234 }
235
Popular Tags