/** * Packages#getPackages(). */ public static Package of(final ClassLoader classLoader, final String name) { return Package.getPackage(name); } }
Package pkg = Package.getPackage("com.abc"); System.out.println(pkg); Class<A> a = A.class; pkg = Package.getPackage("com.abc"); System.out.println(pkg);
public Object readResolve() { return inPackage(Package.getPackage(packageName)); }
/** * Get the version. * * @return the version of WorldEdit */ public static String getVersion() { if (version != null) { return version; } Package p = WorldEdit.class.getPackage(); if (p == null) { p = Package.getPackage("com.sk89q.worldedit"); } if (p == null) { version = "(unknown)"; } else { version = p.getImplementationVersion(); if (version == null) { version = "(unknown)"; } } return version; }
private static Ignore findAnnotation(Package testPackage) { if (testPackage == null) { return null; } Ignore result = testPackage.getAnnotation(Ignore.class); if (result != null) { return result; } String[] parts = testPackage.getName().split("\\."); String[] parentParts = Arrays.copyOf(parts, parts.length - 1); String parentPackageName = Strings.join(".", parentParts); if (parentPackageName.isEmpty()) { return null; } return findAnnotation(Package.getPackage(parentPackageName)); } }
private boolean isLoadCandidate(Resource resource) { if (resource == null || !resource.exists()) { return false; } if (resource instanceof ClassPathResource) { // A simple package without a '.' may accidentally get loaded as an XML // document if we're not careful. The result of getInputStream() will be // a file list of the package content. We double check here that it's not // actually a package. String path = ((ClassPathResource) resource).getPath(); if (path.indexOf('.') == -1) { try { return Package.getPackage(path) == null; } catch (Exception ex) { // Ignore } } } return true; }
String logLevelUpper = (logLevel == null) ? "OFF" : logLevel.toUpperCase(); try { Package log4jPackage = Package.getPackage(LOG4J_CLASSIC); if (log4jPackage == null) { LOG.warn("Log4j is not in the classpath!");
private Package findPackage(CharSequence source) { Package pkg = Package.getPackage(source.toString()); if (pkg != null) { return pkg; } try { // Attempt to find a class in this package ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver( getClass().getClassLoader()); Resource[] resources = resolver.getResources( ClassUtils.convertClassNameToResourcePath(source.toString()) + "/*.class"); for (Resource resource : resources) { String className = StringUtils .stripFilenameExtension(resource.getFilename()); load(Class.forName(source.toString() + "." + className)); break; } } catch (Exception ex) { // swallow exception and continue } return Package.getPackage(source.toString()); }
String logLevelUpper = (logLevel == null) ? "OFF" : logLevel.toUpperCase(); try { Package logbackPackage = Package.getPackage(LOGBACK_CLASSIC); if (logbackPackage == null) { LOG.warn("Logback is not in the classpath!");
private static Ignore findAnnotation(Package testPackage) { if (testPackage == null) { return null; } Ignore result = testPackage.getAnnotation(Ignore.class); if (result != null) { return result; } String[] parts = testPackage.getName().split("\\."); String[] parentParts = Arrays.copyOf(parts, parts.length - 1); String parentPackageName = Strings.join(".", parentParts); if (parentPackageName.isEmpty()) { return null; } return findAnnotation(Package.getPackage(parentPackageName)); } }
@Test public void testPackagesFromParentClassLoaderAreMadeAvailableByName() throws Exception { assertThat(Test.class.getPackage()).isNotNull(); assertThat(Package.getPackage("org.junit")).isNotNull(); assertThat(Package.getPackage("org.junit")).isEqualTo(Test.class.getPackage()); } }
@Override public Object convertFromString(Class<?> cls, String str) { return Package.getPackage(str); } },
@Override public Package getActualPackage() { return Package.getPackage(getSimpleName()); }
static String shortClassName(Class<?> type) { Package pkg = type.getPackage(); if (ClassUtils.isPrimitiveOrWrapper(type)) { if (!type.isPrimitive()) { type = ClassUtils.wrapperToPrimitive(type); } return type.getName(); } else if (pkg == null || pkg.equals(Package.getPackage("java.lang"))) { return type.getSimpleName(); } else { String[] words = type.getName().split(" "); String fullClassName = words[words.length - 1]; String[] path = fullClassName.split("\\."); int i = 0; while (i + 1 < path.length && !Character.isUpperCase(path[i + 1].charAt(0))) { path[i] = path[i].substring(0, 1); i++; } return StringUtils.join(path, "."); } }
@SuppressForbidden(reason = "ClassLoader.getDefinedPackage not available yet") public Object readResolve() { // TODO minJava >= 9 : use ClassLoader.getDefinedPackage and remove @SuppressForbidden return inPackage(Package.getPackage(packageName)); } }
@Test public void testCreateNorma() { new ProviderInfo(Package.getPackage("java.util")); }
private static Package getParentPackage(Package pkg) { String name = pkg.getName(); int idx = name.lastIndexOf('.'); return idx == -1 ? null : Package.getPackage(name.substring(0, idx)); }
public static void main(String args[]) throws Exception { Package p = Package.getPackage("org.apache.karaf.shell.impl.console.standalone"); if (p != null && p.getImplementationVersion() != null) { System.setProperty("karaf.version", p.getImplementationVersion()); } Main main = new Main(); main.run(args); }
@JRubyMethod(name = "sealed?") public IRubyObject sealed_p(ThreadContext context) { final Package pkg = Package.getPackage(packageName); if ( pkg == null ) return context.nil; return context.runtime.newBoolean(pkg.isSealed()); }
protected void applyDefaultVersion(Swagger data) { if (applyDefaultVersion && data.getInfo() != null && data.getInfo().getVersion() == null && beanConfig != null && beanConfig.getResourcePackage() != null) { Package resourcePackage = Package.getPackage(beanConfig.getResourcePackage()); if (resourcePackage != null) { data.getInfo().setVersion(resourcePackage.getImplementationVersion()); } } }