Search in sources :

Example 1 with NewLiferayComponentOp

use of com.liferay.ide.project.core.modules.NewLiferayComponentOp in project liferay-ide by liferay.

the class MavenModuleProjectTests method testNewLiferayComponentBndAndMavenForPortleActionCommandAndRest.

@Test
public void testNewLiferayComponentBndAndMavenForPortleActionCommandAndRest() throws Exception {
    NewLiferayModuleProjectOp pop = NewLiferayModuleProjectOp.TYPE.instantiate();
    pop.setProjectName("testMavenModuleComponentBnd");
    pop.setProjectTemplateName("portlet");
    pop.setProjectProvider("maven-module");
    Status modulePorjectStatus = NewLiferayModuleProjectOpMethods.execute(pop, ProgressMonitorBridge.create(new NullProgressMonitor()));
    assertTrue(modulePorjectStatus.ok());
    IProject modPorject = CoreUtil.getProject(pop.getProjectName().content());
    modPorject.open(new NullProgressMonitor());
    NewLiferayComponentOp cop = NewLiferayComponentOp.TYPE.instantiate();
    cop.setProjectName(pop.getProjectName().content());
    cop.setComponentClassTemplateName("PortletActionCommand");
    NewLiferayComponentOpMethods.execute(cop, ProgressMonitorBridge.create(new NullProgressMonitor()));
    IFile bgd = modPorject.getFile("bnd.bnd");
    String bndcontent = FileUtil.readContents(bgd.getLocation().toFile(), true);
    String bndConfig = "-includeresource: \\" + System.getProperty("line.separator") + "\t" + "@com.liferay.util.bridges-2.0.0.jar!/com/liferay/util/bridges/freemarker/FreeMarkerPortlet.class,\\" + System.getProperty("line.separator") + "\t" + "@com.liferay.util.taglib-2.0.0.jar!/META-INF/*.tld" + System.getProperty("line.separator");
    assertTrue(bndcontent.contains(bndConfig));
    IFile pomFile = modPorject.getFile(IMavenConstants.POM_FILE_NAME);
    final IMaven maven = MavenPlugin.getMaven();
    Model model = maven.readModel(pomFile.getLocation().toFile());
    List<Dependency> dependencies = model.getDependencies();
    boolean hasDependency = false;
    for (Dependency de : dependencies) {
        String managementKey = de.getManagementKey();
        if (managementKey.equals("com.liferay.portal:com.liferay.util.bridges:jar")) {
            hasDependency = true;
            break;
        }
    }
    assertTrue(hasDependency);
    NewLiferayComponentOp copRest = NewLiferayComponentOp.TYPE.instantiate();
    copRest.setProjectName(pop.getProjectName().content());
    copRest.setComponentClassTemplateName("RestService");
    NewLiferayComponentOpMethods.execute(copRest, ProgressMonitorBridge.create(new NullProgressMonitor()));
    bgd = modPorject.getFile("bnd.bnd");
    bndcontent = FileUtil.readContents(bgd.getLocation().toFile(), true);
    assertTrue(bndcontent.contains(bndConfig));
    final String restConfig = "Require-Capability: osgi.contract; filter:=\"(&(osgi.contract=JavaJAXRS)(version=2))\"";
    assertTrue(bndcontent.contains(restConfig));
    model = maven.readModel(pomFile.getLocation().toFile());
    dependencies = model.getDependencies();
    hasDependency = false;
    for (Dependency de : dependencies) {
        String managementKey = de.getManagementKey();
        if (managementKey.equals("javax.ws.rs:javax.ws.rs-api:jar")) {
            hasDependency = true;
            break;
        }
    }
    assertTrue(hasDependency);
    NewLiferayComponentOp copAuth = NewLiferayComponentOp.TYPE.instantiate();
    copAuth.setProjectName(pop.getProjectName().content());
    copAuth.setComponentClassTemplateName("Authenticator");
    NewLiferayComponentOpMethods.execute(copAuth, ProgressMonitorBridge.create(new NullProgressMonitor()));
    bgd = modPorject.getFile("bnd.bnd");
    bndcontent = FileUtil.readContents(bgd.getLocation().toFile(), true);
    bndConfig = "-includeresource: \\" + System.getProperty("line.separator") + "\t" + "@com.liferay.util.bridges-2.0.0.jar!/com/liferay/util/bridges/freemarker/FreeMarkerPortlet.class,\\" + System.getProperty("line.separator") + "\t" + "@com.liferay.util.taglib-2.0.0.jar!/META-INF/*.tld,\\" + System.getProperty("line.separator") + "\t" + "@shiro-core-1.1.0.jar";
    assertTrue(bndcontent.contains(bndConfig));
    model = maven.readModel(pomFile.getLocation().toFile());
    dependencies = model.getDependencies();
    hasDependency = false;
    for (Dependency de : dependencies) {
        String managementKey = de.getManagementKey();
        if (managementKey.equals("org.apache.shiro:shiro-core:jar")) {
            hasDependency = true;
            break;
        }
    }
    assertTrue(hasDependency);
}
Also used : Status(org.eclipse.sapphire.modeling.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) NewLiferayModuleProjectOp(com.liferay.ide.project.core.modules.NewLiferayModuleProjectOp) NewLiferayComponentOp(com.liferay.ide.project.core.modules.NewLiferayComponentOp) Model(org.apache.maven.model.Model) Dependency(org.apache.maven.model.Dependency) IProject(org.eclipse.core.resources.IProject) IMaven(org.eclipse.m2e.core.embedder.IMaven) Test(org.junit.Test)

