Search in sources :

Example 31 with Status

use of org.eclipse.sapphire.modeling.Status in project liferay-ide by liferay.

the class ImportLiferayWorkspaceOpMethods method execute.

public static Status execute(ImportLiferayWorkspaceOp op, ProgressMonitor pm) {
    IProgressMonitor monitor = ProgressMonitorBridge.create(pm);
    monitor.beginTask("Importing Liferay Workspace project...", 100);
    Status retval = null;
    try {
        op.setProjectProvider(op.getBuildType().content());
        NewLiferayWorkspaceProjectProvider<NewLiferayWorkspaceOp> provider = op.getProjectProvider().content(true);
        org.eclipse.sapphire.modeling.Path workspaceLocation = op.getWorkspaceLocation().content();
        String location = workspaceLocation.toOSString();
        LiferayWorkspaceUtil.clearWorkspace(location);
        boolean initBundle = op.getProvisionLiferayBundle().content();
        boolean hasBundlesDir = op.getHasBundlesDir().content();
        String bundleUrl = op.getBundleUrl().content(false);
        IStatus importStatus;
        if (initBundle && !hasBundlesDir) {
            importStatus = provider.importProject(location, monitor, true, bundleUrl);
        } else {
            importStatus = provider.importProject(location, monitor, false, null);
        }
        retval = StatusBridge.create(importStatus);
        if (!retval.ok() || (retval.exception() != null)) {
            return retval;
        }
        if (initBundle || hasBundlesDir) {
            String serverRuntimeName = op.getServerName().content();
            IPath bundlesLocation = null;
            String buildType = op.getBuildType().content();
            if (buildType.equals("gradle-liferay-workspace")) {
                bundlesLocation = LiferayWorkspaceUtil.getHomeLocation(location);
            } else {
                bundlesLocation = new Path(location).append("bundles");
            }
            if ((bundlesLocation != null) && bundlesLocation.toFile().exists()) {
                ServerUtil.addPortalRuntimeAndServer(serverRuntimeName, bundlesLocation, monitor);
            }
        }
    } catch (Exception e) {
        String msg = "import Liferay Workspace project error";
        ProjectCore.logError(msg, e);
        retval = Status.createErrorStatus(msg, e);
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.sapphire.modeling.Status) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)

Example 32 with Status

use of org.eclipse.sapphire.modeling.Status in project liferay-ide by liferay.

the class ImportWorkspaceLocationValidationService method compute.

@Override
protected Status compute() {
    Status retval = Status.createOkStatus();
    try {
        if (LiferayWorkspaceUtil.hasWorkspace()) {
            return Status.createErrorStatus(LiferayWorkspaceUtil.hasLiferayWorkspaceMsg);
        }
    } catch (CoreException ce) {
        return Status.createErrorStatus(LiferayWorkspaceUtil.multiWorkspaceErrorMsg);
    }
    Value<Path> workspaceLocation = _op().getWorkspaceLocation();
    Path currentProjectLocation = workspaceLocation.content(true);
    if ((currentProjectLocation != null) && !currentProjectLocation.isEmpty()) {
        String currentPath = currentProjectLocation.toOSString();
        IStatus validPathStatus = ProjectImportUtil.validatePath(currentPath);
        if (!validPathStatus.isOK()) {
            return Status.createErrorStatus(validPathStatus.getMessage());
        }
        if (LiferayWorkspaceUtil.getWorkspaceType(currentPath) == null) {
            return Status.createErrorStatus("Invalid Liferay Workspace");
        }
        String projectName = currentProjectLocation.lastSegment();
        if (CoreUtil.getProject(projectName).exists()) {
            return Status.createErrorStatus("A project with that name already exists.");
        }
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.sapphire.modeling.Status) Path(org.eclipse.sapphire.modeling.Path) IStatus(org.eclipse.core.runtime.IStatus) CoreException(org.eclipse.core.runtime.CoreException)

Example 33 with Status

use of org.eclipse.sapphire.modeling.Status in project liferay-ide by liferay.

the class NewLiferayWorkspaceOpMethods method execute.

public static Status execute(NewLiferayWorkspaceOp op, ProgressMonitor pm) {
    IProgressMonitor monitor = ProgressMonitorBridge.create(pm);
    monitor.beginTask("Creating Liferay Workspace project...", 100);
    Status retval = null;
    try {
        String wsName = op.getWorkspaceName().content();
        NewLiferayProjectProvider<NewLiferayWorkspaceOp> provider = op.getProjectProvider().content(true);
        IStatus status = provider.createNewProject(op, monitor);
        retval = StatusBridge.create(status);
        if (!retval.ok()) {
            return retval;
        }
        org.eclipse.sapphire.modeling.Path parent = op.getLocation().content();
        String location = parent.append(wsName).toPortableString();
        boolean initBundle = op.getProvisionLiferayBundle().content();
        if (initBundle) {
            String serverRuntimeName = op.getServerName().content();
            IPath bundlesLocation = null;
            String projectProvider = op.getProjectProvider().text();
            if (projectProvider.equals("gradle-liferay-workspace")) {
                bundlesLocation = LiferayWorkspaceUtil.getHomeLocation(location);
            } else {
                bundlesLocation = new Path(location).append("bundles");
            }
            if (bundlesLocation.toFile().exists()) {
                ServerUtil.addPortalRuntimeAndServer(serverRuntimeName, bundlesLocation, monitor);
            }
        }
    } catch (Exception e) {
        String msg = "Error creating Liferay Workspace project.";
        ProjectCore.logError(msg, e);
        return Status.createErrorStatus(msg, e);
    }
    if (retval.ok()) {
        _updateBuildPrefs(op);
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.sapphire.modeling.Status) IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IStatus(org.eclipse.core.runtime.IStatus) IPath(org.eclipse.core.runtime.IPath) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor)

Example 34 with Status

use of org.eclipse.sapphire.modeling.Status 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 35 with Status

use of org.eclipse.sapphire.modeling.Status 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)

Aggregations

Status (org.eclipse.sapphire.modeling.Status)83 IProject (org.eclipse.core.resources.IProject)33 Test (org.junit.Test)31 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)29 IStatus (org.eclipse.core.runtime.IStatus)25 Path (org.eclipse.sapphire.modeling.Path)18 CoreException (org.eclipse.core.runtime.CoreException)15 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)15 NewLiferayJSFModuleProjectOp (com.liferay.ide.project.core.jsf.NewLiferayJSFModuleProjectOp)14 IFile (org.eclipse.core.resources.IFile)12 IPath (org.eclipse.core.runtime.IPath)11 NewLiferayPluginProjectOp (com.liferay.ide.project.core.model.NewLiferayPluginProjectOp)10 NewLiferayModuleProjectOp (com.liferay.ide.project.core.modules.NewLiferayModuleProjectOp)9 SDK (com.liferay.ide.sdk.core.SDK)9 File (java.io.File)6 NewLiferayComponentOp (com.liferay.ide.project.core.modules.NewLiferayComponentOp)5 IRuntime (org.eclipse.wst.server.core.IRuntime)5 PropertyKey (com.liferay.ide.project.core.modules.PropertyKey)3 NewModuleFragmentOp (com.liferay.ide.project.core.modules.fragment.NewModuleFragmentOp)3 ArrayList (java.util.ArrayList)3