Search in sources :

Example 26 with IFacetedProject

use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project liferay-ide by liferay.

the class UpgradeRuntimeHandler method execute.

@Override
public Status execute(IProject project, String runtimeName, IProgressMonitor monitor, int perUnit) {
    Status retval = Status.createOkStatus();
    try {
        int worked = 0;
        IProgressMonitor submon = CoreUtil.newSubMonitor(monitor, 25);
        submon.subTask("Update project runtime");
        org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime = RuntimeManager.getRuntime(runtimeName);
        if (runtime != null) {
            worked = worked + perUnit;
            submon.worked(worked);
            if (runtime != null) {
                IFacetedProject fProject = ProjectUtil.getFacetedProject(project);
                org.eclipse.wst.common.project.facet.core.runtime.IRuntime primaryRuntime = fProject.getPrimaryRuntime();
                if (!runtime.equals(primaryRuntime)) {
                    worked = worked + perUnit;
                    submon.worked(worked);
                    fProject.setTargetedRuntimes(Collections.singleton(runtime), monitor);
                    worked = worked + perUnit;
                    submon.worked(worked);
                    fProject.setPrimaryRuntime(runtime, monitor);
                    worked = worked + perUnit;
                    submon.worked(worked);
                }
            }
        }
    } catch (Exception e) {
        IStatus error = ProjectCore.createErrorStatus("Unable to upgrade target runtime for " + project.getName(), e);
        ProjectCore.logError(error);
        retval = StatusBridge.create(error);
    }
    return retval;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.sapphire.modeling.Status) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IStatus(org.eclipse.core.runtime.IStatus)

Example 27 with IFacetedProject

use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project liferay-ide by liferay.

the class PrimaryRuntimeNotLiferayRuntimeResolution method run.

public void run(IMarker marker) {
    IFacetedProject fproj = ProjectUtil.getFacetedProject((IProject) marker.getResource());
    try {
        fproj.setPrimaryRuntime(null, null);
        fproj.setTargetedRuntimes(null, null);
    } catch (CoreException ce) {
        ProjectUI.logError(ce);
    }
    super.run(marker);
}
Also used : IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) CoreException(org.eclipse.core.runtime.CoreException)

Example 28 with IFacetedProject

use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project liferay-ide by liferay.

the class PrimaryRuntimeNotSetResolution method run.

/**
 * IDE-1179, Quick fix for the project of which primary runtime is not set.
 */
public void run(IMarker marker) {
    if (marker.getResource() instanceof IProject) {
        final IProject proj = (IProject) marker.getResource();
        final IFacetedProject fproj = ProjectUtil.getFacetedProject(proj);
        /*
			 * Let users set a Liferay server runtime when there is no available one.
			 */
        if (ServerUtil.getAvailableLiferayRuntimes().size() == 0) {
            boolean openNewRuntimeWizard = MessageDialog.openQuestion(null, null, Msgs.noLiferayRuntimeAvailable);
            if (openNewRuntimeWizard) {
                ServerUIUtil.showNewRuntimeWizard(null, null, null, "com.liferay.");
            }
        }
        /*
			 * Let users confirm when there is only one available Liferay runtime.
			 *
			 * If the previous judgment block is executed, the size of available targeted
			 * runtimes will increase to 1.
			 */
        if (ServerUtil.getAvailableLiferayRuntimes().size() == 1) {
            final Set<IRuntime> availableFacetRuntimes = _convertToFacetRuntimes(ServerUtil.getAvailableLiferayRuntimes());
            String runtimeName = ((IRuntime) availableFacetRuntimes.toArray()[0]).getName();
            boolean setAsPrimary = MessageDialog.openQuestion(null, null, NLS.bind(Msgs.setOnlyRuntimeAsPrimary, runtimeName));
            if (setAsPrimary) {
                try {
                    fproj.setTargetedRuntimes(availableFacetRuntimes, null);
                    fproj.setPrimaryRuntime((IRuntime) availableFacetRuntimes.toArray()[0], null);
                } catch (CoreException ce) {
                    ProjectUI.logError(ce);
                }
            }
        }
        /*
			 * Open the "Targeted Runtimes" property page and let users set a runtime as the
			 * primary one when there are multiple Liferay runtimes available.
			 */
        if (ServerUtil.getAvailableLiferayRuntimes().size() > 1) {
            boolean openRuntimesProperty = MessageDialog.openQuestion(null, null, Msgs.multipleAvailableRuntimes);
            if (openRuntimesProperty) {
                PropertyDialog.createDialogOn(null, TARGETED_RUNTIMES_PROPERTY_PAGE_ID, proj).open();
            }
        }
    }
}
Also used : IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) IRuntime(org.eclipse.wst.common.project.facet.core.runtime.IRuntime)

Example 29 with IFacetedProject

use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project liferay-ide by liferay.

