diff --git a/analyzer-checkov/src/main/java/io/codety/scanner/analyzer/checkov/CheckovCodeAnalyzer.java b/analyzer-checkov/src/main/java/io/codety/scanner/analyzer/checkov/CheckovCodeAnalyzer.java index 7c96dd8..d7c3cc1 100644 --- a/analyzer-checkov/src/main/java/io/codety/scanner/analyzer/checkov/CheckovCodeAnalyzer.java +++ b/analyzer-checkov/src/main/java/io/codety/scanner/analyzer/checkov/CheckovCodeAnalyzer.java @@ -19,7 +19,7 @@ public class CheckovCodeAnalyzer implements CodeAnalyzerInterface { private static final String checkov = "checkov"; @Override public List analyzeCode(AnalyzerConfigurationDetailDto runnerConfiguration, AnalyzerRequest request) { - CodetyConsoleLogger.debug("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"..."); + CodetyConsoleLogger.info("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"..."); ArrayList list = new ArrayList(); String[] command; diff --git a/analyzer-cppcheck/src/main/java/io/codety/scanner/analyzer/cppcheck/CppcheckCodeAnalyzer.java b/analyzer-cppcheck/src/main/java/io/codety/scanner/analyzer/cppcheck/CppcheckCodeAnalyzer.java index 89eb7c1..d0c4700 100644 --- a/analyzer-cppcheck/src/main/java/io/codety/scanner/analyzer/cppcheck/CppcheckCodeAnalyzer.java +++ b/analyzer-cppcheck/src/main/java/io/codety/scanner/analyzer/cppcheck/CppcheckCodeAnalyzer.java @@ -31,7 +31,7 @@ public class CppcheckCodeAnalyzer implements CodeAnalyzerInterface { private static final String INFO_failedToRunCppcheck = "Failed to run cpp analyzer due to error: "; @Override public List analyzeCode(AnalyzerConfigurationDetailDto runnerConfiguration, AnalyzerRequest request) { - CodetyConsoleLogger.debug("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"..."); + CodetyConsoleLogger.info("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"..."); File file = runnerConfiguration.getFile(); //cppcheck . --suppressions-list=suppression.txt --xml 2>error1.txt ArrayList list = new ArrayList(); diff --git a/analyzer-eslint/src/main/java/io/codety/scanner/analyzer/eslint/EslintCodeAnalyzer.java b/analyzer-eslint/src/main/java/io/codety/scanner/analyzer/eslint/EslintCodeAnalyzer.java index 4f94d82..a2f808a 100644 --- a/analyzer-eslint/src/main/java/io/codety/scanner/analyzer/eslint/EslintCodeAnalyzer.java +++ b/analyzer-eslint/src/main/java/io/codety/scanner/analyzer/eslint/EslintCodeAnalyzer.java @@ -47,7 +47,7 @@ public class EslintCodeAnalyzer implements CodeAnalyzerInterface { String aTrue = "true"; @Override public List analyzeCode(AnalyzerConfigurationDetailDto runnerConfiguration, AnalyzerRequest request) { - CodetyConsoleLogger.debug("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getPluginCode()+"..."); + CodetyConsoleLogger.info("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getPluginCode()+"..."); List result = new ArrayList<>(); CodetyConsoleLogger.debug(infoStartProcessing + runnerConfiguration.getLanguage() + " " + runnerConfiguration.getPluginCode()); diff --git a/analyzer-pmd/src/main/java/io/codety/scanner/analyzer/pmd/JavaPmdCodeAnalyzer.java b/analyzer-pmd/src/main/java/io/codety/scanner/analyzer/pmd/JavaPmdCodeAnalyzer.java index 0b53ed9..392b8bc 100644 --- a/analyzer-pmd/src/main/java/io/codety/scanner/analyzer/pmd/JavaPmdCodeAnalyzer.java +++ b/analyzer-pmd/src/main/java/io/codety/scanner/analyzer/pmd/JavaPmdCodeAnalyzer.java @@ -92,7 +92,7 @@ private List parsePmdResult(String pmdCsvResult, String ba @Override public List analyzeCode(AnalyzerConfigurationDetailDto runnerConfiguration, AnalyzerRequest request) { - CodetyConsoleLogger.debug("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"..."); + CodetyConsoleLogger.info("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"..."); String baseSourcePath = request.getLocalGitRepoPath(); CodeAnalyzerSettingGroupDto codeAnalyzerSettingGroupDto = sourceCodeDirectoryLayoutAnalyzer.analyzeSourceDirectory(baseSourcePath); List resultSetDto = new ArrayList<>(); diff --git a/analyzer-pylint/src/main/java/io/codety/scanner/analyzer/pylint/PylintCodeAnalyzer.java b/analyzer-pylint/src/main/java/io/codety/scanner/analyzer/pylint/PylintCodeAnalyzer.java index b590330..53d260c 100644 --- a/analyzer-pylint/src/main/java/io/codety/scanner/analyzer/pylint/PylintCodeAnalyzer.java +++ b/analyzer-pylint/src/main/java/io/codety/scanner/analyzer/pylint/PylintCodeAnalyzer.java @@ -26,7 +26,7 @@ public class PylintCodeAnalyzer implements CodeAnalyzerInterface { String message = "Cannot get any unmaterialized rules."; @Override public List analyzeCode(AnalyzerConfigurationDetailDto runnerConfiguration, AnalyzerRequest request) { - CodetyConsoleLogger.debug("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"..."); + CodetyConsoleLogger.info("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"..."); List result = new ArrayList<>(); CodetyConsoleLogger.debug(infoStartProcessing + runnerConfiguration.getLanguage() + " " + runnerConfiguration.getPluginCode()); diff --git a/analyzer-scalastyle/src/main/java/io/codety/scanner/analyzer/scalastyle/ScalastyleCodeAnalyzer.java b/analyzer-scalastyle/src/main/java/io/codety/scanner/analyzer/scalastyle/ScalastyleCodeAnalyzer.java new file mode 100644 index 0000000..63f35ab --- /dev/null +++ b/analyzer-scalastyle/src/main/java/io/codety/scanner/analyzer/scalastyle/ScalastyleCodeAnalyzer.java @@ -0,0 +1,77 @@ +package io.codety.scanner.analyzer.scalastyle; + +import io.codety.scanner.analyzer.CodeAnalyzerInterface; +import io.codety.scanner.analyzer.dto.AnalyzerConfigurationDetailDto; +import io.codety.scanner.reporter.dto.CodeAnalysisIssueDto; +import io.codety.scanner.reporter.dto.CodeAnalysisResultDto; +import io.codety.scanner.service.dto.AnalyzerRequest; +import io.codety.scanner.util.CodetyConsoleLogger; +import io.codety.scanner.util.RuntimeExecUtil; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.stereotype.Service; + +import java.io.File; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; + +@Service +public class ScalastyleCodeAnalyzer implements CodeAnalyzerInterface { + + + @Value("${codety.base.path}") + String scalaStyleJarPath; + + @Override + public List analyzeCode(AnalyzerConfigurationDetailDto runnerConfiguration, AnalyzerRequest request) { + + //cmd example: + // java -jar ~/dev/scalastyle.jar --config analyzer-scalastyle/src/test/resources/default-config.xml --xmlOutput ~/dev/tmp.xml code-issue-examples/scala + CodetyConsoleLogger.info("Scanning "+runnerConfiguration.getLanguage()+" code via "+runnerConfiguration.getCodeAnalyzerType().name()+"..."); + File file = runnerConfiguration.getFile(); + ArrayList list = new ArrayList(); + + String[] command; + String jarPath = scalaStyleJarPath + "/scalastyle.jar"; + runnerConfiguration.getFile(); + File tmpConfigDownloadFolder = new File("/tmp/scala_output_" + System.currentTimeMillis() + ".xml"); + String absoluteFile = tmpConfigDownloadFolder.getAbsolutePath(); + + if(runnerConfiguration.getPayload() == null || runnerConfiguration.getPayload().isEmpty()){ + command = new String[]{"java", "-jar", scalaStyleJarPath, "--config", request.getLocalGitRepoPath(), "--xmlOutput", absoluteFile, request.getLocalGitRepoPath()}; + }else{ + command = new String[]{"java", "-jar", scalaStyleJarPath, "--config", request.getLocalGitRepoPath(), "--xmlOutput", absoluteFile, request.getLocalGitRepoPath()}; + } + try { + + RuntimeExecUtil.RuntimeExecResult runtimeExecResult = RuntimeExecUtil.exec(command, null, 60, false, null); + + String errorOutput = runtimeExecResult.getErrorOutput(); + String successOutput = runtimeExecResult.getSuccessOutput(); + +// List codeAnalysisIssueDtoList = CppcheckResultConverter.convertResult(errorOutput); +// if(codeAnalysisIssueDtoList == null || codeAnalysisIssueDtoList.isEmpty()){ +// return list; +// } +// +// CodeAnalysisResultDto resultDto = new CodeAnalysisResultDto(runnerConfiguration.getLanguage(), runnerConfiguration.getCodeAnalyzerType()); +// +// resultDto.setDisplayTitle(cppTitle); +// resultDto.addIssues(codeAnalysisIssueDtoList); +// +// +// list.add(resultDto); + + } catch (Exception e) { + + CodetyConsoleLogger.debug("Failed to run scalastyle due to error " + e.getMessage(), e); + } + + return list; + } + + @Override + public List analyzeCode(AnalyzerRequest request) { + return null; + } +} diff --git a/analyzer-scalastyle/src/test/java/io/codety/scanner/analyzer/checkov/CheckovCodeAnalyzerTest.java b/analyzer-scalastyle/src/test/java/io/codety/scanner/analyzer/checkov/CheckovCodeAnalyzerTest.java deleted file mode 100644 index 348b432..0000000 --- a/analyzer-scalastyle/src/test/java/io/codety/scanner/analyzer/checkov/CheckovCodeAnalyzerTest.java +++ /dev/null @@ -1,57 +0,0 @@ -package io.codety.scanner.analyzer.checkov; - -import io.codety.common.dto.CodeAnalyzerType; -import io.codety.scanner.CodetyScannerTestMain; -import io.codety.scanner.analyzer.dto.AnalyzerConfigurationDetailDto; -import io.codety.scanner.reporter.dto.CodeAnalysisIssueDto; -import io.codety.scanner.reporter.dto.CodeAnalysisResultDto; -import io.codety.scanner.service.dto.AnalyzerRequest; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import java.nio.file.Paths; -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -@SpringBootTest(classes = CodetyScannerTestMain.class) -public class CheckovCodeAnalyzerTest { - - @Autowired - CheckovCodeAnalyzer checkovCodeAnalyzer; - - @Test - void testAnalyze(){ - - String path = Paths.get("../","code-issue-examples", "iac").toFile().getAbsoluteFile().getPath(); - - String language = "java"; - AnalyzerConfigurationDetailDto runnerConfiguration = new AnalyzerConfigurationDetailDto(language, CodeAnalyzerType.trivy); - Map env = new HashMap<>(); - AnalyzerRequest analyzerRequest = AnalyzerRequest.processSystemVariablesToRequest(env, new String[]{path}); - List codeAnalysisResultDtos = checkovCodeAnalyzer.analyzeCode(runnerConfiguration, analyzerRequest); - Assertions.assertTrue(codeAnalysisResultDtos.size() > 0); - - CodeAnalysisResultDto resultDto = codeAnalysisResultDtos.get(0); - Assertions.assertEquals(resultDto.getLanguage(), language); - Map> issuesByFile = resultDto.getIssuesByFile(); - Assertions.assertTrue(issuesByFile.size()>0); - for(String file : issuesByFile.keySet()) { - List issues = issuesByFile.get(file); - Assertions.assertTrue(issues.size() > 0); - for (CodeAnalysisIssueDto issueDto : issues) { - Assertions.assertTrue(issueDto.getStartLineNumber() > 0); - Assertions.assertTrue(issueDto.getIssueCode().length() > 0); - Assertions.assertTrue(issueDto.getPriority() > 0); - Assertions.assertTrue(issueDto.getIssueCategory().length() > 0); - Assertions.assertTrue(issueDto.getDescription().length() > 10); - Assertions.assertTrue(issueDto.getFilePath().length() > 10); - } - } - - - } - -} diff --git a/analyzer-scalastyle/src/test/resources/default-config.xml b/analyzer-scalastyle/src/test/resources/scalastyle-default-config.xml similarity index 100% rename from analyzer-scalastyle/src/test/resources/default-config.xml rename to analyzer-scalastyle/src/test/resources/scalastyle-default-config.xml diff --git a/scanner/tools/scalastyle-default-config.xml b/scanner/tools/scalastyle-default-config.xml new file mode 100644 index 0000000..db93055 --- /dev/null +++ b/scanner/tools/scalastyle-default-config.xml @@ -0,0 +1,142 @@ + + Scalastyle standard configuration + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/scanner/tools/scalastyle.jar b/scanner/tools/scalastyle.jar new file mode 100644 index 0000000..4a944f2 Binary files /dev/null and b/scanner/tools/scalastyle.jar differ