Compilers (and every other kind of translator) in Eclipse are implemented with builders. These are notified when a file or a set of files are changed and can take appropriate action. In the case of the Java builder, it translates the .java
source files into the .class
files. Perform the following steps:
minimark.ui
project's .project
file. This is visible in the Navigator view, but not in the Package Explorer or other views. Builders are associated to a project within the .project
file. The builder ID is referenced via buildCommand
, for example have a look at the following code:<projectDescription> <name>com.packtpub.e4.minimark.ui</name> <buildSpec> <buildCommand> <name>org.eclipse.jdt.core.javabuilder</name> </buildCommand> ...
.minimark
file into HTML automatically, a builder is needed. A builder is a class that extends IncrementalProjectBuilder
and implements a build()
method. This is called by the framework when files are saved and either gives a list of changed files or asks that the full project is built. Since this is defined in the core resources bundle, open plugin.xml
and add the org.eclipse.core.resources
bundle to plugin.xml
in the dependency list.com.packtpub.e4.minimark.ui
package called MinimarkBuilder
:public class MinimarkBuilder extends IncrementalProjectBuilder { protected IProject[] build(int kind, Map<String, String> args,IProgressMonitor monitor) throws CoreException { return null; } }
FULL_BUILD
there's also a resource delta, which contains the set of resources that have been changed. Calculating a resource delta is a non-free operation so should only be done if needed. The build()
method is typically implemented as follows:protected IProject[] build(int kind, Map<String, String> args,IProgressMonitor monitor) throws CoreException { if (kind == FULL_BUILD) { fullBuild(getProject(), monitor); } else { incrementalBuild(getProject(), monitor,getDelta(getProject())); } return null; }
fullBuild()
and incrementalBuild()
methods need to be defined. It is also necessary to handle the case where getDelta()
returns a null
value, and invoke the full builder accordingly:private void incrementalBuild(IProject project, IProgressMonitormonitor, IResourceDelta delta) throws CoreException { if (delta == null) { fullBuild(project, monitor); } else { System.out.println("Doing an incremental build"); } } private void fullBuild(IProject project, IProgressMonitor monitor)throws CoreException { System.out.println("Doing a full build"); }
org.eclipse.core.resources.builders
. This defines a reference (via an ID) to a class that implements IncrementalProjectBuilder
. Add the following code to plugin.xml
:<extension id="MinimarkBuilder"point="org.eclipse.core.resources.builders"><buildercallOnEmptyDelta="false"hasNature="false"isConfigurable="false"supportsConfigurations="false"> <run class="com.packtpub.e4.minimark.ui.MinimarkBuilder"/> </builder> </extension>
.project
file. Add the builder manually by adding in a buildCommand
with the ID from the extension point:<buildSpec> <buildCommand> <name>com.packtpub.e4.minimark.ui.MinimarkBuilder</name> </buildCommand> </buildSpec>
.minimark
file, and the message Doing an incremental build should be displayed.The builder is capable of being invoked when files in a project are changed. To associate the builder with the project, it was added as a build command to the project, which is contained in the .project
file. The name used for the builder is the extension's unique ID, which is formed as a dot-separated concatenation of the plug-in's ID and the element in the plugin.xml
file.
The incremental builder has a standard pattern which allows an implementation to determine if it is doing a full or incremental build. There is also a clean()
method (which wasn't implemented here) that is used to remove all resources that have been created by a builder.