use of net.sf.eclipsecs.core.jobs.AuditorJob in project eclipse-cs by checkstyle.
the class CheckstyleBuilder method handleBuildSelection.
/**
* Builds the selected resources.
*
* @param resources
* the resourcesto build
* @param configuration
* the project configuration
* @param monitor
* the progress monitor
* @param project
* the built project
* @param kind
* the kind of build
* @param <T>
* the resource type parameter
* @throws CoreException
* if the build fails
*/
public final <T extends IResource> void handleBuildSelection(final Collection<T> resources, final IProjectConfiguration configuration, final IProgressMonitor monitor, final IProject project, final int kind) throws CoreException {
// on full build remove all previous checkstyle markers
if (kind == IncrementalProjectBuilder.FULL_BUILD) {
project.deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_INFINITE);
}
boolean backgroundFullBuild = CheckstylePluginPrefs.getBoolean(CheckstylePluginPrefs.PREF_BACKGROUND_FULL_BUILD);
try {
//
// Build a set of auditors from the file sets of this project
// configuration.
// File sets that share the same check configuration merge into
// one Auditor.
//
List<FileSet> fileSets = configuration.getFileSets();
Map<ICheckConfiguration, Auditor> audits = new HashMap<>();
for (FileSet fileSet : fileSets) {
// skip not enabled filesets
if (!fileSet.isEnabled()) {
continue;
}
ICheckConfiguration checkConfig = fileSet.getCheckConfig();
if (checkConfig == null) {
throw new CheckstylePluginException(NLS.bind(Messages.errorNoCheckConfig, project.getName()));
}
// get an already created audit from the map
Auditor audit = audits.get(checkConfig);
// create the audit with the file sets check configuration
if (audit == null) {
audit = new Auditor(checkConfig);
audits.put(checkConfig, audit);
}
// check which files belong to the file set
for (IResource resource : resources) {
if (resource instanceof IFile) {
IFile file = (IFile) resource;
// if file set includes file add to the audit
if (fileSet.includesFile(file)) {
audit.addFile(file);
// remove markers on this file
file.deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_ZERO);
// remove markers from package to prevent
// packagehtml messages from accumulatin
file.getParent().deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_ZERO);
}
}
}
}
// run all auditors
for (Auditor audit : audits.values()) {
if (monitor.isCanceled()) {
throw new OperationCanceledException();
}
if (backgroundFullBuild && kind == FULL_BUILD) {
AuditorJob j = new AuditorJob(project, audit);
j.schedule();
} else {
audit.runAudit(project, monitor);
}
}
} catch (CheckstylePluginException e) {
Status status = new Status(IStatus.ERROR, CheckstylePlugin.PLUGIN_ID, IStatus.ERROR, e.getLocalizedMessage(), e);
throw new CoreException(status);
}
}
Aggregations