View | Details | Raw Unified | Return to bug 284348 | Differences between
and this patch

Collapse All | Expand All

(-)src/org/eclipse/emf/validation/tests/PluginTest.java (+56 lines)
Added Link Here
1
/**
2
 * <copyright>
3
 *
4
 * Copyright (c) 2009 SAP AG and others.
5
 * All rights reserved.   This program and the accompanying materials
6
 * are made available under the terms of the Eclipse Public License v1.0
7
 * which accompanies this distribution, and is available at
8
 * http://www.eclipse.org/legal/epl-v10.html
9
 *
10
 * Contributors:
11
 *   SAP - Initial API and implementation
12
 *
13
 * </copyright>
14
 *
15
 * $Id$
16
 */
17
package org.eclipse.emf.validation.tests;
18
19
import org.eclipse.emf.validation.internal.EMFModelValidationPlugin;
20
import org.osgi.framework.Bundle;
21
22
import junit.framework.TestCase;
23
24
/**
25
 * Tests for the validation plugin integration.
26
 * 
27
 * @author Boris Gruschko
28
 *
29
 */
30
public class PluginTest extends TestCase {
31
32
	private static final String DEBUG_OPTION = "org.eclipse.emf.validation/debug"; //$NON-NLS-1$
33
34
	public PluginTest() {
35
		super( "Validation plugin integration");  //$NON-NLS-1$
36
	}
37
	
38
	/**
39
	 * Tests the dynamic switch into debug/trace mode
40
	 */
41
	public void testDebugModeSetting() {
42
		assertEquals(Bundle.ACTIVE, EMFModelValidationPlugin.getPlugin().getBundle().getState());
43
		assertFalse(EMFModelValidationPlugin.getPlugin().isDebugging());
44
		assertFalse(EMFModelValidationPlugin.Tracing.shouldTrace(DEBUG_OPTION));
45
		
46
		EMFModelValidationPlugin.getPlugin().setDebugging(true);
47
48
		assertTrue(EMFModelValidationPlugin.getPlugin().isDebugging());
49
		assertTrue(EMFModelValidationPlugin.Tracing.shouldTrace(DEBUG_OPTION));
50
	
51
		EMFModelValidationPlugin.getPlugin().setDebugging(false);
52
		
53
		assertFalse(EMFModelValidationPlugin.Tracing.shouldTrace(DEBUG_OPTION));
54
	}
55
56
}
(-)src/org/eclipse/emf/validation/internal/EMFModelValidationPlugin.java (-2 / +34 lines)
Lines 15-21 Link Here
15
package org.eclipse.emf.validation.internal;
15
package org.eclipse.emf.validation.internal;
16
16
17
import java.util.Collection;
17
import java.util.Collection;
18
import java.util.Dictionary;
18
import java.util.HashMap;
19
import java.util.HashMap;
20
import java.util.Hashtable;
19
import java.util.Iterator;
21
import java.util.Iterator;
20
import java.util.Map;
22
import java.util.Map;
21
23
Lines 26-31 Link Here
26
import org.eclipse.emf.common.EMFPlugin;
28
import org.eclipse.emf.common.EMFPlugin;
27
import org.eclipse.emf.common.util.ResourceLocator;
29
import org.eclipse.emf.common.util.ResourceLocator;
28
import org.eclipse.emf.validation.internal.l10n.ValidationMessages;
30
import org.eclipse.emf.validation.internal.l10n.ValidationMessages;
31
import org.eclipse.osgi.service.debug.DebugOptions;
32
import org.eclipse.osgi.service.debug.DebugOptionsListener;
29
import org.eclipse.osgi.util.NLS;
33
import org.eclipse.osgi.util.NLS;
30
import org.osgi.framework.BundleContext;
34
import org.osgi.framework.BundleContext;
31
35
Lines 213-219 Link Here
213
	 * 
217
	 * 
214
	 * @author Christian W. Damus (cdamus)
218
	 * @author Christian W. Damus (cdamus)
215
	 */
219
	 */
216
	public static class Implementation extends EMFPlugin.EclipsePlugin {
220
	public static class Implementation extends EMFPlugin.EclipsePlugin implements DebugOptionsListener {
217
		/**
221
		/**
218
		 * Track extensions for extension points defined in this bundle.
222
		 * Track extensions for extension points defined in this bundle.
219
		 */
223
		 */
Lines 237-242 Link Here
237
			super.start(context);
241
			super.start(context);
238
			
242
			
239
			extensionTracker = new ExtensionTracker();
243
			extensionTracker = new ExtensionTracker();
244
			
245
			// register listener that is notified whenever debug options change
246
			Dictionary<String, Object> props = new Hashtable<String, Object>(4);
247
			props.put(DebugOptions.LISTENER_SYMBOLICNAME, getPluginId());
248
			context.registerService(DebugOptionsListener.class.getName(), this, props);
240
		}
249
		}
241
		
250
		
242
		@Override
251
		@Override
Lines 246-251 Link Here
246
			
255
			
247
			super.stop(context);
256
			super.stop(context);
248
		}
257
		}
258
		
259
		public void optionsChanged(DebugOptions options) {
260
			Tracing.invalidateCache();
261
		}
249
	}
262
	}
250
	
263
	
251
    public static class Tracing {
264
    public static class Tracing {
Lines 255-267 Link Here
255
    	private static final Map<String, Boolean> cachedOptions = new HashMap<String, Boolean>();
268
    	private static final Map<String, Boolean> cachedOptions = new HashMap<String, Boolean>();
256
269
257
    	/**
270
    	/**
271
    	 * The cached Boolean value indicating whether tracing is enabled. 
272
    	 */
273
    	private static Boolean debugging = null;
274
    	
275
    	/**
276
    	 * Invalidates the cached debug options and the cached Boolean value
277
    	 * indicating whether tracing is enabled.
278
    	 */
279
    	protected static void invalidateCache() {
280
    		cachedOptions.clear();
281
    		debugging = null;
282
    	}
283
    	
284
    	/**
258
    	 * Retrieves a Boolean value indicating whether tracing is enabled.
285
    	 * Retrieves a Boolean value indicating whether tracing is enabled.
259
    	 * 
286
    	 * 
260
    	 * @return Whether tracing is enabled for the plug-in.
287
    	 * @return Whether tracing is enabled for the plug-in.
261
    	 * 
288
    	 * 
262
    	 */
289
    	 */
263
    	protected static boolean shouldTrace() {
290
    	protected static boolean shouldTrace() {
264
    		return plugin.isDebugging();
291
    		synchronized (cachedOptions) {
292
    			if (debugging == null) {    			
293
    				debugging = plugin.isDebugging();
294
    			}
295
			}
296
    		return debugging.booleanValue();
265
    	}
297
    	}
266
298
267
    	/**
299
    	/**

Return to bug 284348