This project has retired. For details please refer to its Attic page.
Source code
001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.reef.util;
020
021import javax.inject.Inject;
022import java.io.IOException;
023import java.io.InputStream;
024import java.util.Properties;
025import java.util.logging.Level;
026import java.util.logging.Logger;
027
028/**
029 * Version information, retrieved from the pom (via a properties file reference).
030 */
031public final class REEFVersion {
032
033  private static final Logger LOG = Logger.getLogger(REEFVersion.class.getName());
034
035  private static final String FILENAME = "version.properties";
036  private static final String VERSION_KEY = "version";
037  private static final String VERSION_DEFAULT = "unknown";
038
039  private final String version;
040
041  @Inject
042  public REEFVersion() {
043    this.version = loadVersion();
044  }
045
046  /**
047   * Logs the version of REEF into the log Level INFO.
048   */
049  public void logVersion() {
050    this.logVersion(Level.INFO);
051  }
052
053  /**
054   * Logs the version of REEF into the given logLevel.
055   *
056   * @param logLevel The level to use in the log.
057   */
058  public void logVersion(final Level logLevel) {
059    LOG.log(logLevel, "REEF Version: {0}", this.version);
060  }
061
062  /**
063   * @return the version string for REEF.
064   */
065  public String getVersion() {
066    return version;
067  }
068
069  private static String loadVersion() {
070    String version;
071    try (final InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(FILENAME)) {
072      if (is == null) {
073        throw new IOException(FILENAME + " not found");
074      }
075      final Properties properties = new Properties();
076      properties.load(is);
077      version = properties.getProperty(VERSION_KEY, VERSION_DEFAULT);
078    } catch (final IOException e) {
079      LOG.log(Level.WARNING, "Could not find REEF version");
080      version = VERSION_DEFAULT;
081    }
082    return version;
083  }
084}