/******************************************************************************* * This file is part of the Symfony eclipse plugin. * * (c) Robert Gruendler <r.gruendler@gmail.com> * * For the full copyright and license information, please view the LICENSE * file that was distributed with this source code. ******************************************************************************/ package com.dubture.symfony.core.builder; import org.eclipse.core.resources.ICommand; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.runtime.CoreException; import org.eclipse.dltk.core.ScriptNature; import com.dubture.symfony.core.SymfonyCorePlugin; public class SymfonyNature extends ScriptNature { /** * ID of this project nature */ public static final String NATURE_ID = SymfonyCorePlugin.ID + ".symfonyNature"; /* * (non-Javadoc) * * @see org.eclipse.core.resources.IProjectNature#configure() */ public void configure() throws CoreException { super.configure(); IProjectDescription desc = getProject().getDescription(); ICommand[] commands = desc.getBuildSpec(); for (int i = 0; i < commands.length; ++i) { if (commands[i].getBuilderName().equals(SymfonyBuilder.BUILDER_ID)) { return; } } ICommand[] newCommands = new ICommand[commands.length + 1]; // put the SymfonyBuilder on the first position as we need to // parse the xml/yml files before the php sources are being parses // so the definitions for ie. services can be resolved. System.arraycopy(commands, 0, newCommands, 1, commands.length); ICommand command = desc.newCommand(); command.setBuilderName(SymfonyBuilder.BUILDER_ID); newCommands[0] = command; desc.setBuildSpec(newCommands); getProject().setDescription(desc, null); } /* * (non-Javadoc) * * @see org.eclipse.core.resources.IProjectNature#deconfigure() */ public void deconfigure() throws CoreException { super.deconfigure(); IProjectDescription description = getProject().getDescription(); ICommand[] commands = description.getBuildSpec(); for (int i = 0; i < commands.length; ++i) { if (commands[i].getBuilderName().equals(SymfonyBuilder.BUILDER_ID)) { ICommand[] newCommands = new ICommand[commands.length - 1]; System.arraycopy(commands, 0, newCommands, 0, i); System.arraycopy(commands, i + 1, newCommands, i, commands.length - i - 1); description.setBuildSpec(newCommands); getProject().setDescription(description, null); return; } } } }