/** * Load a new {@link ExProperties} object from the given file. */ public static ExProperties load(File file) { return Props.load(file); }
/** * Reads the given properties file. * * @throws NestedIOException if an I/O error occurs. */ public static ExProperties load(File file) throws NestedIOException { return load(file,null); }
/** * Load a new {@link ExProperties} object from the given file. */ public static ExProperties load(File file,Properties defaults) { return Props.load(file); }
public I18nHelper(String dir, String defaultBaseName, String locale) { super(defaultBaseName); File file = new File(dir + "_i18n/messages.properties"); if(file.exists()) { this.props.putAll(Props.load(file).toMap()); } file = new File(dir + "_i18n/messages_" + locale + ".properties"); if(file.exists()) { this.props.putAll(Props.load(file).toMap()); } }
private void loadPatterns(Resource r) { if(r.exists()){ ExProperties p = Props.load(r); for(Entry<Object, Object> entry : p.entrySet()){ String name = (String)entry.getKey(); String value = (String)entry.getValue(); if(name.endsWith(FLAGS_SUFFIX)){ continue; } if(name.endsWith(REGEX_SUFFIX)){ name = name.substring(0,name.length() - REGEX_SUFFIX.length()); } addPattern(r, name, value, p.get(name + FLAGS_SUFFIX)); } } }
protected void initDefaultProperties(ConfigurableEnvironment env) { Map<String, Object> props = new HashMap<>(); for(Resource resource : Resources.scan("classpath*:META-INF/jmms/application.properties")){ props.putAll(Props.load(resource).toMap()); } env.getPropertySources().addLast(new MapPropertySource("jmms-meta-inf-config", props)); }
private void init(Map<String, BeanInfo> beans, String type, String types) { for(Resource resource : Resources.scan("classpath*:META-INF/jmms." + types)) { String url = resource.getURLString(); Map<String, String> nameAndValues = Props.load(resource).toMap(); nameAndValues.forEach((beanName, className) -> { BeanInfo exists = beans.get(beanName); if(null != exists) { throw new IllegalStateException("Found duplicated " + type + " '" + beanName + "' at [ " + exists.url + " , " + url + " ]"); } if(Strings.isEmpty(className)) { throw new IllegalStateException("The class of '" + beanName + "' must not be empty, " + url); } try { Class<?> cls = Classes.forName(className); BeanInfo info = new BeanInfo(); info.cls = cls; info.url = url; beans.put(beanName, info); }catch (Exception e) { throw new IllegalStateException("Invalid class '" + className + "' , " + e.getMessage() + ", " + url); } }); } }
@Override public boolean readProperties(AppPropertyContext context, Resource resource) { String filename = resource.getFilename(); if(Strings.endsWithIgnoreCase(filename, ".properties") || Strings.endsWithIgnoreCase(filename,".properties.xml")) { Props.load(resource).forEach( (key, value) -> putProperty(context, resource, (String)key, (String)value) ); return true; } return false; }
private static void addBasePackagesFromConfigurations(Set<String> bps) { String frameworkPackage = ClassUtils.getPackageName(SpringRunListener.class); for(Resource r : Resources.scan("classpath*:META-INF/spring.factories")) { if(r.exists()) { ExProperties props = Props.load(r); String prop = props.get("org.springframework.boot.autoconfigure.EnableAutoConfiguration"); if(!Strings.isEmpty(prop)) { String[] classNames = Strings.split(prop, ','); for(String className : classNames) { if(className.startsWith(frameworkPackage) || className.startsWith(Global.SPRING_PACKAGE_PREFIX)) { continue; } Class<?> c = Classes.tryForName(className); if(null != c) { bps.add(ClassUtils.getPackageName(c)); addBasePackages(bps, c); } } } } } } }
public static ExProperties load(Resource r) throws NestedIOException { try { if(r.isFile()){ return load(r.getFile()); }else{ ExProperties p = new ExProperties(); if(Strings.endsWithIgnoreCase(r.getFilename(), ".xml")){ try(InputStream in = r.getInputStream()){ p.loadFromXML(in); } }else{ try(Reader reader = r.getInputStreamReader()){ p.load(reader); } } return p; } } catch (IOException e) { throw new NestedIOException("Error loading properties from resource '" + r.getDescription() + "', " + e.getMessage(), e); } }