1. Project Clover database Sat Feb 2 2019 06:45:20 CET
  2. Package org.xwiki.extension.job

File AbstractExtensionRequest.java

 

Coverage histogram

../../../../img/srcFileCovDistChart9.png
41% of files have more coverage

Code metrics

4
24
15
1
206
99
17
0.71
1.6
15
1.13

Classes

Class Line # Actions
AbstractExtensionRequest 39 24 0% 17 4
0.9069767690.7%
 

Contributing tests

This file is covered by 125 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.job;
21   
22    import java.beans.Transient;
23    import java.util.ArrayList;
24    import java.util.Collection;
25    import java.util.HashSet;
26   
27    import org.xwiki.extension.Extension;
28    import org.xwiki.extension.ExtensionId;
29    import org.xwiki.extension.ExtensionRewriter;
30    import org.xwiki.job.AbstractRequest;
31    import org.xwiki.job.Request;
32   
33    /**
34    * Base class for extension manipulation related {@link Request} implementations.
35    *
36    * @version $Id: 7b4895290cadc74ea5bff6fffec10a14b41d1fbc $
37    * @since 4.0M1
38    */
 
39    public abstract class AbstractExtensionRequest extends AbstractRequest implements ExtensionRequest
40    {
41    /**
42    * @see #getExtensions()
43    */
44    public static final String PROPERTY_EXTENSIONS = "extensions";
45   
46    /**
47    * @see #getExcludedExtensions()
48    */
49    public static final String PROPERTY_EXCLUDEDEXTENSIONS = "extensions.excluded";
50   
51    /**
52    * @see #getNamespaces()
53    */
54    public static final String PROPERTY_NAMESPACES = "namespaces";
55   
56    /**
57    * @see #isRootModificationsAllowed()
58    */
59    public static final String PROPERTY_ROOTMODIFICATIONSALLOWED = "rootModificationsAllowed";
60   
61    /**
62    * @see #isUninstallAllowed()
63    */
64    public static final String PROPERTY_UNINSTALLALLOWED = "uninstallAllowed";
65   
66    /**
67    * @see #getRewriter()
68    */
69    public static final String PROPERTY_REWRITER = "rewriter";
70   
71    /**
72    * Serialization identifier.
73    */
74    private static final long serialVersionUID = 1L;
75   
76    /**
77    * Default constructor.
78    */
 
79  289 toggle public AbstractExtensionRequest()
80    {
81  289 setProperty(PROPERTY_EXTENSIONS, new ArrayList<ExtensionId>());
82  289 setProperty(PROPERTY_EXCLUDEDEXTENSIONS, new HashSet<ExtensionId>());
83    }
84   
85    /**
86    * @param request the request to copy
87    */
 
88  203 toggle public AbstractExtensionRequest(Request request)
89    {
90  203 super(request);
91   
92  203 Collection<ExtensionId> extensions = getExtensions();
93  203 if (extensions == null) {
94  0 setProperty(PROPERTY_EXTENSIONS, new ArrayList<ExtensionId>());
95    }
96    }
97   
 
98  3462 toggle @Override
99    public Collection<ExtensionId> getExtensions()
100    {
101  3462 return getProperty(PROPERTY_EXTENSIONS);
102    }
103   
104    /**
105    * @return extensions to not take into account
106    */
 
107  237 toggle public Collection<ExtensionId> getExcludedExtensions()
108    {
109  237 return getProperty(PROPERTY_EXCLUDEDEXTENSIONS);
110    }
111   
 
112  1823 toggle @Override
113    public Collection<String> getNamespaces()
114    {
115  1823 return getProperty(PROPERTY_NAMESPACES);
116    }
117   
 
118  323 toggle @Override
119    public boolean hasNamespaces()
120    {
121  323 Collection<String> namespaces = getNamespaces();
122   
123  323 return namespaces != null && !namespaces.isEmpty();
124    }
125   
126    /**
127    * @param extensionId the extension identifier
128    */
 
129  265 toggle public void addExtension(ExtensionId extensionId)
130    {
131  265 getExtensions().add(extensionId);
132    }
133   
134    /**
135    * @param extensionId the extension identifier
136    */
 
137  0 toggle public void addExcludedExtension(ExtensionId extensionId)
138    {
139  0 getExcludedExtensions().add(extensionId);
140    }
141   
142    /**
143    * @param namespace the namespace
144    */
 
145  168 toggle public void addNamespace(String namespace)
146    {
147  168 Collection<String> namespaces = getNamespaces();
148   
149  168 if (namespaces == null) {
150  164 namespaces = new ArrayList<>();
151  164 setProperty(PROPERTY_NAMESPACES, namespaces);
152    }
153   
154  168 namespaces.add(namespace);
155    }
156   
 
157  715 toggle @Override
158    public boolean isRootModificationsAllowed()
159    {
160  715 return getProperty(PROPERTY_ROOTMODIFICATIONSALLOWED, true);
161    }
162   
163    /**
164    * @param allowed indicate if it's allowed to do modifications on root namespace during the job execution (not taken
165    * into account if the target of the request is root namespace)
166    */
 
167  161 toggle public void setRootModificationsAllowed(boolean allowed)
168    {
169  161 setProperty(PROPERTY_ROOTMODIFICATIONSALLOWED, allowed);
170    }
171   
172    /**
173    * Allow modifying manipulated {@link Extension}s on the fly (change allowed namespaces, dependencies, etc.).
174    *
175    * @param rewriter the filter
176    * @since 8.4.2
177    * @since 9.0RC1
178    */
 
179  23 toggle @Transient
180    public void setRewriter(ExtensionRewriter rewriter)
181    {
182  23 setProperty(PROPERTY_REWRITER, rewriter);
183    }
184   
 
185  1075 toggle @Override
186    @Transient
187    public ExtensionRewriter getRewriter()
188    {
189  1075 return getProperty(PROPERTY_REWRITER);
190    }
191   
 
192  119 toggle @Override
193    public boolean isUninstallAllowed()
194    {
195  119 return getProperty(PROPERTY_UNINSTALLALLOWED, true);
196    }
197   
198    /**
199    * @param allowed true if it's allowed remove extension in conflict with the new extension(s)
200    * @since 9.1RC1
201    */
 
202  1 toggle public void setUninstallAllowed(boolean allowed)
203    {
204  1 setProperty(PROPERTY_UNINSTALLALLOWED, allowed);
205    }
206    }