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

File AbstractExtensionHandler.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart6.png
69% of files have more coverage

Code metrics

2
9
6
1
110
65
8
0.89
1.5
6
1.33

Classes

Class Line # Actions
AbstractExtensionHandler 46 9 0% 8 7
0.588235358.8%
 

Contributing tests

This file is covered by 99 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.Provider;
28   
29    import org.slf4j.Logger;
30    import org.xwiki.extension.Extension;
31    import org.xwiki.extension.ExtensionException;
32    import org.xwiki.extension.InstallException;
33    import org.xwiki.extension.InstalledExtension;
34    import org.xwiki.extension.LocalExtension;
35    import org.xwiki.extension.UninstallException;
36    import org.xwiki.extension.handler.ExtensionHandler;
37    import org.xwiki.extension.handler.ExtensionValidator;
38    import org.xwiki.job.Request;
39   
40    /**
41    * Base class for {@link ExtensionHandler} implementations.
42    *
43    * @version $Id: 4ed302dfb228f0dab467617d856d8cc5796a2cf8 $
44    * @since 4.0M1
45    */
 
46    public abstract class AbstractExtensionHandler implements ExtensionHandler
47    {
48    /**
49    * The logger to log.
50    */
51    @Inject
52    protected Logger logger;
53   
54    /**
55    * Used to check if an extension it is possible to install/uninstall a given extension.
56    */
57    @Inject
58    private Provider<ExtensionValidator> defaultValidatorProvider;
59   
60    // ExtensionHandler
61   
 
62  0 toggle @Override
63    @Deprecated
64    public void uninstall(LocalExtension localExtension, String namespace, Request request) throws UninstallException
65    {
66  0 uninstall((InstalledExtension) localExtension, namespace, request);
67    }
68   
 
69  0 toggle @Override
70    @Deprecated
71    public void upgrade(LocalExtension previousLocalExtension, LocalExtension newLocalExtension, String namespace,
72    Request request) throws InstallException
73    {
74  0 upgrade(previousLocalExtension != null ? Arrays.asList((InstalledExtension) previousLocalExtension)
75    : Collections.<InstalledExtension>emptyList(), newLocalExtension, namespace, request);
76    }
77   
 
78  8 toggle @Override
79    public void upgrade(Collection<InstalledExtension> previousInstalledExtensions, LocalExtension newLocalExtension,
80    String namespace, Request request) throws InstallException
81    {
82  8 for (InstalledExtension previousExtension : previousInstalledExtensions) {
83  8 try {
84  8 uninstall(previousExtension, namespace, request);
85    } catch (UninstallException e) {
86  0 throw new InstallException("Failed to uninstall previous extension [" + previousExtension + "]", e);
87    }
88    }
89  8 install(newLocalExtension, namespace, null);
90    }
91   
 
92  31 toggle @Override
93    public void initialize(LocalExtension localExtension, String namespace) throws ExtensionException
94    {
95    // do nothing by default
96    }
97   
 
98  248 toggle @Override
99    public void checkInstall(Extension extension, String namespace, Request request) throws InstallException
100    {
101  248 this.defaultValidatorProvider.get().checkInstall(extension, namespace, request);
102    }
103   
 
104  104 toggle @Override
105    public void checkUninstall(InstalledExtension extension, String namespace, Request request)
106    throws UninstallException
107    {
108  104 this.defaultValidatorProvider.get().checkUninstall(extension, namespace, request);
109    }
110    }