1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.extension.wrap

File WrappingExtension.java

 

Coverage histogram

../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

38
65
27
1
296
210
46
0.71
2.41
27
1.7

Classes

Class Line # Actions
WrappingExtension 45 65 0% 46 60
0.5384615753.8%
 

Contributing tests

This file is covered by 22 tests. .

Source view

1    /*
2    * See the NOTICE file distributed with this work for additional
3    * information regarding copyright ownership.
4    *
5    * This is free software; you can redistribute it and/or modify it
6    * under the terms of the GNU Lesser General Public License as
7    * published by the Free Software Foundation; either version 2.1 of
8    * the License, or (at your option) any later version.
9    *
10    * This software is distributed in the hope that it will be useful,
11    * but WITHOUT ANY WARRANTY; without even the implied warranty of
12    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13    * Lesser General Public License for more details.
14    *
15    * You should have received a copy of the GNU Lesser General Public
16    * License along with this software; if not, write to the Free
17    * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
18    * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
19    */
20    package org.xwiki.extension.wrap;
21   
22    import java.util.Collection;
23    import java.util.HashMap;
24    import java.util.Map;
25   
26    import org.xwiki.extension.Extension;
27    import org.xwiki.extension.ExtensionAuthor;
28    import org.xwiki.extension.ExtensionDependency;
29    import org.xwiki.extension.ExtensionFile;
30    import org.xwiki.extension.ExtensionId;
31    import org.xwiki.extension.ExtensionIssueManagement;
32    import org.xwiki.extension.ExtensionLicense;
33    import org.xwiki.extension.ExtensionScm;
34    import org.xwiki.extension.internal.converter.ExtensionIdConverter;
35    import org.xwiki.extension.repository.ExtensionRepository;
36    import org.xwiki.extension.repository.ExtensionRepositoryDescriptor;
37   
38    /**
39    * Wrap an extension.
40    *
41    * @param <E> the extension type
42    * @version $Id: 2c2b2b6ae4f206d10a1ff1265552a3410d2d198c $
43    * @since 4.0M1
44    */
 
