Search in sources :

Example 1 with IFacetedProjectWorkingCopy

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

the class LayoutTplPluginFacetInstall method removeUnneededClasspathEntries.

protected void removeUnneededClasspathEntries() {
    IFacetedProjectWorkingCopy facetedProject = getFacetedProject();
    IJavaProject javaProject = JavaCore.create(facetedProject.getProject());
    try {
        IClasspathEntry[] existingClasspath = javaProject.getRawClasspath();
        List<IClasspathEntry> newClasspath = new ArrayList<>();
        for (IClasspathEntry entry : existingClasspath) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                continue;
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                String path = entry.getPath().toPortableString();
                if (path.contains("org.eclipse.jdt.launching.JRE_CONTAINER") || path.contains("org.eclipse.jst.j2ee.internal.web.container") || path.contains("org.eclipse.jst.j2ee.internal.module.container")) {
                    continue;
                }
            }
            newClasspath.add(entry);
        }
        javaProject.setRawClasspath(newClasspath.toArray(new IClasspathEntry[0]), null);
        IResource sourceFolder = javaProject.getProject().findMember(IPluginFacetConstants.PORTLET_PLUGIN_SDK_SOURCE_FOLDER);
        if (FileUtil.exists(sourceFolder)) {
            sourceFolder.delete(true, null);
        }
    } catch (Exception e) {
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) IFacetedProjectWorkingCopy(org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy) IResource(org.eclipse.core.resources.IResource) CoreException(org.eclipse.core.runtime.CoreException)

Example 2 with IFacetedProjectWorkingCopy

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

the class SDKProjectConvertDataModelProvider method init.

@Override
public void init() {
    super.init();
    // set the project facets to get the runtime target dropdown to only show liferay runtimes
    IFacetedProjectWorkingCopy facetedProject = getFacetedProjectWorkingCopy();
    Set<IProjectFacetVersion> facets = ProjectUtil.getFacetsForPreset(IPluginFacetConstants.LIFERAY_PORTLET_PRESET);
    Set<IProjectFacet> fixedFacets = new HashSet<>();
    for (IProjectFacetVersion pfv : facets) {
        fixedFacets.add(pfv.getProjectFacet());
    }
    facetedProject.setFixedProjectFacets(Collections.unmodifiableSet(fixedFacets));
}
Also used : IProjectFacetVersion(org.eclipse.wst.common.project.facet.core.IProjectFacetVersion) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) IFacetedProjectWorkingCopy(org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy) HashSet(java.util.HashSet)

Example 3 with IFacetedProjectWorkingCopy

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

the class SDKProjectsImportDataModelProvider method init.

@Override
public void init() {
    super.init();
    // set the project facets to get the runtime target dropdown to only show liferay runtimes
    IFacetedProjectWorkingCopy facetedProject = getFacetedProjectWorkingCopy();
    facetedProject.setSelectedPreset(IPluginFacetConstants.LIFERAY_PORTLET_PRESET);
    Set<IProjectFacet> fixedFacets = new HashSet<>();
    fixedFacets.add(ProjectFacetsManager.getProjectFacet(IPluginFacetConstants.LIFERAY_EXT_FACET_ID));
    facetedProject.setFixedProjectFacets(Collections.unmodifiableSet(fixedFacets));
    ProjectUtil.setDefaultRuntime(getDataModel());
}
Also used : IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) IFacetedProjectWorkingCopy(org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy) HashSet(java.util.HashSet)

Example 4 with IFacetedProjectWorkingCopy

use of org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy 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 5 with IFacetedProjectWorkingCopy

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

the class ThemePluginFacetInstall method removeUnneededClasspathEntries.

protected void removeUnneededClasspathEntries() {
    IFacetedProjectWorkingCopy facetedProject = getFacetedProject();
    IJavaProject javaProject = JavaCore.create(facetedProject.getProject());
    try {
        IClasspathEntry[] existingClasspath = javaProject.getRawClasspath();
        List<IClasspathEntry> newClasspath = new ArrayList<>();
        for (IClasspathEntry entry : existingClasspath) {
            if (entry.getEntryKind() == IClasspathEntry.CPE_SOURCE) {
                continue;
            } else if (entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) {
                String path = entry.getPath().toPortableString();
                if (path.contains("org.eclipse.jdt.launching.JRE_CONTAINER") || path.contains("org.eclipse.jst.j2ee.internal.web.container") || path.contains("org.eclipse.jst.j2ee.internal.module.container")) {
                    continue;
                }
            }
            newClasspath.add(entry);
        }
        javaProject.setRawClasspath(newClasspath.toArray(new IClasspathEntry[0]), null);
        IResource sourceFolder = javaProject.getProject().findMember(IPluginFacetConstants.PORTLET_PLUGIN_SDK_SOURCE_FOLDER);
        if (sourceFolder.exists()) {
            sourceFolder.delete(true, null);
        }
    } catch (Exception e) {
    }
}
Also used : IJavaProject(org.eclipse.jdt.core.IJavaProject) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) ArrayList(java.util.ArrayList) IFacetedProjectWorkingCopy(org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy) IResource(org.eclipse.core.resources.IResource) CoreException(org.eclipse.core.runtime.CoreException) IOException(java.io.IOException)

Aggregations

IFacetedProjectWorkingCopy (org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy)12 HashSet (java.util.HashSet)5 CoreException (org.eclipse.core.runtime.CoreException)5 IProjectFacet (org.eclipse.wst.common.project.facet.core.IProjectFacet)5 IProjectFacetVersion (org.eclipse.wst.common.project.facet.core.IProjectFacetVersion)5 IJavaProject (org.eclipse.jdt.core.IJavaProject)3 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 ArrayList (java.util.ArrayList)2 IResource (org.eclipse.core.resources.IResource)2 IPath (org.eclipse.core.runtime.IPath)2 Path (org.eclipse.core.runtime.Path)2 IClasspathEntry (org.eclipse.jdt.core.IClasspathEntry)2 IDataModel (org.eclipse.wst.common.frameworks.datamodel.IDataModel)2 IFacetedProject (org.eclipse.wst.common.project.facet.core.IFacetedProject)2 ModifyFacetedProjectWizard (org.eclipse.wst.common.project.facet.ui.ModifyFacetedProjectWizard)2 ContainerType (com.centurylink.mdw.plugin.project.model.ServerSettings.ContainerType)1 SDK (com.liferay.ide.sdk.core.SDK)1 File (java.io.File)1