Package tool.builder

Source Code of tool.builder.FscriptBuilder$ToolDeltaVisitor

package tool.builder;

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;

import tool.ToolBuilderActivator;

public class FscriptBuilder extends IncrementalProjectBuilder {

  class ToolDeltaVisitor implements IResourceDeltaVisitor {
    /*
     * (non-Javadoc)
     *
     * @see org.eclipse.core.resources.IResourceDeltaVisitor#visit(org.eclipse.core.resources.IResourceDelta)
     */
    public boolean visit(IResourceDelta delta) throws CoreException {
      IResource resource = delta.getResource();
      switch (delta.getKind()) {
      case IResourceDelta.ADDED:
        // handle added resource
        checkTool(resource);
        break;
      case IResourceDelta.REMOVED:
        // handle removed resource
        break;
      case IResourceDelta.CHANGED:
        // handle changed resource
        checkTool(resource);
        break;
      }
      //return true to continue visiting children.
      return true;
    }
  }

  class ToolResourceVisitor implements IResourceVisitor {
    public boolean visit(IResource resource) {
      checkTool(resource);
      //return true to continue visiting children.
      return true;
    }
  }


  public static final String BUILDER_ID = "ToolBuilder.FscriptBuilder";

  public static final String MARKER_TYPE = "ToolBuilder.ToolError";

  private SAXParserFactory parserFactory;

  private FScript fscript;


  /*
   * (non-Javadoc)
   *
   * @see org.eclipse.core.internal.events.InternalBuilder#build(int,
   *      java.util.Map, org.eclipse.core.runtime.IProgressMonitor)
   */
  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;
  }

  void checkTool(IResource resource) {
    if (resource instanceof IFile && resource.getName().endsWith(".CLA")) { //TODO add other file extensions
      IFile file = (IFile) resource;
      deleteMarkers(file);
      FscriptErrorHandler reporter = new FscriptErrorHandler(file);
      try {
        getFScript(file).compilePlanComponent(file.getParent().getName(), file.getFullPath().toOSString(), reporter);
      } catch (CoreException e) {
        ToolBuilderActivator.showError("FScript error", e);
      } catch (InvalidToolRepositoryException e) {
        ToolBuilderActivator.showError("FScript error", e);
      } catch (ToolSystemException e) {
        ToolBuilderActivator.showError("FScript error", e);
      }
    }
  }

  private void deleteMarkers(IFile file) {
    try {
      file.deleteMarkers(MARKER_TYPE, false, IResource.DEPTH_ZERO);
    } catch (CoreException ce) {
    }
  }
  protected FScript getFScript(IFile file) throws CoreException{
    if (this.fscript == null){
      IProject project = file.getProject();
      this.fscript = new FScript(project.getPersistentProperty(ToolNature.forteRootQualifiedName),
          project.getPersistentProperty(ToolNature.reposQualifiedName),
          project.getPersistentProperty(ToolNature.workspaceQualifiedName),
          project.getPersistentProperty(ToolNature.worspacePasswordQualifiedName),
          project.getPersistentProperty(ToolNature.loggerQualifiedName),
          false);
    }
    return this.fscript;
  }
  protected void fullBuild(final IProgressMonitor monitor)
      throws CoreException {
    try {
      getProject().accept(new ToolResourceVisitor());
    } catch (CoreException e) {
    }
  }

  protected void incrementalBuild(IResourceDelta delta,
      IProgressMonitor monitor) throws CoreException {
    // the visitor does the work.
    delta.accept(new ToolDeltaVisitor());
  }
}
TOP

Related Classes of tool.builder.FscriptBuilder$ToolDeltaVisitor

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.