WabProcessor { public File getProcessedFile() throws IOException { _pluginDir = autoDeploy(); if ((_pluginDir == null) || !_pluginDir.exists() || !_pluginDir.isDirectory()) { return null; } File outputFile = null; try (Jar jar = new Jar(_pluginDir)) { if (jar.getBsn() == null) { outputFile = transformToOSGiBundle(jar); } } catch (Exception exception) { ReflectionUtil.throwException(exception); } if (PropsValues.MODULE_FRAMEWORK_WEB_GENERATOR_GENERATED_WABS_STORE) { writeGeneratedWab(outputFile); } return outputFile; } WabProcessor(
		ClassLoader classLoader, File file, Map<String, String[]> parameters); File getProcessedFile();  }
@Test public void testClassicThemeWab() throws Exception { File file = getFile("/classic-theme.autodeployed.war"); try (Jar jar = new Jar(file)) { Assert.assertNull(jar.getBsn()); Map<String, Resource> resources = jar.getResources(); Assert.assertEquals(resources.toString(), 1244, resources.size()); } WabProcessor wabProcessor = new TestWabProcessor( file, HashMapBuilder.put( "Bundle-Version", new String[] {"7.0.0.8"} ).put( "Web-ContextPath", new String[] {"/classic-theme"} ).build()); File processedFile = wabProcessor.getProcessedFile(); Assert.assertNotNull(processedFile); try (Jar jar = new Jar(processedFile)) { Map<String, Map<String, Resource>> directories = jar.getDirectories(); Map<String, Resource> resources = jar.getResources(); Assert.assertEquals(resources.toString(), 1240, resources.size()); Assert.assertEquals("classic-theme", jar.getBsn()); Assert.assertEquals("7.0.0.8", jar.getVersion()); Domain domain = Domain.domain(jar.getManifest()); Parameters bundleClassPath = domain.getBundleClassPath(); Assert.assertEquals(4, bundleClassPath.size()); Assert.assertTrue( bundleClassPath.containsKey("ext/WEB-INF/classes")); for (String bundleClassPathEntry : bundleClassPath.keySet()) { if (bundleClassPathEntry.equals("ext/WEB-INF/classes")) { Assert.assertNull(resources.get(bundleClassPathEntry)); } else if (bundleClassPathEntry.equals("WEB-INF/classes")) { Assert.assertNull(resources.get(bundleClassPathEntry)); Assert.assertTrue( directories.containsKey(bundleClassPathEntry)); } else { Assert.assertNotNull(resources.get(bundleClassPathEntry)); } } Parameters importedPackages = domain.getImportPackage(); Assert.assertTrue(importedPackages.containsKey("javax.servlet")); Assert.assertTrue( importedPackages.containsKey("javax.servlet.http")); Assert.assertTrue( importedPackages.containsKey("com.liferay.portal.model")); Assert.assertTrue( importedPackages.containsKey("com.liferay.portal.service")); Assert.assertTrue( importedPackages.containsKey( "com.liferay.portal.servlet.filters.aggregate")); Assert.assertTrue( importedPackages.containsKey( "com.liferay.portal.osgi.web.servlet.jsp.compiler")); Assert.assertTrue( importedPackages.containsKey( "com.liferay.portal.spring.context")); Assert.assertTrue( importedPackages.containsKey("com.liferay.portal.util")); Assert.assertTrue( importedPackages.containsKey("com.liferay.portlet")); Assert.assertTrue(importedPackages.containsKey("com.sun.el")); Assert.assertTrue( importedPackages.containsKey( "org.apache.commons.chain.generic")); Assert.assertTrue( importedPackages.containsKey("org.apache.naming.java")); Assert.assertTrue( importedPackages.containsKey( "com.liferay.portal.kernel.servlet.filters.invoker")); Assert.assertTrue( importedPackages.containsKey("com.liferay.portal.webserver")); } }
@Test public void testFatCDIWabOptsOutOfOSGiCDIIntegration() throws Exception { WabProcessor wabProcessor = new TestWabProcessor( getFile("/jsf.cdi.applicant.portlet.war"), Collections.singletonMap( "Web-ContextPath", new String[] {"/jsf-cdi-applicant-portlet"})); File processedFile = wabProcessor.getProcessedFile(); Assert.assertNotNull(processedFile); try (Jar jar = new Jar(processedFile)) { Assert.assertEquals("jsf-cdi-applicant-portlet", jar.getBsn()); Assert.assertEquals("4.1.2", jar.getVersion()); Resource beansXMLFile = jar.getResource("WEB-INF/beans.xml"); Assert.assertNotNull(beansXMLFile); try (InputStream inputStream = beansXMLFile.openInputStream()) { Document document = SAXReaderUtil.read(inputStream); Node beanDiscoveryMode = document.selectSingleNode( "/beans/@bean-discovery-mode"); String value = beanDiscoveryMode.getStringValue(); Assert.assertNotEquals("none", value); } Resource packageProperties = jar.getResource( "WEB-INF/liferay-plugin-package.properties"); Properties properties = new Properties(); try (InputStream inputStream = packageProperties.openInputStream()) { properties.load(inputStream); } Assert.assertEquals( "", properties.getProperty(Constants.CDIANNOTATIONS)); Domain domain = Domain.domain(jar.getManifest()); Parameters requirements = domain.getRequireCapability(); Map<String, Object> arguments = HashMapBuilder.<String, Object>put( "osgi.extender", "osgi.cdi" ).put( "version", new Version(1) ).build(); for (Attrs attrs : requirements.values()) { String filterString = attrs.get("filter:"); if (filterString == null) { continue; } Filter filter = new Filter(filterString); Assert.assertFalse(filter.matchMap(arguments)); } } }
@Test public void testSkinnyCDIWabGainsOSGiCDIIntegration() throws Exception { WabProcessor wabProcessor = new TestWabProcessor( getFile("/PortletV3AnnotatedDemo.war"), Collections.singletonMap( "Web-ContextPath", new String[] {"/portlet-V3-annotated-demo"})); File processedFile = wabProcessor.getProcessedFile(); Assert.assertNotNull(processedFile); try (Jar jar = new Jar(processedFile)) { Assert.assertEquals("portlet-V3-annotated-demo", jar.getBsn()); Assert.assertEquals("1.0.0", jar.getVersion()); Resource beansXMLFile = jar.getResource("WEB-INF/beans.xml"); Assert.assertNotNull(beansXMLFile); try (InputStream inputStream = beansXMLFile.openInputStream()) { Document document = SAXReaderUtil.read(inputStream); Node beanDiscoveryMode = document.selectSingleNode( "/beans/@bean-discovery-mode"); String value = beanDiscoveryMode.getStringValue(); Assert.assertNotEquals("none", value); } Resource packageProperties = jar.getResource( "WEB-INF/liferay-plugin-package.properties"); Properties properties = new Properties(); try (InputStream inputStream = packageProperties.openInputStream()) { properties.load(inputStream); } Assert.assertFalse( properties.containsKey(Constants.CDIANNOTATIONS)); Domain domain = Domain.domain(jar.getManifest()); Parameters requirements = domain.getRequireCapability(); Map.Entry<String, Attrs> entry = findRequirement( requirements, "osgi.extender", HashMapBuilder.<String, Object>put( "osgi.extender", "osgi.cdi" ).put( "version", new Version(1) ).build()); Assert.assertNotNull(entry); Attrs attrs = entry.getValue(); List<String> beans = attrs.getTyped(Attrs.LIST_STRING, "beans"); Assert.assertEquals(beans.toString(), 23, beans.size()); Assert.assertNotNull( findRequirement( requirements, "osgi.cdi.extension", Collections.singletonMap( "osgi.cdi.extension", "com.liferay.bean.portlet.cdi.extension"))); Assert.assertNotNull( findRequirement( requirements, "osgi.cdi.extension", Collections.singletonMap( "osgi.cdi.extension", "aries.cdi.http"))); Assert.assertNotNull( findRequirement( requirements, "osgi.cdi.extension", Collections.singletonMap( "osgi.cdi.extension", "aries.cdi.el.jsp"))); } }
@Test public void testThatEmbeddedLibsAreHandledProperly() throws Exception { WabProcessor wabProcessor = new TestWabProcessor( getFile("/tck-V3URLTests.wab.war"), Collections.singletonMap( "Web-ContextPath", new String[] {"/portlet-V3-annotated-demo"})); File processedFile = wabProcessor.getProcessedFile(); Assert.assertNotNull(processedFile); try (Jar jar = new Jar(processedFile)) { Assert.assertEquals("portlet-V3-annotated-demo", jar.getBsn()); Assert.assertEquals("1.0.0", jar.getVersion()); Resource beansXMLFile = jar.getResource("WEB-INF/beans.xml"); Assert.assertNotNull(beansXMLFile); try (InputStream inputStream = beansXMLFile.openInputStream()) { Document document = SAXReaderUtil.read(inputStream); Node beanDiscoveryMode = document.selectSingleNode( "/beans/@bean-discovery-mode"); String value = beanDiscoveryMode.getStringValue(); Assert.assertNotEquals("none", value); } Domain domain = Domain.domain(jar.getManifest()); Parameters requirements = domain.getRequireCapability(); Map.Entry<String, Attrs> entry = findRequirement( requirements, "osgi.extender", HashMapBuilder.<String, Object>put( "osgi.extender", "osgi.cdi" ).put( "version", new Version(1) ).build()); Assert.assertNotNull(entry); Attrs attrs = entry.getValue(); List<String> beans = attrs.getTyped(Attrs.LIST_STRING, "beans"); Assert.assertEquals(beans.toString(), 5, beans.size()); List<String> expectedList = Arrays.asList( "javax.portlet.tck.portlets.URLTests_ActionURL", "javax.portlet.tck.portlets.URLTests_BaseURL", "javax.portlet.tck.portlets.URLTests_RenderURL", "javax.portlet.tck.portlets.URLTests_ResourceURL", "javax.portlet.tck.util.ModuleTestCaseDetails"); Assert.assertEquals(expectedList.toString(), expectedList, beans); Assert.assertNotNull( findRequirement( requirements, "osgi.cdi.extension", Collections.singletonMap( "osgi.cdi.extension", "com.liferay.bean.portlet.cdi.extension"))); Assert.assertNotNull( findRequirement( requirements, "osgi.cdi.extension", Collections.singletonMap( "osgi.cdi.extension", "aries.cdi.http"))); Assert.assertNotNull( findRequirement( requirements, "osgi.cdi.extension", Collections.singletonMap( "osgi.cdi.extension", "aries.cdi.el.jsp"))); } }