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

com.dropchop.quarkus.snakejar.SnakeJarPropertiesUtil Maven / Gradle / Ivy

Go to download

Quarkus extension that integrates SnakeJar Java library with embedded CPython to Quarkus. This extension enables calling Python native code from Quarkus REST services.

There is a newer version: 1.35.7
Show newest version
package com.dropchop.quarkus.snakejar;

import io.quarkus.runtime.LaunchMode;
import org.eclipse.microprofile.config.Config;
import org.eclipse.microprofile.config.ConfigProvider;

import java.util.Optional;
import java.util.Properties;

/**
 * @author Nikola Ivačič  on 6. 11. 21.
 */
public class SnakeJarPropertiesUtil {

  private static final String SNAKEJAR_OPTION_PREFIX = "snakejar.";
  private static final String QUARKUS_SNAKEJAR_OPTION_PREFIX = "quarkus." + SNAKEJAR_OPTION_PREFIX;

  private static boolean isSnakeJarProperty(String prefix, String property) {
    return property.startsWith(prefix);
  }

  private static void includeSnakeJarProperty(Config config, Properties snakeJarProperties, String prefix, String property) {
    Optional value = config.getOptionalValue(property, String.class);
    value.ifPresent(s -> snakeJarProperties.setProperty(property.substring(prefix.length()), s));
  }

  private static Properties snakeJarProperties(String prefix) {
    Properties snakeJarProperties = new Properties();
    Config config = ConfigProvider.getConfig();
    for (String property : config.getPropertyNames()) {
      if (isSnakeJarProperty(prefix, property)) {
        includeSnakeJarProperty(config, snakeJarProperties, prefix, property);
      }
    }

    return snakeJarProperties;
  }

  public static Properties appSnakeJarProperties() {
    return snakeJarProperties(SNAKEJAR_OPTION_PREFIX);
  }

  public static Properties quarkusSnakeJarProperties() {
    return snakeJarProperties(QUARKUS_SNAKEJAR_OPTION_PREFIX);
  }

  public static Properties buildSnakeJarProperties(LaunchMode launchMode) {
    return appSnakeJarProperties();
  }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy