//# 0 errors, 151 messages
//#
/*
    //#pebblecontext.java:1:1: class: net.sourceforge.pebble.PebbleContext
 * Copyright (c) 2003-2006, Simon Brown
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions are met:
 *
 *   - Redistributions of source code must retain the above copyright
 *     notice, this list of conditions and the following disclaimer.
 *
 *   - Redistributions in binary form must reproduce the above copyright
 *     notice, this list of conditions and the following disclaimer in
 *     the documentation and/or other materials provided with the
 *     distribution.
 *
 *   - Neither the name of Pebble nor the names of its contributors may
 *     be used to endorse or promote products derived from this software
 *     without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */
package net.sourceforge.pebble;

import net.sourceforge.pebble.security.SecurityRealm;
import net.sourceforge.pebble.util.RelativeDate;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.io.IOException;
import java.io.InputStream;
import java.util.Date;
import java.util.Properties;

/**
 * A bean representing the Pebble context.
 *
 * @author    Simon Brown
 */
public class PebbleContext {

  /** the log used by this class */
  private static Log log = LogFactory.getLog(PebbleContext.class);
    //#pebblecontext.java:52: method: net.sourceforge.pebble.PebbleContext.net.sourceforge.pebble.PebbleContext__static_init
    //#pebblecontext.java:52: Warning: method not available
    //#    -- call on Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.PebbleContext
    //#    method: net.sourceforge.pebble.PebbleContext__static_init
    //#    unanalyzed callee: Log org.apache.commons.logging.LogFactory:getLog(Class)
    //#output(net.sourceforge.pebble.PebbleContext__static_init): __Descendant_Table[net/sourceforge/pebble/PebbleContext]
    //#output(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.getBuildDate()Ljava/lang/String;
    //#output(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.getBuildVersion()Ljava/lang/String;
    //#output(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.getConfiguration()Lnet/sourceforge/pebble/Configuration;
    //#output(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.getMemoryUsageInKB()J
    //#output(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.getTotalMemoryInKB()J
    //#output(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.getUptime()Lnet/sourceforge/pebble/util/RelativeDate;
    //#output(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.getWebApplicationRoot()Ljava/lang/String;
    //#output(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.setConfiguration(Lnet/sourceforge/pebble/Configuration;)V
    //#output(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.setWebApplicationRoot(Ljava/lang/String;)V
    //#output(net.sourceforge.pebble.PebbleContext__static_init): instance
    //#output(net.sourceforge.pebble.PebbleContext__static_init): log
    //#output(net.sourceforge.pebble.PebbleContext__static_init): new Date(PebbleContext#1) num objects
    //#output(net.sourceforge.pebble.PebbleContext__static_init): new PebbleContext(PebbleContext__static_init#1) num objects
    //#output(net.sourceforge.pebble.PebbleContext__static_init): instance.__Tag
    //#output(net.sourceforge.pebble.PebbleContext__static_init): instance.buildVersion
    //#output(net.sourceforge.pebble.PebbleContext__static_init): instance.startTime
    //#new obj(net.sourceforge.pebble.PebbleContext__static_init): new Date(PebbleContext#1)
    //#new obj(net.sourceforge.pebble.PebbleContext__static_init): new PebbleContext(PebbleContext__static_init#1)
    //#presumption(net.sourceforge.pebble.PebbleContext__static_init): org.apache.commons.logging.LogFactory:getLog(...)@52 != null
    //#post(net.sourceforge.pebble.PebbleContext__static_init): __Descendant_Table[net/sourceforge/pebble/PebbleContext] == &__Dispatch_Table
    //#post(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.getBuildDate()Ljava/lang/String; == &getBuildDate
    //#post(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.getBuildVersion()Ljava/lang/String; == &getBuildVersion
    //#post(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.getConfiguration()Lnet/sourceforge/pebble/Configuration; == &getConfiguration
    //#post(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.getMemoryUsageInKB()J == &getMemoryUsageInKB
    //#post(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.getTotalMemoryInKB()J == &getTotalMemoryInKB
    //#post(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.getUptime()Lnet/sourceforge/pebble/util/RelativeDate; == &getUptime
    //#post(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.getWebApplicationRoot()Ljava/lang/String; == &getWebApplicationRoot
    //#post(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.setConfiguration(Lnet/sourceforge/pebble/Configuration;)V == &setConfiguration
    //#post(net.sourceforge.pebble.PebbleContext__static_init): __Dispatch_Table.setWebApplicationRoot(Ljava/lang/String;)V == &setWebApplicationRoot
    //#post(net.sourceforge.pebble.PebbleContext__static_init): instance == &new PebbleContext(PebbleContext__static_init#1)
    //#post(net.sourceforge.pebble.PebbleContext__static_init): (soft) log != null
    //#post(net.sourceforge.pebble.PebbleContext__static_init): new Date(PebbleContext#1) num objects == 1
    //#post(net.sourceforge.pebble.PebbleContext__static_init): new PebbleContext(PebbleContext__static_init#1) num objects == 1
    //#post(net.sourceforge.pebble.PebbleContext__static_init): instance.__Tag == net/sourceforge/pebble/PebbleContext
    //#post(net.sourceforge.pebble.PebbleContext__static_init): possibly_updated(instance.buildVersion)
    //#post(net.sourceforge.pebble.PebbleContext__static_init): instance.startTime == &new Date(PebbleContext#1)
    //#unanalyzed(net.sourceforge.pebble.PebbleContext__static_init): Effects-of-calling:java.util.Date
    //#unanalyzed(net.sourceforge.pebble.PebbleContext__static_init): Effects-of-calling:java.util.Properties
    //#unanalyzed(net.sourceforge.pebble.PebbleContext__static_init): Effects-of-calling:java.lang.Object:getClass
    //#unanalyzed(net.sourceforge.pebble.PebbleContext__static_init): Effects-of-calling:java.lang.Class:getClassLoader
    //#unanalyzed(net.sourceforge.pebble.PebbleContext__static_init): Effects-of-calling:java.lang.ClassLoader:getResourceAsStream
    //#unanalyzed(net.sourceforge.pebble.PebbleContext__static_init): Effects-of-calling:java.util.Properties:load
    //#unanalyzed(net.sourceforge.pebble.PebbleContext__static_init): Effects-of-calling:java.util.Properties:getProperty
    //#unanalyzed(net.sourceforge.pebble.PebbleContext__static_init): Effects-of-calling:java.io.InputStream:close
    //#unanalyzed(net.sourceforge.pebble.PebbleContext__static_init): Effects-of-calling:org.apache.commons.logging.Log:warn
    //#unanalyzed(net.sourceforge.pebble.PebbleContext__static_init): Effects-of-calling:java.io.IOException:getMessage
    //#unanalyzed(net.sourceforge.pebble.PebbleContext__static_init): Effects-of-calling:org.apache.commons.logging.Log:error
    //#unanalyzed(net.sourceforge.pebble.PebbleContext__static_init): Effects-of-calling:java.io.IOException:printStackTrace

