Java Code Examples for org.eclipse.core.resources.IProjectDescription#getBuildSpec()

The following examples show how to use org.eclipse.core.resources.IProjectDescription#getBuildSpec() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: FindBugsNature.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Update the FindBugs command in the build spec (replace existing one if
 * present, add one first if none).
 */
private void setFindBugsCommand(IProjectDescription description, ICommand newCommand) throws CoreException {
    ICommand[] oldCommands = description.getBuildSpec();
    ICommand oldFindBugsCommand = getFindBugsCommand(description);
    ICommand[] newCommands;
    if (oldFindBugsCommand == null) {
        // Add the FindBugs build spec AFTER all other builders
        newCommands = new ICommand[oldCommands.length + 1];
        System.arraycopy(oldCommands, 0, newCommands, 0, oldCommands.length);
        newCommands[oldCommands.length] = newCommand;
    } else {
        for (int i = 0, max = oldCommands.length; i < max; i++) {
            if (oldCommands[i] == oldFindBugsCommand) {
                oldCommands[i] = newCommand;
                break;
            }
        }
        newCommands = oldCommands;
    }
    // Commit the spec change into the project
    description.setBuildSpec(newCommands);
    getProject().setDescription(description, null);
}
 
Example 2
Source File: ProjectUtils.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
public static void removeJavaNatureAndBuilder(IProject project, IProgressMonitor monitor) throws CoreException {
	if (project != null && project.isAccessible() && ProjectUtils.isJavaProject(project)) {
		IProjectDescription description = project.getDescription();
		String[] natureIds = description.getNatureIds();
		String[] newIds = new String[natureIds.length - 1];
		int count = 0;
		for (String id : natureIds) {
			if (!JavaCore.NATURE_ID.equals(id)) {
				newIds[count++] = id;
			}
		}
		description.setNatureIds(newIds);
		ICommand[] commands = description.getBuildSpec();
		for (int i = 0; i < commands.length; ++i) {
			if (commands[i].getBuilderName().equals(JavaCore.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);
				break;
			}
		}
		project.setDescription(description, IResource.FORCE, monitor);
	}
}
 
Example 3
Source File: LangNature.java    From goclipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Adds a builder to the build spec for the configured project.
 */
protected void addToBuildSpec(String builderID) throws CoreException {
	IProjectDescription description = project.getDescription();
	ICommand[] commands = description.getBuildSpec();
	int commandIndex = getCommandIndex(commands, builderID);
	if (commandIndex == -1) {
		ICommand command = description.newCommand();
		command.setBuilderName(builderID);
		command.setBuilding(IncrementalProjectBuilder.AUTO_BUILD, false);
		
		// Add a build command to the build spec
		ICommand[] newCommands = ArrayUtil.prepend(command, commands);
		description.setBuildSpec(newCommands);
		project.setDescription(description, null);
	}
}
 
Example 4
Source File: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static void removeBuilder(IProject project, String builderId) throws CoreException {
	IProjectDescription description = project.getDescription();
	ICommand[] builderSpecs = description.getBuildSpec();

	for (int i = 0; i < builderSpecs.length; ++i) {
		if (builderId.equals(builderSpecs[i].getBuilderName())) {
			// Remove the builder
			ICommand[] modifiedSpecs = new ICommand[builderSpecs.length - 1];
			System.arraycopy(builderSpecs, 0, modifiedSpecs, 0, i);
			System.arraycopy(builderSpecs, i + 1, modifiedSpecs, i, builderSpecs.length - i - 1);
			description.setBuildSpec(modifiedSpecs);
			project.setDescription(description, null);
			return;
		}
	}

}
 
Example 5
Source File: XtextNature.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Override
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(XtextBuilder.BUILDER_ID)) {
			return;
		}
	}

	ICommand[] newCommands = new ICommand[commands.length + 1];
	System.arraycopy(commands, 0, newCommands, 1, commands.length);
	ICommand command = desc.newCommand();
	command.setBuilderName(XtextBuilder.BUILDER_ID);
	newCommands[0] = command;
	desc.setBuildSpec(newCommands);
	project.setDescription(desc, null);
}
 
