diff --git a/analyzer-scalastyle/build.gradle b/analyzer-scalastyle/build.gradle new file mode 100644 index 0000000..423cc55 --- /dev/null +++ b/analyzer-scalastyle/build.gradle @@ -0,0 +1,21 @@ +plugins { + id 'java-library' +} + +group = 'io.codety' +version = 'unspecified' + +dependencies { + implementation project(':scanner-common') + +} + +test { + useJUnitPlatform() +} + +jar { + enabled = true + archiveClassifier = '' //use empty string + version = null +} diff --git a/analyzer-scalastyle/doc/doc.md b/analyzer-scalastyle/doc/doc.md new file mode 100644 index 0000000..411bb4d --- /dev/null +++ b/analyzer-scalastyle/doc/doc.md @@ -0,0 +1,3 @@ + +Doc: +https://www.scalastyle.org/ diff --git a/analyzer-scalastyle/src/test/java/io/codety/scanner/CodetyScannerTestMain.java b/analyzer-scalastyle/src/test/java/io/codety/scanner/CodetyScannerTestMain.java new file mode 100644 index 0000000..cf24031 --- /dev/null +++ b/analyzer-scalastyle/src/test/java/io/codety/scanner/CodetyScannerTestMain.java @@ -0,0 +1,17 @@ +package io.codety.scanner; + +import io.codety.scanner.util.CodetyConstant; +import org.springframework.boot.CommandLineRunner; +import org.springframework.boot.autoconfigure.SpringBootApplication; +import org.springframework.context.annotation.ComponentScan; + +@SpringBootApplication +@ComponentScan(CodetyConstant.BASE_PACKAGE) //fixing the NoSuchBeanDefinitionException +//@Profile("!dev") +public class CodetyScannerTestMain implements CommandLineRunner { + + @Override + public void run(String... args) throws Exception { + + } +} \ No newline at end of file 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 new file mode 100644 index 0000000..348b432 --- /dev/null +++ b/analyzer-scalastyle/src/test/java/io/codety/scanner/analyzer/checkov/CheckovCodeAnalyzerTest.java @@ -0,0 +1,57 @@ +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/default-config.xml new file mode 100644 index 0000000..db93055 --- /dev/null +++ b/analyzer-scalastyle/src/test/resources/default-config.xml @@ -0,0 +1,142 @@ + + Scalastyle standard configuration + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/code-issue-examples/scala/emptyclass.scala b/code-issue-examples/scala/emptyclass.scala new file mode 100644 index 0000000..7faed6d --- /dev/null +++ b/code-issue-examples/scala/emptyclass.scala @@ -0,0 +1,2 @@ +object MyEmptyClass { +} \ No newline at end of file diff --git a/code-issue-examples/scala/test.scala b/code-issue-examples/scala/test.scala new file mode 100644 index 0000000..2026ad4 --- /dev/null +++ b/code-issue-examples/scala/test.scala @@ -0,0 +1,8 @@ +object OrderService { + def make ( + userService: UserService, + discountForProuduct: DiscountService, + bonusForPurchase: BonusesService, + productIdIsValid: ProductService + ): OrderService +} \ No newline at end of file diff --git a/image/Dockerfile b/image/Dockerfile index 1c5d208..d696f88 100644 --- a/image/Dockerfile +++ b/image/Dockerfile @@ -23,6 +23,7 @@ COPY scanner/codety.sh /usr/bin/codety COPY scanner/tools/ /tools/ COPY scanner/build/libs/app.jar /usr/app.jar RUN chmod +x /usr/bin/codety +RUN curl -sfL https://oss.sonatype.org/content/repositories/releases/org/scalastyle/scalastyle_2.12/1.0.0/scalastyle_2.12-1.0.0-batch.jar > /tools/scalastyle.jar WORKDIR /src ENTRYPOINT ["codety"] diff --git a/scanner/build.gradle b/scanner/build.gradle index 8f7d603..fa6ae30 100644 --- a/scanner/build.gradle +++ b/scanner/build.gradle @@ -35,6 +35,7 @@ dependencies { implementation project(':analyzer-trivy') implementation project(':analyzer-golangcilint') implementation project(':analyzer-codety') + implementation project(':analyzer-scalastyle') } diff --git a/settings.gradle b/settings.gradle index ebfba5e..7869b13 100644 --- a/settings.gradle +++ b/settings.gradle @@ -12,3 +12,4 @@ include 'analyzer-pmd' include 'analyzer-pylint' include 'analyzer-trivy' include 'analyzer-golangcilint' +include 'analyzer-scalastyle'