Jump to: navigation, search

Difference between revisions of "FAQ How do I implement an incremental project builder?"

 
m (Minor indention correction)
 
(One intermediate revision by one other user not shown)
Line 33: Line 33:
 
         }
 
         }
 
         return null;
 
         return null;
    }   
+
      }   
 
       private void incrementalBuild(IResourceDelta delta,  
 
       private void incrementalBuild(IResourceDelta delta,  
 
       IProgressMonitor monitor) {
 
       IProgressMonitor monitor) {
Line 41: Line 41:
 
               public boolean visit(IResourceDelta delta) {
 
               public boolean visit(IResourceDelta delta) {
 
                   System.out.println("changed: "+
 
                   System.out.println("changed: "+
                    delta.getResource().getRawLocation());
+
                  delta.getResource().getRawLocation());
 
                   return true; // visit children too
 
                   return true; // visit children too
 
               }
 
               }
Line 60: Line 60:
  
 
== See Also: ==
 
== See Also: ==
[[FAQ_How_do_I_handle_setup_problems_for_a_given_builder%3F]]
+
[[FAQ How do I handle setup problems for a given builder?]]
  
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>
 
<hr><font size=-2>This FAQ was originally published in [http://www.eclipsefaq.org Official Eclipse 3.0 FAQs]. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the [http://www.eclipse.org/legal/epl-v10.html Eclipse Public License v1.0].</font>

Latest revision as of 02:44, 2 May 2012

To implement an incremental project builder, you first have to create an extension for org.eclipse.core.resources.builders:

   <extension 
         id="Builder" 
         name="eScript Builder" 
         point="org.eclipse.core.resources.builders">
      <builder>
         <run class="org.eclipse.escript.builder.Builder">
            <parameter name="optimize" value="true"/>
            <parameter name="comment" value="escript Builder"/>
         </run>
      </builder>
   </extension>


The second step is to create a builder class that must extend the abstract IncrementalProjectBuilder superclass:

   public class Builder extends IncrementalProjectBuilder {   
      protected IProject[] build(int kind, Map args, 
       IProgressMonitor monitor) {
         if (kind == IncrementalProjectBuilder.FULL_BUILD) {
            fullBuild(monitor);
         } else {
            IResourceDelta delta = getDelta(getProject());
            if (delta == null) {
               fullBuild(monitor);
            } else {
               incrementalBuild(delta, monitor);
            }
         }
         return null;
      }   
      private void incrementalBuild(IResourceDelta delta, 
       IProgressMonitor monitor) {
         System.out.println("incremental build on "+delta);
         try {
            delta.accept(new IResourceDeltaVisitor() {
               public boolean visit(IResourceDelta delta) {
                  System.out.println("changed: "+
                   delta.getResource().getRawLocation());
                  return true; // visit children too
               }
            });
         } catch (CoreException e) {
            e.printStackTrace();
         }
      }
      private void fullBuild(IProgressMonitor monitor) {
         System.out.println("full build");
      }
   }

It is important to return true in the visit method for those folders that contain the resources of interest. If you return false, the children of the resource delta are not visited.

See Also:

FAQ How do I handle setup problems for a given builder?


This FAQ was originally published in Official Eclipse 3.0 FAQs. Copyright 2004, Pearson Education, Inc. All rights reserved. This text is made available here under the terms of the Eclipse Public License v1.0.