Search in sources :

Example 6 with NewLiferayComponentOp

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

the class NewLiferayComponentWizard method performPostFinish.

@Override
public void performPostFinish() {
    final NewLiferayComponentOp op = element().nearest(NewLiferayComponentOp.class);
    IProject currentProject = CoreUtil.getProject(op.getProjectName().content());
    if (currentProject == null) {
        return;
    }
    IJavaProject javaProject = JavaCore.create(currentProject);
    if (javaProject == null) {
        return;
    }
    try {
        String componentClass = op.getComponentClassName().content();
        String packageName = op.getPackageName().text();
        final IType type = javaProject.findType(packageName, componentClass);
        if (type == null) {
            return;
        }
        final IFile classFile = (IFile) type.getResource();
        if (classFile != null) {
            Display.getCurrent().asyncExec(new Runnable() {

                public void run() {
                    try {
                        IWorkbenchWindow activeWorkbenchWindow = PlatformUI.getWorkbench().getActiveWorkbenchWindow();
                        IWorkbenchPage page = activeWorkbenchWindow.getActivePage();
                        IDE.openEditor(page, classFile, true);
                    } catch (Exception e) {
                        ProjectUI.logError(e);
                    }
                }
            });
        }
    } catch (Exception e) {
        ProjectUI.logError(e);
    }
}
Also used : IWorkbenchWindow(org.eclipse.ui.IWorkbenchWindow) IJavaProject(org.eclipse.jdt.core.IJavaProject) IFile(org.eclipse.core.resources.IFile) NewLiferayComponentOp(com.liferay.ide.project.core.modules.NewLiferayComponentOp) IWorkbenchPage(org.eclipse.ui.IWorkbenchPage) IProject(org.eclipse.core.resources.IProject) IType(org.eclipse.jdt.core.IType)

Example 7 with NewLiferayComponentOp

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

the class NewLiferayComponentOpTests method testNewLiferayComponentDefaultValueServiceIsListeningToProjectName.

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

Example 8 with NewLiferayComponentOp

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

the class NewLiferayComponentOpTests method testNewLiferayComponentBndAndGradleForPortleActionCommandAndRest.

@Test
public void testNewLiferayComponentBndAndGradleForPortleActionCommandAndRest() throws Exception {
    NewLiferayModuleProjectOp pop = NewLiferayModuleProjectOp.TYPE.instantiate();
    pop.setProjectName("testGradleModuleComponentBnd");
    pop.setProjectTemplateName("portlet");
    pop.setProjectProvider("gradle-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 buildgrade = modPorject.getFile("build.gradle");
    String buildgradeContent = FileUtil.readContents(buildgrade.getLocation().toFile(), true);
    assertTrue(buildgradeContent.contains("compile group: \"com.liferay.portal\", name:\"com.liferay.util.bridges\", version:\"2.0.0\""));
    assertTrue(buildgradeContent.contains("compile group: \"org.osgi\", name:\"org.osgi.service.component.annotations\", version:\"1.3.0\""));
    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));
    buildgrade = modPorject.getFile("build.gradle");
    buildgradeContent = FileUtil.readContents(buildgrade.getLocation().toFile(), true);
    assertTrue(buildgradeContent.contains("compile group: \"javax.ws.rs\", name:\"javax.ws.rs-api\", version:\"2.0.1\""));
    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));
    buildgrade = modPorject.getFile("build.gradle");
    buildgradeContent = FileUtil.readContents(buildgrade.getLocation().toFile(), true);
    assertTrue(buildgradeContent.contains("compile group: \"org.apache.shiro\", name:\"shiro-core\", version:\"1.1.0\""));
    NewLiferayComponentOp copStruts = NewLiferayComponentOp.TYPE.instantiate();
    copStruts.setProjectName(pop.getProjectName().content());
    copStruts.setComponentClassTemplateName("StrutsAction");
    NewLiferayComponentOpMethods.execute(copStruts, ProgressMonitorBridge.create(new NullProgressMonitor()));
    bgd = modPorject.getFile("bnd.bnd");
    bndcontent = FileUtil.readContents(bgd.getLocation().toFile(), true);
    bndConfig = "Web-ContextPath: /TestgradlemodulecomponentbndStrutsAction";
    assertTrue(bndcontent.contains(bndConfig));
}
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 9 with NewLiferayComponentOp

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

the class NewLiferayComponentOpTests method testNewLiferayComponentStrutsAction.

@Test
public void testNewLiferayComponentStrutsAction() throws Exception {
    NewLiferayModuleProjectOp op = NewLiferayModuleProjectOp.TYPE.instantiate();
    op.setProjectName("testGradleStrutsActionComponent");
    op.setProjectTemplateName("portlet");
    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("StrutsAction");
    Status status = NewLiferayComponentOpMethods.execute(cop, ProgressMonitorBridge.create(new NullProgressMonitor()));
    assertEquals(Status.createOkStatus(), status);
    IFile javaFile = modProject.getFile("/src/main/java/testGradleStrutsActionComponent" + "/portlet/TestgradlestrutsactioncomponentStrutsAction.java");
    assertTrue(javaFile.exists());
    String javaFileContent = FileUtil.readContents(javaFile.getLocation().toFile(), true);
    assertTrue(javaFileContent.contains("osgi.web.symbolicname=testGradleStrutsActionComponent"));
    IFile jspFile = modProject.getFile("/src/main/resources/META-INF/resources" + "/testgradlestrutsactioncomponentstrutsaction/html/portal/testgradlestrutsactioncomponent.jsp");
    assertTrue(jspFile.exists());
    String jspFileContent = FileUtil.readContents(jspFile.getLocation().toFile(), true);
    assertTrue(jspFileContent.contains("/testgradlestrutsactioncomponentstrutsaction/html/init.jsp"));
}
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 10 with NewLiferayComponentOp

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

the class NewLiferayComponentOpTests method testNewLiferayComponentDefaultValueServiceDots.

@Test
public void testNewLiferayComponentDefaultValueServiceDots() 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