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

File WikisFlavorDistributionStep.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart0.png
83% of files have more coverage

Code metrics

8
21
2
1
109
60
8
0.38
10.5
2
4

Classes

Class Line # Actions
WikisFlavorDistributionStep 46 21 0% 8 31
0.00%
 

Contributing tests

No tests hitting this source file were found.

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.distribution.internal.job.step;
21   
22    import java.util.Collection;
23   
24    import javax.inject.Inject;
25    import javax.inject.Named;
26   
27    import org.slf4j.Logger;
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.component.annotation.InstantiationStrategy;
30    import org.xwiki.component.descriptor.ComponentInstantiationStrategy;
31    import org.xwiki.extension.ExtensionId;
32    import org.xwiki.extension.repository.InstalledExtensionRepository;
33    import org.xwiki.platform.flavor.FlavorManager;
34    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
35    import org.xwiki.wiki.manager.WikiManagerException;
36   
37    /**
38    * Optional step to install sub-wikis default UI extensions.
39    *
40    * @version $Id: 6a7fdf457d3ab1201789b913f835f5d89e4baa60 $
41    * @since 7.1M1
42    */
43    @Component
44    @Named(WikisFlavorDistributionStep.ID)
45    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
46    public class WikisFlavorDistributionStep extends AbstractDistributionStep
47    {
48    /**
49    * ID of the distribution step.
50    */
51    public static final String ID = "extension.flavor.wikis";
52   
53    /**
54    * The flavor manager.
55    */
56    private transient FlavorManager flavorManager;
57   
58    @Inject
59    private transient InstalledExtensionRepository installedRepository;
60   
61    @Inject
62    private transient Logger logger;
63   
64    /**
65    * Constructs a new WikisFlavorDistributionStep.
66    */
 
67  0 toggle public WikisFlavorDistributionStep()
68    {
69  0 super(ID);
70    }
71   
 
72  0 toggle @Override
73    public void prepare()
74    {
75  0 if (getState() == null) {
76  0 setState(State.COMPLETED);
77   
78  0 if (!isMainWiki()) {
79  0 return;
80    }
81   
82  0 WikiDescriptorManager wikiDescriptorManager = this.wikiDescriptorManagerProvider.get();
83   
84  0 Collection<String> wikiIds;
85  0 try {
86  0 wikiIds = wikiDescriptorManager.getAllIds();
87    } catch (WikiManagerException e) {
88  0 this.logger.error("Failed to get the list of wikis", e);
89  0 setState(null);
90  0 return;
91    }
92   
93  0 String mainWiki = wikiDescriptorManager.getMainWikiId();
94   
95    // Enable if any of the wikis has no valid top level flavor extension
96  0 for (String wikiId : wikiIds) {
97  0 if (mainWiki.equals(wikiId)) {
98  0 continue;
99    }
100  0 String namespace = "wiki:" + wikiId;
101  0 ExtensionId flavor = flavorManager.getFlavorOfWiki(getWiki());
102  0 if (flavor == null || !installedRepository.getInstalledExtension(flavor).isValid(namespace)) {
103  0 setState(null);
104  0 return;
105    }
106    }
107    }
108    }
109    }