1919import org .eclipse .core .resources .IMarker ;
2020import org .eclipse .core .resources .IProject ;
2121import org .eclipse .core .resources .IResource ;
22+ import org .eclipse .core .resources .IWorkspace ;
23+ import org .eclipse .core .resources .IWorkspaceDescription ;
24+ import org .eclipse .core .resources .ResourcesPlugin ;
25+ import org .eclipse .core .runtime .CoreException ;
2226import org .eclipse .debug .core .ILaunch ;
2327import org .eclipse .debug .core .model .IDebugTarget ;
2428import org .eclipse .ui .IMarkerResolution ;
@@ -61,7 +65,12 @@ public abstract class BaseTest extends TestCase {
6165 protected static String relativeURL ;
6266 protected static String srcPath ;
6367
68+ protected static Boolean origAutoBuildSetting = null ;
69+
6470 public void doSetup () throws Exception {
71+ // Disable workspace auto build
72+ origAutoBuildSetting = setWorkspaceAutoBuild (false );
73+
6574 // Create a microclimate connection
6675 connection = MicroclimateObjectFactory .createMicroclimateConnection (new URI (MICROCLIMATE_URI ));
6776 MicroclimateConnectionManager .add (connection );
@@ -82,6 +91,19 @@ public void doSetup() throws Exception {
8291 assertNotNull ("The " + projectName + " project should be imported in eclipse" , project );
8392 }
8493
94+ public void doTearDown () {
95+ try {
96+ MicroclimateUtil .cleanup (connection );
97+ } catch (Exception e ) {
98+ TestUtil .print ("Test case cleanup failed" , e );
99+ }
100+
101+ // Restore workspace auto build setting
102+ if (origAutoBuildSetting != null ) {
103+ setWorkspaceAutoBuild (origAutoBuildSetting .booleanValue ());
104+ }
105+ }
106+
85107 public void checkApp (String text ) throws Exception {
86108 MicroclimateApplication app = connection .getAppByName (projectName );
87109 assertTrue ("App should be in started state. Current state is: " + app .getAppState (), MicroclimateUtil .waitForAppState (app , AppState .STARTED , 120 , 2 ));
@@ -200,5 +222,21 @@ protected void runQuickFix(IResource resource) throws Exception {
200222 resolutions [0 ].run (markers [0 ]);
201223 TestUtil .waitForJobs (10 , 1 );
202224 }
225+
226+ public static Boolean setWorkspaceAutoBuild (boolean enabled ) {
227+ IWorkspace workspace = ResourcesPlugin .getWorkspace ();
228+ IWorkspaceDescription wsDescription = workspace .getDescription ();
229+ boolean origEnabled = wsDescription .isAutoBuilding ();
230+ if (enabled != origEnabled ) {
231+ try {
232+ wsDescription .setAutoBuilding (enabled );
233+ workspace .setDescription (wsDescription );
234+ return origEnabled ? Boolean .TRUE : Boolean .FALSE ;
235+ } catch (CoreException e ) {
236+ TestUtil .print ("Failed to set workspace auto build enabled to: " + enabled , e );
237+ }
238+ }
239+ return null ;
240+ }
203241
204242}
0 commit comments