Path: blob/trunk/java/src/org/openqa/selenium/BuildInfo.java
1865 views
// Licensed to the Software Freedom Conservancy (SFC) under one1// or more contributor license agreements. See the NOTICE file2// distributed with this work for additional information3// regarding copyright ownership. The SFC licenses this file4// to you under the Apache License, Version 2.0 (the5// "License"); you may not use this file except in compliance6// with the License. You may obtain a copy of the License at7//8// http://www.apache.org/licenses/LICENSE-2.09//10// Unless required by applicable law or agreed to in writing,11// software distributed under the License is distributed on an12// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY13// KIND, either express or implied. See the License for the14// specific language governing permissions and limitations15// under the License.1617package org.openqa.selenium;1819import java.io.IOException;20import java.io.InputStream;21import java.net.URL;22import java.util.Properties;2324/** Reads information about how the current application was built. */25public class BuildInfo {2627private static final Properties BUILD_PROPERTIES = loadBuildProperties();2829private static Properties loadBuildProperties() {30Properties properties = new Properties();3132URL resource = BuildInfo.class.getResource("/META-INF/selenium-build.properties");33try (InputStream is = resource.openStream()) {34properties.load(is);35} catch (IOException | NullPointerException ignored) {36// Do nothing37}3839return properties;40}4142/**43* @return The embedded release label or "unknown".44*/45public String getReleaseLabel() {46return read("Selenium-Version");47}4849/**50* @return The embedded build revision or "unknown".51*/52public String getBuildRevision() {53return read("Build-Revision");54}5556@Override57public String toString() {58return String.format(59"Build info: version: '%s', revision: '%s'", getReleaseLabel(), getBuildRevision());60}6162private String read(String propertyName) {63String value = BUILD_PROPERTIES.getProperty(propertyName);64if (value == null || value.trim().isEmpty()) {65return "unknown";66}67return value.trim();68}69}707172