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 .java
source files into .class
files.
.project
file in the com.packtpub.e4.minimark.ui
project. This is visible in the Navigator view, but not in the Package Explorer or other views. Alternatively, use Cmd + Shift + R on macOS (or Ctrl + Shift + R on other platforms) to open the resource by name. Builders are associated to a project within the .project
file. The builder ID is referenced via the buildCommand
, for example:<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 requests that the full project is built. Since this is defined in the core resources bundle, open the plugin.xml
file and add the org.eclipse.core.resources
bundle to 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 costly operation, so it should only be accessed 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 cases where the getDelta
method returns a null
value, and invoke the full builder accordingly:private void incrementalBuild(IProject project, IProgressMonitor monitor, 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 the IncrementalProjectBuilder
. Add the following to the plugin.xml
file:<extension id="MinimarkBuilder" point="org.eclipse.core.resources.builders"> <builder callOnEmptyDelta="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 kind that allows an implementation to determine whether 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.
3.144.12.14