/*
 * Copyright (c) 2019, 2020 Oracle and/or its affiliates. All rights reserved.
 *
 * 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 io.helidon.integrations.graal.nativeimage.extension;

/**
 * A utility class to configure native image features.
 * Currently uses System properties to control configuration.
 * Each property is prefixed with {@code helidon.native}.
 */
public final class NativeConfig {
    private static final String PREFIX = "helidon.native.";
    private NativeConfig() {
    }

    /**
     * Find a boolean option.
     *
     * @param name name of the option, prefixed with {@code helidon.native} by this method
     * @param defaultValue default value to return if option is not found
     * @return value configured or default value
     */
    public static boolean option(String name, boolean defaultValue) {
        String prop = System.getProperty(name(name));

        if (null == prop) {
            return defaultValue;
        }

        return Boolean.parseBoolean(prop);
    }

    private static String name(String name) {
        return PREFIX + name;
    }
}
