1. Project Clover database Sat Feb 2 2019 06:45:20 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
58
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 29 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: 66de5f1e02db93c3cba36b0c187cad9f5d2a7e5d $
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  360 toggle private ExtensionValidator getExtensionValidator(String type)
58    {
59  360 ComponentManager componentManager = this.componentManagerProvider.get();
60  360 if (componentManager.hasComponent(ExtensionValidator.class, type)) {
61  329 try {
62  329 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  31 return null;
69    }
70   
 
71  319 toggle @Override
72    public void checkInstallInternal(Extension extension, String namespace, Request request) throws InstallException
73    {
74    // Try custom ExtensionValidator
75  319 ExtensionValidator validator = getExtensionValidator(extension.getType());
76  319 if (validator != null) {
77  293 validator.checkInstall(extension, namespace, request);
78    } else {
79    // Fallback on programming right
80  26 super.checkInstallInternal(extension, namespace, request);
81    }
82    }
83   
 
84  41 toggle @Override
85    public void checkUninstallInternal(InstalledExtension extension, String namespace, Request request)
86    throws UninstallException
87    {
88    // Try custom ExtensionValidator
89  41 ExtensionValidator validator = getExtensionValidator(extension.getType());
90  41 if (validator != null) {
91  36 validator.checkUninstall(extension, namespace, request);
92    } else {
93    // Fallback on programming right
94  5 super.checkUninstallInternal(extension, namespace, request);
95    }
96    }
97    }