/** * Returns the set of package names, compiled from all * checkstyle_packages.xml files found on the given class loaders * classpath. * @param classLoader the class loader for loading the * checkstyle_packages.xml files. * @return the set of package names. * @throws CheckstyleException if an error occurs. */ public static Set<String> getPackageNames(ClassLoader classLoader) throws CheckstyleException { final Set<String> result; try { //create the loader outside the loop to prevent PackageObjectFactory //being created anew for each file final PackageNamesLoader namesLoader = new PackageNamesLoader(); final Enumeration<URL> packageFiles = classLoader.getResources(CHECKSTYLE_PACKAGES); while (packageFiles.hasMoreElements()) { processFile(packageFiles.nextElement(), namesLoader); } result = namesLoader.packageNames; } catch (IOException ex) { throw new CheckstyleException("unable to get package file resources", ex); } catch (ParserConfigurationException | SAXException ex) { throw new CheckstyleException("unable to open one of package files", ex); } return result; }
/** * Returns the set of package names, compiled from all * checkstyle_packages.xml files found on the given class loaders * classpath. * @param classLoader the class loader for loading the * checkstyle_packages.xml files. * @return the set of package names. * @throws CheckstyleException if an error occurs. */ public static Set<String> getPackageNames(ClassLoader classLoader) throws CheckstyleException { final Set<String> result; try { //create the loader outside the loop to prevent PackageObjectFactory //being created anew for each file final PackageNamesLoader namesLoader = new PackageNamesLoader(); final Enumeration<URL> packageFiles = classLoader.getResources(CHECKSTYLE_PACKAGES); while (packageFiles.hasMoreElements()) { processFile(packageFiles.nextElement(), namesLoader); } result = namesLoader.packageNames; } catch (IOException ex) { throw new CheckstyleException("unable to get package file resources", ex); } catch (ParserConfigurationException | SAXException ex) { throw new CheckstyleException("unable to open one of package files", ex); } return result; }