NpmAnalyzerPlugin implements AnalyzerPlugin { @Override public boolean analyzeJar(Analyzer analyzer) throws Exception { Jar jar = analyzer.getJar(); Resource npmJSONResource = jar.getResource("package.json"); if (npmJSONResource == null) { return false; } NpmModule npmModule = processNpmJsonResource(analyzer, npmJSONResource); processDependencies(analyzer, npmModule); return false; }  @Override boolean analyzeJar(Analyzer analyzer); static final String WEB_CONTEXT_PATH; }
@Test public void testPlugin() throws Exception { Analyzer analyzer = new Analyzer(); Jar jar = new Jar("test"); jar.putResource( "package.json", new EmbeddedResource(getString("dependencies/package.json"), 0)); analyzer.setJar(jar); NpmAnalyzerPlugin npmAnalyzerPlugin = new NpmAnalyzerPlugin(); npmAnalyzerPlugin.analyzeJar(analyzer); Assert.assertEquals("1.2.4", analyzer.getBundleVersion()); Assert.assertEquals( "/liferay-1.2.4", analyzer.getProperty(NpmAnalyzerPlugin.WEB_CONTEXT_PATH)); String property = analyzer.getProperty(Constants.PROVIDE_CAPABILITY); Assert.assertEquals( "osgi.webresource;osgi.webresource=liferay;" + "version:Version=\"1.2.4\"", property); property = analyzer.getProperty(Constants.REQUIRE_CAPABILITY); Assert.assertEquals( "osgi.webresource;filter:=\"(&(osgi.webresource=liferay)" + "(&(version>=1.0.0)(!(version>=1.1.0))))\"", property); }
@Test public void testPluginWithBadVersion() throws Exception { Analyzer analyzer = new Analyzer(); Jar jar = new Jar("test"); jar.putResource( "package.json", new EmbeddedResource( getString("dependencies/package.bad.version.json"), 0)); analyzer.setJar(jar); NpmAnalyzerPlugin npmAnalyzerPlugin = new NpmAnalyzerPlugin(); npmAnalyzerPlugin.analyzeJar(analyzer); Assert.assertEquals("0.0.0.1word-cha_rs", analyzer.getBundleVersion()); Assert.assertEquals( "/liferay-0.0.0.1word-cha_rs", analyzer.getProperty(NpmAnalyzerPlugin.WEB_CONTEXT_PATH)); Assert.assertEquals( "osgi.webresource;osgi.webresource=liferay;" + "version:Version=\"0.0.0.1word-cha_rs\"", analyzer.getProperty(Constants.PROVIDE_CAPABILITY)); }
@Test(expected = IllegalArgumentException.class) public void testPluginWithEmptyBower() throws Exception { Analyzer analyzer = new Analyzer(); Jar jar = new Jar("test"); jar.putResource("package.json", new EmbeddedResource("", 0)); analyzer.setJar(jar); NpmAnalyzerPlugin npmAnalyzerPlugin = new NpmAnalyzerPlugin(); npmAnalyzerPlugin.analyzeJar(analyzer); }