org.eclipse.core.resources.IProjectDescription Java Examples

The following examples show how to use org.eclipse.core.resources.IProjectDescription. 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: ProjectFactory.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
protected IProjectDescription createProjectDescription() {
	final IProjectDescription projectDescription = workspace.newProjectDescription(projectName);
	if (location != null && !Platform.getLocation().equals(location.removeLastSegments(1))) {
		projectDescription.setLocation(location);
	}

	if (referencedProjects != null && referencedProjects.size() != 0) {
		projectDescription
				.setReferencedProjects(referencedProjects.toArray(new IProject[referencedProjects.size()]));
	}
	if (projectNatures != null)
		projectDescription.setNatureIds(projectNatures.toArray(new String[projectNatures.size()]));
	if (builderIds != null)
		setBuilder(projectDescription, builderIds.toArray(new String[builderIds.size()]));
	return projectDescription;
}
 
Example #2
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 #3
Source File: IDEOpenSampleReportAction.java    From birt with Eclipse Public License 1.0 6 votes vote down vote up
private void create( IProjectDescription description,
		IProject projectHandle, IProgressMonitor monitor )
		throws CoreException, OperationCanceledException
{
	try
	{
		monitor.beginTask( "", 2000 );//$NON-NLS-1$
		projectHandle.create( description, new SubProgressMonitor( monitor,
				1000 ) );
		if ( monitor.isCanceled( ) )
			throw new OperationCanceledException( );
		projectHandle.open( new SubProgressMonitor( monitor, 1000 ) );

	}
	finally
	{
		monitor.done( );
	}
}
 
Example #4
Source File: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static void setReference(final IProject from, final IProject to)
		throws CoreException, InvocationTargetException,
		InterruptedException {
	new WorkspaceModifyOperation() {

		@Override
		protected void execute(IProgressMonitor monitor)
				throws CoreException, InvocationTargetException,
				InterruptedException {
			IProjectDescription projectDescription = from.getDescription();
			IProject[] projects = projectDescription
					.getReferencedProjects();
			IProject[] newProjects = new IProject[projects.length + 1];
			System.arraycopy(projects, 0, newProjects, 0, projects.length);
			newProjects[projects.length] = to;
			projectDescription.setReferencedProjects(newProjects);
			from.setDescription(projectDescription, monitor());
		}
	}.run(monitor());
}
 
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: IResourcesSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
public static void removeNature(IProject project, String nature)
		throws CoreException {
	IProjectDescription description = project.getDescription();
	String[] natures = description.getNatureIds();

	for (int i = 0; i < natures.length; ++i) {
		if (nature.equals(natures[i])) {
			// Remove the nature
			String[] newNatures = new String[natures.length - 1];
			System.arraycopy(natures, 0, newNatures, 0, i);
			System.arraycopy(natures, i + 1, newNatures, i, natures.length
					- i - 1);
			description.setNatureIds(newNatures);
			project.setDescription(description, null);
			return;
		}
	}

}
 
Example #7
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 #8
Source File: SARLProjectConfigurator.java    From sarl with Apache License 2.0 6 votes vote down vote up
@Override
public void unconfigure(IProject project, IProgressMonitor monitor) throws CoreException {
	try {
		final SubMonitor mon = SubMonitor.convert(monitor, 4);
		final IProjectDescription description = project.getDescription();
		final List<String> natures = new LinkedList<>(Arrays.asList(description.getNatureIds()));
		natures.remove(SARLEclipseConfig.XTEXT_NATURE_ID);
		natures.remove(SARLEclipseConfig.NATURE_ID);
		final String[] newNatures = natures.toArray(new String[natures.size()]);
		mon.worked(1);
		final IStatus status = ResourcesPlugin.getWorkspace().validateNatureSet(newNatures);
		mon.worked(1);
		if (status.getCode() == IStatus.OK) {
			description.setNatureIds(newNatures);
			project.setDescription(description, mon.newChild(1));
			safeRefresh(project, mon.newChild(1));
		} else {
			throw new CoreException(status);
		}
	} finally {
		monitor.done();
	}
}
 
