Skip to content
This repository has been archived by the owner on Feb 28, 2024. It is now read-only.

Commit

Permalink
Merge pull request #90 from synopsys-sig/sonarcube-maintainability-is…
Browse files Browse the repository at this point in the history
…sue-fix

high priority issue fixed
  • Loading branch information
sadmananik authored Oct 10, 2023
2 parents 7be4799 + 98ddd57 commit 10c92b1
Show file tree
Hide file tree
Showing 5 changed files with 60 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,10 @@ private void handleBridgeDownload(boolean isBridgeDownloadRequired, boolean isNe
private int runScanner(Map<String, Object> scanParameters, FilePath bridgeInstallationPath) throws PluginExceptionHandler, ScannerException {
try {
return scanner.runScanner(scanParameters, bridgeInstallationPath);
} catch (PluginExceptionHandler e) {
throw new PluginExceptionHandler("Workflow failed! " + e.getMessage());
} catch (Exception e) {
if (e instanceof PluginExceptionHandler) {
throw new PluginExceptionHandler("Workflow failed! " + e.getMessage());
} else {
throw new ScannerException(ExceptionMessages.scannerFailureMessage(e.getMessage()));
}
throw new ScannerException(ExceptionMessages.scannerFailureMessage(e.getMessage()));
}
}

Expand All @@ -127,9 +125,11 @@ private void handleExitCode(int exitCode) throws PluginExceptionHandler {


public void logMessagesForParameters(Map<String, Object> scanParameters, Set<String> securityProducts) {
final String LOG_DASH = " --- ";

logger.println("-------------------------- Parameter Validation Initiated --------------------------");

logger.info(" --- " + ApplicationConstants.PRODUCT_KEY + " = " + securityProducts.toString());
logger.info(LOG_DASH + ApplicationConstants.PRODUCT_KEY + " = " + securityProducts.toString());

for (String product : securityProducts) {
String securityProduct = product.toLowerCase();
Expand All @@ -143,7 +143,7 @@ public void logMessagesForParameters(Map<String, Object> scanParameters, Set<Str
|| key.equals(ApplicationConstants.COVERITY_PASSPHRASE_KEY)) {
value = LogMessages.ASTERISKS;
}
logger.info(" --- " + key + " = " + value.toString());
logger.info(LOG_DASH + key + " = " + value.toString());
}
}

Expand All @@ -157,7 +157,7 @@ public void logMessagesForParameters(Map<String, Object> scanParameters, Set<Str
if(key.equals(ApplicationConstants.SYNOPSYS_BRIDGE_DOWNLOAD_URL) || key.equals(ApplicationConstants.SYNOPSYS_BRIDGE_DOWNLOAD_VERSION)
|| key.equals(ApplicationConstants.SYNOPSYS_BRIDGE_INSTALL_DIRECTORY) || key.equals(ApplicationConstants.INCLUDE_DIAGNOSTICS_KEY)) {
Object value = entry.getValue();
logger.info(" --- " + key + " = " + value.toString());
logger.info(LOG_DASH + key + " = " + value.toString());
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@

public class BridgeInstall {
private final LoggerWrapper logger;
private final TaskListener listener;
private final FilePath workspace;

public BridgeInstall(FilePath workspace, TaskListener listener) {
this.workspace = workspace;
this.listener = listener;
this.logger = new LoggerWrapper(listener);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ public class SecurityScanStep extends Step implements Serializable {

@DataBoundConstructor
public SecurityScanStep() {
// this block is kept empty intentionally
}

@DataBoundSetter
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ public String invoke(File workspace, VirtualChannel channel) {

@Override
public void checkRoles(RoleChecker checker) throws SecurityException {
// this method is kept empty intentionally
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,38 +67,22 @@ public BlackDuck prepareBlackDuckObjectForBridge(Map<String, Object> blackDuckPa
blackDuck.setToken(value);
break;
case ApplicationConstants.BLACKDUCK_INSTALL_DIRECTORY_KEY:
blackDuck.getInstall().setDirectory(value);
setInstallDirectory(blackDuck, value);
break;
case ApplicationConstants.BLACKDUCK_SCAN_FULL_KEY:
if (value.equals("true") || value.equals("false")) {
blackDuck.getScan().setFull(Boolean.parseBoolean(value));
}
setScanFull(blackDuck, value);
break;
case ApplicationConstants.BLACKDUCK_SCAN_FAILURE_SEVERITIES_KEY:
if (!value.isEmpty()) {
List<String> failureSeverities = new ArrayList<>();
String[] failureSeveritiesInput = value.toUpperCase().split(",");

for (String input : failureSeveritiesInput) {
failureSeverities.add(input.trim());
}
blackDuck.getScan().getFailure().setSeverities(failureSeverities);
}
setScanFailureSeverities(blackDuck, value);
break;
case ApplicationConstants.BLACKDUCK_AUTOMATION_FIXPR_KEY:
if (value.equals("true") || value.equals("false")) {
blackDuck.getAutomation().setFixpr(Boolean.parseBoolean(value));
}
setAutomationFixpr(blackDuck, value);
break;
case ApplicationConstants.BLACKDUCK_AUTOMATION_PRCOMMENT_KEY:
if (value.equals("true") || value.equals("false")) {
blackDuck.getAutomation().setPrComment(Boolean.parseBoolean(value));
}
setAutomationPrComment(blackDuck, value);
break;
case ApplicationConstants.BLACKDUCK_DOWNLOAD_URL_KEY:
Download download = new Download();
download.setUrl(value);
blackDuck.setDownload(download);
setDownloadUrl(blackDuck, value);
break;
default:
break;
Expand All @@ -108,4 +92,48 @@ public BlackDuck prepareBlackDuckObjectForBridge(Map<String, Object> blackDuckPa
return blackDuck;
}

private void setInstallDirectory(BlackDuck blackDuck, String value) {
blackDuck.getInstall().setDirectory(value);
}

private void setScanFull(BlackDuck blackDuck, String value) {
if (isBoolean(value)) {
blackDuck.getScan().setFull(Boolean.parseBoolean(value));
}
}

private void setScanFailureSeverities(BlackDuck blackDuck, String value) {
if (!value.isEmpty()) {
List<String> failureSeverities = new ArrayList<>();
String[] failureSeveritiesInput = value.toUpperCase().split(",");

for (String input : failureSeveritiesInput) {
failureSeverities.add(input.trim());
}
blackDuck.getScan().getFailure().setSeverities(failureSeverities);
}
}

private void setAutomationFixpr(BlackDuck blackDuck, String value) {
if (isBoolean(value)) {
blackDuck.getAutomation().setFixpr(Boolean.parseBoolean(value));
}
}

private void setAutomationPrComment(BlackDuck blackDuck, String value) {
if (isBoolean(value)) {
blackDuck.getAutomation().setPrComment(Boolean.parseBoolean(value));
}
}

private void setDownloadUrl(BlackDuck blackDuck, String value) {
Download download = new Download();
download.setUrl(value);
blackDuck.setDownload(download);
}

private boolean isBoolean(String value) {
return value.equals("true") || value.equals("false");
}

}

0 comments on commit 10c92b1

Please sign in to comment.