View Javadoc
1   package net.avcompris.commons3.utils;
2   
3   import static com.google.common.base.Preconditions.checkNotNull;
4   import static org.apache.commons.lang3.StringUtils.isBlank;
5   
6   public abstract class EnvUtils {
7   
8   	public static String getEnvProperty(final String propertyName, final String sampleValue) {
9   
10  		checkNotNull(propertyName, "propertyName");
11  		checkNotNull(sampleValue, "sampleValue");
12  
13  		final String propertyValue = System.getProperty(propertyName);
14  
15  		if (isBlank(propertyValue)) {
16  
17  			throw new RuntimeException("Cannot read environment property: " + propertyName
18  					+ ", it should be of the form: \"" + sampleValue + "\", but was: " + propertyValue);
19  		}
20  
21  		return propertyValue;
22  	}
23  }