Example 6
Source File: HybrisNature.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
@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(StandardTsvBuilder.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;
		}
	}
}
 
Example 7
Source File: AppEngineStandardFacetChangeListener.java    From google-cloud-eclipse with Apache License 2.0 6 votes vote down vote up
/**
 * Add our {@code appengine-web.xml} builder that monitors for changes to the {@code <runtime>}
 * element.
 */
private static void addAppEngineWebBuilder(IProject project) {
  try {
    IProjectDescription projectDescription = project.getDescription();
    ICommand[] commands = projectDescription.getBuildSpec();
    for (int i = 0; i < commands.length; i++) {
      if (AppEngineWebBuilder.BUILDER_ID.equals(commands[i].getBuilderName())) {
        return;
      }
    }
    ICommand[] newCommands = new ICommand[commands.length + 1];
    // Add it after other builders.
    System.arraycopy(commands, 0, newCommands, 0, commands.length);
    // add builder to project
    ICommand command = projectDescription.newCommand();
    command.setBuilderName(AppEngineWebBuilder.BUILDER_ID);
    newCommands[commands.length] = command;
    projectDescription.setBuildSpec(newCommands);
    project.setDescription(projectDescription, null);
    logger.finer(project + ": added AppEngineWebBuilder");
  } catch (CoreException ex) {
    logger.log(Level.SEVERE, "Unable to add builder for " + project, ex);
  }
}
 
Example 8
Source File: Nature.java    From cppcheclipse with Apache License 2.0 6 votes vote down vote up
public void configure() throws CoreException {
	// add builder to list of proect builders
	IProjectDescription desc = project.getDescription();
	ICommand[] commands = desc.getBuildSpec();
	for (int i = 0; i < commands.length; ++i) {
		if (commands[i].getBuilderName().equals(Builder.BUILDER_ID)) {
			return;
		}
	}
	ICommand[] newCommands = new ICommand[commands.length + 1];
	System.arraycopy(commands, 0, newCommands, 0, commands.length);
	ICommand command = desc.newCommand();
	command.setBuilderName(Builder.BUILDER_ID);
	newCommands[newCommands.length - 1] = command;
	desc.setBuildSpec(newCommands);
	project.setDescription(desc, null);
}
 
Example 9
Source File: GamlUtils.java    From gama with GNU General Public License v3.0 6 votes vote down vote up
public static void removeBuilder(final IProject project, final String builderId) throws CoreException {
	final IProjectDescription description = project.getDescription();
	final ICommand[] builderSpecs = description.getBuildSpec();

	for (int i = 0; i < builderSpecs.length; ++i) {
		if (builderId.equals(builderSpecs[i].getBuilderName())) {
			// Remove the builder
			final ICommand[] modifiedSpecs = new ICommand[builderSpecs.length - 1];
			System.arraycopy(builderSpecs, 0, modifiedSpecs, 0, i);
			System.arraycopy(builderSpecs, i + 1, modifiedSpecs, i, builderSpecs.length - i - 1);
			description.setBuildSpec(modifiedSpecs);
			project.setDescription(description, null);
			return;
		}
	}

}
 
Example 10
Source File: CheckstyleNature.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Checks if the ordering of the builders of the given project is correct, more specifically if
 * the CheckstyleBuilder is set to run after the JavaBuilder.
 *
 * @param project
 *          the project to check
 * @return <code>true</code> if the builder order for this project is correct, <code>false</code>
 *         otherwise
 * @throws CoreException
 *           error getting project description
 */
