X-Git-Url: https://mograsim.net/gitweb/?a=blobdiff_plain;f=net.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Fnature%2FMograsimBuilder.java;fp=net.mograsim.plugin.core%2Fsrc%2Fnet%2Fmograsim%2Fplugin%2Fnature%2FMograsimBuilder.java;h=0000000000000000000000000000000000000000;hb=7d05144c25daa53e60fc9ed9fd503546a86567f8;hp=9fc0ea419a03cb7dddbcfd3a7a2a8ffa85d3ec3c;hpb=8bed58cd47f4e53a0a83e066d38864aa6875502f;p=Mograsim.git diff --git a/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MograsimBuilder.java b/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MograsimBuilder.java deleted file mode 100644 index 9fc0ea41..00000000 --- a/net.mograsim.plugin.core/src/net/mograsim/plugin/nature/MograsimBuilder.java +++ /dev/null @@ -1,195 +0,0 @@ -package net.mograsim.plugin.nature; - -import java.util.Map; - -import javax.xml.parsers.ParserConfigurationException; -import javax.xml.parsers.SAXParser; -import javax.xml.parsers.SAXParserFactory; - -import org.eclipse.core.resources.IFile; -import org.eclipse.core.resources.IMarker; -import org.eclipse.core.resources.IProject; -import org.eclipse.core.resources.IResource; -import org.eclipse.core.resources.IResourceDelta; -import org.eclipse.core.resources.IResourceDeltaVisitor; -import org.eclipse.core.resources.IResourceVisitor; -import org.eclipse.core.resources.IncrementalProjectBuilder; -import org.eclipse.core.runtime.CoreException; -import org.eclipse.core.runtime.IProgressMonitor; -import org.xml.sax.SAXException; -import org.xml.sax.SAXParseException; -import org.xml.sax.helpers.DefaultHandler; - -public class MograsimBuilder extends IncrementalProjectBuilder -{ - - class SampleDeltaVisitor implements IResourceDeltaVisitor - { - @Override - public boolean visit(IResourceDelta delta) throws CoreException - { - IResource resource = delta.getResource(); - switch (delta.getKind()) - { - case IResourceDelta.ADDED: - // handle added resource - checkXML(resource); - break; - case IResourceDelta.REMOVED: - // handle removed resource - break; - case IResourceDelta.CHANGED: - // handle changed resource - checkXML(resource); - break; - } - // return true to continue visiting children. - return true; - } - } - - class SampleResourceVisitor implements IResourceVisitor - { - public boolean visit(IResource resource) - { - checkXML(resource); - // return true to continue visiting children. - return true; - } - } - - class XMLErrorHandler extends DefaultHandler - { - - private IFile file; - - public XMLErrorHandler(IFile file) - { - this.file = file; - } - - private void addMarker(SAXParseException e, int severity) - { - MograsimBuilder.this.addMarker(file, e.getMessage(), e.getLineNumber(), severity); - } - - public void error(SAXParseException exception) throws SAXException - { - addMarker(exception, IMarker.SEVERITY_ERROR); - } - - public void fatalError(SAXParseException exception) throws SAXException - { - addMarker(exception, IMarker.SEVERITY_ERROR); - } - - public void warning(SAXParseException exception) throws SAXException - { - addMarker(exception, IMarker.SEVERITY_WARNING); - } - } - - public static final String BUILDER_ID = "PluginTest.mograsimBuilder"; - - private static final String MARKER_TYPE = "PluginTest.xmlProblem"; - - private SAXParserFactory parserFactory; - - private void addMarker(IFile file, String message, int lineNumber, int severity) - { - try - { - IMarker marker = file.createMarker(MARKER_TYPE); - marker.setAttribute(IMarker.MESSAGE, message); - marker.setAttribute(IMarker.SEVERITY, severity); - if (lineNumber == -1) - { - lineNumber = 1; - } - marker.setAttribute(IMarker.LINE_NUMBER, lineNumber); - } - catch (CoreException e) - { - } - } - - @Override - protected IProject[] build(int kind, Map args, IProgressMonitor monitor) throws CoreException - { - if (kind == FULL_BUILD) - { - fullBuild(monitor); - } else - { - IResourceDelta delta = getDelta(getProject()); - if (delta == null) - { - fullBuild(monitor); - } else - { - incrementalBuild(delta, monitor); - } - } - return null; - } - - protected void clean(IProgressMonitor monitor) throws CoreException - { - // delete markers set and files created - getProject().deleteMarkers(MARKER_TYPE, true, IResource.DEPTH_INFINITE); - } - - void checkXML(IResource resource) - { - if (resource instanceof IFile && resource.getName().endsWith(".xml")) - { - IFile file = (IFile) resource; - deleteMarkers(file); - XMLErrorHandler reporter = new XMLErrorHandler(file); - try - { - getParser().parse(file.getContents(), reporter); - } - catch (Exception e1) - { - } - } - } - - private void deleteMarkers(IFile file) - { - try - { - file.deleteMarkers(MARKER_TYPE, false, IResource.DEPTH_ZERO); - } - catch (CoreException ce) - { - } - } - - protected void fullBuild(final IProgressMonitor monitor) throws CoreException - { - try - { - getProject().accept(new SampleResourceVisitor()); - } - catch (CoreException e) - { - } - } - - private SAXParser getParser() throws ParserConfigurationException, SAXException - { - if (parserFactory == null) - { - parserFactory = SAXParserFactory.newInstance(); - } - return parserFactory.newSAXParser(); - } - - protected void incrementalBuild(IResourceDelta delta, IProgressMonitor monitor) throws CoreException - { - // the visitor does the work. - delta.accept(new SampleDeltaVisitor()); - } -}