use of org.openstreetmap.atlas.utilities.configuration.Configuration in project atlas-checks by osmlab.
the class TagTest method testConfiguration.
/**
* Private function used by all test cases to easily test the configuration instead of rewriting
* the code constantly.
*
* @param config
* The {@link Configuration} is string form that is being test.
* @param numberOfFlags
* The number of expected flags to be processed based on the provided configuration
*/
private void testConfiguration(final String config, final int numberOfFlags) {
final Atlas atlas = setup.getAtlas();
final Configuration configuration = ConfigurationResolver.inlineConfiguration(config);
final List<CheckFlag> flags = Iterables.asList(new BaseTestCheck(configuration).flags(atlas));
// will return the number of flags for the number of objects because no restrictions
Assert.assertEquals(numberOfFlags, flags.size());
}
use of org.openstreetmap.atlas.utilities.configuration.Configuration in project atlas-checks by osmlab.
the class CheckResourceLoader method loadChecks.
/**
* Loads checks that are enabled by some other means, defined by {@code isEnabled}
*
* @param isEnabled
* {@link Predicate} used to determine if a check is enabled
* @param configuration
* {@link Configuration} used to loadChecks {@link CheckResourceLoader}
* @param <T>
* check type
* @return a {@link Set} of checks
*/
@SuppressWarnings("unchecked")
public <T extends Check> Set<T> loadChecks(final Predicate<Class> isEnabled, final Configuration configuration) {
final Set<T> checks = new HashSet<>();
final Time time = Time.now();
try {
final ClassPath classPath = ClassPath.from(Thread.currentThread().getContextClassLoader());
packages.forEach(packageName -> classPath.getTopLevelClassesRecursive(packageName).forEach(classInfo -> {
final Class<?> checkClass = classInfo.load();
if (checkType.isAssignableFrom(checkClass) && !Modifier.isAbstract(checkClass.getModifiers()) && isEnabled.test(checkClass)) {
try {
Object check;
try {
check = checkClass.getConstructor(Configuration.class).newInstance(configuration);
} catch (final InvocationTargetException oops) {
throw new CoreException("Unable to create a configurable instance of {}", checkClass.getSimpleName(), oops);
} catch (final NoSuchMethodException oops) {
check = checkClass.newInstance();
}
if (check != null) {
checks.add((T) check);
}
} catch (final ClassCastException | InstantiationException | IllegalAccessException oops) {
logger.error("Failed to instantiate {}, ignoring. Reason: {}", checkClass.getName(), oops.getMessage());
}
}
}));
} catch (final IOException oops) {
throw new CoreException("Failed to discover {} classes on classpath", checkType.getSimpleName());
}
logger.info("Loaded {} {} in {}", checks.size(), checkType.getSimpleName(), time.elapsedSince());
return checks;
}
use of org.openstreetmap.atlas.utilities.configuration.Configuration in project atlas-checks by osmlab.
the class CheckResourceLoader method getConfigurationForCountry.
/**
* Get configuration for a specific country, overriding for country specific overrides and group
* specific overrides
*
* @param country
* country string
* @return {@link Configuration}
*/
public Configuration getConfigurationForCountry(final String country) {
Configuration specializedConfiguration = this.configuration.configurationForKeyword(country);
final List<String> groups = this.countryGroups.get(country);
if (groups != null) {
for (final String group : groups) {
specializedConfiguration = specializedConfiguration.configurationForKeyword(group);
}
}
return specializedConfiguration;
}
Aggregations