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

File UninstallJob.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

4
23
3
1
130
66
5
0.22
7.67
3
1.67

Classes

Class Line # Actions
UninstallJob 49 23 0% 5 2
0.9333333493.3%
 

Contributing tests

This file is covered by 37 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.internal;
21   
22    import java.util.Collection;
23    import java.util.List;
24   
25    import javax.inject.Inject;
26    import javax.inject.Named;
27   
28    import org.xwiki.component.annotation.Component;
29    import org.xwiki.context.Execution;
30    import org.xwiki.context.ExecutionContext;
31    import org.xwiki.extension.UninstallException;
32    import org.xwiki.extension.job.UninstallRequest;
33    import org.xwiki.extension.job.plan.ExtensionPlan;
34    import org.xwiki.extension.job.plan.ExtensionPlanAction;
35    import org.xwiki.job.DefaultJobStatus;
36    import org.xwiki.job.Job;
37    import org.xwiki.job.Request;
38   
39    /**
40    * Extension uninstallation related task.
41    * <p>
42    * This task generates related events.
43    *
44    * @version $Id: c18a14fc7ced719c5b68655dd7200eebae0ab6d3 $
45    * @since 4.0M1
46    */
47    @Component
48    @Named(UninstallJob.JOBTYPE)
 
49    public class UninstallJob extends AbstractExtensionJob<UninstallRequest, DefaultJobStatus<UninstallRequest>>
50    {
51    /**
52    * The id of the job.
53    */
54    public static final String JOBTYPE = "uninstall";
55   
56    /**
57    * Used to generate the install plan.
58    */
59    @Inject
60    @Named(UninstallPlanJob.JOBTYPE)
61    private Job uninstallPlanJob;
62   
63    /**
64    * Used to access the execution context.
65    */
66    @Inject
67    private Execution execution;
68   
 
69  288 toggle @Override
70    public String getType()
71    {
72  288 return JOBTYPE;
73    }
74   
 
75  55 toggle @Override
76    protected UninstallRequest castRequest(Request request)
77    {
78  55 UninstallRequest uninstallRequest;
79  55 if (request instanceof UninstallRequest) {
80  55 uninstallRequest = (UninstallRequest) request;
81    } else {
82  0 uninstallRequest = new UninstallRequest(request);
83    }
84   
85  55 return uninstallRequest;
86    }
87   
 
88  55 toggle @Override
89    protected void runInternal() throws Exception
90    {
91  55 this.progressManager.pushLevelProgress(2, this);
92   
93  55 ExecutionContext context = this.execution.getContext();
94   
95  55 try {
96  55 this.progressManager.startStep(this);
97   
98    // Create the plan
99   
100  55 UninstallRequest planRequest = new UninstallRequest(getRequest());
101  55 planRequest.setId((List<String>) null);
102   
103  55 this.uninstallPlanJob.initialize(planRequest);
104  55 this.uninstallPlanJob.run();
105   
106  55 ExtensionPlan plan = (ExtensionPlan) this.uninstallPlanJob.getStatus();
107   
108  55 if (plan.getError() != null) {
109  5 throw new UninstallException("Failed to create install plan", plan.getError());
110    }
111   
112  50 this.progressManager.startStep(this);
113   
114    // Put the plan in context
115    // TODO: use a stack ?
116  50 context.setProperty(CONTEXTKEY_PLAN, plan);
117   
118    // Apply the plan
119   
120  50 Collection<ExtensionPlanAction> actions = plan.getActions();
121   
122  50 applyActions(actions);
123    } finally {
124  55 this.progressManager.popLevelProgress(this);
125   
126    // Clean context
127  55 context.removeProperty(CONTEXTKEY_PLAN);
128    }
129    }
130    }