Skip to content

Commit e897bb9

Browse files
Resolved Conflict
2 parents f0a8405 + cac206a commit e897bb9

File tree

7 files changed

+156
-82
lines changed

7 files changed

+156
-82
lines changed

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: 125 additions & 77 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;
@@ -99,6 +100,8 @@
99100
import com.google.common.base.Strings;
100101
import com.google.common.eventbus.EventBus;
101102
import com.google.common.eventbus.Subscribe;
103+
import java.util.Timer;
104+
import java.util.TimerTask;
102105

103106
public class CheckmarxView extends ViewPart implements EventHandler {
104107

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

119+
private Timer debounceTimer = new Timer("ProjectSearchDebounce", true);
120+
private TimerTask pendingSearchTask;
121+
private static final int DEBOUNCE_DELAY_MS = 400;
122+
private volatile String latestProjectSearchTerm = "";
123+
116124
private static final int SCROLL_WIDTH = 30;
117125
/**
118126
* The ID of the view as specified by the extension.
@@ -815,21 +823,61 @@ protected IStatus run(IProgressMonitor arg0) {
815823
});
816824

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

18201868
private void drawPackageData(DisplayModel selectedItem) {
1821-
ScrolledComposite sc = new ScrolledComposite(attackVectorCompositePanel, SWT.H_SCROLL | SWT.V_SCROLL);
1869+
ScrolledComposite sc = new ScrolledComposite(attackVectorCompositePanel, SWT.H_SCROLL | SWT.V_SCROLL);
18221870

1823-
Composite child = new Composite(sc, SWT.NONE);
1824-
child.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
1825-
child.setLayout(new GridLayout(1, false));
1826-
child.setBackground(attackVectorCompositePanel.getBackground());
1871+
Composite child = new Composite(sc, SWT.NONE);
1872+
child.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
1873+
child.setLayout(new GridLayout(1, false));
1874+
child.setBackground(attackVectorCompositePanel.getBackground());
18271875

1828-
drawAttackVectorTitle(child, PluginConstants.PACKAGE_DATA);
1829-
drawIndividualPackageData(child, selectedItem.getResult().getData().getPackageData());
1876+
drawAttackVectorTitle(child, PluginConstants.PACKAGE_DATA);
1877+
drawIndividualPackageData(child, selectedItem.getResult().getData().getPackageData());
18301878

1831-
sc.setContent(child);
1832-
sc.setMinSize(child.computeSize(SWT.DEFAULT, SWT.DEFAULT));
1833-
sc.setExpandHorizontal(true);
1834-
sc.setExpandVertical(true);
1879+
sc.setContent(child);
1880+
sc.setMinSize(child.computeSize(SWT.DEFAULT, SWT.DEFAULT));
1881+
sc.setExpandHorizontal(true);
1882+
sc.setExpandVertical(true);
18351883
}
18361884

18371885
/**
@@ -1942,18 +1990,18 @@ private void drawSASTLearnMore(DisplayModel selectedItem, TabFolder folder, TabI
19421990
final ScrolledComposite learnMoreScrolledComposite = new ScrolledComposite(folder, SWT.V_SCROLL);
19431991
learnMoreScrolledComposite.setExpandHorizontal(true);
19441992
learnMoreScrolledComposite.setExpandVertical(true);
1945-
1946-
final Composite learnMoreComposite = new Composite(learnMoreScrolledComposite, SWT.NONE);
1947-
learnMoreComposite.setLayout(new GridLayout());
1948-
1949-
learnMoreScrolledComposite.setContent(learnMoreComposite);
1950-
learnMoreScrolledComposite.setMinSize(learnMoreComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
19511993

1952-
if(learnMoreData == null) {
1953-
CLabel loadingLabel = new CLabel(learnMoreComposite, SWT.NONE);
1994+
final Composite learnMoreComposite = new Composite(learnMoreScrolledComposite, SWT.NONE);
1995+
learnMoreComposite.setLayout(new GridLayout());
1996+
1997+
learnMoreScrolledComposite.setContent(learnMoreComposite);
1998+
learnMoreScrolledComposite.setMinSize(learnMoreComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
1999+
2000+
if(learnMoreData == null) {
2001+
CLabel loadingLabel = new CLabel(learnMoreComposite, SWT.NONE);
19542002
loadingLabel.setText(PluginConstants.LEARN_MORE_LOADING);
1955-
}
1956-
2003+
}
2004+
19572005
learnMoreTab.setControl(learnMoreScrolledComposite);
19582006

19592007
Job job = new Job(PluginConstants.GETTING_LEARN_MORE_JOB) {
@@ -1987,8 +2035,8 @@ protected IStatus run(IProgressMonitor arg0) {
19872035
});
19882036
}
19892037

1990-
learnMoreScrolledComposite.setMinSize(learnMoreComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
1991-
learnMoreComposite.layout();
2038+
learnMoreScrolledComposite.setMinSize(learnMoreComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
2039+
learnMoreComposite.layout();
19922040
}
19932041
} catch (Exception e) {
19942042
CxLogger.error(String.format(PluginConstants.ERROR_GETTING_LEARN_MORE, e.getMessage()), e);
@@ -2036,17 +2084,17 @@ private void drawSASTRemediationExamples(DisplayModel selectedItem, TabFolder fo
20362084
final ScrolledComposite remediationExamplesScrolledComposite = new ScrolledComposite(folder, SWT.V_SCROLL | SWT.BORDER);
20372085
remediationExamplesScrolledComposite.setExpandHorizontal(true);
20382086
remediationExamplesScrolledComposite.setExpandVertical(true);
2039-
2040-
final Composite remediationExamplesComposite = new Composite(remediationExamplesScrolledComposite, SWT.NONE);
2041-
remediationExamplesComposite.setLayout(new GridLayout());
2042-
2043-
remediationExamplesScrolledComposite.setContent(remediationExamplesComposite);
2044-
remediationExamplesScrolledComposite.setMinSize(remediationExamplesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
20452087

2046-
if(learnMoreData == null) {
2047-
Label loadingLabel = new Label(remediationExamplesComposite, SWT.NONE);
2088+
final Composite remediationExamplesComposite = new Composite(remediationExamplesScrolledComposite, SWT.NONE);
2089+
remediationExamplesComposite.setLayout(new GridLayout());
2090+
2091+
remediationExamplesScrolledComposite.setContent(remediationExamplesComposite);
2092+
remediationExamplesScrolledComposite.setMinSize(remediationExamplesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
2093+
2094+
if(learnMoreData == null) {
2095+
Label loadingLabel = new Label(remediationExamplesComposite, SWT.NONE);
20482096
loadingLabel.setText(PluginConstants.LEARN_MORE_LOADING);
2049-
}
2097+
}
20502098

20512099
remediationExamplesTab.setControl(remediationExamplesScrolledComposite);
20522100

@@ -2074,14 +2122,14 @@ protected IStatus run(IProgressMonitor arg0) {
20742122
for(Sample sample : samples) {
20752123
StyledText sampleTitle = new StyledText(remediationExamplesComposite, SWT.WRAP);
20762124
sampleTitle.setText(String.format(PluginConstants.REMEDIATION_EXAMPLE_TITLE_FORMAT, sample.getTitle(), sample.getProgLanguage()));
2077-
GridData titleLayoutData = new GridData( GridData.FILL_HORIZONTAL ) ;
2078-
titleLayoutData.grabExcessHorizontalSpace = true;
2079-
titleLayoutData.horizontalAlignment = SWT.FILL;
2080-
titleLayoutData.widthHint = remediationExamplesScrolledComposite.getClientArea().width - SCROLL_WIDTH;
2081-
titleLayoutData.horizontalSpan = 2;
2082-
sampleTitle.setLayoutData(titleLayoutData);
2083-
sampleTitle.setMargins(2, 5, 2, 5);
2084-
2125+
GridData titleLayoutData = new GridData( GridData.FILL_HORIZONTAL ) ;
2126+
titleLayoutData.grabExcessHorizontalSpace = true;
2127+
titleLayoutData.horizontalAlignment = SWT.FILL;
2128+
titleLayoutData.widthHint = remediationExamplesScrolledComposite.getClientArea().width - SCROLL_WIDTH;
2129+
titleLayoutData.horizontalSpan = 2;
2130+
sampleTitle.setLayoutData(titleLayoutData);
2131+
sampleTitle.setMargins(2, 5, 2, 5);
2132+
20852133
Composite sampleExampleComposite = new Composite(remediationExamplesComposite, SWT.NONE);
20862134
sampleExampleComposite.setBackground(remediationExamplesComposite.getBackground());
20872135
GridLayout layout = new GridLayout();
@@ -2092,12 +2140,12 @@ protected IStatus run(IProgressMonitor arg0) {
20922140

20932141
Label sampleExample = new Label(sampleExampleComposite, SWT.WRAP);
20942142
sampleExample.setText(sample.getCode());
2095-
GridData exampleLayoutData = new GridData(GridData.FILL_HORIZONTAL) ;
2096-
exampleLayoutData.grabExcessHorizontalSpace = true;
2097-
exampleLayoutData.horizontalAlignment = SWT.FILL;
2098-
exampleLayoutData.widthHint = remediationExamplesScrolledComposite.getClientArea().width - SCROLL_WIDTH;
2099-
exampleLayoutData.horizontalSpan = 2;
2100-
sampleExample.setLayoutData(exampleLayoutData);
2143+
GridData exampleLayoutData = new GridData(GridData.FILL_HORIZONTAL) ;
2144+
exampleLayoutData.grabExcessHorizontalSpace = true;
2145+
exampleLayoutData.horizontalAlignment = SWT.FILL;
2146+
exampleLayoutData.widthHint = remediationExamplesScrolledComposite.getClientArea().width - SCROLL_WIDTH;
2147+
exampleLayoutData.horizontalSpan = 2;
2148+
sampleExample.setLayoutData(exampleLayoutData);
21012149

21022150
remediationExamplesScrolledComposite.setMinSize(remediationExamplesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
21032151
remediationExamplesComposite.layout();
@@ -2146,14 +2194,14 @@ private void addLearnMoreSectionsToComposite(Composite composite, String title,
21462194
titleLabel.setFont(boldFont);
21472195

21482196
StyledText descriptionLabel = new StyledText(composite, SWT.WRAP);
2149-
descriptionLabel.setText(description);
2150-
GridData descriptionLayout = new GridData(GridData.FILL_HORIZONTAL);
2151-
descriptionLayout.grabExcessHorizontalSpace = true;
2152-
descriptionLayout.horizontalAlignment = SWT.FILL;
2153-
descriptionLayout.widthHint = composite.getClientArea().width - SCROLL_WIDTH;
2154-
descriptionLayout.horizontalSpan = 2;
2155-
descriptionLabel.setLayoutData(descriptionLayout);
2156-
descriptionLabel.setBottomMargin(20);
2197+
descriptionLabel.setText(description);
2198+
GridData descriptionLayout = new GridData(GridData.FILL_HORIZONTAL);
2199+
descriptionLayout.grabExcessHorizontalSpace = true;
2200+
descriptionLayout.horizontalAlignment = SWT.FILL;
2201+
descriptionLayout.widthHint = composite.getClientArea().width - SCROLL_WIDTH;
2202+
descriptionLayout.horizontalSpan = 2;
2203+
descriptionLabel.setLayoutData(descriptionLayout);
2204+
descriptionLabel.setBottomMargin(20);
21572205
}
21582206

21592207
/*private void populateBFLMessage(Image image, String bflMessage) {
@@ -2232,18 +2280,18 @@ protected IStatus run(IProgressMonitor arg0) {
22322280
private void drawVulnerabilityLocation(DisplayModel selectedItem) {
22332281
ScrolledComposite sc = new ScrolledComposite(attackVectorCompositePanel, SWT.H_SCROLL | SWT.V_SCROLL);
22342282

2235-
Composite child = new Composite(sc, SWT.NONE);
2236-
child.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
2237-
child.setLayout(new GridLayout(1, false));
2238-
child.setBackground(attackVectorCompositePanel.getBackground());
2283+
Composite child = new Composite(sc, SWT.NONE);
2284+
child.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
2285+
child.setLayout(new GridLayout(1, false));
2286+
child.setBackground(attackVectorCompositePanel.getBackground());
22392287

2240-
drawAttackVectorTitle(child, PluginConstants.LOCATION);
2288+
drawAttackVectorTitle(child, PluginConstants.LOCATION);
22412289
drawIndividualLocationData(child, selectedItem);
22422290

2243-
sc.setContent(child);
2244-
sc.setMinSize(child.computeSize(SWT.DEFAULT, SWT.DEFAULT));
2245-
sc.setExpandHorizontal(true);
2246-
sc.setExpandVertical(true);
2291+
sc.setContent(child);
2292+
sc.setMinSize(child.computeSize(SWT.DEFAULT, SWT.DEFAULT));
2293+
sc.setExpandHorizontal(true);
2294+
sc.setExpandVertical(true);
22472295
}
22482296

22492297
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)