Time for action – implementing incremental builds

The final part of the puzzle is to implement the incremental part of the builder. Most of the builds that Eclipse performs are incremental, which means that it only compiles the files that are needed at each point. An incremental build gives a resource delta, which contains which files have been modified, added, or removed. This is implemented in an IResourceDelta interface, which is handed to the IResourceDeltaVisitor method visit. A resource delta combines an IResource instance with a flag that says whether it was added or removed.

  1. Open the MinimarkVisitor and go to the visit(IResourceDelta) method. This is used by the incremental build when individual files are changed. Since the delta already has a resource, it can be used to determine whether the file is relevant, and if so, pass it to the processResource method:
    public boolean visit(IResourceDelta delta) throws CoreException {
      IResource resource = delta.getResource();
      if(resource.getName().endsWith(".minimark")) {
        processResource(resource);
      }
      return true;
    }
  2. Run the target Eclipse instance, and edit and save the .minimark file. The builder's incremental builder will be invoked, with the given resource, and the file will be updated. Eclipse's HTML editor won't automatically refresh the change, but if the .html file is opened with a text editor, a side-by-side view shows that the file is being updated with each save.

What just happened?

An incremental build and a full build are very similar; they both process a set of resources. In the former case, it's the set of files that were changed in a workspace update operation (such as a Save or Save All). In the latter case, it's all files in an individual project. Refactoring to a common processResource method allows the implementation to be written once and then called from either situation.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.146.178.245