use of net.sf.eclipsecs.core.config.ICheckConfiguration in project eclipse-cs by checkstyle.
the class CheckConfigurationWorkingSetEditor method copyCheckConfig.
/**
* Copy an existing config.
*/
private void copyCheckConfig() {
IStructuredSelection selection = (IStructuredSelection) mViewer.getSelection();
ICheckConfiguration sourceConfig = (ICheckConfiguration) selection.getFirstElement();
if (sourceConfig == null) {
//
return;
}
try {
// Open the properties dialog to change default name and description
CheckConfigurationPropertiesDialog dialog = new CheckConfigurationPropertiesDialog(getShell(), null, mWorkingSet);
dialog.setTemplateConfiguration(sourceConfig);
dialog.setBlockOnOpen(true);
if (Window.OK == dialog.open()) {
CheckConfigurationWorkingCopy newConfig = dialog.getCheckConfiguration();
// Copy the source configuration into the new internal config
CheckConfigurationFactory.copyConfiguration(sourceConfig, newConfig);
mWorkingSet.addCheckConfiguration(newConfig);
mViewer.setInput(mWorkingSet.getWorkingCopies());
mViewer.refresh();
}
} catch (CheckstylePluginException e) {
CheckstyleUIPlugin.errorDialog(getShell(), e, true);
}
}
use of net.sf.eclipsecs.core.config.ICheckConfiguration 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);
}
}
use of net.sf.eclipsecs.core.config.ICheckConfiguration in project eclipse-cs by checkstyle.
the class CheckConfigurationLabelProvider method getText.
/**
* {@inheritDoc}
*/
@Override
public String getText(Object element) {
String text = super.getText(element);
if (element instanceof ICheckConfiguration) {
ICheckConfiguration checkConfig = (ICheckConfiguration) element;
text = // $NON-NLS-1$
checkConfig.getName() + " " + (checkConfig.isGlobal() ? Messages.CheckConfigurationLabelProvider_suffixGlobal : Messages.CheckConfigurationLabelProvider_suffixLocal);
}
return text;
}
use of net.sf.eclipsecs.core.config.ICheckConfiguration in project eclipse-cs by checkstyle.
the class CheckConfigurationViewerSorter method compare.
/**
* {@inheritDoc}
*/
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
int result = 0;
if ((e1 instanceof ICheckConfiguration) && (e2 instanceof ICheckConfiguration)) {
ICheckConfiguration cfg1 = (ICheckConfiguration) e1;
ICheckConfiguration cfg2 = (ICheckConfiguration) e2;
String string1 = cfg1.getName();
String string2 = cfg2.getName();
result = string1.compareToIgnoreCase(string2);
}
return result;
}
use of net.sf.eclipsecs.core.config.ICheckConfiguration in project eclipse-cs by checkstyle.
the class ProjectConfigurationFactory method getLocalCheckConfigs.
@SuppressWarnings("unchecked")
private static List<ICheckConfiguration> getLocalCheckConfigs(Element root, IProject project) {
List<ICheckConfiguration> configurations = new ArrayList<>();
List<Element> configElements = root.elements(XMLTags.CHECK_CONFIG_TAG);
for (Element configEl : configElements) {
final String name = configEl.attributeValue(XMLTags.NAME_TAG);
final String description = configEl.attributeValue(XMLTags.DESCRIPTION_TAG);
String location = configEl.attributeValue(XMLTags.LOCATION_TAG);
String type = configEl.attributeValue(XMLTags.TYPE_TAG);
IConfigurationType configType = ConfigurationTypes.getByInternalName(type);
if (configType instanceof ProjectConfigurationType) {
// RFE 1420212
// treat config files relative to *THIS* project
IWorkspaceRoot workspaceRoot = project.getWorkspace().getRoot();
// test if the location contains the project name
if (workspaceRoot.findMember(location) == null) {
location = project.getFullPath().append(location).toString();
}
}
// get resolvable properties
List<ResolvableProperty> props = new ArrayList<>();
List<Element> propertiesElements = configEl.elements(XMLTags.PROPERTY_TAG);
for (Element propsEl : propertiesElements) {
ResolvableProperty prop = new ResolvableProperty(propsEl.attributeValue(XMLTags.NAME_TAG), propsEl.attributeValue(XMLTags.VALUE_TAG));
props.add(prop);
}
// get additional data
Map<String, String> additionalData = new HashMap<>();
List<Element> dataElements = configEl.elements(XMLTags.ADDITIONAL_DATA_TAG);
for (Element dataEl : dataElements) {
additionalData.put(dataEl.attributeValue(XMLTags.NAME_TAG), dataEl.attributeValue(XMLTags.VALUE_TAG));
}
ICheckConfiguration checkConfig = new CheckConfiguration(name, location, description, configType, false, props, additionalData);
configurations.add(checkConfig);
}
return configurations;
}
Aggregations