1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.rendering.internal.macro.ctsreport; |
21 |
|
|
22 |
|
import java.util.ArrayList; |
23 |
|
import java.util.Collections; |
24 |
|
import java.util.List; |
25 |
|
import java.util.Map; |
26 |
|
import java.util.Set; |
27 |
|
|
28 |
|
import javax.inject.Inject; |
29 |
|
import javax.inject.Named; |
30 |
|
import javax.inject.Singleton; |
31 |
|
import javax.script.ScriptContext; |
32 |
|
|
33 |
|
import org.apache.commons.lang3.tuple.Pair; |
34 |
|
import org.slf4j.Logger; |
35 |
|
import org.xwiki.component.annotation.Component; |
36 |
|
import org.xwiki.rendering.block.Block; |
37 |
|
import org.xwiki.rendering.block.XDOM; |
38 |
|
import org.xwiki.rendering.macro.AbstractNoParameterMacro; |
39 |
|
import org.xwiki.rendering.macro.MacroContentParser; |
40 |
|
import org.xwiki.rendering.macro.MacroExecutionException; |
41 |
|
import org.xwiki.rendering.macro.descriptor.DefaultContentDescriptor; |
42 |
|
import org.xwiki.rendering.renderer.BlockRenderer; |
43 |
|
import org.xwiki.rendering.renderer.printer.DefaultWikiPrinter; |
44 |
|
import org.xwiki.rendering.transformation.MacroTransformationContext; |
45 |
|
import org.xwiki.script.ScriptContextManager; |
46 |
|
|
47 |
|
|
48 |
|
|
49 |
|
|
50 |
|
|
51 |
|
@version |
52 |
|
@since |
53 |
|
|
54 |
|
@Component |
55 |
|
@Named("ctsdata") |
56 |
|
@Singleton |
|
|
| 84.6% |
Uncovered Elements: 4 (26) |
Complexity: 4 |
Complexity Density: 0.19 |
|
57 |
|
public class CTSDataMacro extends AbstractNoParameterMacro |
58 |
|
{ |
59 |
|
|
60 |
|
|
61 |
|
|
62 |
|
private static final String DESCRIPTION = |
63 |
|
"Parses XWiki Rendering Compatibility Test Suite (CTS) JUnit Results"; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
private static final String CONTENT_DESCRIPTION = "Textual results of CTS execution, one result per line"; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
@Inject |
74 |
|
private Logger logger; |
75 |
|
|
76 |
|
@Inject |
77 |
|
private ScriptContextManager scriptContextManager; |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
@Inject |
83 |
|
private MacroContentParser contentParser; |
84 |
|
|
85 |
|
|
86 |
|
|
87 |
|
|
88 |
|
@Inject |
89 |
|
@Named("plain/1.0") |
90 |
|
private BlockRenderer plainTextRenderer; |
91 |
|
|
92 |
|
|
93 |
|
|
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
95 |
1 |
public CTSDataMacro()... |
96 |
|
{ |
97 |
1 |
super("CTS Data", DESCRIPTION, new DefaultContentDescriptor(CONTENT_DESCRIPTION)); |
98 |
1 |
setDefaultCategory(DEFAULT_CATEGORY_DEVELOPMENT); |
99 |
|
} |
100 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
101 |
0 |
@Override... |
102 |
|
public boolean supportsInlineMode() |
103 |
|
{ |
104 |
0 |
return true; |
105 |
|
} |
106 |
|
|
|
|
| 90% |
Uncovered Elements: 2 (20) |
Complexity: 2 |
Complexity Density: 0.11 |
|
107 |
1 |
@Override... |
108 |
|
public List<Block> execute(Object unusedParameters, String content, MacroTransformationContext context) |
109 |
|
throws MacroExecutionException |
110 |
|
{ |
111 |
|
|
112 |
1 |
XDOM xdom = this.contentParser.parse(content, context, true, false); |
113 |
1 |
DefaultWikiPrinter printer = new DefaultWikiPrinter(); |
114 |
1 |
this.plainTextRenderer.render(xdom, printer); |
115 |
1 |
String parsedContent = printer.toString(); |
116 |
|
|
117 |
|
|
118 |
1 |
TestParser parser = new TestParser(); |
119 |
1 |
List<Result> results = new ArrayList<Result>(); |
120 |
1 |
for (String resultLine : parsedContent.split("[\\r\\n]+")) { |
121 |
4 |
results.add(parser.parse(resultLine)); |
122 |
|
} |
123 |
|
|
124 |
|
|
125 |
1 |
ScriptContext scriptContext = this.scriptContextManager.getCurrentScriptContext(); |
126 |
1 |
if (scriptContext != null) { |
127 |
1 |
ResultExtractor extractor = new ResultExtractor(); |
128 |
1 |
Set<String> testNames = extractor.extractByTestName(results); |
129 |
1 |
scriptContext.setAttribute("ctsTestNames", testNames, ScriptContext.ENGINE_SCOPE); |
130 |
1 |
Map<String, Pair<Set<Test>, Set<Test>>> tests = extractor.extractBySyntax(results); |
131 |
1 |
extractor.normalize(testNames, tests); |
132 |
1 |
scriptContext.setAttribute("ctsTests", tests, ScriptContext.ENGINE_SCOPE); |
133 |
|
} else { |
134 |
0 |
this.logger.warn("Script Context not found in the Execution Context. CTS Data variable not bound!"); |
135 |
|
} |
136 |
|
|
137 |
1 |
return Collections.emptyList(); |
138 |
|
} |
139 |
|
} |