Search in sources :

Example 1 with IProjectConfiguration

use of net.sf.eclipsecs.core.projectconfig.IProjectConfiguration in project eclipse-cs by checkstyle.

the class CheckstyleBuilder method build.

/**
 * {@inheritDoc}
 */
@Override
protected final IProject[] build(final int kind, @SuppressWarnings("rawtypes") final Map args, final IProgressMonitor monitor) throws CoreException {
    // get the associated project for this builder
    IProject project = getProject();
    // remove project level error markers
    project.deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_ZERO);
    if (CheckstyleNature.hasCorrectBuilderOrder(project)) {
        // 
        // get the project configuration
        // 
        IProjectConfiguration config = null;
        try {
            config = ProjectConfigurationFactory.getConfiguration(project);
        } catch (CheckstylePluginException e) {
            Status status = new Status(IStatus.ERROR, CheckstylePlugin.PLUGIN_ID, IStatus.ERROR, e.getMessage() != null ? e.getMessage() : Messages.CheckstyleBuilder_msgErrorUnknown, e);
            throw new CoreException(status);
        }
        Collection<IResource> resources = null;
        // get the delta of the latest changes
        IResourceDelta resourceDelta = getDelta(project);
        IFilter[] filters = config.getFilters().toArray(new IFilter[config.getFilters().size()]);
        // find the files for the build
        if (resourceDelta != null) {
            resources = getResources(resourceDelta, filters);
        } else {
            resources = getResources(project, filters);
        }
        handleBuildSelection(resources, config, monitor, project, kind);
    } else {
        // the builder order is wrong. Refuse to check and create a error
        // marker.
        // remove all existing Checkstyle markers
        project.deleteMarkers(CheckstyleMarker.MARKER_ID, false, IResource.DEPTH_INFINITE);
        Map<String, Object> markerAttributes = new HashMap<>();
        markerAttributes.put(IMarker.PRIORITY, new Integer(IMarker.PRIORITY_HIGH));
        markerAttributes.put(IMarker.SEVERITY, new Integer(IMarker.SEVERITY_ERROR));
        markerAttributes.put(IMarker.MESSAGE, NLS.bind(Messages.CheckstyleBuilder_msgWrongBuilderOrder, project.getName()));
        // enables own category under Java Problem Type
        // setting for Problems view (RFE 1530366)
        // $NON-NLS-1$
        markerAttributes.put("categoryId", new Integer(999));
        // create a marker for the actual resource
        IMarker marker = project.createMarker(CheckstyleMarker.MARKER_ID);
        marker.setAttributes(markerAttributes);
    }
    return new IProject[] { project };
}
Also used : IStatus(org.eclipse.core.runtime.IStatus) Status(org.eclipse.core.runtime.Status) HashMap(java.util.HashMap) IProjectConfiguration(net.sf.eclipsecs.core.projectconfig.IProjectConfiguration) IProject(org.eclipse.core.resources.IProject) CoreException(org.eclipse.core.runtime.CoreException) IFilter(net.sf.eclipsecs.core.projectconfig.filters.IFilter) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) IMarker(org.eclipse.core.resources.IMarker) IResource(org.eclipse.core.resources.IResource) IResourceDelta(org.eclipse.core.resources.IResourceDelta)

Example 2 with IProjectConfiguration

use of net.sf.eclipsecs.core.projectconfig.IProjectConfiguration in project eclipse-cs by checkstyle.

the class RunCheckstyleOnFilesJob method runInWorkspace.

/**
 * {@inheritDoc}
 */
@Override
public final IStatus runInWorkspace(final IProgressMonitor monitor) throws CoreException {
    try {
        Map<IProject, List<IFile>> projectFilesMap = getFilesSortedToProject(mFilesToCheck);
        for (Map.Entry<IProject, List<IFile>> entry : projectFilesMap.entrySet()) {
            IProject project = entry.getKey();
            List<IFile> files = entry.getValue();
            IProjectConfiguration checkConfig = ProjectConfigurationFactory.getConfiguration(project);
            filter(files, checkConfig);
            CheckstyleBuilder builder = new CheckstyleBuilder();
            builder.handleBuildSelection(files, checkConfig, monitor, project, IncrementalProjectBuilder.INCREMENTAL_BUILD);
        }
    } catch (CheckstylePluginException e) {
        Status status = new Status(IStatus.ERROR, CheckstylePlugin.PLUGIN_ID, IStatus.ERROR, e.getLocalizedMessage(), e);
        throw new CoreException(status);
    }
    return Status.OK_STATUS;
}
Also used : Status(org.eclipse.core.runtime.Status) IStatus(org.eclipse.core.runtime.IStatus) IFile(org.eclipse.core.resources.IFile) CoreException(org.eclipse.core.runtime.CoreException) CheckstyleBuilder(net.sf.eclipsecs.core.builder.CheckstyleBuilder) IProjectConfiguration(net.sf.eclipsecs.core.projectconfig.IProjectConfiguration) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) IProject(org.eclipse.core.resources.IProject)

Example 3 with IProjectConfiguration

use of net.sf.eclipsecs.core.projectconfig.IProjectConfiguration in project eclipse-cs by checkstyle.

the class GlobalCheckConfigurationWorkingSet method updateProjectConfigurations.

/**
 * Updates the project configurations that use the changed check configurations.
 *
 * @param configurations
 *          the check configurations
 * @throws CheckstylePluginException
 *           an unexpected exception occurred
 */
