private boolean init(IValidationContext helper, IReporter reporter, boolean test) { if (!test && disabled) { return false; } if (context == null) { synchronized (reporters) { reporters.add(document); } String[] uris = helper.getURIs(); if (uris.length == 0) { return false; } IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot(); file = root.getFile(new Path(uris[0])); if (!file.isAccessible()) { return false; } context = new EditorValidationContext(file.getProject(), document); if (context.getValidators().isEmpty()) { return false; } rootProjects = new HashMap<IValidator, IProject>(); for (IValidator validator : context.getValidators()) { Map<IProject, IValidatingProjectSet> projectTree = context.getValidatingProjectTree(validator).getBrunches(); if (!projectTree.isEmpty()) { IProject rootProject = projectTree.keySet().iterator().next(); rootProjects.put(validator, rootProject); } } } return true; }
public void validate(IValidationContext helper, IReporter reporter) throws ValidationException { /* Added by BC ---- */ // if(true) return; /* end Added by BC ---- */ String[] uris = helper.getURIs(); if (uris.length > 0) { IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot(); IFile currentFile = null; for (int i = 0; i < uris.length && !reporter.isCancelled(); i++) { currentFile = wsRoot.getFile(new Path(uris[i])); reporter.removeAllMessages(this, currentFile); if (currentFile != null && currentFile.exists()) { if (shouldValidate(currentFile)) { // && fragmentCheck(currentFile)) { int percent = (i * 100) / uris.length + 1; IMessage message = new LocalizedMessage( IMessage.LOW_SEVERITY, percent + "% " + uris[i]); // $NON-NLS-1$ reporter.displaySubtask(this, message); validateFile(currentFile, reporter); } if (DEBUG) { System.out.println("validating: [" + uris[i] + "]"); // $NON-NLS-1$ //$NON-NLS-2$ } } } } else { // if uris[] length 0 -> validate() gets called for each project if (helper instanceof IWorkbenchContext) { IProject project = ((IWorkbenchContext) helper).getProject(); JSFileVisitor visitor = new JSFileVisitor(reporter); try { // collect all jsp files for the project project.accept(visitor, IResource.DEPTH_INFINITE); } catch (CoreException e) { if (DEBUG) { e.printStackTrace(); } } IFile[] files = visitor.getFiles(); for (int i = 0; i < files.length && !reporter.isCancelled(); i++) { int percent = (i * 100) / files.length + 1; IMessage message = new LocalizedMessage( IMessage.LOW_SEVERITY, percent + "% " + files[i].getFullPath().toString()); // $NON-NLS-1$ reporter.displaySubtask(this, message); validateFile(files[i], reporter); if (DEBUG) { System.out.println("validating: [" + files[i] + "]"); // $NON-NLS-1$ //$NON-NLS-2$ } } } } }
private IEditorInput findEditor(IValidationContext helper) { String[] delta = helper.getURIs(); if (delta.length > 0) { // get the file, model and document: IFile file = getFile(delta[0]); if (file == null || !file.exists()) { IFileStore fileStore = FileBuffers.getFileStoreAtLocation(new Path(delta[0])); return new FileStoreEditorInput(fileStore); } return new FileEditorInput(file); } return null; }