kbendick commented on code in PR #5186: URL: https://github.com/apache/iceberg/pull/5186#discussion_r914044383
########## core/src/main/java/org/apache/iceberg/util/VersionPropertiesUtil.java: ########## @@ -0,0 +1,108 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ + +package org.apache.iceberg.util; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Properties; +import org.apache.iceberg.relocated.com.google.common.io.Resources; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +/** + * Loads the version.properties file with build information for project iceberg-core. + */ +public class VersionPropertiesUtil { + + private VersionPropertiesUtil() { + } + + private static final Logger LOG = LoggerFactory.getLogger(VersionPropertiesUtil.class); + private static final String VERSION_PROPERTIES_FILE = "version.properties"; + + private static boolean isLoaded = false; + private static Properties versionProperties = new Properties(); + + private static String gitHash; // 10 character short git hash of the build + private static String gitHashFull; // 40 character full git hash of the build + private static String projectName; + private static String projectVersion; + + /** + * Loads the version.properties file for this module. + */ + public static void loadBuildInfo() { + InputStream inputStream = null; + + try { + inputStream = readResource(VERSION_PROPERTIES_FILE); + } catch (IOException e) { + LOG.warn("Failed to load version properties from {}. Will use default values.", VERSION_PROPERTIES_FILE, e); + } + + if (inputStream != null) { + try { + versionProperties.load(inputStream); + } catch (Exception e) { + LOG.error("Could not load version.properties", e); + } + } + + gitHash = versionProperties.getProperty("gitHash", "git-hash-not-found"); + gitHashFull = versionProperties.getProperty("gitHashFull", "git-hash-full-not-found"); + projectName = versionProperties.getProperty("projectName", "iceberg-core"); + projectVersion = versionProperties.getProperty("projectVersion", "project-version-not-found"); Review Comment: Updated to a constant of "uknown". -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected] --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
