CreateCommandMaven extends CreateCommand { @Override public void execute() throws Exception { BladeCLI bladeCLI = getBladeCLI(); CreateArgs createArgs = getArgs(); File dir = createArgs.getDir(); if (dir == null) { dir = createArgs.getBase(); } WorkspaceProvider workspaceProvider = bladeCLI.getWorkspaceProvider(dir); if ((workspaceProvider == null) || (workspaceProvider instanceof MavenWorkspaceProvider)) { createArgs.setProduct("portal"); createArgs.setProfileName("maven"); super.execute(); } else { bladeCLI.error("Cannot create maven project here, incompatible workspace profile type."); } } CreateCommandMaven();  CreateCommandMaven(BladeCLI bladeCLI); @Override void execute();  }
@Test public void testCreateApi() throws Exception { File workspaceDir = _workspaceDir; MavenTestUtil.makeMavenWorkspace(_extensionsDir, workspaceDir, BladeTest.PRODUCT_VERSION_PORTAL_73); File modulesDir = new File(workspaceDir, "modules"); String[] mavenArgs = { "create", "--base", workspaceDir.getAbsolutePath(), "-d", modulesDir.getAbsolutePath(), "-P", "maven", "-t", "api", "foo" }; File projectDir = new File(modulesDir, "foo"); String projectPath = projectDir.getAbsolutePath(); TestUtil.runBlade(workspaceDir, _extensionsDir, mavenArgs); _checkMavenBuildFiles(projectPath); _contains(_checkFileExists(projectPath + "/src/main/java/foo/api/Foo.java"), ".*^public interface Foo.*"); _contains(_checkFileExists(projectPath + "/src/main/resources/foo/api/packageinfo"), "version 1.0.0"); TestUtil.updateMavenRepositories(projectPath); execute(projectPath, new String[] {"clean", "package"}); MavenTestUtil.verifyBuildOutput(projectPath, "foo-1.0.0.jar"); _verifyImportPackage(new File(projectPath, "target/foo-1.0.0.jar")); try (Jar jar = new Jar(new File(projectPath, "target/foo-1.0.0.jar"))) { Manifest manifest = jar.getManifest(); Attributes mainAttributes = manifest.getMainAttributes(); Assert.assertEquals("foo.api;version=\"1.0.0\"", mainAttributes.getValue("Export-Package")); } }
@Test public void testCreateFragment() throws Exception { File workspaceDir = _workspaceDir; MavenTestUtil.makeMavenWorkspace(_extensionsDir, workspaceDir, BladeTest.PRODUCT_VERSION_PORTAL_73); File modulesDir = new File(workspaceDir, "modules"); String[] mavenArgs = { "create", "--base", workspaceDir.getAbsolutePath(), "-d", modulesDir.getAbsolutePath(), "-P", "maven", "-t", "fragment", "-h", "com.liferay.login.web", "-H", "1.0.0", "loginHook" }; File projectDir = new File(modulesDir, "loginHook"); String projectPath = projectDir.getAbsolutePath(); TestUtil.runBlade(workspaceDir, _extensionsDir, mavenArgs); _checkMavenBuildFiles(projectPath); _contains( _checkFileExists(projectPath + "/bnd.bnd"), new String[] { ".*^Bundle-SymbolicName: loginhook.*$", ".*^Fragment-Host: com.liferay.login.web;bundle-version=\"1.0.0\".*$" }); TestUtil.updateMavenRepositories(projectPath); execute(projectPath, new String[] {"clean", "package"}); MavenTestUtil.verifyBuildOutput(projectPath, "loginHook-1.0.0.jar"); _verifyImportPackage(new File(projectPath, "target/loginHook-1.0.0.jar")); }
@Test public void testCreateMVCPortlet() throws Exception { File workspaceDir = _workspaceDir; MavenTestUtil.makeMavenWorkspace(_extensionsDir, workspaceDir, BladeTest.PRODUCT_VERSION_PORTAL_73); File modulesDir = new File(workspaceDir, "modules"); String[] mavenArgs = { "create", "--base", workspaceDir.getAbsolutePath(), "-d", modulesDir.getAbsolutePath(), "-P", "maven", "-t", "mvc-portlet", "foo" }; File projectDir = new File(modulesDir, "foo"); String projectPath = projectDir.getAbsolutePath(); TestUtil.runBlade(workspaceDir, _extensionsDir, mavenArgs); _checkMavenBuildFiles(projectPath); _contains( _checkFileExists(projectPath + "/src/main/java/foo/portlet/FooPortlet.java"), ".*^public class FooPortlet extends MVCPortlet.*$"); _checkFileExists(projectPath + "/src/main/resources/META-INF/resources/view.jsp"); _checkFileExists(projectPath + "/src/main/resources/META-INF/resources/init.jsp"); TestUtil.updateMavenRepositories(projectPath); execute(projectPath, new String[] {"clean", "package"}); MavenTestUtil.verifyBuildOutput(projectPath, "foo-1.0.0.jar"); _verifyImportPackage(new File(projectPath, "target/foo-1.0.0.jar")); }
@Test public void testCreateMVCPortletDXP72() throws Exception { MavenTestUtil.makeMavenWorkspace(_extensionsDir, _workspaceDir, "dxp-7.2-sp2"); File modulesDir = new File(_workspaceDir, "modules"); String[] mavenArgs = { "create", "--base", _workspaceDir.getAbsolutePath(), "-d", modulesDir.getAbsolutePath(), "-P", "maven", "-t", "mvc-portlet", "foo", "--product", "dxp" }; File projectDir = new File(modulesDir, "foo"); String projectPath = projectDir.getAbsolutePath(); TestUtil.runBlade(_workspaceDir, _extensionsDir, mavenArgs); _checkMavenBuildFiles(projectPath); _contains(_checkFileExists(projectPath + "/pom.xml"), ".*<artifactId>release.portal.bom</artifactId>.*"); TestUtil.updateMavenRepositories(projectPath); execute(projectPath, new String[] {"clean", "package"}); MavenTestUtil.verifyBuildOutput(projectPath, "foo-1.0.0.jar"); _verifyImportPackage(new File(projectPath, "target/foo-1.0.0.jar")); }
@Test public void testCreateMVCPortletDXP73() throws Exception { MavenTestUtil.makeMavenWorkspace(_extensionsDir, _workspaceDir, "dxp-7.3-ep5"); File modulesDir = new File(_workspaceDir, "modules"); String[] mavenArgs = { "create", "--base", _workspaceDir.getAbsolutePath(), "-d", modulesDir.getAbsolutePath(), "-P", "maven", "-t", "mvc-portlet", "foo", "--product", "dxp" }; File projectDir = new File(modulesDir, "foo"); String projectPath = projectDir.getAbsolutePath(); TestUtil.runBlade(_workspaceDir, _extensionsDir, mavenArgs); _checkMavenBuildFiles(projectPath); _contains(_checkFileExists(projectPath + "/pom.xml"), ".*<artifactId>release.portal.api</artifactId>.*"); TestUtil.updateMavenRepositories(projectPath); execute(projectPath, new String[] {"clean", "package"}); MavenTestUtil.verifyBuildOutput(projectPath, "foo-1.0.0.jar"); _verifyImportPackage(new File(projectPath, "target/foo-1.0.0.jar")); }
@Test public void testCreateMVCPortletLegacyFlag() throws Exception { File workspaceDir = _workspaceDir; MavenTestUtil.makeMavenWorkspace(_extensionsDir, workspaceDir, BladeTest.PRODUCT_VERSION_PORTAL_73); File modulesDir = new File(workspaceDir, "modules"); String[] mavenArgs = { "create", "--base", workspaceDir.getAbsolutePath(), "-d", modulesDir.getAbsolutePath(), "-b", "maven", "-t", "mvc-portlet", "foo" }; File projectDir = new File(modulesDir, "foo"); String projectPath = projectDir.getAbsolutePath(); TestUtil.runBlade(workspaceDir, _extensionsDir, mavenArgs); _checkMavenBuildFiles(projectPath); _contains( _checkFileExists(projectPath + "/src/main/java/foo/portlet/FooPortlet.java"), ".*^public class FooPortlet extends MVCPortlet.*$"); _checkFileExists(projectPath + "/src/main/resources/META-INF/resources/view.jsp"); _checkFileExists(projectPath + "/src/main/resources/META-INF/resources/init.jsp"); TestUtil.updateMavenRepositories(projectPath); execute(projectPath, new String[] {"clean", "package"}); MavenTestUtil.verifyBuildOutput(projectPath, "foo-1.0.0.jar"); _verifyImportPackage(new File(projectPath, "target/foo-1.0.0.jar")); }