JspAnalyzerPlugin implements AnalyzerPlugin { protected void addTaglibRequirements( Analyzer analyzer, String content, Set<String> taglibURIs) { Set<String> taglibRequirements = new TreeSet<>(); for (String uri : getTaglibURIs(content)) { if (taglibURIs.contains(uri)) { continue; } taglibURIs.add(uri); if (containsTLD(analyzer, analyzer.getJar(), "META-INF", uri) || containsTLD( analyzer, analyzer.getJar(), "META-INF/resources", uri) || containsTLD(analyzer, analyzer.getJar(), "WEB-INF/tld", uri) || containsTLDInBundleClassPath(analyzer, "META-INF", uri) || containsTLDInBundleClassPath( analyzer, "META-INF/resources", uri)) { continue; } if (Arrays.binarySearch(_JSTL_CORE_URIS, uri) < 0) { addTaglibRequirement(taglibRequirements, uri); } } if (taglibRequirements.isEmpty()) { return; } String value = analyzer.getProperty(Constants.REQUIRE_CAPABILITY); if (value != null) { Parameters parameters = OSGiHeader.parseHeader(value); for (Map.Entry<String, Attrs> entry : parameters.entrySet()) { String key = Processor.removeDuplicateMarker(entry.getKey()); StringBuilder sb = new StringBuilder(key); Attrs attrs = entry.getValue(); if (attrs != null) { sb.append(";"); attrs.append(sb); } taglibRequirements.add(sb.toString()); } } analyzer.setProperty( Constants.REQUIRE_CAPABILITY, Strings.join(taglibRequirements)); }  @Override boolean analyzeJar(Analyzer analyzer);  }
@Test public void testRemoveDuplicateTaglibRequirements() throws Exception { JspAnalyzerPlugin jspAnalyzerPlugin = new JspAnalyzerPlugin(); URL url = getResource("dependencies/imports_without_comments.jsp"); InputStream inputStream = url.openStream(); String content = IO.collect(inputStream); Builder builder = new Builder(); builder.build(); Set<String> taglibURIs = new HashSet<>(); jspAnalyzerPlugin.addTaglibRequirements(builder, content, taglibURIs); String requireCapability1 = builder.getProperty( Constants.REQUIRE_CAPABILITY); jspAnalyzerPlugin.addTaglibRequirements(builder, content, taglibURIs); String requireCapability2 = builder.getProperty( Constants.REQUIRE_CAPABILITY); Assert.assertEquals(requireCapability1, requireCapability2); }