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

File XWikiExtensionValidator.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

6
14
3
1
97
56
7
0.5
4.67
3
2.33

Classes

Class Line # Actions
XWikiExtensionValidator 48 14 0% 7 1
0.9565217595.7%
 

Contributing tests

This file is covered by 28 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.internal.validator;
21   
22    import javax.inject.Inject;
23    import javax.inject.Named;
24    import javax.inject.Provider;
25    import javax.inject.Singleton;
26   
27    import org.slf4j.Logger;
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.component.manager.ComponentLookupException;
30    import org.xwiki.component.manager.ComponentManager;
31    import org.xwiki.extension.Extension;
32    import org.xwiki.extension.InstallException;
33    import org.xwiki.extension.InstalledExtension;
34    import org.xwiki.extension.UninstallException;
35    import org.xwiki.extension.handler.ExtensionValidator;
36    import org.xwiki.job.Request;
37   
38    /**
39    * Default right needed to install/uninstall an extension in XWiki.
40    *
41    * @version $Id: a19119ac4dae8c1f0af09c7cec8e6134d14a5256 $
42    * @since 4.2M2
43    */
44    // The rationale for being in this module is that checking right is useless if you don't also provide public script
45    // service but if there is other things to put in a new xwiki-platform-extension-xwiki we might want to move it.
46    @Component
47    @Singleton
 
48    public class XWikiExtensionValidator extends AbstractExtensionValidator
49    {
50    @Inject
51    @Named("context")
52    private Provider<ComponentManager> componentManagerProvider;
53   
54    @Inject
55    private Logger logger;
56   
 
57  102 toggle private ExtensionValidator getExtensionValidator(String type)
58    {
59  102 ComponentManager componentManager = this.componentManagerProvider.get();
60  102 if (componentManager.hasComponent(ExtensionValidator.class, type)) {
61  89 try {
62  89 return componentManager.<ExtensionValidator>getInstance(ExtensionValidator.class, type);
63    } catch (ComponentLookupException e) {
64  0 this.logger.error("Failed to get extension validator. Fallback on programming right.", e);
65    }
66    }
67   
68  13 return null;
69    }
70   
 
71  73 toggle @Override
72    public void checkInstallInternal(Extension extension, String namespace, Request request) throws InstallException
73    {
74    // Try custom ExtensionValidator
75  73 ExtensionValidator validator = getExtensionValidator(extension.getType());
76  73 if (validator != null) {
77  65 validator.checkInstall(extension, namespace, request);
78    }
79   
80    // Fallback on programming right
81  71 super.checkInstallInternal(extension, namespace, request);
82    }
83   
 
84  29 toggle @Override
85    public void checkUninstallInternal(InstalledExtension extension, String namespace, Request request)
86    throws UninstallException
87    {
88    // Try custom ExtensionValidator
89  29 ExtensionValidator validator = getExtensionValidator(extension.getType());
90  29 if (validator != null) {
91  24 validator.checkUninstall(extension, namespace, request);
92    }
93   
94    // Fallback on programming right
95  27 super.checkUninstallInternal(extension, namespace, request);
96    }
97    }