Package org.playframework.playclipse.builder

Source Code of org.playframework.playclipse.builder.PlayNature

package org.playframework.playclipse.builder;

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;
import org.eclipse.jdt.core.IJavaProject;
import org.eclipse.jdt.core.JavaCore;

public class PlayNature implements IProjectNature {

  /**
   * ID of this project nature
   */
  public static final String NATURE_ID = "org.playframework.playclipse.playNature";

  private IProject project;
  private IJavaProject javaProject;


  @Override
  public void configure() throws CoreException {
    System.out.println("configure Japid Nature ");
    IProjectDescription desc = project.getDescription();
    ICommand[] commands = desc.getBuildSpec();

    for (int i = 0; i < commands.length; ++i) {
      if (commands[i].getBuilderName().equals(PlayBuilder.BUILDER_ID)) {
        return;
      }
    }

    ICommand[] newCommands = new ICommand[commands.length + 1];
    System.arraycopy(commands, 0, newCommands, 1, commands.length);
    ICommand command = desc.newCommand();
    command.setBuilderName(PlayBuilder.BUILDER_ID);
    newCommands[0] = command;
    desc.setBuildSpec(newCommands);
    project.setDescription(desc, null);
  }

  public Map<String, String> getModules() {
    ConfigurationFile conf = new ConfigurationFile(project);
    return conf.getModules();
  }

  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.core.resources.IProjectNature#deconfigure()
   */
  @Override
  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(PlayBuilder.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);
        project.setDescription(description, null);
        return;
      }
    }
  }

  @Override
  public IProject getProject() {
    return project;
  }

  public IJavaProject getJavaProject() {
    return javaProject;
  }


  @Override
  public void setProject(IProject project) {
    this.project = project;
    this.javaProject = JavaCore.create(project);

  }

}
TOP

Related Classes of org.playframework.playclipse.builder.PlayNature

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.