/** * {@inheritDoc} */ public String getName() { return aPackage.getName(); } }
/** * @since 2.7 */ public static String getPackageName(Class<?> cls) { Package pkg = cls.getPackage(); return (pkg == null) ? null : pkg.getName(); }
/** * @since 2.7 */ public static String getPackageName(Class<?> cls) { Package pkg = cls.getPackage(); return (pkg == null) ? null : pkg.getName(); }
/** * {@inheritDoc} */ public void setLoggerContext(LoggerContext lc) { this.lc = lc; this.logger = lc.getLogger(getClass().getPackage().getName()); }
private String resolveName(String templateName) { if (templateName.startsWith("/")) { return templateName; } final String packagePath = getClass().getPackage().getName().replace('.', '/'); return String.format("/%s/%s", packagePath, templateName); } }
public String toPath(Package packageName) { return toPath(packageName.getName()); }
private List<Class<?>> loadClassesInPackage() throws IOException { List<Class<?>> classes = Lists.newArrayList(); String packageName = getClass().getPackage().getName(); for (ClassPath.ClassInfo classInfo : ClassPath.from(getClass().getClassLoader()).getTopLevelClasses(packageName)) { Class<?> cls; try { cls = classInfo.load(); } catch (NoClassDefFoundError e) { // In case there were linking problems, this is probably not a class we care to test anyway. logger.log(Level.SEVERE, "Cannot load class " + classInfo + ", skipping...", e); continue; } if (!cls.isInterface()) { classes.add(cls); } } return classes; }
@Override boolean isExported(Class<?> source) { if (source.getPackage() == null) { return true; } return (Boolean) invoke(isExportedUnqualified, invoke(getModule, source), source.getPackage().getName()); }
@Override boolean isExported(Class<?> source, Class<?> target) { if (source.getPackage() == null) { return true; } return (Boolean) invoke(isExported, invoke(getModule, source), source.getPackage().getName(), invoke(getModule, target)); }
@Override boolean isOpened(Class<?> source, Class<?> target) { if (source.getPackage() == null) { return true; } return (Boolean) invoke(isOpen, invoke(getModule, source), source.getPackage().getName(), invoke(getModule, target)); }
private static ClassLoader getClassLoader(final Set<String> disallowedClassNames) { final String concurrentPackage = SettableFuture.class.getPackage().getName(); ClassLoader classLoader = AbstractFutureFallbackAtomicHelperTest.class.getClassLoader(); // we delegate to the current classloader so both loaders agree on classes like TestCase return new URLClassLoader(ClassPathUtil.getClassPathUrls(), classLoader) { @Override public Class<?> loadClass(String name) throws ClassNotFoundException { if (disallowedClassNames.contains(name)) { throw new ClassNotFoundException("I'm sorry Dave, I'm afraid I can't do that."); } if (name.startsWith(concurrentPackage)) { Class<?> c = findLoadedClass(name); if (c == null) { return super.findClass(name); } return c; } return super.loadClass(name); } }; } }
private static ClassLoader getClassLoader(final Set<String> blocklist) { final String concurrentPackage = SettableFuture.class.getPackage().getName(); ClassLoader classLoader = AggregateFutureStateFallbackAtomicHelperTest.class.getClassLoader(); // we delegate to the current classloader so both loaders agree on classes like TestCase return new URLClassLoader(ClassPathUtil.getClassPathUrls(), classLoader) { @Override public Class<?> loadClass(String name) throws ClassNotFoundException { if (blocklist.contains(name)) { throw new ClassNotFoundException("I'm sorry Dave, I'm afraid I can't do that."); } if (name.startsWith(concurrentPackage)) { Class<?> c = findLoadedClass(name); if (c == null) { return super.findClass(name); } return c; } return super.loadClass(name); } }; } }
@Test public void shouldNotScanTwice() { TestImport.scanned = false; AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(); context.scan(TestImport.class.getPackage().getName()); context.refresh(); context.getBean(TestConfiguration.class); }
@Test public void testHasValidTag() { assertEquals(RequestManagerRetriever.class.getPackage().getName(), RequestManagerRetriever.FRAGMENT_TAG); }
/** * Prior to the fix for SPR-8761, this test threw because the nested MyComponent * annotation was being falsely considered as a 'lite' Configuration class candidate. */ @Test public void repro() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.scan(getClass().getPackage().getName()); ctx.refresh(); assertThat(ctx.containsBean("withNestedAnnotation"), is(true)); }
@Test public void testGetPackageName() { assertEquals("java.lang", ClassUtils.getPackageName(String.class)); assertEquals(getClass().getPackage().getName(), ClassUtils.getPackageName(getClass())); }
/** * Prior to fixing SPR-10546 this might have succeeded depending on the ordering the * classes were picked up. If they are picked up in the same order as * {@link #enclosingConfigFirstParentDefinesBean()} then it would fail. This test is * mostly for illustration purposes, but doesn't hurt to continue using it. * * <p>We purposely use the {@link AEnclosingConfig} to make it alphabetically prior to the * {@link AEnclosingConfig.ChildConfig} which encourages this to occur with the * classpath scanning implementation being used by the author of this test. */ @Test public void enclosingConfigFirstParentDefinesBeanWithScanning() { AnnotationConfigApplicationContext ctx= new AnnotationConfigApplicationContext(); context = ctx; ctx.scan(AEnclosingConfig.class.getPackage().getName()); ctx.refresh(); assertThat(context.getBean("myBean",String.class), equalTo("myBean")); }
@Test public void controlScan() { AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext(); ctx.scan(example.scannable._package.class.getPackage().getName()); ctx.refresh(); assertThat("control scan for example.scannable package failed to register FooServiceImpl bean", ctx.containsBean("fooServiceImpl"), is(true)); }
private ApplicationContext createContext(ScopedProxyMode scopedProxyMode) { GenericWebApplicationContext context = new GenericWebApplicationContext(); ClassPathBeanDefinitionScanner scanner = new ClassPathBeanDefinitionScanner(context); scanner.setIncludeAnnotationConfig(false); scanner.setBeanNameGenerator((definition, registry) -> definition.getScope()); scanner.setScopedProxyMode(scopedProxyMode); // Scan twice in order to find errors in the bean definition compatibility check. scanner.scan(getClass().getPackage().getName()); scanner.scan(getClass().getPackage().getName()); context.refresh(); return context; }
@Test public void naming() throws MalformedObjectNameException { JmxTestBean bean = new JmxTestBean(); IdentityNamingStrategy strategy = new IdentityNamingStrategy(); ObjectName objectName = strategy.getObjectName(bean, "null"); assertEquals("Domain is incorrect", bean.getClass().getPackage().getName(), objectName.getDomain()); assertEquals("Type property is incorrect", ClassUtils.getShortName(bean.getClass()), objectName.getKeyProperty(IdentityNamingStrategy.TYPE_KEY)); assertEquals("HashCode property is incorrect", ObjectUtils.getIdentityHexString(bean), objectName.getKeyProperty(IdentityNamingStrategy.HASH_CODE_KEY)); }