001 /*
002 * Copyright (c) 2013 by Oli B.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 * http://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing, software
011 * distributed under the License is distributed on an "AS IS" BASIS,
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express orimplied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 *
016 * (c)reated 06.04.2014 by Oli B. (boehm@javatux.de)
017 */
018
019 package patterntesting.runtime.jmx;
020
021 import java.io.*;
022 import java.util.Properties;
023
024 import org.slf4j.*;
025
026 /**
027 * This Info bean is registered as MBean and provides some information about
028 * PatternTesting.
029 *
030 * @author oliver (boehm@javatux.de)
031 * @since 1.4 (06.04.2014)
032 */
033 public final class Info implements InfoMBean {
034
035 private static final Logger log = LoggerFactory.getLogger(Info.class);
036 private final Properties properties = new Properties();
037
038 /**
039 * Instantiates a new info.
040 */
041 public Info() {
042 try {
043 this.loadProperties("info.properties");
044 } catch (IOException ioe) {
045 log.warn("Cannot read property file.", ioe);
046 }
047 }
048
049 private void loadProperties(final String resource) throws IOException {
050 InputStream istream = this.getClass().getResourceAsStream(resource);
051 if (istream == null) {
052 throw new FileNotFoundException("resource \"" + resource + "\" not found in classpath");
053 }
054 try {
055 this.properties.load(istream);
056 } finally {
057 istream.close();
058 }
059 }
060
061 /**
062 * Gets the version.
063 *
064 * @return the version
065 * @see InfoMBean#getVersion()
066 */
067 public String getVersion() {
068 return this.properties.getProperty("patterntesting.version", "unknown");
069 }
070
071 /**
072 * Gets the builds the time of PatternTesting.
073 *
074 * @return the builds the time
075 */
076 public String getBuildTime() {
077 String buildTime = this.properties.getProperty("patterntesting.buildtime", "unknown");
078 if (buildTime.startsWith("${")) {
079 return "unknown";
080 }
081 return buildTime;
082 }
083
084 }
085