All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.polypheny.jdbc.utils.VersionUtil Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2019-2024 The Polypheny Project
 *
 * Licensed 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.polypheny.jdbc.utils;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.util.Properties;
import lombok.extern.slf4j.Slf4j;

/**
 * Utility class for accessing version information stored in a properties file generated by a gradle task.
 */
@Slf4j
public class VersionUtil {

    private static final String VERSION_FILE = "polypheny-jdbc-driver-version.properties";
    private static final String API_VERSION_PROPERTIES = "prism-api-version.properties";

    public static final int MAJOR;
    public static final int MINOR;
    public static final String QUALIFIER;
    public static final String BUILD_TIMESTAMP;
    public static final String VERSION_STRING;

    public static final int MAJOR_API_VERSION;
    public static final int MINOR_API_VERSION;
    public static final String API_VERSION_STRING;


    static {
        Properties properties = new Properties();
        try ( InputStream inputStream = VersionUtil.class.getClassLoader().getResourceAsStream( VERSION_FILE ) ) {
            if ( inputStream != null ) {
                properties.load( inputStream );
                MAJOR = Integer.parseInt( properties.getProperty( "major" ) );
                MINOR = Integer.parseInt( properties.getProperty( "minor" ) );
                QUALIFIER = properties.getProperty( "qualifier" );
                BUILD_TIMESTAMP = properties.getProperty( "buildTimestamp" );
                VERSION_STRING = properties.getProperty( "version" );
            } else {
                throw new FileNotFoundException( "The version properties could not be found." );
            }
        } catch ( IOException e ) {
            throw new RuntimeException( "Error loading version properties", e );
        }

        properties = new Properties();
        try ( InputStream inputStream = VersionUtil.class.getClassLoader().getResourceAsStream( API_VERSION_PROPERTIES ) ) {
            if ( inputStream != null ) {
                properties.load( inputStream );
                API_VERSION_STRING = properties.getProperty( "version" );
                MAJOR_API_VERSION = Integer.parseInt( properties.getProperty( "majorVersion" ) );
                MINOR_API_VERSION = Integer.parseInt( properties.getProperty( "minorVersion" ) );
            } else {
                throw new FileNotFoundException( "The prism api version properties could not be found." );
            }
        } catch ( IOException e ) {
            throw new RuntimeException( "Error loading API version properties", e );
        }
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy