Search in sources :

Example 1 with AuditorJob

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);
    }
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) IFile(org.eclipse.core.resources.IFile) FileSet(net.sf.eclipsecs.core.projectconfig.FileSet) ICheckConfiguration(net.sf.eclipsecs.core.config.ICheckConfiguration) HashMap(java.util.HashMap) OperationCanceledException(org.eclipse.core.runtime.OperationCanceledException) AuditorJob(net.sf.eclipsecs.core.jobs.AuditorJob) CoreException(org.eclipse.core.runtime.CoreException) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) IResource(org.eclipse.core.resources.IResource)

Aggregations

HashMap (java.util.HashMap)1 ICheckConfiguration (net.sf.eclipsecs.core.config.ICheckConfiguration)1 AuditorJob (net.sf.eclipsecs.core.jobs.AuditorJob)1 FileSet (net.sf.eclipsecs.core.projectconfig.FileSet)1 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)1 IFile (org.eclipse.core.resources.IFile)1 IResource (org.eclipse.core.resources.IResource)1 CoreException (org.eclipse.core.runtime.CoreException)1 IStatus (org.eclipse.core.runtime.IStatus)1 OperationCanceledException (org.eclipse.core.runtime.OperationCanceledException)1 Status (org.eclipse.core.runtime.Status)1