diff --git a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java index ef9ff830..7a078e9e 100644 --- a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java +++ b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java @@ -41,7 +41,6 @@ public abstract class BaseUITest { @BeforeClass public static void beforeClass() throws Exception { - // Needed to set CI environment keyboard layout SWTBotPreferences.KEYBOARD_LAYOUT = "EN_US"; diff --git a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/TestUI.java b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/TestUI.java index 4b430839..72daeac1 100644 --- a/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/TestUI.java +++ b/checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/TestUI.java @@ -51,7 +51,6 @@ public void testSuccessfulConnetion() { @Test public void testAddCheckmarxASTPlugin() { - // Add Checkmarx plugin to the eclipse view addCheckmarxPlugin(); @@ -64,7 +63,6 @@ public void testAddCheckmarxASTPlugin() { @Test public void testMissingSetCheckmarxServerUrl() { - // Clear Checkmarx credentials to expect missing Server Url clearCheckmarxCredentials(); @@ -104,7 +102,6 @@ public void testMissingSetCheckmarxServerUrl() { */ @Test public void testEnd2End() throws TimeoutException { - // Set credentials, test connection and add checkmarx plugin setUpCheckmarxPlugin(); @@ -123,7 +120,6 @@ public void testEnd2End() throws TimeoutException { @Test public void testFilterButtonsAndGroupByActionsInToolBar() throws TimeoutException { - // Add Checkmarx AST Plugin addCheckmarxPlugin(); @@ -146,7 +142,6 @@ public void testFilterButtonsAndGroupByActionsInToolBar() throws TimeoutExceptio @Test public void testFilteringAndGroupingResults() throws TimeoutException { - // Set credentials, test connection and add checkmarx plugin setUpCheckmarxPlugin(); @@ -187,9 +182,7 @@ public void testFilteringAndGroupingResults() throws TimeoutException { // Click to include High severity clickSeverityFilter(ActionName.HIGH.name()); currentActiveFilters.add(Severity.HIGH.name()); - - _bot.viewByTitle(VIEW_CHECKMARX_AST_SCAN).viewMenu().menu(ToolBarActions.MENU_GROUP_BY).menu(ToolBarActions.GROUP_BY_QUERY_NAME).click(); - + sleep(1000); String firstNodeName = _bot.tree().cell(0, COLUMN_TITLE); @@ -304,7 +297,6 @@ private List expandTreeUntilFirstEngineAndGetCurrentSeverities() { * Test successful connection */ private void testSuccessfulConnection() { - preventWidgetWasNullInCIEnvironment(); _bot.menu(TAB_WINDOW).menu(ITEM_PREFERENCES).click(); @@ -335,7 +327,6 @@ private void testSuccessfulConnection() { * Add Checkmarx plugin in the show view perspective */ private void addCheckmarxPlugin() { - preventWidgetWasNullInCIEnvironment(); _bot.menu(TAB_WINDOW).menu(ITEM_SHOW_VIEW).menu(ITEM_OTHER).click(); @@ -348,7 +339,6 @@ private void addCheckmarxPlugin() { * Type a valid Scan ID to get results */ private void typeValidScanID() { - preventWidgetWasNullInCIEnvironment(); _bot.textWithLabel(LABEL_SCAN_ID).setText(Environment.SCAN_ID); @@ -359,7 +349,6 @@ private void typeValidScanID() { * Clear all Checkmarx credentials */ private void clearCheckmarxCredentials() { - if (!_cxSettingsDefined) { return; } @@ -403,7 +392,6 @@ private void clearCheckmarxCredentials() { * @throws TimeoutException */ private static void waitWhileTreeNodeEqualsTo(String nodeText) throws TimeoutException { - int retryIdx = 0; while (_bot.tree().getAllItems()[0].getText().equals(nodeText)) { diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/utils/PluginConstants.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/utils/PluginConstants.java index ef3fb78d..5e9e37a2 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/utils/PluginConstants.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/utils/PluginConstants.java @@ -4,4 +4,5 @@ public class PluginConstants { public static final String SAST = "sast"; public static final String SCA_DEPENDENCY = "dependency"; public static final String KICS_INFRASTRUCTURE = "infrastructure"; + public static final String MSG_RETRIEVING_RESULTS = "Retrieving the results for the scan id: %s ."; } diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/utils/PluginUtils.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/utils/PluginUtils.java index a8ac5e96..6951e329 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/utils/PluginUtils.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/utils/PluginUtils.java @@ -16,8 +16,7 @@ public class PluginUtils { private static final String PARAM_TIMESTAMP_PATTERN = "yyyy-MM-dd | HH:mm:ss"; private static final String PARAM_SCAN_ID_VALID_FORMAT = "[a-f0-9]{8}-[a-f0-9]{4}-[1-5][a-f0-9]{3}-[89ab][a-f0-9]{3}-[0-9a-f]{12}"; - - + /** * Converts a String timestamp to a specific format * @@ -25,7 +24,6 @@ public class PluginUtils { * @return */ public static String convertStringTimeStamp(String timestamp) { - String parsedDate = null; try { @@ -41,7 +39,7 @@ public static String convertStringTimeStamp(String timestamp) { return parsedDate; } - + /** * Validate scan id format * @@ -49,44 +47,42 @@ public static String convertStringTimeStamp(String timestamp) { * @return */ public static boolean validateScanIdFormat(String scanId) { - return scanId.matches(PARAM_SCAN_ID_VALID_FORMAT); + return scanId.matches(PARAM_SCAN_ID_VALID_FORMAT); } - + /** * Enables a combo viewer * * @param comboviewer * @param enable */ - public static void enableComboViewer(ComboViewer comboviewer, boolean enable){ + public static void enableComboViewer(ComboViewer comboviewer, boolean enable) { comboviewer.getCombo().setEnabled(enable); } - + /** * Set combo viewer placeholder * * @param comboViewer * @param text */ - public static void setTextForComboViewer(ComboViewer comboViewer , String text) { + public static void setTextForComboViewer(ComboViewer comboViewer, String text) { comboViewer.getCombo().setText(text); } - + /** * Enable/Disable filter actions * * @param filterActions */ public static void updateFiltersEnabledAndCheckedState(List filterActions) { - - for(Action action : filterActions) { - + for (Action action : filterActions) { // avoid to disable group by severity and group by query name actions - if(!action.getId().equals(ActionName.GROUP_BY_SEVERITY.name()) && !action.getId().equals(ActionName.GROUP_BY_QUERY_NAME.name())) { + if (!action.getId().equals(ActionName.GROUP_BY_SEVERITY.name()) && !action.getId().equals(ActionName.GROUP_BY_QUERY_NAME.name())) { action.setEnabled(DataProvider.getInstance().getCurrentScanId() != null); } - + action.setChecked(FilterState.isSeverityEnabled(action.getId())); } - } + } } diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java index 85075045..6fa6eacc 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java @@ -3,6 +3,7 @@ import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.Optional; import java.util.concurrent.CompletableFuture; import org.eclipse.core.resources.IFile; @@ -48,7 +49,6 @@ import org.eclipse.swt.widgets.Text; import org.eclipse.swt.widgets.TreeColumn; import org.eclipse.ui.IActionBars; -import org.eclipse.ui.IWorkbench; import org.eclipse.ui.IWorkbenchPage; import org.eclipse.ui.PlatformUI; import org.eclipse.ui.ide.IDE; @@ -91,7 +91,6 @@ public class CheckmarxView extends ViewPart { public static final Image INFO_SEVERITY = Activator.getImageDescriptor("platform:/plugin/org.eclipse.ui/icons/full/obj16/info_tsk.png").createImage(); - IWorkbench workbench; private TreeViewer viewer; private ComboViewer scanIdComboViewer, projectComboViewer; @@ -120,10 +119,13 @@ public class CheckmarxView extends ViewPart { private EventBus pluginEventBus; + private GlobalSettings globalSettings = new GlobalSettings(); + public CheckmarxView() { super(); rootModel = new DisplayModel.DisplayModelBuilder("").build(); + globalSettings.loadSettings(); } @Override @@ -159,7 +161,6 @@ private void fillContextMenu(IMenuManager manager) { * Creates the Checkmarx plugin tool bar with all actions */ private void createToolbar() { - IActionBars actionBars = getViewSite().getActionBars(); IToolBarManager toolBarManager = actionBars.getToolBarManager(); @@ -191,7 +192,6 @@ public void setFocus() { } private void createViewer(Composite parent) { - GridLayout parentLayout = new GridLayout(); parentLayout.numColumns = 1; parentLayout.horizontalSpacing = 0; @@ -251,6 +251,10 @@ public void handleEvent(Event event) { viewer = new TreeViewer(leftCompositePanel, SWT.MULTI | SWT.H_SCROLL | SWT.V_SCROLL | SWT.FULL_SELECTION | SWT.BORDER); + // Display initial message + boolean gettingResults = globalSettings.getProjectId() != null && !globalSettings.getProjectId().isEmpty() && globalSettings.getScanId() != null && !globalSettings.getScanId().isEmpty(); + showMessage(gettingResults ? String.format(PluginConstants.MSG_RETRIEVING_RESULTS, globalSettings.getScanId()) : ""); + ColumnViewerToolTipSupport.enableFor(viewer); createColumns(); @@ -333,6 +337,8 @@ public void handleEvent(Event event) { private void createProjectListComboBox(Composite parent) { List projectList = DataProvider.getInstance().getProjectList(); + String currentProjectId = globalSettings.getProjectId(); + String currentProjectName = getProjectFromId(projectList, currentProjectId); projectComboViewer = new ComboViewer(parent, SWT.DROP_DOWN); projectComboViewer.setContentProvider(ArrayContentProvider.getInstance()); @@ -359,13 +365,21 @@ public void selectionChanged(SelectionChangedEvent event) { IStructuredSelection selection = (IStructuredSelection) event.getSelection(); if (selection.size() > 0) { + + Project selectedProject = ((Project) selection.getFirstElement()); + + // Avoid non-sense trigger changed when opening the combo + if(selectedProject.getID().equals(currentProjectId)) { + return; + } PluginUtils.enableComboViewer(scanIdComboViewer, false); PluginUtils.setTextForComboViewer(scanIdComboViewer, "Getting scans for the project..."); scanIdComboViewer.getCombo().update(); - Project selectedProject = ((Project) selection.getFirstElement()); - + GlobalSettings.storeInPreferences(GlobalSettings.PARAM_PROJECT_ID, selectedProject.getID()); + GlobalSettings.storeInPreferences(GlobalSettings.PARAM_SCAN_ID, ""); + List scanList = DataProvider.getInstance().getScanListOfProject(selectedProject.getID()); if (scanList.isEmpty()) { @@ -381,10 +395,24 @@ public void selectionChanged(SelectionChangedEvent event) { } }); - PluginUtils.setTextForComboViewer(projectComboViewer, PROJECT_COMBO_VIEWER_TEXT); + PluginUtils.setTextForComboViewer(projectComboViewer, currentProjectName); + } + + /** + * Get project name from project Id + * + * @param projects + * @param projectId + * @return + */ + private String getProjectFromId(List projects, String projectId) { + Optional project = projects.stream().filter(p -> p.getID().equals(projectId)).findFirst(); + + return project.isPresent() ? project.get().getName() : PROJECT_COMBO_VIEWER_TEXT; } private void createScanIdComboBox(Composite parent){ + String currentScanId = globalSettings.getScanId(); scanIdComboViewer = new ComboViewer(parent, SWT.DROP_DOWN); scanIdComboViewer.setContentProvider(ArrayContentProvider.getInstance()); @@ -394,9 +422,7 @@ private void createScanIdComboBox(Composite parent){ public String getText(Object element) { if (element instanceof Scan) { Scan scan = (Scan) element; - String updatedAtDate = PluginUtils.convertStringTimeStamp(scan.getUpdatedAt()); - String itemLabel = scan.getID() + " ( " + scan.getStatus() + ", " + updatedAtDate + " )"; - return itemLabel ; + return formatScanLabel(scan); } return super.getText(element); } @@ -411,9 +437,15 @@ public void selectionChanged(SelectionChangedEvent event) { if (selection.size() > 0) { Scan selectedScan = ((Scan) selection.getFirstElement()); + + // Avoid non-sense trigger changed when opening the combo + if(selectedScan.getID().equals(currentScanId)) { + return; + } + + GlobalSettings.storeInPreferences(GlobalSettings.PARAM_SCAN_ID, selectedScan.getID()); - /// Using async approach so that message can be displayed in the tree while - /// getting the scans list + /// Using async approach so that message can be displayed in the tree while getting the scans list showMessage(String.format(RUNNING, selectedScan.getID())); toolBarActions.getScanResultsAction().setEnabled(false); @@ -422,22 +454,62 @@ public void selectionChanged(SelectionChangedEvent event) { alreadyRunning = true; updateResultsTree(DataProvider.getInstance().getResultsForScanId(selectedScan.getID())); }); - - // end } } }); PluginUtils.setTextForComboViewer(scanIdComboViewer, SCAN_COMBO_VIEWER_TEXT); + if(!globalSettings.getProjectId().isEmpty()) { + List scanList = DataProvider.getInstance().getScanListOfProject(globalSettings.getProjectId()); + scanIdComboViewer.setInput(scanList); + + String currentScanName = getScanNameFromId(scanList, currentScanId); + + PluginUtils.setTextForComboViewer(scanIdComboViewer, currentScanName); + + if(currentScanId != null && !currentScanId.isEmpty()) { + CompletableFuture.runAsync(() -> { + alreadyRunning = true; + updateResultsTree(DataProvider.getInstance().getResultsForScanId(currentScanId)); + }); + } + } + GridData gridData = new GridData(); gridData.widthHint = 510; scanIdComboViewer.getCombo().setLayoutData(gridData); - PluginUtils.enableComboViewer(scanIdComboViewer, false); + + boolean enableScanCombo = !projectComboViewer.getCombo().getText().isEmpty(); + PluginUtils.enableComboViewer(scanIdComboViewer, enableScanCombo); + } + + /** + * Get formated scan name from scan id + * + * @param scans + * @param scanId + * @return + */ + private String getScanNameFromId(List scans, String scanId) { + Optional scan = scans.stream().filter(s -> s.getID().equals(scanId)).findFirst(); + + return scan.isPresent() ? formatScanLabel(scan.get()) : SCAN_COMBO_VIEWER_TEXT; + } + + /** + * Formats scan's displayed label + * + * @param scan + * @return + */ + private static String formatScanLabel(Scan scan) { + String updatedAtDate = PluginUtils.convertStringTimeStamp(scan.getUpdatedAt()); + + return scan.getID() + " ( " + scan.getStatus() + ", " + updatedAtDate + " )"; } private void configureTreeItemSelectionChangeEvent(TreeViewer viewer) { - viewer.addSelectionChangedListener(new ISelectionChangedListener() { @Override @@ -480,16 +552,12 @@ public void selectionChanged(SelectionChangedEvent event) { { updateAttackVectorForSelectedTreeItem(selectedItem); } - - } } }); - } private void updateAttackVectorForSelectedTreeItem(DisplayModel selectedItem) { - clearAttackVectorSection(attackVectorCompositePanel); attackVectorCompositePanel.setVisible(true); @@ -526,13 +594,11 @@ private void updateAttackVectorForSelectedTreeItem(DisplayModel selectedItem) { } if (selectedItem.getType().equalsIgnoreCase(PluginConstants.SAST)) { - String queryName = selectedItem.getResult().getData().getQueryName(); String groupName = selectedItem.getResult().getData().getGroup(); List nodesList = selectedItem.getResult().getData().getNodes(); if (nodesList != null && nodesList.size() > 0) { - for (Node node : nodesList) { String nodeName = node.getName(); @@ -548,7 +614,6 @@ public void handleEvent(Event event) { }); attackVectorCompositePanel.layout(); - } } else { if (attackVectorValueLinkText != null) { @@ -559,7 +624,6 @@ public void handleEvent(Event event) { } private void clearAttackVectorSection(Composite attackVectorCompositePanel) { - for (Control child : attackVectorCompositePanel.getChildren()) { if (!(child instanceof Label)) @@ -568,7 +632,6 @@ private void clearAttackVectorSection(Composite attackVectorCompositePanel) { } private void openTheSelectedFile(String fileName, Integer lineNumber, String markerDescription) { - Path filePath = new Path(fileName); List filesFound = findFileInWorkspace(filePath.lastSegment()); @@ -620,7 +683,6 @@ private void createColumns() { TreeViewerColumn col = createTreeViewerColumn("Title", 500); ColumnProvider label = new ColumnProvider(this::findSeverityImage, model -> model.name); col.setLabelProvider((label)); - } private TreeViewerColumn createTreeViewerColumn(String title, int bound) { @@ -660,7 +722,6 @@ public void showMessage(String message) { @Subscribe private void listener(PluginListenerDefinition definition) { - switch(definition.getListenerType()) { case FILTER_CHANGED: case GET_RESULTS: @@ -678,7 +739,6 @@ private void listener(PluginListenerDefinition definition) { * @param results */ private void updateResultsTree(List results) { - rootModel.children.clear(); rootModel.children.addAll(results); viewer.getTree().getDisplay().asyncExec(() -> viewer.refresh()); @@ -692,7 +752,6 @@ private void updateResultsTree(List results) { * Clear all plugin fields and reload projects */ private void clearAndRefreshPlugin() { - resultInfoCompositePanel.setVisible(false); attackVectorCompositePanel.setVisible(false); diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java index f8857f1c..6417e5f6 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java @@ -10,10 +10,6 @@ import java.util.concurrent.atomic.AtomicBoolean; import java.util.stream.Collectors; -import org.eclipse.core.runtime.ILog; -import org.eclipse.core.runtime.Platform; -import org.osgi.framework.Bundle; -import org.osgi.framework.FrameworkUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -35,9 +31,6 @@ public class DataProvider { private static final String SCA_TREE_NAME = "SCA (%d)"; private static final String KICS_TREE_NAME = "KICS (%d)"; private static final String RESULTS_TREE_NAME = "%s (%d Issues)"; - - private static final Bundle BUNDLE = FrameworkUtil.getBundle(DataProvider.class); - private static final ILog LOG = Platform.getLog(BUNDLE); public static DataProvider _dataProvider = null; @@ -52,7 +45,6 @@ public class DataProvider { * @return */ public static final DataProvider getInstance() { - if(_dataProvider == null) { _dataProvider = new DataProvider(); } @@ -164,7 +156,6 @@ private CxWrapper authenticateWithAST() } public List getResultsForScanId(String scanId) { - abort.set(false); Results scanResults = null; @@ -193,7 +184,6 @@ public List getResultsForScanId(String scanId) { } private List processResults(Results scanResults, String scanId) { - if(scanResults == null || scanResults.getResults() == null || scanResults.getResults().isEmpty()) { return Collections.emptyList(); } @@ -218,7 +208,6 @@ private List processResults(Results scanResults, String scanId) { * @return */ private List buildResults(String scanId, Map> filteredResultsByScannerType){ - if(FilterState.groupBySeverity) { // Divide the results for each scanner as per the severity Map> sastResultsMap = new HashMap<>(); @@ -337,7 +326,6 @@ private List addResults(String scanId, Integer sastCount, List> filterResultsByScannerTypeV2(List allResultsTransformed) { - Map> filteredMap = new HashMap<>(); for (DisplayModel transformedResult : allResultsTransformed) { @@ -377,11 +364,9 @@ private Map> filterResultsByScannerTypeV2(List> filterResultsBySeverityV2(List resultList) { - Map> filteredMapBySeverity = new HashMap<>(); for (DisplayModel result : resultList) { - String severityType = result.getSeverity(); if(FilterState.isSeverityEnabled(severityType)) { @@ -405,7 +390,6 @@ private Map> filterResultsBySeverityV2(List> results) { - for (Map.Entry> entry : results.entrySet()) { String severityOrScannerType = entry.getKey(); @@ -441,7 +425,6 @@ private void filterResultsByQueryName(Map> results) { * @return */ private Map> createParentNodeByScanner(Map> map){ - Map> result = new HashMap<>(); List resultList = new ArrayList<>(); int counter = 0; @@ -478,7 +461,6 @@ private Map> createParentNodeByScanner(Map results) { - int counter = 0; for (DisplayModel dm : results) { diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DisplayModel.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DisplayModel.java index 77af682b..a8e6bb8b 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DisplayModel.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DisplayModel.java @@ -74,7 +74,6 @@ public void setResult(Result result) { } static class DisplayModelBuilder{ - public DisplayModel parent; public List children = new ArrayList<>(); @@ -118,11 +117,8 @@ public DisplayModelBuilder setResult(Result result) { return this; } - public DisplayModel build() { - return new DisplayModel(this); - } - - + public DisplayModel build() { + return new DisplayModel(this); + } } - } diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/PluginListenerDefinition.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/PluginListenerDefinition.java index 30383a19..b03223ee 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/PluginListenerDefinition.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/PluginListenerDefinition.java @@ -2,6 +2,12 @@ import java.util.List; +/** + * Class which represents a Listener Configuration to be used in Event Bus + * + * @author HugoMa + * + */ public class PluginListenerDefinition { private PluginListenerType listenerType; diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionClearSelection.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionClearSelection.java index d3c0858b..4189fd0c 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionClearSelection.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionClearSelection.java @@ -20,7 +20,6 @@ public class ActionClearSelection extends CxBaseAction { private EventBus pluginEventBus; public ActionClearSelection(DisplayModel rootModel, TreeViewer resultsTree, EventBus pluginEventBus) { - super(rootModel, resultsTree); this.pluginEventBus = pluginEventBus; diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionGetScanResults.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionGetScanResults.java index dbd9d70e..fac87c15 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionGetScanResults.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionGetScanResults.java @@ -7,6 +7,7 @@ import org.eclipse.jface.viewers.TreeViewer; import com.checkmarx.eclipse.Activator; +import com.checkmarx.eclipse.utils.PluginConstants; import com.checkmarx.eclipse.utils.PluginUtils; import com.checkmarx.eclipse.views.DataProvider; import com.checkmarx.eclipse.views.DisplayModel; @@ -18,9 +19,7 @@ public class ActionGetScanResults extends CxBaseAction { private static final String ACTION_SCAN_RESULTS_TOOLTIP = "Get results for the scan id."; private static final String ACTION_SCAN_RESULTS_ICON_PATH = "platform:/plugin/org.eclipse.ui.browser/icons/clcl16/nav_go.png"; - - private static final String MSG_RETRIEVING_RESULTS = "Retrieving the results for the scan id: %s ."; - + private Action abortScanResultsAction; private boolean alreadyRunning = false; @@ -28,7 +27,6 @@ public class ActionGetScanResults extends CxBaseAction { private EventBus pluginEventBus; public ActionGetScanResults(DisplayModel rootModel, TreeViewer resultsTree, boolean alreadyRunning, StringFieldEditor scanIdField, Action abortScanResultsAction, EventBus pluginEventBus) { - super(rootModel, resultsTree); this.abortScanResultsAction = abortScanResultsAction; @@ -52,7 +50,7 @@ public void run() { return; } - showMessage(String.format(MSG_RETRIEVING_RESULTS, scanId)); + showMessage(String.format(PluginConstants.MSG_RETRIEVING_RESULTS, scanId)); this.setEnabled(false); abortScanResultsAction.setEnabled(true); diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionOpenPreferencesPage.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionOpenPreferencesPage.java index a8206d93..7c3b3ff9 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionOpenPreferencesPage.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ActionOpenPreferencesPage.java @@ -17,7 +17,6 @@ public class ActionOpenPreferencesPage extends CxBaseAction { private Shell shell; public ActionOpenPreferencesPage(DisplayModel rootModel, TreeViewer resultsTree, boolean alreadyRunning, StringFieldEditor scanIdField, Shell shell) { - super(rootModel, resultsTree); this.shell = shell; diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ToolBarActions.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ToolBarActions.java index e7592cd7..95c754cd 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ToolBarActions.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/actions/ToolBarActions.java @@ -57,7 +57,6 @@ private ToolBarActions(ToolBarActionsBuilder toolBarActionsBuilder) { * Create all tool bar actions */ private void createActions() { - filterActions = new ActionFilters(pluginEventBus).createFilterActions(); Action clearSelectionAction = new ActionClearSelection(rootModel, resultsTree, pluginEventBus).createAction(); diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/ActionFilters.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/ActionFilters.java index aa25cf61..9df85794 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/ActionFilters.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/ActionFilters.java @@ -38,7 +38,6 @@ public ActionFilters(EventBus pluginEventBus) { * @return */ public List createFilterActions(){ - List filters = new ArrayList<>(); Action filterHighAction = createFilterAction(ACTION_FILTER_HIGH_TOOLTIP, ACTION_FILTER_HIGH_ICON_PATH, Severity.HIGH, ActionName.HIGH); diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/FilterState.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/FilterState.java index 085c9c2c..e29c51b6 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/FilterState.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/filters/FilterState.java @@ -1,5 +1,6 @@ package com.checkmarx.eclipse.views.filters; +import com.checkmarx.eclipse.views.GlobalSettings; public class FilterState { @@ -8,7 +9,17 @@ public class FilterState { public static boolean low = false; public static boolean info = false; public static boolean groupBySeverity = true; - public static boolean groupByQueryName = false; + public static boolean groupByQueryName = true; + + + public static void loadFiltersFromSettings() { + high = Boolean.parseBoolean(GlobalSettings.getFromPreferences(Severity.HIGH.name(), "true")); + medium = Boolean.parseBoolean(GlobalSettings.getFromPreferences(Severity.MEDIUM.name(), "true")); + low = Boolean.parseBoolean(GlobalSettings.getFromPreferences(Severity.LOW.name(), "false")); + info = Boolean.parseBoolean(GlobalSettings.getFromPreferences(Severity.INFO.name(), "false")); + groupBySeverity = Boolean.parseBoolean(GlobalSettings.getFromPreferences(Severity.GROUP_BY_SEVERITY.name(), "true")); + groupByQueryName = Boolean.parseBoolean(GlobalSettings.getFromPreferences(Severity.GROUP_BY_QUERY_NAME.name(), "true")); + } /** * Change severity state @@ -16,25 +27,30 @@ public class FilterState { * @param severity */ public static void setState(Severity severity) { - switch(severity) { case HIGH: high = !high; + GlobalSettings.storeInPreferences(Severity.HIGH.name(), String.valueOf(high)); break; case MEDIUM: medium = !medium; + GlobalSettings.storeInPreferences(Severity.MEDIUM.name(), String.valueOf(medium)); break; case LOW: low = !low; + GlobalSettings.storeInPreferences(Severity.LOW.name(), String.valueOf(low)); break; case INFO: info = !info; + GlobalSettings.storeInPreferences(Severity.INFO.name(), String.valueOf(info)); break; case GROUP_BY_SEVERITY: groupBySeverity = !groupBySeverity; + GlobalSettings.storeInPreferences(Severity.GROUP_BY_SEVERITY.name(), String.valueOf(groupBySeverity)); break; case GROUP_BY_QUERY_NAME: groupByQueryName = !groupByQueryName; + GlobalSettings.storeInPreferences(Severity.GROUP_BY_QUERY_NAME.name(), String.valueOf(groupByQueryName)); break; } } @@ -46,7 +62,6 @@ public static void setState(Severity severity) { * @return */ public static boolean isSeverityEnabled(String severity) { - switch(Severity.getSeverity(severity)) { case HIGH: return high; case MEDIUM: return medium; @@ -68,6 +83,6 @@ public static void resetFilters() { low = false; info = false; groupBySeverity = true; - groupByQueryName = false; + groupByQueryName = true; } }