Clover icon

Magnolia Resources Module 2.4.2

  1. Project Clover database Fri Nov 6 2015 16:15:26 CET
  2. Package info.magnolia.module.resources.setup

File InstallResourcesTask.java

 

Coverage histogram

../../../../../img/srcFileCovDistChart0.png
76% of files have more coverage

Code metrics

4
21
12
1
131
60
14
0.67
1.75
12
1.17

Classes

Class Line # Actions
InstallResourcesTask 48 21 0% 14 37
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

1    /**
2    * This file Copyright (c) 2009-2015 Magnolia International
3    * Ltd. (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10    * This file is distributed in the hope that it will be
11    * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12    * implied warranty of MERCHANTABILITY or FITNESS FOR A
13    * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14    * Redistribution, except as permitted by whichever of the GPL
15    * or MNA you select, is prohibited.
16    *
17    * 1. For the GPL license (GPL), you can redistribute and/or
18    * modify this file under the terms of the GNU General
19    * Public License, Version 3, as published by the Free Software
20    * Foundation. You should have received a copy of the GNU
21    * General Public License, Version 3 along with this program;
22    * if not, write to the Free Software Foundation, Inc., 51
23    * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24    *
25    * 2. For the Magnolia Network Agreement (MNA), this file
26    * and the accompanying materials are made available under the
27    * terms of the MNA which accompanies this distribution, and
28    * is available at http://www.magnolia-cms.com/mna.html
29    *
30    * Any modifications to this file must keep this entire header
31    * intact.
32    *
33    */
34    package info.magnolia.module.resources.setup;
35   
36    import info.magnolia.cms.util.ClasspathResourcesUtil;
37    import info.magnolia.module.InstallContext;
38    import info.magnolia.module.delta.ArrayDelegateTask;
39    import info.magnolia.module.delta.TaskExecutionException;
40   
41    import org.apache.commons.lang3.StringUtils;
42   
43    /**
44    * Task to load new resources into repository based on name pattern.
45    *
46    * @deprecated since 2.2.1, use {@link InstallBinaryResourcesTask or @link InstallTextResourcesTask} instead.
47    */
 
48    public class InstallResourcesTask extends ArrayDelegateTask {
49    protected String pattern;
50   
51    protected String template;
52   
53    private final String modelClass;
54   
55    private final boolean binary;
56   
57    private final boolean preserveResourcesParameters;
58   
59    /**
60    * @deprecated Use {@link #InstallResourcesTask(String, String, boolean)} instead.
61    */
 
62  0 toggle public InstallResourcesTask(String pattern, String template) {
63  0 this(pattern, template, false);
64    }
65   
 
66  0 toggle public InstallResourcesTask(String pattern, String template, boolean binary) {
67  0 this(pattern, template, binary, null);
68    }
69   
 
70  0 toggle public InstallResourcesTask(String pattern, String template, boolean binary, boolean preserveResourcesParameters) {
71  0 this(pattern, template, binary, null, preserveResourcesParameters);
72    }
73   
74    /**
75    * @deprecated Use {@link #InstallResourcesTask(String, String, boolean, String)} instead.
76    */
 
77  0 toggle public InstallResourcesTask(String pattern, String template, String modelClass) {
78  0 this(pattern, template, false, modelClass);
79    }
80   
 
81  0 toggle public InstallResourcesTask(String pattern, String template, boolean binary, String modelClass) {
82  0 this("Install resources", "Installs all resources matching the " + pattern + " pattern.", pattern, template, binary, modelClass);
83    }
84   
 
85  0 toggle public InstallResourcesTask(String pattern, String template, boolean binary, String modelClass, boolean preserveTemplate) {
86  0 this("Install resources", "Installs all resources matching the " + pattern + " pattern.", pattern, template, binary, modelClass, preserveTemplate);
87    }
88   
89    /**
90    * @deprecated Use {@link #InstallResourcesTask(String, String, String, String, boolean, String)} instead.
91    */
 
92  0 toggle public InstallResourcesTask(String taskName, String taskDescription, String pattern, String template, String modelClass) {
93  0 this(taskName, taskDescription, pattern, template, false, modelClass);
94    }
95   
 
96  0 toggle public InstallResourcesTask(String taskName, String taskDescription, String pattern, String template, boolean binary, String modelClass) {
97  0 this(taskName, taskDescription, pattern, template, binary, modelClass, false);
98    }
99   
 
100  0 toggle public InstallResourcesTask(String taskName, String taskDescription, String pattern, String template, boolean binary, String modelClass, boolean preserveResourcesParameters) {
101  0 super(taskName, taskDescription);
102  0 this.pattern = pattern;
103  0 this.template = template;
104  0 this.modelClass = modelClass;
105  0 this.binary = binary;
106  0 this.preserveResourcesParameters = preserveResourcesParameters;
107    }
108   
 
109  0 toggle @Override
110    public void execute(InstallContext ctx) throws TaskExecutionException {
111  0 final String[] resources = findResources();
112   
113  0 for (int i = 0; i < resources.length; i++) {
114  0 String resource = resources[i];
115  0 String template = determineTemplate(resource);
116  0 new InstallResourceTask(resource, template, binary, modelClass, preserveResourcesParameters).execute(ctx);
117    }
118    }
119   
120    /**
121    * If no template has been defined the file extension is used.
122    */
 
123  0 toggle protected String determineTemplate(String resource) {
124  0 return template != null ? template : StringUtils.substringAfterLast(resource, ".");
125    }
126   
 
127  0 toggle protected String[] findResources() {
128  0 return ClasspathResourcesUtil.findResources(pattern);
129    }
130   
131    }