/** * Return the full version string of the present Spring codebase, * or {@code null} if it cannot be determined. * @see Package#getImplementationVersion() */ @Nullable public static String getVersion() { Package pkg = SpringVersion.class.getPackage(); return (pkg != null ? pkg.getImplementationVersion() : null); }
/** * @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 boolean isComingFromJDK(Class<?> type) { // Comes from the manifest entry : // Implementation-Title: Java Runtime Environment // This entry is not necessarily present in every jar of the JDK return type.getPackage() != null && "Java Runtime Environment".equalsIgnoreCase(type.getPackage().getImplementationTitle()) || type.getName().startsWith("java.") || type.getName().startsWith("javax."); }
@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)); }
@Test(groups = CLI, timeOut = TIMEOUT) public void shouldDisplayVersion() throws IOException { launchPrestoCli("--version"); String version = firstNonNull(Presto.class.getPackage().getImplementationVersion(), "(version unknown)"); assertThat(presto.readRemainingOutputLines()).containsExactly("Presto CLI " + version); }
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; }
public File toGeneratedFile(Class<?> compiledClass) { File output = new File(OUTPUT_DIRECTORY, toPath(compiledClass.getPackage()) + "/" + compiledClass.getSimpleName() + getAndroidAnnotationsClassSuffix() + SOURCE_FILE_SUFFIX); return output; }
@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)); }
@Test public void testToFullyQualifiedNamePackageString() throws Exception { final String expected = "org.apache.commons.lang3.Test.properties"; final String actual = ClassPathUtils.toFullyQualifiedName(ClassPathUtils.class.getPackage(), "Test.properties"); assertEquals(expected, actual); }
@Test public void testToFullyQualifiedPathPackage() throws Exception { final String expected = "org/apache/commons/lang3/Test.properties"; final String actual = ClassPathUtils.toFullyQualifiedPath(ClassPathUtils.class.getPackage(), "Test.properties"); assertEquals(expected, actual); } }