1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.util; |
21 |
|
|
22 |
|
import java.util.HashMap; |
23 |
|
import java.util.Map; |
24 |
|
|
25 |
|
import org.slf4j.Logger; |
26 |
|
import org.slf4j.LoggerFactory; |
27 |
|
import org.xwiki.context.Execution; |
28 |
|
import org.xwiki.context.ExecutionContext; |
29 |
|
import org.xwiki.context.ExecutionContextException; |
30 |
|
import org.xwiki.context.ExecutionContextManager; |
31 |
|
|
32 |
|
import com.xpn.xwiki.web.Utils; |
33 |
|
|
34 |
|
|
35 |
|
|
36 |
|
|
37 |
|
@since |
38 |
|
@since |
39 |
|
@since |
40 |
|
@version |
41 |
|
|
|
|
| 75% |
Uncovered Elements: 6 (24) |
Complexity: 8 |
Complexity Density: 0.47 |
|
42 |
|
public abstract class AbstractXWikiRunnable implements Runnable |
43 |
|
{ |
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
private static final Logger LOGGER = LoggerFactory.getLogger(AbstractXWikiRunnable.class); |
48 |
|
|
49 |
|
private final Map<String, Object> properties = new HashMap<String, Object>(); |
50 |
|
|
51 |
|
|
52 |
|
@link |
53 |
|
|
54 |
|
@link |
55 |
|
@link |
56 |
|
|
57 |
|
private Execution execution; |
58 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
59 |
64 |
protected AbstractXWikiRunnable()... |
60 |
|
{ |
61 |
|
} |
62 |
|
|
63 |
|
|
64 |
|
@param |
65 |
|
@param |
66 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
67 |
0 |
protected AbstractXWikiRunnable(String propertyName, Object propertyValue)... |
68 |
|
{ |
69 |
0 |
this.properties.put(propertyName, propertyValue); |
70 |
|
} |
71 |
|
|
72 |
|
|
73 |
|
@param |
74 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
75 |
0 |
protected AbstractXWikiRunnable(Map<String, Object> properties)... |
76 |
|
{ |
77 |
0 |
this.properties.putAll(properties); |
78 |
|
} |
79 |
|
|
80 |
|
|
81 |
|
|
82 |
|
|
83 |
|
@param |
84 |
|
|
|
|
| - |
Uncovered Elements: 0 (0) |
Complexity: 1 |
Complexity Density: - |
|
85 |
4 |
protected void declareProperties(ExecutionContext executionContext)... |
86 |
|
{ |
87 |
|
} |
88 |
|
|
89 |
|
|
90 |
|
|
91 |
|
|
92 |
|
@return |
93 |
|
@throws |
94 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (7) |
Complexity: 1 |
Complexity Density: 0.14 |
|
95 |
64 |
protected ExecutionContext initExecutionContext() throws ExecutionContextException... |
96 |
|
{ |
97 |
|
|
98 |
|
|
99 |
64 |
this.execution = Utils.getComponent(Execution.class); |
100 |
|
|
101 |
64 |
ExecutionContextManager ecim = Utils.getComponent(ExecutionContextManager.class); |
102 |
64 |
ExecutionContext context = new ExecutionContext(); |
103 |
|
|
104 |
64 |
declareProperties(context); |
105 |
|
|
106 |
64 |
ecim.initialize(context); |
107 |
|
|
108 |
64 |
context.setProperties(this.properties); |
109 |
|
|
110 |
64 |
return context; |
111 |
|
} |
112 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
113 |
3 |
protected void cleanupExecutionContext()... |
114 |
|
{ |
115 |
|
|
116 |
|
|
117 |
3 |
this.execution.removeContext(); |
118 |
|
} |
119 |
|
|
|
|
| 71.4% |
Uncovered Elements: 2 (7) |
Complexity: 2 |
Complexity Density: 0.29 |
|
120 |
64 |
@Override... |
121 |
|
public final void run() |
122 |
|
{ |
123 |
64 |
try { |
124 |
|
|
125 |
64 |
initExecutionContext(); |
126 |
|
} catch (ExecutionContextException e) { |
127 |
0 |
LOGGER.error("Failed to initialize execution context", e); |
128 |
0 |
return; |
129 |
|
} |
130 |
|
|
131 |
64 |
try { |
132 |
|
|
133 |
64 |
runInternal(); |
134 |
|
} finally { |
135 |
|
|
136 |
3 |
cleanupExecutionContext(); |
137 |
|
} |
138 |
|
} |
139 |
|
|
140 |
|
protected abstract void runInternal(); |
141 |
|
} |