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 | |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 18 | import org.onosproject.core.Version; |
| 19 | import org.onosproject.core.VersionService; |
| 20 | import org.osgi.service.component.annotations.Activate; |
| 21 | import org.osgi.service.component.annotations.Component; |
| 22 | import org.slf4j.Logger; |
| 23 | import org.slf4j.LoggerFactory; |
| 24 | |
Jordan Halterman | f70bf46 | 2017-07-29 13:12:00 -0700 | [diff] [blame] | 25 | import java.io.File; |
| 26 | import java.io.IOException; |
| 27 | import java.nio.file.Files; |
| 28 | import java.nio.file.Path; |
| 29 | import java.nio.file.Paths; |
| 30 | import java.util.List; |
| 31 | |
Jordan Halterman | f70bf46 | 2017-07-29 13:12:00 -0700 | [diff] [blame] | 32 | /** |
| 33 | * Node version service implementation. |
| 34 | */ |
Ray Milkey | d84f89b | 2018-08-17 14:54:17 -0700 | [diff] [blame] | 35 | @Component(immediate = true, service = VersionService.class) |
Jordan Halterman | f70bf46 | 2017-07-29 13:12:00 -0700 | [diff] [blame] | 36 | public class VersionManager implements VersionService { |
| 37 | |
| 38 | private final Logger log = LoggerFactory.getLogger(getClass()); |
| 39 | |
| 40 | private static final File VERSION_FILE = new File("../VERSION"); |
ONOS Jenkins User | e8cc971 | 2020-01-24 16:50:55 +0000 | [diff] [blame^] | 41 | private static Version version = Version.version("2.3.0-SNAPSHOT"); |
Jordan Halterman | f70bf46 | 2017-07-29 13:12:00 -0700 | [diff] [blame] | 42 | |
| 43 | @Activate |
| 44 | protected void activate() { |
| 45 | try { |
| 46 | Path path = Paths.get(VERSION_FILE.getPath()); |
| 47 | List<String> versionLines = Files.readAllLines(path); |
| 48 | if (versionLines != null && !versionLines.isEmpty()) { |
| 49 | version = Version.version(versionLines.get(0)); |
| 50 | } |
| 51 | } catch (IOException e) { |
| 52 | // version file not found, using default |
| 53 | log.trace("Version file not found", e); |
| 54 | } |
Jordan Halterman | 980a8c1 | 2017-09-22 18:01:19 -0700 | [diff] [blame] | 55 | log.info("Started"); |
Jordan Halterman | f70bf46 | 2017-07-29 13:12:00 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| 58 | @Override |
| 59 | public Version version() { |
| 60 | return version; |
| 61 | } |
Ray Milkey | 17463db | 2017-08-01 10:46:24 -0700 | [diff] [blame] | 62 | } |