blob: ae056a33499ed092d20ca70e656f8e389bc4703a [file] [log] [blame]
Jordan Haltermanf70bf462017-07-29 13:12:00 -07001/*
Brian O'Connora09fe5b2017-08-03 21:12:30 -07002 * Copyright 2017-present Open Networking Foundation
Jordan Haltermanf70bf462017-07-29 13:12:00 -07003 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 */
16package org.onosproject.core.impl;
17
18import java.io.File;
19import java.io.IOException;
20import java.nio.file.Files;
21import java.nio.file.Path;
22import java.nio.file.Paths;
23import java.util.List;
24
25import org.apache.felix.scr.annotations.Activate;
26import org.apache.felix.scr.annotations.Component;
27import org.apache.felix.scr.annotations.Service;
28import org.onosproject.core.Version;
29import org.onosproject.core.VersionService;
30import org.slf4j.Logger;
31import org.slf4j.LoggerFactory;
32
33/**
34 * Node version service implementation.
35 */
36@Component(immediate = true)
37@Service
38public class VersionManager implements VersionService {
39
40 private final Logger log = LoggerFactory.getLogger(getClass());
41
42 private static final File VERSION_FILE = new File("../VERSION");
ONOS Jenkins User168ac922017-12-12 18:44:15 +000043 private static Version version = Version.version("1.13.0-b6");
Jordan Haltermanf70bf462017-07-29 13:12:00 -070044
45 @Activate
46 protected void activate() {
47 try {
48 Path path = Paths.get(VERSION_FILE.getPath());
49 List<String> versionLines = Files.readAllLines(path);
50 if (versionLines != null && !versionLines.isEmpty()) {
51 version = Version.version(versionLines.get(0));
52 }
53 } catch (IOException e) {
54 // version file not found, using default
55 log.trace("Version file not found", e);
56 }
Jordan Halterman980a8c12017-09-22 18:01:19 -070057 log.info("Started");
Jordan Haltermanf70bf462017-07-29 13:12:00 -070058 }
59
60 @Override
61 public Version version() {
62 return version;
63 }
Ray Milkey17463db2017-08-01 10:46:24 -070064}