Search in sources :

Example 1 with PluginFacetProjectCreationDataModelProvider

use of com.liferay.ide.project.core.facet.PluginFacetProjectCreationDataModelProvider in project liferay-ide by liferay.

the class ProjectUtil method createNewSDKProject.

public static IProject createNewSDKProject(ProjectRecord projectRecord, IPath sdkLocation, IProgressMonitor monitor, NewLiferayPluginProjectOp op) throws CoreException {
    IDataModel newProjectDataModel = DataModelFactory.createDataModel(new PluginFacetProjectCreationDataModelProvider());
    // we are importing so set flag to not create anything
    newProjectDataModel.setBooleanProperty(IPluginProjectDataModelProperties.CREATE_PROJECT_OPERATION, false);
    IDataModel nestedModel = newProjectDataModel.getNestedModel(IPluginProjectDataModelProperties.NESTED_PROJECT_DM);
    // using sdk location
    nestedModel.setBooleanProperty(IPluginProjectDataModelProperties.USE_DEFAULT_LOCATION, true);
    newProjectDataModel.setBooleanProperty(IPluginProjectDataModelProperties.LIFERAY_USE_SDK_LOCATION, false);
    newProjectDataModel.setBooleanProperty(IPluginProjectDataModelProperties.LIFERAY_USE_WORKSPACE_LOCATION, true);
    setGenerateDD(newProjectDataModel, false);
    IPath webXmlPath = projectRecord.getProjectLocation().append(ISDKConstants.DEFAULT_DOCROOT_FOLDER + "/WEB-INF/web.xml");
    File webXmlFile = webXmlPath.toFile();
    if (projectRecord.getProjectName().endsWith(ISDKConstants.PORTLET_PLUGIN_PROJECT_SUFFIX)) {
        newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_PORTLET, true);
        if (FileUtil.notExists(webXmlFile)) {
            createDefaultWebXml(webXmlFile, projectRecord.getProjectName());
        }
    } else if (projectRecord.getProjectName().endsWith(ISDKConstants.HOOK_PLUGIN_PROJECT_SUFFIX)) {
        newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_HOOK, true);
        if (FileUtil.notExists(webXmlFile)) {
            createDefaultWebXml(webXmlFile, projectRecord.getProjectName());
        }
    } else if (projectRecord.getProjectName().endsWith(ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX)) {
        Path path = new Path(ISDKConstants.DEFAULT_DOCROOT_FOLDER + "/WEB-INF/ext-web/docroot/WEB-INF/web.xml");
        webXmlPath = webXmlPath.removeLastSegments(3).append(path);
        webXmlFile = webXmlPath.toFile();
        newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_EXT, true);
        if (FileUtil.notExists(webXmlFile)) {
            createDefaultWebXml(webXmlPath.toFile(), projectRecord.getProjectName());
        }
    } else if (projectRecord.getProjectName().endsWith(ISDKConstants.LAYOUTTPL_PLUGIN_PROJECT_SUFFIX)) {
        newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_LAYOUTTPL, true);
    } else if (projectRecord.getProjectName().endsWith(ISDKConstants.THEME_PLUGIN_PROJECT_SUFFIX)) {
        newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_THEME, true);
    } else if (projectRecord.getProjectName().endsWith(ISDKConstants.WEB_PLUGIN_PROJECT_SUFFIX)) {
        newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_WEB, true);
    }
    IFacetedProjectWorkingCopy fpwc = (IFacetedProjectWorkingCopy) newProjectDataModel.getProperty(IFacetProjectCreationDataModelProperties.FACETED_PROJECT_WORKING_COPY);
    fpwc.setProjectName(projectRecord.getProjectName());
    IPath projectLocation = projectRecord.getProjectLocation();
    String projectDirName = projectLocation.lastSegment();
    // for now always set a project location (so it can be used by facet install methods) may be unset later
    fpwc.setProjectLocation(projectRecord.getProjectLocation());
    String pluginType = null;
    if (op != null) {
        PluginType type = op.getPluginType().content();
        pluginType = type.name();
        if (PluginType.theme.name().equals(pluginType)) {
            newProjectDataModel.setProperty(IPluginProjectDataModelProperties.THEME_PARENT, op.getThemeParent().content(true));
            newProjectDataModel.setProperty(IPluginProjectDataModelProperties.THEME_TEMPLATE_FRAMEWORK, op.getThemeFramework().content(true));
        }
    } else {
        pluginType = guessPluginType(fpwc);
    }
    SDKPluginFacetUtil.configureProjectAsSDKProject(fpwc, pluginType, sdkLocation.toPortableString(), projectRecord);
    if ((op != null) && PluginType.portlet.name().equals(pluginType)) {
        IPortletFramework portletFramework = op.getPortletFramework().content(true);
        portletFramework.configureNewProject(newProjectDataModel, fpwc);
    }
    // if project is located in natural workspace location then don't need to set a project location
    IPath rootLocation = CoreUtil.getWorkspaceRoot().getLocation();
    if (rootLocation.append(projectDirName).equals(projectLocation)) {
        fpwc.setProjectLocation(null);
    }
    fpwc.commitChanges(monitor);
    CoreUtil.getWorkspace().run(new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            SDK sdk = SDKUtil.createSDKFromLocation(sdkLocation);
            SDKUtil.openAsProject(sdk);
        }
    }, monitor);
    return fpwc.getProject();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IPath(org.eclipse.core.runtime.IPath) IDataModel(org.eclipse.wst.common.frameworks.datamodel.IDataModel) PluginType(com.liferay.ide.project.core.model.PluginType) IPortletFramework(com.liferay.ide.project.core.IPortletFramework) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) CoreException(org.eclipse.core.runtime.CoreException) IFacetedProjectWorkingCopy(org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy) SDK(com.liferay.ide.sdk.core.SDK) PluginFacetProjectCreationDataModelProvider(com.liferay.ide.project.core.facet.PluginFacetProjectCreationDataModelProvider) IFile(org.eclipse.core.resources.IFile) File(java.io.File)

