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

File AbstractExtensionRequest.java

 

Coverage histogram

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

Code metrics

6
24
13
1
189
94
16
0.67
1.85
13
1.23

Classes

Class Line # Actions
AbstractExtensionRequest 40 24 0% 16 5
0.8837209388.4%
 

Contributing tests

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