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;
}
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;
}
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;
}
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();
}
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;
}
Aggregations