public static boolean hasCorrectBuilderOrder(IProject project) throws CoreException {
  IProjectDescription description = project.getDescription();
  ICommand[] commands = description.getBuildSpec();

  int javaBuilderIndex = -1;
  int checkstyleBuilderIndex = -1;

  for (int i = 0; i < commands.length; i++) {

    if (commands[i].getBuilderName().equals(CheckstyleBuilder.BUILDER_ID)) {
      checkstyleBuilderIndex = i;
    } else if (commands[i].getBuilderName().equals(JavaCore.BUILDER_ID)) {
      javaBuilderIndex = i;
    }
  }
  return javaBuilderIndex < checkstyleBuilderIndex;
}
 
Example 11
Source File: GamlUtils.java    From gama with GNU General Public License v3.0 5 votes vote down vote up
public static void addBuilder(final IProject project, final String builderId) throws CoreException {
	final IProjectDescription description = project.getDescription();
	final ICommand[] specs = description.getBuildSpec();
	final ICommand command = description.newCommand();
	command.setBuilderName(builderId);
	// Add the nature
	final ICommand[] specsModified = new ICommand[specs.length + 1];
	System.arraycopy(specs, 0, specsModified, 0, specs.length);
	specsModified[specs.length] = command;
	description.setBuildSpec(specsModified);
	project.setDescription(description, monitor());
}
 
Example 12
Source File: SCTNature.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
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(SCTBuilder.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;
		}
	}
}
 
Example 13
Source File: ProblemMarkerNature.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public void deconfigure() throws CoreException {
	final IProjectDescription description = getProject().getDescription();
	final ICommand[] commands = description.getBuildSpec();
	for (int i = 0; i < commands.length; ++i) {
		if (commands[i].getBuilderName().equals(Constants.BUILDER_ID)) {
			final 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);
			this.project.setDescription(description, null);
			return;
		}
	}
}
 
Example 14
Source File: LangNature.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
/** Removes the given builder from the build spec for the configured project. */
protected void removeFromBuildSpec(String builderID) throws CoreException {
	IProjectDescription description = project.getDescription();
	
	ICommand[] commands = description.getBuildSpec();
	int commandIndex = getCommandIndex(commands, builderID);
	if(commandIndex != -1) {
		commands = ArrayUtil.removeAt(commands, commandIndex);
		description.setBuildSpec(commands);
		project.setDescription(description, null);
	}
}
 
Example 15
Source File: LangNature.java    From goclipse with Eclipse Public License 1.0 5 votes vote down vote up
public static void disableAutoBuildMode(IProject project, String builderId, IProgressMonitor monitor) 
		throws CoreException {
	IProjectDescription description = project.getDescription();
	ICommand[] buildSpec = description.getBuildSpec();
	for(ICommand command : buildSpec) {
		if(command.getBuilderName().equals(builderId)) {
			command.setBuilding(IncrementalProjectBuilder.AUTO_BUILD, false);
		}
	}
	description.setBuildSpec(buildSpec);
	project.setDescription(description, IResource.AVOID_NATURE_CONFIG, monitor);
}
 
Example 16
Source File: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
public static void addBuilder(IProject project, String builderId) throws CoreException {
	IProjectDescription description = project.getDescription();
	ICommand[] specs = description.getBuildSpec();
	ICommand command = description.newCommand();
	command.setBuilderName(builderId);
	// Add the nature
	ICommand[] specsModified = new ICommand[specs.length + 1];
	System.arraycopy(specs, 0, specsModified, 0, specs.length);
	specsModified[specs.length] = command;
	description.setBuildSpec(specsModified);
	project.setDescription(description, monitor());
}
 
Example 17
Source File: TypeScriptResourceUtil.java    From typescript.java with MIT License 5 votes vote down vote up
public static void addTypeScriptBuilder(IProject project) throws CoreException {
	IProjectDescription description = project.getDescription();
	ICommand[] commands = description.getBuildSpec();
	ICommand[] newCommands = new ICommand[commands.length + 1];
	System.arraycopy(commands, 0, newCommands, 0, commands.length);
	ICommand command = description.newCommand();
	command.setBuilderName(TypeScriptBuilder.ID);
	newCommands[newCommands.length - 1] = command;
	description.setBuildSpec(newCommands);
	project.setDescription(description, null);
}
 
