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