1. Project Clover database Tue Dec 20 2016 21:24:09 CET
  2. Package org.xwiki.platform.wiki.creationjob.internal

File ExtensionInstaller.java

 

Coverage histogram

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

Code metrics

0
10
1
1
79
38
2
0.2
10
1
2

Classes

Class Line # Actions
ExtensionInstaller 45 10 0% 2 0
1.0100%
 

Contributing tests

This file is covered by 2 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.platform.wiki.creationjob.internal;
21   
22    import java.util.Arrays;
23   
24    import javax.inject.Inject;
25    import javax.inject.Singleton;
26   
27    import org.xwiki.component.annotation.Component;
28    import org.xwiki.component.manager.ComponentLookupException;
29    import org.xwiki.component.manager.ComponentManager;
30    import org.xwiki.extension.ExtensionId;
31    import org.xwiki.extension.job.InstallRequest;
32    import org.xwiki.extension.job.internal.InstallJob;
33    import org.xwiki.job.Job;
34    import org.xwiki.model.reference.DocumentReference;
35    import org.xwiki.platform.wiki.creationjob.WikiCreationException;
36   
37    /**
38    * Component that installs an extension on a wiki.
39    *
40    * @version $Id: 158e39e98192fa761973cd21b348c787c8c74c22 $
41    * @since 7.0M2
42    */
43    @Component(roles = ExtensionInstaller.class)
44    @Singleton
 
45    public class ExtensionInstaller
46    {
47    private static final String PROPERTY_USERREFERENCE = "user.reference";
48   
49    private static final DocumentReference SUPERADMIN_REFERENCE = new DocumentReference("xwiki", "XWiki", "superadmin");
50   
51    @Inject
52    private ComponentManager componentManager;
53   
54    /**
55    * Install an extension on a wiki.
56    *
57    * @param wikiId id of the wiki
58    * @param extensionId id of the extension to install
59    * @throws org.xwiki.platform.wiki.creationjob.WikiCreationException if problem occurs
60    */
 
61  3 toggle public void installExtension(String wikiId, ExtensionId extensionId) throws WikiCreationException
62    {
63  3 try {
64    // Create the install request
65  3 InstallRequest installRequest = new InstallRequest();
66  3 installRequest.setId(Arrays.asList(WikiCreationJob.JOB_ID_PREFIX, "install", wikiId));
67  3 installRequest.addExtension(extensionId);
68  3 installRequest.addNamespace("wiki:" + wikiId);
69    // To avoid problem with Programming Rights, we install everything with superadmin
70  3 installRequest.setProperty(PROPERTY_USERREFERENCE, SUPERADMIN_REFERENCE);
71  3 InstallJob job = componentManager.getInstance(Job.class, InstallJob.JOBTYPE);
72  2 job.initialize(installRequest);
73  2 job.run();
74    } catch (ComponentLookupException e) {
75  1 throw new WikiCreationException(String.format("Failed to install the extension [%s] on the wiki [%s].",
76    extensionId.toString(), wikiId), e);
77    }
78    }
79    }