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

File DefaultCoreExtension.java

 

Coverage histogram

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

Code metrics

0
21
16
1
191
90
16
0.76
1.31
16
1

Classes

Class Line # Actions
DefaultCoreExtension 37 21 0% 16 6
0.837837883.8%
 

Contributing tests

This file is covered by 10 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.repository.internal.core;
21   
22    import java.net.URL;
23    import java.util.Collection;
24   
25    import org.xwiki.extension.AbstractExtension;
26    import org.xwiki.extension.CoreExtension;
27    import org.xwiki.extension.Extension;
28    import org.xwiki.extension.ExtensionDependency;
29    import org.xwiki.extension.ExtensionId;
30   
31    /**
32    * Default implementation of {@link CoreExtension}.
33    *
34    * @version $Id: a79c31a0ff260b4757ad6bcd6b097a9ffc8ca188 $
35    * @since 4.0M1
36    */
 
37    public class DefaultCoreExtension extends AbstractExtension implements CoreExtension
38    {
39    /**
40    * @see #getDescriptorURL()
41    */
42    private static final String PKEY_DESCRIPTORURL = "core.descriptorurl";
43   
44    /**
45    * @see #isComplete()
46    */
47    private boolean complete;
48   
49    /**
50    * @param repository the core extension repository
51    * @param url the core extension URL
52    * @param id the id/version combination which makes the extension unique
53    * @param type the type of the extension
54    */
 
55  13947 toggle public DefaultCoreExtension(DefaultCoreExtensionRepository repository, URL url, ExtensionId id, String type)
56    {
57  13947 super(repository, id, type);
58   
59  13947 setURL(url);
60    }
61   
62    // Extension
63   
64    /**
65    * Copy the passed {@link Extension} but filter useless stuff from {@link CoreExtension} point of view like managed
66    * dependencies.
67    *
68    * @param repository the core extension repository
69    * @param url the core extension URL
70    * @param extension the extension to copy
71    */
 
72  10899 toggle public DefaultCoreExtension(DefaultCoreExtensionRepository repository, URL url, Extension extension)
73    {
74  10899 super(repository, extension);
75   
76  10899 setURL(url);
77    }
78   
 
79  10919 toggle @Override
80    public void setAllowedNamespaces(Collection<String> namespaces)
81    {
82    // Filter useless stuff from {@link CoreExtension} point of view that could take a lot of memory in the end
83    // TODO: dynamically load it from the cache when possible
84    }
85   
 
86  22696 toggle @Override
87    public void setManagedDependencies(Collection<? extends ExtensionDependency> managedDependencies)
88    {
89    // Filter useless stuff from {@link CoreExtension} point of view that could take a lot of memory in the end
90    // TODO: dynamically load it from the cache when possible
91    }
92   
93    /**
94    * @return true if the extension come from a complete descriptor (xed file, the cache, etc.)
95    * @since 8.4RC1
96    */
 
97  805 toggle public boolean isComplete()
98    {
99  805 return this.complete;
100    }
101   
102    /**
103    * @param complete true if the extension come from a complete descriptor (xed file, the cache, etc.)
104    * @since 8.4RC1
105    */
 
106  12054 toggle public void setComplete(boolean complete)
107    {
108  12054 this.complete = complete;
109    }
110   
 
111  0 toggle @Override
112    public void setId(ExtensionId id)
113    {
114  0 super.setId(id);
115    }
116   
 
117  0 toggle @Override
118    public void setType(String type)
119    {
120  0 super.setType(type);
121    }
122   
123    // CoreExtension
124   
 
125  10918 toggle @Override
126    public URL getURL()
127    {
128  10918 return getProperty(PKEY_URL, null);
129    }
130   
131    /**
132    * @param url the {@link URL} pointing to the core extension file
133    */
 
134  35764 toggle public void setURL(URL url)
135    {
136  35764 setFile(new DefaultCoreExtensionFile(url));
137   
138  35764 putProperty(PKEY_URL, url);
139    }
140   
141    /**
142    * @return the {@link URL} pointing to the core extension descriptor (usually inside the extension file)
143    */
 
144  12748 toggle public URL getDescriptorURL()
145    {
146  12748 return getProperty(PKEY_DESCRIPTORURL, null);
147    }
148   
149    /**
150    * @param descriptorURL the {@link URL} pointing to the core extension descriptor (usually inside the extension
151    * file)
152    */
 
153  32995 toggle public void setDescriptorURL(URL descriptorURL)
154    {
155  32995 putProperty(PKEY_DESCRIPTORURL, descriptorURL);
156    }
157   
 
158  0 toggle @Override
159    public boolean isGuessed()
160    {
161  0 return getProperty(PKEY_GUESSED, false);
162    }
163   
164    /**
165    * @param guessed true if the extension is "guessed"
166    */
 
167  2000 toggle public void setGuessed(boolean guessed)
168    {
169  2000 putProperty(PKEY_GUESSED, guessed);
170    }
171   
172    // Object
173   
 
174  5570 toggle @Override
175    public String toString()
176    {
177  5570 return getId().toString();
178    }
179   
 
180  10918 toggle @Override
181    public void set(Extension extension)
182    {
183  10918 URL url = getURL();
184  10918 URL descriptorURL = getDescriptorURL();
185   
186  10918 super.set(extension);
187   
188  10918 setURL(url);
189  10918 setDescriptorURL(descriptorURL);
190    }
191    }