the class ProjectCoreBase method createProject.

public IProject createProject(NewLiferayPluginProjectOp op, String projectName) {
    Status status = op.execute(ProgressMonitorBridge.create(new NullProgressMonitor()));
    assertNotNull(status);
    assertEquals(status.toString(), Status.createOkStatus().message().toLowerCase(), status.message().toLowerCase());
    if (projectName == null || op.getProjectProvider().content().getShortName().equalsIgnoreCase("ant")) {
        projectName = op.getFinalProjectName().content();
    }
    // if( op.getProjectProvider().content().getShortName().equalsIgnoreCase( "maven" ) )
    // {
    // if( op.getPluginType().content().equals( PluginType.ext ) )
    // {
    // projectName = projectName + "-ext";
    // }
    // else if( op.getPluginType().content().equals( PluginType.servicebuilder ) )
    // {
    // projectName = projectName + "-portlet";
    // }
    // }
    final IProject newLiferayPluginProject = project(projectName);
    assertNotNull(newLiferayPluginProject);
    assertEquals(true, newLiferayPluginProject.exists());
    final IFacetedProject facetedProject = ProjectUtil.getFacetedProject(newLiferayPluginProject);
    assertNotNull(facetedProject);
    final IProjectFacet liferayFacet = ProjectUtil.getLiferayFacet(facetedProject);
    assertNotNull(liferayFacet);
    final PluginType pluginTypeValue = op.getPluginType().content(true);
    if (pluginTypeValue.equals(PluginType.servicebuilder)) {
        assertEquals("liferay.portlet", liferayFacet.getId());
    } else {
        assertEquals("liferay." + pluginTypeValue, liferayFacet.getId());
    }
    return newLiferayPluginProject;
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.sapphire.modeling.Status) NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) PluginType(com.liferay.ide.project.core.model.PluginType) IProject(org.eclipse.core.resources.IProject)

Example 30 with IFacetedProject

use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project liferay-ide by liferay.

the class LiferayPublishHelper method prePublishModule.

public static boolean prePublishModule(ServerBehaviourDelegate delegate, int kind, int deltaKind, IModule[] moduleTree, IModuleResourceDelta[] resourceDelta, IProgressMonitor monitor) {
    boolean retval = true;
    if (ListUtil.isNotEmpty(moduleTree) && moduleTree[0].getProject() != null) {
        IProject project = moduleTree[0].getProject();
        IFacetedProject facetedProject = ServerUtil.getFacetedProject(project);
        if (facetedProject != null) {
            IProjectFacet liferayFacet = ServerUtil.getLiferayFacet(facetedProject);
            if (liferayFacet != null) {
                String facetId = liferayFacet.getId();
                IRuntime runtime = null;
                try {
                    runtime = delegate.getServer().getRuntime();
                    if (runtime != null) {
                        IPluginPublisher pluginPublisher = LiferayServerCore.getPluginPublisher(facetId, runtime.getRuntimeType().getId());
                        if (pluginPublisher != null) {
                            retval = pluginPublisher.prePublishModule(delegate, kind, deltaKind, moduleTree, resourceDelta, monitor);
                        }
                    }
                } catch (Exception e) {
                    // $NON-NLS-1$
                    LiferayServerCore.logError("Plugin publisher failed", e);
                }
            }
        }
    }
    return retval;
}
Also used : IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) IPluginPublisher(com.liferay.ide.server.core.IPluginPublisher) IProject(org.eclipse.core.resources.IProject) IRuntime(org.eclipse.wst.server.core.IRuntime)

Aggregations

IFacetedProject (org.eclipse.wst.common.project.facet.core.IFacetedProject)32 CoreException (org.eclipse.core.runtime.CoreException)20 IProjectFacet (org.eclipse.wst.common.project.facet.core.IProjectFacet)17 IProject (org.eclipse.core.resources.IProject)16 NullProgressMonitor (org.eclipse.core.runtime.NullProgressMonitor)9 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)6 IStatus (org.eclipse.core.runtime.IStatus)6 IProjectFacetVersion (org.eclipse.wst.common.project.facet.core.IProjectFacetVersion)5 IRuntime (org.eclipse.wst.server.core.IRuntime)5 IWorkspace (org.eclipse.core.resources.IWorkspace)4 IPath (org.eclipse.core.runtime.IPath)4 IFile (org.eclipse.core.resources.IFile)3 Path (org.eclipse.core.runtime.Path)3 IFacetedProjectWorkingCopy (org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy)3 FacetedProjectWorkingCopy (org.eclipse.wst.common.project.facet.core.internal.FacetedProjectWorkingCopy)3 PluginClasspathContainerInitializer (com.liferay.ide.project.core.PluginClasspathContainerInitializer)2 IPluginPublisher (com.liferay.ide.server.core.IPluginPublisher)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 Status (org.eclipse.core.runtime.Status)2