Example #9
Source File: UserJavaProject.java    From CogniCrypt with Eclipse Public License 2.0 6 votes vote down vote up
/**
 * @param sourceProject The name of the project to be cloned
 * @param cloneName The name of the cloned project
 * @return a cloned project
 * @throws CoreException
 */

public static IProject cloneProject(final String sourceProject) throws CoreException {
	final IProgressMonitor m = new NullProgressMonitor();
	final IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
	final IProject project = workspaceRoot.getProject(sourceProject);
	final IProjectDescription projectDescription = project.getDescription();
	final String cloneName = sourceProject + "_copy";
	// create clone project in workspace
	final IProjectDescription cloneDescription = workspaceRoot.getWorkspace().newProjectDescription(cloneName);
	// copy project files
	project.copy(cloneDescription, true, m);
	final IProject clone = workspaceRoot.getProject(cloneName);
	// copy the project properties
	cloneDescription.setNatureIds(projectDescription.getNatureIds());
	cloneDescription.setReferencedProjects(projectDescription.getReferencedProjects());
	cloneDescription.setDynamicReferences(projectDescription.getDynamicReferences());
	cloneDescription.setBuildSpec(projectDescription.getBuildSpec());
	cloneDescription.setReferencedProjects(projectDescription.getReferencedProjects());
	clone.setDescription(cloneDescription, null);
	return clone;
}
 
Example #10
Source File: ResourceUtil.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Reurns a list of all the natures that belong to Aptana.
 * 
 * @param description
 * @return
 */
public static String[] getAptanaNatures(IProjectDescription description)
{
	String[] natures = description.getNatureIds();
	List<String> newNatures = new ArrayList<String>();
	// Add Aptana natures to list
	for (String nature : natures)
	{
		if (isAptanaNature(nature))
		{
			newNatures.add(nature);
		}
	}

	return newNatures.toArray(new String[newNatures.size()]);
}
 
Example #11
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 #12
Source File: JavaProject.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Removes the given builder from the build spec for the given project.
 */
