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

The following examples show how to use org.eclipse.core.resources.IProject#delete() . 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: CodewindEclipseApplication.java    From codewind-eclipse with Eclipse Public License 2.0 6 votes vote down vote up
private void deleteProject() {
	Job job = new Job(NLS.bind(Messages.DeleteProjectJobLabel, name)) {
		@Override
		protected IStatus run(IProgressMonitor monitor) {
			try {
				IProject project = CoreUtil.getEclipseProject(CodewindEclipseApplication.this);
				if (project != null) {
					project.delete(true, true, monitor);
				} else if (fullLocalPath.toFile().exists()) {
					FileUtil.deleteDirectory(fullLocalPath.toOSString(), true);
				} else {
					Logger.log("No project contents were found to delete for application: " + name);
				}
			} catch (Exception e) {
				Logger.logError("Error deleting project contents: " + name, e); //$NON-NLS-1$
				return new Status(IStatus.ERROR, CodewindCorePlugin.PLUGIN_ID, NLS.bind(Messages.DeleteProjectError, name), e);
			}
			if (monitor.isCanceled()) {
				return Status.CANCEL_STATUS;
			}
			return Status.OK_STATUS;
		}
	};
	job.schedule();
}
 
Example 2
Source File: ProjectTestUtil.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Creates a simple project.
 *
 * @param projectName the name of the project
 * @param natureIds an array of natures IDs to set on the project, or {@code null} if none should
 *        be set
 * @return the created project
 * @throws CoreException if the project is not created
 */
public static IProject createSimpleProject(String projectName, String... natureIds)
    throws CoreException {
  IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(projectName);
  if (project.exists()) {
    project.delete(true, true, npm());
  }
  project.create(npm());
  project.open(npm());
  if (natureIds != null) {
    IProjectDescription desc = project.getDescription();
    desc.setNatureIds(natureIds);
    project.setDescription(desc, npm());
  }
  return project;
}
 
Example 3
Source File: ImportedProjectNamePluginTest.java    From n4js with Eclipse Public License 1.0 6 votes vote down vote up
/**
 * Tests the following project name configuration.
 *
 * <pre>
 * File System: 	eclipse-file-other-system
 * Package.json: 	eclipse-file-system
 * Eclipse: 		eclipse-system
 * </pre>
 */
@Test
public void testDifferentFileSystemAndEclipseName() throws CoreException {
	// workspace setup
	final IProject testProject = ProjectTestsUtils.createProjectWithLocation(projectsRoot,
			"eclipse-file-other-system", "eclipse-system");
	configureProjectWithXtext(testProject);
	waitForAutoBuild();

	// obtain package.json resource
	final IResource packageJsonResource = testProject.findMember(IN4JSProject.PACKAGE_JSON);

	// assert project name markers
	assertHasMarker(packageJsonResource, IssueCodes.PKGJ_PACKAGE_NAME_MISMATCH);
	assertHasMarker(packageJsonResource, IssueCodes.PKGJ_PROJECT_NAME_ECLIPSE_MISMATCH);

	// tear down
	testProject.delete(false, true, new NullProgressMonitor());
}
 
Example 4
Source File: TestAutoClosing.java    From tm4e with Eclipse Public License 1.0 5 votes vote down vote up
@After
public void tearDown() throws Exception {
	PlatformUI.getWorkbench().getActiveWorkbenchWindow().getActivePage().closeAllEditors(false);
	for (IProject p : ResourcesPlugin.getWorkspace().getRoot().getProjects()) {
		p.delete(true, null);
	}
}
 
Example 5
Source File: TestRunConfiguration.java    From corrosion with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testFailOnDeletedProject() throws IOException, CoreException {
	IProject project = getProject(BASIC_PROJECT_NAME);
	ILaunchConfigurationWorkingCopy launchConfiguration = createLaunchConfiguration(project);
	project.delete(true, new NullProgressMonitor());
	confirmErrorPopup(launchConfiguration);
}
 
