ExtJarGraph { void addJarFile(JarFile jar) { JarNode node = null; Manifest manifest = null; try { manifest = jar.getManifest(); } catch (IOException ioe) { throw new IllegalStateException("Failed to get manifest from " + "jar file: " + jar.getName()); } if (manifest == null) { throw new IllegalStateException("Manifest missing in extension " + "jar file: " + jar.getName()); } Attributes attrs = manifest.getMainAttributes(); String extName = attrs.getValue(Name.SPECIFICATION_TITLE); if (extName == null) { throw new IllegalStateException("Specification name required"); } if (extNodes.containsKey(extName)) { throw new IllegalStateException("Found two extensions with the " + "same name: " + extName); } String extVersion = attrs.getValue(Name.SPECIFICATION_VERSION); if (extVersion == null) { throw new IllegalStateException("Specification version required"); } JarEntry propertiesEntry = jar.getJarEntry(EXT_PROPERTIES_FILE); if (propertiesEntry != null) { Properties p = new Properties(); try { p.load(jar.getInputStream(propertiesEntry)); } catch (IOException ioe) { throw new IllegalStateException("Malformed properties in " + "ext jar: " + jar.getName()); } node = new JarNode(extName, extVersion, p); hasPreferences = true; String dependencies = (String) p.remove(DEPENDENCY_PROPERTY); if (dependencies != null) { hasDependencies = true; for (String dependency : dependencies.split(":")) { node.namedDependencies.add(dependency); } } } else { node = new JarNode(extName, extVersion); } extNodes.put(extName, node); dependencyRoots.add(node); } ExtJarGraph();   }
@Test(expected = IllegalStateException.class) public void testJarMissingManifest() throws Exception { ExtJarGraph graph = new ExtJarGraph(); graph.addJarFile(new JarFile(JAR_NO_MANIFEST)); }
@Test(expected = IllegalStateException.class) public void testJarMissingName() throws Exception { ExtJarGraph graph = new ExtJarGraph(); graph.addJarFile(new JarFile(JAR_NO_NAME)); }
@Test(expected = IllegalStateException.class) public void testJarMissingVersion() throws Exception { ExtJarGraph graph = new ExtJarGraph(); graph.addJarFile(new JarFile(JAR_NO_VERSION)); }
@Test(expected = IllegalStateException.class) public void testDuplicateNamedJar() throws Exception { ExtJarGraph graph = new ExtJarGraph(); try { graph.addJarFile(new JarFile(JAR_A)); } catch (IllegalStateException ise) { throw new RuntimeException("Unexpected Failure", ise); } graph.addJarFile(new JarFile(JAR_A)); }