/******************************************************************************* * Copyright (c) 2011 Obeo. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * Obeo - initial API and implementation *******************************************************************************/ package org.eclipse.mylyn.docs.intent.client.ui.ide.builder; import java.util.HashMap; import java.util.Map; 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; /** * The Intent Project nature. * * @author <a href="mailto:alex.lagarde@obeo.fr">Alex Lagarde</a> */ public class IntentNature implements IProjectNature { /** * ID of the Intent workspace type. */ public static final String INTENT_WORKSPACE_TYPE = "org.eclipse.mylyn.docs.intent.collab.ide.repository"; /** * Type tag. */ public static final String TYPE_TAG = "type"; /** * ID of this project nature. */ public static final String NATURE_ID = "org.eclipse.mylyn.docs.intent.client.ui.ide.intentNature"; /** * The {@link IProject} associated to this nature. */ private IProject project; /** * {@inheritDoc} * * @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(IntentBuilder.BUILDER_ID)) { return; } } ICommand[] newCommands = new ICommand[commands.length + 1]; System.arraycopy(commands, 0, newCommands, 0, commands.length); ICommand command = desc.newCommand(); command.setBuilderName(IntentBuilder.BUILDER_ID); Map<String, String> args = new HashMap<String, String>(); args.put(TYPE_TAG, INTENT_WORKSPACE_TYPE); command.setArguments(args); newCommands[newCommands.length - 1] = command; desc.setBuildSpec(newCommands); project.setDescription(desc, null); } /** * {@inheritDoc} * * @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(IntentBuilder.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; } } } /** * {@inheritDoc} * * @see org.eclipse.core.resources.IProjectNature#getProject() */ public IProject getProject() { return project; } /** * {@inheritDoc} * * @see org.eclipse.core.resources.IProjectNature#setProject(org.eclipse.core.resources.IProject) */ public void setProject(IProject project) { this.project = project; } }