use of org.sonarlint.eclipse.core.internal.resources.ExclusionItem in project sonarlint-eclipse by SonarSource.
the class SonarLintGlobalConfigurationTest method should_serialize_file_exclusions.
@Test
public void should_serialize_file_exclusions() {
var list = List.of(new ExclusionItem(Type.FILE, "file"), new ExclusionItem(Type.DIRECTORY, "dir"));
var serialized = SonarLintGlobalConfiguration.serializeFileExclusions(list);
var desList = SonarLintGlobalConfiguration.deserializeFileExclusions(serialized);
assertThat(desList).isEqualTo(list);
}
use of org.sonarlint.eclipse.core.internal.resources.ExclusionItem in project sonarlint-eclipse by SonarSource.
the class EditProjectExclusionDialog method selectFile.
/**
* Opens a dialog where the user can select a file path.
*/
private void selectFile() {
ISelectionStatusValidator validator = arr -> {
if (arr.length > 1) {
return ValidationStatus.error("Only one file can be selected");
}
if (arr.length == 0) {
return ValidationStatus.ok();
}
Object obj = arr[0];
ISonarLintFile file = Adapters.adapt(obj, ISonarLintFile.class);
return file != null ? ValidationStatus.ok() : ValidationStatus.error("Select a file");
};
var viewFilter = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IFolder) {
var folder = (IFolder) element;
return SonarLintUtils.isSonarLintFileCandidate(folder);
}
if (element instanceof IFile) {
var file = Adapters.adapt(element, ISonarLintFile.class);
return file != null;
}
return false;
}
};
var lp = new WorkbenchLabelProvider();
var cp = new WorkbenchContentProvider();
var dialog = new ElementTreeSelectionDialog(getShell(), lp, cp);
dialog.setTitle("Select File");
dialog.setInput(project.getResource());
dialog.setAllowMultiple(false);
dialog.addFilter(viewFilter);
dialog.setValidator(validator);
dialog.setMessage("Select a project file to be excluded from SonarLint analysis");
if (editItem != null) {
dialog.setInitialSelection(editItem.item());
}
if (dialog.open() == Window.OK) {
var obj = dialog.getFirstResult();
var file = Adapters.adapt(obj, ISonarLintFile.class);
if (file != null) {
editItem = new ExclusionItem(Type.FILE, file.getProjectRelativePath());
fileField.setText(editItem.item());
}
}
}
use of org.sonarlint.eclipse.core.internal.resources.ExclusionItem in project sonarlint-eclipse by SonarSource.
the class EditProjectExclusionDialog method selectFolder.
/**
* Opens a dialog where the user can select a folder path.
*/
private void selectFolder() {
ISelectionStatusValidator validator = arr -> {
if (arr.length > 1) {
return ValidationStatus.error("Only one folder can be selected");
}
if (arr.length == 0) {
return ValidationStatus.ok();
}
var obj = arr[0];
return (obj instanceof IFolder) ? ValidationStatus.ok() : ValidationStatus.error("Select a folder");
};
var viewFilter = new ViewerFilter() {
@Override
public boolean select(Viewer viewer, Object parentElement, Object element) {
if (element instanceof IFolder) {
IFolder folder = (IFolder) element;
return SonarLintUtils.isSonarLintFileCandidate(folder);
}
return false;
}
};
var lp = new WorkbenchLabelProvider();
var cp = new WorkbenchContentProvider();
var dialog = new ElementTreeSelectionDialog(getShell(), lp, cp);
dialog.setTitle("Select Folder");
dialog.setInput(project.getResource());
dialog.setAllowMultiple(false);
dialog.addFilter(viewFilter);
dialog.setValidator(validator);
dialog.setMessage("Select a project folder to be excluded from SonarLint analysis");
if (editItem != null) {
dialog.setInitialSelection(editItem.item());
}
if (dialog.open() == Window.OK) {
var obj = dialog.getFirstResult();
var folder = (IFolder) obj;
if (folder != null) {
editItem = new ExclusionItem(Type.DIRECTORY, folder.getProjectRelativePath().toString());
directoryField.setText(editItem.item());
}
}
}
use of org.sonarlint.eclipse.core.internal.resources.ExclusionItem in project sonarlint-eclipse by SonarSource.
the class FileExclusionsPage method edit.
@Override
protected void edit() {
var exclusion = (ExclusionItem) table.getStructuredSelection().getFirstElement();
EditExclusionDialog dialog;
if (isGlobal()) {
dialog = new EditGlobalExclusionDialog(shell, exclusion.item());
} else {
dialog = new EditProjectExclusionDialog(getProject(), shell, exclusion);
}
// opens the dialog - just returns if the user cancels it
if (dialog.open() == Window.CANCEL) {
return;
}
var newExclusion = dialog.get();
if (newExclusion != null) {
var index = exclusions.indexOf(exclusion);
exclusions.set(index, newExclusion);
table.setSelection(new StructuredSelection(newExclusion));
table.refresh();
}
}
Aggregations