  private Configuration configuration;

  private String buildVersion;
  private String buildDate;

  private static final String BUILD_VERSION_KEY = "build.version";
  private static final String BUILD_DATE_KEY = "build.date";

  /** the time that Pebble was started */
  private Date startTime;

  /** the directory where Pebble is deployed */
  private String webApplicationRoot;

  private static final PebbleContext instance = new PebbleContext();
    //#pebblecontext.java:68: end of method: net.sourceforge.pebble.PebbleContext.net.sourceforge.pebble.PebbleContext__static_init

  public static PebbleContext getInstance() {
    return instance;
    //#pebblecontext.java:71: method: PebbleContext net.sourceforge.pebble.PebbleContext.getInstance()
    //#input(PebbleContext getInstance()): instance
    //#output(PebbleContext getInstance()): return_value
    //#post(PebbleContext getInstance()): return_value == &new PebbleContext(PebbleContext__static_init#1)
    //#pebblecontext.java:71: end of method: PebbleContext net.sourceforge.pebble.PebbleContext.getInstance()
  }

  private PebbleContext() {
    //#pebblecontext.java:74: method: void net.sourceforge.pebble.PebbleContext.net.sourceforge.pebble.PebbleContext()
    //#input(void net.sourceforge.pebble.PebbleContext()): log
    //#input(void net.sourceforge.pebble.PebbleContext()): this
    //#output(void net.sourceforge.pebble.PebbleContext()): new Date(PebbleContext#1) num objects
    //#output(void net.sourceforge.pebble.PebbleContext()): this.buildVersion
    //#output(void net.sourceforge.pebble.PebbleContext()): this.startTime
    //#new obj(void net.sourceforge.pebble.PebbleContext()): new Date(PebbleContext#1)
    //#pre[1] (void net.sourceforge.pebble.PebbleContext()): (soft) log != null
    //#presumption(void net.sourceforge.pebble.PebbleContext()): java.lang.Class:getClassLoader(...)@80 != null
    //#presumption(void net.sourceforge.pebble.PebbleContext()): java.lang.Object:getClass(...)@80 != null
    //#post(void net.sourceforge.pebble.PebbleContext()): possibly_updated(this.buildVersion)
    //#post(void net.sourceforge.pebble.PebbleContext()): this.startTime == &new Date(PebbleContext#1)
    //#post(void net.sourceforge.pebble.PebbleContext()): new Date(PebbleContext#1) num objects == 1
    //#test_vector(void net.sourceforge.pebble.PebbleContext()): java.lang.ClassLoader:getResourceAsStream(...)@80: Addr_Set{null}, Inverse{null}
    // and note when Pebble was started
    this.startTime = new Date();

    try {
      Properties buildProperties = new Properties();
      InputStream in = getClass().getClassLoader().getResourceAsStream(
              "META-INF/maven/org.sourceforge.pebble/pebble/pom.properties");
      if (in != null) {
        buildProperties.load(in);
        this.buildVersion = buildProperties.getProperty("version");
        // It's a little harder to do this in maven, seeing as it's not used anyway, commenting out.
        // this.buildDate = buildProperties.getProperty(BUILD_DATE_KEY);
        in.close();
      } else {
        log.warn("No maven pom.properties found, build version set for development");
    //#pebblecontext.java:89: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:warn(Object)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.PebbleContext
    //#    method: void net.sourceforge.pebble.PebbleContext()
    //#    unanalyzed callee: void org.apache.commons.logging.Log:warn(Object)
      }
    } catch (IOException e) {
      log.error(e.getMessage(), e);
    //#pebblecontext.java:92: Warning: method not available
    //#    -- call on void org.apache.commons.logging.Log:error(Object, Throwable)
    //#    severity: INFORMATIONAL
    //#    class: net.sourceforge.pebble.PebbleContext
    //#    method: void net.sourceforge.pebble.PebbleContext()
    //#    unanalyzed callee: void org.apache.commons.logging.Log:error(Object, Throwable)
      e.printStackTrace();
    }
  }
    //#pebblecontext.java:95: end of method: void net.sourceforge.pebble.PebbleContext.net.sourceforge.pebble.PebbleContext()

