From c2c8a1881e64bb8d2b5a5f216510eceafe616a81 Mon Sep 17 00:00:00 2001 From: GhannamZ Date: Sun, 25 Oct 2020 00:39:24 +0300 Subject: [PATCH] Fixed upgrade issues --- gradle.properties | 2 +- .../com/checkmarx/jenkins/CxScanBuilder.java | 47 ++++++++++++++++++- .../jenkins/DependencyScanConfig.java | 3 +- .../jenkins/DependencyScannerType.java | 6 +++ .../jenkins/PluginDataMigration.java | 3 +- .../jenkins/CxScanBuilder/config.jelly | 4 +- .../jenkins/CxScanBuilder/global.jelly | 4 +- 7 files changed, 59 insertions(+), 10 deletions(-) create mode 100644 src/main/java/com/checkmarx/jenkins/DependencyScannerType.java diff --git a/gradle.properties b/gradle.properties index 5ab8e98b..2ae6c5e6 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,6 +1,6 @@ description = Provides automatic scan of code by Checkmarx server and shows results summary and trend in Jenkins interface. group = com.checkmarx.jenkins -version = 2020.4.2 +version = 2020.4.3 repositoryVersion= diff --git a/src/main/java/com/checkmarx/jenkins/CxScanBuilder.java b/src/main/java/com/checkmarx/jenkins/CxScanBuilder.java index 5fd342a2..a36b6a28 100644 --- a/src/main/java/com/checkmarx/jenkins/CxScanBuilder.java +++ b/src/main/java/com/checkmarx/jenkins/CxScanBuilder.java @@ -433,6 +433,11 @@ public boolean isOsaEnabled() { return osaEnabled; } + @DataBoundSetter + public void setOsaEnabled(boolean osaEnabled) { + this.osaEnabled = osaEnabled; + } + @Nullable public Integer getOsaHighThreshold() { return osaHighThreshold; @@ -468,21 +473,41 @@ public String getExcludeOpenSourceFolders() { return excludeOpenSourceFolders; } + @DataBoundSetter + public void setExcludeOpenSourceFolders(@Nullable String excludeOpenSourceFolders) { + this.excludeOpenSourceFolders = excludeOpenSourceFolders; + } + @Nullable public String getIncludeOpenSourceFolders() { return includeOpenSourceFolders; } + @DataBoundSetter + public void setIncludeOpenSourceFolders(@Nullable String includeOpenSourceFolders) { + this.includeOpenSourceFolders = includeOpenSourceFolders; + } + @Nullable public String getOsaArchiveIncludePatterns() { return osaArchiveIncludePatterns; } + @DataBoundSetter + public void setOsaArchiveIncludePatterns(@Nullable String osaArchiveIncludePatterns) { + this.osaArchiveIncludePatterns = osaArchiveIncludePatterns; + } + @Nullable public boolean isOsaInstallBeforeScan() { return osaInstallBeforeScan; } + @DataBoundSetter + public void setOsaInstallBeforeScan(boolean osaInstallBeforeScan) { + this.osaInstallBeforeScan = osaInstallBeforeScan; + } + public boolean isGeneratePdfReport() { return generatePdfReport; } @@ -855,6 +880,17 @@ private CxScanConfig resolveConfiguration(Run run, DescriptorImpl descript } } + if (isOsaEnabled() && getDependencyScanConfig() == null) { + DependencyScanConfig config = new DependencyScanConfig(); + config.overrideGlobalConfig = true; + config.dependencyScannerType = DependencyScannerType.OSA; + config.dependencyScanPatterns = getIncludeOpenSourceFolders(); + config.dependencyScanExcludeFolders = getExcludeOpenSourceFolders(); + config.osaArchiveIncludePatterns = getOsaArchiveIncludePatterns(); + config.osaInstallBeforeScan = isOsaInstallBeforeScan(); + setDependencyScanConfig(config); + } + configureDependencyScan(run, descriptor, env, ret); if (!ret.getSynchronous()) { @@ -884,7 +920,16 @@ private void configureDependencyScan(Run run, DescriptorImpl descriptor, E return; } - config.addScannerType(effectiveConfig.dependencyScannerType); + ScannerType scannerType = null; + if (effectiveConfig.dependencyScannerType == DependencyScannerType.OSA) { + scannerType = ScannerType.OSA; + } else if (effectiveConfig.dependencyScannerType == DependencyScannerType.SCA) { + scannerType = ScannerType.AST_SCA; + } + + if (scannerType != null) { + config.addScannerType(scannerType); + } config.setOsaFilterPattern(env.expand(effectiveConfig.dependencyScanPatterns)); config.setOsaFolderExclusions(env.expand(effectiveConfig.dependencyScanExcludeFolders)); diff --git a/src/main/java/com/checkmarx/jenkins/DependencyScanConfig.java b/src/main/java/com/checkmarx/jenkins/DependencyScanConfig.java index af207833..fdad6d56 100644 --- a/src/main/java/com/checkmarx/jenkins/DependencyScanConfig.java +++ b/src/main/java/com/checkmarx/jenkins/DependencyScanConfig.java @@ -1,6 +1,5 @@ package com.checkmarx.jenkins; -import com.cx.restclient.dto.ScannerType; import org.kohsuke.stapler.DataBoundConstructor; import org.kohsuke.stapler.DataBoundSetter; @@ -22,7 +21,7 @@ public class DependencyScanConfig { public String dependencyScanExcludeFolders; @DataBoundSetter - public ScannerType dependencyScannerType; + public DependencyScannerType dependencyScannerType; @DataBoundSetter public String osaArchiveIncludePatterns; diff --git a/src/main/java/com/checkmarx/jenkins/DependencyScannerType.java b/src/main/java/com/checkmarx/jenkins/DependencyScannerType.java new file mode 100644 index 00000000..5bd9ca7a --- /dev/null +++ b/src/main/java/com/checkmarx/jenkins/DependencyScannerType.java @@ -0,0 +1,6 @@ +package com.checkmarx.jenkins; + +public enum DependencyScannerType { + OSA, + SCA +} diff --git a/src/main/java/com/checkmarx/jenkins/PluginDataMigration.java b/src/main/java/com/checkmarx/jenkins/PluginDataMigration.java index adcee836..774eb8c4 100644 --- a/src/main/java/com/checkmarx/jenkins/PluginDataMigration.java +++ b/src/main/java/com/checkmarx/jenkins/PluginDataMigration.java @@ -1,6 +1,5 @@ package com.checkmarx.jenkins; -import com.cx.restclient.dto.ScannerType; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.ObjectMapper; import org.jetbrains.annotations.NotNull; @@ -43,7 +42,7 @@ private boolean needToMigrate(CxScanBuilder builder) { private DependencyScanConfig extractDependencyScanConfig(CxScanBuilder builder) { DependencyScanConfig config = new DependencyScanConfig(); config.overrideGlobalConfig = true; - config.dependencyScannerType = ScannerType.OSA; + config.dependencyScannerType = DependencyScannerType.OSA; config.dependencyScanPatterns = builder.getIncludeOpenSourceFolders(); config.dependencyScanExcludeFolders = builder.getExcludeOpenSourceFolders(); config.osaArchiveIncludePatterns = builder.getOsaArchiveIncludePatterns(); diff --git a/src/main/resources/com/checkmarx/jenkins/CxScanBuilder/config.jelly b/src/main/resources/com/checkmarx/jenkins/CxScanBuilder/config.jelly index 14c16ca4..cc3949b0 100644 --- a/src/main/resources/com/checkmarx/jenkins/CxScanBuilder/config.jelly +++ b/src/main/resources/com/checkmarx/jenkins/CxScanBuilder/config.jelly @@ -131,8 +131,8 @@ - + - +