Search in sources :

Example 11 with IRuntime

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

the class LiferayProjectImportOperation method execute.

@Override
public IStatus execute(IProgressMonitor monitor, IAdaptable info) throws ExecutionException {
    ProjectRecord projectRecord = (ProjectRecord) getDataModel().getProperty(PROJECT_RECORD);
    if (projectRecord == null) {
        return ProjectCore.createErrorStatus("Project record to import is null.");
    }
    File projectDir = projectRecord.getProjectLocation().toFile();
    SDK sdk = SDKUtil.getSDKFromProjectDir(projectDir);
    if ((sdk != null) && !(SDKManager.getInstance().containsSDK(sdk))) {
        SDKManager.getInstance().addSDK(sdk);
    }
    IRuntime runtime = (IRuntime) model.getProperty(IFacetProjectCreationDataModelProperties.FACET_RUNTIME);
    try {
        ProjectImportUtil.importProject(projectRecord, runtime, sdk.getLocation().toOSString(), monitor);
    } catch (CoreException ce) {
        return ProjectCore.createErrorStatus(ce);
    }
    return Status.OK_STATUS;
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) SDK(com.liferay.ide.sdk.core.SDK) File(java.io.File) IRuntime(org.eclipse.wst.common.project.facet.core.runtime.IRuntime)

Example 12 with IRuntime

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

the class SDKPluginFacetUtil method configureProjectAsSDKProject.

public static void configureProjectAsSDKProject(IFacetedProjectWorkingCopy fpjwc, String pluginType, String sdkLocation, ProjectRecord projectRecord) throws CoreException {
    IFacetedProjectTemplate template = getLiferayTemplateForProject(pluginType);
    IPreset preset = getLiferayPresetForProject(pluginType);
    if (preset == null) {
        throw new CoreException(ProjectCore.createErrorStatus(NLS.bind(Msgs.noFacetPreset, fpjwc.getProjectName())));
    }
    IRuntime primaryRuntime = fpjwc.getPrimaryRuntime();
    if (primaryRuntime != null) {
        fpjwc.removeTargetedRuntime(primaryRuntime);
    }
    Set<IProjectFacetVersion> currentProjectFacetVersions = fpjwc.getProjectFacets();
    Set<IProjectFacet> requiredFacets = template.getFixedProjectFacets();
    for (IProjectFacet requiredFacet : requiredFacets) {
        boolean hasRequiredFacet = false;
        for (IProjectFacetVersion currentFacetVersion : currentProjectFacetVersions) {
            if (currentFacetVersion.getProjectFacet().equals(requiredFacet)) {
                // TODO how to check the bundle support status?
                boolean requiredVersion = _isRequiredVersion(currentFacetVersion);
                if (requiredVersion) {
                    hasRequiredFacet = true;
                } else {
                    fpjwc.removeProjectFacet(currentFacetVersion);
                }
                break;
            }
        }
        if (!hasRequiredFacet) {
            IProjectFacetVersion requiredFacetVersion = _getRequiredFacetVersionFromPreset(requiredFacet, preset);
            if (requiredFacetVersion != null) {
                fpjwc.addProjectFacet(requiredFacetVersion);
                if (ProjectUtil.isJavaFacet(requiredFacetVersion)) {
                    configureJavaFacet(fpjwc, requiredFacetVersion.getProjectFacet(), preset, projectRecord);
                } else if (ProjectUtil.isDynamicWebFacet(requiredFacetVersion)) {
                    configureWebFacet(fpjwc, requiredFacetVersion.getProjectFacet(), preset);
                }
            }
        } else {
            if (ProjectUtil.isJavaFacet(requiredFacet)) {
                configureJavaFacet(fpjwc, requiredFacet, preset, projectRecord);
            } else if (ProjectUtil.isDynamicWebFacet(requiredFacet)) {
                configureWebFacet(fpjwc, requiredFacet, preset);
            }
        }
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) IFacetedProjectTemplate(org.eclipse.wst.common.project.facet.core.IFacetedProjectTemplate) IPreset(org.eclipse.wst.common.project.facet.core.IPreset) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) IRuntime(org.eclipse.wst.common.project.facet.core.runtime.IRuntime)

Example 13 with IRuntime

use of org.eclipse.wst.common.project.facet.core.runtime.IRuntime 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)

Aggregations

IRuntime (org.eclipse.wst.common.project.facet.core.runtime.IRuntime)13 CoreException (org.eclipse.core.runtime.CoreException)4 IProjectFacetVersion (org.eclipse.wst.common.project.facet.core.IProjectFacetVersion)3 SDK (com.liferay.ide.sdk.core.SDK)2 ArrayList (java.util.ArrayList)2 Iterator (java.util.Iterator)2 List (java.util.List)2 IProject (org.eclipse.core.resources.IProject)2 WorkspaceJob (org.eclipse.core.resources.WorkspaceJob)2 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)2 Path (org.eclipse.core.runtime.Path)2 IFacetedProject (org.eclipse.wst.common.project.facet.core.IFacetedProject)2 IPreset (org.eclipse.wst.common.project.facet.core.IPreset)2 IRuntimeComponent (org.eclipse.wst.common.project.facet.core.runtime.IRuntimeComponent)2 SDKManager (com.liferay.ide.sdk.core.SDKManager)1 File (java.io.File)1 IOException (java.io.IOException)1 ExecutionException (org.eclipse.core.commands.ExecutionException)1 IWorkspace (org.eclipse.core.resources.IWorkspace)1 IPath (org.eclipse.core.runtime.IPath)1