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 };
}
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;
}
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();
}
}
}
}
}
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);
}
}
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);
}
}
Aggregations