From b02350996e2a622afc97c682529e9922d954ab4a Mon Sep 17 00:00:00 2001 From: Aniket Shinde Date: Thu, 14 May 2026 15:10:15 +0530 Subject: [PATCH] Parity and project combobox --- .../eclipse/plugin/tests/ui/BaseUITest.java | 2 +- checkmarx-ast-eclipse-plugin/plugin.xml | 4 +++ .../eclipse/properties/PreferencesPage.java | 11 ++++++- .../eclipse/startup/PluginStartup.java | 31 +++++++++++++++++++ .../eclipse/utils/PluginConstants.java | 2 ++ .../eclipse/views/CheckmarxView.java | 22 +++++++++++-- .../checkmarx/eclipse/views/DataProvider.java | 20 ++++++++++-- .../eclipse/views/filters/FilterState.java | 8 ++--- 8 files changed, 90 insertions(+), 10 deletions(-) create mode 100644 checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/startup/PluginStartup.java 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 2211c71b..175febc8 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 @@ -26,7 +26,7 @@ public abstract class BaseUITest { - private static final String INFO_SUCCESSFUL_CONNECTION = "Successfully authenticated to Checkmarx One server!"; + private static final String INFO_SUCCESSFUL_CONNECTION = "You are connected to Checkmarx One"; protected static final String ASSERT_FILTER_ACTIONS_IN_TOOLBAR = "All filter actions must be in the tool bar"; diff --git a/checkmarx-ast-eclipse-plugin/plugin.xml b/checkmarx-ast-eclipse-plugin/plugin.xml index 362a4c37..e0f787b1 100644 --- a/checkmarx-ast-eclipse-plugin/plugin.xml +++ b/checkmarx-ast-eclipse-plugin/plugin.xml @@ -39,4 +39,8 @@ + + + + diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/properties/PreferencesPage.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/properties/PreferencesPage.java index 49cb12d8..3c5af098 100644 --- a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/properties/PreferencesPage.java +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/properties/PreferencesPage.java @@ -137,7 +137,7 @@ public void widgetSelected(SelectionEvent e) { return t.getMessage(); } }).thenAccept((result) -> Display.getDefault().syncExec(() -> { - connectionLabel.setText(result); + connectionLabel.setText(mapAuthResult(result)); getFieldEditorParent().layout(); connectionButton.setEnabled(true); })); @@ -145,6 +145,15 @@ public void widgetSelected(SelectionEvent e) { }); } + + + private static String mapAuthResult(String result) { + if (result != null && result.contains(PluginConstants.AUTH_SUCCESS_PATTERN)) { + return PluginConstants.AUTH_SUCCESS_DISPLAY; + } + return result; + } + private FieldEditor space() { return new LabelFieldEditor("", getFieldEditorParent()); } diff --git a/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/startup/PluginStartup.java b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/startup/PluginStartup.java new file mode 100644 index 00000000..e520f992 --- /dev/null +++ b/checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/startup/PluginStartup.java @@ -0,0 +1,31 @@ +package com.checkmarx.eclipse.startup; + +import org.eclipse.ui.IStartup; +import org.eclipse.ui.IWorkbenchPage; +import org.eclipse.ui.IWorkbenchWindow; +import org.eclipse.ui.PartInitException; +import org.eclipse.ui.PlatformUI; + +import com.checkmarx.eclipse.utils.CxLogger; + +public class PluginStartup implements IStartup { + + private static final String VIEW_ID = "com.checkmarx.eclipse.views.CheckmarxView"; + + @Override + public void earlyStartup() { + PlatformUI.getWorkbench().getDisplay().asyncExec(() -> { + try { + IWorkbenchWindow window = PlatformUI.getWorkbench().getActiveWorkbenchWindow(); + if (window != null) { + IWorkbenchPage page = window.getActivePage(); + if (page != null && page.findView(VIEW_ID) == null) { + page.showView(VIEW_ID); + } + } + } catch (PartInitException e) { + CxLogger.error("Failed to open Checkmarx One view on startup: " + e.getMessage(), e); + } + }); + } +} 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 ad48cd29..524b1136 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 @@ -49,6 +49,8 @@ public class PluginConstants { public static final String INFO_CHANGE_SCAN_EVENT_NOT_TRIGGERED = "Change scan id event not triggered. Request already running: %s. Scan id results already retrieved: %s"; public static final String INFO_CHANGE_BRANCH_EVENT_NOT_TRIGGERED = "Change branch event not triggered. Branch already selected"; public static final String INFO_CHANGE_PROJECT_EVENT_NOT_TRIGGERED = "Change project event not triggered. Project already selected"; + public static final String AUTH_SUCCESS_PATTERN = "Successfully authenticated"; + public static final String AUTH_SUCCESS_DISPLAY = "You are connected to Checkmarx One"; /******************************** TREE MESSAGES ********************************/ public static final String TREE_INVALID_SCAN_ID_FORMAT = "Invalid scan id format."; 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 43c16a47..8c2b11df 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 @@ -1264,13 +1264,31 @@ protected IStatus run(IProgressMonitor arg0) { List projectList = getProjects(); if (projectList.isEmpty()) return null; - String projectName = getProjectFromId(projectList, projectId); + + // Fetch the project directly by ID — the full list may not contain it (e.g. pagination limits) + Project fetchedProject = DataProvider.getInstance().getProjectById(projectId); + + // Determine project name: prefer the directly-fetched result, fall back to list lookup + String projectName = (fetchedProject != null) + ? fetchedProject.getName() + : getProjectFromId(projectList, projectId); + + // If the project was not already in the list, prepend it so it's visible in the dropdown + if (fetchedProject != null && projectList.stream().noneMatch(p -> p.getId().equals(projectId))) { + projectList = new ArrayList<>(projectList); + projectList.add(0, fetchedProject); + } + final List finalProjectList = projectList; + currentProjectId = projectId; GlobalSettings.storeInPreferences(GlobalSettings.PARAM_PROJECT_ID, currentProjectId); sync.asyncExec(() -> { - projectComboViewer.setInput(projectList); + currentProjects = finalProjectList; + storeCurrentProjects = finalProjectList; + projectComboViewer.setInput(finalProjectList); PluginUtils.setTextForComboViewer(projectComboViewer, projectName); + PluginUtils.enableComboViewer(projectComboViewer, true); setSelectionForBranchComboViewer(scan.getBranch(), projectId); setSelectionForScanIdComboViewer(scan.getId(), scan.getBranch()); updateStartScanButton(true); 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 d0229325..efe9f5e2 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 @@ -112,11 +112,27 @@ public List getProjects() throws Exception { return projectList; } + /** + * Fetch a single project directly by its ID using the project show command. + * Returns null if the project cannot be retrieved. + */ + public Project getProjectById(String projectId) { + try { + CxWrapper cxWrapper = getWrapper(); + if (cxWrapper != null && projectId != null && !projectId.isEmpty()) { + return cxWrapper.projectShow(UUID.fromString(projectId)); + } + } catch (Exception e) { + CxLogger.error(String.format(PluginConstants.ERROR_GETTING_PROJECTS, e.getMessage()), e); + } + return null; + } + /** * Get One projects filtered by name - * + * * @return - * @throws Exception + * @throws Exception */ public List getProjects(String projectName) throws Exception { List projectList = new ArrayList(); 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 a3c41d05..e5957112 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 @@ -15,8 +15,8 @@ public class FilterState { public static boolean critical = true; public static boolean high = true; public static boolean medium = true; - public static boolean low = false; - public static boolean info = false; + public static boolean low = true; + public static boolean info = true; public static boolean groupBySeverity = true; public static boolean groupByQueryName = false; public static boolean groupByStateName = false; @@ -42,8 +42,8 @@ public static void loadFiltersFromSettings() { critical = Boolean.parseBoolean(GlobalSettings.getFromPreferences(Severity.CRITICAL.name(), "true")); 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")); + low = Boolean.parseBoolean(GlobalSettings.getFromPreferences(Severity.LOW.name(), "true")); + info = Boolean.parseBoolean(GlobalSettings.getFromPreferences(Severity.INFO.name(), "true")); groupBySeverity = Boolean .parseBoolean(GlobalSettings.getFromPreferences(Severity.GROUP_BY_SEVERITY.name(), "true")); groupByQueryName = Boolean