Example 6
Source File: XtextTestProjectManager.java    From dsl-devkit with Eclipse Public License 1.0 5 votes vote down vote up
/** {@inheritDoc} */
@Override
public void teardown() {
  testSources.clear();
  IProject project = ResourcesPlugin.getWorkspace().getRoot().getProject(TEST_PROJECT_NAME);
  if (project != null && project.exists()) {
    try {
      project.delete(true, true, new NullProgressMonitor());
    } catch (CoreException e) {
      throw new WrappedException(e);
    }
  }
}
 
Example 7
Source File: JReFrameworker.java    From JReFrameworker with MIT License 5 votes vote down vote up
public static IStatus deleteProject(IProject project) {
	if (project != null && project.exists())
		try {
			project.delete(true, true, new NullProgressMonitor());
		} catch (CoreException e) {
			Log.error("Could not delete project", e);
			return new Status(Status.ERROR, Activator.PLUGIN_ID, "Could not delete project", e);
		}
	return Status.OK_STATUS;
}
 
Example 8
Source File: TestWizardUI.java    From aCute with Eclipse Public License 2.0 5 votes vote down vote up
@Test
public void testPresetFolderNameCreation() throws CoreException {
	SWTBotShell shell = openWizard();
	String firstPresetName = bot.textWithLabel("Project name").getText();
	IProject newProject = checkProjectCreate(shell, null);
	bot.closeAllEditors();

	shell = openWizard();
	String secondPresetName = bot.textWithLabel("Project name").getText();

	assertNotEquals("Pre-set project name is not unique from currently created project", firstPresetName, secondPresetName);

	bot.button("Cancel").click();
	newProject.delete(true, true, new NullProgressMonitor());
}
 
Example 9
Source File: ProjectArtifactHandler.java    From developer-studio with Apache License 2.0 5 votes vote down vote up
protected void clearProject(IProject project) {
	try {
		project.delete(true, nullProgressMonitor);
	} catch (CoreException e) {
		log.error(e.getMessage(), e);
	}
}
 
Example 10
Source File: AbstractGWTPluginTestCase.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
@Override
protected void tearDown() throws Exception {
  super.tearDown();

  IProject project = Util.getWorkspaceRoot().getProject(TEST_PROJECT_NAME);
  if (project.exists()) {
    project.delete(true, true, null);
    JobsUtilities.waitForIdle();
  }
}
 
Example 11
Source File: ProjectTestUtilities.java    From gwt-eclipse-plugin with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Deletes the project with the given name.
 * 
 * @throws CoreException
 */
public static void deleteProject(String projectName) throws CoreException {
  IWorkspaceRoot workspaceRoot = ResourcesPlugin.getWorkspace().getRoot();
  IProject project = workspaceRoot.getProject(projectName);
  if (!project.exists()) {
    throw new IllegalStateException("Project " + projectName
        + " does not exist in this workspace");
  }

  project.delete(true, new NullProgressMonitor());
}
 
Example 12
Source File: AbstractBuilderTest.java    From n4js with Eclipse Public License 1.0 5 votes vote down vote up
private static void deleteProjects(final IProject[] projects, StringBuilder error) {
	for (final IProject project : projects) {
		if (project.exists()) {
			try {
				project.delete(true, true, new NullProgressMonitor());
			} catch (CoreException e) {
				error.append(e.getMessage());
			}
		}
	}
}
 
