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

File InstalledExtensionScriptService.java

 

Coverage histogram

../../../../img/srcFileCovDistChart4.png
78% of files have more coverage

Code metrics

2
24
7
1
182
70
10
0.42
3.43
7
1.43

Classes

Class Line # Actions
InstalledExtensionScriptService 43 24 0% 10 22
0.3333333433.3%
 

Contributing tests

No tests hitting this source file were found.

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.script;
21   
22    import java.util.Collection;
23    import java.util.Map;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27    import javax.inject.Singleton;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.extension.ExtensionId;
31    import org.xwiki.extension.InstalledExtension;
32    import org.xwiki.extension.repository.InstalledExtensionRepository;
33   
34    /**
35    * Various script APIs related to installed extensions.
36    *
37    * @version $Id: 4372ef4140722ddaa58b0070fe583469aa47c62e $
38    * @since 5.3M1
39    */
40    @Component
41    @Named(ExtensionManagerScriptService.ROLEHINT + '.' + InstalledExtensionScriptService.ID)
42    @Singleton
 
43    public class InstalledExtensionScriptService extends AbstractExtensionScriptService
44    {
45    /**
46    * The identifier of the sub extension {@link org.xwiki.script.service.ScriptService}.
47    */
48    public static final String ID = "installed";
49   
50    /**
51    * The repository containing installed extensions.
52    */
53    @Inject
54    private InstalledExtensionRepository installedExtensionRepository;
55   
56    /**
57    * @return the installed extensions repository
58    */
 
59  8 toggle public InstalledExtensionRepository getRepository()
60    {
61  8 return safe(this.installedExtensionRepository);
62    }
63   
64    /**
65    * Get a list of all currently installed extensions. This doesn't include core extensions, only custom extensions
66    * installed by the administrators.
67    *
68    * @return a list of read-only handlers corresponding to the installed extensions, an empty list if nothing is
69    * installed
70    */
 
71  9 toggle public Collection<InstalledExtension> getInstalledExtensions()
72    {
73  9 return safe(this.installedExtensionRepository.getInstalledExtensions());
74    }
75   
76    /**
77    * Return all the extensions available for the provide namespace. This also include root extension since namespaces
78    * inherit from root.
79    * <p>
80    * This doesn't include core extensions, only extension installed through the API.
81    *
82    * @param namespace the target namespace for which to retrieve the list of installed extensions
83    * @return a list of read-only handlers corresponding to the installed extensions, an empty list if nothing is
84    * installed in the target namespace
85    */
 
86  0 toggle public Collection<InstalledExtension> getInstalledExtensions(String namespace)
87    {
88  0 return safe(this.installedExtensionRepository.getInstalledExtensions(namespace));
89    }
90   
91    /**
92    * Get the extension handler corresponding to the given installed extension ID or feature (virtual ID) provided by
93    * the extension and namespace.
94    * <p>
95    * The returned handler can be used to get more information about the extension, such as the authors, an extension
96    * description, its license...
97    *
98    * @param feature the extension id or provided feature (virtual extension) of the extension to resolve
99    * @param namespace the optional namespace where the extension should be installed
100    * @return the read-only handler corresponding to the requested extension, or {@code null} if the extension isn't
101    * installed in the target namespace
102    */
 
103  396 toggle public InstalledExtension getInstalledExtension(String feature, String namespace)
104    {
105  396 return safe(this.installedExtensionRepository.getInstalledExtension(feature, namespace));
106    }
107   
108    /**
109    * Get all the installed extensions that depend on the specified root extension. The results are grouped by
110    * namespace.
111    *
112    * @param feature the extension id or provided feature (virtual extension) of the extension to resolve
113    * @return a map namespace -&gt; list of dependent extensions, or {@code null} if any error occurs while computing
114    * the result, in which case {@link #getLastError()} contains the failure reason
115    */
 
116  0 toggle public Map<String, Collection<InstalledExtension>> getBackwardDependencies(String feature)
117    {
118  0 InstalledExtension installedExtension = this.installedExtensionRepository.getInstalledExtension(feature, null);
119   
120  0 Map<String, Collection<InstalledExtension>> extensions;
121   
122  0 if (installedExtension != null) {
123  0 extensions = getBackwardDependencies(installedExtension.getId());
124    } else {
125  0 extensions = null;
126    }
127   
128  0 return extensions;
129    }
130   
131    /**
132    * Get all backward dependencies by namespace for the provided installed extension.
133    *
134    * @param extensionId the extension identifier
135    * @return the extension backward dependencies in all namespaces, or {@code null} if any error occurs while
136    * computing the result, in which case {@link #getLastError()} contains the failure reason
137    */
 
138  0 toggle public Map<String, Collection<InstalledExtension>> getBackwardDependencies(ExtensionId extensionId)
139    {
140  0 Map<String, Collection<InstalledExtension>> extensions;
141   
142  0 setError(null);
143   
144  0 try {
145  0 return safe(this.installedExtensionRepository.getBackwardDependencies(extensionId));
146    } catch (Exception e) {
147  0 setError(e);
148   
149  0 extensions = null;
150    }
151   
152  0 return extensions;
153    }
154   
155    /**
156    * Get provided installed extension backward dependencies in the provided namespace.
157    * <p>
158    * Only look at the backward dependencies in the provided namespace. To get all the dependencies of a root extension
159    * (namespace=null) across namespaces use {@link #getBackwardDependencies(ExtensionId)} instead.
160    *
161    * @param feature the extension unique identifier
162    * @param namespace the namespace where to search for backward dependencies
163    * @return the backward dependencies, an empty collection of none could be found, or {@code null} if any error
164    * occurs while computing the result, in which case {@link #getLastError()} contains the failure reason
165    */
 
166  29 toggle public Collection<InstalledExtension> getBackwardDependencies(String feature, String namespace)
167    {
168  29 Collection<InstalledExtension> extensions;
169   
170  29 setError(null);
171   
172  29 try {
173  29 return safe(this.installedExtensionRepository.getBackwardDependencies(feature, namespace));
174    } catch (Exception e) {
175  0 setError(e);
176   
177  0 extensions = null;
178    }
179   
180  0 return extensions;
181    }
182    }