### Question:
LibraryVersions implements DynamicMBean, InitializingBean { void findMavenArtifacts(Enumeration<URL> mavenDirs) throws IOException, SAXException, XPathExpressionException, ParserConfigurationException { XPath xpath = XPathFactory.newInstance().newXPath(); DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance(); builderFactory.setFeature(XMLConstants.FEATURE_SECURE_PROCESSING, true); builderFactory.setFeature("http: builderFactory.setFeature("http: DocumentBuilder builder = builderFactory.newDocumentBuilder(); while (mavenDirs.hasMoreElements()) { URL u = mavenDirs.nextElement(); if (u.getProtocol().equals("jar")) { String file = u.getFile(); file = file.substring(0, file.indexOf("!")); file = file.substring(5); file = URLDecoder.decode(file, "UTF-8"); try (JarFile jarFile = new JarFile(file)) { Enumeration<JarEntry> entries = jarFile.entries(); while (entries.hasMoreElements()) { JarEntry entry = entries.nextElement(); try { if (entry.getName().endsWith("pom.xml")) { try (InputStream is = jarFile.getInputStream(entry)) { Document doc = builder.parse(is); String groupId = xpath.evaluate("/project/groupId", doc); if (groupId == null || "".equals(groupId)) { groupId = xpath.evaluate("/project/parent/groupId", doc); if (groupId == null || "".equals(groupId)) { logger.warn("Can't work out groupId for pom: "+file+"!"+entry); break; } } String artifactId = xpath.evaluate("/project/artifactId", doc); if (artifactId == null || "".equals(artifactId)) { artifactId = xpath.evaluate("/project/parent/artifactId", doc); if (artifactId == null || "".equals(artifactId)) { logger.warn("Can't work out artifactId for pom: "+file+"!"+entry); break; } } String version = xpath.evaluate("/project/version", doc); if (version == null || "".equals(version)) { version = xpath.evaluate("/project/parent/version", doc); if (version == null || "".equals(version)) { logger.warn("Can't work out version for pom: "+file+"!"+entry); break; } } artifacts.put(groupId + ":" + artifactId, version); } } } catch (IOException e) { logger.error("Can't resolve "+entry.getName()); throw e; } } } } else { logger.info("Can't examine maven artifact in non jar location: "+u); } } }  @Override void afterPropertiesSet(); @Override Object getAttribute(String attribute); @Override void setAttribute(Attribute attribute); @Override AttributeList getAttributes(String[] attributes); @Override AttributeList setAttributes(AttributeList attributes); @Override Object invoke(String actionName, Object[] params, String[] signature); @Override MBeanInfo getMBeanInfo();  }### Answer:
@Test public void normalPath() throws IOException, SAXException, XPathExpressionException, ParserConfigurationException, ReflectionException, AttributeNotFoundException, MBeanException { URL u = createJarWithPom("somejar.jar"); LibraryVersions lv = new LibraryVersions(); Enumeration<URL> enumeration = new ArrayEnumerator<URL>(new URL[] {u}); lv.findMavenArtifacts(enumeration); assertAttribute(lv); }
@Test public void pathWithSpaces() throws IOException, SAXException, XPathExpressionException, ParserConfigurationException, ReflectionException, AttributeNotFoundException, MBeanException { URL u = createJarWithPom("some jar.jar"); LibraryVersions lv = new LibraryVersions(); Enumeration<URL> enumeration = new ArrayEnumerator<URL>(new URL[] {u}); lv.findMavenArtifacts(enumeration); assertAttribute(lv); }