Java Code Examples for org.eclipse.core.resources.IProject#close()

The following examples show how to use org.eclipse.core.resources.IProject#close() . 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: Bug334456Test.java    From xtext-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
@Test public void testSameResourceCountForTwoProjects() throws Exception {
	IProject fooProject = createPluginProject("foo");
	build();
	IResourceDescriptions descriptions = BuilderUtil.getBuilderState();
	int firstSize = Iterables.size(descriptions.getAllResourceDescriptions());
	IProject barProject = createPluginProject("bar");
	build();
	descriptions = BuilderUtil.getBuilderState();
	int secondSize = Iterables.size(descriptions.getAllResourceDescriptions());
	assertEquals(firstSize, secondSize);
	barProject.close(null);
	build();
	descriptions = BuilderUtil.getBuilderState();
	int thirdSize = Iterables.size(descriptions.getAllResourceDescriptions());
	assertEquals(firstSize, thirdSize);
	fooProject.close(null);
	build();
	descriptions = BuilderUtil.getBuilderState();
	int forthSize = Iterables.size(descriptions.getAllResourceDescriptions());
	// no remaining references to archives - fewer entries in index
	assertTrue(firstSize > forthSize);
}
 
Example 2
Source File: MavenProjectImporterTest.java    From eclipse.jdt.ls with Eclipse Public License 2.0 6 votes vote down vote up
@Test
public void testInvalidProject() throws Exception {
	List<IProject> projects = importProjects(MAVEN_INVALID);
	assertEquals(2, projects.size());
	IProject invalid = WorkspaceHelper.getProject(INVALID);
	assertIsMavenProject(invalid);
	IFile projectFile = invalid.getFile("/.project");
	assertTrue(projectFile.exists());
	File file = projectFile.getRawLocation().makeAbsolute().toFile();
	invalid.close(new NullProgressMonitor());
	assertTrue(file.exists());
	file.delete();
	assertFalse(file.exists());
	projects = importProjects(MAVEN_INVALID);
	assertEquals(2, projects.size());
	invalid = WorkspaceHelper.getProject(INVALID);
	assertIsMavenProject(invalid);
}
 
Example 3
Source File: ProjectCustomizer.java    From uima-uimaj with Apache License 2.0 6 votes vote down vote up
/**
 * Adds the UIMA nature to a project
 * 
 * @param project
 *          an IProject
 * @throws PearException
 *           If a problem occurs
 */
public static void addUIMANature(IProject project) throws PearException {
  try {
    if (!project.hasNature(UIMA_NATURE_ID)) {
      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] = UIMA_NATURE_ID;
      description.setNatureIds(newNatures);
      project.setDescription(description, null);
      project.close(null);
      project.open(null);
    }
  } catch (Throwable e) {
    PearException subEx = new PearException("The UIMA Nature could not be added properly.", e);
    throw subEx;
  }
}
 
Example 4
Source File: LocalAppEnginePublishOperationTest.java    From google-cloud-eclipse with Apache License 2.0 5 votes vote down vote up
private void reopenProjects() throws CoreException {
  for (IProject project : projects) {
    project.close(null);
    project.open(null);
  }
  ProjectUtils.waitForProjects(projects);
  serverModule = ServerUtil.getModule(serverProject);
  sharedModule = ServerUtil.getModule(sharedProject);
}
 
Example 5
Source File: Importer.java    From hybris-commerce-eclipse-plugin with Apache License 2.0 5 votes vote down vote up
private void closeProjectsThatAreNotReferenced(IProgressMonitor monitor, File platformHome) throws CoreException {
	if (DEBUG)
		Activator.log("Retrieving projects not in localextensions using platformhome [" + platformHome.getAbsolutePath() + "]");
	Set<IProject> projectsToClose = FixProjectsUtils.getProjectsNotInLocalExtensionsFile(platformHome.getAbsolutePath());

	// close projects from the above set that are not referenced by a
	// project that is not scheduled for closing
	if (projectsToClose != null) {
		for (IProject projectToClose : projectsToClose) {

			// check if this project is a dependency of another project that
			// is not scheduled to be closed
			IProject[] referencingProjects = projectToClose.getReferencingProjects();
			boolean abortClose = false;
			if (referencingProjects != null) {
				for (IProject proj : referencingProjects) {
					if (!projectsToClose.contains(proj)) {
						if (DEBUG)
							Activator.log("Aborting close of project [" + projectToClose.getName() + "] because it is referenced by [" + proj.getName() + "]");
						abortClose = true;
					}
				}
			}

			// close projects
			if (!abortClose) {
				if (DEBUG)
					Activator.log("Closing project [" + projectToClose.getName() + "]");
				projectToClose.close(monitor);
			}
		}
	}
}
 
Example 6
Source File: DynamicWorkingSetUpdaterPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testCloseMatchingProject() throws CoreException {
  setWorkingSetPattern( ANYTHING );
  workingSetManager.addWorkingSet( workingSet );
  IProject project = projectHelper.getProject();

  project.close( new NullProgressMonitor() );

  assertThat( workingSet.getElements() ).containsOnly( project );
}
 
Example 7
Source File: DynamicWorkingSetUpdaterPDETest.java    From eclipse-extras with Eclipse Public License 1.0 5 votes vote down vote up
@Test
public void testAddWorkingSetWithClosedProject() throws CoreException {
  IProject project = projectHelper.getProject();
  project.close( new NullProgressMonitor() );

  setWorkingSetPattern( ANYTHING );
  workingSetManager.addWorkingSet( workingSet );

  assertThat( workingSet.getElements() ).containsOnly( project );
}
 
Example 8
Source File: AbstractGWTPluginTestCase.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
private void closeProject(String projectName) throws CoreException {
  IProject project = Util.getWorkspaceRoot().getProject(projectName);
  if (project.exists() && project.isOpen()) {
    project.close(null);
    JobsUtilities.waitForIdle();
  }
}
 
Example 9
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 10
Source File: Bug386476Test.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
private void stimulateBuildSchedulerTrigger(IProject project) throws CoreException {
	project.close(monitor());
	build();
	project.open(monitor());
	build();
}
 
Example 11
Source File: ProjectUtils.java    From XPagesExtensionLibrary with Apache License 2.0 4 votes vote down vote up
public static void closeAndDeleteProject(final IProject project, final boolean delete) throws Exception {
    project.close(null);
    if (delete) {
        project.delete(true, true, null);
    }
}