45    public class WrappingExtension<E extends Extension> extends AbstractWrappingObject<E> implements Extension
46    {
47    protected Map<String, Object> overwrites = new HashMap<>();
48   
49    /**
50    * @param extension the wrapped extension
51    */
 
52  6658 toggle public WrappingExtension(E extension)
53    {
54  6658 super(extension);
55    }
56   
57    /**
58    * @param key the key associated to the Extension field (usually found in {@link Extension} constants) to overwrite
59    * @param value the value to overwrite
60    * @since 9.0RC1
61    * @since 8.4.2
62    */
 
63  1 toggle public void setOverwrite(String key, Object value)
64    {
65  1 this.overwrites.put(key, value);
66    }
67   
68    // Extension
69   
 
70  448 toggle @Override
71    public <T> T get(String fieldName)
72    {
73  447 if (this.overwrites.containsKey(fieldName)) {
74  0 return (T) this.overwrites.get(fieldName);
75    }
76   
77  448 return getWrapped().get(fieldName);
78    }
79   
 
80  8121 toggle @Override
81    public ExtensionId getId()
82    {
83  8121 return getWrapped().getId();
84    }
85   
 
86  111 toggle @Override
87    @Deprecated
88    public Collection<String> getFeatures()
89    {
90  111 return ExtensionIdConverter.toStringList(getExtensionFeatures());
91    }
92   
 
93  502 toggle @Override
94    public Collection<ExtensionId> getExtensionFeatures()
95    {
96  502 if (this.overwrites.containsKey(Extension.FIELD_EXTENSIONFEATURES)) {
97  0 return (Collection<ExtensionId>) this.overwrites.get(Extension.FIELD_EXTENSIONFEATURES);
98    }
99   
100  502 return getWrapped().getExtensionFeatures();
101    }
102   
 
103  8 toggle @Override
104    public ExtensionId getExtensionFeature(String featureId)
105    {
106  8 return getWrapped().getExtensionFeature(featureId);
107    }
108   
 
109  88 toggle @Override
110    public String getType()
111    {
112  88 if (this.overwrites.containsKey(Extension.FIELD_TYPE)) {
113  0 return (String) this.overwrites.get(Extension.FIELD_TYPE);
114    }
115   
116  88 return getWrapped().getType();
117    }
118   
 
119  771 toggle @Override
120    public String getName()
121    {
122  771 if (this.overwrites.containsKey(Extension.FIELD_NAME)) {
123  0 return (String) this.overwrites.get(Extension.FIELD_NAME);
124    }
125   
126  771 return getWrapped().getName();
127    }
128   
 
129  124 toggle @Override
130    public Collection<ExtensionLicense> getLicenses()
131    {
132  124 if (this.overwrites.containsKey(Extension.FIELD_LICENSES)) {
133  0 return (Collection<ExtensionLicense>) this.overwrites.get(Extension.FIELD_LICENSES);
134    }
135   
136  124 return getWrapped().getLicenses();
137    }
138   
 
139  558 toggle @Override
140    public String getSummary()
141    {
142  558 if (this.overwrites.containsKey(Extension.FIELD_SUMMARY)) {
143  0 return (String) this.overwrites.get(Extension.FIELD_SUMMARY);
144    }
145   
146  558 return getWrapped().getSummary();
147    }
148   
 
149  4 toggle @Override
150    public String getDescription()
151    {
152  4 if (this.overwrites.containsKey(Extension.FIELD_DESCRIPTION)) {
153  0 return (String) this.overwrites.get(Extension.FIELD_DESCRIPTION);
154    }
155   
156  4 return getWrapped().getDescription();
157    }
158   
 
159  165 toggle @Override
160    public String getWebSite()
161    {
162  165 if (this.overwrites.containsKey(Extension.FIELD_WEBSITE)) {
163  0 return (String) this.overwrites.get(Extension.FIELD_WEBSITE);
164    }
165   
166  165 return getWrapped().getWebSite();
167    }
168   
 
169  500 toggle @Override
170    public Collection<ExtensionAuthor> getAuthors()
171    {
172  500 if (this.overwrites.containsKey(Extension.FIELD_AUTHORS)) {
173  0 return (Collection<ExtensionAuthor>) this.overwrites.get(Extension.FIELD_AUTHORS);
174    }
175   
176  500 return getWrapped().getAuthors();
177    }
178   
 
179  38 toggle @Override
180    public Collection<String> getAllowedNamespaces()
181    {
182  38 if (this.overwrites.containsKey(Extension.FIELD_ALLOWEDNAMESPACES)) {
183  2 return (Collection<String>) this.overwrites.get(Extension.FIELD_ALLOWEDNAMESPACES);
184    }
185   
186  36 return getWrapped().getAllowedNamespaces();
187    }
188   
 
189  157 toggle @Override
190    public Collection<ExtensionDependency> getDependencies()
191    {
192  157 if (this.overwrites.containsKey(Extension.FIELD_DEPENDENCIES)) {
193  0 return (Collection<ExtensionDependency>) this.overwrites.get(Extension.FIELD_DEPENDENCIES);
194    }
195   
196  157 return getWrapped().getDependencies();
197    }
198   
 
199  0 toggle @Override
200    public Collection<ExtensionDependency> getManagedDependencies()
201    {
202  0 if (this.overwrites.containsKey(Extension.FIELD_MANAGEDDEPENDENCIES)) {
203  0 return (Collection<ExtensionDependency>) this.overwrites.get(Extension.FIELD_MANAGEDDEPENDENCIES);
204    }
205   
206  0 return getWrapped().getManagedDependencies();
207    }
208   
 
209  111 toggle @Override
210    public ExtensionFile getFile()
211    {
212  111 return getWrapped().getFile();
213    }
214   
 
215  469 toggle @Override
216    public ExtensionRepository getRepository()
217    {
218  469 return getWrapped().getRepository();
219    }
220   
 
221  172 toggle @Override
222    public ExtensionScm getScm()
223    {
224  172 if (this.overwrites.containsKey(Extension.FIELD_SCM)) {
225  0 return (ExtensionScm) this.overwrites.get(Extension.FIELD_SCM);
226    }
227   
228  172 return getWrapped().getScm();
229    }
230   
 
231  55 toggle @Override
232    public ExtensionIssueManagement getIssueManagement()
233    {
234  55 if (this.overwrites.containsKey(Extension.FIELD_ISSUEMANAGEMENT)) {
235  0 return (ExtensionIssueManagement) this.overwrites.get(Extension.FIELD_ISSUEMANAGEMENT);
236    }
237   
238  55 return getWrapped().getIssueManagement();
239    }
240   
 
241  0 toggle @Override
242    public String getCategory()
243    {
244  0 if (this.overwrites.containsKey(Extension.FIELD_CATEGORY)) {
245  0 return (String) this.overwrites.get(Extension.FIELD_CATEGORY);
246    }
247   
248  0 return getWrapped().getCategory();
249    }
250   
 
251  0 toggle @Override
252    public Collection<ExtensionRepositoryDescriptor> getRepositories()
253    {
254  0 if (this.overwrites.containsKey(Extension.FIELD_REPOSITORIES)) {
255  0 return (Collection<ExtensionRepositoryDescriptor>) this.overwrites.get(Extension.FIELD_REPOSITORIES);
256    }
257   
258  0 return getWrapped().getRepositories();
259    }
260   
 
261  0 toggle @Override
262    public Map<String, Object> getProperties()
263    {
264  0 if (this.overwrites.containsKey(Extension.FIELD_PROPERTIES)) {
265  0 return (Map<String, Object>) this.overwrites.get(Extension.FIELD_PROPERTIES);
266    }
267   
268  0 return getWrapped().getProperties();
269    }
270   
 
271  0 toggle @Override
272    public <T> T getProperty(String key)
273    {
274  0 if (this.overwrites.containsKey(Extension.FIELD_PROPERTIES + '_' + key)) {
275  0 return (T) this.overwrites.get(Extension.FIELD_PROPERTIES + '_' + key);
276    }
277   
278  0 return getWrapped().getProperty(key);
279    }
280   
 
281  0 toggle @Override
282    public <T> T getProperty(String key, T def)
283    {
284  0 if (this.overwrites.containsKey(Extension.FIELD_PROPERTIES + '_' + key)) {
285  0 return (T) this.overwrites.get(Extension.FIELD_PROPERTIES + '_' + key);
286    }
287   
288  0 return getWrapped().getProperty(key, def);
289    }
290   
 
291  6 toggle @Override
292    public int compareTo(Extension o)
293    {
294  6 return getWrapped().compareTo(o);
295    }
296    }