  /**
   * Gets the version of Pebble being used.
   *
   * @return    the version number as a String
   */
  public String getBuildVersion() {
    return this.buildVersion;
    //#pebblecontext.java:103: method: String net.sourceforge.pebble.PebbleContext.getBuildVersion()
    //#input(String getBuildVersion()): this
    //#input(String getBuildVersion()): this.buildVersion
    //#output(String getBuildVersion()): return_value
    //#pre[2] (String getBuildVersion()): init'ed(this.buildVersion)
    //#post(String getBuildVersion()): return_value == this.buildVersion
    //#post(String getBuildVersion()): init'ed(return_value)
    //#pebblecontext.java:103: end of method: String net.sourceforge.pebble.PebbleContext.getBuildVersion()
  }

  /**
   * Gets the date that Pebble was built.
   *
   * @return    the date as a String
   */
  public String getBuildDate() {
    return this.buildDate;
    //#pebblecontext.java:112: method: String net.sourceforge.pebble.PebbleContext.getBuildDate()
    //#input(String getBuildDate()): this
    //#input(String getBuildDate()): this.buildDate
    //#output(String getBuildDate()): return_value
    //#pre[2] (String getBuildDate()): init'ed(this.buildDate)
    //#post(String getBuildDate()): return_value == this.buildDate
    //#post(String getBuildDate()): init'ed(return_value)
    //#pebblecontext.java:112: end of method: String net.sourceforge.pebble.PebbleContext.getBuildDate()
  }

