1+ /**
2+ *
3+ * Copyright 2016, Optimizely and contributors
4+ *
5+ * Licensed under the Apache License, Version 2.0 (the "License");
6+ * you may not use this file except in compliance with the License.
7+ * You may obtain a copy of the License at
8+ *
9+ * http://www.apache.org/licenses/LICENSE-2.0
10+ *
11+ * Unless required by applicable law or agreed to in writing, software
12+ * distributed under the License is distributed on an "AS IS" BASIS,
13+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+ * See the License for the specific language governing permissions and
15+ * limitations under the License.
16+ */
17+ package com .optimizely .ab .event .internal ;
18+
19+ import org .slf4j .Logger ;
20+ import org .slf4j .LoggerFactory ;
21+
22+ import java .io .BufferedReader ;
23+ import java .io .IOException ;
24+ import java .io .InputStreamReader ;
25+ import java .nio .charset .Charset ;
26+
27+ import javax .annotation .concurrent .Immutable ;
28+
29+ /**
30+ * Helper class to retrieve the SDK version information.
31+ */
32+ @ Immutable
33+ public final class BuildVersionInfo {
34+
35+ private static final Logger logger = LoggerFactory .getLogger (BuildVersionInfo .class );
36+
37+ public final static String VERSION = readVersionNumber ();
38+ private static String readVersionNumber () {
39+ BufferedReader bufferedReader =
40+ new BufferedReader (
41+ new InputStreamReader (BuildVersionInfo .class .getResourceAsStream ("/optimizely-build-version" ),
42+ Charset .forName ("UTF-8" )));
43+ try {
44+ return bufferedReader .readLine ();
45+ } catch (IOException e ) {
46+ logger .error ("unable to read version number" );
47+ return "unknown" ;
48+ } finally {
49+ try {
50+ bufferedReader .close ();
51+ } catch (IOException e ) {
52+ logger .error ("unable to close reader cleanly" );
53+ }
54+ }
55+ }
56+
57+ private BuildVersionInfo () { }
58+ }
0 commit comments