1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package de.smartics.maven.exceptions.report;
17
18 import java.util.Collection;
19 import java.util.Iterator;
20 import java.util.List;
21
22 import org.apache.commons.lang.ObjectUtils;
23 import org.apache.commons.lang.StringUtils;
24 import org.apache.maven.doxia.sink.Sink;
25
26 import com.sun.javadoc.ClassDoc;
27 import com.sun.javadoc.FieldDoc;
28
29 import de.smartics.exceptions.code.NumberCode;
30 import de.smartics.exceptions.core.Code;
31 import de.smartics.exceptions.report.sort.CodeUtils;
32 import de.smartics.exceptions.report.sort.MixedCodeComparator;
33 import de.smartics.exceptions.report.sort.CodeUtils.CodeContainer;
34 import de.smartics.maven.exceptions.AbstractSinkReportGenerator;
35 import de.smartics.report.conf.ProjectConfiguration;
36 import de.smartics.report.conf.ReportData;
37 import de.smartics.report.util.JavadocUtils;
38
39
40
41
42
43
44
45
46 public class CodeSortedSinkReportGenerator extends AbstractSinkReportGenerator
47 {
48
49
50
51
52
53
54
55
56
57
58
59
60
61 public CodeSortedSinkReportGenerator()
62 {
63 }
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83 protected void write(final Object output, final ProjectConfiguration config,
84 final ReportData reportData) throws Exception
85 {
86 final Sink sink = toSink(output);
87 final Collection javadocs = reportData.getJavadocs();
88
89 final List codeContainerList =
90 CodeUtils.getCodeList(config, javadocs, new MixedCodeComparator());
91
92 writeHeader(output, config);
93 String currentComponentId = null;
94 String currentCodeMajorNumber = null;
95 boolean firstTime = true;
96 for (final Iterator i = codeContainerList.iterator(); i.hasNext();)
97 {
98 boolean headerChanged = false;
99 final CodeContainer codeContainer = (CodeContainer) i.next();
100 final ClassDoc classDoc = codeContainer.getClassDoc();
101 final FieldDoc fieldDoc = codeContainer.getFieldDoc();
102 final Code code = codeContainer.getCode();
103
104 final String componentId = code.getComponentId();
105 if (!ObjectUtils.equals(currentComponentId, componentId))
106 {
107 if (!firstTime)
108 {
109 writeInfoSubFooter(output, config);
110 writeInfoFooter(output, config);
111 }
112 firstTime = false;
113 writeInfoHeader(output, config, componentId, classDoc);
114 currentComponentId = componentId;
115 headerChanged = true;
116 }
117
118 if (code instanceof NumberCode)
119 {
120 final NumberCode numberCode = (NumberCode) code;
121 final String codeMajorNumber =
122 String.valueOf(numberCode.getMajorNumber());
123 if (!ObjectUtils.equals(currentCodeMajorNumber, codeMajorNumber))
124 {
125 if (!headerChanged)
126 {
127 writeInfoSubFooter(output, config);
128 }
129 writeInfoSubHeader(output, config, codeMajorNumber);
130 currentCodeMajorNumber = codeMajorNumber;
131 headerChanged = true;
132 }
133 }
134 else if (currentCodeMajorNumber != null)
135 {
136 currentCodeMajorNumber = null;
137 if (!headerChanged)
138 {
139 writeInfoSubHeader(output, config, "-----");
140 headerChanged = true;
141 }
142 }
143
144 if (headerChanged)
145 {
146 final String relDir = config.getJavadocRelativeDir();
147 if (relDir != null)
148 {
149 sink.paragraph();
150
151 final String className = classDoc.qualifiedName();
152 final String path = JavadocUtils.expandJavadocUrl(relDir, className);
153 sink.link(path);
154 sink.text(className);
155 sink.link_();
156 sink.paragraph_();
157 }
158
159 final String message = classDoc.commentText();
160 if (!StringUtils.isBlank(message))
161 {
162 sink.paragraph();
163 sink.text(message);
164 sink.paragraph_();
165 }
166
167 writeTableHeader(output, config);
168 }
169
170 writeReportElementInfo(output, config, fieldDoc);
171 }
172
173 writeInfoSubFooter(output, config);
174 writeInfoFooter(output, config);
175 writeFooter(output, config);
176 }
177
178
179
180 }