Clover Coverage Report - Pebble 2.5-SNAPSHOT
Coverage timestamp: Sat Jun 12 2010 09:39:29 EST
../../../img/srcFileCovDistChart4.png 41% of files have more coverage
21   149   13   1,91
2   65   0,62   11
11     1,18  
1    
This report was generated with an evaluation server license. Purchase Clover or configure your license.
 
  PebbleContext       Line # 49 21 0% 13 21 38,2% 0.38235295
 
  (208)
 
1    /*
2    * Copyright (c) 2003-2006, Simon Brown
3    * All rights reserved.
4    *
5    * Redistribution and use in source and binary forms, with or without
6    * modification, are permitted provided that the following conditions are met:
7    *
8    * - Redistributions of source code must retain the above copyright
9    * notice, this list of conditions and the following disclaimer.
10    *
11    * - Redistributions in binary form must reproduce the above copyright
12    * notice, this list of conditions and the following disclaimer in
13    * the documentation and/or other materials provided with the
14    * distribution.
15    *
16    * - Neither the name of Pebble nor the names of its contributors may
17    * be used to endorse or promote products derived from this software
18    * without specific prior written permission.
19    *
20    * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21    * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22    * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23    * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
24    * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
25    * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
26    * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
27    * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
28    * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
29    * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30    * POSSIBILITY OF SUCH DAMAGE.
31    */
32    package net.sourceforge.pebble;
33   
34    import net.sourceforge.pebble.security.SecurityRealm;
35    import net.sourceforge.pebble.util.RelativeDate;
36    import org.apache.commons.logging.Log;
37    import org.apache.commons.logging.LogFactory;
38   
39    import java.io.IOException;
40    import java.io.InputStream;
41    import java.util.Date;
42    import java.util.Properties;
43   
44    /**
45    * A bean representing the Pebble context.
46    *
47    * @author Simon Brown
48    */
 
49    public class PebbleContext {
50   
51    /** the log used by this class */
52    private static Log log = LogFactory.getLog(PebbleContext.class);
53   
54    private Configuration configuration;
55   
56    private String buildVersion;
57    private String buildDate;
58   
59    private static final String BUILD_VERSION_KEY = "build.version";
60    private static final String BUILD_DATE_KEY = "build.date";
61   
62    /** the time that Pebble was started */
63    private Date startTime;
64   
65    /** the directory where Pebble is deployed */
66    private String webApplicationRoot;
67   
68    private static final PebbleContext instance = new PebbleContext();
69   
 
70  4448 toggle public static PebbleContext getInstance() {
71  4448 return instance;
72    }
73   
 
74  2 toggle private PebbleContext() {
75    // and note when Pebble was started
76  2 this.startTime = new Date();
77   
78  2 try {
79  2 Properties buildProperties = new Properties();
80  2 InputStream in = getClass().getClassLoader().getResourceAsStream("pebble-build.properties");
81  2 if (in != null) {
82  0 buildProperties.load(in);
83  0 this.buildVersion = buildProperties.getProperty(BUILD_VERSION_KEY);
84  0 this.buildDate = buildProperties.getProperty(BUILD_DATE_KEY);
85  0 in.close();
86    }
87    } catch (IOException e) {
88  0 log.error(e.getMessage(), e);
89  0 e.printStackTrace();
90    }
91    }
92   
93    /**
94    * Gets the version of Pebble being used.
95    *
96    * @return the version number as a String
97    */
 
98  0 toggle public String getBuildVersion() {
99  0 return this.buildVersion;
100    }
101   
102    /**
103    * Gets the date that Pebble was built.
104    *
105    * @return the date as a String
106    */
 
107  0 toggle public String getBuildDate() {
108  0 return this.buildDate;
109    }
110   
111    /**
112    * Gets the amount of time that Pebble has been running for.
113    *
114    * @return a number of milliseconds
115    */
 
116  0 toggle public RelativeDate getUptime() {
117  0 return new RelativeDate(new Date().getTime() - startTime.getTime());
118    }
119   
 
120  0 toggle public long getMemoryUsageInKB() {
121  0 return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024;
122    }
123   
 
124  0 toggle public long getTotalMemoryInKB() {
125  0 return Runtime.getRuntime().totalMemory() / 1024;
126    }
127   
 
128  2024 toggle public Configuration getConfiguration() {
129  2024 return configuration;
130    }
131   
 
132  2432 toggle public void setConfiguration(Configuration configuration) {
133  2432 this.configuration = configuration;
134    }
135   
136    /**
137    * Sets the directory where themes are located.
138    *
139    * @param webApplicationRoot the absolute path to the webapp root on disk
140    */
 
141  0 toggle public void setWebApplicationRoot(String webApplicationRoot) {
142  0 this.webApplicationRoot = webApplicationRoot;
143    }
144   
 
145  0 toggle public String getWebApplicationRoot() {
146  0 return webApplicationRoot;
147    }
148   
149    }