Example 13
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 14
Source File: AbstractJavaGeneratorTest.java    From statecharts with Eclipse Public License 1.0 5 votes vote down vote up
public IMarker[] generateAndCompile(Statechart statechart) throws Exception {
	GeneratorEntry entry = createGeneratorEntry(statechart.getName(), SRC_GEN);
	entry.setElementRef(statechart);
	IProject targetProject = getProject(entry);
	targetProject.delete(true, new NullProgressMonitor());
	targetProject = getProject(entry);
	if (!targetProject.exists()) {
		targetProject.create(new NullProgressMonitor());
		targetProject.open(new NullProgressMonitor());
	}
	IGeneratorEntryExecutor executor = new EclipseContextGeneratorExecutorLookup() {
		protected Module getContextModule() {
			return Modules.override(super.getContextModule()).with(new Module() {
				@Override
				public void configure(Binder binder) {
					binder.bind(IConsoleLogger.class).to(TestLogger.class);
				}
			});
		};
	}.createExecutor(entry, "yakindu::java");
	executor.execute(entry);
	targetProject.refreshLocal(IResource.DEPTH_INFINITE, null);
	targetProject.getWorkspace().build(IncrementalProjectBuilder.INCREMENTAL_BUILD, null);
	targetProject.build(IncrementalProjectBuilder.INCREMENTAL_BUILD, new NullProgressMonitor());
	IMarker[] markers = targetProject.findMarkers(IJavaModelMarker.JAVA_MODEL_PROBLEM_MARKER, true,
			IResource.DEPTH_INFINITE);
	return markers;
}
 
Example 15
Source File: ProjectCacheInvalidationPluginTest.java    From n4js with Eclipse Public License 1.0 4 votes vote down vote up
/**
 * Updates two project description files in the workspace within one atomic workspace operation, resulting in a
 * single {@link IResourceChangeEvent} that notifies clients of both modifications.
 *
 * Asserts that the {@link EclipseBasedN4JSWorkspace} correctly invalidates its cache for both projects and
 * correctly reflects the changes of both project description files.
 */
@Test
public void testMultipleProjectDescriptionChanges() throws CoreException {
	// test case constants
	final String updatedImplementationId1 = "updated1";
	final String updatedImplementationId2 = "updated2";

	// setup
	final IProject testProject1 = createN4JSProject("P1", ProjectType.LIBRARY);
	final IProject testProject2 = createN4JSProject("P2", ProjectType.LIBRARY);

	// perform package.json modification
	runAtomicWorkspaceOperation(monitor -> {
		final IFile packageJson1 = testProject1.getFile(IN4JSProject.PACKAGE_JSON);
		final IFile packageJson2 = testProject2.getFile(IN4JSProject.PACKAGE_JSON);

		updatePackageJsonFile(packageJson1,
				o -> PackageJSONTestUtils.setImplementationId(o, updatedImplementationId1));
		updatePackageJsonFile(packageJson2,
				o -> PackageJSONTestUtils.setImplementationId(o, updatedImplementationId2));
	});

	// obtain workspace representation of test projects
	Optional<? extends IN4JSProject> projectHandle1 = n4jsCore
			.findProject(URI.createPlatformResourceURI(testProject1.getFullPath().toString(), true));
	Optional<? extends IN4JSProject> projectHandle2 = n4jsCore
			.findProject(URI.createPlatformResourceURI(testProject2.getFullPath().toString(), true));

	// make assertions
	assertTrue("Project handle for test project 1 can be obtained.", projectHandle1.isPresent());
	assertTrue("Project handle for test project 2 can be obtained.", projectHandle2.isPresent());

	assertTrue("Project handle for test project 1 should have implementation ID (cache was invalidated).",
			projectHandle1.get().getImplementationId().isPresent());
	assertTrue("Project handle for test project 2 should have implementation ID (cache was invalidated).",
			projectHandle2.get().getImplementationId().isPresent());

	assertEquals(updatedImplementationId1, projectHandle1.get().getImplementationId().get().getRawName());
	assertEquals(updatedImplementationId2, projectHandle2.get().getImplementationId().get().getRawName());

	// tear down
	testProject1.delete(true, new NullProgressMonitor());
	testProject2.delete(true, new NullProgressMonitor());
}
 
