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

File DefaultExtensionHandlerManager.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart7.png
64% of files have more coverage

Code metrics

2
30
7
1
159
105
17
0.57
4.29
7
2.43

Classes

Class Line # Actions
DefaultExtensionHandlerManager 49 30 0% 17 14
0.6410256664.1%
 

Contributing tests

This file is covered by 80 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.handler.internal;
21   
22    import java.util.Arrays;
23    import java.util.Collection;
24    import java.util.Collections;
25   
26    import javax.inject.Inject;
27    import javax.inject.Singleton;
28   
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.component.manager.ComponentLookupException;
31    import org.xwiki.component.manager.ComponentManager;
32    import org.xwiki.extension.ExtensionException;
33    import org.xwiki.extension.InstallException;
34    import org.xwiki.extension.InstalledExtension;
35    import org.xwiki.extension.LocalExtension;
36    import org.xwiki.extension.UninstallException;
37    import org.xwiki.extension.handler.ExtensionHandler;
38    import org.xwiki.extension.handler.ExtensionHandlerManager;
39    import org.xwiki.job.Request;
40   
41    /**
42    * Default implementation of {@link ExtensionHandlerManager}.
43    *
44    * @version $Id: 3a8cb0a00d2296fa5a3fe99df2870252f5bc4ad3 $
45    * @since 4.0M1
46    */
47    @Component
48    @Singleton
 
49    public class DefaultExtensionHandlerManager implements ExtensionHandlerManager
50    {
51    /**
52    * Message used when falling to find a proper extension handler.
53    */
54    private static final String LOOKUPERROR = "Can't find any extension handler for the extension ";
55   
56    /**
57    * Use to lookup {@link ExtensionHandler} implementations.
58    */
59    @Inject
60    private ComponentManager componentManager;
61   
62    /**
63    * Get the handler corresponding to the provided extension.
64    *
65    * @param localExtension the extension to handler
66    * @return the handler
67    * @throws ComponentLookupException failed to find a proper handler for the provided extension
68    */
 
69  1602 toggle private ExtensionHandler getExtensionHandler(LocalExtension localExtension) throws ComponentLookupException
70    {
71  1602 return this.componentManager.getInstance(ExtensionHandler.class, localExtension.getType().toLowerCase());
72    }
73   
 
74  166 toggle @Override
75    public void install(LocalExtension localExtension, String namespace, Request request) throws InstallException
76    {
77  166 ExtensionHandler extensionHandler;
78  166 try {
79  166 extensionHandler = getExtensionHandler(localExtension);
80    } catch (ComponentLookupException e) {
81  0 throw new InstallException(LOOKUPERROR + '[' + localExtension + ']', e);
82    }
83   
84  166 try {
85  166 extensionHandler.install(localExtension, namespace, request);
86    } catch (Exception e) {
87  1 throw new InstallException("Failed to install extension [" + localExtension.getId() + "]", e);
88    }
89    }
90   
 
91  0 toggle @Override
92    @Deprecated
93    public void uninstall(LocalExtension localExtension, String namespace, Request request) throws UninstallException
94    {
95  0 uninstall((InstalledExtension) localExtension, namespace, request);
96    }
97   
 
98  91 toggle @Override
99    public void uninstall(InstalledExtension installedExtension, String namespace, Request request)
100    throws UninstallException
101    {
102  91 ExtensionHandler extensionHandler;
103  91 try {
104  91 extensionHandler = getExtensionHandler(installedExtension);
105    } catch (ComponentLookupException e) {
106  0 throw new UninstallException(LOOKUPERROR + '[' + installedExtension + ']', e);
107    }
108   
109  91 try {
110  91 extensionHandler.uninstall(installedExtension, namespace, request);
111    } catch (UninstallException e) {
112  0 throw e;
113    } catch (Exception e) {
114  0 throw new UninstallException("Failed to uninstall extension [" + installedExtension.getId() + "]", e);
115    }
116    }
117   
 
118  0 toggle @Override
119    @Deprecated
120    public void upgrade(LocalExtension previousLocalExtension, LocalExtension newLocalExtension, String namespace,
121    Request request) throws InstallException
122    {
123  0 upgrade(previousLocalExtension != null ? Arrays.asList((InstalledExtension) previousLocalExtension)
124    : Collections.<InstalledExtension>emptyList(), newLocalExtension, namespace, request);
125    }
126   
 
127  14 toggle @Override
128    public void upgrade(Collection<InstalledExtension> previousLocalExtensions, LocalExtension newLocalExtension,
129    String namespace, Request request) throws InstallException
130    {
131  14 ExtensionHandler extensionHandler;
132  14 try {
133  14 extensionHandler = getExtensionHandler(newLocalExtension);
134    } catch (ComponentLookupException e) {
135  0 throw new InstallException(LOOKUPERROR + '[' + newLocalExtension + ']', e);
136    }
137   
138  14 try {
139  14 extensionHandler.upgrade(previousLocalExtensions, newLocalExtension, namespace, request);
140    } catch (InstallException e) {
141  0 throw e;
142    } catch (Exception e) {
143  0 throw new InstallException("Failed to upgrade from extension [" + previousLocalExtensions
144    + "] to extension [" + newLocalExtension.getId() + "]", e);
145    }
146    }
147   
 
148  1331 toggle @Override
149    public void initialize(LocalExtension localExtension, String namespace) throws ExtensionException
150    {
151  1331 try {
152  1331 ExtensionHandler extensionHandler = getExtensionHandler(localExtension);
153   
154  1331 extensionHandler.initialize(localExtension, namespace);
155    } catch (Exception e) {
156  0 throw new InstallException("Failed to initialize extension [" + localExtension.getId() + "]", e);
157    }
158    }
159    }