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

The following examples show how to use org.eclipse.core.resources.IProjectDescription#setBuildSpec() . 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: TexlipseNature.java    From texlipse with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Add a builder to the project.
 * 
 * @param id id of the builder to add
 * @throws CoreException
 */
private void addBuilder(String id) throws CoreException {

    IProjectDescription desc = project.getDescription();
    ICommand[] commands = desc.getBuildSpec();

    if (!hasBuilder(commands, id)) {

        ICommand command = desc.newCommand();
        command.setBuilderName(id);
        ICommand[] newCommands = new ICommand[commands.length + 1];

        System.arraycopy(commands, 0, newCommands, 1, commands.length);
        newCommands[0] = command;
        desc.setBuildSpec(newCommands);

        project.setDescription(desc, null);
    }
}
 
Example 2
Source File: XtextNature.java    From xtext-eclipse with Eclipse Public 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(XtextBuilder.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);			
			project.deleteMarkers(MarkerTypes.ANY_VALIDATION, true, IResource.DEPTH_INFINITE);
			return;
		}
	}
}
 
Example 3
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 4
Source File: ProblemMarkerNature.java    From CogniCrypt with Eclipse Public License 2.0 6 votes vote down vote up
@Override
public void configure() throws CoreException {
	final IProjectDescription desc = this.project.getDescription();
	final ICommand[] commands = desc.getBuildSpec();

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

	final ICommand[] newCommands = new ICommand[commands.length + 1];
	System.arraycopy(commands, 0, newCommands, 0, commands.length);
	final ICommand command = desc.newCommand();
	command.setBuilderName(Constants.BUILDER_ID);
	newCommands[newCommands.length - 1] = command;
	desc.setBuildSpec(newCommands);
	this.project.setDescription(desc, null);
}
 
Example 5
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 6
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 7
Source File: ProjectUtils.java    From developer-studio with Apache License 2.0 6 votes vote down vote up
public static void addBuildSpecificationsToProject(IProject project, String...buildCommandList) throws CoreException{
		IProjectDescription description = project.getDescription();
		ICommand[] buildSpecifications = new BuildCommand[buildCommandList.length];
		
		int i = 0;
		for (ICommand buildCommand : buildSpecifications) {
			buildCommand = new BuildCommand();
			buildCommand.setBuilderName(buildCommandList[i]);
			buildSpecifications[i] = buildCommand;
			i++;
		}
		
		
//		int i = 0;
//		for (String buildCommand : buildCommandList) {
//			new bui
//			buildSpecifications[i].setBuilderName(buildCommand);
//			i++;
//		}
		
		description.setBuildSpec(buildSpecifications);
		project.setDescription(description, null);
	}
 
Example 8
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 9
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 10
Source File: JReFrameworker.java    From JReFrameworker with MIT License 6 votes vote down vote up
private static IJavaProject createProject(String projectName, IPath projectPath, IProject project, IProgressMonitor monitor) throws CoreException {
	IProjectDescription projectDescription = project.getWorkspace().newProjectDescription(project.getName());
	URI location = getProjectLocation(projectName, projectPath);
	projectDescription.setLocationURI(location);
	
	// make this a JReFrameworker project
	projectDescription.setNatureIds(new String[] { JReFrameworkerNature.NATURE_ID, JavaCore.NATURE_ID });

	// build first with Java compiler then JReFramewoker bytecode operations
	BuildCommand javaBuildCommand = new BuildCommand();
	javaBuildCommand.setBuilderName(JavaCore.BUILDER_ID);
	BuildCommand jrefBuildCommand = new BuildCommand();
	jrefBuildCommand.setBuilderName(JReFrameworkerBuilder.BUILDER_ID);
	projectDescription.setBuildSpec(new ICommand[]{ javaBuildCommand, jrefBuildCommand});

	// create and open the Eclipse project
	project.create(projectDescription, null);
	IJavaProject jProject = JavaCore.create(project);
	project.open(new NullProgressMonitor());
	return jProject;
}
 
Example 11
Source File: JReFrameworkerProject.java    From JReFrameworker with MIT License 5 votes vote down vote up
public void disableJavaBuilder() throws CoreException {
	IProjectDescription description = getProject().getDescription();
	ICommand[] commands = description.getBuildSpec();
	for (int i = 0; i < commands.length; ++i) {
		// if the command exists, remove it
		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);
			project.setDescription(description, null);			
			return;
		}
	}
}
 
Example 12
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 13
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 14
Source File: RadlNature.java    From RADL with Apache License 2.0 5 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 (RadlBuilder.BUILDER_ID.equals(commands[i].getBuilderName())) {
      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;
    }
  }
}
 
Example 15
Source File: TypeScriptResourceUtil.java    From typescript.java with MIT License 5 votes vote down vote up
public static void removeTypeScriptBuilder(IProject project) throws CoreException {
	IProjectDescription description = project.getDescription();
	ICommand[] commands = description.getBuildSpec();
	for (int i = 0; i < commands.length; i++) {
		if (TypeScriptBuilder.ID.equals(commands[i].getBuilderName())) {
			// Remove the builder
			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);
		}
	}
}
 
Example 16
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 17
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 18
Source File: NewReportProjectWizard.java    From birt with Eclipse Public License 1.0 5 votes vote down vote up
private void addJavaBuildSpec( IProjectDescription description )
{
	ICommand command = description.newCommand( );
	command.setBuilderName( JavaCore.BUILDER_ID );
	description.setBuildSpec( new ICommand[]{
		command
	} );
}
 
Example 19
Source File: AddDotnetBuilder.java    From aCute with Eclipse Public License 2.0 5 votes vote down vote up
@Override
public Object execute(final ExecutionEvent event) {
	final IProject project = getProject(event);

	if (project != null) {
		try {
			if (hasBuilder(project)) {
				return null;
			}

			IProjectDescription description = project.getDescription();
			final ICommand buildCommand = description.newCommand();
			buildCommand.setBuilderName(IncrementalDotnetBuilder.BUILDER_ID);

			final List<ICommand> commands = new ArrayList<>();
			commands.addAll(Arrays.asList(description.getBuildSpec()));
			commands.add(buildCommand);

			description.setBuildSpec(commands.toArray(new ICommand[commands.size()]));
			project.setDescription(description, null);

		} catch (final CoreException e) {
		}
	}

	return null;
}
 
Example 20
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 deconfigure() throws CoreException {

  //
  // Remove the builder from the project.
  //
  IProjectDescription description = mProject.getDescription();
  ICommand[] commands = description.getBuildSpec();
  List<ICommand> newCommandsVec = new ArrayList<>();
  for (int i = 0; i < commands.length; ++i) {
    if (commands[i].getBuilderName().equals(CheckstyleBuilder.BUILDER_ID)) {
      continue;
    } else {
      newCommandsVec.add(commands[i]);
    }
  }

  ICommand[] newCommands = newCommandsVec.toArray(new ICommand[newCommandsVec.size()]);
  description.setBuildSpec(newCommands);

  ensureProjectFileWritable();

  mProject.setDescription(description, new NullProgressMonitor());

  // remove checkstyle markers from the project
  getProject().deleteMarkers(CheckstyleMarker.MARKER_ID, true, IResource.DEPTH_INFINITE);

}