Skip to content

Commit cac206a

Browse files
Get filtered projects from server (AST-104768) (#216)
* Get filtered projects from server when projects are more that 10000 * Resolved SCA vulnurability * SWTBotPreferences timeout increased * Resolved review comments
1 parent d4b710a commit cac206a

8 files changed

Lines changed: 154 additions & 80 deletions

File tree

checkmarx-ast-eclipse-plugin-tests/src/test/java/checkmarx/ast/eclipse/plugin/tests/ui/BaseUITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public static void beforeClass() throws Exception {
6060
// Used to decrease tests velocity
6161
SWTBotPreferences.PLAYBACK_DELAY = 500;
6262

63-
SWTBotPreferences.TIMEOUT = 20000;
63+
SWTBotPreferences.TIMEOUT = 30000;
6464

6565
_bot = new SWTWorkbenchBot();
6666

checkmarx-ast-eclipse-plugin/.classpath

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,13 @@
1111
<classpathentry exported="true" kind="lib" path="lib/slf4j-api-1.7.5.jar"/>
1212
<classpathentry exported="true" kind="lib" path="lib/jackson-annotations-2.15.2.jar"/>
1313
<classpathentry exported="true" kind="lib" path="lib/jackson-core-2.15.2.jar"/>
14-
<classpathentry exported="true" kind="lib" path="lib/commons-lang3-3.12.0.jar"/>
14+
<classpathentry exported="true" kind="lib" path="lib/commons-lang3-3.18.0.jar"/>
1515
<classpathentry exported="true" kind="lib" path="lib/ast-cli-java-wrapper-2.4.4.jar"/>
1616
<classpathentry exported="true" kind="lib" path="lib/jackson-databind-2.15.2.jar"/>
1717
<classpathentry exported="true" kind="lib" path="lib/org.eclipse.mylyn.commons.ui_3.25.2.v20200813-0821.jar"/>
1818
<classpathentry exported="true" kind="lib" path="lib/org.apache.commons.lang_2.6.0.v20220406-2305.jar"/>
1919
<classpathentry exported="true" kind="lib" path="lib/org-eclipse-mylyn-commons-core.jar"/>
20-
<classpathentry kind="src" path="src/"/>
20+
<classpathentry kind="lib" path="lib/commons-lang3-3.18.0.jar"/>
21+
<classpathentry kind="src" path="src"/>
2122
<classpathentry kind="output" path="target/classes"/>
22-
</classpath>
23+
</classpath>

checkmarx-ast-eclipse-plugin/META-INF/MANIFEST.MF

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ Bundle-ClassPath: lib/slf4j-simple-1.7.5.jar,
2424
lib/slf4j-api-1.7.5.jar,
2525
lib/jackson-annotations-2.15.2.jar,
2626
lib/jackson-core-2.15.2.jar,
27-
lib/commons-lang3-3.12.0.jar,
27+
lib/commons-lang3-3.18.0.jar,
2828
lib/ast-cli-java-wrapper-2.4.4.jar,
2929
lib/jackson-databind-2.15.2.jar,
3030
lib/org.eclipse.mylyn.commons.ui_3.25.2.v20200813-0821.jar,

checkmarx-ast-eclipse-plugin/build.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ bin.includes = plugin.xml,\
77
lib/slf4j-api-1.7.5.jar,\
88
lib/jackson-annotations-2.15.2.jar,\
99
lib/jackson-core-2.15.2.jar,\
10-
lib/commons-lang3-3.12.0.jar,\
10+
lib/commons-lang3-3.18.0.jar,\
1111
lib/ast-cli-java-wrapper-2.4.4.jar,\
1212
lib/jackson-databind-2.15.2.jar,\
1313
lib/org.eclipse.mylyn.commons.ui_3.25.2.v20200813-0821.jar,\
-574 KB
Binary file not shown.
686 KB
Binary file not shown.

checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/CheckmarxView.java

Lines changed: 122 additions & 74 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import java.util.Optional;
1212
import java.util.Set;
1313
import java.util.UUID;
14+
import java.util.stream.Collectors;
1415

1516
import org.apache.commons.lang3.StringUtils;
1617
import org.eclipse.core.resources.IFile;
@@ -98,6 +99,8 @@
9899
import com.google.common.base.Strings;
99100
import com.google.common.eventbus.EventBus;
100101
import com.google.common.eventbus.Subscribe;
102+
import java.util.Timer;
103+
import java.util.TimerTask;
101104

102105
public class CheckmarxView extends ViewPart implements EventHandler {
103106

@@ -112,6 +115,11 @@ public class CheckmarxView extends ViewPart implements EventHandler {
112115
private static final String FORMATTED_SCAN_LABEL = "%s %s";
113116
private static final String FORMATTED_SCAN_LABEL_LATEST = "%s %s (%s)";
114117

118+
private Timer debounceTimer = new Timer("ProjectSearchDebounce", true);
119+
private TimerTask pendingSearchTask;
120+
private static final int DEBOUNCE_DELAY_MS = 400;
121+
private volatile String latestProjectSearchTerm = "";
122+
115123
private static final int SCROLL_WIDTH = 30;
116124
/**
117125
* The ID of the view as specified by the extension.
@@ -805,18 +813,58 @@ protected IStatus run(IProgressMonitor arg0) {
805813

806814
// Add ModifyListener to handle manual text input for projects
807815
projectComboViewer.getCombo().addModifyListener(e -> {
808-
String enteredProject = projectComboViewer.getCombo().getText();
809-
810-
// Check if text was modified and project doesn't exist
811-
boolean projectExists = currentProjects.stream()
812-
.anyMatch(p -> p.getName().equals(enteredProject));
813-
814-
if (!projectExists) {
816+
String enteredProject = projectComboViewer.getCombo().getText().trim();
817+
// Skip search if the text is the default instruction
818+
if (enteredProject.equals(PROJECT_COMBO_VIEWER_TEXT)) {
815819
updateStartScanButton(false); // Disable scan button
816-
} else {
817-
// Only enable if we also have a valid branch
818-
boolean validBranch = !currentBranch.isEmpty() && currentBranches.contains(currentBranch);
819-
updateStartScanButton(validBranch);
820+
return;
821+
}
822+
823+
latestProjectSearchTerm = enteredProject; // Track the latest term
824+
List<String> matchedProjects;
825+
matchedProjects = currentProjects.stream().map(Project::getName)
826+
.filter(name -> name != null && name.toLowerCase().contains(enteredProject.toLowerCase())).limit(100)
827+
.collect(Collectors.toList());
828+
829+
if (matchedProjects.isEmpty()) {
830+
CxLogger.info("Entered project is not exist in current projects list");
831+
// Cancel any pending search
832+
if (pendingSearchTask != null) {
833+
pendingSearchTask.cancel();
834+
}
835+
// Schedule a new search after the debounce delay
836+
pendingSearchTask = new java.util.TimerTask() {
837+
@Override
838+
public void run() {
839+
final String searchTerm = latestProjectSearchTerm; // Capture the term for this search
840+
// Schedule a background job for the server search
841+
Job job = new Job("Checkmarx: Searching for project on server...") {
842+
@Override
843+
protected IStatus run(IProgressMonitor monitor) {
844+
List<Project> searchedProjects;
845+
try {
846+
searchedProjects = DataProvider.getInstance().getProjects(searchTerm);
847+
Display.getDefault().asyncExec(() -> {
848+
if (searchTerm.equals(latestProjectSearchTerm)) {
849+
// Update UI in UI thread
850+
if (searchedProjects != null && !searchedProjects.isEmpty()) {
851+
projectComboViewer.setInput(searchedProjects);
852+
currentProjects = searchedProjects;
853+
} else {
854+
updateStartScanButton(false); // Disable scan button
855+
}
856+
}
857+
});
858+
} catch (Exception ex) {
859+
ex.printStackTrace();
860+
}
861+
return Status.OK_STATUS;
862+
}
863+
};
864+
job.schedule();
865+
}
866+
};
867+
debounceTimer.schedule(pendingSearchTask, DEBOUNCE_DELAY_MS);
820868
}
821869
});
822870
}
@@ -1806,20 +1854,20 @@ private void layoutAttackVectorItemComposite() {
18061854
}
18071855

18081856
private void drawPackageData(DisplayModel selectedItem) {
1809-
ScrolledComposite sc = new ScrolledComposite(attackVectorCompositePanel, SWT.H_SCROLL | SWT.V_SCROLL);
1857+
ScrolledComposite sc = new ScrolledComposite(attackVectorCompositePanel, SWT.H_SCROLL | SWT.V_SCROLL);
18101858

1811-
Composite child = new Composite(sc, SWT.NONE);
1812-
child.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
1813-
child.setLayout(new GridLayout(1, false));
1814-
child.setBackground(attackVectorCompositePanel.getBackground());
1859+
Composite child = new Composite(sc, SWT.NONE);
1860+
child.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
1861+
child.setLayout(new GridLayout(1, false));
1862+
child.setBackground(attackVectorCompositePanel.getBackground());
18151863

1816-
drawAttackVectorTitle(child, PluginConstants.PACKAGE_DATA);
1817-
drawIndividualPackageData(child, selectedItem.getResult().getData().getPackageData());
1864+
drawAttackVectorTitle(child, PluginConstants.PACKAGE_DATA);
1865+
drawIndividualPackageData(child, selectedItem.getResult().getData().getPackageData());
18181866

1819-
sc.setContent(child);
1820-
sc.setMinSize(child.computeSize(SWT.DEFAULT, SWT.DEFAULT));
1821-
sc.setExpandHorizontal(true);
1822-
sc.setExpandVertical(true);
1867+
sc.setContent(child);
1868+
sc.setMinSize(child.computeSize(SWT.DEFAULT, SWT.DEFAULT));
1869+
sc.setExpandHorizontal(true);
1870+
sc.setExpandVertical(true);
18231871
}
18241872

18251873
/**
@@ -1930,18 +1978,18 @@ private void drawSASTLearnMore(DisplayModel selectedItem, TabFolder folder, TabI
19301978
final ScrolledComposite learnMoreScrolledComposite = new ScrolledComposite(folder, SWT.V_SCROLL);
19311979
learnMoreScrolledComposite.setExpandHorizontal(true);
19321980
learnMoreScrolledComposite.setExpandVertical(true);
1933-
1934-
final Composite learnMoreComposite = new Composite(learnMoreScrolledComposite, SWT.NONE);
1935-
learnMoreComposite.setLayout(new GridLayout());
1936-
1937-
learnMoreScrolledComposite.setContent(learnMoreComposite);
1938-
learnMoreScrolledComposite.setMinSize(learnMoreComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
19391981

1940-
if(learnMoreData == null) {
1941-
CLabel loadingLabel = new CLabel(learnMoreComposite, SWT.NONE);
1982+
final Composite learnMoreComposite = new Composite(learnMoreScrolledComposite, SWT.NONE);
1983+
learnMoreComposite.setLayout(new GridLayout());
1984+
1985+
learnMoreScrolledComposite.setContent(learnMoreComposite);
1986+
learnMoreScrolledComposite.setMinSize(learnMoreComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
1987+
1988+
if(learnMoreData == null) {
1989+
CLabel loadingLabel = new CLabel(learnMoreComposite, SWT.NONE);
19421990
loadingLabel.setText(PluginConstants.LEARN_MORE_LOADING);
1943-
}
1944-
1991+
}
1992+
19451993
learnMoreTab.setControl(learnMoreScrolledComposite);
19461994

19471995
Job job = new Job(PluginConstants.GETTING_LEARN_MORE_JOB) {
@@ -1975,8 +2023,8 @@ protected IStatus run(IProgressMonitor arg0) {
19752023
});
19762024
}
19772025

1978-
learnMoreScrolledComposite.setMinSize(learnMoreComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
1979-
learnMoreComposite.layout();
2026+
learnMoreScrolledComposite.setMinSize(learnMoreComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
2027+
learnMoreComposite.layout();
19802028
}
19812029
} catch (Exception e) {
19822030
CxLogger.error(String.format(PluginConstants.ERROR_GETTING_LEARN_MORE, e.getMessage()), e);
@@ -2024,17 +2072,17 @@ private void drawSASTRemediationExamples(DisplayModel selectedItem, TabFolder fo
20242072
final ScrolledComposite remediationExamplesScrolledComposite = new ScrolledComposite(folder, SWT.V_SCROLL | SWT.BORDER);
20252073
remediationExamplesScrolledComposite.setExpandHorizontal(true);
20262074
remediationExamplesScrolledComposite.setExpandVertical(true);
2027-
2028-
final Composite remediationExamplesComposite = new Composite(remediationExamplesScrolledComposite, SWT.NONE);
2029-
remediationExamplesComposite.setLayout(new GridLayout());
2030-
2031-
remediationExamplesScrolledComposite.setContent(remediationExamplesComposite);
2032-
remediationExamplesScrolledComposite.setMinSize(remediationExamplesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
20332075

2034-
if(learnMoreData == null) {
2035-
Label loadingLabel = new Label(remediationExamplesComposite, SWT.NONE);
2076+
final Composite remediationExamplesComposite = new Composite(remediationExamplesScrolledComposite, SWT.NONE);
2077+
remediationExamplesComposite.setLayout(new GridLayout());
2078+
2079+
remediationExamplesScrolledComposite.setContent(remediationExamplesComposite);
2080+
remediationExamplesScrolledComposite.setMinSize(remediationExamplesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
2081+
2082+
if(learnMoreData == null) {
2083+
Label loadingLabel = new Label(remediationExamplesComposite, SWT.NONE);
20362084
loadingLabel.setText(PluginConstants.LEARN_MORE_LOADING);
2037-
}
2085+
}
20382086

20392087
remediationExamplesTab.setControl(remediationExamplesScrolledComposite);
20402088

@@ -2062,14 +2110,14 @@ protected IStatus run(IProgressMonitor arg0) {
20622110
for(Sample sample : samples) {
20632111
StyledText sampleTitle = new StyledText(remediationExamplesComposite, SWT.WRAP);
20642112
sampleTitle.setText(String.format(PluginConstants.REMEDIATION_EXAMPLE_TITLE_FORMAT, sample.getTitle(), sample.getProgLanguage()));
2065-
GridData titleLayoutData = new GridData( GridData.FILL_HORIZONTAL ) ;
2066-
titleLayoutData.grabExcessHorizontalSpace = true;
2067-
titleLayoutData.horizontalAlignment = SWT.FILL;
2068-
titleLayoutData.widthHint = remediationExamplesScrolledComposite.getClientArea().width - SCROLL_WIDTH;
2069-
titleLayoutData.horizontalSpan = 2;
2070-
sampleTitle.setLayoutData(titleLayoutData);
2071-
sampleTitle.setMargins(2, 5, 2, 5);
2072-
2113+
GridData titleLayoutData = new GridData( GridData.FILL_HORIZONTAL ) ;
2114+
titleLayoutData.grabExcessHorizontalSpace = true;
2115+
titleLayoutData.horizontalAlignment = SWT.FILL;
2116+
titleLayoutData.widthHint = remediationExamplesScrolledComposite.getClientArea().width - SCROLL_WIDTH;
2117+
titleLayoutData.horizontalSpan = 2;
2118+
sampleTitle.setLayoutData(titleLayoutData);
2119+
sampleTitle.setMargins(2, 5, 2, 5);
2120+
20732121
Composite sampleExampleComposite = new Composite(remediationExamplesComposite, SWT.NONE);
20742122
sampleExampleComposite.setBackground(remediationExamplesComposite.getBackground());
20752123
GridLayout layout = new GridLayout();
@@ -2080,12 +2128,12 @@ protected IStatus run(IProgressMonitor arg0) {
20802128

20812129
Label sampleExample = new Label(sampleExampleComposite, SWT.WRAP);
20822130
sampleExample.setText(sample.getCode());
2083-
GridData exampleLayoutData = new GridData(GridData.FILL_HORIZONTAL) ;
2084-
exampleLayoutData.grabExcessHorizontalSpace = true;
2085-
exampleLayoutData.horizontalAlignment = SWT.FILL;
2086-
exampleLayoutData.widthHint = remediationExamplesScrolledComposite.getClientArea().width - SCROLL_WIDTH;
2087-
exampleLayoutData.horizontalSpan = 2;
2088-
sampleExample.setLayoutData(exampleLayoutData);
2131+
GridData exampleLayoutData = new GridData(GridData.FILL_HORIZONTAL) ;
2132+
exampleLayoutData.grabExcessHorizontalSpace = true;
2133+
exampleLayoutData.horizontalAlignment = SWT.FILL;
2134+
exampleLayoutData.widthHint = remediationExamplesScrolledComposite.getClientArea().width - SCROLL_WIDTH;
2135+
exampleLayoutData.horizontalSpan = 2;
2136+
sampleExample.setLayoutData(exampleLayoutData);
20892137

20902138
remediationExamplesScrolledComposite.setMinSize(remediationExamplesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
20912139
remediationExamplesComposite.layout();
@@ -2134,14 +2182,14 @@ private void addLearnMoreSectionsToComposite(Composite composite, String title,
21342182
titleLabel.setFont(boldFont);
21352183

21362184
StyledText descriptionLabel = new StyledText(composite, SWT.WRAP);
2137-
descriptionLabel.setText(description);
2138-
GridData descriptionLayout = new GridData(GridData.FILL_HORIZONTAL);
2139-
descriptionLayout.grabExcessHorizontalSpace = true;
2140-
descriptionLayout.horizontalAlignment = SWT.FILL;
2141-
descriptionLayout.widthHint = composite.getClientArea().width - SCROLL_WIDTH;
2142-
descriptionLayout.horizontalSpan = 2;
2143-
descriptionLabel.setLayoutData(descriptionLayout);
2144-
descriptionLabel.setBottomMargin(20);
2185+
descriptionLabel.setText(description);
2186+
GridData descriptionLayout = new GridData(GridData.FILL_HORIZONTAL);
2187+
descriptionLayout.grabExcessHorizontalSpace = true;
2188+
descriptionLayout.horizontalAlignment = SWT.FILL;
2189+
descriptionLayout.widthHint = composite.getClientArea().width - SCROLL_WIDTH;
2190+
descriptionLayout.horizontalSpan = 2;
2191+
descriptionLabel.setLayoutData(descriptionLayout);
2192+
descriptionLabel.setBottomMargin(20);
21452193
}
21462194

21472195
/*private void populateBFLMessage(Image image, String bflMessage) {
@@ -2220,18 +2268,18 @@ protected IStatus run(IProgressMonitor arg0) {
22202268
private void drawVulnerabilityLocation(DisplayModel selectedItem) {
22212269
ScrolledComposite sc = new ScrolledComposite(attackVectorCompositePanel, SWT.H_SCROLL | SWT.V_SCROLL);
22222270

2223-
Composite child = new Composite(sc, SWT.NONE);
2224-
child.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
2225-
child.setLayout(new GridLayout(1, false));
2226-
child.setBackground(attackVectorCompositePanel.getBackground());
2271+
Composite child = new Composite(sc, SWT.NONE);
2272+
child.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
2273+
child.setLayout(new GridLayout(1, false));
2274+
child.setBackground(attackVectorCompositePanel.getBackground());
22272275

2228-
drawAttackVectorTitle(child, PluginConstants.LOCATION);
2276+
drawAttackVectorTitle(child, PluginConstants.LOCATION);
22292277
drawIndividualLocationData(child, selectedItem);
22302278

2231-
sc.setContent(child);
2232-
sc.setMinSize(child.computeSize(SWT.DEFAULT, SWT.DEFAULT));
2233-
sc.setExpandHorizontal(true);
2234-
sc.setExpandVertical(true);
2279+
sc.setContent(child);
2280+
sc.setMinSize(child.computeSize(SWT.DEFAULT, SWT.DEFAULT));
2281+
sc.setExpandHorizontal(true);
2282+
sc.setExpandVertical(true);
22352283
}
22362284

22372285
private void drawIndividualLocationData(Composite parent, DisplayModel selectedItem) {

checkmarx-ast-eclipse-plugin/src/com/checkmarx/eclipse/views/DataProvider.java

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ public class DataProvider {
4242
private static final List<String> SEVERITY_ORDER = Arrays.asList("CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO");
4343

4444
private static final String LIMIT_FILTER="limit=10000";
45+
private static final String NAME_FILTER="name=";
4546
private static final String FILTER_SCANS_FOR_PROJECT = "project-id=%s,branch=%s,limit=10000,statuses=Completed";
4647

4748
private static final String SAST_TREE_NAME = "SAST (%d)";
@@ -111,6 +112,30 @@ public List<Project> getProjects() throws Exception {
111112
return projectList;
112113
}
113114

115+
/**
116+
* Get One projects filtered by name
117+
*
118+
* @return
119+
* @throws Exception
120+
*/
121+
public List<Project> getProjects(String projectName) throws Exception {
122+
List<Project> projectList = new ArrayList<Project>();
123+
124+
CxWrapper cxWrapper = authenticateWithAST();
125+
String filterProject = NAME_FILTER+projectName;
126+
127+
if (cxWrapper != null) {
128+
try {
129+
projectList = cxWrapper.projectList(filterProject);
130+
131+
} catch (IOException | InterruptedException | CxException e) {
132+
CxLogger.error(String.format(PluginConstants.ERROR_GETTING_PROJECTS, e.getMessage()), e);
133+
}
134+
}
135+
136+
return projectList;
137+
}
138+
114139
/**
115140
* Get the codeBashing link
116141
* @throws Exception

0 commit comments

Comments
 (0)