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

File InstalledExtensionSynchronizer.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
14
3
1
111
59
6
0.43
4.67
3
2

Classes

Class Line # Actions
InstalledExtensionSynchronizer 51 14 0% 6 1
0.9523809695.2%
 

Contributing tests

This file is covered by 22 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.xar.internal.repository;
21   
22    import java.util.Collection;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26    import javax.inject.Singleton;
27   
28    import org.slf4j.Logger;
29    import org.xwiki.component.annotation.Component;
30    import org.xwiki.extension.InstalledExtension;
31    import org.xwiki.extension.event.ExtensionEvent;
32    import org.xwiki.extension.event.ExtensionInstalledEvent;
33    import org.xwiki.extension.event.ExtensionUninstalledEvent;
34    import org.xwiki.extension.event.ExtensionUpgradedEvent;
35    import org.xwiki.extension.repository.InstalledExtensionRepository;
36    import org.xwiki.extension.xar.internal.handler.UnsupportedNamespaceException;
37    import org.xwiki.extension.xar.internal.handler.XarExtensionHandler;
38    import org.xwiki.observation.AbstractEventListener;
39    import org.xwiki.observation.event.Event;
40   
41    /**
42    * Maintain extension stored in {@link XarInstalledExtensionRepository} in sync with the standard
43    * {@link InstalledExtensionRepository} component.
44    *
45    * @version $Id: 1cb88995bef17516d4b34538b4f8cbea82c6ad0d $
46    * @since 8.1M2
47    */
48    @Component
49    @Named("org.xwiki.extension.xar.internal.repository.InstalledExtensionSynchronizer")
50    @Singleton
 
51    public class InstalledExtensionSynchronizer extends AbstractEventListener
52    {
53    @Inject
54    @Named(XarExtensionHandler.TYPE)
55    private InstalledExtensionRepository xarRepository;
56   
57    @Inject
58    private Logger logger;
59   
60    /**
61    * Default constructor.
62    */
 
63  101 toggle public InstalledExtensionSynchronizer()
64    {
65  101 super(InstalledExtensionSynchronizer.class.getName(), new ExtensionInstalledEvent(),
66    new ExtensionUninstalledEvent(), new ExtensionUpgradedEvent());
67    }
68   
 
69  1260 toggle private XarInstalledExtensionRepository getXarRepository()
70    {
71  1260 return (XarInstalledExtensionRepository) this.xarRepository;
72    }
73   
 
74  517 toggle @Override
75    public void onEvent(Event event, Object source, Object data)
76    {
77  517 ExtensionEvent extensionEvent = (ExtensionEvent) event;
78   
79  517 try {
80  517 if (extensionEvent instanceof ExtensionUninstalledEvent) {
81    // Update documents index
82  27 getXarRepository().pagesRemoved(extensionEvent.getExtensionId(), extensionEvent.getNamespace());
83   
84    // Update extension cache
85  27 getXarRepository().updateCachedXarExtension(extensionEvent.getExtensionId());
86    } else {
87    // Previous extensions
88   
89  490 if (data != null) {
90  113 for (InstalledExtension installedExtension : (Collection<InstalledExtension>) data) {
91    // Update documents index
92  113 getXarRepository().pagesRemoved(installedExtension.getId(), extensionEvent.getNamespace());
93   
94    // Update extension cache
95  113 getXarRepository().updateCachedXarExtension(installedExtension.getId());
96    }
97    }
98   
99    // New extension
100   
101    // Update extension cache
102  490 getXarRepository().updateCachedXarExtension(extensionEvent.getExtensionId());
103   
104    // Update documents index
105  490 getXarRepository().pagesAdded(extensionEvent.getExtensionId(), extensionEvent.getNamespace());
106    }
107    } catch (UnsupportedNamespaceException e) {
108  0 logger.error("Failed to extract wiki from namespace [{}]", extensionEvent.getNamespace());
109    }
110    }
111    }