/* * Copyright (C) 2003-2007 Kepler Project. * * Permission is hereby granted, free of charge, to any person obtaining * a copy of this software and associated documentation files (the * "Software"), to deal in the Software without restriction, including * without limitation the rights to use, copy, modify, merge, publish, * distribute, sublicense, and/or sell copies of the Software, and to * permit persons to whom the Software is furnished to do so, subject to * the following conditions: * * The above copyright notice and this permission notice shall be * included in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ package org.keplerproject.ldt.core.project; import org.eclipse.core.resources.ICommand; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; import org.eclipse.core.resources.IProjectNature; import org.eclipse.core.runtime.CoreException; import org.keplerproject.ldt.core.LuaProject; /** * The Lua Project Nature. Eclipse projects tha use Lua files * may have this nature. * * @author guilherme * @version $Id$ */ public class LuaProjectNature implements IProjectNature { /** * ID of this project nature */ public static final String NATURE_ID = "org.keplerproject.ldt.core.luaProjectNature"; private IProject project; /* * (non-Javadoc) * * @see org.eclipse.core.resources.IProjectNature#configure() */ public void configure() throws CoreException { IProjectDescription desc = project.getDescription(); ICommand[] commands = desc.getBuildSpec(); for (int i = 0; i < commands.length; ++i) { if (commands[i].getBuilderName().equals(LuaProjectBuilder.BUILDER_ID)) { return; } } ICommand[] newCommands = new ICommand[commands.length + 1]; System.arraycopy(commands, 0, newCommands, 0, commands.length); ICommand command = desc.newCommand(); command.setBuilderName(LuaProjectBuilder.BUILDER_ID); newCommands[newCommands.length - 1] = command; desc.setBuildSpec(newCommands); project.setDescription(desc, null); } /* * (non-Javadoc) * * @see org.eclipse.core.resources.IProjectNature#deconfigure() */ public void deconfigure() throws CoreException { IProjectDescription description = getProject().getDescription(); ICommand[] commands = description.getBuildSpec(); for (int i = 0; i < commands.length; ++i) { if (commands[i].getBuilderName().equals(LuaProjectBuilder.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); return; } } } /* * (non-Javadoc) * * @see org.eclipse.core.resources.IProjectNature#getProject() */ public IProject getProject() { return project; } /* * (non-Javadoc) * * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject) */ public void setProject(IProject project) { this.project = project; LuaProject.getLuaProject(project); } }