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

File OutdatedExtensionsDistributionStep.java

 

Coverage histogram

../../../../../../../img/srcFileCovDistChart4.png
78% of files have more coverage

Code metrics

12
24
2
1
109
68
8
0.33
12
2
4

Classes

Class Line # Actions
OutdatedExtensionsDistributionStep 43 24 0% 8 24
0.3684210536.8%
 

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.InstalledExtension;
32    import org.xwiki.extension.repository.InstalledExtensionRepository;
33   
34    /**
35    * List and allow to upgrade outdated extensions.
36    *
37    * @version $Id: 874765e797f5b01d0d2f24031f3db76552b6b429 $
38    * @since 5.0RC1
39    */
40    @Component
41    @Named(OutdatedExtensionsDistributionStep.ID)
42    @InstantiationStrategy(ComponentInstantiationStrategy.PER_LOOKUP)
 
43    public class OutdatedExtensionsDistributionStep extends AbstractDistributionStep
44    {
45    public static final String ID = "extension.outdatedextensions";
46   
47    @Inject
48    private transient InstalledExtensionRepository installedRepository;
49   
50    @Inject
51    private transient Logger logger;
52   
 
53  3 toggle public OutdatedExtensionsDistributionStep()
54    {
55  3 super(ID);
56    }
57   
 
58  4 toggle @Override
59    public void prepare()
60    {
61  4 if (getState() == null) {
62  1 setState(State.COMPLETED);
63   
64  1 if (isMainWiki()) {
65  0 Collection<InstalledExtension> installedExtensions = this.installedRepository.getInstalledExtensions();
66   
67    // Upgrade outdated extensions only when there is invalid extensions
68  0 for (InstalledExtension extension : installedExtensions) {
69  0 Collection<String> installedNamespaces = extension.getNamespaces();
70  0 if (installedNamespaces == null) {
71  0 if (!extension.isValid(null)) {
72  0 this.logger.debug("Enabling outdate extension step on main wiki "
73    + "because extension [{}] is invalid on root namespace", extension.getId());
74   
75  0 setState(null);
76  0 break;
77    }
78    } else {
79  0 for (String installedNamespace : installedNamespaces) {
80  0 if (!extension.isValid(installedNamespace)) {
81  0 this.logger.debug("Enabling outdate extension step on main wiki "
82    + "because extension [{}] is invalid on namespace [{}]", extension.getId(),
83    installedNamespace);
84   
85  0 setState(null);
86  0 break;
87    }
88    }
89    }
90    }
91    } else {
92  1 String currentNamespace = getNamespace();
93  1 Collection<InstalledExtension> installedExtensions =
94    this.installedRepository.getInstalledExtensions(currentNamespace);
95   
96    // Upgrade outdated extensions only when there is invalid extensions
97  1 for (InstalledExtension extension : installedExtensions) {
98  2 if (!extension.isValid(currentNamespace)) {
99  0 this.logger.debug("Enabling outdate extension step on wiki [{}]"
100    + "because extension [{}] is invalid", getWiki(), extension.getId());
101   
102  0 setState(null);
103  0 break;
104    }
105    }
106    }
107    }
108    }
109    }