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