Example 16
Source File: AbstractContentAssistTest.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
@AfterClass
@AfterAll
public static void tearDown() throws CoreException {
	IProject project = AbstractContentAssistTest.javaProject.getProject();
	project.delete(true, new NullProgressMonitor());
}
 
Example 17
Source File: WorkbenchTestHelper.java    From sarl with Apache License 2.0 4 votes vote down vote up
/** Delete the given project.
 *
 * @param project the project to delete.
 * @throws CoreException
 */
public static void deleteProject(IProject project) throws CoreException {
	if (project != null && project.exists()) {
		project.delete(true, true, null);
	}
}
 
Example 18
Source File: WorkspaceSpecManager.java    From tlaplus with MIT License 4 votes vote down vote up
/**
 * Constructor
 */
public WorkspaceSpecManager(final IProgressMonitor monitor)
{
    // initialize the spec life cycle manager
    lifecycleManager = new SpecLifecycleManager();

    final IWorkspace ws = ResourcesPlugin.getWorkspace();

    final String specLoadedName = PreferenceStoreHelper.getInstancePreferenceStore().getString(
            IPreferenceConstants.I_SPEC_LOADED);

    final IProject[] projects = ws.getRoot().getProjects();
    try
    {

        for (int i = 0; i < projects.length; i++)
        {
            // changed from projects[i].isAccessible()
            final IProject project = projects[i];
if (project.isOpen())
            {
                if (project.hasNature(TLANature.ID))
                {
		// Refresh the project in case the actual on-disk
		// representation and the cached Eclipse representation
		// have diverged. This can happen when e.g. another
		// Toolbox opens the project or the files get manually
		// edited. Without calling refresh, code down below 
                	// might throw exceptions due to out-of-sync problems.  
                	project.refreshLocal(IResource.DEPTH_INFINITE, monitor);
                    
                	final Spec spec = new Spec(project);
                    // Added by LL on 12 Apr 2011
                    // If spec.rootFile = null, then this is a bad spec. So
                    // we should report it and not perform addSpec(spec).  It
                    // would be nice if we could report it to the user, but
                    // it seems to be impossible to popup a window at this point
                    // in the code.
                    if (spec.getRootFile() == null)
                    {
                        Activator.getDefault().logError("The bad spec is: `" + project.getName() + "'", null);
                    } else
                    {
                        // This to threw a null pointer exception for Tom, probably causing the abortion
                        // of the Toolbox start. But it started on the next attempt.  Should we catch the
                        // and perhaps report the bad spec?
                        addSpec(spec);
                    }
                    
                    // load the spec if found
                    if (spec.getName().equals(specLoadedName))
                    {
                        this.setSpecLoaded(spec);
                    }
                }
            } else
            {
                // DELETE closed projects
                project.delete(IResource.FORCE | IResource.ALWAYS_DELETE_PROJECT_CONTENT, monitor);
            }
        }

        if (specLoadedName != null && !specLoadedName.equals("") && this.loadedSpec == null)
        {
            // there was a spec loaded but it was not found
            // explicit un-set it
            setSpecLoaded(null);
        }

    } catch (CoreException e)
    {
        Activator.getDefault().logError("Error initializing specification workspace", e);
    }

    ws.addResourceChangeListener(this);
    
    Platform.getAdapterManager().registerAdapters(this, IProject.class);
}
 
Example 19
Source File: JavaProjectSetupUtil.java    From xtext-eclipse with Eclipse Public License 2.0 4 votes vote down vote up
public static void deleteProject(IProject project) throws CoreException {
	if (project.exists()) {
		project.delete(true, true, null);
	}
}
 
Example 20
Source File: FileUtil.java    From birt with Eclipse Public License 1.0 2 votes vote down vote up
/**
 * Deletes a project.
 * 
 * @param proj
 *            the project
 */
public static void deleteProject( IProject proj ) throws CoreException
{
	proj.delete( true, null );
}