1. Project Clover database Sat Feb 2 2019 06:45:20 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
24
3
1
132
67
5
0.21
8
3
1.67

Classes

Class Line # Actions
UninstallJob 49 24 0% 5 0
1.0100%
 

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: ad9a6f52a189b67726479e07da1c30e3cb4230e2 $
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  357 toggle @Override
70    public String getType()
71    {
72  357 return JOBTYPE;
73    }
74   
 
75  57 toggle @Override
76    protected UninstallRequest castRequest(Request request)
77    {
78  57 UninstallRequest uninstallRequest;
79  57 if (request instanceof UninstallRequest) {
80  56 uninstallRequest = (UninstallRequest) request;
81    } else {
82  1 uninstallRequest = new UninstallRequest(request);
83    }
84   
85  57 return uninstallRequest;
86    }
87   
 
88  57 toggle @Override
89    protected void runInternal() throws Exception
90    {
91  57 this.progressManager.pushLevelProgress(2, this);
92   
93  57 ExecutionContext context = this.execution.getContext();
94   
95  57 try {
96  57 this.progressManager.startStep(this);
97   
98    // Create the plan
99   
100  57 UninstallRequest planRequest = new UninstallRequest(getRequest());
101  57 planRequest.setId((List<String>) null);
102   
103  57 this.uninstallPlanJob.initialize(planRequest);
104  57 this.uninstallPlanJob.run();
105   
106  57 ExtensionPlan plan = (ExtensionPlan) this.uninstallPlanJob.getStatus();
107   
108  57 if (plan.getError() != null) {
109  5 throw new UninstallException("Failed to create install plan", plan.getError());
110    }
111   
112  52 this.progressManager.endStep(this);
113   
114  52 this.progressManager.startStep(this);
115   
116    // Put the plan in context
117    // TODO: use a stack ?
118  52 context.setProperty(CONTEXTKEY_PLAN, plan);
119   
120    // Apply the plan
121   
122  52 Collection<ExtensionPlanAction> actions = plan.getActions();
123   
124  52 applyActions(actions);
125    } finally {
126  57 this.progressManager.popLevelProgress(this);
127   
128    // Clean context
129  57 context.removeProperty(CONTEXTKEY_PLAN);
130    }
131    }
132    }