Search in sources :

Example 21 with IFacetedProject

use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project webtools.sourceediting by eclipse.

the class FacetModuleCoreSupportDelegate method isWebProject.

/**
 * @param project
 * @return
 * @throws CoreException
 */
static boolean isWebProject(IProject project) {
    boolean is = false;
    try {
        IFacetedProject faceted = ProjectFacetsManager.create(project);
        if (ProjectFacetsManager.isProjectFacetDefined(JST_WEB_MODULE)) {
            IProjectFacet facet = ProjectFacetsManager.getProjectFacet(JST_WEB_MODULE);
            is = is || (faceted != null && faceted.hasProjectFacet(facet));
        }
        if (!is && ProjectFacetsManager.isProjectFacetDefined(WST_WEB_MODULE)) {
            IProjectFacet facet = ProjectFacetsManager.getProjectFacet(WST_WEB_MODULE);
            is = is || (faceted != null && faceted.hasProjectFacet(facet));
        }
        if (!is && ProjectFacetsManager.isProjectFacetDefined(JST_WEBFRAGMENT_MODULE)) {
            IProjectFacet facet = ProjectFacetsManager.getProjectFacet(JST_WEBFRAGMENT_MODULE);
            is = is || (faceted != null && faceted.hasProjectFacet(facet));
        }
    } catch (CoreException e) {
        Logger.logException(e);
    }
    return is;
}
Also used : IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) CoreException(org.eclipse.core.runtime.CoreException) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet)

Example 22 with IFacetedProject

use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project webtools.servertools by eclipse.

the class FacetUtil method isRuntimeTargeted.

/**
 * Returns true if the given runtime is being targeted by the facet
 * framework, and false otherwise.
 *
 * @param runtime a runtime
 * @return <code>true</code> if the runtime is in use, and <code>false</code>
 *    otherwise
 */
public static boolean isRuntimeTargeted(IRuntime runtime) {
    try {
        org.eclipse.wst.common.project.facet.core.runtime.IRuntime runtime2 = getRuntime(runtime);
        IProject[] projects = ResourcesPlugin.getWorkspace().getRoot().getProjects();
        if (projects != null) {
            for (IProject project : projects) {
                IFacetedProject facetedProject = ProjectFacetsManager.create(project);
                if (facetedProject != null) {
                    Set<org.eclipse.wst.common.project.facet.core.runtime.IRuntime> set = facetedProject.getTargetedRuntimes();
                    if (set != null && set.contains(runtime2))
                        return true;
                }
            }
        }
    } catch (Throwable t) {
        if (Trace.WARNING) {
            Trace.trace(Trace.STRING_WARNING, "Could not determine if runtime is in use", t);
        }
    }
    return false;
}
Also used : IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IProject(org.eclipse.core.resources.IProject) IRuntime(org.eclipse.wst.server.core.IRuntime)

Example 23 with IFacetedProject

use of org.eclipse.wst.common.project.facet.core.IFacetedProject in project webtools.servertools by eclipse.

the class InitialSelectionProvider method getInitialSelection.

/**
 * Allows adopters to provide an initial selection out of a list of items.
 * <p>
 * The <code>IProject</code> can be null, in cases where a project selection was not available (ie: New Server Wizard)
 * </p><p>
 * Returning <code>null</code> means no object is applicable to be selected.
 * </p>
 *
 * @param servers
 * @param project
 * @return
 */
public IServer getInitialSelection(IServer[] servers, IProject project) {
    if (servers == null)
        return null;
    IServer rval = servers[0];
    if (project != null) {
        try {
            // check for the targeted runtime of the project
            IFacetedProject facetedProject = ProjectFacetsManager.create(project);
            if (facetedProject != null) {
                org.eclipse.wst.common.project.facet.core.runtime.IRuntime facetedRuntime = facetedProject.getPrimaryRuntime();
                if (facetedRuntime != null) {
                    IRuntime runtime = FacetUtil.getRuntime(facetedRuntime);
                    IServer server = findServerFromRuntime(runtime.getId());
                    if (server != null) {
                        rval = server;
                    }
                }
            }
        } catch (CoreException ce) {
            if (Trace.WARNING) {
                Trace.trace(Trace.STRING_WARNING, "Could not create a faceted project", ce);
            }
        }
    }
    return rval;
}
Also used : IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) CoreException(org.eclipse.core.runtime.CoreException)

Example 24 with IFacetedProject

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

the class LiferayFacetedProjectListener method handleEvent.

