List of usage examples for org.springframework.util ClassUtils CLASS_FILE_SUFFIX
String CLASS_FILE_SUFFIX
To view the source code for org.springframework.util ClassUtils CLASS_FILE_SUFFIX.
Click Source Link
From source file:org.bitsofinfo.util.reflection.SpringClassFinder.java
private static String convertResourceToClassName(Resource resource, String basePackage) throws IOException { String path = resource.getURI().toString(); String pathWithoutSuffix = path.substring(0, path.length() - ClassUtils.CLASS_FILE_SUFFIX.length()); String relativePathWithoutSuffix = pathWithoutSuffix.substring(pathWithoutSuffix.indexOf(basePackage)); String className = relativePathWithoutSuffix.replace(File.separator, "."); return className; }
From source file:org.eclipse.gemini.blueprint.test.AbstractOnTheFlyBundleCreatorTests.java
/** * Determine imports for the given bundle. Based on the user settings, this * method will consider only the the test hierarchy until the testing * framework is found or all classes available inside the test bundle. <p/> * Note that split packages are not supported. * //from ww w. ja v a2 s. com * @return */ private String[] determineImports() { boolean useTestClassOnly = false; // no jar entry present, bail out. if (jarEntries == null || jarEntries.isEmpty()) { logger.debug("No test jar content detected, generating bundle imports from the test class"); useTestClassOnly = true; } else if (createManifestOnlyFromTestClass()) { logger.info("Using the test class for generating bundle imports"); useTestClassOnly = true; } else logger.info("Using all classes in the jar for the generation of bundle imports"); // className, class resource Map entries; if (useTestClassOnly) { entries = new LinkedHashMap(4); // get current class (test class that bootstraps the OSGi infrastructure) Class<?> clazz = getClass(); String clazzPackage = null; String endPackage = AbstractOnTheFlyBundleCreatorTests.class.getPackage().getName(); do { // consider inner classes as well List classes = new ArrayList(4); classes.add(clazz); CollectionUtils.mergeArrayIntoCollection(clazz.getDeclaredClasses(), classes); for (Iterator iterator = classes.iterator(); iterator.hasNext();) { Class<?> classToInspect = (Class) iterator.next(); Package pkg = classToInspect.getPackage(); if (pkg != null) { clazzPackage = pkg.getName(); String classFile = ClassUtils.getClassFileName(classToInspect); entries.put(classToInspect.getName().replace('.', '/').concat(ClassUtils.CLASS_FILE_SUFFIX), new InputStreamResource(classToInspect.getResourceAsStream(classFile))); } // handle default package else { logger.warn("Could not find package for class " + classToInspect + "; ignoring..."); } } clazz = clazz.getSuperclass(); } while (!endPackage.equals(clazzPackage)); } else entries = jarEntries; return determineImportsFor(entries); }
From source file:org.eclipse.gemini.blueprint.test.AbstractOnTheFlyBundleCreatorTests.java
private String[] determineImportsFor(Map entries) { // get contained packages to do matching on the test hierarchy Collection containedPackages = jarCreator.getContainedPackages(); Set cumulatedPackages = new LinkedHashSet(); // make sure the collection package is valid boolean validPackageCollection = !containedPackages.isEmpty(); boolean trace = logger.isTraceEnabled(); for (Iterator iterator = entries.entrySet().iterator(); iterator.hasNext();) { Map.Entry entry = (Map.Entry) iterator.next(); String resourceName = (String) entry.getKey(); // filter out the test hierarchy if (resourceName.endsWith(ClassUtils.CLASS_FILE_SUFFIX)) { if (trace) logger.trace("Analyze imports for test bundle resource " + resourceName); String classFileName = StringUtils.getFilename(resourceName); String className = classFileName.substring(0, classFileName.length() - ClassUtils.CLASS_FILE_SUFFIX.length()); String classPkg = resourceName.substring(0, resourceName.length() - classFileName.length()) .replace('/', '.'); if (classPkg.startsWith(".")) classPkg = classPkg.substring(1); if (classPkg.endsWith(".")) classPkg = classPkg.substring(0, classPkg.length() - 1); // if we don't have the package, add it if (validPackageCollection && StringUtils.hasText(classPkg) && !containedPackages.contains(classPkg)) { logger.trace(//from www . j a v a2 s. c o m "Package [" + classPkg + "] is NOT part of the test archive; adding an import for it"); cumulatedPackages.add(classPkg); } // otherwise parse the class byte-code else { if (trace) logger.trace("Package [" + classPkg + "] is part of the test archive; parsing " + className + " bytecode to determine imports..."); cumulatedPackages.addAll(determineImportsForClass(className, (Resource) entry.getValue())); } } } return (String[]) cumulatedPackages.toArray(new String[cumulatedPackages.size()]); }