use of org.reflections.Reflections in project Gaffer by gchq.
the class StreamUtil method openStreams.
/**
* Open all of the files found in the specified subdirectory of the provided
* class.
*
* @param clazz the class location
* @param folderPath the subdirectory in the class location
* @return an array of {@link InputStream}s representing the files found
*/
public static InputStream[] openStreams(final Class clazz, final String folderPath) {
if (null == folderPath) {
return new InputStream[0];
}
String folderPathChecked = getFormattedPath(folderPath);
final HashSet<InputStream> inputStreams = Sets.newHashSet();
new Reflections(new ConfigurationBuilder().setScanners(new ResourcesScanner()).setUrls(ClasspathHelper.forClass(clazz))).getResources(Pattern.compile(".*")).stream().filter(file -> file.startsWith(folderPathChecked)).forEach(file -> {
try {
inputStreams.add(openStream(clazz, file));
} catch (final Exception e) {
int closedStreamsCount = closeStreams(inputStreams.toArray(new InputStream[inputStreams.size()]));
LOGGER.info(String.format("Closed %s input streams", closedStreamsCount));
}
});
if (inputStreams.isEmpty()) {
throw new IllegalArgumentException("No file could be found in path: " + folderPath);
}
return inputStreams.toArray(new InputStream[inputStreams.size()]);
}
use of org.reflections.Reflections in project alluxio by Alluxio.
the class CollectInfoTest method getNumberOfCommands.
private int getNumberOfCommands() {
Reflections reflections = new Reflections(AbstractCollectInfoCommand.class.getPackage().getName());
int cnt = 0;
for (Class<? extends Command> cls : reflections.getSubTypesOf(Command.class)) {
if (!Modifier.isAbstract(cls.getModifiers())) {
cnt++;
}
}
return cnt;
}
use of org.reflections.Reflections in project Smack by igniterealtime.
the class SmackIntegrationTestFramework method run.
public synchronized TestRunResult run() throws KeyManagementException, NoSuchAlgorithmException, SmackException, IOException, XMPPException, InterruptedException, InstantiationException, IllegalAccessException, IllegalArgumentException, InvocationTargetException {
// it is a global setting, but we treat it like a per sinttest run setting.
switch(config.dnsResolver) {
case minidns:
MiniDnsResolver.setup();
break;
case javax:
JavaxResolver.setup();
break;
case dnsjava:
DNSJavaResolver.setup();
break;
}
testRunResult = new TestRunResult();
// Create a connection manager *after* we created the testRunId (in testRunResult).
this.connectionManager = new XmppConnectionManager(this);
LOGGER.info("SmackIntegrationTestFramework [" + testRunResult.testRunId + ']' + ": Starting\nSmack version: " + Smack.getVersion());
if (config.debugger != Configuration.Debugger.none) {
// JUL Debugger will not print any information until configured to print log messages of
// level FINE
// TODO configure JUL for log?
SmackConfiguration.addDisabledSmackClass("org.jivesoftware.smack.debugger.JulDebugger");
SmackConfiguration.DEBUG = true;
}
if (config.replyTimeout > 0) {
SmackConfiguration.setDefaultReplyTimeout(config.replyTimeout);
}
if (config.securityMode != SecurityMode.required && config.accountRegistration == AccountRegistration.inBandRegistration) {
AccountManager.sensitiveOperationOverInsecureConnectionDefault(true);
}
// TODO print effective configuration
String[] testPackages;
if (config.testPackages == null || config.testPackages.isEmpty()) {
testPackages = new String[] { "org.jivesoftware.smackx", "org.jivesoftware.smack" };
} else {
testPackages = config.testPackages.toArray(new String[config.testPackages.size()]);
}
Reflections reflections = new Reflections(testPackages, new SubTypesScanner(), new TypeAnnotationsScanner(), new MethodAnnotationsScanner(), new MethodParameterScanner());
Set<Class<? extends AbstractSmackIntegrationTest>> inttestClasses = reflections.getSubTypesOf(AbstractSmackIntegrationTest.class);
Set<Class<? extends AbstractSmackLowLevelIntegrationTest>> lowLevelInttestClasses = reflections.getSubTypesOf(AbstractSmackLowLevelIntegrationTest.class);
final int builtInTestCount = inttestClasses.size() + lowLevelInttestClasses.size();
Set<Class<? extends AbstractSmackIntTest>> classes = new HashSet<>(builtInTestCount);
classes.addAll(inttestClasses);
classes.addAll(lowLevelInttestClasses);
{
// Remove all abstract classes.
// TODO: This may be a good candidate for Java stream filtering once Smack is Android API 24 or higher.
Iterator<Class<? extends AbstractSmackIntTest>> it = classes.iterator();
while (it.hasNext()) {
Class<? extends AbstractSmackIntTest> clazz = it.next();
if (Modifier.isAbstract(clazz.getModifiers())) {
it.remove();
}
}
}
if (classes.isEmpty()) {
throw new IllegalStateException("No test classes in " + Arrays.toString(testPackages) + " found");
}
LOGGER.info("SmackIntegrationTestFramework [" + testRunResult.testRunId + "]: Finished scanning for tests, preparing environment");
environment = prepareEnvironment();
try {
runTests(classes);
} catch (Throwable t) {
// Log the thrown Throwable to prevent it being shadowed in case the finally block below also throws.
LOGGER.log(Level.SEVERE, "Unexpected abort because runTests() threw throwable", t);
throw t;
} finally {
// Ensure that the accounts are deleted and disconnected before we continue
connectionManager.disconnectAndCleanup();
}
return testRunResult;
}
use of org.reflections.Reflections in project ambrose by twitter.
the class JSONUtil method newMapper.
private static ObjectMapper newMapper() {
ObjectMapper mapper = new ObjectMapper();
mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
mapper.enable(SerializationFeature.INDENT_OUTPUT);
mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_TARGET, false);
mapper.configure(JsonGenerator.Feature.AUTO_CLOSE_JSON_CONTENT, false);
mapper.disable(SerializationFeature.FLUSH_AFTER_WRITE_VALUE);
mapper.disable(SerializationFeature.CLOSE_CLOSEABLE);
mapper.disable(SerializationFeature.FAIL_ON_EMPTY_BEANS);
mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES);
Reflections reflections = new Reflections("com.twitter.ambrose");
Set<Class<? extends Job>> jobSubTypes = reflections.getSubTypesOf(Job.class);
mapper.registerSubtypes(jobSubTypes.toArray(new Class<?>[jobSubTypes.size()]));
return mapper;
}
use of org.reflections.Reflections in project cas by apereo.
the class ConfigurationMetadataClassSourceLocator method locatePropertiesClassForType.
/**
* Locate properties class for type class.
*
* @param type the type
* @return the class
*/
public Class locatePropertiesClassForType(final ClassOrInterfaceType type) {
if (cachedPropertiesClasses.containsKey(type.getNameAsString())) {
return cachedPropertiesClasses.get(type.getNameAsString());
}
val urls = new ArrayList<>(ClasspathHelper.forPackage("org.apereo.cas"));
val reflections = new Reflections(new ConfigurationBuilder().filterInputsBy(s -> s != null && s.contains(type.getNameAsString())).setUrls(urls));
val clz = reflections.getSubTypesOf(Serializable.class).stream().filter(c -> c.getSimpleName().equalsIgnoreCase(type.getNameAsString())).findFirst().orElseThrow(() -> new IllegalArgumentException("Cant locate class for " + type.getNameAsString()));
cachedPropertiesClasses.put(type.getNameAsString(), clz);
return clz;
}
Aggregations