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

File ExtensionFactory.java

 

Coverage histogram

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

Code metrics

4
20
12
1
225
89
14
0.7
1.67
12
1.17

Classes

Class Line # Actions
ExtensionFactory 51 20 0% 14 4
0.888888988.9%
 

Contributing tests

This file is covered by 126 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;
21   
22    import java.net.URI;
23    import java.util.Map;
24   
25    import javax.inject.Singleton;
26   
27    import org.xwiki.collection.SoftCache;
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.extension.DefaultExtensionAuthor;
30    import org.xwiki.extension.DefaultExtensionDependency;
31    import org.xwiki.extension.DefaultExtensionIssueManagement;
32    import org.xwiki.extension.Extension;
33    import org.xwiki.extension.ExtensionAuthor;
34    import org.xwiki.extension.ExtensionDependency;
35    import org.xwiki.extension.ExtensionIssueManagement;
36    import org.xwiki.extension.repository.DefaultExtensionRepositoryDescriptor;
37    import org.xwiki.extension.repository.ExtensionRepositoryDescriptor;
38    import org.xwiki.extension.version.Version;
39    import org.xwiki.extension.version.VersionConstraint;
40    import org.xwiki.extension.version.internal.DefaultVersion;
41    import org.xwiki.extension.version.internal.DefaultVersionConstraint;
42   
43    /**
44    * Allow sharing the same instance for various part of {@link Extension}s.
45    *
46    * @version $Id: 711bb88e683b230311753413d5824a04c409a80c $
47    * @since 8.4
48    */
49    @Component(roles = ExtensionFactory.class)
50    @Singleton
 