Example 2 with PluginFacetProjectCreationDataModelProvider

use of com.liferay.ide.project.core.facet.PluginFacetProjectCreationDataModelProvider in project liferay-ide by liferay.

the class ProjectUtil method createNewSDKProject.

public static IProject createNewSDKProject(ProjectRecord projectRecord, IRuntime runtime, String sdkLocation, NewLiferayPluginProjectOp op, IProgressMonitor monitor) throws CoreException {
    IDataModel newProjectDataModel = DataModelFactory.createDataModel(new PluginFacetProjectCreationDataModelProvider());
    // we are importing so set flag to not create anything
    newProjectDataModel.setBooleanProperty(IPluginProjectDataModelProperties.CREATE_PROJECT_OPERATION, false);
    IDataModel nestedModel = newProjectDataModel.getNestedModel(IPluginProjectDataModelProperties.NESTED_PROJECT_DM);
    if (op != null) {
        if (op.getUseDefaultLocation().content(true)) {
            // using Eclipse workspace location
            nestedModel.setBooleanProperty(IPluginProjectDataModelProperties.USE_DEFAULT_LOCATION, true);
            newProjectDataModel.setBooleanProperty(IPluginProjectDataModelProperties.LIFERAY_USE_SDK_LOCATION, false);
            newProjectDataModel.setBooleanProperty(IPluginProjectDataModelProperties.LIFERAY_USE_WORKSPACE_LOCATION, true);
        } else {
            nestedModel.setBooleanProperty(IPluginProjectDataModelProperties.USE_DEFAULT_LOCATION, false);
            org.eclipse.sapphire.modeling.Path path = op.getLocation().content(true);
            nestedModel.setStringProperty(IPluginProjectDataModelProperties.USER_DEFINED_LOCATION, path.toOSString());
            if (!op.getUseDefaultLocation().content(true)) {
                newProjectDataModel.setBooleanProperty(IPluginProjectDataModelProperties.LIFERAY_USE_CUSTOM_LOCATION, true);
            }
        }
    }
    setGenerateDD(newProjectDataModel, false);
    IPath webXmlPath = projectRecord.getProjectLocation().append(ISDKConstants.DEFAULT_DOCROOT_FOLDER + "/WEB-INF/web.xml");
    String projectName = projectRecord.getProjectName();
    if (projectName.endsWith(ISDKConstants.PORTLET_PLUGIN_PROJECT_SUFFIX)) {
        newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_PORTLET, true);
        if (!(webXmlPath.toFile().exists())) {
            createDefaultWebXml(webXmlPath.toFile(), projectRecord.getProjectName());
        }
    } else if (projectName.endsWith(ISDKConstants.HOOK_PLUGIN_PROJECT_SUFFIX)) {
        newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_HOOK, true);
        if (!(webXmlPath.toFile().exists())) {
            createDefaultWebXml(webXmlPath.toFile(), projectName);
        }
    } else if (projectName.endsWith(ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX)) {
        Path webPath = new Path(ISDKConstants.DEFAULT_DOCROOT_FOLDER + "/WEB-INF/ext-web/docroot/WEB-INF/web.xml");
        webXmlPath = webXmlPath.removeLastSegments(3).append(webPath);
        newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_EXT, true);
        if (!(webXmlPath.toFile().exists())) {
            createDefaultWebXml(webXmlPath.toFile(), projectName);
        }
    } else if (projectName.endsWith(ISDKConstants.LAYOUTTPL_PLUGIN_PROJECT_SUFFIX)) {
        newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_LAYOUTTPL, true);
    } else if (projectName.endsWith(ISDKConstants.THEME_PLUGIN_PROJECT_SUFFIX)) {
        newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_THEME, true);
    } else if (projectName.endsWith(ISDKConstants.WEB_PLUGIN_PROJECT_SUFFIX)) {
        newProjectDataModel.setProperty(IPluginProjectDataModelProperties.PLUGIN_TYPE_WEB, true);
    }
    IFacetedProjectWorkingCopy fpwc = (IFacetedProjectWorkingCopy) newProjectDataModel.getProperty(IFacetProjectCreationDataModelProperties.FACETED_PROJECT_WORKING_COPY);
    fpwc.setProjectName(projectName);
    IPath projectLocation = projectRecord.getProjectLocation();
    String projectDirName = projectLocation.lastSegment();
    // for now always set a project location (so it can be used by facet install methods) may be unset later
    fpwc.setProjectLocation(projectRecord.getProjectLocation());
    String pluginType = null;
    if (op != null) {
        PluginType type = op.getPluginType().content();
        pluginType = type.name();
        if (PluginType.theme.name().equals(pluginType)) {
            newProjectDataModel.setProperty(IPluginProjectDataModelProperties.THEME_PARENT, op.getThemeParent().content(true));
            newProjectDataModel.setProperty(IPluginProjectDataModelProperties.THEME_TEMPLATE_FRAMEWORK, op.getThemeFramework().content(true));
        }
    } else {
        pluginType = guessPluginType(fpwc);
    }
    SDKPluginFacetUtil.configureProjectAsRuntimeProject(fpwc, runtime, pluginType, sdkLocation, projectRecord);
    String portlet = PluginType.portlet.name();
    if ((op != null) && portlet.equals(pluginType)) {
        IPortletFramework portletFramework = op.getPortletFramework().content(true);
        portletFramework.configureNewProject(newProjectDataModel, fpwc);
    }
    // if project is located in natural workspace location then don't need to set a project location
    IPath workspaceLocation = CoreUtil.getWorkspaceRoot().getLocation();
    if (workspaceLocation.append(projectDirName).equals(projectLocation)) {
        fpwc.setProjectLocation(null);
    }
    fpwc.commitChanges(monitor);
    return fpwc.getProject();
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IPortletFramework(com.liferay.ide.project.core.IPortletFramework) IPath(org.eclipse.core.runtime.IPath) IFacetedProjectWorkingCopy(org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy) IDataModel(org.eclipse.wst.common.frameworks.datamodel.IDataModel) PluginFacetProjectCreationDataModelProvider(com.liferay.ide.project.core.facet.PluginFacetProjectCreationDataModelProvider) PluginType(com.liferay.ide.project.core.model.PluginType)

Aggregations

IPortletFramework (com.liferay.ide.project.core.IPortletFramework)2 PluginFacetProjectCreationDataModelProvider (com.liferay.ide.project.core.facet.PluginFacetProjectCreationDataModelProvider)2 PluginType (com.liferay.ide.project.core.model.PluginType)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 IDataModel (org.eclipse.wst.common.frameworks.datamodel.IDataModel)2 IFacetedProjectWorkingCopy (org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy)2 SDK (com.liferay.ide.sdk.core.SDK)1 File (java.io.File)1 IFile (org.eclipse.core.resources.IFile)1 IWorkspaceRunnable (org.eclipse.core.resources.IWorkspaceRunnable)1 CoreException (org.eclipse.core.runtime.CoreException)1 IProgressMonitor (org.eclipse.core.runtime.IProgressMonitor)1