1

My ultimate goal is to create an eclipse plugin that sets up a PDT project, but with some added builders (and custom build scripts) as well as a specific folder layout (and different folders should be treated as source and some as regular folders).

I've looked at / followed eclipse plugin development tutorials, and ok. I get the gist of creating a wizard that creates a file, but I'm having trouble trying to figure out how to create a project, and more importantly, make that project associated with the PDT (PHP Development Tools) feature.

Answer:

I did stumble upon a solution myself before the answer was given, but it's quite similar.

First, WizardNewProjectCreationPage was used as the first page of my wizard.

Second, on performFinish() I ran the following code:

        IProgressMonitor    m           = new NullProgressMonitor();
        IWorkspaceRoot      root        = ResourcesPlugin.getWorkspace().getRoot();
        IProject            project     = root.getProject(_pageOne.getProjectName());

        if (!project.exists())
        {
            IProjectDescription desc = project.getWorkspace().newProjectDescription(project.getName());
            URI projectLocation = _pageOne.getLocationURI();
            // desc.setLocationURI(projectLocation);

            String[]            natures     = desc.getNatureIds();
            String[]            newNatures  = new String[natures.length + 1];

            System.arraycopy(natures, 0, newNatures, 0, natures.length);
            newNatures[natures.length] = PHPNature.ID;

            desc.setNatureIds(newNatures);
            project.create(desc, m);
            project.open(m);
        }

1 Answer 1

1

how to create a project

Take a look at BasicNewProjectResourceWizard.createNewProject() method.

make that project associated with the PDT (PHP Development Tools) feature

You need to add "org.eclipse.php.core.PHPNature" to the project (that's what Add PHP Support... action does). Use IProjectDescription.setNatureIds().

1
  • Thank you for your answer. I've edited my question to show what I did to accomplish what I wanted. I stumbled upon it myself, and is almost identical to what you describe. I was simply not aware of how natures worked ;)
    – Alex Dow
    Feb 23, 2012 at 20:19

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.