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

File ExtensionApplicationStartedListener.java

 

Coverage histogram

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

Code metrics

2
6
3
1
101
51
6
1
2
3
2

Classes

Class Line # Actions
ExtensionApplicationStartedListener 50 6 0% 6 0
1.0100%
 

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   
21    package org.xwiki.extension.internal;
22   
23    import java.util.Collections;
24    import java.util.List;
25   
26    import javax.inject.Inject;
27    import javax.inject.Named;
28    import javax.inject.Provider;
29    import javax.inject.Singleton;
30   
31    import org.xwiki.component.annotation.Component;
32    import org.xwiki.extension.ExtensionManagerConfiguration;
33    import org.xwiki.extension.handler.ExtensionInitializer;
34    import org.xwiki.extension.repository.CoreExtensionRepository;
35    import org.xwiki.extension.repository.ExtensionRepositoryManager;
36    import org.xwiki.extension.repository.internal.core.DefaultCoreExtensionRepository;
37    import org.xwiki.observation.EventListener;
38    import org.xwiki.observation.event.ApplicationStartedEvent;
39    import org.xwiki.observation.event.Event;
40   
41    /**
42    * An application started listener to initialize extensions.
43    *
44    * @version $Id: cde3f75f22019f9bfe0e5c9be7e0b966477fe91f $
45    * @since 4.0M1
46    */
47    @Component
48    @Singleton
49    @Named("ExtensionApplicationStartedListener")
 
50    public class ExtensionApplicationStartedListener implements EventListener
51    {
52    /**
53    * The list of events observed.
54    */
55    private static final List<Event> EVENTS = Collections.<Event>singletonList(new ApplicationStartedEvent());
56   
57    @Inject
58    private Provider<CoreExtensionRepository> coreExtensionsProvider;
59   
60    @Inject
61    private Provider<ExtensionManagerConfiguration> configuration;
62   
63    @Inject
64    private Provider<ExtensionRepositoryManager> repositoryManagerProvider;
65   
66    /**
67    * The extension initializer.
68    * <p>
69    * Use it only when receiving an {@link ApplicationStartedEvent} event.
70    */
71    @Inject
72    private Provider<ExtensionInitializer> extensionInitializer;
73   
 
74  297 toggle @Override
75    public List<Event> getEvents()
76    {
77  297 return EVENTS;
78    }
79   
 
80  1107 toggle @Override
81    public String getName()
82    {
83  1107 return "ExtensionApplicationStartedListener";
84    }
85   
 
86  39 toggle @Override
87    public void onEvent(Event arg0, Object arg1, Object arg2)
88    {
89    // Make sure installed extensions are initialized (it might have already been done but it's OK since initialize
90    // is automatically called only once)
91  39 this.extensionInitializer.get();
92   
93    // Update core extension informations
94    // Only if enabled and only if there is any remote extension repositories enabled
95  39 CoreExtensionRepository coreExtensions = this.coreExtensionsProvider.get();
96  39 if (coreExtensions instanceof DefaultCoreExtensionRepository && this.configuration.get().resolveCoreExtensions()
97    && !this.repositoryManagerProvider.get().getRepositories().isEmpty()) {
98  10 ((DefaultCoreExtensionRepository) coreExtensions).updateExtensions();
99    }
100    }
101    }