1 package net.sourceforge.phpeclipse;
3 import java.util.ArrayList;
6 import net.sourceforge.phpeclipse.resourcesview.PHPFile;
7 import net.sourceforge.phpeclipse.resourcesview.PHPProject;
9 import org.eclipse.core.resources.IFile;
10 import org.eclipse.core.resources.IProject;
11 import org.eclipse.core.resources.IProjectDescription;
12 import org.eclipse.core.runtime.CoreException;
13 import org.eclipse.core.runtime.IProgressMonitor;
15 public class PHPCore {
17 public static IProject[] getPHPProjects() {
18 List phpProjectsList = new ArrayList();
19 IProject[] workspaceProjects = PHPeclipsePlugin.getWorkspace().getRoot().getProjects();
21 for (int i = 0; i < workspaceProjects.length; i++) {
22 IProject iProject = workspaceProjects[i];
23 if (isPHPProject(iProject))
24 phpProjectsList.add(iProject);
27 IProject[] phpProjects = new IProject[phpProjectsList.size()];
28 return (IProject[]) phpProjectsList.toArray(phpProjects);
31 public static PHPProject getPHPProject(String name) {
32 IProject aProject = PHPeclipsePlugin.getWorkspace().getRoot().getProject(name);
33 if (isPHPProject(aProject)) {
34 PHPProject thePHPProject = new PHPProject();
35 thePHPProject.setProject(aProject);
41 public static boolean isPHPProject(IProject aProject) {
43 return aProject.hasNature(PHPeclipsePlugin.PHP_NATURE_ID);
44 } catch (CoreException e) {
50 public static PHPFile create(IFile aFile) {
51 if (PHPFile.EXTENSION.equalsIgnoreCase(aFile.getFileExtension()))
52 return new PHPFile(aFile);
53 if (PHPFile.EXTENSION1.equalsIgnoreCase(aFile.getFileExtension()))
54 return new PHPFile(aFile);
55 if (PHPFile.EXTENSION2.equalsIgnoreCase(aFile.getFileExtension()))
56 return new PHPFile(aFile);
57 if (PHPFile.EXTENSION3.equalsIgnoreCase(aFile.getFileExtension()))
58 return new PHPFile(aFile);
59 if (PHPFile.EXTENSION4.equalsIgnoreCase(aFile.getFileExtension()))
60 return new PHPFile(aFile);
61 if (PHPFile.EXTENSION5.equalsIgnoreCase(aFile.getFileExtension()))
62 return new PHPFile(aFile);
67 public static PHPProject create(IProject aProject) {
69 if (aProject.hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) {
70 PHPProject project = new PHPProject();
71 project.setProject(aProject);
74 } catch (CoreException e) {
75 System.err.println("Exception occurred in PHPCore#create(IProject): " + e.toString());
81 public static void addPHPNature(IProject project, IProgressMonitor monitor) throws CoreException {
82 if (!project.hasNature(PHPeclipsePlugin.PHP_NATURE_ID)) {
83 IProjectDescription description = project.getDescription();
84 String[] prevNatures = description.getNatureIds();
85 String[] newNatures = new String[prevNatures.length + 1];
86 System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
87 newNatures[prevNatures.length] = PHPeclipsePlugin.PHP_NATURE_ID;
88 description.setNatureIds(newNatures);
89 project.setDescription(description, monitor);