public void handleEvent(IFacetedProjectEvent event) {
    if (event.getType() != IFacetedProjectEvent.Type.POST_INSTALL) {
        return;
    }
    IProjectFacetActionEvent actionEvent = (IProjectFacetActionEvent) event;
    if (!JSDT_FACET.equals(actionEvent.getProjectFacet().getId())) {
        return;
    }
    Job uninstall = new WorkspaceJob("uninstall jsdt facet") {

        @Override
        public IStatus runInWorkspace(IProgressMonitor monitor) throws CoreException {
            try {
                IFacetedProject fProject = actionEvent.getProject();
                Set<IProjectFacet> fixedFacets = fProject.getFixedProjectFacets();
                Set<IProjectFacet> updatedFacets = new HashSet<>();
                for (IProjectFacet f : fixedFacets) {
                    if (!JSDT_FACET.equals(f.getId())) {
                        updatedFacets.add(f);
                    }
                }
                fProject.setFixedProjectFacets(updatedFacets);
            } catch (Exception e) {
                ProjectCore.logError("Unable to removed fixed jsdt facet", e);
            }
            try {
                Set<Action> actions = new HashSet<>();
                Type type = Type.valueOf("uninstall");
                Action uninstallJsdt = new Action(type, actionEvent.getProjectFacetVersion(), null);
                actions.add(uninstallJsdt);
                actionEvent.getProject().modify(actions, monitor);
                // try to remove unneeded jsdt files
                IProject project = actionEvent.getProject().getProject();
                IFile jsdtscope = project.getFile(".settings/.jsdtscope");
                if (FileUtil.exists(jsdtscope)) {
                    jsdtscope.delete(true, monitor);
                }
                IFile container = project.getFile(".settings/org.eclipse.wst.jsdt.ui.superType.container");
                if (FileUtil.exists(container)) {
                    container.delete(true, monitor);
                }
                IFile name = project.getFile(".settings/org.eclipse.wst.jsdt.ui.superType.name");
                if (FileUtil.exists(name)) {
                    name.delete(true, monitor);
                }
            } catch (CoreException ce) {
                ProjectCore.logError("Unable to uninstall jsdt facet", ce);
            }
            return Status.OK_STATUS;
        }
    };
    uninstall.schedule();
}
Also used : IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) Action(org.eclipse.wst.common.project.facet.core.IFacetedProject.Action) IFile(org.eclipse.core.resources.IFile) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) CoreException(org.eclipse.core.runtime.CoreException) IProject(org.eclipse.core.resources.IProject) IProjectFacetActionEvent(org.eclipse.wst.common.project.facet.core.events.IProjectFacetActionEvent) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) Type(org.eclipse.wst.common.project.facet.core.IFacetedProject.Action.Type) CoreException(org.eclipse.core.runtime.CoreException) IProjectFacet(org.eclipse.wst.common.project.facet.core.IProjectFacet) Job(org.eclipse.core.runtime.jobs.Job) WorkspaceJob(org.eclipse.core.resources.WorkspaceJob) HashSet(java.util.HashSet)

Example 25 with IFacetedProject

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

the class ProjectUtil method createExistingProject.

public static IProject createExistingProject(ProjectRecord record, IRuntime runtime, String sdkLocation, IProgressMonitor monitor) throws CoreException {
    String projectName = record.getProjectName();
    IWorkspace workspace = ResourcesPlugin.getWorkspace();
    IProject project = workspace.getRoot().getProject(projectName);
    if (record.description == null) {
        // error case
        record.description = workspace.newProjectDescription(projectName);
        IPath locationPath = new Path(record.projectSystemFile.getAbsolutePath());
        if (Platform.getLocation().isPrefixOf(locationPath)) {
            record.description.setLocation(null);
        } else {
            record.description.setLocation(locationPath);
        }
    } else {
        record.description.setName(projectName);
    }
    monitor.beginTask(Msgs.importingProject, 100);
    project.create(record.description, CoreUtil.newSubMonitor(monitor, 30));
    project.open(IResource.FORCE, CoreUtil.newSubMonitor(monitor, 70));
    if (project.getName().endsWith(ISDKConstants.EXT_PLUGIN_PROJECT_SUFFIX)) {
        _fixExtProjectClasspathEntries(project);
    }
    IFacetedProject fProject = ProjectFacetsManager.create(project, true, monitor);
    FacetedProjectWorkingCopy fpwc = new FacetedProjectWorkingCopy(fProject);
    String pluginType = guessPluginType(fpwc);
    SDKPluginFacetUtil.configureProjectAsRuntimeProject(fpwc, runtime, pluginType, sdkLocation, record);
    fpwc.commitChanges(monitor);
    IJavaProject javaProject = JavaCore.create(fProject.getProject());
    CoreUtil.getWorkspace().run(new IWorkspaceRunnable() {

        @Override
        public void run(IProgressMonitor monitor) throws CoreException {
            for (IClasspathEntry entry : javaProject.getRawClasspath()) {
                String segment = entry.getPath().segment(0);
                if ((entry.getEntryKind() == IClasspathEntry.CPE_CONTAINER) && segment.equals(PluginClasspathContainerInitializer.ID)) {
                    ClasspathContainerInitializer initializer = JavaCore.getClasspathContainerInitializer(PluginClasspathContainerInitializer.ID);
                    initializer.initialize(entry.getPath(), javaProject);
                    break;
                }
            }
            monitor.done();
        }
    }, monitor);
    return project;
}
Also used : IPath(org.eclipse.core.runtime.IPath) Path(org.eclipse.core.runtime.Path) IWorkspaceRunnable(org.eclipse.core.resources.IWorkspaceRunnable) IFacetedProject(org.eclipse.wst.common.project.facet.core.IFacetedProject) IPath(org.eclipse.core.runtime.IPath) IClasspathEntry(org.eclipse.jdt.core.IClasspathEntry) FacetedProjectWorkingCopy(org.eclipse.wst.common.project.facet.core.internal.FacetedProjectWorkingCopy) IFacetedProjectWorkingCopy(org.eclipse.wst.common.project.facet.core.IFacetedProjectWorkingCopy) IProject(org.eclipse.core.resources.IProject) PluginClasspathContainerInitializer(com.liferay.ide.project.core.PluginClasspathContainerInitializer) ClasspathContainerInitializer(org.eclipse.jdt.core.ClasspathContainerInitializer) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) IJavaProject(org.eclipse.jdt.core.IJavaProject) CoreException(org.eclipse.core.runtime.CoreException) IWorkspace(org.eclipse.core.resources.IWorkspace)

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