  /**
   * Gets the amount of time that Pebble has been running for.
   *
   * @return  a number of milliseconds
   */
  public RelativeDate getUptime() {
    return new RelativeDate(new Date().getTime() - startTime.getTime());
    //#pebblecontext.java:121: method: RelativeDate net.sourceforge.pebble.PebbleContext.getUptime()
    //#input(RelativeDate getUptime()): this
    //#input(RelativeDate getUptime()): this.startTime
    //#output(RelativeDate getUptime()): new RelativeDate(getUptime#1) num objects
    //#output(RelativeDate getUptime()): return_value.__Tag
    //#output(RelativeDate getUptime()): return_value.time
    //#output(RelativeDate getUptime()): return_value
    //#new obj(RelativeDate getUptime()): new RelativeDate(getUptime#1)
    //#pre[2] (RelativeDate getUptime()): this.startTime != null
    //#presumption(RelativeDate getUptime()): java.util.Date:getTime(...)@121 - java.util.Date:getTime(...)@121 in -18_446_744_073_709_551_615..9_223_372_036_854_775_808
    //#presumption(RelativeDate getUptime()): java.util.Date:getTime(...)@121 - java.util.Date:getTime(...)@121 in -18_446_744_073_709_551_615..9_223_372_036_854_775_808
    //#post(RelativeDate getUptime()): return_value == &new RelativeDate(getUptime#1)
    //#post(RelativeDate getUptime()): new RelativeDate(getUptime#1) num objects == 1
    //#post(RelativeDate getUptime()): return_value.__Tag == net/sourceforge/pebble/util/RelativeDate
    //#post(RelativeDate getUptime()): (soft) init'ed(return_value.time)
    //#pebblecontext.java:121: end of method: RelativeDate net.sourceforge.pebble.PebbleContext.getUptime()
  }

  public long getMemoryUsageInKB() {
    return (Runtime.getRuntime().totalMemory() - Runtime.getRuntime().freeMemory()) / 1024;
    //#pebblecontext.java:125: method: long net.sourceforge.pebble.PebbleContext.getMemoryUsageInKB()
    //#output(long getMemoryUsageInKB()): return_value
    //#presumption(long getMemoryUsageInKB()): (-(java.lang.Runtime:freeMemory(...)@125 - java.lang.Runtime:totalMemory(...)@125))/1_024 in -27_021_597_764_222_975..27_021_597_764_222_975
    //#presumption(long getMemoryUsageInKB()): java.lang.Runtime:getRuntime(...)@125 != null
    //#presumption(long getMemoryUsageInKB()): java.lang.Runtime:getRuntime(...)@125 != null
    //#post(long getMemoryUsageInKB()): return_value in -27_021_597_764_222_975..27_021_597_764_222_975
    //#pebblecontext.java:125: end of method: long net.sourceforge.pebble.PebbleContext.getMemoryUsageInKB()
  }

