1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.diff.script; |
21 |
|
|
22 |
|
import java.util.List; |
23 |
|
|
24 |
|
import javax.inject.Inject; |
25 |
|
import javax.inject.Named; |
26 |
|
import javax.inject.Singleton; |
27 |
|
|
28 |
|
import org.xwiki.component.annotation.Component; |
29 |
|
import org.xwiki.context.Execution; |
30 |
|
import org.xwiki.diff.DiffException; |
31 |
|
import org.xwiki.diff.DiffManager; |
32 |
|
import org.xwiki.diff.DiffResult; |
33 |
|
import org.xwiki.diff.display.InlineDiffChunk; |
34 |
|
import org.xwiki.diff.display.InlineDiffDisplayer; |
35 |
|
import org.xwiki.diff.display.Splitter; |
36 |
|
import org.xwiki.diff.display.UnifiedDiffBlock; |
37 |
|
import org.xwiki.diff.display.UnifiedDiffConfiguration; |
38 |
|
import org.xwiki.diff.display.UnifiedDiffDisplayer; |
39 |
|
import org.xwiki.script.service.ScriptService; |
40 |
|
|
41 |
|
|
42 |
|
|
43 |
|
|
44 |
|
@version |
45 |
|
@since |
46 |
|
|
47 |
|
@Component |
48 |
|
@Named("diff.display") |
49 |
|
@Singleton |
|
|
| 27.3% |
Uncovered Elements: 24 (33) |
Complexity: 11 |
Complexity Density: 0.42 |
|
50 |
|
public class DiffDisplayerScriptService implements ScriptService |
51 |
|
{ |
52 |
|
|
53 |
|
|
54 |
|
|
55 |
|
@Inject |
56 |
|
private Execution execution; |
57 |
|
|
58 |
|
|
59 |
|
|
60 |
|
|
61 |
|
@Inject |
62 |
|
@Named("line") |
63 |
|
private Splitter<String, String> lineSplitter; |
64 |
|
|
65 |
|
|
66 |
|
|
67 |
|
|
68 |
|
@Inject |
69 |
|
private Splitter<String, Character> charSplitter; |
70 |
|
|
71 |
|
|
72 |
|
|
73 |
|
|
74 |
|
@Inject |
75 |
|
private DiffManager diffManager; |
76 |
|
|
77 |
|
|
78 |
|
|
79 |
|
|
80 |
|
@Inject |
81 |
|
private InlineDiffDisplayer inlineDiffDisplayer; |
82 |
|
|
83 |
|
|
84 |
|
|
85 |
|
|
86 |
|
@Inject |
87 |
|
private UnifiedDiffDisplayer unifiedDiffDisplayer; |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
@param |
93 |
|
@param |
94 |
|
@param |
95 |
|
@return |
96 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
97 |
0 |
public <E> List<InlineDiffChunk<E>> inline(List<E> previous, List<E> next)... |
98 |
|
{ |
99 |
0 |
setError(null); |
100 |
|
|
101 |
0 |
try { |
102 |
0 |
return this.inlineDiffDisplayer.display(this.diffManager.diff(previous, next, null)); |
103 |
|
} catch (DiffException e) { |
104 |
0 |
setError(e); |
105 |
0 |
return null; |
106 |
|
} |
107 |
|
} |
108 |
|
|
109 |
|
|
110 |
|
|
111 |
|
|
112 |
|
@param |
113 |
|
@param |
114 |
|
@return |
115 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
116 |
0 |
public List<InlineDiffChunk<Character>> inline(String previous, String next)... |
117 |
|
{ |
118 |
0 |
setError(null); |
119 |
|
|
120 |
0 |
try { |
121 |
0 |
return this.inlineDiffDisplayer |
122 |
|
.display(this.diffManager.diff(this.charSplitter.split(previous), this.charSplitter.split(next), null)); |
123 |
|
} catch (DiffException e) { |
124 |
0 |
setError(e); |
125 |
0 |
return null; |
126 |
|
} |
127 |
|
} |
128 |
|
|
129 |
|
|
130 |
|
|
131 |
|
|
132 |
|
|
133 |
|
@param |
134 |
|
@param |
135 |
|
@return |
136 |
|
|
|
|
| 75% |
Uncovered Elements: 2 (8) |
Complexity: 2 |
Complexity Density: 0.25 |
|
137 |
7 |
public List<UnifiedDiffBlock<String, Character>> unified(String previous, String next)... |
138 |
|
{ |
139 |
7 |
setError(null); |
140 |
|
|
141 |
7 |
try { |
142 |
7 |
DiffResult<String> diffResult = |
143 |
|
this.diffManager.diff(this.lineSplitter.split(previous), this.lineSplitter.split(next), null); |
144 |
7 |
UnifiedDiffConfiguration<String, Character> config = this.unifiedDiffDisplayer.getDefaultConfiguration(); |
145 |
7 |
config.setSplitter(this.charSplitter); |
146 |
7 |
return this.unifiedDiffDisplayer.display(diffResult, config); |
147 |
|
} catch (DiffException e) { |
148 |
0 |
setError(e); |
149 |
0 |
return null; |
150 |
|
} |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
|
156 |
|
|
157 |
|
|
158 |
|
@param |
159 |
|
@param |
160 |
|
@param |
161 |
|
@param |
162 |
|
@param |
163 |
|
@return |
164 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.4 |
|
165 |
0 |
public <E, F> List<UnifiedDiffBlock<E, F>> unified(List<E> previous, List<E> next,... |
166 |
|
UnifiedDiffConfiguration<E, F> config) |
167 |
|
{ |
168 |
0 |
setError(null); |
169 |
|
|
170 |
0 |
try { |
171 |
0 |
return this.unifiedDiffDisplayer.display(this.diffManager.diff(previous, next, null), config); |
172 |
|
} catch (DiffException e) { |
173 |
0 |
setError(e); |
174 |
0 |
return null; |
175 |
|
} |
176 |
|
} |
177 |
|
|
178 |
|
|
179 |
|
@param |
180 |
|
@param |
181 |
|
|
182 |
|
@return |
183 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
184 |
0 |
public <E, F> UnifiedDiffConfiguration<E, F> getUnifiedDiffConfiguration()... |
185 |
|
{ |
186 |
0 |
return this.unifiedDiffDisplayer.getDefaultConfiguration(); |
187 |
|
} |
188 |
|
|
189 |
|
|
190 |
|
|
191 |
|
|
192 |
|
@return |
193 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
194 |
0 |
public Exception getLastError()... |
195 |
|
{ |
196 |
0 |
return (Exception) this.execution.getContext().getProperty(DiffScriptService.DIFF_ERROR_KEY); |
197 |
|
} |
198 |
|
|
199 |
|
|
200 |
|
@link |
201 |
|
|
202 |
|
@param |
203 |
|
@see |
204 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
205 |
7 |
private void setError(Exception e)... |
206 |
|
{ |
207 |
7 |
this.execution.getContext().setProperty(DiffScriptService.DIFF_ERROR_KEY, e); |
208 |
|
} |
209 |
|
} |