private void updateProjectConfigurations() throws CheckstylePluginException {
    for (CheckConfigurationWorkingCopy checkConfig : mWorkingCopies) {
        ICheckConfiguration original = checkConfig.getSourceCheckConfiguration();
        // only if the name of the check config differs from the original
        if (original != null && original.getName() != null && !checkConfig.getName().equals(original.getName())) {
            List<IProject> projects = ProjectConfigurationFactory.getProjectsUsingConfig(checkConfig);
            for (IProject project : projects) {
                IProjectConfiguration projectConfig = ProjectConfigurationFactory.getConfiguration(project);
                ProjectConfigurationWorkingCopy workingCopy = new ProjectConfigurationWorkingCopy(projectConfig);
                List<FileSet> fileSets = workingCopy.getFileSets();
                for (FileSet fileSet : fileSets) {
                    // Check if the fileset uses the check config
                    if (original.equals(fileSet.getCheckConfig())) {
                        // set the new check configuration
                        fileSet.setCheckConfig(checkConfig);
                    }
                }
                // store the project configuration
                if (workingCopy.isDirty()) {
                    workingCopy.store();
                }
            }
        }
    }
}
Also used : FileSet(net.sf.eclipsecs.core.projectconfig.FileSet) IProjectConfiguration(net.sf.eclipsecs.core.projectconfig.IProjectConfiguration) ProjectConfigurationWorkingCopy(net.sf.eclipsecs.core.projectconfig.ProjectConfigurationWorkingCopy) IProject(org.eclipse.core.resources.IProject)

Example 4 with IProjectConfiguration

use of net.sf.eclipsecs.core.projectconfig.IProjectConfiguration in project eclipse-cs by checkstyle.

the class CheckstylePropertyPage method setElement.

/**
 * {@inheritDoc}
 */
@Override
public void setElement(IAdaptable element) {
    super.setElement(element);
    IProject project = null;
    try {
        // 
        // Get the project.
        // 
        IResource resource = (IResource) element;
        if (resource.getType() == IResource.PROJECT) {
            project = (IProject) resource;
        }
        IProjectConfiguration projectConfig = ProjectConfigurationFactory.getConfiguration(project);
        mProjectConfig = new ProjectConfigurationWorkingCopy(projectConfig);
        mCheckstyleInitiallyActivated = project.hasNature(CheckstyleNature.NATURE_ID);
    } catch (CoreException e) {
        handleConfigFileError(e, project);
    } catch (CheckstylePluginException e) {
        handleConfigFileError(e, project);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IProjectConfiguration(net.sf.eclipsecs.core.projectconfig.IProjectConfiguration) CheckstylePluginException(net.sf.eclipsecs.core.util.CheckstylePluginException) ProjectConfigurationWorkingCopy(net.sf.eclipsecs.core.projectconfig.ProjectConfigurationWorkingCopy) IProject(org.eclipse.core.resources.IProject) IResource(org.eclipse.core.resources.IResource)

Example 5 with IProjectConfiguration

use of net.sf.eclipsecs.core.projectconfig.IProjectConfiguration in project eclipse-cs by checkstyle.

the class CheckstylePropertyPage method handleConfigFileError.

private void handleConfigFileError(Exception e, IProject project) {
    CheckstyleLog.log(e, Messages.errorOpeningPropertiesPage);
    CheckstyleUIPlugin.warningDialog(null, Messages.errorOpeningPropertiesPage, e);
    IProjectConfiguration projectConfig = ProjectConfigurationFactory.createDefaultProjectConfiguration(project);
    mProjectConfig = new ProjectConfigurationWorkingCopy(projectConfig);
    try {
        mCheckstyleInitiallyActivated = project.hasNature(CheckstyleNature.NATURE_ID);
    } catch (CoreException e1) {
        CheckstyleUIPlugin.errorDialog(null, e1.getMessage(), e1, true);
    }
}
Also used : CoreException(org.eclipse.core.runtime.CoreException) IProjectConfiguration(net.sf.eclipsecs.core.projectconfig.IProjectConfiguration) ProjectConfigurationWorkingCopy(net.sf.eclipsecs.core.projectconfig.ProjectConfigurationWorkingCopy)

Aggregations

IProjectConfiguration (net.sf.eclipsecs.core.projectconfig.IProjectConfiguration)7 CoreException (org.eclipse.core.runtime.CoreException)6 CheckstylePluginException (net.sf.eclipsecs.core.util.CheckstylePluginException)5 IProject (org.eclipse.core.resources.IProject)5 ProjectConfigurationWorkingCopy (net.sf.eclipsecs.core.projectconfig.ProjectConfigurationWorkingCopy)3 IStatus (org.eclipse.core.runtime.IStatus)3 Status (org.eclipse.core.runtime.Status)3 ArrayList (java.util.ArrayList)2 HashMap (java.util.HashMap)2 FileSet (net.sf.eclipsecs.core.projectconfig.FileSet)2 IFilter (net.sf.eclipsecs.core.projectconfig.filters.IFilter)2 IResource (org.eclipse.core.resources.IResource)2 PropertyResolver (com.puppycrawl.tools.checkstyle.PropertyResolver)1 CheckstyleException (com.puppycrawl.tools.checkstyle.api.CheckstyleException)1 Configuration (com.puppycrawl.tools.checkstyle.api.Configuration)1 List (java.util.List)1 Map (java.util.Map)1 CheckstyleBuilder (net.sf.eclipsecs.core.builder.CheckstyleBuilder)1 CheckstyleConfigurationFile (net.sf.eclipsecs.core.config.CheckstyleConfigurationFile)1 ICheckConfiguration (net.sf.eclipsecs.core.config.ICheckConfiguration)1