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

File WikisDefaultUIDistributionStep.java

 

Coverage histogram

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

Code metrics

10
20
2
1
107
64
9
0.45
10
2
4.5

Classes

Class Line # Actions
WikisDefaultUIDistributionStep 47 20 0% 9 32
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.InstalledExtension;
33    import org.xwiki.extension.distribution.internal.DistributionManager;
34    import org.xwiki.extension.repository.InstalledExtensionRepository;
35    import org.xwiki.wiki.descriptor.WikiDescriptorManager;
36    import org.xwiki.wiki.manager.WikiManagerException;
37   
38    /**
39    * Optional step to install sub-wikis default UI extensions.
40    *
41    * @version $Id: b9a46f0f4cc6b6b0066d60d8c4a43c26943ee70f $
42    * @since 5.2RC1
43    */
44    @Component
45    @Named(WikisDefaultUIDistributionStep.ID)
46    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
47    public class WikisDefaultUIDistributionStep extends AbstractDistributionStep
48    {
49    public static final String ID = "extension.defaultui.wikis";
50   
51    @Inject
52    private transient InstalledExtensionRepository installedRepository;
53   
54    /**
55    * The component used to get information about the current distribution.
56    */
57    @Inject
58    protected transient DistributionManager distributionManager;
59   
60    @Inject
61    private transient Logger logger;
62   
 
63  0 toggle public WikisDefaultUIDistributionStep()
64    {
65  0 super(ID);
66    }
67   
 
68  0 toggle @Override
69    public void prepare()
70    {
71  0 if (getState() == null) {
72  0 setState(State.COMPLETED);
73   
74  0 if (isMainWiki()) {
75  0 WikiDescriptorManager wikiDescriptorManager = this.wikiDescriptorManagerProvider.get();
76   
77  0 Collection<String> wikiIds;
78  0 try {
79  0 wikiIds = wikiDescriptorManager.getAllIds();
80    } catch (WikiManagerException e) {
81  0 this.logger.error("Failed to get the list of wikis", e);
82  0 setState(null);
83  0 return;
84    }
85   
86  0 ExtensionId wikiExtensionUI = this.distributionManager.getWikiUIExtensionId();
87   
88  0 for (String wikiId : wikiIds) {
89  0 if (!wikiDescriptorManager.getMainWikiId().equals(wikiId)) {
90  0 String namespace = "wiki:" + wikiId;
91   
92    // Only if the UI is not already installed
93  0 if (wikiExtensionUI != null) {
94  0 InstalledExtension installedExtension =
95    this.installedRepository.getInstalledExtension(wikiExtensionUI.getId(), namespace);
96  0 if (installedExtension == null
97    || !installedExtension.getId().getVersion().equals(wikiExtensionUI.getVersion())) {
98  0 setState(null);
99  0 return;
100    }
101    }
102    }
103    }
104    }
105    }
106    }
107    }