blob: 72eb841612a62539d99c5397a522e0a3d9e4202f [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
Ray Milkeyd84f89b2018-08-17 14:54:17 -070018import org.onosproject.core.Version;
19import org.onosproject.core.VersionService;
20import org.osgi.service.component.annotations.Activate;
21import org.osgi.service.component.annotations.Component;
22import org.slf4j.Logger;
23import org.slf4j.LoggerFactory;
24
Jordan Haltermanf70bf462017-07-29 13:12:00 -070025import java.io.File;
26import java.io.IOException;
27import java.nio.file.Files;
28import java.nio.file.Path;
29import java.nio.file.Paths;
30import java.util.List;
31
Jordan Haltermanf70bf462017-07-29 13:12:00 -070032/**
33 * Node version service implementation.
34 */
Ray Milkeyd84f89b2018-08-17 14:54:17 -070035@Component(immediate = true, service = VersionService.class)
Jordan Haltermanf70bf462017-07-29 13:12:00 -070036public 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 User14789b02020-11-19 19:58:01 +000041 private static Version version = Version.version("2.5.0-SNAPSHOT");
Jordan Haltermanf70bf462017-07-29 13:12:00 -070042
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 Halterman980a8c12017-09-22 18:01:19 -070055 log.info("Started");
Jordan Haltermanf70bf462017-07-29 13:12:00 -070056 }
57
58 @Override
59 public Version version() {
60 return version;
61 }
Ray Milkey17463db2017-08-01 10:46:24 -070062}