Java Code Examples for org.eclipse.core.resources.ICommand#setBuilderName()

The following examples show how to use org.eclipse.core.resources.ICommand#setBuilderName() . 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: 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 2
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 3
Source File: ClientTemplate.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
private void createFeatureProject ( final IProject project, final Map<String, String> properties, final IProgressMonitor monitor ) throws CoreException
{
    monitor.beginTask ( "Creating feature project", 6 );

    final String name = this.pluginId + ".feature"; //$NON-NLS-1$
    final IProjectDescription desc = project.getWorkspace ().newProjectDescription ( name );

    final ICommand featureBuilder = desc.newCommand ();
    featureBuilder.setBuilderName ( "org.eclipse.pde.FeatureBuilder" ); //$NON-NLS-1$

    desc.setNatureIds ( new String[] { "org.eclipse.pde.FeatureNature" } ); //$NON-NLS-1$
    desc.setBuildSpec ( new ICommand[] {
            featureBuilder
    } );

    final IProject newProject = project.getWorkspace ().getRoot ().getProject ( name );
    newProject.create ( desc, new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1
    newProject.open ( new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1

    addFilteredResource ( newProject, "pom.xml", getResource ( "feature-pom.xml" ), "UTF-8", properties, new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1
    addFilteredResource ( newProject, "feature.xml", getResource ( "feature/feature.xml" ), "UTF-8", properties, new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1
    addFilteredResource ( newProject, "feature.properties", getResource ( "feature/feature.properties" ), "ISO-8859-1", properties, new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1
    addFilteredResource ( newProject, "build.properties", getResource ( "feature/build.properties" ), "ISO-8859-1", properties, new SubProgressMonitor ( monitor, 1 ) ); // COUNT:1

    monitor.done ();
}
 
Example 4
Source File: JReFrameworkerNature.java    From JReFrameworker with MIT License 6 votes vote down vote up
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(JReFrameworkerBuilder.BUILDER_ID)) {
			return;
		}
	}

	ICommand[] newCommands = new ICommand[commands.length + 1];
	System.arraycopy(commands, 0, newCommands, 0, commands.length);
	ICommand command = desc.newCommand();
	command.setBuilderName(JReFrameworkerBuilder.BUILDER_ID);
	newCommands[newCommands.length - 1] = command;
	desc.setBuildSpec(newCommands);
	project.setDescription(desc, null);
}
 
Example 5
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 6
Source File: JReFrameworkerProject.java    From JReFrameworker with MIT License 6 votes vote down vote up
public void enableJavaBuilder() throws CoreException {
	IProjectDescription desc = project.getDescription();
	ICommand[] commands = desc.getBuildSpec();
	// if the command already exists, don't add it again
	for (int i = 0; i < commands.length; ++i) {
		if (commands[i].getBuilderName().equals(JavaCore.BUILDER_ID)) {
			return;
		}
	}
	ICommand[] newCommands = new ICommand[commands.length + 1];
	System.arraycopy(commands, 0, newCommands, 0, commands.length);
	ICommand command = desc.newCommand();
	command.setBuilderName(JavaCore.BUILDER_ID);
	newCommands[newCommands.length - 1] = command;
	
	if(!command1PreceedsCommand2(JavaCore.BUILDER_ID, JReFrameworkerBuilder.BUILDER_ID, newCommands)){
		swapBuildCommands(JavaCore.BUILDER_ID, JReFrameworkerBuilder.BUILDER_ID, newCommands);
	}
	
	desc.setBuildSpec(newCommands);
	project.setDescription(desc, null);
}
 
Example 7
Source File: BuilderUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Adds a builder with the specified ID to the project if the project does not
 * already have the builder.
 * 
 * @param project project to add the builder to
 * @param builderId id of the builder to add
 * @throws CoreException
 */
public static void addBuilderToProject(IProject project, String builderId)
    throws CoreException {

  if (hasBuilder(project, builderId)) {
    return;
  }

  IProjectDescription description = project.getDescription();
  List<ICommand> builders = new ArrayList<ICommand>(
      Arrays.asList(description.getBuildSpec()));

  ICommand newBuilder = description.newCommand();
  newBuilder.setBuilderName(builderId);
  builders.add(newBuilder);

  description.setBuildSpec(builders.toArray(new ICommand[builders.size()]));
  project.setDescription(description, null);
}
 
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: 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 10
Source File: ProjectFactory.java    From xtext-eclipse with Eclipse Public License 2.0 5 votes vote down vote up
protected void setBuilder(final IProjectDescription projectDescription, final String[] builders) {
	List<ICommand> commands = Lists.newArrayList();
	for (int i = 0; i < builders.length; i++) {
		ICommand command = projectDescription.newCommand();
		command.setBuilderName(builders[i]);
		commands.add(command);
	}
	projectDescription.setBuildSpec(commands.toArray(new ICommand[commands.size()]));
}
 
Example 11
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 12
Source File: FindBugsNature.java    From spotbugs with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Adds a builder to the build spec for the given project.
 */
protected void addToBuildSpec(String builderID) throws CoreException {
    IProjectDescription description = getProject().getDescription();
    ICommand findBugsCommand = getFindBugsCommand(description);
    if (findBugsCommand == null) {
        // Add a Java command to the build spec
        ICommand newCommand = description.newCommand();
        newCommand.setBuilderName(builderID);
        setFindBugsCommand(description, newCommand);
    }
}
 
Example 13
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 14
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 15
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 16
Source File: RadlNatureTest.java    From RADL with Apache License 2.0 5 votes vote down vote up
@Test
public void deconfigureRemovesBuilderWhenPresent() throws CoreException {
  ICommand command = new Command();
  command.setBuilderName(RadlBuilder.BUILDER_ID);
  commands.add(command);
  init();

  nature.deconfigure();

  assertBuilder(false);
}
 
Example 17
Source File: IDEOpenSampleReportAction.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 18
Source File: MDDProjectNature.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void configure() throws CoreException {
    // add mdd builder
    IProjectDescription description = project.getDescription();
    ICommand command = description.newCommand();
    command.setBuilderName(UIConstants.BUILDER_ID);
    description.setBuildSpec(new ICommand[] { command });
    project.setDescription(description, null);
}
 
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: AddTypeScriptBuilderHandler.java    From typescript.java with MIT License 5 votes vote down vote up
@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
	ISelection selection = HandlerUtil.getCurrentSelection(event);
	if (selection != null && selection instanceof IStructuredSelection) {
		for (Object obj : ((IStructuredSelection) selection).toList()) {
			if (obj instanceof IAdaptable) {
				IProject project = (IProject) ((IAdaptable) obj).getAdapter(IProject.class);
				if (project != null) {
					try {
						if (TypeScriptResourceUtil.hasTypeScriptBuilder(project)) {
							return null;
						}
						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);

					} catch (CoreException e) {
						throw new ExecutionException(e.getMessage(), e);
					}
				}
			}

		}
	}
	return null;
}