51    public class ExtensionFactory
52    {
53    private SoftCache<ExtensionDependency, ExtensionDependency> dependencies = new SoftCache<>();
54   
55    private SoftCache<ExtensionAuthor, ExtensionAuthor> authors = new SoftCache<>();
56   
57    private SoftCache<ExtensionRepositoryDescriptor, ExtensionRepositoryDescriptor> repositories = new SoftCache<>();
58   
59    private SoftCache<ExtensionIssueManagement, ExtensionIssueManagement> issueManagements = new SoftCache<>();
60   
61    private SoftCache<String, Version> versions = new SoftCache<>();
62   
63    private SoftCache<String, VersionConstraint> versionConstrains = new SoftCache<>();
64   
65    /**
66    * Store and return a weak reference equals to the passed {@link ExtensionDependency}.
67    *
68    * @param dependency the {@link ExtensionDependency} to find
69    * @return unique instance of {@link ExtensionDependency} equals to the passed one
70    */
 
71  3434613 toggle public ExtensionDependency getExtensionDependency(ExtensionDependency dependency)
72    {
73  3434613 return this.dependencies.get(dependency, dependency);
74    }
75   
76    /**
77    * Store and return a weak reference equals to the passed {@link ExtensionDependency}.
78    *
79    * @param id the id of the extension dependency
80    * @param versionConstraint the version constraint of the extension dependency
81    * @param optional true if the dependency is optional
82    * @param properties the custom properties of the extension dependency
83    * @return unique instance of {@link ExtensionDependency} equals to the passed one
84    * @since 9.6RC1
85    */
 
86  1893505 toggle public ExtensionDependency getExtensionDependency(String id, VersionConstraint versionConstraint, boolean optional,
87    Map<String, Object> properties)
88    {
89  1893505 return getExtensionDependency(new DefaultExtensionDependency(id, versionConstraint, optional, properties));
90    }
91   
92    /**
93    * Store and return a weak reference equals to the passed {@link ExtensionAuthor}.
94    *
95    * @param author the {@link ExtensionAuthor} to find
96    * @return unique instance of {@link ExtensionAuthor} equals to the passed one
97    */
 
98  142064 toggle public ExtensionAuthor getExtensionAuthor(ExtensionAuthor author)
99    {
100  142064 return this.authors.get(author, author);
101    }
102   
103    /**
104    * Store and return a weak reference equals to the passed {@link ExtensionAuthor}.
105    *
106    * @param name the name of the author
107    * @param url the url of the author public profile
108    * @return unique instance of {@link ExtensionAuthor} equals to the passed one
109    */
 
110  142064 toggle public ExtensionAuthor getExtensionAuthor(String name, String url)
111    {
112  142064 return getExtensionAuthor(new DefaultExtensionAuthor(name, url));
113    }
114   
115    /**
116    * Store and return a weak reference equals to the passed {@link ExtensionRepositoryDescriptor}.
117    *
118    * @param repository the {@link ExtensionRepositoryDescriptor} to find
119    * @return unique instance of {@link ExtensionRepositoryDescriptor} equals to the passed one
120    */
 
121  36294 toggle public ExtensionRepositoryDescriptor getExtensionRepositoryDescriptor(ExtensionRepositoryDescriptor repository)
122    {
123  36294 return this.repositories.get(repository, repository);
124    }
125   
126    /**
127    * Store and return a weak reference equals to the passed {@link ExtensionRepositoryDescriptor} elements.
128    *
129    * @param id the unique identifier
130    * @param type the repository type (maven, xwiki, etc.)
131    * @param uri the repository address
132    * @return unique instance of {@link ExtensionRepositoryDescriptor} equals to the passed one
133    */
 
134  36294 toggle public ExtensionRepositoryDescriptor getExtensionRepositoryDescriptor(String id, String type, URI uri)
135    {
136  36294 return getExtensionRepositoryDescriptor(new DefaultExtensionRepositoryDescriptor(id, type, uri));
137    }
138   
139    /**
140    * Store and return a weak reference equals to the passed {@link ExtensionIssueManagement}.
141    *
142    * @param issueManagement the {@link ExtensionIssueManagement} to find
143    * @return unique instance of {@link ExtensionIssueManagement} equals to the passed one
144    */
 
145  26621 toggle public ExtensionIssueManagement getExtensionIssueManagement(ExtensionIssueManagement issueManagement)
146    {
147  26621 return this.issueManagements.get(issueManagement, issueManagement);
148    }
149   
150    /**
151    * Store and return a weak reference equals to the passed {@link ExtensionIssueManagement} elements.
152    *
153    * @param system the name of the issue management system (jira, bugzilla, etc.)
154    * @param url the URL of that extension in the issues management system
155    * @return unique instance of {@link ExtensionIssueManagement} equals to the passed one
156    */
 
157  26621 toggle public ExtensionIssueManagement getExtensionIssueManagement(String system, String url)
158    {
159  26621 return getExtensionIssueManagement(new DefaultExtensionIssueManagement(system, url));
160    }
161   
162    /**
163    * Store and return a weak reference equals to the passed {@link Version}.
164    *
165    * @param version the {@link Version} to find
166    * @return unique instance of {@link Version} equals to the passed one
167    */
 
168  0 toggle public Version getVersion(Version version)
169    {
170    // Use the initial value as key because it's displayed and for example displaying "1.0" instead of "1.0.0.GA"
171    // might produce a WTF effect even if it's exactly the same version.
172  0 return this.versions.get(version.getValue(), version);
173    }
174   
175    /**
176    * Store and return a weak reference equals to the passed version.
177    *
178    * @param rawVersion the version to find
179    * @return unique instance of {@link VersionConstraint} equals to the passed one
180    */
 
181  43711 toggle public Version getVersion(String rawVersion)
182    {
183  43711 Version version = this.versions.get(rawVersion);
184   
185  43711 if (version == null) {
186  13228 version = new DefaultVersion(rawVersion);
187   
188  13228 this.versions.put(rawVersion, version);
189    }
190   
191  43711 return version;
192    }
193   
194    /**
195    * Store and return a weak reference equals to the passed {@link VersionConstraint}.
196    *
197    * @param versionConstraint the {@link VersionConstraint} to find
198    * @return unique instance of {@link VersionConstraint} equals to the passed one
199    */
 
200  0 toggle public VersionConstraint getVersionConstraint(VersionConstraint versionConstraint)
201    {
202    // Use the initial value as key because it's displayed and for example displaying "[1.0]" instead of
203    // "[1.0.0.GA]" might produce a WTF effect even if it's exactly the same version constraint.
204  0 return this.versionConstrains.get(versionConstraint.getValue(), versionConstraint);
205    }
206   
207    /**
208    * Store and return a weak reference equals to the passed version constraint.
209    *
210    * @param rawConstraint the version constraint to find
211    * @return unique instance of {@link VersionConstraint} equals to the passed one
212    */
 
213  1891756 toggle public VersionConstraint getVersionConstraint(String rawConstraint)
214    {
215  1891756 VersionConstraint constraint = this.versionConstrains.get(rawConstraint);
216   
217  1891756 if (constraint == null) {
218  22648 constraint = new DefaultVersionConstraint(rawConstraint);
219   
220  22648 this.versionConstrains.put(rawConstraint, constraint);
221    }
222   
223  1891756 return constraint;
224    }
225    }