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

File DefaultExtensionPlanAction.java

 

Coverage histogram

../../../../../../img/srcFileCovDistChart9.png
41% 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 97 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  2191 toggle public DefaultExtensionPlanAction(Extension extension, Extension rewrittenExtension,
81    Collection<InstalledExtension> previousExtensions, Action action, String namespace, boolean dependency)
82    {
83  2191 this.extension = extension;
84  2191 this.rewrittenExtension = rewrittenExtension;
85   
86  2191 this.previousExtensions = previousExtensions != null ? new LinkedHashSet<InstalledExtension>(previousExtensions)
87    : Collections.<InstalledExtension>emptyList();
88  2191 this.action = action;
89  2191 this.namespace = namespace;
90  2191 this.dependency = dependency;
91    }
92   
 
93  14001 toggle @Override
94    public Extension getExtension()
95    {
96  14001 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  826 toggle @Override
113    public Collection<InstalledExtension> getPreviousExtensions()
114    {
115  826 return this.previousExtensions;
116    }
117   
 
118  5659 toggle @Override
119    public Action getAction()
120    {
121  5659 return this.action;
122    }
123   
 
124  18703 toggle @Override
125    public String getNamespace()
126    {
127  18703 return this.namespace;
128    }
129   
 
130  425 toggle @Override
131    public boolean isDependency()
132    {
133  425 return this.dependency;
134    }
135   
136    // Object
137   
 
138  25396 toggle @Override
139    public int hashCode()
140    {
141  25396 HashCodeBuilder builder = new HashCodeBuilder();
142   
143  25396 builder.append(this.extension);
144  25396 builder.append(this.namespace);
145   
146  25396 return builder.toHashCode();
147    }
148   
 
149  9689 toggle @Override
150    public boolean equals(Object obj)
151    {
152  9689 if (this == obj) {
153  0 return true;
154    }
155   
156  9689 boolean equals;
157   
158  9689 if (obj instanceof ExtensionPlanAction) {
159  9689 ExtensionPlanAction epa = (ExtensionPlanAction) obj;
160  9689 equals = this.extension.equals(epa.getExtension()) && Objects.equals(this.namespace, epa.getNamespace());
161    } else {
162  0 equals = false;
163    }
164   
165  9689 return equals;
166    }
167   
 
168  1533589 toggle @Override
169    public String toString()
170    {
171  1533589 StringBuilder builder = new StringBuilder();
172   
173  1533589 builder.append(this.action);
174   
175  1533589 builder.append(": ");
176   
177  1533589 builder.append(this.extension);
178   
179  1533589 builder.append(" (");
180  1533589 builder.append(this.namespace);
181  1533589 if (!this.previousExtensions.isEmpty()) {
182  291209 builder.append(", ");
183  291209 builder.append(this.previousExtensions);
184    }
185  1533589 builder.append(')');
186   
187  1533589 return builder.toString();
188    }
189    }