protected void removeFromBuildSpec(String builderID) throws CoreException {

	IProjectDescription description = this.project.getDescription();
	ICommand[] commands = description.getBuildSpec();
	for (int i = 0; i < commands.length; ++i) {
		if (commands[i].getBuilderName().equals(builderID)) {
			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 #13
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 #14
Source File: RadlCreatorTest.java    From RADL with Apache License 2.0 6 votes vote down vote up
@Before
public void init() throws CoreException {
  IProjectDescription description = mock(IProjectDescription.class);
  when(description.getBuildSpec()).thenReturn(new ICommand[0]);
  when(description.newCommand()).thenReturn(mock(ICommand.class));
  when(description.getNatureIds()).thenReturn(natureIds.toArray(new String[natureIds.size()]));
  doAnswer(new Answer<Void>() {
    @Override
    public Void answer(InvocationOnMock invocation) throws Throwable {
      natureIds.clear();
      natureIds.addAll(Arrays.asList((String[])invocation.getArguments()[0]));
      return null;
    }
  }).when(description).setNatureIds(any(String[].class));
  when(project.getDescription()).thenReturn(description);
  when(folder.getProject()).thenReturn(project);
  when(folder.exists()).thenReturn(true);
  when(folder.getFile(anyString())).thenReturn(file);
  when(root.getFolder(new Path(folderName))).thenReturn(folder);
}
 
Example #15
Source File: Importer.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 6 votes vote down vote up
private void addHybrisNature(IProject project, IProgressMonitor monitor) throws CoreException {
	IProjectDescription description = project.getDescription();
	String[] natures = description.getNatureIds();

	for (int i = 0; i < natures.length; ++i) {
		if (HYBRIS_NATURE_ID.equals(natures[i])) {
			return;
		}
	}

	// Add the nature
	String[] newNatures = new String[natures.length + 1];
	System.arraycopy(natures, 0, newNatures, 0, natures.length);
	newNatures[natures.length] = HYBRIS_NATURE_ID;
	description.setNatureIds(newNatures);
	project.setDescription(description, monitor);
}
 
Example #16
Source File: CreateProjectOperation.java    From neoscada with Eclipse Public License 1.0 6 votes vote down vote up
protected void createProject ( final IProgressMonitor monitor ) throws CoreException
{
    monitor.beginTask ( "Create project", 2 );

    final IProject project = this.info.getProject ();

    final IProjectDescription desc = project.getWorkspace ().newProjectDescription ( project.getName () );
    desc.setLocation ( this.info.getProjectLocation () );
    desc.setNatureIds ( new String[] { Constants.PROJECT_NATURE_CONFIGURATION, PROJECT_NATURE_JS } );

    final ICommand jsCmd = desc.newCommand ();
    jsCmd.setBuilderName ( BUILDER_JS_VALIDATOR );

    final ICommand localBuilder = desc.newCommand ();
    localBuilder.setBuilderName ( Constants.PROJECT_BUILDER );

    desc.setBuildSpec ( new ICommand[] { jsCmd, localBuilder } );

    if ( !project.exists () )
    {
        project.create ( desc, new SubProgressMonitor ( monitor, 1 ) );
        project.open ( new SubProgressMonitor ( monitor, 1 ) );
    }
    monitor.done ();
}
 
Example #17
Source File: BuildPathsBlock.java    From Eclipse-Postfix-Code-Completion with Eclipse Public License 1.0 6 votes vote down vote up
public static void addJavaNature(IProject project, IProgressMonitor monitor) throws CoreException {
	if (monitor != null && monitor.isCanceled()) {
		throw new OperationCanceledException();
	}
	if (!project.hasNature(JavaCore.NATURE_ID)) {
		IProjectDescription description = project.getDescription();
		String[] prevNatures= description.getNatureIds();
		String[] newNatures= new String[prevNatures.length + 1];
		System.arraycopy(prevNatures, 0, newNatures, 0, prevNatures.length);
		newNatures[prevNatures.length]= JavaCore.NATURE_ID;
		description.setNatureIds(newNatures);
		project.setDescription(description, monitor);
	} else {
		if (monitor != null) {
			monitor.worked(1);
		}
	}
}
 
Example #18
Source File: SVNProjectSetCapability.java    From APICloud-Studio with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Creates a new project in the workbench from an existing one
 * 
 * @param monitor
 * @throws CoreException
 */

void createExistingProject(IProgressMonitor monitor)
        throws CoreException {
    String projectName = project.getName();
    IProjectDescription description;

    try {
        monitor.beginTask("Creating " + projectName, 2 * 1000);

        description = ResourcesPlugin.getWorkspace()
                .loadProjectDescription(
                        new Path(directory + File.separatorChar
                                + ".project")); //$NON-NLS-1$

        description.setName(projectName);
        project.create(description, new SubProgressMonitor(monitor,
                1000));
        project.open(new SubProgressMonitor(monitor, 1000));
    } finally {
        monitor.done();
    }
}
 
Example #19
Source File: MavenProjectImporterTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testPreexistingIProjectDifferentName() throws Exception {
	File from = new File(getSourceProjectDirectory(), "maven/salut");
	Path projectDir = Files.createTempDirectory("testImportDifferentName");

	IWorkspaceRoot wsRoot = WorkspaceHelper.getWorkspaceRoot();
	IWorkspace workspace = wsRoot.getWorkspace();
	String projectName = projectDir.getFileName().toString();
	IProject salut = wsRoot.getProject("salut");
	salut.delete(true, monitor);
	IProjectDescription description = workspace.newProjectDescription(projectName);
	description.setLocation(new org.eclipse.core.runtime.Path(projectDir.toFile().getAbsolutePath()));

	IProject project = wsRoot.getProject(projectName);
	project.create(description, monitor);


	assertTrue(WorkspaceHelper.getAllProjects().contains(project));

	FileUtils.copyDirectory(from, projectDir.toFile());

	assertTrue(project.exists());
	Job updateJob = projectsManager.updateWorkspaceFolders(Collections.singleton(new org.eclipse.core.runtime.Path(projectDir.toString())), Collections.emptySet());
	updateJob.join(20000, monitor);
	assertTrue("Failed to import preexistingProjectTest:\n" + updateJob.getResult().getException(), updateJob.getResult().isOK());
}
 
Example #20
Source File: ProjectAssert.java    From bonita-studio with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Verifies that the actual IProject's description is equal to the given one.
 *
 * @param description the given description to compare the actual IProject's description to.
 * @return this assertion object.
 * @throws CoreException
 * @throws AssertionError - if the actual IProject's description is not equal to the given one.
 */
public ProjectAssert hasDescription(final IProjectDescription description) throws CoreException, AssertionError {
    // check that actual IProject we want to make assertions on is not null.
    isNotNull();

    // we overrides the default error message with a more explicit one
    final String errorMessage = format("\nExpected <%s> description to be:\n  <%s>\n but was:\n  <%s>", actual, description, actual.getDescription());

    // check
    if (!actual.getDescription().equals(description)) {
        throw new AssertionError(errorMessage);
    }

    // return the current assertion for method chaining
    return this;
}
 
Example #21
Source File: NatureUtils.java    From xds-ide with Eclipse Public License 1.0 6 votes vote down vote up
public static void removeNature(IProject project, String nature) {
	try {
		IProjectDescription description = project.getDescription();
		String[] currentNatures = description.getNatureIds();

		int index = 0;
		for (int i = 0; i < currentNatures.length; i++) {
			if (nature.equals(currentNatures[i])) {
				index = i;
				break;
			}
		}

		if (index != -1) {
			String[] newNatures = new String[currentNatures.length - 1];
			System.arraycopy(currentNatures, 0, newNatures, 0, index);
			System.arraycopy(currentNatures, index + 1, newNatures, index,
					newNatures.length - index);
			description.setNatureIds(newNatures);
			project.setDescription(description, null);
		}
	} catch (CoreException e) {
		LogHelper.logError(e);
	}
}
 
Example #22
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 #23
Source File: ConfigureDeconfigureNatureJob.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Helper method to disable the given nature for the project.
 * 
 * @throws CoreException
 *           an error while removing the nature occured
 */
private void disableNature() throws CoreException {

  IProjectDescription desc = mProject.getDescription();
  String[] natures = desc.getNatureIds();

  // remove given nature from the array
  List<String> newNaturesList = new ArrayList<>();
  for (int i = 0; i < natures.length; i++) {
    if (!mNatureId.equals(natures[i])) {
      newNaturesList.add(natures[i]);
    }
  }

  String[] newNatures = newNaturesList.toArray(new String[newNaturesList.size()]);

  // set natures
  desc.setNatureIds(newNatures);
  mProject.setDescription(desc, mMonitor);
}
 
Example #24
Source File: ConfigureDeconfigureNatureJob.java    From eclipse-cs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Helper method to enable the given nature for the project.
 * 
 * @throws CoreException
 *           an error while setting the nature occured
 */
private void enableNature() throws CoreException {

  // get the description
  IProjectDescription desc = mProject.getDescription();

  // copy existing natures and add the nature
  String[] natures = desc.getNatureIds();

  String[] newNatures = new String[natures.length + 1];
  System.arraycopy(natures, 0, newNatures, 0, natures.length);
  newNatures[natures.length] = mNatureId;

  // set natures
  desc.setNatureIds(newNatures);
  mProject.setDescription(desc, mMonitor);
}
 
Example #25
Source File: FindBugsNature.java    From spotbugs with GNU Lesser General Public License v2.1 6 votes vote down vote up
/**
 * Removes the given builder from the build spec for the given project.
 */
protected void removeFromBuildSpec(String builderID) throws CoreException {
    MarkerUtil.removeMarkers(getProject());
    IProjectDescription description = getProject().getDescription();
    ICommand[] commands = description.getBuildSpec();
    for (int i = 0; i < commands.length; ++i) {
        if (commands[i].getBuilderName().equals(builderID)) {
            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 #26
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 #27
Source File: MDDProjectNature.java    From textuml with Eclipse Public License 1.0 5 votes vote down vote up
public void deconfigure() throws CoreException {
    // remove mdd builder
    IProjectDescription description = project.getDescription();
    ICommand[] oldCommands = description.getBuildSpec();
    ICommand[] newCommands = new ICommand[oldCommands.length - 1];
    for (int i = 0, j = 0; i < oldCommands.length; i++) {
        ICommand command = oldCommands[i];
        if (!UIConstants.BUILDER_ID.equals(command.getBuilderName())) {
            newCommands[j++] = oldCommands[i];
        }
    }
    description.setBuildSpec(newCommands);
    project.setDescription(description, null);
}
 
Example #28
Source File: TypeScriptResourceUtil.java    From typescript.java with MIT License 5 votes vote down vote up
/**
 * 
 * @param project
 * @return
 */
public static boolean hasTypeScriptBuilder(IProject project) {
	try {
		IProjectDescription description = project.getDescription();
		ICommand[] commands = description.getBuildSpec();
		for (int i = 0; i < commands.length; i++) {
			if (TypeScriptBuilder.ID.equals(commands[i].getBuilderName())) {
				return true;
			}
		}
	} catch (CoreException e) {
		return false;
	}
	return false;
}
 
Example #29
Source File: EnableSarlMavenNatureAction.java    From sarl with Apache License 2.0 5 votes vote down vote up
/** Create the configuration job for a Maven project.
 *
 * @param project the project to configure.
 * @return the job.
 */
@SuppressWarnings("static-method")
protected Job createJobForMavenProject(IProject project) {
	return new Job(Messages.EnableSarlMavenNatureAction_0) {

		@Override
		protected IStatus run(IProgressMonitor monitor) {
			final SubMonitor mon = SubMonitor.convert(monitor, 3);
			try {
				// The project should be a Maven project.
				final IPath descriptionFilename = project.getFile(new Path(IProjectDescription.DESCRIPTION_FILE_NAME)).getLocation();
				final File projectDescriptionFile = descriptionFilename.toFile();
				final IPath classpathFilename = project.getFile(new Path(FILENAME_CLASSPATH)).getLocation();
				final File classpathFile = classpathFilename.toFile();
				// Project was open by the super class. Close it because Maven fails when a project already exists.
				project.close(mon.newChild(1));
				// Delete the Eclipse project and classpath definitions because Maven fails when a project already exists.
				project.delete(false, true, mon.newChild(1));
				if (projectDescriptionFile.exists()) {
					projectDescriptionFile.delete();
				}
				if (classpathFile.exists()) {
					classpathFile.delete();
				}
				// Import
				MavenImportUtils.importMavenProject(
						project.getWorkspace().getRoot(),
						project.getName(),
						true,
						mon.newChild(1));
			} catch (CoreException exception) {
				SARLMavenEclipsePlugin.getDefault().log(exception);
			}
			return Status.OK_STATUS;
		}
	};
}
 
Example #30
Source File: ProjectTestUtil.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Returns the {@link ICommand} for the specified builder, or {@code null} if the builder does not
 * exist.
 */
public static ICommand getBuilder(IProject project, String builderId) throws CoreException {
  IProjectDescription description = project.getDescription();

  for (ICommand command : description.getBuildSpec()) {
    if (command.getBuilderName().equals(builderId)) {
      return command;
    }
  }
  return null;
}