Jordan Halterman | f70bf46 | 2017-07-29 13:12:00 -0700 | [diff] [blame] | 1 | /* |
Brian O'Connor | a09fe5b | 2017-08-03 21:12:30 -0700 | [diff] [blame] | 2 | * Copyright 2017-present Open Networking Foundation |
Jordan Halterman | f70bf46 | 2017-07-29 13:12:00 -0700 | [diff] [blame] | 3 | * |
| 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 | */ |
| 16 | package org.onosproject.core.impl; |
| 17 | |
| 18 | import java.io.File; |
| 19 | import java.io.IOException; |
| 20 | import java.nio.file.Files; |
| 21 | import java.nio.file.Path; |
| 22 | import java.nio.file.Paths; |
| 23 | import java.util.List; |
| 24 | |
| 25 | import org.apache.felix.scr.annotations.Activate; |
| 26 | import org.apache.felix.scr.annotations.Component; |
| 27 | import org.apache.felix.scr.annotations.Service; |
| 28 | import org.onosproject.core.Version; |
| 29 | import org.onosproject.core.VersionService; |
| 30 | import org.slf4j.Logger; |
| 31 | import org.slf4j.LoggerFactory; |
| 32 | |
| 33 | /** |
| 34 | * Node version service implementation. |
| 35 | */ |
| 36 | @Component(immediate = true) |
| 37 | @Service |
| 38 | public 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 User | 40fda91 | 2019-02-27 01:46:02 +0000 | [diff] [blame^] | 43 | private static Version version = Version.version("1.13.9-SNAPSHOT"); |
Jordan Halterman | f70bf46 | 2017-07-29 13:12:00 -0700 | [diff] [blame] | 44 | |
| 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 Halterman | 980a8c1 | 2017-09-22 18:01:19 -0700 | [diff] [blame] | 57 | log.info("Started"); |
Jordan Halterman | f70bf46 | 2017-07-29 13:12:00 -0700 | [diff] [blame] | 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public Version version() { |
| 62 | return version; |
| 63 | } |
Ray Milkey | 17463db | 2017-08-01 10:46:24 -0700 | [diff] [blame] | 64 | } |