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

File AbstractApplicationContext.java

 

Coverage histogram

../../../img/srcFileCovDistChart1.png
82% of files have more coverage

Code metrics

12
22
3
1
117
57
10
0.45
7.33
3
3.33

Classes

Class Line # Actions
AbstractApplicationContext 37 22 0% 10 35
0.0540540555.4%
 

Contributing tests

No tests hitting this source file were found.

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.container;
21   
22    import java.io.File;
23   
24    import org.slf4j.Logger;
25    import org.slf4j.LoggerFactory;
26    import org.xwiki.component.manager.ComponentLookupException;
27    import org.xwiki.component.manager.ComponentManager;
28    import org.xwiki.configuration.ConfigurationSource;
29   
30    /**
31    * Base class for {@link ApplicationContext} implementations.
32    *
33    * @version $Id: a34f980089565d6f81ce1f3495b8c8fcde1020f0 $
34    * @deprecated starting with 3.5M1, use the notion of Environment instead
35    */
36    @Deprecated
 
37    public abstract class AbstractApplicationContext implements ApplicationContext
38    {
39    /**
40    * The logger to log.
41    */
42    private static final Logger LOGGER = LoggerFactory.getLogger(AbstractApplicationContext.class);
43   
44    /**
45    * The name of the property for configuring the persistent directory path.
46    */
47    private static final String PROPERTY_PERSISTENTDIRECTORY = "container.persistentDirectory";
48   
49    /**
50    * Use to lookup {@link ConfigurationSource} component.
51    */
52    private final ComponentManager componentManager;
53   
54    /**
55    * @see #getPermanentDirectory()
56    */
57    private File permanentDirectory;
58   
59    /**
60    * @param componentManager use to lookup {@link ConfigurationSource} component. Can't directly get the
61    * {@link ConfigurationSource} because it depends on {@link ApplicationContext} to actually get the
62    * configuration
63    */
 
64  116 toggle public AbstractApplicationContext(ComponentManager componentManager)
65    {
66  116 this.componentManager = componentManager;
67    }
68   
 
69  0 toggle @Override
70    public File getPermanentDirectory()
71    {
72  0 if (this.permanentDirectory == null) {
73  0 try {
74  0 this.permanentDirectory = getConfiguredPermanentDirectory();
75    } catch (Exception e) {
76  0 LOGGER.error("Failed to get configured permanent directory", e);
77    }
78   
79  0 if (this.permanentDirectory == null) {
80    // Only choice left
81  0 this.permanentDirectory = getTemporaryDirectory();
82    }
83    }
84   
85  0 return this.permanentDirectory;
86    }
87   
88    /**
89    * @return the directory indicated in configuration, null if none is configured or if it's invalid
90    * @throws ComponentLookupException error when trying to lookup {@link ConfigurationSource} component
91    */
 
92  0 toggle private File getConfiguredPermanentDirectory() throws ComponentLookupException
93    {
94  0 File directory = null;
95   
96  0 ConfigurationSource source = this.componentManager.getInstance(ConfigurationSource.class, "xwikiproperties");
97  0 String directoryName = source.getProperty(PROPERTY_PERSISTENTDIRECTORY);
98  0 if (directoryName != null) {
99  0 directory = new File(directoryName);
100  0 if (directory.exists()) {
101  0 if (!directory.isDirectory()) {
102  0 LOGGER.error("Configured permanent storage directory [{}] is not a directory",
103    directory.getAbsolutePath());
104  0 directory = null;
105  0 } else if (!directory.canWrite()) {
106  0 LOGGER.error("Configured permanent storage directory [{}] is not writable",
107    directory.getAbsolutePath());
108  0 directory = null;
109    }
110    } else {
111  0 directory.mkdirs();
112    }
113    }
114   
115  0 return directory;
116    }
117    }