public static Properties getTestContainerConfig() { String cdiTestRunnerConfig = ConfigResolver.getProjectStageAwarePropertyValue( CUSTOM_TEST_CONTAINER_CONFIG_FILE_KEY, DEFAULT_TEST_CONTAINER_CONFIG_FILE_NAME); return PropertyLoader.getProperties(cdiTestRunnerConfig); }
/** * Implement a quick and dirty sorting mechanism for the given Properties. * @param allProperties * @return the Properties list sorted by it's 'configuration.ordinal' in ascending order. */ private static List<Properties> sortProperties(List<Properties> allProperties) { List<Properties> sortedProperties = new ArrayList<Properties>(); for (Properties p : allProperties) { int configOrder = getConfigurationOrdinal(p); int i; for (i = 0; i < sortedProperties.size(); i++) { int listConfigOrder = getConfigurationOrdinal(sortedProperties.get(i)); if (listConfigOrder > configOrder) { // only go as far as we found a higher priority Properties file break; } } sortedProperties.add(i, p); } return sortedProperties; }
List<Properties> allProperties = loadAllProperties(propertyFileName); if (allProperties == null) List<Properties> sortedProperties = sortProperties(allProperties); Properties properties = mergeProperties(sortedProperties); return properties;
private static List<Properties> loadAllProperties(String propertyFileName) throws IOException { ClassLoader cl = ClassUtils.getClassLoader(null); List<Properties> properties = new ArrayList<Properties>(); // read the normal property file names Enumeration<URL> propertyUrls = cl.getResources(propertyFileName + FILE_EXTENSION); while (propertyUrls != null && propertyUrls.hasMoreElements()) { URL propertyUrl = propertyUrls.nextElement(); fillProperties(properties, propertyUrl); } // and also read the ones post-fixed with the projectStage ProjectStage ps = ProjectStageProducer.getInstance().getProjectStage(); propertyUrls = cl.getResources(propertyFileName + "-" + ps + FILE_EXTENSION); while (propertyUrls != null && propertyUrls.hasMoreElements()) { URL propertyUrl = propertyUrls.nextElement(); fillProperties(properties, propertyUrl); } if (properties.isEmpty()) { if (LOG.isLoggable(Level.INFO)) { LOG.info("could not find any property files with name " + propertyFileName); } return null; } return properties; }
private static List<Properties> loadAllProperties(String propertyFileName) throws IOException { ClassLoader cl = ClassUtils.getClassLoader(null); List<Properties> properties = new ArrayList<Properties>(); // read the normal property file names Enumeration<URL> propertyUrls = cl.getResources(propertyFileName + FILE_EXTENSION); while (propertyUrls != null && propertyUrls.hasMoreElements()) { URL propertyUrl = propertyUrls.nextElement(); fillProperties(properties, propertyUrl); } // and also read the ones post-fixed with the projectStage ProjectStage ps = ProjectStageProducer.getInstance().getProjectStage(); propertyUrls = cl.getResources(propertyFileName + "-" + ps + FILE_EXTENSION); while (propertyUrls != null && propertyUrls.hasMoreElements()) { URL propertyUrl = propertyUrls.nextElement(); fillProperties(properties, propertyUrl); } if (properties.isEmpty()) { if (LOG.isLoggable(Level.INFO)) { LOG.info("could not find any property files with name " + propertyFileName); } return null; } return properties; }
List<Properties> allProperties = loadAllProperties(propertyFileName); if (allProperties == null) List<Properties> sortedProperties = sortProperties(allProperties); Properties properties = mergeProperties(sortedProperties); return properties;
@Override public Properties getEntityManagerFactoryConfiguration(String persistenceUnitName) { Properties unitProperties = PropertyLoader.getProperties("persistence-" + persistenceUnitName); if (unitProperties == null) { unitProperties = new Properties(); } // apply ConfigFilters to the configured values. for (Map.Entry entry : unitProperties.entrySet()) { String key = (String) entry.getKey(); String value = (String) entry.getValue(); entry.setValue(ConfigResolver.filterConfigValue(key, value)); } unitProperties = addConfigProperties(unitProperties, persistenceUnitName); // add spec expected attributes unitProperties.put("javax.persistence.bean.manager", BeanManagerProvider.getInstance().getBeanManager()); return unitProperties; }
/** * Implement a quick and dirty sorting mechanism for the given Properties. * @param allProperties * @return the Properties list sorted by it's 'configuration.ordinal' in ascending order. */ private static List<Properties> sortProperties(List<Properties> allProperties) { List<Properties> sortedProperties = new ArrayList<Properties>(); for (Properties p : allProperties) { int configOrder = getConfigurationOrdinal(p); int i; for (i = 0; i < sortedProperties.size(); i++) { int listConfigOrder = getConfigurationOrdinal(sortedProperties.get(i)); if (listConfigOrder > configOrder) { // only go as far as we found a higher priority Properties file break; } } sortedProperties.add(i, p); } return sortedProperties; }
private static List<Properties> loadAllProperties(String propertyFileName) throws IOException { ClassLoader cl = ClassUtils.getClassLoader(null); List<Properties> properties = new ArrayList<Properties>(); // read the normal property file names Enumeration<URL> propertyUrls = cl.getResources(propertyFileName + FILE_EXTENSION); while (propertyUrls != null && propertyUrls.hasMoreElements()) { URL propertyUrl = propertyUrls.nextElement(); fillProperties(properties, propertyUrl); } // and also read the ones post-fixed with the projectStage ProjectStage ps = ProjectStageProducer.getInstance().getProjectStage(); propertyUrls = cl.getResources(propertyFileName + "-" + ps + FILE_EXTENSION); while (propertyUrls != null && propertyUrls.hasMoreElements()) { URL propertyUrl = propertyUrls.nextElement(); fillProperties(properties, propertyUrl); } if (properties.isEmpty()) { if (LOG.isLoggable(Level.INFO)) { LOG.info("could not find any property files with name " + propertyFileName); } return null; } return properties; }
List<Properties> allProperties = loadAllProperties(propertyFileName); if (allProperties == null) List<Properties> sortedProperties = sortProperties(allProperties); Properties properties = mergeProperties(sortedProperties); return properties;
@Test public void testNotExistingPropertyLoading() throws Exception { Assert.assertNull(PropertyLoader.getProperties("notexistingProperty")); Assert.assertNull(PropertyLoader.getProperties("notexistingProperty.properties")); }
/** * Implement a quick and dirty sorting mechanism for the given Properties. * @param allProperties * @return the Properties list sorted by it's 'configuration.ordinal' in ascending order. */ private static List<Properties> sortProperties(List<Properties> allProperties) { List<Properties> sortedProperties = new ArrayList<Properties>(); for (Properties p : allProperties) { int configOrder = getConfigurationOrdinal(p); int i; for (i = 0; i < sortedProperties.size(); i++) { int listConfigOrder = getConfigurationOrdinal(sortedProperties.get(i)); if (listConfigOrder > configOrder) { // only go as far as we found a higher priority Properties file break; } } sortedProperties.add(i, p); } return sortedProperties; }
private void checkProperties(String propertyFile, String expectedValue) { Properties p = PropertyLoader.getProperties(propertyFile); Assert.assertNotNull(p); Assert.assertEquals(1, p.size()); Assert.assertEquals(expectedValue, p.get("test.value")); }
private static void fillProperties(List<Properties> properties, URL propertyUrl) throws IOException { InputStream is = null; try { is = propertyUrl.openStream(); Properties prop = new Properties(); prop.load(is); properties.add(prop); // a bit debugging output int ordinal = getConfigurationOrdinal(prop); if (LOG.isLoggable(Level.FINE)) { LOG.fine("loading properties with ordinal " + ordinal + " from file " + propertyUrl.getFile()); } } finally { if (is != null) { is.close(); } } }
private static void fillProperties(List<Properties> properties, URL propertyUrl) throws IOException { InputStream is = null; try { is = propertyUrl.openStream(); Properties prop = new Properties(); prop.load(is); properties.add(prop); // a bit debugging output int ordinal = getConfigurationOrdinal(prop); if (LOG.isLoggable(Level.FINE)) { LOG.fine("loading properties with ordinal " + ordinal + " from file " + propertyUrl.getFile()); } } finally { if (is != null) { is.close(); } } }
private static void fillProperties(List<Properties> properties, URL propertyUrl) throws IOException { InputStream is = null; try { is = propertyUrl.openStream(); Properties prop = new Properties(); prop.load(is); properties.add(prop); // a bit debugging output int ordinal = getConfigurationOrdinal(prop); if (LOG.isLoggable(Level.FINE)) { LOG.fine("loading properties with ordinal " + ordinal + " from file " + propertyUrl.getFile()); } } finally { if (is != null) { is.close(); } } }