|
| 1 | +/** |
| 2 | +
|
| 3 | + Copyright (c) 2015, Alessandro Pieri |
| 4 | + All rights reserved. |
| 5 | +
|
| 6 | + Redistribution and use in source and binary forms, with or without |
| 7 | + modification, are permitted provided that the following conditions are met: |
| 8 | +
|
| 9 | + 1. Redistributions of source code must retain the above copyright notice, this |
| 10 | + list of conditions and the following disclaimer. |
| 11 | + 2. Redistributions in binary form must reproduce the above copyright notice, |
| 12 | + this list of conditions and the following disclaimer in the documentation |
| 13 | + and/or other materials provided with the distribution. |
| 14 | +
|
| 15 | + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND |
| 16 | + ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
| 17 | + WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
| 18 | + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR |
| 19 | + ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 20 | + (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 21 | + LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 22 | + ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 23 | + (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 24 | + SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 25 | +
|
| 26 | + The views and conclusions contained in the software and documentation are those |
| 27 | + of the authors and should not be interpreted as representing official policies, |
| 28 | + either expressed or implied, of the FreeBSD Project. |
| 29 | +
|
| 30 | + */ |
| 31 | +package io.getstream.client.util; |
| 32 | + |
| 33 | +import com.google.common.io.Resources; |
| 34 | +import org.slf4j.Logger; |
| 35 | +import org.slf4j.LoggerFactory; |
| 36 | + |
| 37 | +import java.io.IOException; |
| 38 | +import java.io.InputStream; |
| 39 | +import java.util.Properties; |
| 40 | + |
| 41 | +/** |
| 42 | + * Read the properties carved at build time into the jar artifact. |
| 43 | + */ |
| 44 | +public class InfoUtil { |
| 45 | + |
| 46 | + private static final Logger LOG = LoggerFactory.getLogger(InfoUtil.class); |
| 47 | + |
| 48 | + public static final String VERSION = "version"; |
| 49 | + public static final String STREAM_JAVA_INFO = "/stream-java.info"; |
| 50 | + |
| 51 | + /** |
| 52 | + * Read the build properties carved into the jar. |
| 53 | + * @return Build properties |
| 54 | + */ |
| 55 | + public static Properties getProperties() { |
| 56 | + Properties properties = new Properties(); |
| 57 | + try (InputStream inputStream = Resources.asByteSource(InfoUtil.class.getResource(STREAM_JAVA_INFO)).openStream()) { |
| 58 | + properties.load(inputStream); |
| 59 | + } catch (IOException e) { |
| 60 | + LOG.error("Failed to read the properties file " + STREAM_JAVA_INFO + "from the jar", e); |
| 61 | + } |
| 62 | + return properties; |
| 63 | + } |
| 64 | +} |
0 commit comments