1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package org.xwiki.lesscss.internal.cache; |
21 |
|
|
22 |
|
import javax.inject.Inject; |
23 |
|
import javax.inject.Provider; |
24 |
|
|
25 |
|
import org.slf4j.Logger; |
26 |
|
import org.xwiki.lesscss.compiler.LESSCompilerException; |
27 |
|
import org.xwiki.lesscss.internal.LESSContext; |
28 |
|
import org.xwiki.lesscss.internal.colortheme.ColorThemeReference; |
29 |
|
import org.xwiki.lesscss.internal.colortheme.ColorThemeReferenceFactory; |
30 |
|
import org.xwiki.lesscss.internal.colortheme.CurrentColorThemeGetter; |
31 |
|
import org.xwiki.lesscss.internal.compiler.DefaultLESSCompiler; |
32 |
|
import org.xwiki.lesscss.internal.skin.SkinReference; |
33 |
|
import org.xwiki.lesscss.internal.skin.SkinReferenceFactory; |
34 |
|
import org.xwiki.lesscss.resources.LESSResourceReference; |
35 |
|
|
36 |
|
import com.xpn.xwiki.XWikiContext; |
37 |
|
|
38 |
|
|
39 |
|
|
40 |
|
|
41 |
|
@param |
42 |
|
|
43 |
|
@since |
44 |
|
@version |
45 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (32) |
Complexity: 9 |
Complexity Density: 0.41 |
|
46 |
|
public abstract class AbstractCachedCompiler<T> |
47 |
|
{ |
48 |
|
protected LESSCache<T> cache; |
49 |
|
|
50 |
|
protected CachedCompilerInterface<T> compiler; |
51 |
|
|
52 |
|
@Inject |
53 |
|
protected Provider<XWikiContext> xcontextProvider; |
54 |
|
|
55 |
|
@Inject |
56 |
|
protected CurrentColorThemeGetter currentColorThemeGetter; |
57 |
|
|
58 |
|
@Inject |
59 |
|
protected SkinReferenceFactory skinReferenceFactory; |
60 |
|
|
61 |
|
@Inject |
62 |
|
protected ColorThemeReferenceFactory colorThemeReferenceFactory; |
63 |
|
|
64 |
|
@Inject |
65 |
|
protected LESSContext lessContext; |
66 |
|
|
67 |
|
@Inject |
68 |
|
protected Logger logger; |
69 |
|
|
70 |
|
|
71 |
|
|
72 |
|
@param |
73 |
|
@param |
74 |
|
|
75 |
|
@param |
76 |
|
@param |
77 |
|
@return |
78 |
|
@throws |
79 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
80 |
2133 |
public T getResult(LESSResourceReference lessResourceReference, boolean includeSkinStyle, boolean useVelocity,... |
81 |
|
boolean force) throws LESSCompilerException |
82 |
|
{ |
83 |
2133 |
XWikiContext context = xcontextProvider.get(); |
84 |
2133 |
String skin = context.getWiki().getSkin(context); |
85 |
2132 |
return getResult(lessResourceReference, includeSkinStyle, useVelocity, skin, force); |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
@param |
91 |
|
@param |
92 |
|
|
93 |
|
@param |
94 |
|
@param |
95 |
|
@param |
96 |
|
@return |
97 |
|
@throws |
98 |
|
|
|
|
| 100% |
Uncovered Elements: 0 (27) |
Complexity: 8 |
Complexity Density: 0.42 |
|
99 |
2166 |
public T getResult(LESSResourceReference lessResourceReference, boolean includeSkinStyle, boolean useVelocity,... |
100 |
|
String skin, boolean force) throws LESSCompilerException |
101 |
|
{ |
102 |
|
|
103 |
2168 |
if (lessContext.isCacheDisabled()) { |
104 |
1 |
return compiler.compute(lessResourceReference, includeSkinStyle, useVelocity, true, skin); |
105 |
|
} |
106 |
|
|
107 |
2168 |
T result = null; |
108 |
|
|
109 |
2168 |
SkinReference skinReference = skinReferenceFactory.createReference(skin); |
110 |
2169 |
ColorThemeReference colorThemeReference = colorThemeReferenceFactory.createReference( |
111 |
|
currentColorThemeGetter.getCurrentColorTheme(true, "default")); |
112 |
|
|
113 |
|
|
114 |
|
|
115 |
2169 |
Object mutex = cache.getMutex(lessResourceReference, skinReference, colorThemeReference); |
116 |
2169 |
synchronized (mutex) { |
117 |
|
|
118 |
|
|
119 |
2169 |
if (!force) { |
120 |
2168 |
result = cache.get(lessResourceReference, skinReference, colorThemeReference); |
121 |
2168 |
if (result != null) { |
122 |
|
|
123 |
|
|
124 |
|
|
125 |
|
|
126 |
|
|
127 |
|
|
128 |
2097 |
if (lessContext.isHtmlExport() && useVelocity && this instanceof DefaultLESSCompiler) { |
129 |
1 |
compiler.compute(lessResourceReference, includeSkinStyle, true, false, skin); |
130 |
|
} |
131 |
2097 |
return cloneResult(result); |
132 |
|
} |
133 |
|
} |
134 |
|
|
135 |
|
|
136 |
72 |
try { |
137 |
72 |
result = compiler.compute(lessResourceReference, includeSkinStyle, useVelocity, true, skin); |
138 |
|
} catch (LESSCompilerException e) { |
139 |
1 |
logger.error("Error during the compilation of the resource [{}].", lessResourceReference, e); |
140 |
|
|
141 |
|
|
142 |
1 |
result = exceptionAsResult(e); |
143 |
|
} finally { |
144 |
|
|
145 |
72 |
cache.set(lessResourceReference, skinReference, colorThemeReference, result); |
146 |
|
} |
147 |
|
} |
148 |
|
|
149 |
72 |
return cloneResult(result); |
150 |
|
} |
151 |
|
|
152 |
|
|
153 |
|
|
154 |
|
|
155 |
|
@param |
156 |
|
@return |
157 |
|
|
158 |
|
@since |
159 |
|
|
160 |
|
protected abstract T cloneResult(T toClone); |
161 |
|
|
162 |
|
|
163 |
|
|
164 |
|
|
165 |
|
|
166 |
|
|
167 |
|
|
168 |
|
@param |
169 |
|
@return |
170 |
|
|
171 |
|
@since |
172 |
|
@since |
173 |
|
@since |
174 |
|
@since |
175 |
|
|
176 |
|
protected abstract T exceptionAsResult(LESSCompilerException exception); |
177 |
|
} |