Example 2 with NewLiferayComponentOp

use of com.liferay.ide.project.core.modules.NewLiferayComponentOp in project liferay-ide by liferay.

the class AbstractLiferayComponentTemplate method initializeOperation.

protected void initializeOperation(NewLiferayComponentOp op) {
    projectName = op.getProjectName().content(true);
    packageName = op.getPackageName().content(true);
    componentClassName = op.getComponentClassName().content(true);
    IComponentTemplate<NewLiferayComponentOp> componentTemplate = op.getComponentClassTemplateName().content(true);
    templateName = componentTemplate.getShortName();
    serviceName = op.getServiceName().content(true);
    modelClass = op.getModelClass().content(true);
    componentNameWithoutTemplateName = componentClassName.replace(templateName, "");
    if (modelClass != null) {
        int modeClassPos = modelClass.lastIndexOf(".");
        simpleModelClass = modelClass.substring(modeClassPos + 1);
    }
    ElementList<PropertyKey> propertyKeys = op.getPropertyKeys();
    for (int i = 0; i < propertyKeys.size(); i++) {
        PropertyKey propertyKey = propertyKeys.get(i);
        StringBuilder sb = new StringBuilder();
        sb.append(propertyKey.getName().content(true));
        sb.append("=");
        sb.append(propertyKey.getValue().content(true));
        if (i != (propertyKeys.size() - 1)) {
            sb.append(",");
        } else {
            sb.append("");
        }
        properties.add(sb.toString());
    }
}
Also used : NewLiferayComponentOp(com.liferay.ide.project.core.modules.NewLiferayComponentOp) PropertyKey(com.liferay.ide.project.core.modules.PropertyKey)

Example 3 with NewLiferayComponentOp

use of com.liferay.ide.project.core.modules.NewLiferayComponentOp in project liferay-ide by liferay.

the class NewLiferayComponentOpTests method testNewLiferayComponentActionCommandPortlet.

@Test
public void testNewLiferayComponentActionCommandPortlet() throws Exception {
    NewLiferayModuleProjectOp op = NewLiferayModuleProjectOp.TYPE.instantiate();
    op.setProjectName("action-command-test");
    op.setProjectTemplateName("activator");
    op.setProjectProvider("gradle-module");
    Status modulePorjectStatus = NewLiferayModuleProjectOpMethods.execute(op, ProgressMonitorBridge.create(new NullProgressMonitor()));
    assertTrue(modulePorjectStatus.ok());
    IProject modProject = CoreUtil.getProject(op.getProjectName().content());
    modProject.open(new NullProgressMonitor());
    NewLiferayComponentOp cop = NewLiferayComponentOp.TYPE.instantiate();
    cop.setProjectName(op.getProjectName().content());
    cop.setComponentClassTemplateName("PortletActionCommand");
    Status status = NewLiferayComponentOpMethods.execute(cop, ProgressMonitorBridge.create(new NullProgressMonitor()));
    assertEquals(Status.createOkStatus(), status);
    IFile javaFile = modProject.getFile("/src/main/java/action/command/test/ActionCommandTestActionCommand.java");
    assertTrue(javaFile.exists());
    String javaFileContent = FileUtil.readContents(javaFile.getLocation().toFile(), true);
    assertTrue(javaFileContent.contains("javax.portlet.name=action_command_test_ActionCommandTestPortlet"));
    assertTrue(javaFileContent.contains("mvc.command.name=greet"));
    IFile initFile = modProject.getFile("/src/main/resources/META-INF/resources/actioncommandtestportletactioncommand/init.ftl");
    assertTrue(initFile.exists());
    IFile viewFile = modProject.getFile("/src/main/resources/META-INF/resources/actioncommandtestportletactioncommand/view.ftl");
    assertTrue(viewFile.exists());
}
Also used : Status(org.eclipse.sapphire.modeling.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) NewLiferayModuleProjectOp(com.liferay.ide.project.core.modules.NewLiferayModuleProjectOp) NewLiferayComponentOp(com.liferay.ide.project.core.modules.NewLiferayComponentOp) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 4 with NewLiferayComponentOp

