/** * Answer the most current ValidatorProjectManager creating a new one if you have to. * * @return */ public static ValidatorProjectManager get() { ValidatorProjectManager vpm = _me.get(); if (vpm != null) return vpm; int next = _counter.incrementAndGet(); ValidatorProjectManager newVpm = null; boolean looking = true; while (looking) { vpm = _me.get(); if (vpm == null || next > vpm.getSequence()) { if (newVpm == null) newVpm = new ValidatorProjectManager(next); if (_me.compareAndSet(vpm, newVpm)) return newVpm; } else looking = false; } return vpm; }
/** * Accept a visitor for all the validators that are enabled for the given project. * * @param visitor * @param project * @param valType the type of validation * @param operation * @param monitor */ public void accept( IValidatorVisitor visitor, IProject project, ValType valType, ValOperation operation, IProgressMonitor monitor) { if (isDisabled(project)) return; for (Validator val : getValidators(project)) { if (monitor.isCanceled()) return; if (!ValidatorProjectManager.get().shouldValidate(val, project, valType)) continue; if (operation.isSuspended(val, project)) continue; try { visitor.visit(val, project, valType, operation, monitor); } catch (Exception e) { ValidationPlugin.getPlugin().handleException(e); } } }
/** * Let the validation manager know that a project has been removed. * * @param project The project that has been closed or deleted. */ public void projectRemoved(IProject project) { ValidatorProjectManager.reset(); _projectPreferences.remove(project); _cache.reset(project); }
/** * Accept a visitor for all the validators that are enabled for the given project, resource, and * validation mode. * * @param valType the type of validation request */ public void accept( IValidatorVisitor visitor, IProject project, IResource resource, ValType valType, ValOperation operation, IProgressMonitor monitor) { if (isDisabled(project)) return; Map<String, IValidatorGroupListener[]> groupListeners = new HashMap<String, IValidatorGroupListener[]>(); ValProperty vp = getValProperty(resource, valType, _configNumber.get()); if (vp != null) { BitSet bs = vp.getConfigSet(); for (Validator val : getValidators(project)) { if (!monitor.isCanceled()) { if (!bs.get(_idManager.getIndex(val.getId()))) continue; if (operation.isSuspended(val, project)) continue; Validator.V2 v2 = val.asV2Validator(); if (v2 != null) { notifyGroupListenersStarting( resource, operation.getState(), monitor, groupListeners, v2); } try { visitor.visit(val, project, valType, operation, monitor); } catch (Exception e) { ValidationPlugin.getPlugin().handleException(e); } } } notifyGroupFinishing(resource, operation.getState(), monitor, groupListeners); return; } vp = new ValProperty(); vp.setConfigNumber(_configNumber.get()); ContentTypeWrapper ctw = new ContentTypeWrapper(); for (Validator val : getValidators(project)) { if (!monitor.isCanceled()) { if (!ValidatorProjectManager.get().shouldValidate(val, project, valType)) continue; if (Friend.shouldValidate(val, resource, valType, ctw)) { vp.getConfigSet().set(_idManager.getIndex(val.getId())); // we do the suspend check after figuring out if it needs to be validated, because we save // this information for the session. if (operation.isSuspended(val, project)) continue; Validator.V2 v2 = val.asV2Validator(); if (v2 != null) { notifyGroupListenersStarting( resource, operation.getState(), monitor, groupListeners, v2); } try { visitor.visit(val, project, valType, operation, monitor); } catch (Exception e) { ValidationPlugin.getPlugin().handleException(e); } } } } notifyGroupFinishing(resource, operation.getState(), monitor, groupListeners); putValProperty(vp, resource, valType); }
/** This method needs to be called whenever the validation configuration has changed. */ private void configHasChanged() { _configNumber.incrementAndGet(); ValidatorProjectManager.reset(); _cache.reset(); }
/** * Reset the ValidatorProjectManager to null, which will force a newer one to be created the * next time that it is requested. */ public static void reset() { int next = _counter.incrementAndGet(); ValidatorProjectManager vpm = _me.get(); if (vpm == null) return; if (next > vpm.getSequence()) _me.compareAndSet(vpm, null); }