KickJava   Java API By Example, From Geeks To Geeks.

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


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 Ralph Krueger.
17  */

18
19 package org.netbeans.modules.changelog;
20
21
22 import java.util.*;
23 import org.openide.windows.*;
24 import org.openide.*;
25 import java.io.*;
26
27 /**
28  * prints the processed groups to text file..
29  * @author ralph
30  */

31 public class LogPrinter_Text implements LogPrinter {
32
33     private java.io.PrintWriter JavaDoc writer;
34     private boolean includeSummary;
35
36     public LogPrinter_Text(File file) {
37         if (!file.exists()) {
38             try {
39                 if (file.getParentFile() != null) {
40                     file.getParentFile().mkdirs();
41                 }
42                 file.createNewFile();
43             } catch (IOException exc) {
44                  org.openide.ErrorManager.getDefault().notify(exc);
45                  System.out.println("error while creating file..");
46             }
47         }
48         writer = null;
49         try {
50             writer = new PrintWriter(new FileOutputStream(file));
51         } catch (IOException exc) {
52                  org.openide.ErrorManager.getDefault().notify(exc);
53                  System.out.println("error while opening file..");
54         }
55     }
56     
57     public void printHeader(ChangeLogProcessor processor) {
58         if (writer == null) {
59             return;
60         }
61         includeSummary = processor.isIncludeSummary();
62         if (processor.isIncludeQueryDescription()) {
63             writer.println("Query:");
64             if (processor.getDateRange() != null) {
65                 writer.println(" Date Range:" + processor.getDateRange());
66             }
67             if (processor.getRevisionRange() != null) {
68                 writer.println(" Revision Filter:" + processor.getRevisionRange());
69             }
70             if (processor.getMessageFilter() != null) {
71                 String JavaDoc messageType = "";
72                 if (processor.getMessageFilterType() == ChangeLogProcessor.MESSAGE_FILTER_SUBSTRING) {
73                     messageType = "Substring";
74                 } else if (processor.getMessageFilterType() == ChangeLogProcessor.MESSAGE_FILTER_SOME_WORDS) {
75                     messageType = "Any of words";
76                 } else if (processor.getMessageFilterType() == ChangeLogProcessor.MESSAGE_FILTER_ALL_WORDS) {
77                     messageType = "All of words";
78                 } else if (processor.getMessageFilterType() == ChangeLogProcessor.MESSAGE_FILTER_REGEXP) {
79                     messageType = "Regular expression";
80                 }
81                 writer.println(" Message Filter (" + messageType + "):" + processor.getMessageFilter());
82             }
83             if (processor.getFileFilter() != null) {
84                 String JavaDoc fileType = "";
85                 if (processor.getFileFilterType() == ChangeLogProcessor.FILE_FILTER_SUBSTRING) {
86                     fileType = "Substring";
87                 } else if (processor.getFileFilterType() == ChangeLogProcessor.FILE_FILTER_REGEXP) {
88                     fileType = "Regular expression";
89                 }
90                 writer.println(" Contained Files Filter (" + fileType + "):" + processor.getFileFilter());
91             }
92             if (processor.getSortMode() == ChangeLogProcessor.SORT_BY_DATE) {
93                 writer.print(" Sort: by Date");
94             } else if (processor.getSortMode() == ChangeLogProcessor.SORT_BY_USER) {
95                 writer.print(" Sort: by User");
96             }
97             if (processor.isDescendingSort()) {
98                 writer.println(" (Descending)");
99             } else {
100                 writer.println(" (Ascending)");
101             }
102             writer.println();
103             writer.println();
104         }
105     }
106     
107     public void printGroupHeader(RevisionsGroup group) {
108         if (writer == null) {
109             return;
110         }
111           writer.println("--------------------------------------------------");
112           writer.println("User: " + group.getUser());
113           writer.println("Date: " + group.getStartingDate());
114           writer.println("Message:" + group.getMessage());
115     }
116     
117     public void printSingleRevision(LogInfoRevision revision) {
118         if (writer == null ) {
119             return;
120         }
121         String JavaDoc repoFileName = revision.getLogInfoHeader().getRepositoryFilename();
122         repoFileName = repoFileName.substring(0, repoFileName.length() - 2);
123         writer.println(" " + revision.getNumber() + " " + repoFileName);
124     }
125     
126     public void printGroupFooter(RevisionsGroup group) {
127         //do nothing
128
}
129     
130     public void printSummary(SummaryProcessor processor) {
131         if (writer == null) {
132             return;
133         }
134         if (includeSummary) {
135             writer.println("=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=");
136             writer.println("Summary:");
137             writer.println("Number of changes: " + processor.getCommitCount());
138             writer.print("Developers: ");
139             String JavaDoc[] users = processor.getUserList();
140             for (int i = 0; i < users.length; i++) {
141                 if (i < users.length) {
142                     writer.println(users[i] + ", ");
143                 } else {
144                     writer.println(users[i]);
145                 }
146             }
147             writer.println();
148             String JavaDoc[] mostChanged = processor.getMostChangedFiles();
149             writer.println("Most frequently changed files:");
150             for (int j = 0; j < mostChanged.length; j++) {
151                 writer.println(mostChanged[j]);
152             }
153             writer.println();
154             writer.println("Most active developers (based on number of commits):");
155             String JavaDoc[] mostActive= processor.getMostActiveUsers();
156             for (int k = 0; k < mostActive.length; k++) {
157                 writer.println(mostActive[k]);
158             }
159             writer.println();
160         }
161     }
162     
163     public void printFooter(ChangeLogProcessor processor) {
164         //do nothing
165
if (writer != null) {
166             writer.flush();
167             writer.close();
168         }
169     }
170     
171 }
172
Popular Tags