Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public static void beforeClass() throws Exception {
// Used to decrease tests velocity
SWTBotPreferences.PLAYBACK_DELAY = 500;

SWTBotPreferences.TIMEOUT = 20000;
SWTBotPreferences.TIMEOUT = 30000;

_bot = new SWTWorkbenchBot();

Expand Down
7 changes: 4 additions & 3 deletions checkmarx-ast-eclipse-plugin/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
<classpathentry exported="true" kind="lib" path="lib/slf4j-api-1.7.5.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jackson-annotations-2.15.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jackson-core-2.15.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/commons-lang3-3.12.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/commons-lang3-3.18.0.jar"/>
<classpathentry exported="true" kind="lib" path="lib/ast-cli-java-wrapper-2.4.4.jar"/>
<classpathentry exported="true" kind="lib" path="lib/jackson-databind-2.15.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/org.eclipse.mylyn.commons.ui_3.25.2.v20200813-0821.jar"/>
<classpathentry exported="true" kind="lib" path="lib/org.apache.commons.lang_2.6.0.v20220406-2305.jar"/>
<classpathentry exported="true" kind="lib" path="lib/org-eclipse-mylyn-commons-core.jar"/>
<classpathentry kind="src" path="src/"/>
<classpathentry kind="lib" path="lib/commons-lang3-3.18.0.jar"/>
<classpathentry kind="src" path="src"/>
<classpathentry kind="output" path="target/classes"/>
</classpath>
</classpath>
2 changes: 1 addition & 1 deletion checkmarx-ast-eclipse-plugin/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ Bundle-ClassPath: lib/slf4j-simple-1.7.5.jar,
lib/slf4j-api-1.7.5.jar,
lib/jackson-annotations-2.15.2.jar,
lib/jackson-core-2.15.2.jar,
lib/commons-lang3-3.12.0.jar,
lib/commons-lang3-3.18.0.jar,
lib/ast-cli-java-wrapper-2.4.4.jar,
lib/jackson-databind-2.15.2.jar,
lib/org.eclipse.mylyn.commons.ui_3.25.2.v20200813-0821.jar,
Expand Down
2 changes: 1 addition & 1 deletion checkmarx-ast-eclipse-plugin/build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ bin.includes = plugin.xml,\
lib/slf4j-api-1.7.5.jar,\
lib/jackson-annotations-2.15.2.jar,\
lib/jackson-core-2.15.2.jar,\
lib/commons-lang3-3.12.0.jar,\
lib/commons-lang3-3.18.0.jar,\
lib/ast-cli-java-wrapper-2.4.4.jar,\
lib/jackson-databind-2.15.2.jar,\
lib/org.eclipse.mylyn.commons.ui_3.25.2.v20200813-0821.jar,\
Expand Down
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.util.Optional;
import java.util.Set;
import java.util.UUID;
import java.util.stream.Collectors;

import org.apache.commons.lang3.StringUtils;
import org.eclipse.core.resources.IFile;
Expand Down Expand Up @@ -98,6 +99,8 @@
import com.google.common.base.Strings;
import com.google.common.eventbus.EventBus;
import com.google.common.eventbus.Subscribe;
import java.util.Timer;
import java.util.TimerTask;

public class CheckmarxView extends ViewPart implements EventHandler {

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

private Timer debounceTimer = new Timer("ProjectSearchDebounce", true);
private TimerTask pendingSearchTask;
private static final int DEBOUNCE_DELAY_MS = 400;
private volatile String latestProjectSearchTerm = "";

private static final int SCROLL_WIDTH = 30;
/**
* The ID of the view as specified by the extension.
Expand Down Expand Up @@ -805,18 +813,58 @@ protected IStatus run(IProgressMonitor arg0) {

// Add ModifyListener to handle manual text input for projects
projectComboViewer.getCombo().addModifyListener(e -> {
String enteredProject = projectComboViewer.getCombo().getText();

// Check if text was modified and project doesn't exist
boolean projectExists = currentProjects.stream()
.anyMatch(p -> p.getName().equals(enteredProject));

if (!projectExists) {
String enteredProject = projectComboViewer.getCombo().getText().trim();
// Skip search if the text is the default instruction
if (enteredProject.equals(PROJECT_COMBO_VIEWER_TEXT)) {
updateStartScanButton(false); // Disable scan button
} else {
// Only enable if we also have a valid branch
boolean validBranch = !currentBranch.isEmpty() && currentBranches.contains(currentBranch);
updateStartScanButton(validBranch);
return;
}

latestProjectSearchTerm = enteredProject; // Track the latest term
List<String> matchedProjects;
matchedProjects = currentProjects.stream().map(Project::getName)
.filter(name -> name != null && name.toLowerCase().contains(enteredProject.toLowerCase())).limit(100)
.collect(Collectors.toList());

if (matchedProjects.isEmpty()) {
CxLogger.info("Entered project is not exist in current projects list");
// Cancel any pending search
if (pendingSearchTask != null) {
pendingSearchTask.cancel();
}
// Schedule a new search after the debounce delay
pendingSearchTask = new java.util.TimerTask() {
@Override
public void run() {
final String searchTerm = latestProjectSearchTerm; // Capture the term for this search
// Schedule a background job for the server search
Job job = new Job("Checkmarx: Searching for project on server...") {
@Override
protected IStatus run(IProgressMonitor monitor) {
List<Project> searchedProjects;
try {
searchedProjects = DataProvider.getInstance().getProjects(searchTerm);
Display.getDefault().asyncExec(() -> {
if (searchTerm.equals(latestProjectSearchTerm)) {
// Update UI in UI thread
if (searchedProjects != null && !searchedProjects.isEmpty()) {
projectComboViewer.setInput(searchedProjects);
currentProjects = searchedProjects;
} else {
updateStartScanButton(false); // Disable scan button
}
}
});
} catch (Exception ex) {
ex.printStackTrace();
}
return Status.OK_STATUS;
}
};
job.schedule();
}
};
debounceTimer.schedule(pendingSearchTask, DEBOUNCE_DELAY_MS);
}
});
}
Expand Down Expand Up @@ -1806,20 +1854,20 @@ private void layoutAttackVectorItemComposite() {
}

private void drawPackageData(DisplayModel selectedItem) {
ScrolledComposite sc = new ScrolledComposite(attackVectorCompositePanel, SWT.H_SCROLL | SWT.V_SCROLL);
ScrolledComposite sc = new ScrolledComposite(attackVectorCompositePanel, SWT.H_SCROLL | SWT.V_SCROLL);

Composite child = new Composite(sc, SWT.NONE);
child.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
child.setLayout(new GridLayout(1, false));
child.setBackground(attackVectorCompositePanel.getBackground());
Composite child = new Composite(sc, SWT.NONE);
child.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
child.setLayout(new GridLayout(1, false));
child.setBackground(attackVectorCompositePanel.getBackground());

drawAttackVectorTitle(child, PluginConstants.PACKAGE_DATA);
drawIndividualPackageData(child, selectedItem.getResult().getData().getPackageData());
drawAttackVectorTitle(child, PluginConstants.PACKAGE_DATA);
drawIndividualPackageData(child, selectedItem.getResult().getData().getPackageData());

sc.setContent(child);
sc.setMinSize(child.computeSize(SWT.DEFAULT, SWT.DEFAULT));
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setContent(child);
sc.setMinSize(child.computeSize(SWT.DEFAULT, SWT.DEFAULT));
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
}

/**
Expand Down Expand Up @@ -1930,18 +1978,18 @@ private void drawSASTLearnMore(DisplayModel selectedItem, TabFolder folder, TabI
final ScrolledComposite learnMoreScrolledComposite = new ScrolledComposite(folder, SWT.V_SCROLL);
learnMoreScrolledComposite.setExpandHorizontal(true);
learnMoreScrolledComposite.setExpandVertical(true);

final Composite learnMoreComposite = new Composite(learnMoreScrolledComposite, SWT.NONE);
learnMoreComposite.setLayout(new GridLayout());

learnMoreScrolledComposite.setContent(learnMoreComposite);
learnMoreScrolledComposite.setMinSize(learnMoreComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));

if(learnMoreData == null) {
CLabel loadingLabel = new CLabel(learnMoreComposite, SWT.NONE);
final Composite learnMoreComposite = new Composite(learnMoreScrolledComposite, SWT.NONE);
learnMoreComposite.setLayout(new GridLayout());

learnMoreScrolledComposite.setContent(learnMoreComposite);
learnMoreScrolledComposite.setMinSize(learnMoreComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));

if(learnMoreData == null) {
CLabel loadingLabel = new CLabel(learnMoreComposite, SWT.NONE);
loadingLabel.setText(PluginConstants.LEARN_MORE_LOADING);
}
}
learnMoreTab.setControl(learnMoreScrolledComposite);

Job job = new Job(PluginConstants.GETTING_LEARN_MORE_JOB) {
Expand Down Expand Up @@ -1975,8 +2023,8 @@ protected IStatus run(IProgressMonitor arg0) {
});
}

learnMoreScrolledComposite.setMinSize(learnMoreComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
learnMoreComposite.layout();
learnMoreScrolledComposite.setMinSize(learnMoreComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
learnMoreComposite.layout();
}
} catch (Exception e) {
CxLogger.error(String.format(PluginConstants.ERROR_GETTING_LEARN_MORE, e.getMessage()), e);
Expand Down Expand Up @@ -2024,17 +2072,17 @@ private void drawSASTRemediationExamples(DisplayModel selectedItem, TabFolder fo
final ScrolledComposite remediationExamplesScrolledComposite = new ScrolledComposite(folder, SWT.V_SCROLL | SWT.BORDER);
remediationExamplesScrolledComposite.setExpandHorizontal(true);
remediationExamplesScrolledComposite.setExpandVertical(true);

final Composite remediationExamplesComposite = new Composite(remediationExamplesScrolledComposite, SWT.NONE);
remediationExamplesComposite.setLayout(new GridLayout());

remediationExamplesScrolledComposite.setContent(remediationExamplesComposite);
remediationExamplesScrolledComposite.setMinSize(remediationExamplesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));

if(learnMoreData == null) {
Label loadingLabel = new Label(remediationExamplesComposite, SWT.NONE);
final Composite remediationExamplesComposite = new Composite(remediationExamplesScrolledComposite, SWT.NONE);
remediationExamplesComposite.setLayout(new GridLayout());

remediationExamplesScrolledComposite.setContent(remediationExamplesComposite);
remediationExamplesScrolledComposite.setMinSize(remediationExamplesComposite.computeSize(SWT.DEFAULT, SWT.DEFAULT));

if(learnMoreData == null) {
Label loadingLabel = new Label(remediationExamplesComposite, SWT.NONE);
loadingLabel.setText(PluginConstants.LEARN_MORE_LOADING);
}
}

remediationExamplesTab.setControl(remediationExamplesScrolledComposite);

Expand Down Expand Up @@ -2062,14 +2110,14 @@ protected IStatus run(IProgressMonitor arg0) {
for(Sample sample : samples) {
StyledText sampleTitle = new StyledText(remediationExamplesComposite, SWT.WRAP);
sampleTitle.setText(String.format(PluginConstants.REMEDIATION_EXAMPLE_TITLE_FORMAT, sample.getTitle(), sample.getProgLanguage()));
GridData titleLayoutData = new GridData( GridData.FILL_HORIZONTAL ) ;
titleLayoutData.grabExcessHorizontalSpace = true;
titleLayoutData.horizontalAlignment = SWT.FILL;
titleLayoutData.widthHint = remediationExamplesScrolledComposite.getClientArea().width - SCROLL_WIDTH;
titleLayoutData.horizontalSpan = 2;
sampleTitle.setLayoutData(titleLayoutData);
sampleTitle.setMargins(2, 5, 2, 5);
GridData titleLayoutData = new GridData( GridData.FILL_HORIZONTAL ) ;
titleLayoutData.grabExcessHorizontalSpace = true;
titleLayoutData.horizontalAlignment = SWT.FILL;
titleLayoutData.widthHint = remediationExamplesScrolledComposite.getClientArea().width - SCROLL_WIDTH;
titleLayoutData.horizontalSpan = 2;
sampleTitle.setLayoutData(titleLayoutData);
sampleTitle.setMargins(2, 5, 2, 5);
Composite sampleExampleComposite = new Composite(remediationExamplesComposite, SWT.NONE);
sampleExampleComposite.setBackground(remediationExamplesComposite.getBackground());
GridLayout layout = new GridLayout();
Expand All @@ -2080,12 +2128,12 @@ protected IStatus run(IProgressMonitor arg0) {

Label sampleExample = new Label(sampleExampleComposite, SWT.WRAP);
sampleExample.setText(sample.getCode());
GridData exampleLayoutData = new GridData(GridData.FILL_HORIZONTAL) ;
exampleLayoutData.grabExcessHorizontalSpace = true;
exampleLayoutData.horizontalAlignment = SWT.FILL;
exampleLayoutData.widthHint = remediationExamplesScrolledComposite.getClientArea().width - SCROLL_WIDTH;
exampleLayoutData.horizontalSpan = 2;
sampleExample.setLayoutData(exampleLayoutData);
GridData exampleLayoutData = new GridData(GridData.FILL_HORIZONTAL) ;
exampleLayoutData.grabExcessHorizontalSpace = true;
exampleLayoutData.horizontalAlignment = SWT.FILL;
exampleLayoutData.widthHint = remediationExamplesScrolledComposite.getClientArea().width - SCROLL_WIDTH;
exampleLayoutData.horizontalSpan = 2;
sampleExample.setLayoutData(exampleLayoutData);

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

StyledText descriptionLabel = new StyledText(composite, SWT.WRAP);
descriptionLabel.setText(description);
GridData descriptionLayout = new GridData(GridData.FILL_HORIZONTAL);
descriptionLayout.grabExcessHorizontalSpace = true;
descriptionLayout.horizontalAlignment = SWT.FILL;
descriptionLayout.widthHint = composite.getClientArea().width - SCROLL_WIDTH;
descriptionLayout.horizontalSpan = 2;
descriptionLabel.setLayoutData(descriptionLayout);
descriptionLabel.setBottomMargin(20);
descriptionLabel.setText(description);
GridData descriptionLayout = new GridData(GridData.FILL_HORIZONTAL);
descriptionLayout.grabExcessHorizontalSpace = true;
descriptionLayout.horizontalAlignment = SWT.FILL;
descriptionLayout.widthHint = composite.getClientArea().width - SCROLL_WIDTH;
descriptionLayout.horizontalSpan = 2;
descriptionLabel.setLayoutData(descriptionLayout);
descriptionLabel.setBottomMargin(20);
}

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

Composite child = new Composite(sc, SWT.NONE);
child.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
child.setLayout(new GridLayout(1, false));
child.setBackground(attackVectorCompositePanel.getBackground());
Composite child = new Composite(sc, SWT.NONE);
child.setLayoutData(new GridData(GridData.FILL, GridData.BEGINNING, true, true));
child.setLayout(new GridLayout(1, false));
child.setBackground(attackVectorCompositePanel.getBackground());

drawAttackVectorTitle(child, PluginConstants.LOCATION);
drawAttackVectorTitle(child, PluginConstants.LOCATION);
drawIndividualLocationData(child, selectedItem);

sc.setContent(child);
sc.setMinSize(child.computeSize(SWT.DEFAULT, SWT.DEFAULT));
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
sc.setContent(child);
sc.setMinSize(child.computeSize(SWT.DEFAULT, SWT.DEFAULT));
sc.setExpandHorizontal(true);
sc.setExpandVertical(true);
}

private void drawIndividualLocationData(Composite parent, DisplayModel selectedItem) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ public class DataProvider {
private static final List<String> SEVERITY_ORDER = Arrays.asList("CRITICAL", "HIGH", "MEDIUM", "LOW", "INFO");

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

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

/**
* Get One projects filtered by name
*
* @return
* @throws Exception
*/
public List<Project> getProjects(String projectName) throws Exception {
List<Project> projectList = new ArrayList<Project>();

CxWrapper cxWrapper = authenticateWithAST();
String filterProject = NAME_FILTER+projectName;

if (cxWrapper != null) {
try {
projectList = cxWrapper.projectList(filterProject);

} catch (IOException | InterruptedException | CxException e) {
CxLogger.error(String.format(PluginConstants.ERROR_GETTING_PROJECTS, e.getMessage()), e);
}
}

return projectList;
}

/**
* Get the codeBashing link
* @throws Exception
Expand Down