Example 18
Source File: JReFrameworkerNature.java    From JReFrameworker with MIT License 5 votes vote down vote up
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(JReFrameworkerBuilder.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;
		}
	}
}
 
Example 19
Source File: CheckstyleNature.java    From eclipse-cs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * {@inheritDoc}
 */
@Override
public void configure() throws CoreException {

  //
  // Add the builder to the project.
  //
  IProjectDescription description = mProject.getDescription();
  ICommand[] commands = description.getBuildSpec();
  boolean found = false;
  for (int i = 0; i < commands.length; ++i) {
    if (commands[i].getBuilderName().equals(CheckstyleBuilder.BUILDER_ID)) {
      found = true;
      break;
    }
  }

  if (!found) {
    // add builder to project
    ICommand command = description.newCommand();
    command.setBuilderName(CheckstyleBuilder.BUILDER_ID);
    ICommand[] newCommands = new ICommand[commands.length + 1];

    // Add it after the other builders.
    System.arraycopy(commands, 0, newCommands, 0, commands.length);
    newCommands[commands.length] = command;
    description.setBuildSpec(newCommands);

    ensureProjectFileWritable();

    mProject.setDescription(description, null);
  }
}
 
Example 20
Source File: ResourceUtil.java    From APICloud-Studio with GNU General Public License v3.0 4 votes vote down vote up
/**
 * @param projectPath
 *            the project location
 * @param natureIds
 *            the list of required natures
 * @param builderIds
 *            the list of required builders
 * @return a project description for the project that includes the list of required natures and builders
 */
public static IProjectDescription getProjectDescription(IPath projectPath, String[] natureIds, String[] builderIds)
{
	if (projectPath == null)
	{
		return null;
	}

	IProjectDescription description = null;
	IPath dotProjectPath = projectPath.append(IProjectDescription.DESCRIPTION_FILE_NAME);
	File dotProjectFile = dotProjectPath.toFile();
	IWorkspace workspace = ResourcesPlugin.getWorkspace();
	if (dotProjectFile.exists())
	{
		// loads description from the existing .project file
		try
		{
			description = workspace.loadProjectDescription(dotProjectPath);
			if (Platform.getLocation().isPrefixOf(projectPath))
			{
				description.setLocation(null);
			}
		}
		catch (CoreException e)
		{
			IdeLog.logWarning(CorePlugin.getDefault(), "Failed to load the existing .project file.", e); //$NON-NLS-1$
		}
	}
	if (description == null)
	{
		// creates a new project description
		description = workspace.newProjectDescription(projectPath.lastSegment());
		if (Platform.getLocation().isPrefixOf(projectPath))
		{
			description.setLocation(null);
		}
		else
		{
			description.setLocation(projectPath);
		}
	}

	// adds the required natures to the project description
	if (!ArrayUtil.isEmpty(natureIds))
	{
		Set<String> natures = CollectionsUtil.newInOrderSet(natureIds);
		CollectionsUtil.addToSet(natures, description.getNatureIds());
		description.setNatureIds(natures.toArray(new String[natures.size()]));
	}

	// adds the required builders to the project description
	if (!ArrayUtil.isEmpty(builderIds))
	{
		ICommand[] existingBuilders = description.getBuildSpec();
		List<ICommand> builders = CollectionsUtil.newList(existingBuilders);
		for (String builderId : builderIds)
		{
			if (!hasBuilder(builderId, existingBuilders))
			{
				ICommand newBuilder = description.newCommand();
				newBuilder.setBuilderName(builderId);
				builders.add(newBuilder);
			}
		}
		description.setBuildSpec(builders.toArray(new ICommand[builders.size()]));
	}

	return description;
}