public ValidationLauncherJob(Job validationJob) { super(ResourceHandler.getExternalizedMessage("VBF_VALIDATION_JOB_MSG")); setSystem(true); setRule(ResourcesPlugin.getWorkspace().getRoot()); this.validationJob= validationJob; } protected IStatus run(IProgressMonitor monitor) {
protected ValidationConfiguration(IResource resource, ValidatorMetaData[] validators) throws InvocationTargetException { this(); if (resource == null) { throw new InvocationTargetException(null, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_NULLCREATE)); } setResource(resource); setValidators(validators); }
/** * Once all of the fields have been updated on this ValidationConfiguration instance, this * preference should be stored back on the IResource for later use. This method must be called * manually by the validation framework once the fields of this type have been updated. */ public final void passivate() throws InvocationTargetException { try { if (getResource() == null) { throw new InvocationTargetException(null, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_NULLSAVE)); } getResource().setSessionProperty(ConfigurationConstants.USER_PREFERENCE, this); } catch (CoreException exc) { throw new InvocationTargetException(exc, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_SAVE, new String[]{getResource().getName()})); } }
String msg = ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_STATUS_VALIDATOR_TERMINATED); status = WTPCommonPlugin.createCancelStatus(msg);
protected final String loadVersion(IResource resource) throws InvocationTargetException { try { // This method will be called in one of two situations: // 1. This is a new workspace and no preferences exist. // 2. This is a migrated workspace and the old preferences have already been created as // persistent properties. String storedConfiguration = resource.getPersistentProperty(ConfigurationConstants.USER_PREFERENCE); String version = null; if (storedConfiguration == null) { version = getVersionDefault(); } else { int versionIndex = storedConfiguration.indexOf(ConfigurationConstants.VERSION); if (versionIndex != -1) version = storedConfiguration.substring(versionIndex + ConfigurationConstants.VERSION.length()); } if (version == null) { return getVersionDefault(); } return version; } catch (CoreException exc) { throw new InvocationTargetException(exc, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_RETRIEVE, new String[]{getResource().getName()})); } }
/** * Load the values of these fields when the project or workspace is opened. */ protected final void load() throws InvocationTargetException { try { if (getResource() == null) { throw new InvocationTargetException(null, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_NULLRETRIEVE)); } IMarker[] marker = getMarker(); if (marker == null) { // either a new workspace or already migrated; proceed as normal loadPreference(); } else { // migrate load(marker); } } catch (InvocationTargetException exc) { throw exc; } catch (Exception exc) { String resourceName = (getResource() == null) ? "null" : getResource().getName(); //$NON-NLS-1$ throw new InvocationTargetException(exc, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_RETRIEVE, new String[]{resourceName})); } }
/** * Validate the existance of Web Roles within the EAR Roles and duplicates in Web Roles. */ protected void validateWEBRolesWithEARRoles(EList earRoleList, EList warRoles) { int numRoles = warRoles.size(); // TFB This implementation requires a 'small' list of warRoles. // If 'warRoles' gets too big then another implementation // will be necessary. for (int roleNo = 0; roleNo < numRoles; roleNo++) { if( _reporter.isCancelled() ){ String msg = ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_STATUS_VALIDATOR_TERMINATED); status = WTPCommonPlugin.createErrorStatus(msg); } SecurityRoleImpl nextRole = (SecurityRoleImpl) (warRoles.get(roleNo)); String[] parms = new String[1]; parms[0] = nextRole.getRoleName(); if (!(earRoleList.contains(nextRole))) addWarning(WAR_CATEGORY, ERROR_EAR_MISSING_EJB_ROLE, parms, nextRole); } } }
/** * This method returns the validator if it can be loaded; if the validator cannot be loaded, * e.g., if its plugin is disabled for some reason, then this method throws an * InstantiationException. Before the CoreException is thrown, this validator is disabled. * * @return IValidator * @throws InstantiationException */ public IValidator getValidator() throws InstantiationException { if (_validator == null) { _validator = ValidationRegistryReader.createValidator(_validatorClassElement, getValidatorUniqueName()); // Since the element won't be used any more, clear it. //_validatorClassElement = null; if (_validator == null) { setCannotLoad(); throw new InstantiationException(ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_DISABLEV, new String[]{getValidatorUniqueName()})); } } return _validator; }
/** * Returns the Validator extension point */ private IExtensionPoint getValidatorExtensionPoint() { IExtensionRegistry registry = Platform.getExtensionRegistry(); IExtensionPoint extensionPoint = registry.getExtensionPoint(PLUGIN_ID, VALIDATOR_EXT_PT_ID); if (extensionPoint == null) { // If this happens it means that someone removed the "validator" extension point // declaration // from our plugin.xml file. Logger logger = ValidationPlugin.getPlugin().getMsgLogger(); if (logger.isLoggingLevel(Level.FINE)) { LogEntry entry = ValidationPlugin.getLogEntry(); entry.setSourceID("ValidationRegistryReader.getValidatorExtensionPoint()"); //$NON-NLS-1$ entry.setMessageTypeID(ResourceConstants.VBF_EXC_MISSING_VALIDATOR_EP); //entry.setTokens(new String[]{ValidationPlugin.PLUGIN_ID + "." + VALIDATOR_EXT_PT_ID}); //$NON-NLS-1$ String result = MessageFormat.format(ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_MISSING_VALIDATOR_EP), new String[]{ValidationPlugin.PLUGIN_ID + "." + VALIDATOR_EXT_PT_ID}); entry.setText(result); logger.write(Level.FINE, entry); } } return extensionPoint; }
public ProjectConfiguration getProjectConfiguration(IProject project) throws InvocationTargetException { ProjectConfiguration prjp = null; try { prjp = (ProjectConfiguration) project.getSessionProperty(USER_PREFERENCE); if (prjp == null || !prjp.getResource().exists()) { prjp = new ProjectConfiguration(project); prjp.getVersion(); // initialize the configuration's version attribute prjp.load(); // initialize this instance from the stored values prjp.passivate(); // store this instance as a property on the IResource } return prjp; } catch (CoreException exc) { throw new InvocationTargetException(exc, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_RETRIEVE, new String[]{project.getName()})); } }
/** * Load and store the version number, but nothing else. The version isn't a preference, but it's * stored and loaded as if it is. Because the load mechanism is different between an IProject * and the IWorkspaceRoot, keep the load mechanism inside the ValidationConfiguration * implementation, but initialize only the minimum at first. After the project has been * migrated, load the other fields (loading the other fields before the migration may overwrite * the values of those fields). */ protected final void loadVersion() throws InvocationTargetException { if (getResource() == null) { throw new InvocationTargetException(null, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_NULLRETRIEVE)); } IMarker[] marker = getMarker(); String version = null; if (marker == null) { // either a new workspace or already migrated; proceed as normal version = loadVersion(getResource()); } else { // migrate version = loadVersion(marker); } setVersion(version); }
public ProjectConfiguration getProjectConfigurationWithoutMigrate(IProject project) throws InvocationTargetException { ProjectConfiguration prjp = null; try { prjp = (ProjectConfiguration) project.getSessionProperty(USER_PREFERENCE); if (prjp == null || !prjp.getResource().exists()) { prjp = new ProjectConfiguration(project); prjp.getVersion(); // initialize the configuration's version attribute prjp.load(); // initialize this instance from the stored values prjp.passivate(); // store this instance as a property on the IResource } return prjp; } catch (CoreException exc) { throw new InvocationTargetException(exc, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_RETRIEVE, new String[]{project.getName()})); } }
/* package */static IWorkbenchContext createHelper(IConfigurationElement element, String helperClassName) { IWorkbenchContext wh = null; try { wh = (IWorkbenchContext) element.createExecutableExtension(TAG_HELPER_CLASS); } catch (Exception exc) { Logger logger = ValidationPlugin.getPlugin().getMsgLogger(); if (logger.isLoggingLevel(Level.SEVERE)) { LogEntry entry = ValidationPlugin.getLogEntry(); entry.setSourceID("ValidationRegistryReader.createHelper(IConfigurationElement, String)"); //$NON-NLS-1$ entry.setMessageTypeIdentifier(ResourceConstants.VBF_EXC_SYNTAX_NO_HELPER_THROWABLE); entry.setTargetException(exc); String result = MessageFormat.format(ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_SYNTAX_NO_HELPER_THROWABLE), new String[]{helperClassName}); entry.setText(result); //entry.setTokens(new String[]{helperClassName}); logger.write(Level.SEVERE, entry); } return null; } return wh; }
/** * Provides the instance of the validator delegate pointed to by this * descriptor. * * @return an IValidator instance. * @throws ValidationException */ public IValidator getValidator() throws ValidationException { try { IValidator delegate = (IValidator) delegateConfiguration.createExecutableExtension(ValidatorDelegatesRegistryReader.CLASS_ATTRIBUTE); return delegate; } catch (CoreException e) { String delegatingValidatorName = ValidationRegistryReader.getReader().getValidatorMetaData(getTargetID()).getValidatorDisplayName(); throw new ValidationException(new LocalizedMessage(IMessage.HIGH_SEVERITY, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_CANNOT_INSTANTIATE_DELEGATE, new String[] { getName(), delegatingValidatorName }))); } } }
/** * Return true if the global preferences are at the current level of metadata, false otherwise. */ public boolean isGlobalMigrated() throws InvocationTargetException { IWorkspaceRoot root = ValidationConfiguration.getRoot(); if (root == null) { return false; } try { GlobalConfiguration gp = (GlobalConfiguration) root.getSessionProperty(USER_PREFERENCE); if (gp != null) { return gp.isVersionCurrent(); } String serializedPrjp = root.getPersistentProperty(USER_PREFERENCE); if (serializedPrjp != null) { gp = new GlobalConfiguration(root); gp.getVersion(); // initialize the configuration's version attribute return gp.isVersionCurrent(); } } catch (CoreException exc) { throw new InvocationTargetException(exc, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_RETRIEVE, new String[]{root.getName()})); } return false; }
/** * Return true if the given project has the current level of metadata, false otherwise. */ public boolean isMigrated(IProject project) throws InvocationTargetException { if (project == null) { return false; } try { if (project.isAccessible()) { ProjectConfiguration prjp = (ProjectConfiguration) project.getSessionProperty(USER_PREFERENCE); if (prjp != null) { return prjp.isVersionCurrent(); } String serializedPrjp = project.getPersistentProperty(USER_PREFERENCE); if (serializedPrjp != null) { prjp = new ProjectConfiguration(project); prjp.getVersion(); // initialize the configuration's // version attribute return prjp.isVersionCurrent(); } } } catch (CoreException exc) { throw new InvocationTargetException(exc, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_RETRIEVE, new String[]{project.getName()})); } return false; }
/** * @deprecated Will be removed in Milestone 3. */ protected void terminateCleanup(WorkbenchReporter reporter) { Set enabledValidators = getEnabledValidators(); Iterator iterator = enabledValidators.iterator(); ValidatorMetaData vmd = null; while (iterator.hasNext()) { vmd = (ValidatorMetaData) iterator.next(); reporter.displaySubtask(ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_STATUS_VALIDATOR_CLEANUP, new String[]{vmd.getValidatorDisplayName()})); try { reporter.removeAllMessages(vmd.getValidator()); } catch (InstantiationException exc) { // Remove the vmd from the reader's list ValidationRegistryReader.getReader().disableValidator(vmd); // Log the reason for the disabled validator final Logger logger = ValidationPlugin.getPlugin().getMsgLogger(); if (logger.isLoggingLevel(Level.SEVERE)) { LogEntry entry = ValidationPlugin.getLogEntry(); entry.setSourceID("ValidationOperation::terminateCleanup"); //$NON-NLS-1$ entry.setTargetException(exc); logger.write(Level.SEVERE, entry); } continue; } addCancelTask(vmd); reporter.displaySubtask(ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_STATUS_VALIDATOR_TERMINATED, new String[]{getProject().getName(), vmd.getValidatorDisplayName()})); } }
/** * This method returns the global preferences for the workspace. */ public GlobalConfiguration getGlobalConfiguration() throws InvocationTargetException { IWorkspaceRoot root = ValidationConfiguration.getRoot(); GlobalConfiguration gp = null; try { gp = (GlobalConfiguration) root.getSessionProperty(USER_PREFERENCE); if (gp == null) { gp = new GlobalConfiguration(root); Preferences prefs = ValidationPlugin.getPlugin().getPluginPreferences(); if( prefs != null ){ prefs.addPropertyChangeListener(gp); } gp.getVersion(); // initialize the configuration's version attribute gp.load(); // initialize this instance from the stored values gp.passivate(); // store this instance as a property on the IResource } return gp; } catch (CoreException exc) { throw new InvocationTargetException(exc, ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_RETRIEVE, new String[]{root.getName()})); } }
/* package */static IValidator createValidator(IConfigurationElement element, String validatorClassName) { IValidator validator = null; try { validator = (IValidator) element.createExecutableExtension(ATT_CLASS); } catch (Exception exc) { Logger logger = ValidationPlugin.getPlugin().getMsgLogger(); if (logger.isLoggingLevel(Level.SEVERE)) { LogEntry entry = ValidationPlugin.getLogEntry(); entry.setSourceID("ValidationRegistryReader.createValidator(IConfigurationElement, String, String)"); //$NON-NLS-1$ entry.setMessageTypeID(ResourceConstants.VBF_EXC_SYNTAX_NO_VAL_THROWABLE); //entry.setTokens(new String[]{validatorClassName}); String result = MessageFormat.format(ResourceHandler.getExternalizedMessage(ResourceConstants.VBF_EXC_SYNTAX_NO_VAL_THROWABLE), new String[]{validatorClassName}); entry.setText(result); entry.setTargetException(exc); logger.write(Level.SEVERE, entry); } } if (validator == null) { Logger logger = ValidationPlugin.getPlugin().getMsgLogger(); if (logger.isLoggingLevel(Level.FINE)) { LogEntry entry = ValidationPlugin.getLogEntry(); entry.setSourceID("ValidationRegistryReader.createValidator(IConfigurationElement, String)"); //$NON-NLS-1$ entry.setMessageTypeID(ResourceConstants.VBF_EXC_SYNTAX_NO_VAL_NULL); entry.setTokens(new String[]{validatorClassName}); logger.write(Level.FINE, entry); } return null; } return validator; }
public static String getExternalizedMessage(String key, String[] parms) { String res = ""; //$NON-NLS-1$ try { res = java.text.MessageFormat.format(getExternalizedMessage(key), parms); } catch (MissingResourceException exc) { Logger logger = ValidationPlugin.getPlugin().getMsgLogger(); if (logger.isLoggingLevel(Level.FINE)) { LogEntry entry = ValidationPlugin.getLogEntry(); entry.setSourceID("org.eclipse.wst.validation.internal.operations.internal.ResourceHandler.getExternalizedMessage(String, String[])"); //$NON-NLS-1$ entry.setText("Cannot find message id " + key); //$NON-NLS-1$ entry.setTargetException(exc); logger.write(Level.FINE, entry); } } catch (NullPointerException exc) { Logger logger = ValidationPlugin.getPlugin().getMsgLogger(); if (logger.isLoggingLevel(Level.FINE)) { LogEntry entry = ValidationPlugin.getLogEntry(); entry.setSourceID("org.eclipse.wst.validation.internal.operations.internal.ResourceHandler.getExternalizedMessage(String, String[])"); //$NON-NLS-1$ entry.setText("Cannot format message id " + key + " with " + parms.length + " parameters."); //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ entry.setTargetException(exc); logger.write(Level.FINE, entry); } } return res; } }