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

File DefaultExtensionPlanAction.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
38% of files have more coverage

Code metrics

10
36
11
1
189
105
16
0.44
3.27
11
1.45

Classes

Class Line # Actions
DefaultExtensionPlanAction 39 36 0% 16 6
0.894736889.5%
 

Contributing tests

This file is covered by 91 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.job.plan.internal;
21   
22    import java.util.Collection;
23    import java.util.Collections;
24    import java.util.LinkedHashSet;
25    import java.util.Objects;
26   
27    import org.apache.commons.lang3.builder.HashCodeBuilder;
28    import org.xwiki.extension.Extension;
29    import org.xwiki.extension.ExtensionRewriter;
30    import org.xwiki.extension.InstalledExtension;
31    import org.xwiki.extension.job.plan.ExtensionPlanAction;
32   
33    /**
34    * An action to perform as part of an extension plan.
35    *
36    * @version $Id: 4d7e33738635ea943bdd73332f780d19f273398b $
37    * @since 4.0M1
38    */
 
39    public class DefaultExtensionPlanAction implements ExtensionPlanAction
40    {
41    /**
42    * @see #getExtension()
43    */
44    private Extension extension;
45   
46    /**
47    * @see #getRewrittenExtension()
48    */
49    private Extension rewrittenExtension;
50   
51    /**
52    * @see #getPreviousExtension()
53    */
54    private Collection<InstalledExtension> previousExtensions;
55   
56    /**
57    * @see Action
58    */
59    private Action action;
60   
61    /**
62    * @see #getNamespace()
63    */
64    private String namespace;
65   
66    /**
67    * @see #isDependency()
68    */
69    private boolean dependency;
70   
71    /**
72    * @param extension the extension on which to perform the action
73    * @param rewrittenExtension the result of {@link ExtensionRewriter#rewrite(Extension)} on the extension on which to
74    * perform the actionO
75    * @param previousExtensions the currently installed extensions. Used when upgrading
76    * @param action the action to perform
77    * @param namespace the namespace in which the action should be executed
78    * @param dependency indicate indicate if the extension is a dependency of another one only in the plan
79    */
 
80  365 toggle public DefaultExtensionPlanAction(Extension extension, Extension rewrittenExtension,
81    Collection<InstalledExtension> previousExtensions, Action action, String namespace, boolean dependency)
82    {
83  365 this.extension = extension;
84  365 this.rewrittenExtension = rewrittenExtension;
85   
86  365 this.previousExtensions = previousExtensions != null ? new LinkedHashSet<InstalledExtension>(previousExtensions)
87    : Collections.<InstalledExtension>emptyList();
88  365 this.action = action;
89  365 this.namespace = namespace;
90  365 this.dependency = dependency;
91    }
92   
 
93  1102 toggle @Override
94    public Extension getExtension()
95    {
96  1102 return this.extension;
97    }
98   
 
99  0 toggle @Override
100    public Extension getRewrittenExtension()
101    {
102  0 return this.rewrittenExtension;
103    }
104   
 
105  19 toggle @Override
106    @Deprecated
107    public InstalledExtension getPreviousExtension()
108    {
109  19 return this.previousExtensions.isEmpty() ? null : this.previousExtensions.iterator().next();
110    }
111   
 
112  370 toggle @Override
113    public Collection<InstalledExtension> getPreviousExtensions()
114    {
115  370 return this.previousExtensions;
116    }
117   
 
118  2373 toggle @Override
119    public Action getAction()
120    {
121  2373 return this.action;
122    }
123   
 
124  1836 toggle @Override
125    public String getNamespace()
126    {
127  1836 return this.namespace;
128    }
129   
 
130  180 toggle @Override
131    public boolean isDependency()
132    {
133  180 return this.dependency;
134    }
135   
136    // Object
137   
 
138  452 toggle @Override
139    public int hashCode()
140    {
141  452 HashCodeBuilder builder = new HashCodeBuilder();
142   
143  452 builder.append(this.extension);
144  452 builder.append(this.namespace);
145   
146  452 return builder.toHashCode();
147    }
148   
 
149  1 toggle @Override
150    public boolean equals(Object obj)
151    {
152  1 if (this == obj) {
153  0 return true;
154    }
155   
156  1 boolean equals;
157   
158  1 if (obj instanceof ExtensionPlanAction) {
159  1 ExtensionPlanAction epa = (ExtensionPlanAction) obj;
160  1 equals = this.extension.equals(epa.getExtension()) && Objects.equals(this.namespace, epa.getNamespace());
161    } else {
162  0 equals = false;
163    }
164   
165  1 return equals;
166    }
167   
 
168  623 toggle @Override
169    public String toString()
170    {
171  623 StringBuilder builder = new StringBuilder();
172   
173  623 builder.append(this.action);
174   
175  623 builder.append(": ");
176   
177  623 builder.append(this.extension);
178   
179  623 builder.append(" (");
180  623 builder.append(this.namespace);
181  623 if (!this.previousExtensions.isEmpty()) {
182  404 builder.append(", ");
183  404 builder.append(this.previousExtensions);
184    }
185  623 builder.append(')');
186   
187  623 return builder.toString();
188    }
189    }