use of com.liferay.ide.project.core.modules.NewLiferayComponentOp in project liferay-ide by liferay.

the class NewLiferayComponentOpTests method testNewLiferayComponentProjectValidation.

@Test
public void testNewLiferayComponentProjectValidation() throws Exception {
    deleteAllWorkspaceProjects();
    NewLiferayComponentOp cop = NewLiferayComponentOp.TYPE.instantiate();
    Status projectValidationStatus = cop.getProjectName().validation();
    assertEquals("No suitable Liferay module project.", projectValidationStatus.message());
    NewLiferayModuleProjectOp pop = NewLiferayModuleProjectOp.TYPE.instantiate();
    pop.setProjectName("testProjectValidation");
    pop.setProjectTemplateName("portlet");
    pop.setProjectProvider("gradle-module");
    Status moduleProjectStatus = NewLiferayModuleProjectOpMethods.execute(pop, ProgressMonitorBridge.create(new NullProgressMonitor()));
    assertTrue(moduleProjectStatus.ok());
    IProject modProject = CoreUtil.getProject(pop.getProjectName().content());
    modProject.open(new NullProgressMonitor());
    IFile bndFile = modProject.getFile("bnd.bnd");
    bndFile.delete(true, true, new NullProgressMonitor());
    cop.setProjectName(pop.getProjectName().content());
    projectValidationStatus = cop.getProjectName().validation();
    assertEquals("Can't find bnd.bnd file in the project.", projectValidationStatus.message());
}
Also used : Status(org.eclipse.sapphire.modeling.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFile(org.eclipse.core.resources.IFile) NewLiferayModuleProjectOp(com.liferay.ide.project.core.modules.NewLiferayModuleProjectOp) NewLiferayComponentOp(com.liferay.ide.project.core.modules.NewLiferayComponentOp) IProject(org.eclipse.core.resources.IProject) Test(org.junit.Test)

Example 5 with NewLiferayComponentOp

use of com.liferay.ide.project.core.modules.NewLiferayComponentOp in project liferay-ide by liferay.

the class NewLiferayComponentOpTests method testNewLiferayComponentDefaultValueServiceDashes.

@Test
public void testNewLiferayComponentDefaultValueServiceDashes() throws Exception {
    NewLiferayComponentOp op = NewLiferayComponentOp.TYPE.instantiate();
    op.setProjectName("my-test-project");
    op.setComponentClassTemplateName("PortletActionCommand");
    assertEquals("MyTestProjectPortletActionCommand", op.getComponentClassName().content(true));
}
Also used : NewLiferayComponentOp(com.liferay.ide.project.core.modules.NewLiferayComponentOp) Test(org.junit.Test)

Aggregations

NewLiferayComponentOp (com.liferay.ide.project.core.modules.NewLiferayComponentOp)12 Test (org.junit.Test)10 IFile (org.eclipse.core.resources.IFile)6 IProject (org.eclipse.core.resources.IProject)6 NewLiferayModuleProjectOp (com.liferay.ide.project.core.modules.NewLiferayModuleProjectOp)5 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)5 Status (org.eclipse.sapphire.modeling.Status)5 PropertyKey (com.liferay.ide.project.core.modules.PropertyKey)1 Dependency (org.apache.maven.model.Dependency)1 Model (org.apache.maven.model.Model)1 IJavaProject (org.eclipse.jdt.core.IJavaProject)1 IType (org.eclipse.jdt.core.IType)1 IMaven (org.eclipse.m2e.core.embedder.IMaven)1 IWorkbenchPage (org.eclipse.ui.IWorkbenchPage)1 IWorkbenchWindow (org.eclipse.ui.IWorkbenchWindow)1