swtbot: Delete projects after tests

This allows running the tests repeatedly

Change-Id: I289da60f0d3dc8d2539eeb5bc6f2b14e3bb35fb1
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/37752
Tested-by: Hudson CI
diff --git a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/AbstractTest.java b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/AbstractTest.java
index c4e660e..d834f43 100644
--- a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/AbstractTest.java
+++ b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/AbstractTest.java
@@ -25,6 +25,7 @@
 import org.eclipse.core.resources.IWorkspace;
 import org.eclipse.core.resources.IWorkspaceRoot;
 import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
 import org.eclipse.jface.bindings.keys.KeyStroke;
 import org.eclipse.jface.bindings.keys.ParseException;
 import org.eclipse.swt.SWT;
@@ -52,20 +53,34 @@
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotTreeItem;
 import org.hamcrest.Matcher;
 import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
 
 public abstract class AbstractTest {
+
+	private static final String PROJECT_NAME = "GnuProject";
+
 	protected static SWTWorkbenchBot bot;
 	protected static String projectName;
 	protected static SWTBotShell mainShell;
 	protected static SWTBotView projectExplorer;
 
+	@BeforeClass
+	public static void initAbstractClass() throws Exception {
+		AbstractTest.init(PROJECT_NAME);
+	}
+
+	@AfterClass
+	public static void afterClass() throws Exception {
+		AbstractTest.deleteProject(PROJECT_NAME);
+	}
+
 	public static void init(String projectName) throws Exception {
 		SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US";
 		SWTBotPreferences.PLAYBACK_DELAY = 10;
 		bot = new SWTWorkbenchBot();
 		bot.sleep(5000);
 		mainShell = getMainShell();
-
 		// Close the Welcome view if it exists
 		try {
 			bot.viewByTitle("Welcome").close();
@@ -115,6 +130,10 @@
 		projectExplorer = bot.viewByTitle("Project Explorer");
 	}
 
+	public static void deleteProject(String projectName) throws CoreException {
+		ResourcesPlugin.getWorkspace().getRoot().getProject(projectName).delete(true, null);
+	}
+
 	public static class NodeAvailableAndSelect extends DefaultCondition {
 
 		private SWTBotTree tree;
diff --git a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/SetConfigurationParameter.java b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/SetConfigurationParameter.java
index 000bacf..3b8d618 100644
--- a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/SetConfigurationParameter.java
+++ b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/SetConfigurationParameter.java
@@ -22,7 +22,6 @@
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
 
-import org.eclipse.cdt.autotools.ui.tests.AbstractTest.NodeAvailableAndSelect;
 import org.eclipse.core.resources.IProject;
 import org.eclipse.core.resources.IWorkspace;
 import org.eclipse.core.resources.IWorkspaceRoot;
@@ -50,8 +49,7 @@
 public class SetConfigurationParameter extends AbstractTest {
 
 	@BeforeClass
-	public static void beforeClass() throws Exception {
-		AbstractTest.init("GnuProject0");
+	public static void initClass() throws Exception {
 		initConfigParm();
 	}
 
diff --git a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestEnvironmentVars.java b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestEnvironmentVars.java
index fc881d5..1e9ca4d 100644
--- a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestEnvironmentVars.java
+++ b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestEnvironmentVars.java
@@ -24,7 +24,6 @@
 import org.eclipse.swtbot.swt.finder.waits.Conditions;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotText;
-import org.junit.BeforeClass;
 import org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -34,11 +33,6 @@
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
 public class TestEnvironmentVars extends AbstractTest {
 
-	@BeforeClass
-	public static void beforeClass() throws Exception {
-		AbstractTest.init("GnuProject2");
-	}
-
 	// Verify we can pass an unknown env var in configure options and it will be
 	// nulled out
 	// Verifies fix for Bug: #303616
diff --git a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestMakeTargets.java b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestMakeTargets.java
index 892af6c..5ec9b9c 100644
--- a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestMakeTargets.java
+++ b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestMakeTargets.java
@@ -25,7 +25,6 @@
 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
 import org.eclipse.swtbot.swt.finder.waits.Conditions;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
-import org.junit.BeforeClass;
 import org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -35,11 +34,6 @@
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
 public class TestMakeTargets extends AbstractTest {
 
-	@BeforeClass
-	public static void beforeClass() throws Exception {
-		AbstractTest.init("GnuProject3");
-	}
-
 	@Test
 	// Verify we can build and run the info MakeTarget tool
 	public void t1canBuildAndAccessInfoTarget() throws Exception {
diff --git a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestToolActions.java b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestToolActions.java
index 7e4cb49..1d0a5a7 100644
--- a/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestToolActions.java
+++ b/build/org.eclipse.cdt.autotools.ui.tests/src/org/eclipse/cdt/autotools/ui/tests/TestToolActions.java
@@ -20,7 +20,6 @@
 import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
 import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
 import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
-import org.junit.BeforeClass;
 import org.junit.FixMethodOrder;
 import org.junit.Test;
 import org.junit.runner.RunWith;
@@ -30,11 +29,6 @@
 @FixMethodOrder(MethodSorters.NAME_ASCENDING)
 public class TestToolActions extends AbstractTest {
 
-	@BeforeClass
-	public static void beforeClass() throws Exception {
-		AbstractTest.init("GnuProject4");
-	}
-
 	@Test
 	// Verify we can set the tools via the Autotools Tools page
 	public void t1canSeeTools() throws Exception {