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

The following examples show how to use org.eclipse.core.resources.IProjectDescription#newCommand() . 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: 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 2
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 3
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 4
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 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: 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 7
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 8
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 9
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;
}
 
Example 10
Source File: JavaProject.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 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 = this.project.getDescription();
	int javaCommandIndex = getJavaCommandIndex(description.getBuildSpec());

	if (javaCommandIndex == -1) {

		// Add a Java command to the build spec
		ICommand command = description.newCommand();
		command.setBuilderName(builderID);
		setJavaCommand(description, command);
	}
}
 
Example 11
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 12
Source File: AddBuilder.java    From uml2solidity with Eclipse Public License 1.0 5 votes vote down vote up
@Override
public Object execute(final ExecutionEvent event) {
	final IProject project = getProject(event);

	if (project != null) {
		try {
			// verify already registered builders
			if (hasBuilder(project))
				// already enabled
				return null;

			// add builder to project properties
			IProjectDescription description = project.getDescription();
			final ICommand buildCommand = description.newCommand();
			buildCommand.setBuilderName(SolidityBuilder.BUILDER_ID);

			final List<ICommand> commands = new ArrayList<ICommand>();
			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) {
			Activator.logError("Error adding solc builder", e);
		}
	}
	return null;
}
 
Example 13
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 14
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 15
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 16
Source File: CrySLBuilderUtils.java    From CogniCrypt with Eclipse Public License 2.0 5 votes vote down vote up
public static void addCrySLBuilderToProject(IProject project) {
	try {
		IProjectDescription description = project.getDescription();
		String[] natures = description.getNatureIds();
		String[] newNatures = new String[natures.length + 1];
		System.arraycopy(natures, 0, newNatures, 0, natures.length);
		newNatures[natures.length] = CrySLNature.NATURE_ID;

		// validate the natures
		IWorkspace workspace = ResourcesPlugin.getWorkspace();
		IStatus status = workspace.validateNatureSet(newNatures);

		// only apply new nature, if the status is ok
		if (status.getCode() == IStatus.OK) {
			description.setNatureIds(newNatures);
		}

		ICommand[] buildSpec = description.getBuildSpec();
		ICommand command = description.newCommand();
		command.setBuilderName(CrySLBuilder.BUILDER_ID);
		ICommand[] newbuilders = new ICommand[buildSpec.length + 1];
		System.arraycopy(buildSpec, 0, newbuilders, 0, buildSpec.length);
		newbuilders[buildSpec.length] = command;
		description.setBuildSpec(newbuilders);
		project.setDescription(description, null);
	}
	catch (CoreException e) {
		Activator.getDefault().logError(e);
	}
}
 
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: MockJavaProjectProvider.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public static IJavaProject createJavaProject(
		final String projectName, 
		String[] projectNatures) {

	IProject project = null;
	IJavaProject javaProject = null;
	try {
		project = IResourcesSetupUtil.root().getProject(projectName);
		deleteProject(project);

		javaProject = JavaCore.create(project);
		IProjectDescription projectDescription = ResourcesPlugin.getWorkspace().newProjectDescription(
				projectName);
		project.create(projectDescription, null);
		List<IClasspathEntry> classpathEntries = new ArrayList<IClasspathEntry>();
		projectDescription.setNatureIds(projectNatures);

		final ICommand java = projectDescription.newCommand();
		java.setBuilderName(JavaCore.BUILDER_ID);

		final ICommand manifest = projectDescription.newCommand();
		manifest.setBuilderName("org.eclipse.pde.ManifestBuilder");

		final ICommand schema = projectDescription.newCommand();
		schema.setBuilderName("org.eclipse.pde.SchemaBuilder");

		projectDescription.setBuildSpec(new ICommand[] { java, manifest, schema });

		project.open(null);
		project.setDescription(projectDescription, null);

		classpathEntries.add(JavaCore.newContainerEntry(new Path("org.eclipse.pde.core.requiredPlugins")));

		javaProject.setRawClasspath(classpathEntries.toArray(new IClasspathEntry[classpathEntries.size()]),
				null);
		JavaProjectSetupUtil.addJreClasspathEntry(javaProject);
		
		makeJava8Compliant(javaProject);

		javaProject.setOutputLocation(new Path("/" + projectName + "/bin"), null);
		createManifest(projectName, project);

		refreshExternalArchives(javaProject);
		refresh(javaProject);
	}
	catch (final Exception exception) {
		throw new RuntimeException(exception);
	}
	return javaProject ;
}
 
Example 19
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;
}
 
Example 20
Source File: TLANature.java    From tlaplus with MIT License 4 votes vote down vote up
/**
 * add TLA nature
 */
public void configure() throws CoreException
{
    IProjectDescription desc = project.getDescription();
    ICommand[] commands = desc.getBuildSpec();

    boolean tlaBuilderFound = false;
    boolean pcalBuilderFound = false;
    int numberOfBuildersToInstall = 1;
    
    
    for (int i = 0; i < commands.length; ++i) {
        String builderName = commands[i].getBuilderName();
        if (builderName.equals(TLAParsingBuilder.BUILDER_ID)) 
        {
            tlaBuilderFound = true;
            numberOfBuildersToInstall--;
        }
        
        if (tlaBuilderFound && pcalBuilderFound) 
        {
            return;
        }
    }

    ICommand[] newCommands = new ICommand[commands.length + numberOfBuildersToInstall];
    System.arraycopy(commands, 0, newCommands, 0, commands.length);
    
    int position = commands.length;
    
    if (!tlaBuilderFound) 
    {
        ICommand command = desc.newCommand();
        command.setBuilderName(TLAParsingBuilder.BUILDER_ID);
        newCommands[position] = command;
        position++;
    }
    
    desc.setBuildSpec(newCommands);
    project.setDescription(desc, null);
    Activator.getDefault().logDebug("Nature added");
}