本文整理匯總了Java中org.reflections.util.ClasspathHelper.forPackage方法的典型用法代碼示例。如果您正苦於以下問題:Java ClasspathHelper.forPackage方法的具體用法?Java ClasspathHelper.forPackage怎麽用?Java ClasspathHelper.forPackage使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.reflections.util.ClasspathHelper
的用法示例。
在下文中一共展示了ClasspathHelper.forPackage方法的13個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: prepareAndgetContextListener
import org.reflections.util.ClasspathHelper; //導入方法依賴的package包/類
/**
* Prepares the logger context. Locates the context and
* sets the configuration file.
* @return the logger context
*/
private ServletContextListener prepareAndgetContextListener() {
try {
if (StringUtils.isNotBlank(this.loggerContextPackageName)) {
final Collection<URL> set = ClasspathHelper.forPackage(this.loggerContextPackageName);
final Reflections reflections = new Reflections(new ConfigurationBuilder().addUrls(set).setScanners(new SubTypesScanner()));
final Set<Class<? extends ServletContextListener>> subTypesOf = reflections.getSubTypesOf(ServletContextListener.class);
final ServletContextListener loggingContext = subTypesOf.iterator().next().newInstance();
this.context.setInitParameter(this.logConfigurationField, this.logConfigurationFile.getURI().toString());
return loggingContext;
}
return null;
} catch (final Exception e) {
throw new RuntimeException(e);
}
}
示例2: scanContextForLoggerFactories
import org.reflections.util.ClasspathHelper; //導入方法依賴的package包/類
private Set<Class<? extends ILoggerFactory>> scanContextForLoggerFactories() {
final Set<Class<? extends ILoggerFactory>> loggerFactories;
final Collection<URL> set = ClasspathHelper.forPackage(PACKAGE_TO_SCAN);
final Reflections reflections = new Reflections(new ConfigurationBuilder().addUrls(set).setScanners(new SubTypesScanner()));
loggerFactories = reflections.getSubTypesOf(ILoggerFactory.class);
loggerFactories.remove(this.getClass());
return loggerFactories;
}
示例3: CasLoggerFactory
import org.reflections.util.ClasspathHelper; //導入方法依賴的package包/類
/**
* Instantiates a new Cas logger factory.
* Configures the reflection scanning engine to be prepared to scan <code>org.slf4j.impl</code>
* in order to find other available factories.
*/
public CasLoggerFactory() {
this.loggerMap = new ConcurrentHashMap<>();
final Collection<URL> set = ClasspathHelper.forPackage(PACKAGE_TO_SCAN);
final Reflections reflections = new Reflections(new ConfigurationBuilder().addUrls(set).setScanners(new SubTypesScanner()));
final Set<Class<? extends ILoggerFactory>> subTypesOf = reflections.getSubTypesOf(ILoggerFactory.class);
subTypesOf.remove(this.getClass());
if (subTypesOf.size() > 1) {
Util.report("Multiple ILoggerFactory bindings are found on the classpath:");
for (final Class<? extends ILoggerFactory> c : subTypesOf) {
Util.report("* " + c.getCanonicalName());
}
}
if (subTypesOf.isEmpty()) {
final RuntimeException e = new RuntimeException("No ILoggerFactory could be found on the classpath."
+ " CAS cannot determine the logging framework."
+ " Examine the project dependencies and ensure that there is one and only one logging framework available.");
Util.report(e.getMessage(), e);
throw e;
}
this.realLoggerFactoryClass = subTypesOf.iterator().next();
Util.report("ILoggerFactory to be used for logging is: " + this.realLoggerFactoryClass.getName());
}
示例4: getSubClasses
import org.reflections.util.ClasspathHelper; //導入方法依賴的package包/類
private <CLASS> LinkedHashSet<Class<? extends CLASS>> getSubClasses(final Class<?> clazz, final String packageName) {
final Set<URL> urls = new HashSet<>(ClasspathHelper.forPackage("gaffer"));
final List<Class<? extends CLASS>> classes = new ArrayList(new Reflections(urls).getSubTypesOf(clazz));
keepPublicConcreteClasses(classes);
keepClassesInPackage(classes, packageName);
Collections.sort(classes, new Comparator<Class>() {
@Override
public int compare(final Class class1, final Class class2) {
return class1.getName().compareTo(class2.getName());
}
});
return Sets.newLinkedHashSet((Iterable) classes);
}
示例5: _urlsForPackage
import org.reflections.util.ClasspathHelper; //導入方法依賴的package包/類
private static Collection<URL> _urlsForPackage(final String pckg,
final ClassLoader otherClassLoader) {
ClassLoader[] classLoaders = _scanClassLoaders(otherClassLoader);
// org.reflections.ClasspathHelper seems to return ONLY the jar or path containing the given package
// ... so the package MUST be added back to the url to minimize scan time and unneeded class loading
Collection<URL> outUrls = ClasspathHelper.forPackage(pckg,
classLoaders);
if (CollectionUtils.hasData(outUrls)) {
outUrls = FluentIterable.from(outUrls)
.transform(new Function<URL,URL>() {
@Override
public URL apply(final URL url) {
try {
URL fullUrl = new URL(url.toString() + _resourceName(pckg));
log.trace("URL to be scanned: {}",fullUrl);
return fullUrl;
} catch(Throwable th) {
th.printStackTrace(System.out);
}
return url;
}
})
.toList();
}
return outUrls;
}
示例6: scan
import org.reflections.util.ClasspathHelper; //導入方法依賴的package包/類
@SuppressWarnings("rawtypes")
private Map<Class<?>, Converter<?>> scan(ClassLoader... classloaders) {
if (log.isDebugEnabled())
log.debug("scan <-");
Collection<URL> urls = ClasspathHelper.forPackage("play.utils.meta.convert", classloaders);
if (log.isDebugEnabled())
log.debug("urls : " + urls);
Configuration configs = new ConfigurationBuilder().setUrls(
urls).addClassLoaders(classloaders).setScanners(new SubTypesScanner(false));
final Reflections reflections = new Reflections(configs);
Map<Class<?>, Converter<?>> map = Maps.newHashMap();
Set<Class<? extends Converter>> converterClasses = reflections.getSubTypesOf(Converter.class);
if (log.isDebugEnabled())
log.debug("converterClasses : " + converterClasses);
for (Class<? extends Converter> converterClass : converterClasses) {
try {
if (log.isDebugEnabled())
log.debug("converterClass : " + converterClass);
Converter converter = converterClass.newInstance();
if (converter != null) {
Class<?> keyClass = converter.typeClass();
log.info("Converter:" + keyClass + " : " + converter);
map.put(keyClass, converter);
}
} catch (Exception e) {
e.printStackTrace();
}
}
return map;
}
示例7: dirWithSpaces
import org.reflections.util.ClasspathHelper; //導入方法依賴的package包/類
@Test public void dirWithSpaces() {
Collection<URL> urls = ClasspathHelper.forPackage("dir+with spaces");
assertFalse(urls.isEmpty());
for (URL url : urls) {
testVfsDir(url);
}
}
示例8: addPackage
import org.reflections.util.ClasspathHelper; //導入方法依賴的package包/類
public void addPackage(String packageName) {
ConfigurationBuilder config = new ConfigurationBuilder();
FilterBuilder fb = new FilterBuilder();
fb.include(FilterBuilder.prefix(packageName));
config.filterInputsBy(fb);
Set<URL> urls = ClasspathHelper.forPackage(packageName);
urls = GoogleReflectionsUtil.fixURLs(urls); //jboss compatibility hack
config.setUrls(urls);
Reflections packageReflections = new Reflections(config);
//packageReflections = new Reflections(packageName);
reflections.merge(packageReflections);
refresh();
}
示例9: listLanguageSpecificationPlugins
import org.reflections.util.ClasspathHelper; //導入方法依賴的package包/類
private List<Class<? extends LanguageSpecification>> listLanguageSpecificationPlugins() {
Reflections reflections = new Reflections(ClasspathHelper.forPackage("de.uniwue.info2"), new SubTypesScanner());
Set<Class<? extends LanguageSpecification>> modules = reflections.getSubTypesOf(de.uniwue.info2.generator.LanguageSpecification.class);
List<Class<? extends LanguageSpecification>> specs = new ArrayList<Class<? extends LanguageSpecification>>(modules);
return specs;
}
示例10: listUnitTestLibrarySpecificationPlugins
import org.reflections.util.ClasspathHelper; //導入方法依賴的package包/類
private List<Class<? extends UnitTestLibrarySpecification>> listUnitTestLibrarySpecificationPlugins(Package lang_package) {
Reflections reflections = new Reflections(ClasspathHelper.forPackage("de.uniwue.info2"), new SubTypesScanner());
Set<Class<? extends UnitTestLibrarySpecification>> modules = reflections
.getSubTypesOf(de.uniwue.info2.generator.UnitTestLibrarySpecification.class);
List<Class<? extends UnitTestLibrarySpecification>> specs = new ArrayList<Class<? extends UnitTestLibrarySpecification>>();
for (Class<? extends UnitTestLibrarySpecification> u : modules) {
if (u.getPackage().equals(lang_package)) {
specs.add(u);
}
}
return specs;
}
示例11: listArithmeticLibrarySpecificationPlugins
import org.reflections.util.ClasspathHelper; //導入方法依賴的package包/類
private List<Class<? extends ArithmeticLibrarySpecification>> listArithmeticLibrarySpecificationPlugins(Package lang_package) {
Reflections reflections = new Reflections(ClasspathHelper.forPackage("de.uniwue.info2"), new SubTypesScanner());
Set<Class<? extends ArithmeticLibrarySpecification>> modules = reflections
.getSubTypesOf(de.uniwue.info2.generator.ArithmeticLibrarySpecification.class);
List<Class<? extends ArithmeticLibrarySpecification>> specs = new ArrayList<Class<? extends ArithmeticLibrarySpecification>>();
for (Class<? extends ArithmeticLibrarySpecification> a : modules) {
if (a.getPackage().equals(lang_package)) {
specs.add(a);
}
}
return specs;
}
示例12: forPackage
import org.reflections.util.ClasspathHelper; //導入方法依賴的package包/類
/**
* Creates an {@code EntityFinder} for the provided package.
*
* @param project The Maven project in which the calling Mojo is
* executed. Can be {@code null}.
* @param log An Maven log object for creating output.
* @param packageName The name of the package in the class should look for
* entities.
*
* @return An {@code EntityFinder} instance.
*
* @throws MojoFailureException If the {@link Reflections} instance needed
* by the {@code EntityFinder} can't be
* created.
*/
@SuppressWarnings("unchecked")
public static EntityFinder forPackage(final MavenProject project,
final Log log,
final String packageName)
throws MojoFailureException {
final Reflections reflections;
if (project == null) {
reflections = new Reflections(
ClasspathHelper.forPackage(packageName));
} else {
final List<String> classPathElems;
try {
classPathElems = project.getCompileClasspathElements();
} catch (DependencyResolutionRequiredException ex) {
throw new MojoFailureException(
"Failed to resolve project classpath.", ex);
}
final List<URL> classPathUrls = new ArrayList<>();
for (final String classPathElem : classPathElems) {
log.info(String.format("Adding classpath elemement '%s'...",
classPathElem));
classPathUrls.add(classPathElemToUrl(classPathElem));
}
log.info("Classpath URLs:");
for (final URL url : classPathUrls) {
log.info(String.format("\t%s", url.toString()));
}
//Here we have to do some classloader magic to ensure that the
//Reflections instance uses the correct class loader. Which is the
//one which has access to the compiled classes
final ClassLoader classLoader = AccessController
.doPrivileged(new ClassLoaderCreator(classPathUrls));
reflections = new Reflections(
ClasspathHelper.forPackage(packageName, classLoader));
}
return new EntityFinder(reflections);
}
示例13: runMethodParallelAppium
import org.reflections.util.ClasspathHelper; //導入方法依賴的package包/類
public boolean runMethodParallelAppium(List<String> test, String pack, int devicecount,
String executionType) throws Exception {
URL newUrl = null;
List<URL> newUrls = new ArrayList<>();
Collections.addAll(items, pack.split("\\s*,\\s*"));
int a = 0;
Collection<URL> urls = ClasspathHelper.forPackage(items.get(a));
Iterator<URL> iter = urls.iterator();
URL url = iter.next();
urls.clear();
for (int i = 0; i < items.size(); i++) {
newUrl = new URL(url.toString() + items.get(i).replaceAll("\\.", "/"));
newUrls.add(newUrl);
a++;
}
Reflections reflections = new Reflections(new ConfigurationBuilder().setUrls(newUrls)
.setScanners(new MethodAnnotationsScanner()));
Set<Method> resources =
reflections.getMethodsAnnotatedWith(org.testng.annotations.Test.class);
boolean hasFailure;
String runnerLevel = System.getenv("RUNNER_LEVEL") != null
? System.getenv("RUNNER_LEVEL") : prop.getProperty("RUNNER_LEVEL");
if (executionType.equalsIgnoreCase("distribute")) {
if (runnerLevel != null
&& runnerLevel.equalsIgnoreCase("class")) {
constructXmlSuiteForDistribution(pack, test, createTestsMap(resources),
devicecount);
} else {
constructXmlSuiteForDistributionMethods(pack, test, createTestsMap(resources),
devicecount);
}
hasFailure = runMethodParallel();
} else {
constructXmlSuiteForParallel(pack, test, createTestsMap(resources), devicecount,
deviceAllocationManager.getDevices());
hasFailure = runMethodParallel();
}
System.out.println("Finally complete");
ParallelThread.figlet("Test Completed");
//ImageUtils.creatResultsSet();
//ImageUtils.createJSonForHtml();
return hasFailure;
}