package org.jboss.reddeer.requirements.cleanworkspace;

import java.lang.annotation.Documented;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.jboss.reddeer.eclipse.core.resources.Project;
import org.jboss.reddeer.eclipse.jdt.ui.packageexplorer.PackageExplorer;
import org.jboss.reddeer.eclipse.utils.DeleteUtils;
import org.jboss.reddeer.junit.requirement.Requirement;
import org.jboss.reddeer.requirements.cleanworkspace.CleanWorkspaceRequirement.CleanWorkspace;

/**
 * Clean workspace requirement<br/><br/>
 * 
 * This {@link Requirement} ensures, that all projects are deleted from workspace
 * (aka. workspace is clean).<br/><br>
 * 
 * Annotate test class with {@link CleanWorkspace} annotation to have clean
 * workspace before the test cases are executed.<br/><br/>
 * 
 * Example:<br/>
 * <pre>
 * {@code @CleanWorkspace
 * public class TestClass {
 *    // workspace will be cleaned before tests execution
 * }
 * }
 * </pre>
 * 
 * @author rhopp
 * 
 */
public class CleanWorkspaceRequirement implements Requirement<CleanWorkspace> {

	/**
	 * Marks test class, which requires clean workspace before test cases are executed.
	 */
	@Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.TYPE)
	@Documented
	public @interface CleanWorkspace {
		
	}
	
	/**
	 * Always returns true because cleaning workspace should be possible every time.
	 * 
	 * @return true
	 */
	@Override
	public boolean canFulfill() {
		return true; 
	}

	/**
	 * Deletes all projects from workspace.
	 */
	@Override
	public void fulfill() {	
		PackageExplorer packageExplorer = new PackageExplorer();
		packageExplorer.open();
		for (Project project : packageExplorer.getProjects()){
			DeleteUtils.forceProjectDeletion(project, true);
		}
		packageExplorer.activate();
	}

	/**
	 * This method is empty because annotation {@link CleanWorkspace} has no elements.
	 * However, it is one of methods of {@link Requirement} interface so it has to be
	 * overridden.
	 */
	@Override
	public void setDeclaration(CleanWorkspace declaration) {
		// nothing to do here
	}

}

@@ -352,31 +352,15 @@
 .ui.
-packageexplorer.Package
+Project
 Expl
@@ -1636,22 +1636,22 @@
 ) %7B%09%0A%09%09P
-ackage
+roject
 Explorer
@@ -1656,30 +1656,17 @@
 er p
-ackageExplorer
+e
  = new P
 acka
@@ -1661,22 +1661,22 @@
  = new P
-ackage
+roject
 Explorer
@@ -1682,30 +1682,17 @@
 r();%0A%09%09p
-ackageExplorer
+e
 .open();
@@ -1718,30 +1718,17 @@
 ject : p
-ackageExplorer
+e
 .getProj
@@ -1799,22 +1799,9 @@
 %0A%09%09p
-ackageExplorer
+e
 .act

Use Project explorer instead of package due to state of Eclipse Mars. #942