  public long getTotalMemoryInKB() {
    return Runtime.getRuntime().totalMemory() / 1024;
    //#pebblecontext.java:129: method: long net.sourceforge.pebble.PebbleContext.getTotalMemoryInKB()
    //#output(long getTotalMemoryInKB()): return_value
    //#presumption(long getTotalMemoryInKB()): java.lang.Runtime:getRuntime(...)@129 != null
    //#presumption(long getTotalMemoryInKB()): java.lang.Runtime:totalMemory(...)@129/1_024 in -9_007_199_254_740_992..18_014_398_509_481_983
    //#post(long getTotalMemoryInKB()): return_value in -9_007_199_254_740_992..18_014_398_509_481_983
    //#pebblecontext.java:129: end of method: long net.sourceforge.pebble.PebbleContext.getTotalMemoryInKB()
  }

  public Configuration getConfiguration() {
    return configuration;
    //#pebblecontext.java:133: method: Configuration net.sourceforge.pebble.PebbleContext.getConfiguration()
    //#input(Configuration getConfiguration()): this
    //#input(Configuration getConfiguration()): this.configuration
    //#output(Configuration getConfiguration()): return_value
    //#pre[2] (Configuration getConfiguration()): init'ed(this.configuration)
    //#post(Configuration getConfiguration()): return_value == this.configuration
    //#post(Configuration getConfiguration()): init'ed(return_value)
    //#pebblecontext.java:133: end of method: Configuration net.sourceforge.pebble.PebbleContext.getConfiguration()
  }

  public void setConfiguration(Configuration configuration) {
    this.configuration = configuration;
    //#pebblecontext.java:137: method: void net.sourceforge.pebble.PebbleContext.setConfiguration(Configuration)
    //#input(void setConfiguration(Configuration)): configuration
    //#input(void setConfiguration(Configuration)): this
    //#output(void setConfiguration(Configuration)): this.configuration
    //#post(void setConfiguration(Configuration)): this.configuration == configuration
    //#post(void setConfiguration(Configuration)): init'ed(this.configuration)
  }
    //#pebblecontext.java:138: end of method: void net.sourceforge.pebble.PebbleContext.setConfiguration(Configuration)

  /**
   * Sets the directory where themes are located.
   *
   * @param webApplicationRoot    the absolute path to the webapp root on disk
   */
  public void setWebApplicationRoot(String webApplicationRoot) {
    this.webApplicationRoot = webApplicationRoot;
    //#pebblecontext.java:146: method: void net.sourceforge.pebble.PebbleContext.setWebApplicationRoot(String)
    //#input(void setWebApplicationRoot(String)): this
    //#input(void setWebApplicationRoot(String)): webApplicationRoot
    //#output(void setWebApplicationRoot(String)): this.webApplicationRoot
    //#post(void setWebApplicationRoot(String)): this.webApplicationRoot == webApplicationRoot
    //#post(void setWebApplicationRoot(String)): init'ed(this.webApplicationRoot)
  }
    //#pebblecontext.java:147: end of method: void net.sourceforge.pebble.PebbleContext.setWebApplicationRoot(String)

  public String getWebApplicationRoot() {
    return webApplicationRoot;
    //#pebblecontext.java:150: method: String net.sourceforge.pebble.PebbleContext.getWebApplicationRoot()
    //#input(String getWebApplicationRoot()): this
    //#input(String getWebApplicationRoot()): this.webApplicationRoot
    //#output(String getWebApplicationRoot()): return_value
    //#pre[2] (String getWebApplicationRoot()): init'ed(this.webApplicationRoot)
    //#post(String getWebApplicationRoot()): return_value == this.webApplicationRoot
    //#post(String getWebApplicationRoot()): init'ed(return_value)
    //#pebblecontext.java:150: end of method: String net.sourceforge.pebble.PebbleContext.getWebApplicationRoot()
  }

}    //#pebblecontext.java:: end of class: net.sourceforge.pebble.PebbleContext
