private static void loadDefaultOnInterface( final Properties properties, final Class<? extends GuiceProperty> guiceProperty, final Field field) throws IllegalAccessException { for (final Class<? extends GuiceProperty> guicePropertyClass : ((Class<? extends GuiceProperty>[]) guiceProperty.getInterfaces())) { if (!GuiceProperty.class.equals(guicePropertyClass)) properties.setProperty(getName(guicePropertyClass), getValue(field).toString()); } }
public static void loadDefaults(final Properties properties) { getProperties().forEach(p -> loadDefault(properties, p)); }
public static void loadMappedEnvironmentalProperties(final Properties properties) { getEnvironmentProperties().forEach(p -> loadEnvironmentProperty(properties, p)); }
public static void loadFromEnvironment(final Properties properties) { getProperties().forEach(p -> loadPropertyFromEnvironment(properties, p)); }
public static void loadFromSystemProperty(final Properties properties){ getProperties().forEach(p -> loadPropertyFromSystemProperty(properties, p)); }
private static void loadDefault( final Properties properties, final Class<? extends GuiceProperty> guiceProperty) { for (final Field field : guiceProperty.getDeclaredFields()) { System.out.println("checking if default:" + field); LOGGER.trace("checking value:" + field); if (field.isAnnotationPresent(DefaultValue.class)) { System.out.println("loading default:" + field); LOGGER.trace("setting default value:" + field); try { properties.setProperty(getName(guiceProperty), getValue(field).toString()); if (field.isEnumConstant()) loadDefaultOnInterface(properties, guiceProperty, field); } catch (IllegalAccessException e) { System.err.println("error setting default:" + field); LOGGER.warn("Unable to set default value", e); } } } }
public static String getValue( final Properties properties, final Class<? extends GuiceProperty> guiceProperty) { return (properties.getProperty(getName(guiceProperty))); }
private static void loadPropertyFromEnvironment( final Properties properties, final Class<? extends GuiceProperty> guiceProperty) { System.out.println("loading from env:" + guiceProperty); final String value = System.getenv().get(getEnvironmentVariableName(guiceProperty)); if (value != null) properties.setProperty(getName(guiceProperty), value); }
protected void bindToProperty(final Class<? extends GuiceProperty> guicePropertyClass) { final String value = PropertyUtil.getValue(properties, guicePropertyClass); if (value != null) bindConstant().annotatedWith(new PropertyImpl(guicePropertyClass)).to(value); else { throw (new IllegalStateException( guicePropertyClass + " was not set and not default value was provided either, this is likely a configuration problem.")); } }
public static void loadFromPropertiesFile(final Properties properties) { try { final Properties tempProperties = new Properties(); URL url = PropertyUtil.class.getResource(APPLICATION_PROPERTIES_FILE_PATH); if (url != null) { tempProperties.load(url.openStream()); getProperties().forEach(p -> loadPropertyFromProperties(tempProperties, properties, p)); } else System.out.println("url is null"); } catch (Exception e) { LOGGER.warn("Error loading properties", e); } }
protected void bindToProperties() { PropertyUtil.getProperties().forEach(p -> bindToProperty(p)); }
public static void setJavaProperties(final Properties properties) { getJavaEnvironmentProperties().forEach(p -> setJavaProperty(properties, p)); }
protected void loadDefaults() { PropertyUtil.loadDefaults(properties); }
public static String getEnvironmentVariableName(final Class<? extends GuiceProperty> guiceProperty) { return (getName(guiceProperty).replaceAll("\\.", "_")); }
public static void setJavaProperty( final Properties properties, final Class<? extends JavaEnvironmentProperty> environmentProperty) { for (final JavaEnvironmentProperty environmentProperty1 : environmentProperty.getEnumConstants()) { System.setProperty( environmentProperty1.getKey(), getValue(properties, environmentProperty1.getPropertyKey())); } } }
public static void loadFromCommandLine(final Properties properties, final String[] arguments) { try { final Map<Integer, Option> optionMap = new HashMap<>(); final CommandLineParser parser = new DefaultParser(); final Iterable<Class<? extends GuiceProperty>> guiceProperties = PropertyUtil.getProperties(); final Options options = buildOptions(guiceProperties, optionMap); final CommandLine commandLine = parser.parse(options, arguments); int i = 0; for (final Class<? extends GuiceProperty> guiceProperty : guiceProperties) { setValue(properties, commandLine, optionMap.get(i++), guiceProperty); } } catch (ParseException e) { LOGGER.warn("error parsing CLI options", e); throw (new RuntimeException(e)); } }
private static void loadPropertyFromSystemProperty( final Properties properties, final Class<? extends GuiceProperty> guiceProperty) { System.out.println("loading from SystemProperty:" + guiceProperty); final String value = System.getProperty(getName(guiceProperty)); if (value != null) properties.setProperty(getName(guiceProperty), value); }
private static void doStopService(final Class<? extends Service> serviceClass) { try { final Service service = GuiceHelper.getGuiceInjector().getInstance(serviceClass); if (service.isRunning()) service .stopAsync() .awaitTerminated( Long.valueOf(PropertyUtil.getValue(null, ServiceStopTimeout.class)), TimeUnit.SECONDS); else LOGGER.warn("Service:" + service + " is already stopped."); } catch (TimeoutException | IllegalStateException e) { LOGGER.warn("Service is still stopping, killing."); } } }
private static void loadPropertyFromProperties( final Properties tempProperties, final Properties properties, final Class<? extends GuiceProperty> guiceProperty) { System.out.println("loading from properties file:" + guiceProperty); final Object value = tempProperties.get(getName(guiceProperty)); if (value != null) properties.put(getName(guiceProperty), value); }
protected Class<? extends AbstractCommandLineHandler> getCommandLineHandlerClass() { return (getOperatingMode(PropertyUtil.getValue(getProperties(), getOperatingModeClass())) .getInitiatorClass()); }